Skip to content

Commit cea051f

Browse files
committed
clang
1 parent 0fe51fa commit cea051f

File tree

8 files changed

+184
-184
lines changed

8 files changed

+184
-184
lines changed

src/arduino/Adafruit_USBD_CDC.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,9 @@ Adafruit_USBD_CDC SerialTinyUSB;
4343
//------------- Static member -------------//
4444
uint8_t Adafruit_USBD_CDC::_instance_count = 0;
4545

46-
uint8_t Adafruit_USBD_CDC::getInstanceCount(void)
47-
{
48-
return _instance_count;
49-
}
46+
uint8_t Adafruit_USBD_CDC::getInstanceCount(void) { return _instance_count; }
5047

51-
Adafruit_USBD_CDC::Adafruit_USBD_CDC(void) {
52-
_instance = INVALID_INSTANCE;
53-
}
48+
Adafruit_USBD_CDC::Adafruit_USBD_CDC(void) { _instance = INVALID_INSTANCE; }
5449

5550
uint16_t Adafruit_USBD_CDC::getInterfaceDescriptor(uint8_t itfnum, uint8_t *buf,
5651
uint16_t bufsize) {

src/arduino/Adafruit_USBD_CDC.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,19 @@ class Adafruit_USBD_CDC : public Stream, public Adafruit_USBD_Interface {
7979

8080
uint8_t _instance;
8181

82-
bool isValid(void) {
83-
return _instance != INVALID_INSTANCE;
84-
}
82+
bool isValid(void) { return _instance != INVALID_INSTANCE; }
8583
};
8684

8785
// "Serial" is used with TinyUSB CDC
88-
#if defined(USE_TINYUSB) && !(defined(ARDUINO_ARCH_ESP32) && ARDUINO_SERIAL_PORT==0)
89-
extern Adafruit_USBD_CDC Serial;
90-
#define SerialTinyUSB Serial
86+
#if defined(USE_TINYUSB) && \
87+
!(defined(ARDUINO_ARCH_ESP32) && ARDUINO_SERIAL_PORT == 0)
88+
extern Adafruit_USBD_CDC Serial;
89+
#define SerialTinyUSB Serial
9190
#endif
9291

9392
// Serial is probably used with HW Uart
9493
#ifndef SerialTinyUSB
95-
extern Adafruit_USBD_CDC SerialTinyUSB;
94+
extern Adafruit_USBD_CDC SerialTinyUSB;
9695
#endif
9796

9897
#endif // __cplusplus

src/arduino/Adafruit_USBD_Device.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#define USB_CONFIG_POWER 100
5353
#endif
5454

55-
5655
enum { STRID_LANGUAGE = 0, STRID_MANUFACTURER, STRID_PRODUCT, STRID_SERIAL };
5756

5857
Adafruit_USBD_Device USBDevice;

src/arduino/ports/esp32/Adafruit_TinyUSB_esp32.cpp

Lines changed: 78 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,24 @@
2929
#include "sdkconfig.h"
3030

3131
#include "soc/soc.h"
32+
3233
#include "soc/efuse_reg.h"
34+
#include "soc/periph_defs.h"
3335
#include "soc/rtc_cntl_reg.h"
34-
#include "soc/usb_struct.h"
36+
37+
#include "soc/system_reg.h"
38+
#include "soc/timer_group_struct.h"
39+
#include "soc/usb_periph.h"
3540
#include "soc/usb_reg.h"
41+
#include "soc/usb_struct.h"
3642
#include "soc/usb_wrap_reg.h"
3743
#include "soc/usb_wrap_struct.h"
38-
#include "soc/usb_periph.h"
39-
#include "soc/periph_defs.h"
40-
#include "soc/timer_group_struct.h"
41-
#include "soc/system_reg.h"
4244

4345
#include "hal/usb_hal.h"
4446

4547
// compiler error with gpio_ll_get_drive_capability()
46-
// invalid conversion from 'uint32_t' {aka 'unsigned int'} to 'gpio_drive_cap_t' [-fpermissive]
47-
// #include "hal/gpio_ll.h"
48+
// invalid conversion from 'uint32_t' {aka 'unsigned int'} to 'gpio_drive_cap_t'
49+
// [-fpermissive] #include "hal/gpio_ll.h"
4850

4951
#include "freertos/FreeRTOS.h"
5052
#include "freertos/task.h"
@@ -58,9 +60,9 @@
5860

5961
#include "esp32-hal.h"
6062

61-
#include "esp32s2/rom/usb/usb_persist.h"
62-
#include "esp32s2/rom/usb/usb_dc.h"
6363
#include "esp32s2/rom/usb/chip_usb_dw_wrapper.h"
64+
#include "esp32s2/rom/usb/usb_dc.h"
65+
#include "esp32s2/rom/usb/usb_persist.h"
6466

6567
#include "arduino/Adafruit_TinyUSB_API.h"
6668
#include "arduino/Adafruit_USBD_Device.h"
@@ -69,67 +71,68 @@
6971
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
7072
//--------------------------------------------------------------------+
7173

72-
// Note: persist mode is mostly copied from esp32-hal-tinyusb.c from arduino-esp32 core.
74+
// Note: persist mode is mostly copied from esp32-hal-tinyusb.c from
75+
// arduino-esp32 core.
7376

7477
typedef enum {
75-
RESTART_NO_PERSIST,
76-
RESTART_PERSIST,
77-
RESTART_BOOTLOADER,
78-
RESTART_BOOTLOADER_DFU,
79-
RESTART_TYPE_MAX
78+
RESTART_NO_PERSIST,
79+
RESTART_PERSIST,
80+
RESTART_BOOTLOADER,
81+
RESTART_BOOTLOADER_DFU,
82+
RESTART_TYPE_MAX
8083
} restart_type_t;
8184

8285
static bool usb_persist_enabled = false;
8386
static restart_type_t usb_persist_mode = RESTART_NO_PERSIST;
8487

85-
static void IRAM_ATTR usb_persist_shutdown_handler(void)
86-
{
87-
if(usb_persist_mode != RESTART_NO_PERSIST){
88-
if (usb_persist_enabled) {
89-
usb_dc_prepare_persist();
90-
}
91-
if (usb_persist_mode == RESTART_BOOTLOADER) {
92-
//USB CDC Download
93-
if (usb_persist_enabled) {
94-
chip_usb_set_persist_flags(USBDC_PERSIST_ENA);
95-
} else {
96-
periph_module_reset(PERIPH_USB_MODULE);
97-
periph_module_enable(PERIPH_USB_MODULE);
98-
}
99-
REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
100-
} else if (usb_persist_mode == RESTART_BOOTLOADER_DFU) {
101-
//DFU Download
102-
chip_usb_set_persist_flags(USBDC_BOOT_DFU);
103-
REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
104-
} else if (usb_persist_enabled) {
105-
//USB Persist reboot
106-
chip_usb_set_persist_flags(USBDC_PERSIST_ENA);
107-
}
88+
static void IRAM_ATTR usb_persist_shutdown_handler(void) {
89+
if (usb_persist_mode != RESTART_NO_PERSIST) {
90+
if (usb_persist_enabled) {
91+
usb_dc_prepare_persist();
10892
}
93+
if (usb_persist_mode == RESTART_BOOTLOADER) {
94+
// USB CDC Download
95+
if (usb_persist_enabled) {
96+
chip_usb_set_persist_flags(USBDC_PERSIST_ENA);
97+
} else {
98+
periph_module_reset(PERIPH_USB_MODULE);
99+
periph_module_enable(PERIPH_USB_MODULE);
100+
}
101+
REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
102+
} else if (usb_persist_mode == RESTART_BOOTLOADER_DFU) {
103+
// DFU Download
104+
chip_usb_set_persist_flags(USBDC_BOOT_DFU);
105+
REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
106+
} else if (usb_persist_enabled) {
107+
// USB Persist reboot
108+
chip_usb_set_persist_flags(USBDC_PERSIST_ENA);
109+
}
110+
}
109111
}
110112

111-
static void configure_pins(usb_hal_context_t *usb)
112-
{
113-
for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin) {
114-
if ((usb->use_external_phy) || (iopin->ext_phy_only == 0)) {
115-
esp_rom_gpio_pad_select_gpio(iopin->pin);
116-
if (iopin->is_output) {
117-
esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false);
118-
} else {
119-
esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false);
120-
if ((iopin->pin != GPIO_FUNC_IN_LOW) && (iopin->pin != GPIO_FUNC_IN_HIGH)) {
121-
// workaround for compiler error with including "hal/gpio_ll.h"
122-
// gpio_ll_input_enable(&GPIO, (gpio_num_t) iopin->pin);
123-
PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[iopin->pin]);
124-
}
125-
}
126-
esp_rom_gpio_pad_unhold(iopin->pin);
113+
static void configure_pins(usb_hal_context_t *usb) {
114+
for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1;
115+
++iopin) {
116+
if ((usb->use_external_phy) || (iopin->ext_phy_only == 0)) {
117+
esp_rom_gpio_pad_select_gpio(iopin->pin);
118+
if (iopin->is_output) {
119+
esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false);
120+
} else {
121+
esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false);
122+
if ((iopin->pin != GPIO_FUNC_IN_LOW) &&
123+
(iopin->pin != GPIO_FUNC_IN_HIGH)) {
124+
// workaround for compiler error with including "hal/gpio_ll.h"
125+
// gpio_ll_input_enable(&GPIO, (gpio_num_t) iopin->pin);
126+
PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[iopin->pin]);
127127
}
128+
}
129+
esp_rom_gpio_pad_unhold(iopin->pin);
128130
}
129-
if (!usb->use_external_phy) {
130-
gpio_set_drive_capability((gpio_num_t) USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
131-
gpio_set_drive_capability((gpio_num_t) USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
132-
}
131+
}
132+
if (!usb->use_external_phy) {
133+
gpio_set_drive_capability((gpio_num_t)USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
134+
gpio_set_drive_capability((gpio_num_t)USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
135+
}
133136
}
134137

135138
//--------------------------------------------------------------------+
@@ -141,8 +144,11 @@ static void configure_pins(usb_hal_context_t *usb)
141144
// USB Device Driver task
142145
// This top level thread processes all usb events and invokes callbacks
143146
static void usb_device_task(void *param) {
144-
(void)param;
145-
while(1) tud_task(); // RTOS forever loop
147+
(void)param;
148+
// RTOS forever loop
149+
while (1) {
150+
tud_task();
151+
}
146152
}
147153

148154
void TinyUSB_Port_InitDevice(uint8_t rhport) {
@@ -151,29 +157,28 @@ void TinyUSB_Port_InitDevice(uint8_t rhport) {
151157
// from esp32-hal_tinyusb
152158
bool usb_did_persist = (USB_WRAP.date.val == USBDC_PERSIST_ENA);
153159

154-
//if(usb_did_persist && usb_persist_enabled){
160+
// if(usb_did_persist && usb_persist_enabled){
155161
// Enable USB/IO_MUX peripheral reset, if coming from persistent reboot
156162
REG_CLR_BIT(RTC_CNTL_USB_CONF_REG, RTC_CNTL_IO_MUX_RESET_DISABLE);
157163
REG_CLR_BIT(RTC_CNTL_USB_CONF_REG, RTC_CNTL_USB_RESET_DISABLE);
158164
//} else
159-
if(!usb_did_persist || !usb_persist_enabled){
165+
if (!usb_did_persist || !usb_persist_enabled) {
160166
// Reset USB module
161167
periph_module_reset(PERIPH_USB_MODULE);
162168
periph_module_enable(PERIPH_USB_MODULE);
163169
}
164170

165171
esp_register_shutdown_handler(usb_persist_shutdown_handler);
166172

167-
usb_hal_context_t hal = {
168-
.use_external_phy = false
169-
};
173+
usb_hal_context_t hal = {.use_external_phy = false};
170174
usb_hal_init(&hal);
171175
configure_pins(&hal);
172176

173177
tusb_init();
174178

175179
// Create a task for tinyusb device stack
176-
xTaskCreate(usb_device_task, "usbd", USBD_STACK_SZ, NULL, configMAX_PRIORITIES - 1, NULL);
180+
xTaskCreate(usb_device_task, "usbd", USBD_STACK_SZ, NULL,
181+
configMAX_PRIORITIES - 1, NULL);
177182
}
178183

179184
void TinyUSB_Port_EnterDFU(void) {
@@ -186,18 +191,20 @@ uint8_t TinyUSB_Port_GetSerialNumber(uint8_t serial_id[16]) {
186191
uint32_t *serial_32 = (uint32_t *)serial_id;
187192

188193
/* Get the MAC address */
189-
const uint32_t mac0 = __builtin_bswap32(REG_GET_FIELD(EFUSE_RD_MAC_SPI_SYS_0_REG, EFUSE_MAC_0));
190-
const uint16_t mac1 = __builtin_bswap16((uint16_t) REG_GET_FIELD(EFUSE_RD_MAC_SPI_SYS_1_REG, EFUSE_MAC_1));
194+
const uint32_t mac0 =
195+
__builtin_bswap32(REG_GET_FIELD(EFUSE_RD_MAC_SPI_SYS_0_REG, EFUSE_MAC_0));
196+
const uint16_t mac1 = __builtin_bswap16(
197+
(uint16_t)REG_GET_FIELD(EFUSE_RD_MAC_SPI_SYS_1_REG, EFUSE_MAC_1));
191198

192199
memcpy(serial_id, &mac1, 2);
193-
memcpy(serial_id+2, &mac0, 4);
200+
memcpy(serial_id + 2, &mac0, 4);
194201

195202
return 6;
196203
}
197204

198205
extern "C" void yield(void) {
199-
TinyUSB_Device_FlushCDC();
200-
vPortYield();
206+
TinyUSB_Device_FlushCDC();
207+
vPortYield();
201208
}
202209

203210
#endif // USE_TINYUSB

src/arduino/ports/esp32/tusb_config_esp32.h

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,61 +26,61 @@
2626
#define _TUSB_CONFIG_ESP32_H_
2727

2828
#ifdef __cplusplus
29-
extern "C" {
29+
extern "C" {
3030
#endif
3131

3232
//--------------------------------------------------------------------
3333
// COMMON CONFIGURATION
3434
//--------------------------------------------------------------------
35-
#define CFG_TUSB_MCU OPT_MCU_ESP32S2
35+
#define CFG_TUSB_MCU OPT_MCU_ESP32S2
3636

37-
//#ifdef USE_TINYUSB
38-
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
39-
//#else
40-
//#define CFG_TUSB_RHPORT0_MODE OPT_MODE_NONE
41-
//#endif
37+
#ifdef USE_TINYUSB
38+
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
39+
#else
40+
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_NONE
41+
#endif
4242

43-
#define CFG_TUSB_OS OPT_OS_FREERTOS
43+
#define CFG_TUSB_OS OPT_OS_FREERTOS
4444
#define CFG_TUSB_MEM_SECTION
45-
#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
45+
#define CFG_TUSB_MEM_ALIGN __attribute__((aligned(4)))
4646

4747
#ifndef CFG_TUSB_DEBUG
48-
#define CFG_TUSB_DEBUG 0
48+
#define CFG_TUSB_DEBUG 0
4949
#endif
5050

5151
//--------------------------------------------------------------------
5252
// DEVICE CONFIGURATION
5353
//--------------------------------------------------------------------
5454

55-
#define CFG_TUD_ENDOINT0_SIZE 64
55+
#define CFG_TUD_ENDOINT0_SIZE 64
5656

5757
//------------- CLASS -------------//
58-
#define CFG_TUD_CDC 1
59-
#define CFG_TUD_MSC 1
60-
#define CFG_TUD_HID 1
61-
#define CFG_TUD_MIDI 1
62-
#define CFG_TUD_VENDOR 1
58+
#define CFG_TUD_CDC 1
59+
#define CFG_TUD_MSC 1
60+
#define CFG_TUD_HID 1
61+
#define CFG_TUD_MIDI 1
62+
#define CFG_TUD_VENDOR 1
6363

6464
// CDC FIFO size of TX and RX
65-
#define CFG_TUD_CDC_RX_BUFSIZE 256
66-
#define CFG_TUD_CDC_TX_BUFSIZE 256
65+
#define CFG_TUD_CDC_RX_BUFSIZE 256
66+
#define CFG_TUD_CDC_TX_BUFSIZE 256
6767

6868
// MSC Buffer size of Device Mass storage
69-
#define CFG_TUD_MSC_BUFSIZE 512
69+
#define CFG_TUD_MSC_BUFSIZE 512
7070

7171
// HID buffer size Should be sufficient to hold ID (if any) + Data
72-
#define CFG_TUD_HID_BUFSIZE 64
72+
#define CFG_TUD_HID_BUFSIZE 64
7373

7474
// MIDI FIFO size of TX and RX
75-
#define CFG_TUD_MIDI_RX_BUFSIZE 128
76-
#define CFG_TUD_MIDI_TX_BUFSIZE 128
75+
#define CFG_TUD_MIDI_RX_BUFSIZE 128
76+
#define CFG_TUD_MIDI_TX_BUFSIZE 128
7777

7878
// Vendor FIFO size of TX and RX
79-
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
80-
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
79+
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
80+
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
8181

8282
#ifdef __cplusplus
83-
}
83+
}
8484
#endif
8585

8686
#endif /* _TUSB_CONFIG_ESP32_H_ */

0 commit comments

Comments
 (0)