@@ -54,10 +54,10 @@ static volatile ringbuf_t tx_ringbuf;
54
54
55
55
static void board_init (void ) {
56
56
// Config clock source.
57
- #ifndef BLUETOOTH_SD
57
+ #ifndef BLUETOOTH_SD
58
58
NRF_CLOCK -> LFCLKSRC = (uint32_t )((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos ) & CLOCK_LFCLKSRC_SRC_Msk );
59
59
NRF_CLOCK -> TASKS_LFCLKSTART = 1UL ;
60
- #endif
60
+ #endif
61
61
62
62
// Priorities 0, 1, 4 (nRF52) are reserved for SoftDevice
63
63
// 2 is highest for application
@@ -67,7 +67,7 @@ static void board_init(void) {
67
67
// We need to invoke the handler based on the status initially
68
68
uint32_t usb_reg ;
69
69
70
- #ifdef BLUETOOTH_SD
70
+ #ifdef BLUETOOTH_SD
71
71
uint8_t sd_en = false;
72
72
sd_softdevice_is_enabled (& sd_en );
73
73
@@ -78,14 +78,14 @@ static void board_init(void) {
78
78
79
79
sd_power_usbregstatus_get (& usb_reg );
80
80
} else
81
- #endif
81
+ #endif
82
82
{
83
83
// Power module init
84
84
const nrfx_power_config_t pwr_cfg = { 0 };
85
85
nrfx_power_init (& pwr_cfg );
86
86
87
87
// 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 };
89
89
nrfx_power_usbevt_init (& config );
90
90
91
91
nrfx_power_usbevt_enable ();
@@ -97,48 +97,47 @@ static void board_init(void) {
97
97
tusb_hal_nrf_power_event (NRFX_POWER_USB_EVT_DETECTED );
98
98
}
99
99
100
- #ifndef BLUETOOTH_SD
100
+ #ifndef BLUETOOTH_SD
101
101
if (usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk ) {
102
102
tusb_hal_nrf_power_event (NRFX_POWER_USB_EVT_READY );
103
103
}
104
- #endif
104
+ #endif
105
105
}
106
106
107
107
static bool cdc_rx_any (void ) {
108
108
return rx_ringbuf .iput != rx_ringbuf .iget ;
109
109
}
110
110
111
111
static int cdc_rx_char (void ) {
112
- return ringbuf_get ((ringbuf_t * )& rx_ringbuf );
112
+ return ringbuf_get ((ringbuf_t * )& rx_ringbuf );
113
113
}
114
114
115
115
static bool cdc_tx_any (void ) {
116
116
return tx_ringbuf .iput != tx_ringbuf .iget ;
117
117
}
118
118
119
119
static int cdc_tx_char (void ) {
120
- return ringbuf_get ((ringbuf_t * )& tx_ringbuf );
120
+ return ringbuf_get ((ringbuf_t * )& tx_ringbuf );
121
121
}
122
122
123
- static void cdc_task (void )
124
- {
125
- if ( tud_cdc_connected () ) {
123
+ static void cdc_task (void ) {
124
+ if (tud_cdc_connected ()) {
126
125
// connected and there are data available
127
126
while (tud_cdc_available ()) {
128
127
int c ;
129
128
uint32_t count = tud_cdc_read (& c , 1 );
130
129
(void )count ;
131
- ringbuf_put ((ringbuf_t * )& rx_ringbuf , c );
130
+ ringbuf_put ((ringbuf_t * )& rx_ringbuf , c );
132
131
}
133
132
134
133
int chars = 0 ;
135
134
while (cdc_tx_any ()) {
136
135
if (chars < 64 ) {
137
- tud_cdc_write_char (cdc_tx_char ());
138
- chars ++ ;
136
+ tud_cdc_write_char (cdc_tx_char ());
137
+ chars ++ ;
139
138
} else {
140
- chars = 0 ;
141
- tud_cdc_write_flush ();
139
+ chars = 0 ;
140
+ tud_cdc_write_flush ();
142
141
}
143
142
}
144
143
@@ -151,15 +150,14 @@ static void usb_cdc_loop(void) {
151
150
cdc_task ();
152
151
}
153
152
154
- int usb_cdc_init (void )
155
- {
153
+ int usb_cdc_init (void ) {
156
154
static bool initialized = false;
157
155
if (!initialized ) {
158
156
159
- #if BLUETOOTH_SD
157
+ #if BLUETOOTH_SD
160
158
// Initialize the clock and BLE stack.
161
159
ble_drv_stack_enable ();
162
- #endif
160
+ #endif
163
161
164
162
board_init ();
165
163
initialized = true;
@@ -184,9 +182,9 @@ int usb_cdc_init(void)
184
182
// process SOC event from SD
185
183
void usb_cdc_sd_event_handler (uint32_t soc_evt ) {
186
184
/*------------- 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 ;
190
188
191
189
if (usbevt >= 0 ) {
192
190
tusb_hal_nrf_power_event (usbevt );
@@ -239,7 +237,7 @@ int mp_hal_stdin_rx_chr(void) {
239
237
void mp_hal_stdout_tx_strn (const char * str , mp_uint_t len ) {
240
238
241
239
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 );
243
241
usb_cdc_loop ();
244
242
}
245
243
}
@@ -248,10 +246,10 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
248
246
249
247
for (const char * top = str + len ; str < top ; str ++ ) {
250
248
if (* str == '\n' ) {
251
- ringbuf_put ((ringbuf_t * )& tx_ringbuf , '\r' );
249
+ ringbuf_put ((ringbuf_t * )& tx_ringbuf , '\r' );
252
250
usb_cdc_loop ();
253
251
}
254
- ringbuf_put ((ringbuf_t * )& tx_ringbuf , * str );
252
+ ringbuf_put ((ringbuf_t * )& tx_ringbuf , * str );
255
253
usb_cdc_loop ();
256
254
}
257
255
}
0 commit comments