Added C/Rust-Bindings for XGPIO

This commit is contained in:
paul nehlich 2024-05-16 10:58:26 +02:00
parent 39ea98d9c0
commit 2f196c167e
2 changed files with 39 additions and 0 deletions

View File

@ -1,6 +1,7 @@
#include "FreeRTOS.h"
#include "semphr.h"
#include "task.h"
#include <xgpiops.h>
// 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);
}

View File

@ -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() {