summaryrefslogtreecommitdiff
path: root/examples/device/board_test/src/main.c
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2024-04-01 12:35:57 +0200
committerHiFiPhile <[email protected]>2024-04-01 12:35:57 +0200
commita1f01fcbe0fecb8d1783a105d7f22cba032dfced (patch)
treec8174923ef0bdd1016f55ed731df4c2df3257940 /examples/device/board_test/src/main.c
parentdd0350f5499de586a3405fdcec632f059fd7534e (diff)
parent82dfe95655c7b7564363a2d5cb2f5e32d431b223 (diff)
Merge remote-tracking branch 'upstream/master' into pr/1702
Diffstat (limited to 'examples/device/board_test/src/main.c')
-rw-r--r--examples/device/board_test/src/main.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/examples/device/board_test/src/main.c b/examples/device/board_test/src/main.c
index 5e28cbb27..91799eb89 100644
--- a/examples/device/board_test/src/main.c
+++ b/examples/device/board_test/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -26,39 +26,31 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-
-#include "bsp/board.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF PROTYPES
-//--------------------------------------------------------------------+
+#include "bsp/board_api.h"
/* Blink pattern
* - 250 ms : button is not pressed
* - 1000 ms : button is pressed (and hold)
*/
-enum {
+enum {
BLINK_PRESSED = 250,
BLINK_UNPRESSED = 1000
};
#define HELLO_STR "Hello from TinyUSB\r\n"
-int main(void)
-{
+int main(void) {
board_init();
board_led_write(true);
uint32_t start_ms = 0;
bool led_state = false;
- while (1)
- {
+ while (1) {
uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED;
- // Blink every interval ms
- if ( !(board_millis() - start_ms < interval_ms) )
- {
+ // 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();
@@ -66,14 +58,17 @@ int main(void)
board_led_write(led_state);
led_state = 1 - led_state; // toggle
}
- }
- return 0;
+ // echo
+ uint8_t ch;
+ if (board_uart_read(&ch, 1) > 0) {
+ board_uart_write(&ch, 1);
+ }
+ }
}
#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
-void app_main(void)
-{
+void app_main(void) {
main();
}
#endif