From 9f07bf5188e10b2d4d4405eb1f6c48e977d0662e Mon Sep 17 00:00:00 2001 From: Marno van der Maas Date: Thu, 2 Nov 2023 14:07:03 +0000 Subject: [PATCH] Fix green LEDs in hello world demo Since the display is now connected to the bottom 4 bits of the GPIO, I needed to change the GPIO header to increase the mask to 8 bits. Afterwards the hello world demo is changed to shift through the top 4 bits of the GPIO. Button 0 is still used as a way to pause the shifting. --- sw/c/common/gpio.h | 3 ++- sw/c/demo/hello_world/main.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sw/c/common/gpio.h b/sw/c/common/gpio.h index 6c4a1cc4..6e0962de 100644 --- a/sw/c/common/gpio.h +++ b/sw/c/common/gpio.h @@ -12,7 +12,8 @@ #define GPIO_IN_DBNC_REG 0x8 #define GPIO_OUT_SHIFT_REG 0xC -#define GPIO_OUT_MASK 0xF // Support 4-bit output +#define GPIO_OUT_MASK 0xFF // Support 8-bit output +#define GPIO_LED_MASK 0xF0 // Top 4 bits are green LEDs typedef void* gpio_t; diff --git a/sw/c/demo/hello_world/main.c b/sw/c/demo/hello_world/main.c index 4490de5e..3d4b3339 100644 --- a/sw/c/demo/hello_world/main.c +++ b/sw/c/demo/hello_world/main.c @@ -33,8 +33,8 @@ int main(void) { uint64_t last_elapsed_time = get_elapsed_time(); - // Reset green LEDs to off - set_outputs(GPIO_OUT, 0x0); + // Reset green LEDs to having just one on + set_outputs(GPIO_OUT, 0x10); // Bottom 4 bits are LCD control as you can see in top_artya7.sv // PWM variables uint32_t counter = UINT8_MAX; @@ -64,12 +64,17 @@ int main(void) { // Re-enable interrupts with output complete set_global_interrupt_enable(1); - // Cycling through green LEDs when BTN0 is pressed + // Cycling through green LEDs if (USE_GPIO_SHIFT_REG) { + // Feed value of BTN0 into the shift register set_outputs(GPIO_OUT_SHIFT, in_val); } else { + // Cycle through LEDs unless BTN0 is pressed uint32_t out_val = read_gpio(GPIO_OUT); - out_val = ((out_val << 1) & GPIO_OUT_MASK) | (in_val & 0x1); + out_val = (out_val << 1) & GPIO_LED_MASK; + if ((in_val & 0x1) || (out_val == 0)) { + out_val = 0x10; + } set_outputs(GPIO_OUT, out_val); }