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

Skip to content

Commit aae3428

Browse files
committed
nrf/drivers/usb/usb_cdc.c: Code formatting.
1 parent ebe0e7a commit aae3428

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
< A349 /tr>
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ static volatile ringbuf_t tx_ringbuf;
5353

5454
static void board_init(void) {
5555
// Config clock source.
56-
#ifndef BLUETOOTH_SD
56+
#ifndef BLUETOOTH_SD
5757
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
5858
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
59-
#endif
59+
#endif
6060

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

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

@@ -77,14 +77,14 @@ static void board_init(void) {
7777

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

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

9090
nrfx_power_usbevt_enable();
@@ -96,48 +96,47 @@ static void board_init(void) {
9696
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_DETECTED);
9797
}
9898

99-
#ifndef BLUETOOTH_SD
99+
#ifndef BLUETOOTH_SD
100100
if (usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk) {
101101
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
102102
}
103-
#endif
103+
#endif
104104
}
105105

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

110110
static int cdc_rx_char(void) {
111-
return ringbuf_get((ringbuf_t*)&rx_ringbuf);
111+
return ringbuf_get((ringbuf_t *)&rx_ringbuf);
112112
}
113113

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

118118
static int cdc_tx_char(void) {
119-
return ringbuf_get((ringbuf_t*)&tx_ringbuf);
119+
return ringbuf_get((ringbuf_t *)&tx_ringbuf);
120120
}
121121

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

133132
int chars = 0;
134133
while (cdc_tx_any()) {
135134
if (chars < 64) {
136-
tud_cdc_write_char(cdc_tx_char());
137-
chars++;
135+
tud_cdc_write_char(cdc_tx_char());
136+
chars++;
138137
} else {
139-
chars = 0;
140-
tud_cdc_write_flush();
138+
chars = 0;
139+
tud_cdc_write_flush();
141140
}
142141
}
143142

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

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

158-
#if BLUETOOTH_SD
156+
#if BLUETOOTH_SD
159157
// Initialize the clock and BLE stack.
160158
ble_drv_stack_enable();
161-
#endif
159+
#endif
162160

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

190188
if (usbevt >= 0) {
191189
tusb_hal_nrf_power_event(usbevt);
@@ -227,7 +225,7 @@ int mp_hal_stdin_rx_chr(void) {
227225
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
228226

229227
for (const char *top = str + len; str < top; str++) {
230-
ringbuf_put((ringbuf_t*)&tx_ringbuf, *str);
228+
ringbuf_put((ringbuf_t *)&tx_ringbuf, *str);
231229
usb_cdc_loop();
232230
}
233231
}
@@ -236,10 +234,10 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
236234

237235
for (const char *top = str + len; str < top; str++) {
238236
if (*str == '\n') {
239-
ringbuf_put((ringbuf_t*)&tx_ringbuf, '\r');
237+
ringbuf_put((ringbuf_t *)&tx_ringbuf, '\r');
240238
usb_cdc_loop();
241239
}
242-
ringbuf_put((ringbuf_t*)&tx_ringbuf, *str);
240+
ringbuf_put((ringbuf_t *)&tx_ringbuf, *str);
243241
usb_cdc_loop();
244242
}
245243
}

0 commit comments

Comments
 (0)
0