From 3d1a2e1cb9fd1123fcb71a09858a1b031555df38 Mon Sep 17 00:00:00 2001 From: Thibaut VIARD <thibaut.viard@atmel.com> Date: Tue, 9 Sep 2014 12:40:49 +0200 Subject: [PATCH] Update serial objects and PWM pins Signed-off-by: Thibaut VIARD <thibaut.viard@atmel.com> --- cores/arduino/Uart.cpp | 5 +- cores/arduino/Uart.h | 2 +- cores/arduino/WVariant.h | 50 +++++++------- cores/arduino/wiring_analog.c | 126 +++------------------------------- 4 files changed, 39 insertions(+), 144 deletions(-) diff --git a/cores/arduino/Uart.cpp b/cores/arduino/Uart.cpp index 5f580b45..e1c15e1a 100644 --- a/cores/arduino/Uart.cpp +++ b/cores/arduino/Uart.cpp @@ -156,9 +156,10 @@ SercomParityMode Uart::extractParity(uint8_t config) void SERCOM0_Handler() { - Serial.IrqHandler(); + Serial1.IrqHandler(); } + void SERCOM5_Handler() { - Serial5.IrqHandler(); + Serial.IrqHandler(); } diff --git a/cores/arduino/Uart.h b/cores/arduino/Uart.h index 2d379faa..93e87803 100644 --- a/cores/arduino/Uart.h +++ b/cores/arduino/Uart.h @@ -57,7 +57,7 @@ class Uart : public HardwareSerial }; extern Uart Serial; -extern Uart Serial5; +extern Uart Serial1; #endif diff --git a/cores/arduino/WVariant.h b/cores/arduino/WVariant.h index 612bb135..1b3de932 100644 --- a/cores/arduino/WVariant.h +++ b/cores/arduino/WVariant.h @@ -23,7 +23,7 @@ #include "sam.h" #ifdef __cplusplus -extern "C"{ +extern "C" { #endif // __cplusplus /* Definitions and types for pins */ @@ -62,10 +62,10 @@ typedef enum _ETCChannel TCC1_CH1 = (1<<8)|(1), TCC2_CH0 = (2<<8)|(0), TCC2_CH1 = (2<<8)|(1), - TC3_CH0 = (3<<8)|(0), - TC3_CH1 = (3<<8)|(1), - TC7_CH0 = (7<<8)|(0), - TC7_CH1 = (7<<8)|(1) + TC3_CH0 = (3<<8)|(0), + TC3_CH1 = (3<<8)|(1), + TC7_CH0 = (7<<8)|(0), + TC7_CH1 = (7<<8)|(1) } ETCChannel ; extern const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM] ; @@ -133,19 +133,19 @@ typedef enum _EExt_Interrupts typedef enum _EPioType { - 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_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_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_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_AC_CLK, /* The pin is controlled by the associated signal of peripheral H. */ - PIO_DIGITAL, /* The pin is controlled by PORT. */ - 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_OUTPUT, /* The pin is controlled by PORT and is an output. */ + PIO_NOT_A_PIN=-1, /* Not under control of a peripheral. */ + 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_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_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_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_DIGITAL, /* The pin is controlled by PORT. */ + 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_OUTPUT, /* The pin is controlled by PORT and is an output. */ PIO_PWM=PIO_TIMER, PIO_PWM_ALT=PIO_TIMER_ALT, @@ -165,13 +165,13 @@ typedef enum _EPioType /* Types used for the table below */ typedef struct _PinDescription { - EPortType ulPort ; - uint32_t ulPin ; - EPioType ulPinType ; - uint32_t ulPinAttribute ; - EAnalogChannel ulADCChannelNumber ; /* ADC Channel number in the SAM device */ - EPWMChannel ulPWMChannel ; - ETCChannel ulTCChannel ; + EPortType ulPort ; + uint32_t ulPin ; + EPioType ulPinType ; + uint32_t ulPinAttribute ; + EAnalogChannel ulADCChannelNumber ; /* ADC Channel number in the SAM device */ + EPWMChannel ulPWMChannel ; + ETCChannel ulTCChannel ; EExt_Interrupts ulExtInt ; } PinDescription ; diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index fb8ed238..ba6a74d3 100644 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -95,51 +95,6 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue ) } 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 ) @@ -161,77 +116,6 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue ) 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 switch ( GetTCNumber( g_APinDescription[ulPin].ulPWMChannel ) ) { @@ -264,6 +148,16 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue ) //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 )) ; 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 -- GitLab