diff --git a/mission/freeRTOS_rust_helper.c b/mission/freeRTOS_rust_helper.c index 4e841a4..d7f6790 100644 --- a/mission/freeRTOS_rust_helper.c +++ b/mission/freeRTOS_rust_helper.c @@ -1,6 +1,7 @@ #include "FreeRTOS.h" #include "semphr.h" #include "task.h" +#include // TODO namespace the names @@ -98,4 +99,36 @@ uint8_t give_mutex(void * handle) { } else { return 0; } +} + + + +XGpioPs gpio; +void gpio_setup() { + XGpioPs_Config config; + config.DeviceId = 4; // chosen by fair dice throw + config.BaseAddr = XPS_GPIO_BASEADDR; + s32 returncode = XGpioPs_CfgInitialize(&gpio, &config, XPS_GPIO_BASEADDR); + //printf("Configured XGPIO"); + XGpioPs_SetDirection(&gpio, 0, (1 << 7)); + XGpioPs_SetOutputEnable(&gpio, 0, (1 << 7)); + XGpioPs_WritePin(&gpio, 7, 1); + //printf("Blinking is initialized"); + XGpioPs_WritePin(&gpio, 7, 0); + //printf("Value written once"); +} + + +void gpio_write_pin(uint32_t pin, uint32_t data) { + XGpioPs_WritePin(&gpio, pin, data); +} + +uint32_t gpio_read_pin(uint32_t pin) { + return XGpioPs_ReadPin(&gpio, pin); +} + +void gpio_toggle_pin(uint32_t pin) { + static int pinvalue = 1; + pinvalue = pinvalue ^ 1; + XGpioPs_WritePin(&gpio, pin, pinvalue); } \ No newline at end of file diff --git a/mission_rust/src/fsrc/osal/mod.rs b/mission_rust/src/fsrc/osal/mod.rs index 05191c4..68ae311 100644 --- a/mission_rust/src/fsrc/osal/mod.rs +++ b/mission_rust/src/fsrc/osal/mod.rs @@ -46,6 +46,12 @@ extern "C" { fn enable_global_threading_c(); fn disable_global_threading_c(); + + pub fn gpio_setup() -> (); + pub fn gpio_write_pin(pin: u32, data: u32) -> (); // TODO: Is u32 compatible to uint32_t? + pub fn gpio_read_pin(pin: u32) -> u32; + pub fn gpio_toggle_pin(pin: u32) -> (); + } pub fn task_delete_self() {