update example

This commit is contained in:
hathach
2025-07-02 15:38:14 +07:00
parent 0388700ad7
commit a8b5e2bfc0
3 changed files with 21 additions and 11 deletions

View File

@@ -49,25 +49,28 @@ int main(void) {
while (1) { while (1) {
uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED; 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 // Blink and print every interval ms
if (!(board_millis() - start_ms < interval_ms)) { if (!(board_millis() - start_ms < interval_ms)) {
board_uart_write(HELLO_STR, strlen(HELLO_STR));
start_ms = board_millis(); 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); board_led_write(led_state);
led_state = 1 - led_state; // toggle 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) { void app_main(void) {
main(); main();
} }

View File

@@ -72,7 +72,10 @@ void tuh_cdc_rx_cb(uint8_t idx) {
if (count) { if (count) {
buf[count] = 0; buf[count] = 0;
printf("%s", (char*) buf); 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
} }
} }

View File

@@ -282,6 +282,10 @@ int board_getchar(void) {
return getchar_timeout_us(0); return getchar_timeout_us(0);
} }
void board_putchar(int c) {
stdio_putchar(c);
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// USB Interrupt Handler // USB Interrupt Handler
// rp2040 implementation will install appropriate handler when initializing // rp2040 implementation will install appropriate handler when initializing