summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-07-02 15:38:14 +0700
committerhathach <[email protected]>2025-07-02 15:38:14 +0700
commita8b5e2bfc0a2d35ba775f7b2de81d531ed525e41 (patch)
tree98007b91887c7ef9e3745c893d7607ecb7a2fe6e
parent0388700ad7c0fc8565457a56d7e7bd5744ac0d1d (diff)
update example
-rw-r--r--examples/device/board_test/src/main.c21
-rw-r--r--examples/host/cdc_msc_hid/src/cdc_app.c5
-rw-r--r--hw/bsp/rp2040/family.c6
3 files changed, 21 insertions, 11 deletions
diff --git a/examples/device/board_test/src/main.c b/examples/device/board_test/src/main.c
index 2269d45f1..2c6ab6288 100644
--- a/examples/device/board_test/src/main.c
+++ b/examples/device/board_test/src/main.c
@@ -49,25 +49,28 @@ int main(void) {
while (1) {
uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED;
+ int ch = board_getchar();
+ if (ch > 0) {
+ board_putchar(ch);
+ }
+
// Blink and print every interval ms
if (!(board_millis() - start_ms < interval_ms)) {
- board_uart_write(HELLO_STR, strlen(HELLO_STR));
-
start_ms = board_millis();
+ if (ch < 0) {
+ // skip if echoing
+ printf(HELLO_STR);
+ board_uart_write(HELLO_STR, strlen(HELLO_STR));
+ }
+
board_led_write(led_state);
led_state = 1 - led_state; // toggle
}
-
- // echo
- uint8_t ch;
- if (board_uart_read(&ch, 1) > 0) {
- board_uart_write(&ch, 1);
- }
}
}
-#if TUSB_MCU_VENDOR_ESPRESSIF
+#ifdef ESP_PLATFORM
void app_main(void) {
main();
}
diff --git a/examples/host/cdc_msc_hid/src/cdc_app.c b/examples/host/cdc_msc_hid/src/cdc_app.c
index 2fa9a8560..97f1a96d6 100644
--- a/examples/host/cdc_msc_hid/src/cdc_app.c
+++ b/examples/host/cdc_msc_hid/src/cdc_app.c
@@ -72,7 +72,10 @@ void tuh_cdc_rx_cb(uint8_t idx) {
if (count) {
buf[count] = 0;
printf("%s", (char*) buf);
- fflush(stdout);
+
+ #ifndef __ICCARM__ // TODO IAR doesn't support stream control ?
+ fflush(stdout);// flush right away, else nanolib will wait for newline
+ #endif
}
}
diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c
index 8c85c5cc8..a22924131 100644
--- a/hw/bsp/rp2040/family.c
+++ b/hw/bsp/rp2040/family.c
@@ -254,7 +254,7 @@ size_t board_get_unique_id(uint8_t id[], size_t max_len) {
int board_uart_read(uint8_t *buf, int len) {
#ifdef UART_DEV
int count = 0;
- while ( (count < len) && uart_is_readable(uart_inst) ) {
+ while ((count < len) && uart_is_readable(uart_inst)) {
buf[count] = uart_getc(uart_inst);
count++;
}
@@ -282,6 +282,10 @@ int board_getchar(void) {
return getchar_timeout_us(0);
}
+void board_putchar(int c) {
+ stdio_putchar(c);
+}
+
//--------------------------------------------------------------------+
// USB Interrupt Handler
// rp2040 implementation will install appropriate handler when initializing