Skip to content

Commit 3d1a2e1

Browse files
committed
Update serial objects and PWM pins
Signed-off-by: Thibaut VIARD <thibaut.viard@atmel.com>
1 parent c320c87 commit 3d1a2e1

File tree

4 files changed

+39
-144
lines changed

4 files changed

+39
-144
lines changed

cores/arduino/Uart.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,10 @@ SercomParityMode Uart::extractParity(uint8_t config)
156156

157157
void SERCOM0_Handler()
158158
{
159-
Serial.IrqHandler();
159+
Serial1.IrqHandler();
160160
}
161+
161162
void SERCOM5_Handler()
162163
{
163-
Serial5.IrqHandler();
164+
Serial.IrqHandler();
164165
}

cores/arduino/Uart.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Uart : public HardwareSerial
5757
};
5858

5959
extern Uart Serial;
60-
extern Uart Serial5;
60+
extern Uart Serial1;
6161

6262

6363
#endif

cores/arduino/WVariant.h

+25-25
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "sam.h"
2424

2525
#ifdef __cplusplus
26-
extern "C"{
26+
extern "C" {
2727
#endif // __cplusplus
2828

2929
/* Definitions and types for pins */
@@ -62,10 +62,10 @@ typedef enum _ETCChannel
6262
TCC1_CH1 = (1<<8)|(1),
6363
TCC2_CH0 = (2<<8)|(0),
6464
TCC2_CH1 = (2<<8)|(1),
65-
TC3_CH0 = (3<<8)|(0),
66-
TC3_CH1 = (3<<8)|(1),
67-
TC7_CH0 = (7<<8)|(0),
68-
TC7_CH1 = (7<<8)|(1)
65+
TC3_CH0 = (3<<8)|(0),
66+
TC3_CH1 = (3<<8)|(1),
67+
TC7_CH0 = (7<<8)|(0),
68+
TC7_CH1 = (7<<8)|(1)
6969
} ETCChannel ;
7070

7171
extern const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM] ;
@@ -133,19 +133,19 @@ typedef enum _EExt_Interrupts
133133

134134
typedef enum _EPioType
135135
{
136-
PIO_NOT_A_PIN=-1, /* Not under control of a peripheral. */
137-
PIO_EXTINT, /* The pin is controlled by the associated signal of peripheral A. */
138-
PIO_ANALOG, /* The pin is controlled by the associated signal of peripheral B. */
139-
PIO_SERCOM, /* The pin is controlled by the associated signal of peripheral C. */
140-
PIO_SERCOM_ALT, /* The pin is controlled by the associated signal of peripheral D. */
141-
PIO_TIMER, /* The pin is controlled by the associated signal of peripheral E. */
142-
PIO_TIMER_ALT, /* The pin is controlled by the associated signal of peripheral F. */
143-
PIO_COM, /* The pin is controlled by the associated signal of peripheral G. */
144-
PIO_AC_CLK, /* The pin is controlled by the associated signal of peripheral H. */
145-
PIO_DIGITAL, /* The pin is controlled by PORT. */
146-
PIO_INPUT, /* The pin is controlled by PORT and is an input. */
147-
PIO_INPUT_PULLUP, /* The pin is controlled by PORT and is an input with internal pull-up resistor enabled. */
148-
PIO_OUTPUT, /* The pin is controlled by PORT and is an output. */
136+
PIO_NOT_A_PIN=-1, /* Not under control of a peripheral. */
137+
PIO_EXTINT=0, /* The pin is controlled by the associated signal of peripheral A. */
138+
PIO_ANALOG, /* The pin is controlled by the associated signal of peripheral B. */
139+
PIO_SERCOM, /* The pin is controlled by the associated signal of peripheral C. */
140+
PIO_SERCOM_ALT, /* The pin is controlled by the associated signal of peripheral D. */
141+
PIO_TIMER, /* The pin is controlled by the associated signal of peripheral E. */
142+
PIO_TIMER_ALT, /* The pin is controlled by the associated signal of peripheral F. */
143+
PIO_COM, /* The pin is controlled by the associated signal of peripheral G. */
144+
PIO_AC_CLK, /* The pin is controlled by the associated signal of peripheral H. */
145+
PIO_DIGITAL, /* The pin is controlled by PORT. */
146+
PIO_INPUT, /* The pin is controlled by PORT and is an input. */
147+
PIO_INPUT_PULLUP, /* The pin is controlled by PORT and is an input with internal pull-up resistor enabled. */
148+
PIO_OUTPUT, /* The pin is controlled by PORT and is an output. */
149149

150150
PIO_PWM=PIO_TIMER,
151151
PIO_PWM_ALT=PIO_TIMER_ALT,
@@ -165,13 +165,13 @@ typedef enum _EPioType
165165
/* Types used for the table below */
166166
typedef struct _PinDescription
167167
{
168-
EPortType ulPort ;
169-
uint32_t ulPin ;
170-
EPioType ulPinType ;
171-
uint32_t ulPinAttribute ;
172-
EAnalogChannel ulADCChannelNumber ; /* ADC Channel number in the SAM device */
173-
EPWMChannel ulPWMChannel ;
174-
ETCChannel ulTCChannel ;
168+
EPortType ulPort ;
169+
uint32_t ulPin ;
170+
EPioType ulPinType ;
171+
uint32_t ulPinAttribute ;
172+
EAnalogChannel ulADCChannelNumber ; /* ADC Channel number in the SAM device */
173+
EPWMChannel ulPWMChannel ;
174+
ETCChannel ulTCChannel ;
175175
EExt_Interrupts ulExtInt ;
176176
} PinDescription ;
177177

cores/arduino/wiring_analog.c

+10-116
Original file line numberDiff line numberDiff line change
@@ -95,51 +95,6 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
9595
}
9696

