aboutsummaryrefslogtreecommitdiff
path: root/microblaze-vitis/hello_world/src/main.c
blob: e202c4a6d6a3341550f68ca1c308e7836a7a20a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
	}
}