wrote some ffi functions and interfaces
tested the fact that the rust library could be used in a embedded application
This commit is contained in:
parent
bf429bb8f7
commit
f3a7db00c9
11
autobar.c
11
autobar.c
@ -6,6 +6,11 @@
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
void gpio_put_explict(int pin, bool status) {
|
||||
gpio_put(pin, status);
|
||||
return;
|
||||
}
|
||||
|
||||
void set_and_sleep(int pin, bool state, int sleep_duration);
|
||||
|
||||
int main() {
|
||||
@ -13,9 +18,7 @@ int main() {
|
||||
gpio_init(LED_PIN);
|
||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||
while (true) {
|
||||
gpio_put(LED_PIN, 1);
|
||||
sleep_ms(250);
|
||||
gpio_put(LED_PIN, 0);
|
||||
sleep_ms(250);
|
||||
set_and_sleep(LED_PIN, 1, 1000);
|
||||
set_and_sleep(LED_PIN, 0, 1000);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
[package]
|
||||
name = "libautobar"
|
||||
version = "0.1.0"
|
||||
version = "0.0.1"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[lib]
|
||||
name = "autobar"
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
|
@ -1,3 +1,26 @@
|
||||
#![no_std]
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
#[panic_handler]
|
||||
fn panik(_panic_state: &PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
extern {
|
||||
fn gpio_put_explict(pin: i32, status: bool) -> i32;
|
||||
fn sleep_ms(time: i32) -> i32;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn set_and_sleep(pin: i32, status: bool, time: i32) -> () {
|
||||
unsafe {
|
||||
gpio_put_explict(pin, status);
|
||||
sleep_ms(time);
|
||||
}
|
||||
}
|
||||
|
||||
// this is just a mock test, supposed to pass
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user