Skip to content

Commit

Permalink
Fix green LEDs in hello world demo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marnovandermaas committed Nov 2, 2023
1 parent 341bf7d commit 9f07bf5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion sw/c/common/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 9 additions & 4 deletions sw/c/demo/hello_world/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 9f07bf5

Please sign in to comment.