8000 nrf/drivers/usb/usb_cdc.c: Code formatting. · micropython/micropython@3e79bad · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e79bad

Browse files
committed
nrf/drivers/usb/usb_cdc.c: Code formatting.
1 parent aa6ac60 commit 3e79bad

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

ports/nrf/drivers/usb/usb_cdc.c

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ static volatile ringbuf_t tx_ringbuf;
5454

5555
static void board_init(void) {
5656
// Config clock source.
57-
#ifndef BLUETOOTH_SD
57+
#ifndef BLUETOOTH_SD
5858
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
5959
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
60-
#endif
60+
#endif
6161

6262
// Priorities 0, 1, 4 (nRF52) are reserved for SoftDevice
6363
// 2 is highest for application
@@ -67,7 +67,7 @@ static void board_init(void) {
6767
// We need to invoke the handler based on the status initially
6868
uint32_t usb_reg;
6969

70-
#ifdef BLUETOOTH_SD
70+
#ifdef BLUETOOTH_SD
7171
uint8_t sd_en = false;
7272
sd_softdevice_is_enabled(&sd_en);
7373

@@ -78,14 +78,14 @@ static void board_init(void) {
7878

7979
sd_power_usbregstatus_get(&usb_reg);
8080
} else
81-
#endif
81+
#endif
8282
{
8383
// Power module init
8484
const nrfx_power_config_t pwr_cfg = { 0 };
8585
nrfx_power_init(&pwr_cfg);
8686

8787
// Register tusb function as USB power handler
88-
const nrfx_power_usbevt_config_t config = { .handler = (nrfx_power_usb_event_handler_t) tusb_hal_nrf_power_event };
88+
const nrfx_power_usbevt_config_t config = { .handler = (nrfx_power_usb_event_handler_t)tusb_hal_nrf_power_event };
8989
nrfx_power_usbevt_init(&config);
9090

9191
nrfx_power_usbevt_enable();
@@ -97,48 +97,47 @@ static void board_init(void) {
9797
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_DETECTED);
9898
}
9999

100-
#ifndef BLUETOOTH_SD
100+
#ifndef BLUETOOTH_SD
101101
if (usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk) {
102102
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
103103
}
104-
#endif
104+
#endif
105105
}
106106

107107
static bool cdc_rx_any(void) {
108108
return rx_ringbuf.iput != rx_ringbuf.iget;
109109
}
110110

111111
static int cdc_rx_char(void) {
112-
return ringbuf_get((ringbuf_t*)&rx_ringbuf);
112+
return ringbuf_get((ringbuf_t *)&rx_ringbuf);
113113
}
114114

115115
static bool cdc_tx_any(void) {
116116
return tx_ringbuf.iput != tx_ringbuf.iget;
117117
}
118118

119119
static int cdc_tx_char(void) {
120-
return ringbuf_get((ringbuf_t*)&tx_ringbuf);
120+
return ringbuf_get((ringbuf_t *)&tx_ringbuf);
121121
}
122122

123-
static void cdc_task(void)
124-
{
125-
if ( tud_cdc_connected() ) {
123+
static void cdc_task(void) {
124+
if (tud_cdc_connected()) {
126125
// connected and there are data available
127126
while (tud_cdc_available()) {
128127
int c;
129128
uint32_t count = tud_cdc_read(&c, 1);
130129
(void)count;
131-
ringbuf_put((ringbuf_t*)&rx_ringbuf, c);
130+
ringbuf_put((ringbuf_t *)&rx_ringbuf, c);
132131
}
133132

134133
int chars = 0;
135134
while (cdc_tx_any()) {
136135
if (chars < 64) {
137-
tud_cdc_write_char(cdc_tx_char());
138-
chars++;
136+
tud_cdc_write_char(cdc_tx_char());
137+
chars++;
139138
} else {
140-
chars = 0;
141-
tud_cdc_write_flush();
139+
chars = 0;
140+
tud_cdc_write_flush();
142141
}
143142
}
144143

@@ -151,15 +150,14 @@ static void usb_cdc_loop(void) {
151150
cdc_task();
152151
}
153152

154-
int usb_cdc_init(void)
155-
{
153+
int usb_cdc_init(void) {
156154
static bool initialized = false;
157155
if (!initialized) {
158156

159-
#if BLUETOOTH_SD
157+
#if BLUETOOTH_SD
160158
// Initialize the clock and BLE stack.
161159
ble_drv_stack_enable();
162-
#endif
160+
#endif
163161

164162
board_init();
165163
initialized = true;
@@ -184,9 +182,9 @@ int usb_cdc_init(void)
184182
// process SOC event from SD
185183
void usb_cdc_sd_event_handler(uint32_t soc_evt) {
186184
/*------------- usb power event handler -------------*/
187-
int32_t usbevt = (soc_evt == NRF_EVT_POWER_USB_DETECTED ) ? NRFX_POWER_USB_EVT_DETECTED:
188-
(soc_evt == NRF_EVT_POWER_USB_POWER_READY) ? NRFX_POWER_USB_EVT_READY :
189-
(soc_evt == NRF_EVT_POWER_USB_REMOVED ) ? NRFX_POWER_USB_EVT_REMOVED : -1;
185+
int32_t usbevt = (soc_evt == NRF_EVT_POWER_USB_DETECTED) ? NRFX_POWER_USB_EVT_DETECTED:
186+
(soc_evt == NRF_EVT_POWER_USB_POWER_READY) ? NRFX_POWER_USB_EVT_READY :
187+
(soc_evt == NRF_EVT_POWER_USB_REMOVED) ? NRFX_POWER_USB_EVT_REMOVED : -1;
190188

191189
if (usbevt >= 0) {
192190
tusb_hal_nrf_power_event(usbevt);
@@ -239,7 +237,7 @@ int mp_hal_stdin_rx_chr(void) {
239237
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
240238

241239
for (const char *top = str + len; str < top; str++) {
242-
ringbuf_put((ringbuf_t*)&tx_ringbuf, *str);
240+
ringbuf_put((ringbuf_t *)&tx_ringbuf, *str);
243241
usb_cdc_loop();
244242
}
245243
}
@@ -248,10 +246,10 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
248246

249247
for (const char *top = str + len; str < top; str++) {
250248
if (*str == '\n') {
251-
ringbuf_put((ringbuf_t*)&tx_ringbuf, '\r');
249+
ringbuf_put((ringbuf_t *)&tx_ringbuf, '\r');
252250
usb_cdc_loop();
253251
}
254-
ringbuf_put((ringbuf_t*)&tx_ringbuf, *str);
252+
ringbuf_put((ringbuf_t *)&tx_ringbuf, *str);
255253
usb_cdc_loop();
256254
}
257255
}

0 commit comments

Comments
 (0)
0