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