Select one of the symbols to view example projects that use it.
 
Outline
#define BOARD_API_H_
#include <stdint.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include "tusb.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#include "FreeRTOS.h"
#include "semphr.h"
#include "queue.h"
#include "task.h"
#include "timers.h"
#define CFG_BOARD_UART_BAUDRATE
board_init();
board_init_after_tusb();
board_reset_to_bootloader();
board_led_write(bool);
board_button_read();
board_get_unique_id(uint8_t *, size_t);
board_uart_read(uint8_t *, int);
board_uart_write(const void *, int);
#include "pico/time.h"
board_millis()
board_led_on()
board_led_off()
board_usb_get_serial(uint16_t *, size_t)
board_delay(uint32_t)
board_getchar();
Files
TinyUSB Library
hw
bsp
rp2040
src
PicoSDK
SourceVuRaspberry Pi Pico SDK and ExamplesTinyUSB Libraryhw/bsp/board_api.h
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * The MIT License (MIT) * * Copyright (c) 2019 Ha Thach (tinyusb.org) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * This file is part of the TinyUSB stack. *//* ... */ #ifndef BOARD_API_H_ #define BOARD_API_H_ #ifdef __cplusplus extern "C" { #endif #include <stdint.h> #include <inttypes.h> #include <stdbool.h> #include <string.h> #include "tusb.h" 5 includes #if CFG_TUSB_OS == OPT_OS_FREERTOS #if TUP_MCU_ESPRESSIF // ESP-IDF need "freertos/" prefix in include path. // CFG_TUSB_OS_INC_PATH should be defined accordingly. #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "freertos/queue.h" #include "freertos/task.h" #include "freertos/timers.h" 5 includes#else/* ... */ #include "FreeRTOS.h" #include "semphr.h" #include "queue.h" #include "task.h" #include "timers.h" /* ... */#endif/* ... */ #endif // Define the default baudrate #ifndef CFG_BOARD_UART_BAUDRATE #define CFG_BOARD_UART_BAUDRATE 115200 ///< Default baud rate #endif //--------------------------------------------------------------------+ // Board Porting API // For simplicity, only one LED and one Button are used //--------------------------------------------------------------------+ // Initialize on-board peripherals : led, button, uart and USB void board_init(void); // Init board after tinyusb is initialized void board_init_after_tusb(void) TU_ATTR_WEAK; // Jump to bootloader void board_reset_to_bootloader(void) TU_ATTR_WEAK; // Turn LED on or off void board_led_write(bool state); // Control led pattern using phase duration in ms. // For each phase, LED is toggle then repeated, board_led_task() is required to be called //void board_led_pattern(uint32_t const phase_ms[], uint8_t count); // Get the current state of button // a '1' means active (pressed), a '0' means inactive. 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); // Get characters from UART. Return number of read bytes int board_uart_read(uint8_t *buf, int len); // Send characters to UART. Return number of sent bytes int board_uart_write(void const *buf, int len); #if CFG_TUSB_OS == OPT_OS_NONE // Get current milliseconds, must be implemented when no RTOS is used uint32_t board_millis(void); /* ... */ #elif CFG_TUSB_OS == OPT_OS_FREERTOS static inline uint32_t board_millis(void) { return ( ( ((uint64_t) xTaskGetTickCount()) * 1000) / configTICK_RATE_HZ ); }board_millis (void) { ... } /* ... */ #elif CFG_TUSB_OS == OPT_OS_MYNEWT static inline uint32_t board_millis(void) { return os_time_ticks_to_ms32( os_time_get() ); }board_millis (void) { ... } /* ... */ #elif CFG_TUSB_OS == OPT_OS_PICO #include "pico/time.h" static inline uint32_t board_millis(void) { return to_ms_since_boot(get_absolute_time()); }{ ... } /* ... */#elif CFG_TUSB_OS == OPT_OS_RTTHREAD static inline uint32_t board_millis(void) { return (((uint64_t)rt_tick_get()) * 1000 / RT_TICK_PER_SECOND); }board_millis (void) { ... } /* ... */ #elif CFG_TUSB_OS == OPT_OS_CUSTOM // Implement your own board_millis() in any of .c file uint32_t board_millis(void); /* ... */ #else #error "board_millis() is not implemented for this OS" #endif //--------------------------------------------------------------------+ // Helper functions //--------------------------------------------------------------------+ static inline void board_led_on(void) { board_led_write(true); }{ ... } static inline void board_led_off(void) { board_led_write(false); }{ ... } // Get USB Serial number string from unique ID if available. Return number of character. // Input is string descriptor from index 1 (index 0 is type + len) static inline size_t board_usb_get_serial(uint16_t desc_str1[], size_t max_chars) { uint8_t uid[16] TU_ATTR_ALIGNED(4); 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)); }if (board_get_unique_id) { ... }else { // fixed serial string is 01234567889ABCDEF uint32_t* uid32 = (uint32_t*) (uintptr_t) uid; uid32[0] = 0x67452301; uid32[1] = 0xEFCDAB89; uid_len = 8; } if ( uid_len > max_chars / 2 ) uid_len = max_chars / 2; for ( size_t i = 0; i < uid_len; i++ ) { for ( size_t j = 0; j < 2; j++ ) { const char nibble_to_hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ...}; uint8_t const nibble = (uid[i] >> (j * 4)) & 0xf; desc_str1[i * 2 + (1 - j)] = nibble_to_hex[nibble]; // UTF-16-LE }for (size_t j = 0; j < 2; j++) { ... } }for (size_t i = 0; i < uid_len; i++) { ... } return 2 * uid_len; }{ ... } // TODO remove static inline void board_delay(uint32_t ms) { uint32_t start_ms = board_millis(); while ( board_millis() - start_ms < ms ) { // take chance to run usb background #if CFG_TUD_ENABLED tud_task(); #endif #if CFG_TUH_ENABLED tuh_task(); #endif }while (board_millis() - start_ms < ms) { ... } }{ ... } // stdio getchar() is blocking, this is non-blocking version int board_getchar(void); #ifdef __cplusplus }extern "C" { ... } #endif /* ... */ #endif
Details