Skip to content

Commit cb82cbb

Browse files
committed
Apply clang-format
1 parent 994eda9 commit cb82cbb

2 files changed

Lines changed: 62 additions & 66 deletions

File tree

src/arduino/ports/stm32/Adafruit_TinyUSB_stm32.cpp

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,83 +22,79 @@
2222
* THE SOFTWARE.
2323
*/
2424

25-
#include "tusb_option.h"
25+
#include "tusb_option.h"
2626

27-
#if (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32)) && CFG_TUD_ENABLED
27+
#if (defined(ARDUINO_ARCH_STM32) || \
28+
defined(ARDUINO_ARCH_ARDUINO_CORE_STM32)) && \
29+
CFG_TUD_ENABLED
2830

2931
#define USE_HAL_DRIVER
30-
#include "stm32f4xx_hal.h"
31-
#include "stm32f4xx_hal_rcc.h"
3232
#include "Arduino.h"
3333
#include "arduino/Adafruit_TinyUSB_API.h"
34+
#include "stm32f4xx_hal.h"
35+
#include "stm32f4xx_hal_rcc.h"
3436
#include "tusb.h"
3537

3638
//--------------------------------------------------------------------+
3739
// Forward USB interrupt events to TinyUSB IRQ Handler
3840
//--------------------------------------------------------------------+
3941
extern "C" {
4042

41-
void OTG_FS_IRQHandler(void)
42-
{
43-
tud_int_handler(0);
44-
}
43+
void OTG_FS_IRQHandler(void) { tud_int_handler(0); }
4544

46-
void yield(void)
47-
{
48-
tud_task();
49-
if (tud_cdc_connected()) {
50-
tud_cdc_write_flush();
51-
}
45+
void yield(void) {
46+
tud_task();
47+
if (tud_cdc_connected()) {
48+
tud_cdc_write_flush();
49+
}
5250
}
5351

5452
} // extern "C"
5553

5654
//--------------------------------------------------------------------+
5755
// Porting API
5856
//--------------------------------------------------------------------+
59-
void TinyUSB_Port_InitDevice(uint8_t rhport)
60-
{
61-
(void) rhport;
62-
63-
// Enable clocks FIRST
64-
__HAL_RCC_GPIOA_CLK_ENABLE();
65-
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
66-
67-
// Configure USB pins (PA11 = DM, PA12 = DP)
68-
GPIO_InitTypeDef GPIO_InitStruct = {};
69-
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
70-
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
71-
GPIO_InitStruct.Pull = GPIO_NOPULL;
72-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
73-
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
74-
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
75-
76-
// Enable USB IRQ
77-
NVIC_SetPriority(OTG_FS_IRQn, 0);
78-
NVIC_EnableIRQ(OTG_FS_IRQn);
79-
80-
// Disable VBUS sensing (we're bus-powered, don't need it)
81-
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
82-
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
83-
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
84-
85-
// Initialize TinyUSB device stack
86-
tud_init(rhport);
87-
57+
void TinyUSB_Port_InitDevice(uint8_t rhport) {
58+
(void)rhport;
59+
60+
// Enable clocks FIRST
61+
__HAL_RCC_GPIOA_CLK_ENABLE();
62+
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
63+
64+
// Configure USB pins (PA11 = DM, PA12 = DP)
65+
GPIO_InitTypeDef GPIO_InitStruct = {};
66+
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
67+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
68+
GPIO_InitStruct.Pull = GPIO_NOPULL;
69+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
70+
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
71+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
72+
73+
// Enable USB IRQ
74+
NVIC_SetPriority(OTG_FS_IRQn, 0);
75+
NVIC_EnableIRQ(OTG_FS_IRQn);
76+
77+
// Disable VBUS sensing (we're bus-powered, don't need it)
78+
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
79+
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
80+
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
81+
82+
// Initialize TinyUSB device stack
83+
tud_init(rhport);
8884
}
8985

90-
void TinyUSB_Port_EnterDFU(void) {
91-
// Optional - implement bootloader entry if needed
86+
void TinyUSB_Port_EnterDFU(void) {
87+
// Optional - implement bootloader entry if needed
9288
}
9389

94-
uint8_t TinyUSB_Port_GetSerialNumber(uint8_t serial_id[16])
95-
{
96-
volatile uint32_t *uid = (volatile uint32_t *)0x1FFF7A10; // STM32F411 UID base
97-
uint32_t *serial_32 = (uint32_t *)serial_id;
98-
serial_32[0] = uid[0];
99-
serial_32[1] = uid[1];
100-
serial_32[2] = uid[2];
101-
return 12;
90+
uint8_t TinyUSB_Port_GetSerialNumber(uint8_t serial_id[16]) {
91+
volatile uint32_t *uid =
92+
(volatile uint32_t *)0x1FFF7A10; // STM32F411 UID base
93+
uint32_t *serial_32 = (uint32_t *)serial_id;
94+
serial_32[0] = uid[0];
95+
serial_32[1] = uid[1];
96+
serial_32[2] = uid[2];
97+
return 12;
10298
}
10399

104100
#endif // ARDUINO_ARCH_STM32

src/arduino/ports/stm32/tusb_config_stm32.h

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

2828
// USB Port
29-
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
29+
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
3030
#define CFG_TUSB_RHPORT0_SPEED OPT_FULL_SPEED
31-
#define CFG_TUSB_RHPORT1_MODE OPT_MODE_NONE
31+
#define CFG_TUSB_RHPORT1_MODE OPT_MODE_NONE
3232

3333
// MCU / OS
3434
#define CFG_TUSB_MCU OPT_MCU_STM32F4
35-
#define CFG_TUSB_OS OPT_OS_NONE
35+
#define CFG_TUSB_OS OPT_OS_NONE
3636

3737
// Debug
3838
#ifndef CFG_TUSB_DEBUG
@@ -43,26 +43,26 @@
4343
#define CFG_TUSB_MEM_ALIGN __attribute__((aligned(4)))
4444

4545
// Device stack
46-
#define CFG_TUD_ENABLED 1
46+
#define CFG_TUD_ENABLED 1
4747
#define CFG_TUD_ENDPOINT0_SIZE 64
4848

4949
// Classes
50-
#define CFG_TUD_CDC 1
51-
#define CFG_TUD_MSC 0
52-
#define CFG_TUD_HID 1
53-
#define CFG_TUD_MIDI 1
54-
#define CFG_TUD_VENDOR 0
50+
#define CFG_TUD_CDC 1
51+
#define CFG_TUD_MSC 0
52+
#define CFG_TUD_HID 1
53+
#define CFG_TUD_MIDI 1
54+
#define CFG_TUD_VENDOR 0
5555

5656
// Buffer sizes
57-
#define CFG_TUD_CDC_RX_BUFSIZE 64
58-
#define CFG_TUD_CDC_TX_BUFSIZE 64
59-
#define CFG_TUD_HID_EP_BUFSIZE 64
57+
#define CFG_TUD_CDC_RX_BUFSIZE 64
58+
#define CFG_TUD_CDC_TX_BUFSIZE 64
59+
#define CFG_TUD_HID_EP_BUFSIZE 64
6060
#define CFG_TUD_MIDI_RX_BUFSIZE 128
6161
#define CFG_TUD_MIDI_TX_BUFSIZE 128
6262
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
6363
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
6464

65-
//Serial Redirect
65+
// Serial Redirect
6666
#define Serial SerialTinyUSB
6767

6868
#endif

0 commit comments

Comments
 (0)