summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2025-09-27 20:38:03 +0700
committerGitHub <[email protected]>2025-09-27 20:38:03 +0700
commit152d25ed621393a991561b7de61c2f01bbadeb71 (patch)
tree7a75a0a3da032421907e26616f67f7f1d55b2d09 /hw
parent1f9c41566165b23ff573bf1b9bfd077cfbe9067f (diff)
parent0655f98359de7e9299d8047d94a1087bdd3618ac (diff)
Merge pull request #3256 from hathach/weak_cb
Migrate weak function override to new syntax, update delay api usage
Diffstat (limited to 'hw')
-rw-r--r--hw/bsp/board.c20
-rw-r--r--hw/bsp/board_api.h16
-rw-r--r--hw/bsp/espressif/boards/family.c8
-rw-r--r--hw/bsp/rp2040/family.c8
4 files changed, 40 insertions, 12 deletions
diff --git a/hw/bsp/board.c b/hw/bsp/board.c
index 1ba5a1b9d..e141664da 100644
--- a/hw/bsp/board.c
+++ b/hw/bsp/board.c
@@ -141,6 +141,26 @@ __strong_reference(stdin, stderr);
#endif
//--------------------------------------------------------------------+
+// Weak board API (to be optionally implemented by board)
+//--------------------------------------------------------------------+
+TU_ATTR_WEAK size_t board_get_unique_id(uint8_t id[], size_t max_len) {
+ (void) max_len;
+ // fixed serial string is 01234567889ABCDEF
+ uint32_t* uid32 = (uint32_t*) (uintptr_t)id;
+ uid32[0] = 0x67452301;
+ uid32[1] = 0xEFCDAB89;
+ return 8;
+}
+
+TU_ATTR_WEAK void board_init_after_tusb(void) {
+ // nothing to do
+}
+
+TU_ATTR_WEAK void board_reset_to_bootloader(void) {
+ // not implemented
+}
+
+//--------------------------------------------------------------------+
// Board API
//--------------------------------------------------------------------+
int board_getchar(void) {
diff --git a/hw/bsp/board_api.h b/hw/bsp/board_api.h
index 328fe9363..5ecd7797a 100644
--- a/hw/bsp/board_api.h
+++ b/hw/bsp/board_api.h
@@ -72,10 +72,10 @@ extern "C" {
void board_init(void);
// Init board after tinyusb is initialized
-void board_init_after_tusb(void) TU_ATTR_WEAK;
+void board_init_after_tusb(void);
// Jump to bootloader
-void board_reset_to_bootloader(void) TU_ATTR_WEAK;
+void board_reset_to_bootloader(void);
// Turn LED on or off
void board_led_write(bool state);
@@ -89,7 +89,7 @@ void board_led_write(bool state);
uint32_t board_button_read(void);
// Get board unique ID for USB serial number. Return number of bytes. Note max_len is typically 16
-TU_ATTR_WEAK size_t board_get_unique_id(uint8_t id[], size_t max_len);
+size_t board_get_unique_id(uint8_t id[], size_t max_len);
// Get characters from UART. Return number of read bytes
int board_uart_read(uint8_t *buf, int len);
@@ -152,15 +152,7 @@ static inline size_t board_usb_get_serial(uint16_t desc_str1[], size_t max_chars
size_t uid_len;
// TODO work with make, but not working with esp32s3 cmake
- if ( board_get_unique_id ) {
- uid_len = board_get_unique_id(uid, sizeof(uid));
- }else {
- // fixed serial string is 01234567889ABCDEF
- uint32_t* uid32 = (uint32_t*) (uintptr_t) uid;
- uid32[0] = 0x67452301;
- uid32[1] = 0xEFCDAB89;
- uid_len = 8;
- }
+ uid_len = board_get_unique_id(uid, sizeof(uid));
if ( uid_len > max_chars / 2 ) uid_len = max_chars / 2;
diff --git a/hw/bsp/espressif/boards/family.c b/hw/bsp/espressif/boards/family.c
index 28dd49143..a837417f4 100644
--- a/hw/bsp/espressif/boards/family.c
+++ b/hw/bsp/espressif/boards/family.c
@@ -160,6 +160,14 @@ void board_putchar(int c) {
putchar(c);
}
+void board_init_after_tusb(void) {
+ // nothing to do
+}
+
+void board_reset_to_bootloader(void) {
+ // not implemented
+}
+
//--------------------------------------------------------------------
// PHY Init
//--------------------------------------------------------------------
diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c
index a22924131..989140e02 100644
--- a/hw/bsp/rp2040/family.c
+++ b/hw/bsp/rp2040/family.c
@@ -286,6 +286,14 @@ void board_putchar(int c) {
stdio_putchar(c);
}
+void board_init_after_tusb(void) {
+ // nothing to do
+}
+
+void board_reset_to_bootloader(void) {
+ // not implemented
+}
+
//--------------------------------------------------------------------+
// USB Interrupt Handler
// rp2040 implementation will install appropriate handler when initializing