9797
DAC->DATA.reg = ulValue & 0x3FF; // Dac on 10 bits.
98-
99-
// EAnalogChannel channel = g_APinDescription[ulPin].ulADCChannelNumber;
100-
// if (channel == DA0 || channel == DA1) {
101-
// uint32_t chDACC = ((channel == DA0) ? 0 : 1);
102-
// if (dacc_get_channel_status(DACC_INTERFACE) == 0) {
103-
// /* Enable clock for DACC_INTERFACE */
104-
// pmc_enable_periph_clk(DACC_INTERFACE_ID);
105-
106-
// /* Reset DACC registers */
107-
// dacc_reset(DACC_INTERFACE);
108-
109-
// /* Half word transfer mode */
110-
// dacc_set_transfer_mode(DACC_INTERFACE, 0);
111-
112-
// /* Power save:
113-
// * sleep mode - 0 (disabled)
114-
// * fast wakeup - 0 (disabled)
115-
// */
116-
// dacc_set_power_save(DACC_INTERFACE, 0, 0);
117-
// /* Timing:
118-
// * refresh - 0x08 (1024*8 dacc clocks)
119-
// * max speed mode - 0 (disabled)
120-
// * startup time - 0x10 (1024 dacc clocks)
121-
// */
122-
// dacc_set_timing(DACC_INTERFACE, 0x08, 0, 0x10);
123-
124-
// /* Set up analog current */
125-
// dacc_set_analog_control(DACC_INTERFACE, DACC_ACR_IBCTLCH0(0x02) |
126-
// DACC_ACR_IBCTLCH1(0x02) |
127-
// DACC_ACR_IBCTLDACCORE(0x01));
128-
// }
129-
130-
// /* Disable TAG and select output channel chDACC */
131-
// dacc_set_channel_selection(DACC_INTERFACE, chDACC);
132-
133-
// if ((dacc_get_channel_status(DACC_INTERFACE) & (1 << chDACC)) == 0) {
134-
// dacc_enable_channel(DACC_INTERFACE, chDACC);
135-
// }
136-
137-
// // Write user value
138-
// ulValue = mapResolution(ulValue, _writeResolution, DACC_RESOLUTION);
139-
// dacc_write_conversion_data(DACC_INTERFACE, ulValue);
140-
// while ((dacc_get_interrupt_status(DACC_INTERFACE) & DACC_ISR_EOC) == 0);
141-
// return;
142-
// }
14398
}
14499

145100
if ( (attr & PIN_ATTR_PWM) == PIN_ATTR_PWM )
@@ -161,77 +116,6 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
161116
TCCx = (Tcc*) GetTC( g_APinDescription[ulPin].ulPWMChannel ) ;
162117
}
163118

164-
/*
165-
switch ( g_APinDescription[ulPin].ulPWMChannel )
166-
{
167-
case PWM3_CH0 :
168-
TCx = TC3 ;
169-
Channelx = 0 ;
170-
isTC = 1 ;
171-
break;
172-
173-
case PWM3_CH1:
174-
TCx = TC3 ;
175-
Channelx = 1;
176-
isTC = 1;
177-
break;
178-
179-
case PWM0_CH0 :
180-
TCCx = TCC0;
181-
Channelx = 0;
182-
break;
183-
184-
case PWM0_CH1 :
185-
TCCx = TCC0;
186-
Channelx = 1;
187-
break;
188-
189-
case PWM0_CH4 :
190-
TCCx = TCC0;
191-
//Channelx = 4;
192-
Channelx = 0;
193-
break;
194-
195-
case PWM0_CH5 :
196-
TCCx = TCC0;
197-
//Channelx = 5;
198-
Channelx = 1;
199-
break;
200-
201-
case PWM0_CH6 :
202-
TCCx = TCC0;
203-
//Channelx = 6;
204-
Channelx = 2;
205-
break;
206-
207-
case PWM0_CH7 :
208-
TCCx = TCC0;
209-
//Channelx = 7;
210-
Channelx = 3;
211-
break;
212-
213-
case PWM1_CH0 :
214-
TCCx = TCC1;
215-
Channelx = 0;
216-
break;
217-
218-
case PWM1_CH1 :
219-
TCCx = TCC1;
220-
Channelx = 1;
221-
break;
222-
223-
case PWM2_CH0 :
224-
TCCx = TCC2;
225-
Channelx = 0;
226-
break;
227-
228-
case PWM2_CH1 :
229-
TCCx = TCC2;
230-
Channelx = 1;
231-
break;
232-
}
233-
*/
234-
235119
// Enable clocks according to TCCx instance to use
236120
switch ( GetTCNumber( g_APinDescription[ulPin].ulPWMChannel ) )
237121
{
@@ -264,6 +148,16 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
264148
//Enable GCLK for TC5 (timer counter input clock)
265149
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TC4_TC5 )) ;
266150
break ;
151+
152+
case 6: // TC6
153+
//Enable GCLK for TC6 (timer counter input clock)
154+
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TC6_TC7 ));
155+
break ;
156+
157+
case 7: // TC7
158+
//Enable GCLK for TC7 (timer counter input clock)
159+
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TC6_TC7 )) ;
160+
break ;
267161
}
268162

269163
// Set PORT

0 commit comments

Comments
 (0)