Skip to content

Commit 8c0c211

Browse files
committed
Merge branch 'master' into fork/atoktoto/midihost
# Conflicts: # src/host/usbh.c
2 parents d132044 + 6bba410 commit 8c0c211

File tree

18 files changed

+381
-102
lines changed

18 files changed

+381
-102
lines changed

.idea/cmake.xml

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/host/cdc_msc_hid/src/hid_app.c

Lines changed: 32 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,16 @@
3939
static uint8_t const keycode2ascii[128][2] = { HID_KEYCODE_TO_ASCII };
4040

4141
// Each HID instance can has multiple reports
42-
static struct
43-
{
42+
static struct {
4443
uint8_t report_count;
4544
tuh_hid_report_info_t report_info[MAX_REPORT];
46-
}hid_info[CFG_TUH_HID];
45+
} hid_info[CFG_TUH_HID];
4746

4847
static void process_kbd_report(hid_keyboard_report_t const *report);
4948
static void process_mouse_report(hid_mouse_report_t const * report);
5049
static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
5150

52-
void hid_app_task(void)
53-
{
51+
void hid_app_task(void) {
5452
// nothing to do
5553
}
5654

@@ -63,64 +61,57 @@ void hid_app_task(void)
6361
// can be used to parse common/simple enough descriptor.
6462
// Note: if report descriptor length > CFG_TUH_ENUMERATION_BUFSIZE, it will be skipped
6563
// therefore report_desc = NULL, desc_len = 0
66-
void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len)
67-
{
64+
void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const *desc_report, uint16_t desc_len) {
6865
printf("HID device address = %d, instance = %d is mounted\r\n", dev_addr, instance);
6966

7067
// Interface protocol (hid_interface_protocol_enum_t)
71-
const char* protocol_str[] = { "None", "Keyboard", "Mouse" };
68+
const char *protocol_str[] = {"None", "Keyboard", "Mouse"};
7269
uint8_t const itf_protocol = tuh_hid_interface_protocol(dev_addr, instance);
7370

7471
printf("HID Interface Protocol = %s\r\n", protocol_str[itf_protocol]);
7572

7673
// By default host stack will use activate boot protocol on supported interface.
7774
// Therefore for this simple example, we only need to parse generic report descriptor (with built-in parser)
78-
if ( itf_protocol == HID_ITF_PROTOCOL_NONE )
79-
{
75+
if (itf_protocol == HID_ITF_PROTOCOL_NONE) {
8076
hid_info[instance].report_count = tuh_hid_parse_report_descriptor(hid_info[instance].report_info, MAX_REPORT, desc_report, desc_len);
8177
printf("HID has %u reports \r\n", hid_info[instance].report_count);
8278
}
8379

8480
// request to receive report
8581
// tuh_hid_report_received_cb() will be invoked when report is available
86-
if ( !tuh_hid_receive_report(dev_addr, instance) )
87-
{
82+
if (!tuh_hid_receive_report(dev_addr, instance)) {
8883
printf("Error: cannot request to receive report\r\n");
8984
}
9085
}
9186

9287
// Invoked when device with hid interface is un-mounted
93-
void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance)
94-
{
88+
void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance) {
9589
printf("HID device address = %d, instance = %d is unmounted\r\n", dev_addr, instance);
9690
}
9791

9892
// Invoked when received report from device via interrupt endpoint
99-
void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len)
100-
{
93+
void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t const *report, uint16_t len) {
10194
uint8_t const itf_protocol = tuh_hid_interface_protocol(dev_addr, instance);
10295

103-
switch (itf_protocol)
104-
{
96+
switch (itf_protocol) {
10597
case HID_ITF_PROTOCOL_KEYBOARD:
10698
TU_LOG2("HID receive boot keyboard report\r\n");
107-
process_kbd_report( (hid_keyboard_report_t const*) report );
108-
break;
99+
process_kbd_report((hid_keyboard_report_t const *) report);
100+
break;
109101

110102
case HID_ITF_PROTOCOL_MOUSE:
111103
TU_LOG2("HID receive boot mouse report\r\n");
112-
process_mouse_report( (hid_mouse_report_t const*) report );
113-
break;
104+
process_mouse_report((hid_mouse_report_t const *) report);
105+
break;
114106

115107
default:
116108
// Generic report requires matching ReportID and contents with previous parsed report info
117109
process_generic_report(dev_addr, instance, report, len);
118-
break;
110+
break;
119111
}
120112

121113
// continue to request to receive report
122-
if ( !tuh_hid_receive_report(dev_addr, instance) )
123-
{
114+
if (!tuh_hid_receive_report(dev_addr, instance)) {
124115
printf("Error: cannot request to receive report\r\n");
125116
}
126117
}
@@ -231,29 +222,24 @@ static void process_mouse_report(hid_mouse_report_t const * report)
231222
//--------------------------------------------------------------------+
232223
// Generic Report
233224
//--------------------------------------------------------------------+
234-
static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len)
235-
{
225+
static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t const *report, uint16_t len) {
236226
(void) dev_addr;
237227
(void) len;
238228

239229
uint8_t const rpt_count = hid_info[instance].report_count;
240-
tuh_hid_report_info_t* rpt_info_arr = hid_info[instance].report_info;
241-
tuh_hid_report_info_t* rpt_info = NULL;
230+
tuh_hid_report_info_t *rpt_info_arr = hid_info[instance].report_info;
231+
tuh_hid_report_info_t *rpt_info = NULL;
242232

243-
if ( rpt_count == 1 && rpt_info_arr[0].report_id == 0)
244-
{
233+
if (rpt_count == 1 && rpt_info_arr[0].report_id == 0) {
245234
// Simple report without report ID as 1st byte
246235
rpt_info = &rpt_info_arr[0];
247-
}else
248-
{
236+
} else {
249237
// Composite report, 1st byte is report ID, data starts from 2nd byte
250238
uint8_t const rpt_id = report[0];
251239

252240
// Find report id in the array
253-
for(uint8_t i=0; i<rpt_count; i++)
254-
{
255-
if (rpt_id == rpt_info_arr[i].report_id )
256-
{
241+
for (uint8_t i = 0; i < rpt_count; i++) {
242+
if (rpt_id == rpt_info_arr[i].report_id) {
257243
rpt_info = &rpt_info_arr[i];
258244
break;
259245
}
@@ -263,8 +249,7 @@ static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t c
263249
len--;
264250
}
265251

266-
if (!rpt_info)
267-
{
252+
if (!rpt_info) {
268253
printf("Couldn't find report info !\r\n");
269254
return;
270255
}
@@ -276,23 +261,22 @@ static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t c
276261
// - Consumer Control (Media Key) : Consumer, Consumer Control
277262
// - System Control (Power key) : Desktop, System Control
278263
// - Generic (vendor) : 0xFFxx, xx
279-
if ( rpt_info->usage_page == HID_USAGE_PAGE_DESKTOP )
280-
{
281-
switch (rpt_info->usage)
282-
{
264+
if (rpt_info->usage_page == HID_USAGE_PAGE_DESKTOP) {
265+
switch (rpt_info->usage) {
283266
case HID_USAGE_DESKTOP_KEYBOARD:
284267
TU_LOG1("HID receive keyboard report\r\n");
285268
// Assume keyboard follow boot report layout
286-
process_kbd_report( (hid_keyboard_report_t const*) report );
287-
break;
269+
process_kbd_report((hid_keyboard_report_t const *) report);
270+
break;
288271

289272
case HID_USAGE_DESKTOP_MOUSE:
290273
TU_LOG1("HID receive mouse report\r\n");
291274
// Assume mouse follow boot report layout
292-
process_mouse_report( (hid_mouse_report_t const*) report );
293-
break;
275+
process_mouse_report((hid_mouse_report_t const *) report);
276+
break;
294277

295-
default: break;
278+
default:
279+
break;
296280
}
297281
}
298282
}

hw/bsp/espressif/boards/family.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ int board_getchar(void) {
162162
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
163163

164164
#include "esp_private/usb_phy.h"
165-
#include "soc/usb_pins.h"
166165

167166
static usb_phy_handle_t phy_hdl;
168167

hw/bsp/rp2040/boards/adafruit_feather_rp2040_usb_host/board.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
* This file is part of the TinyUSB stack.
2525
*/
2626

27+
/* metadata:
28+
name: Adafruit Feather RP2040 with USB Type A Host
29+
url: https://www.adafruit.com/product/5723
30+
*/
31+
2732
#ifndef TUSB_BOARD_H
2833
#define TUSB_BOARD_H
2934

hw/bsp/rp2040/boards/adafruit_fruit_jam/board.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
* This file is part of the TinyUSB stack.
2525
*/
2626

27+
/* metadata:
28+
name: Adafruit Fruit Jam - Mini RP2350
29+
url: https://www.adafruit.com/product/6200
30+
*/
31+
2732
#ifndef TUSB_BOARD_H
2833
#define TUSB_BOARD_H
2934

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2025 Ha Thach (tinyusb.org)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
* This file is part of the TinyUSB stack.
25+
*/
26+
#ifndef BOARDS_ADAFRUIT_METRO_RP2350_H
27+
#define BOARDS_ADAFRUIT_METRO_RP2350_H
28+
29+
// required for board that is not part of pico-sdk
30+
31+
// -----------------------------------------------------
32+
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
33+
// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
34+
// -----------------------------------------------------
35+
36+
// pico_cmake_set PICO_PLATFORM=rp2350
37+
38+
// On some samples, the xosc can take longer to stabilize than is usual
39+
#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER
40+
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64
41+
#endif
42+
43+
// For board detection
44+
#define ADAFRUIT_METRO_RP2350
45+
46+
// --- RP2350 VARIANT ---
47+
#define PICO_RP2350A 0
48+
49+
// --- UART ---
50+
#ifndef PICO_DEFAULT_UART
51+
#define PICO_DEFAULT_UART 0
52+
#endif
53+
#ifndef PICO_DEFAULT_UART_TX_PIN
54+
#define PICO_DEFAULT_UART_TX_PIN 0
55+
#endif
56+
#ifndef PICO_DEFAULT_UART_RX_PIN
57+
#define PICO_DEFAULT_UART_RX_PIN 1
58+
#endif
59+
60+
// --- LED ---
61+
#ifndef PICO_DEFAULT_LED_PIN
62+
#define PICO_DEFAULT_LED_PIN 23
63+
#endif
64+
65+
#ifndef PICO_DEFAULT_WS2812_PIN
66+
#define PICO_DEFAULT_WS2812_PIN 25
67+
#endif
68+
69+
// --- I2C ---
70+
#ifndef PICO_DEFAULT_I2C
71+
#define PICO_DEFAULT_I2C 0
72+
#endif
73+
#ifndef PICO_DEFAULT_I2C_SDA_PIN
74+
#define PICO_DEFAULT_I2C_SDA_PIN 20
75+
#endif
76+
#ifndef PICO_DEFAULT_I2C_SCL_PIN
77+
#define PICO_DEFAULT_I2C_SCL_PIN 21
78+
#endif
79+
80+
// --- SPI ---
81+
#ifndef PICO_DEFAULT_SPI
82+
#define PICO_DEFAULT_SPI 1
83+
#endif
84+
#ifndef PICO_DEFAULT_SPI_SCK_PIN
85+
#define PICO_DEFAULT_SPI_SCK_PIN 30
86+
#endif
87+
#ifndef PICO_DEFAULT_SPI_TX_PIN
88+
#define PICO_DEFAULT_SPI_TX_PIN 31
89+
#endif
90+
#ifndef PICO_DEFAULT_SPI_RX_PIN
91+
#define PICO_DEFAULT_SPI_RX_PIN 28
92+
#endif
93+
94+
// --- FLASH ---
95+
96+
// FruitJam use w25q128 but sdk does not have .s for it, use q080 instead
97+
#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1
98+
99+
#ifndef PICO_FLASH_SPI_CLKDIV
100+
#define PICO_FLASH_SPI_CLKDIV 2
101+
#endif
102+
103+
// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024)
104+
#ifndef PICO_FLASH_SIZE_BYTES
105+
#define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024)
106+
#endif
107+
108+
// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1
109+
#ifndef PICO_RP2350_A2_SUPPORTED
110+
#define PICO_RP2350_A2_SUPPORTED 1
111+
#endif
112+
113+
#endif
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(PICO_PLATFORM rp2350-arm-s)
2+
set(PICO_BOARD adafruit_metro_rp2350)
3+
set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR})
4+
#set(OPENOCD_SERIAL E6614103E78E8324)

0 commit comments

Comments
 (0)