Skip to content
Snippets Groups Projects
Commit 3d1a2e1c authored by Thibaut VIARD's avatar Thibaut VIARD
Browse files

Update serial objects and PWM pins

parent c320c873
Loading
...@@ -156,9 +156,10 @@ SercomParityMode Uart::extractParity(uint8_t config) ...@@ -156,9 +156,10 @@ SercomParityMode Uart::extractParity(uint8_t config)
void SERCOM0_Handler() void SERCOM0_Handler()
{ {
Serial.IrqHandler(); Serial1.IrqHandler();
} }
void SERCOM5_Handler() void SERCOM5_Handler()
{ {
Serial5.IrqHandler(); Serial.IrqHandler();
} }
...@@ -57,7 +57,7 @@ class Uart : public HardwareSerial ...@@ -57,7 +57,7 @@ class Uart : public HardwareSerial
}; };
extern Uart Serial; extern Uart Serial;
extern Uart Serial5; extern Uart Serial1;
#endif #endif
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "sam.h" #include "sam.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C"{ extern "C" {
#endif // __cplusplus #endif // __cplusplus
/* Definitions and types for pins */ /* Definitions and types for pins */
...@@ -62,10 +62,10 @@ typedef enum _ETCChannel ...@@ -62,10 +62,10 @@ typedef enum _ETCChannel
TCC1_CH1 = (1<<8)|(1), TCC1_CH1 = (1<<8)|(1),
TCC2_CH0 = (2<<8)|(0), TCC2_CH0 = (2<<8)|(0),
TCC2_CH1 = (2<<8)|(1), TCC2_CH1 = (2<<8)|(1),
TC3_CH0 = (3<<8)|(0), TC3_CH0 = (3<<8)|(0),
TC3_CH1 = (3<<8)|(1), TC3_CH1 = (3<<8)|(1),
TC7_CH0 = (7<<8)|(0), TC7_CH0 = (7<<8)|(0),
TC7_CH1 = (7<<8)|(1) TC7_CH1 = (7<<8)|(1)
} ETCChannel ; } ETCChannel ;
extern const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM] ; extern const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM] ;
...@@ -133,19 +133,19 @@ typedef enum _EExt_Interrupts ...@@ -133,19 +133,19 @@ typedef enum _EExt_Interrupts
typedef enum _EPioType typedef enum _EPioType
{ {
PIO_NOT_A_PIN=-1, /* Not under control of a peripheral. */ PIO_NOT_A_PIN=-1, /* Not under control of a peripheral. */
PIO_EXTINT, /* The pin is controlled by the associated signal of peripheral A. */ PIO_EXTINT=0, /* The pin is controlled by the associated signal of peripheral A. */
PIO_ANALOG, /* The pin is controlled by the associated signal of peripheral B. */ PIO_ANALOG, /* The pin is controlled by the associated signal of peripheral B. */
PIO_SERCOM, /* The pin is controlled by the associated signal of peripheral C. */ PIO_SERCOM, /* The pin is controlled by the associated signal of peripheral C. */
PIO_SERCOM_ALT, /* The pin is controlled by the associated signal of peripheral D. */ PIO_SERCOM_ALT, /* The pin is controlled by the associated signal of peripheral D. */
PIO_TIMER, /* The pin is controlled by the associated signal of peripheral E. */ PIO_TIMER, /* The pin is controlled by the associated signal of peripheral E. */
PIO_TIMER_ALT, /* The pin is controlled by the associated signal of peripheral F. */ PIO_TIMER_ALT, /* The pin is controlled by the associated signal of peripheral F. */
PIO_COM, /* The pin is controlled by the associated signal of peripheral G. */ PIO_COM, /* The pin is controlled by the associated signal of peripheral G. */
PIO_AC_CLK, /* The pin is controlled by the associated signal of peripheral H. */ PIO_AC_CLK, /* The pin is controlled by the associated signal of peripheral H. */
PIO_DIGITAL, /* The pin is controlled by PORT. */ PIO_DIGITAL, /* The pin is controlled by PORT. */
PIO_INPUT, /* The pin is controlled by PORT and is an input. */ PIO_INPUT, /* The pin is controlled by PORT and is an input. */
PIO_INPUT_PULLUP, /* The pin is controlled by PORT and is an input with internal pull-up resistor enabled. */ PIO_INPUT_PULLUP, /* The pin is controlled by PORT and is an input with internal pull-up resistor enabled. */
PIO_OUTPUT, /* The pin is controlled by PORT and is an output. */ PIO_OUTPUT, /* The pin is controlled by PORT and is an output. */
PIO_PWM=PIO_TIMER, PIO_PWM=PIO_TIMER,
PIO_PWM_ALT=PIO_TIMER_ALT, PIO_PWM_ALT=PIO_TIMER_ALT,
...@@ -165,13 +165,13 @@ typedef enum _EPioType ...@@ -165,13 +165,13 @@ typedef enum _EPioType
/* Types used for the table below */ /* Types used for the table below */
typedef struct _PinDescription typedef struct _PinDescription
{ {
EPortType ulPort ; EPortType ulPort ;
uint32_t ulPin ; uint32_t ulPin ;
EPioType ulPinType ; EPioType ulPinType ;
uint32_t ulPinAttribute ; uint32_t ulPinAttribute ;
EAnalogChannel ulADCChannelNumber ; /* ADC Channel number in the SAM device */ EAnalogChannel ulADCChannelNumber ; /* ADC Channel number in the SAM device */
EPWMChannel ulPWMChannel ; EPWMChannel ulPWMChannel ;
ETCChannel ulTCChannel ; ETCChannel ulTCChannel ;
EExt_Interrupts ulExtInt ; EExt_Interrupts ulExtInt ;
} PinDescription ; } PinDescription ;
......
...@@ -95,51 +95,6 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue ) ...@@ -95,51 +95,6 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
} }
DAC->DATA.reg = ulValue & 0x3FF; // Dac on 10 bits. DAC->DATA.reg = ulValue & 0x3FF; // Dac on 10 bits.
// EAnalogChannel channel = g_APinDescription[ulPin].ulADCChannelNumber;
// if (channel == DA0 || channel == DA1) {
// uint32_t chDACC = ((channel == DA0) ? 0 : 1);
// if (dacc_get_channel_status(DACC_INTERFACE) == 0) {
// /* Enable clock for DACC_INTERFACE */
// pmc_enable_periph_clk(DACC_INTERFACE_ID);
// /* Reset DACC registers */
// dacc_reset(DACC_INTERFACE);
// /* Half word transfer mode */
// dacc_set_transfer_mode(DACC_INTERFACE, 0);
// /* Power save:
// * sleep mode - 0 (disabled)
// * fast wakeup - 0 (disabled)
// */
// dacc_set_power_save(DACC_INTERFACE, 0, 0);
// /* Timing:
// * refresh - 0x08 (1024*8 dacc clocks)
// * max speed mode - 0 (disabled)
// * startup time - 0x10 (1024 dacc clocks)
// */
// dacc_set_timing(DACC_INTERFACE, 0x08, 0, 0x10);
// /* Set up analog current */
// dacc_set_analog_control(DACC_INTERFACE, DACC_ACR_IBCTLCH0(0x02) |
// DACC_ACR_IBCTLCH1(0x02) |
// DACC_ACR_IBCTLDACCORE(0x01));
// }
// /* Disable TAG and select output channel chDACC */
// dacc_set_channel_selection(DACC_INTERFACE, chDACC);
// if ((dacc_get_channel_status(DACC_INTERFACE) & (1 << chDACC)) == 0) {
// dacc_enable_channel(DACC_INTERFACE, chDACC);
// }
// // Write user value
// ulValue = mapResolution(ulValue, _writeResolution, DACC_RESOLUTION);
// dacc_write_conversion_data(DACC_INTERFACE, ulValue);
// while ((dacc_get_interrupt_status(DACC_INTERFACE) & DACC_ISR_EOC) == 0);
// return;
// }
} }
if ( (attr & PIN_ATTR_PWM) == PIN_ATTR_PWM ) if ( (attr & PIN_ATTR_PWM) == PIN_ATTR_PWM )
...@@ -161,77 +116,6 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue ) ...@@ -161,77 +116,6 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
TCCx = (Tcc*) GetTC( g_APinDescription[ulPin].ulPWMChannel ) ; TCCx = (Tcc*) GetTC( g_APinDescription[ulPin].ulPWMChannel ) ;
} }
/*
switch ( g_APinDescription[ulPin].ulPWMChannel )
{
case PWM3_CH0 :
TCx = TC3 ;
Channelx = 0 ;
isTC = 1 ;
break;
case PWM3_CH1:
TCx = TC3 ;
Channelx = 1;
isTC = 1;
break;
case PWM0_CH0 :
TCCx = TCC0;
Channelx = 0;
break;
case PWM0_CH1 :
TCCx = TCC0;
Channelx = 1;
break;
case PWM0_CH4 :
TCCx = TCC0;
//Channelx = 4;
Channelx = 0;
break;
case PWM0_CH5 :
TCCx = TCC0;
//Channelx = 5;
Channelx = 1;
break;
case PWM0_CH6 :
TCCx = TCC0;
//Channelx = 6;
Channelx = 2;
break;
case PWM0_CH7 :
TCCx = TCC0;
//Channelx = 7;
Channelx = 3;
break;
case PWM1_CH0 :
TCCx = TCC1;
Channelx = 0;
break;
case PWM1_CH1 :
TCCx = TCC1;
Channelx = 1;
break;
case PWM2_CH0 :
TCCx = TCC2;
Channelx = 0;
break;
case PWM2_CH1 :
TCCx = TCC2;
Channelx = 1;
break;
}
*/
// Enable clocks according to TCCx instance to use // Enable clocks according to TCCx instance to use
switch ( GetTCNumber( g_APinDescription[ulPin].ulPWMChannel ) ) switch ( GetTCNumber( g_APinDescription[ulPin].ulPWMChannel ) )
{ {
...@@ -264,6 +148,16 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue ) ...@@ -264,6 +148,16 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
//Enable GCLK for TC5 (timer counter input clock) //Enable GCLK for TC5 (timer counter input clock)
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TC4_TC5 )) ; GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TC4_TC5 )) ;
break ; break ;
case 6: // TC6
//Enable GCLK for TC6 (timer counter input clock)
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TC6_TC7 ));
break ;
case 7: // TC7
//Enable GCLK for TC7 (timer counter input clock)
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TC6_TC7 )) ;
break ;
} }
// Set PORT // Set PORT
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment