summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorhathach <[email protected]>2021-07-02 14:10:31 +0700
committerhathach <[email protected]>2021-07-02 14:10:31 +0700
commit8de33ca557f4ce929fa7ec0d63382e3e8282558e (patch)
tree6ef349c4e7172a02b551db3bf94cdca77ec0f332 /hw
parentea9ec1fb43eec29c00611335ea1c0585074f2b1b (diff)
parent896388d79640e8d7719e158a9a31810a912bce1d (diff)
Merge branch 'master' into kkitayam-fix_rtt_for_rx_family
Diffstat (limited to 'hw')
-rw-r--r--hw/bsp/board.c57
-rw-r--r--hw/bsp/board.h9
2 files changed, 60 insertions, 6 deletions
diff --git a/hw/bsp/board.c b/hw/bsp/board.c
index 9dae8a04d..6a26f55b7 100644
--- a/hw/bsp/board.c
+++ b/hw/bsp/board.c
@@ -25,6 +25,59 @@
#include "board.h"
+#if 0
+#define LED_PHASE_MAX 8
+
+static struct
+{
+ uint32_t phase[LED_PHASE_MAX];
+ uint8_t phase_count;
+
+ bool led_state;
+ uint8_t current_phase;
+ uint32_t current_ms;
+}led_pattern;
+
+void board_led_pattern(uint32_t const phase_ms[], uint8_t count)
+{
+ memcpy(led_pattern.phase, phase_ms, 4*count);
+ led_pattern.phase_count = count;
+
+ // reset with 1st phase is on
+ led_pattern.current_ms = board_millis();
+ led_pattern.current_phase = 0;
+ led_pattern.led_state = true;
+ board_led_on();
+}
+
+void board_led_task(void)
+{
+ if ( led_pattern.phase_count == 0 ) return;
+
+ uint32_t const duration = led_pattern.phase[led_pattern.current_phase];
+
+ // return if not enough time
+ if (board_millis() - led_pattern.current_ms < duration) return;
+
+ led_pattern.led_state = !led_pattern.led_state;
+ board_led_write(led_pattern.led_state);
+
+ led_pattern.current_ms += duration;
+ led_pattern.current_phase++;
+
+ if (led_pattern.current_phase == led_pattern.phase_count)
+ {
+ led_pattern.current_phase = 0;
+ led_pattern.led_state = true;
+ board_led_on();
+ }
+}
+#endif
+
+//--------------------------------------------------------------------+
+// newlib read()/write() retarget
+//--------------------------------------------------------------------+
+
#if defined(__MSP430__) || defined(__RX__)
#define sys_write write
#define sys_read read
@@ -33,10 +86,6 @@
#define sys_read _read
#endif
-//--------------------------------------------------------------------+
-// newlib read()/write() retarget
-//--------------------------------------------------------------------+
-
#if defined(LOGGER_RTT)
// Logging with RTT
diff --git a/hw/bsp/board.h b/hw/bsp/board.h
index 7b77def50..782e0939c 100644
--- a/hw/bsp/board.h
+++ b/hw/bsp/board.h
@@ -54,6 +54,10 @@ void board_init(void);
// Turn LED on or off
void board_led_write(bool state);
+// Control led pattern using phase duration in ms.
+// For each phase, LED is toggle then repeated, board_led_task() is required to be called
+//void board_led_pattern(uint32_t const phase_ms[], uint8_t count);
+
// Get the current state of button
// a '1' means active (pressed), a '0' means inactive.
uint32_t board_button_read(void);
@@ -81,11 +85,12 @@ int board_uart_write(void const * buf, int len);
}
#elif CFG_TUSB_OS == OPT_OS_PICO
-#include "pico/time.h"
-static inline uint32_t board_millis(void)
+ #include "pico/time.h"
+ static inline uint32_t board_millis(void)
{
return to_ms_since_boot(get_absolute_time());
}
+
#elif CFG_TUSB_OS == OPT_OS_RTTHREAD
static inline uint32_t board_millis(void)
{