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:
Wyatt J. Miller 2022-07-16 10:44:38 -04:00
parent bf429bb8f7
commit f3a7db00c9
3 changed files with 34 additions and 5 deletions

View File

@ -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);
}
}

View File

@ -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]

View File

@ -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]