Skip to content

Commit a8b5e2b

Browse files
committed
update example
1 parent 0388700 commit a8b5e2b

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

examples/device/board_test/src/main.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,28 @@ int main(void) {
4949
while (1) {
5050
uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED;
5151

52+
int ch = board_getchar();
53+
if (ch > 0) {
54+
board_putchar(ch);
55+
}
56+
5257
// Blink and print every interval ms
5358
if (!(board_millis() - start_ms < interval_ms)) {
54-
board_uart_write(HELLO_STR, strlen(HELLO_STR));
55-
5659
start_ms = board_millis();
5760

61+
if (ch < 0) {
62+
// skip if echoing
63+
printf(HELLO_STR);
64+
board_uart_write(HELLO_STR, strlen(HELLO_STR));
65+
}
66+
5867
board_led_write(led_state);
5968
led_state = 1 - led_state; // toggle
6069
}
61-
62-
// echo
63-
uint8_t ch;
64-
if (board_uart_read(&ch, 1) > 0) {
65-
board_uart_write(&ch, 1);
66-
}
6770
}
6871
}
6972

70-
#if TUSB_MCU_VENDOR_ESPRESSIF
73+
#ifdef ESP_PLATFORM
7174
void app_main(void) {
7275
main();
7376
}

examples/host/cdc_msc_hid/src/cdc_app.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ void tuh_cdc_rx_cb(uint8_t idx) {
7272
if (count) {
7373
buf[count] = 0;
7474
printf("%s", (char*) buf);
75-
fflush(stdout);
75+
76+
#ifndef __ICCARM__ // TODO IAR doesn't support stream control ?
77+
fflush(stdout);// flush right away, else nanolib will wait for newline
78+
#endif
7679
}
7780
}
7881

hw/bsp/rp2040/family.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ size_t board_get_unique_id(uint8_t id[], size_t max_len) {
254254
int board_uart_read(uint8_t *buf, int len) {
255255
#ifdef UART_DEV
256256
int count = 0;
257-
while ( (count < len) && uart_is_readable(uart_inst) ) {
257+
while ((count < len) && uart_is_readable(uart_inst)) {
258258
buf[count] = uart_getc(uart_inst);
259259
count++;
260260
}
@@ -282,6 +282,10 @@ int board_getchar(void) {
282282
return getchar_timeout_us(0);
283283
}
284284

285+
void board_putchar(int c) {
286+
stdio_putchar(c);
287+
}
288+
285289
//--------------------------------------------------------------------+
286290
// USB Interrupt Handler
287291
// rp2040 implementation will install appropriate handler when initializing

0 commit comments

Comments
 (0)