-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee83f62
commit f825eac
Showing
6 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
/target | ||
target | ||
/.vscode | ||
*.dll | ||
*.so | ||
*.dylib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "peripheral.h" | ||
#include<stdio.h> | ||
#include <stdint.h> | ||
|
||
uint8_t STATE = 0x00; | ||
|
||
__declspec(dllexport) void init(void) { | ||
printf("C init\n"); | ||
} | ||
|
||
__declspec(dllexport) uint8_t read(void) { | ||
printf("C read\n"); | ||
return STATE; | ||
} | ||
|
||
__declspec(dllexport) void write(uint8_t data) { | ||
printf("C write\n"); | ||
STATE = data; | ||
} | ||
|
||
__declspec(dllexport) const char* name(void) { | ||
return "C Example"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdint.h> | ||
|
||
__declspec(dllexport) void init(void); | ||
__declspec(dllexport) uint8_t read(void); | ||
__declspec(dllexport) void write(uint8_t data); | ||
__declspec(dllexport) const char* name(void); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "example-peripheral" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
name = "rust_peripheral" | ||
crate-type = ["rlib", "cdylib"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
byte-strings = "0.3.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use byte_strings::c_str; | ||
|
||
static mut STATE: u8 = 0x00; | ||
|
||
// Will be called on library load | ||
#[no_mangle] | ||
pub extern "C" fn init() { | ||
println!("Rust init"); | ||
} | ||
|
||
// Will be called whenever the attached port is read from. | ||
#[no_mangle] | ||
pub unsafe extern "C" fn read() -> u8 { | ||
println!("Rust read"); | ||
STATE | ||
} | ||
|
||
// Will be called whenever the attached port is written to. | ||
#[no_mangle] | ||
pub unsafe extern "C" fn write(data: u8) { | ||
println!("Rust example write"); | ||
STATE = data; | ||
} | ||
|
||
// Will be called whenever the attached port is written to. | ||
#[no_mangle] | ||
pub extern "C" fn name() -> *const i8 { | ||
c_str!("Rust Example").as_ptr() | ||
} |