diff options
| author | lonkaars <loek@pipeframe.xyz> | 2024-04-11 14:31:45 +0200 |
|---|---|---|
| committer | lonkaars <loek@pipeframe.xyz> | 2024-04-11 14:31:45 +0200 |
| commit | a2cd704ca2690d77d0ad05e2f1b97d8bbb2305d7 (patch) | |
| tree | b528969571d6dcad20a8c6600c52733989daec9e /microblaze-vitis/hello_world/src/main.c | |
| parent | a1f490fccb27f1b886840269403f84cf5eb0ba3b (diff) | |
Diffstat (limited to 'microblaze-vitis/hello_world/src/main.c')
| -rw-r--r-- | microblaze-vitis/hello_world/src/main.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/microblaze-vitis/hello_world/src/main.c b/microblaze-vitis/hello_world/src/main.c new file mode 100644 index 0000000..e202c4a --- /dev/null +++ b/microblaze-vitis/hello_world/src/main.c @@ -0,0 +1,46 @@ +#include "xparameters.h" +#include "xil_printf.h" +#include "xgpio.h" +#include "xil_types.h" + +// Get device IDs from xparameters.h +#define BTN_ID XPAR_AXI_GPIO_BUTTONS_DEVICE_ID +#define LED_ID XPAR_AXI_GPIO_LED_DEVICE_ID +#define BTN_CHANNEL 1 +#define LED_CHANNEL 1 +#define BTN_MASK 0x0000ffff +#define LED_MASK 0x0000ffff + +void show_buttons(u32 buttons) { + for (int i = 0; i < 16; i++) { + xil_printf("%s ", ((buttons >> 15) & 1) > 0 ? "1" : "0"); + buttons <<= 1; + } + xil_printf("\r\n"); + return; +} + +int main() { + xil_printf("boot'd\r\n"); + XGpio_Config *cfg_ptr; + XGpio led_device, btn_device; + + cfg_ptr = XGpio_LookupConfig(XPAR_AXI_GPIO_LEDS_BASEADDR); + XGpio_CfgInitialize(&led_device, cfg_ptr, cfg_ptr->BaseAddress); + cfg_ptr = XGpio_LookupConfig(XPAR_AXI_GPIO_BUTTONS_BASEADDR); + XGpio_CfgInitialize(&btn_device, cfg_ptr, cfg_ptr->BaseAddress); + XGpio_SetDataDirection(&btn_device, BTN_CHANNEL, BTN_MASK); + XGpio_SetDataDirection(&led_device, LED_CHANNEL, 0); + + + u32 data, old_data; + while (1) { + data = XGpio_DiscreteRead(&btn_device, BTN_CHANNEL); + data &= BTN_MASK; + XGpio_DiscreteWrite(&led_device, LED_CHANNEL, data); + + if (data != old_data) show_buttons(data); + + old_data = data; + } +}
\ No newline at end of file |