@@ -144,15 +144,15 @@ extern const PinDescription g_APinDescription[]=
144
144
// 13 - AMBER LED
145
145
{ PIOB, PIO_PB27B_TIOB0, ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC0_CHB0 }, // TIOB0
146
146
147
- // 14/15 - USART2 (Serial4 )
147
+ // 14/15 - USART3 (Serial3 )
148
148
{ PIOD, PIO_PD4B_TXD3, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TXD3
149
149
{ PIOD, PIO_PD5B_RXD3, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // RXD3
150
150
151
- // 16/17 - USART1 (Serial3 )
151
+ // 16/17 - USART1 (Serial2 )
152
152
{ PIOA, PIO_PA13A_TXD1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TXD1
153
153
{ PIOA, PIO_PA12A_RXD1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // RXD1
154
154
155
- // 18/19 - USART0 (Serial2 )
155
+ // 18/19 - USART0 (Serial1 )
156
156
{ PIOA, PIO_PA11A_TXD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TXD0
157
157
{ PIOA, PIO_PA10A_RXD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // RXD0
158
158
@@ -258,11 +258,11 @@ extern const PinDescription g_APinDescription[]=
258
258
{ PIOB, PIO_PB12A_TWD1|PIO_PB13A_TWCK1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
259
259
// 81 - UART (Serial) all pins
260
260
{ PIOA, PIO_PA8A_URXD|PIO_PA9A_UTXD, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
261
- // 82 - USART0 (Serial2 ) all pins
261
+ // 82 - USART0 (Serial1 ) all pins
262
262
{ PIOA, PIO_PA11A_TXD0|PIO_PA10A_RXD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
263
- // 83 - USART1 (Serial3 ) all pins
263
+ // 83 - USART1 (Serial2 ) all pins
264
264
{ PIOA, PIO_PA13A_TXD1|PIO_PA12A_RXD1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
265
- // 84 - USART3 (Serial4 ) all pins
265
+ // 84 - USART3 (Serial3 ) all pins
266
266
{ PIOD, PIO_PD4B_TXD3|PIO_PD5B_RXD3, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
267
267
268
268
// 85 - USB
@@ -285,42 +285,42 @@ extern const PinDescription g_APinDescription[]=
285
285
/*
286
286
* UART objects
287
287
*/
288
- RingBuffer rx_buffer1 ;
288
+ RingBuffer rx_buffer1;
289
289
290
- UARTClass Serial ( UART, UART_IRQn, ID_UART, &rx_buffer1 ) ;
290
+ UARTClass Serial (UART, UART_IRQn, ID_UART, &rx_buffer1) ;
291
291
292
292
// IT handlers
293
293
void UART_Handler (void )
294
294
{
295
- Serial.IrqHandler () ;
295
+ Serial.IrqHandler ();
296
296
}
297
297
298
298
// ----------------------------------------------------------------------------
299
299
/*
300
300
* USART objects
301
301
*/
302
- RingBuffer rx_buffer2 ;
303
- RingBuffer rx_buffer3 ;
304
- RingBuffer rx_buffer4 ;
302
+ RingBuffer rx_buffer2;
303
+ RingBuffer rx_buffer3;
304
+ RingBuffer rx_buffer4;
305
305
306
- USARTClass Serial2 ( USART0, USART0_IRQn, ID_USART0, &rx_buffer2 ) ;
307
- USARTClass Serial3 ( USART1, USART1_IRQn, ID_USART1, &rx_buffer3 ) ;
308
- USARTClass Serial4 ( USART3, USART3_IRQn, ID_USART3, &rx_buffer4 ) ;
306
+ USARTClass Serial1 ( USART0, USART0_IRQn, ID_USART0, &rx_buffer2) ;
307
+ USARTClass Serial2 ( USART1, USART1_IRQn, ID_USART1, &rx_buffer3) ;
308
+ USARTClass Serial3 ( USART3, USART3_IRQn, ID_USART3, &rx_buffer4) ;
309
309
310
310
// IT handlers
311
- void USART0_Handler ( void )
311
+ void USART0_Handler (void )
312
312
{
313
- Serial2 .IrqHandler () ;
313
+ Serial1 .IrqHandler ();
314
314
}
315
315
316
- void USART1_Handler ( void )
316
+ void USART1_Handler (void )
317
317
{
318
- Serial3 .IrqHandler () ;
318
+ Serial2 .IrqHandler ();
319
319
}
320
320
321
- void USART3_Handler ( void )
321
+ void USART3_Handler (void )
322
322
{
323
- Serial4 .IrqHandler () ;
323
+ Serial3 .IrqHandler ();
324
324
}
325
325
326
326
// ----------------------------------------------------------------------------
@@ -333,17 +333,17 @@ void __libc_init_array(void);
333
333
334
334
void init ( void )
335
335
{
336
- SystemInit () ;
336
+ SystemInit ();
337
337
338
338
// Set Systick to 1ms interval, common to all SAM3 variants
339
- if ( SysTick_Config ( SystemCoreClock / 1000 ) )
339
+ if (SysTick_Config (SystemCoreClock / 1000 ) )
340
340
{
341
341
// Capture error
342
- while ( 1 ) ;
342
+ while (true ) ;
343
343
}
344
344
345
- // Disable watchdog, common to all SAM variants
346
- WDT_Disable ( WDT ) ;
345
+ // Disable watchdog
346
+ WDT_Disable (WDT) ;
347
347
348
348
// Initialize C library
349
349
__libc_init_array ();
@@ -352,16 +352,12 @@ void init( void )
352
352
for (int i = 0 ; i < PINS_COUNT; i++)
353
353
digitalWrite (i, LOW);
354
354
355
- // Initialize Serial port UART, common to all SAM3 variants
355
+ // Initialize Serial port U(S)ART pins
356
356
PIO_Configure (
357
357
g_APinDescription[PINS_UART].pPort ,
358
358
g_APinDescription[PINS_UART].ulPinType ,
359
359
g_APinDescription[PINS_UART].ulPin ,
360
360
g_APinDescription[PINS_UART].ulPinConfiguration );
361
-
362
- Serial.begin (115200 );
363
-
364
- // Initialize Serial ports USART
365
361
PIO_Configure (
366
362
g_APinDescription[PINS_USART0].pPort ,
367
363
g_APinDescription[PINS_USART0].ulPinType ,
@@ -373,25 +369,25 @@ void init( void )
373
369
g_APinDescription[PINS_USART1].ulPin ,
374
370
g_APinDescription[PINS_USART1].ulPinConfiguration );
375
371
PIO_Configure (
376
- g_APinDescription[PINS_USART2 ].pPort ,
377
- g_APinDescription[PINS_USART2 ].ulPinType ,
378
- g_APinDescription[PINS_USART2 ].ulPin ,
379
- g_APinDescription[PINS_USART2 ].ulPinConfiguration );
372
+ g_APinDescription[PINS_USART3 ].pPort ,
373
+ g_APinDescription[PINS_USART3 ].ulPinType ,
374
+ g_APinDescription[PINS_USART3 ].ulPin ,
375
+ g_APinDescription[PINS_USART3 ].ulPinConfiguration );
380
376
381
- // Initialize USB
377
+ // Initialize USB pins
382
378
PIO_Configure (
383
379
g_APinDescription[PINS_USB].pPort ,
384
380
g_APinDescription[PINS_USB].ulPinType ,
385
381
g_APinDescription[PINS_USB].ulPin ,
386
382
g_APinDescription[PINS_USB].ulPinConfiguration );
387
383
388
384
// Initialize Analog Controller
389
- pmc_enable_periph_clk ( ID_ADC ) ;
390
- adc_init ( ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST ) ;
385
+ pmc_enable_periph_clk (ID_ADC) ;
386
+ adc_init (ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST) ;
391
387
adc_configure_timing (ADC, 0 , ADC_SETTLING_TIME_3, 1 );
392
388
adc_configure_trigger (ADC, ADC_TRIG_SW, 0 ); // Disable hardware trigger.
393
- adc_disable_interrupt ( ADC, 0xFFFFFFFF ) ; // Disable all ADC interrupts.
394
- adc_disable_all_channel ( ADC ) ;
389
+ adc_disable_interrupt (ADC, 0xFFFFFFFF ) ; // Disable all ADC interrupts.
390
+ adc_disable_all_channel (ADC) ;
395
391
396
392
// Initialize analogOutput module
397
393
analogOutputInit ();
0 commit comments