Skip to content

Commit 562324d

Browse files
committed
Adjusted off-by-one naming for Serial object: Serial2/3/4 => Serial1/2/3
1 parent e92ad6e commit 562324d

File tree

3 files changed

+53
-55
lines changed

3 files changed

+53
-55
lines changed

build/shared/lib/keywords.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ shiftOut KEYWORD2 ShiftOut
163163
tone KEYWORD2 Tone
164164

165165
Serial KEYWORD3 Serial
166+
Serial1 KEYWORD3 Serial
166167
Serial2 KEYWORD3 Serial
167168
Serial3 KEYWORD3 Serial
168-
Serial4 KEYWORD3 Serial
169169
SerialUSB KEYWORD3 Serial
170170
begin KEYWORD2 Serial_Begin
171171
end KEYWORD2 Serial_End

hardware/arduino/sam/variants/arduino_due_x/variant.cpp

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ extern const PinDescription g_APinDescription[]=
144144
// 13 - AMBER LED
145145
{ 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
146146

147-
// 14/15 - USART2 (Serial4)
147+
// 14/15 - USART3 (Serial3)
148148
{ 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
149149
{ 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
150150

151-
// 16/17 - USART1 (Serial3)
151+
// 16/17 - USART1 (Serial2)
152152
{ 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
153153
{ 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
154154

155-
// 18/19 - USART0 (Serial2)
155+
// 18/19 - USART0 (Serial1)
156156
{ 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
157157
{ 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
158158

@@ -258,11 +258,11 @@ extern const PinDescription g_APinDescription[]=
258258
{ 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 },
259259
// 81 - UART (Serial) all pins
260260
{ 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
262262
{ 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
264264
{ 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
266266
{ 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 },
267267

268268
// 85 - USB
@@ -285,42 +285,42 @@ extern const PinDescription g_APinDescription[]=
285285
/*
286286
* UART objects
287287
*/
288-
RingBuffer rx_buffer1 ;
288+
RingBuffer rx_buffer1;
289289

290-
UARTClass Serial( UART, UART_IRQn, ID_UART, &rx_buffer1 ) ;
290+
UARTClass Serial(UART, UART_IRQn, ID_UART, &rx_buffer1);
291291

292292
// IT handlers
293293
void UART_Handler(void)
294294
{
295-
Serial.IrqHandler() ;
295+
Serial.IrqHandler();
296296
}
297297

298298
// ----------------------------------------------------------------------------
299299
/*
300300
* USART objects
301301
*/
302-
RingBuffer rx_buffer2 ;
303-
RingBuffer rx_buffer3 ;
304-
RingBuffer rx_buffer4 ;
302+
RingBuffer rx_buffer2;
303+
RingBuffer rx_buffer3;
304+
RingBuffer rx_buffer4;
305305

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);
309309

310310
// IT handlers
311-
void USART0_Handler( void )
311+
void USART0_Handler(void)
312312
{
313-
Serial2.IrqHandler() ;
313+
Serial1.IrqHandler();
314314
}
315315

316-
void USART1_Handler( void )
316+
void USART1_Handler(void)
317317
{
318-
Serial3.IrqHandler() ;
318+
Serial2.IrqHandler();
319319
}
320320

321-
void USART3_Handler( void )
321+
void USART3_Handler(void)
322322
{
323-
Serial4.IrqHandler() ;
323+
Serial3.IrqHandler();
324324
}
325325

326326
// ----------------------------------------------------------------------------
@@ -333,17 +333,17 @@ void __libc_init_array(void);
333333

334334
void init( void )
335335
{
336-
SystemInit() ;
336+
SystemInit();
337337

338338
// Set Systick to 1ms interval, common to all SAM3 variants
339-
if ( SysTick_Config( SystemCoreClock / 1000 ) )
339+
if (SysTick_Config(SystemCoreClock / 1000))
340340
{
341341
// Capture error
342-
while ( 1 ) ;
342+
while (true);
343343
}
344344

345-
// Disable watchdog, common to all SAM variants
346-
WDT_Disable( WDT ) ;
345+
// Disable watchdog
346+
WDT_Disable(WDT);
347347

348348
// Initialize C library
349349
__libc_init_array();
@@ -352,16 +352,12 @@ void init( void )
352352
for (int i = 0; i < PINS_COUNT; i++)
353353
digitalWrite(i, LOW);
354354

355-
// Initialize Serial port UART, common to all SAM3 variants
355+
// Initialize Serial port U(S)ART pins
356356
PIO_Configure(
357357
g_APinDescription[PINS_UART].pPort,
358358
g_APinDescription[PINS_UART].ulPinType,
359359
g_APinDescription[PINS_UART].ulPin,
360360
g_APinDescription[PINS_UART].ulPinConfiguration);
361-
362-
Serial.begin(115200);
363-
364-
// Initialize Serial ports USART
365361
PIO_Configure(
366362
g_APinDescription[PINS_USART0].pPort,
367363
g_APinDescription[PINS_USART0].ulPinType,
@@ -373,25 +369,25 @@ void init( void )
373369
g_APinDescription[PINS_USART1].ulPin,
374370
g_APinDescription[PINS_USART1].ulPinConfiguration);
375371
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);
380376

381-
// Initialize USB
377+
// Initialize USB pins
382378
PIO_Configure(
383379
g_APinDescription[PINS_USB].pPort,
384380
g_APinDescription[PINS_USB].ulPinType,
385381
g_APinDescription[PINS_USB].ulPin,
386382
g_APinDescription[PINS_USB].ulPinConfiguration);
387383

388384
// 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);
391387
adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1);
392388
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);
395391

396392
// Initialize analogOutput module
397393
analogOutputInit();

hardware/arduino/sam/variants/arduino_due_x/variant.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ extern "C"{
102102
(x==BOARD_SPI_SS1 ? 1 : \
103103
(x==BOARD_SPI_SS2 ? 2 : 3)))
104104

105-
static const uint8_t SS = BOARD_SPI_SS0 ;
106-
static const uint8_t SS1 = BOARD_SPI_SS1 ;
107-
static const uint8_t SS2 = BOARD_SPI_SS2 ;
108-
static const uint8_t SS3 = BOARD_SPI_SS3 ;
109-
static const uint8_t MOSI = PIN_SPI_MOSI ;
110-
static const uint8_t MISO = PIN_SPI_MISO ;
111-
static const uint8_t SCK = PIN_SPI_SCK ;
105+
static const uint8_t SS = BOARD_SPI_SS0;
106+
static const uint8_t SS1 = BOARD_SPI_SS1;
107+
static const uint8_t SS2 = BOARD_SPI_SS2;
108+
static const uint8_t SS3 = BOARD_SPI_SS3;
109+
static const uint8_t MOSI = PIN_SPI_MOSI;
110+
static const uint8_t MISO = PIN_SPI_MISO;
111+
static const uint8_t SCK = PIN_SPI_SCK;
112112

113113
/*
114114
* Wire Interfaces
@@ -130,11 +130,14 @@ static const uint8_t SCK = PIN_SPI_SCK ;
130130
/*
131131
* UART/USART Interfaces
132132
*/
133+
// Serial
133134
#define PINS_UART (81u)
134-
135+
// Serial1
135136
#define PINS_USART0 (82u)
137+
// Serial2
136138
#define PINS_USART1 (83u)
137-
#define PINS_USART2 (84u)
139+
// Serial3
140+
#define PINS_USART3 (84u)
138141

139142
/*
140143
* USB Interfaces
@@ -201,11 +204,10 @@ static const uint8_t CANTX = 69;
201204

202205
#ifdef __cplusplus
203206

204-
extern UARTClass Serial ;
205-
206-
extern USARTClass Serial2 ;
207-
extern USARTClass Serial3 ;
208-
extern USARTClass Serial4 ;
207+
extern UARTClass Serial;
208+
extern USARTClass Serial1;
209+
extern USARTClass Serial2;
210+
extern USARTClass Serial3;
209211

210212
#endif
211213

0 commit comments

Comments
 (0)