From 9488f0633d6723a2414135b8968425350363e5db Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Thu, 16 Mar 2023 14:25:17 +0100 Subject: [PATCH] fw: Hide *led in led.c --- hw/application_fpga/fw/tk1/led.c | 8 +++++++- hw/application_fpga/fw/tk1/led.h | 3 +-- hw/application_fpga/fw/tk1/proto.c | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hw/application_fpga/fw/tk1/led.c b/hw/application_fpga/fw/tk1/led.c index 605c54a..5f2c5fb 100644 --- a/hw/application_fpga/fw/tk1/led.c +++ b/hw/application_fpga/fw/tk1/led.c @@ -7,9 +7,15 @@ #include "../tk1_mem.h" #include "types.h" +static volatile uint32_t *led = (volatile uint32_t *)TK1_MMIO_TK1_LED; + +void set_led(uint32_t led_value) +{ + *led = led_value; +} + void forever_redflash() { - static volatile uint32_t *led = (volatile uint32_t *)TK1_MMIO_TK1_LED; int led_on = 0; for (;;) { diff --git a/hw/application_fpga/fw/tk1/led.h b/hw/application_fpga/fw/tk1/led.h index eafb486..358690d 100644 --- a/hw/application_fpga/fw/tk1/led.h +++ b/hw/application_fpga/fw/tk1/led.h @@ -10,8 +10,6 @@ #include "types.h" // clang-format off -static volatile uint32_t *led = (volatile uint32_t *)TK1_MMIO_TK1_LED; - #define LED_BLACK 0 #define LED_RED (1 << TK1_MMIO_TK1_LED_R_BIT) #define LED_GREEN (1 << TK1_MMIO_TK1_LED_G_BIT) @@ -19,5 +17,6 @@ static volatile uint32_t *led = (volatile uint32_t *)TK1_MMIO_TK1_LED; #define LED_WHITE (LED_RED | LED_GREEN | LED_BLUE) // clang-format on +void set_led(uint32_t led_value); void forever_redflash(); #endif diff --git a/hw/application_fpga/fw/tk1/proto.c b/hw/application_fpga/fw/tk1/proto.c index 458ba0c..aa7c1c4 100644 --- a/hw/application_fpga/fw/tk1/proto.c +++ b/hw/application_fpga/fw/tk1/proto.c @@ -26,7 +26,7 @@ int readcommand(struct frame_header *hdr, uint8_t *cmd, int state) { uint8_t in = 0; - *led = (state == FW_STATE_LOADING) ? LED_BLACK : LED_WHITE; + set_led((state == FW_STATE_LOADING) ? LED_BLACK : LED_WHITE); in = readbyte(); if (parseframe(in, hdr) == -1) {