From a73966ceaa33f474645edf3232c047482382108f Mon Sep 17 00:00:00 2001 From: Thibaut VIARD <thibaut.viard@atmel.com> Date: Tue, 13 May 2014 17:23:25 +0200 Subject: [PATCH] Fixing the failed compilation due to PR #16 merge --- cores/arduino/wiring_analog.c | 668 +++++++----------- cores/arduino/wiring_analog.h | 2 + .../validation_core/build_as6/test.cppproj | 462 ++++++++++++ .../validation_core/test - Copy.cpp | 100 +++ cores/validation/validation_core/test.cpp | 36 +- variants/arduino_zero/variant.cpp | 94 +-- variants/arduino_zero/variant.h | 4 +- 7 files changed, 897 insertions(+), 469 deletions(-) create mode 100644 cores/validation/validation_core/build_as6/test.cppproj create mode 100644 cores/validation/validation_core/test - Copy.cpp diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index a54e428b..7094cb61 100644 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2011 Arduino. All right reserved. + Copyright (c) 2014 Arduino. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -16,418 +16,282 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "Arduino.h" +#include "wiring_analog.h" +#include "wiring_digital.h" #ifdef __cplusplus extern "C" { #endif -// static int _readResolution = 10; -// static int _writeResolution = 8; - -// void analogReadResolution(int res) { - // _readResolution = res; -// } - -// void analogWriteResolution(int res) { - // _writeResolution = res; -// } - -// static inline uint32_t mapResolution(uint32_t value, uint32_t from, uint32_t to) { - // if (from == to) - // return value; - // if (from > to) - // return value >> (from-to); - // else - // return value << (to-from); -// } - -// eAnalogReference analog_reference = AR_DEFAULT; - -// void analogReference(eAnalogReference ulMode) -// { - // analog_reference = ulMode; -// } - -// uint32_t analogRead(uint32_t ulPin) -// { - // uint32_t ulValue = 0; - // uint32_t ulChannel; - - // if (ulPin < A0) - // ulPin += A0; - - // ulChannel = g_APinDescription[ulPin].ulADCChannelNumber ; - -// #if defined __SAM3U4E__ - // switch ( g_APinDescription[ulPin].ulAnalogChannel ) - // { - // // Handling ADC 10 bits channels - // case ADC0 : - // case ADC1 : - // case ADC2 : - // case ADC3 : - // case ADC4 : - // case ADC5 : - // case ADC6 : - // case ADC7 : - // // Enable the corresponding channel - // adc_enable_channel( ADC, ulChannel ); - - // // Start the ADC - // adc_start( ADC ); - - // // Wait for end of conversion - // while ((adc_get_status(ADC) & ADC_SR_DRDY) != ADC_SR_DRDY) - // ; - - // // Read the value - // ulValue = adc_get_latest_value(ADC); - // ulValue = mapResolution(ulValue, 10, _readResolution); - - // // Disable the corresponding channel - // adc_disable_channel( ADC, ulChannel ); - - // // Stop the ADC - // // adc_stop( ADC ) ; // never do adc_stop() else we have to reconfigure the ADC each time - // break; - - // // Handling ADC 12 bits channels - // case ADC8 : - // case ADC9 : - // case ADC10 : - // case ADC11 : - // case ADC12 : - // case ADC13 : - // case ADC14 : - // case ADC15 : - // // Enable the corresponding channel - // adc12b_enable_channel( ADC12B, ulChannel ); - - // // Start the ADC12B - // adc12b_start( ADC12B ); - - // // Wait for end of conversion - // while ((adc12b_get_status(ADC12B) & ADC12B_SR_DRDY) != ADC12B_SR_DRDY) - // ; - - // // Read the value - // ulValue = adc12b_get_latest_value(ADC12B) >> 2; - // ulValue = mapResolution(ulValue, 12, _readResolution); - - // // Stop the ADC12B - // // adc12_stop( ADC12B ) ; // never do adc12_stop() else we have to reconfigure the ADC12B each time - - // // Disable the corresponding channel - // adc12b_disable_channel( ADC12B, ulChannel ); - // break; - - // // Compiler could yell because we don't handle DAC pins - // default : - // ulValue=0; - // break; - // } -// #endif - -// #if defined __SAM3X8E__ || defined __SAM3X8H__ - // static uint32_t latestSelectedChannel = -1; - // switch ( g_APinDescription[ulPin].ulAnalogChannel ) - // { - // // Handling ADC 12 bits channels - // case ADC0 : - // case ADC1 : - // case ADC2 : - // case ADC3 : - // case ADC4 : - // case ADC5 : - // case ADC6 : - // case ADC7 : - // case ADC8 : - // case ADC9 : - // case ADC10 : - // case ADC11 : - - // // Enable the corresponding channel - // if (ulChannel != latestSelectedChannel) { - // adc_enable_channel( ADC, ulChannel ); - // if ( latestSelectedChannel != -1 ) - // adc_disable_channel( ADC, latestSelectedChannel ); - // latestSelectedChannel = ulChannel; - // } - - // // Start the ADC - // adc_start( ADC ); - - // // Wait for end of conversion - // while ((adc_get_status(ADC) & ADC_ISR_DRDY) != ADC_ISR_DRDY) - // ; - - // // Read the value - // ulValue = adc_get_latest_value(ADC); - // ulValue = mapResolution(ulValue, ADC_RESOLUTION, _readResolution); - - // break; - - // // Compiler could yell because we don't handle DAC pins - // default : - // ulValue=0; - // break; - // } -// #endif - - // return ulValue; -// } +uint32_t analogRead( uint32_t ulPin ) +{ + uint32_t ulValue = 0 ; + uint32_t ulChannel ; + + ulChannel = g_APinDescription[ulPin].ulADCChannelNumber ; + + static uint32_t latestSelectedChannel = -1; + +/* + switch ( g_APinDescription[ulPin].ulAnalogChannel ) + { + // Handling ADC 12 bits channels + case ADC0 : + case ADC1 : + case ADC2 : + case ADC3 : + case ADC4 : + case ADC5 : + break; + // Compiler could yell because we don't handle DAC pin + default : + ulValue=0; + break; + } +*/ + + return ulValue; + } // Right now, PWM output only works on the pins with // hardware support. These are defined in the appropriate // pins_*.c file. For the rest of the pins, we default // to digital output. - -void analogWrite(uint32_t ulPin, uint32_t ulValue) { - - uint32_t attr = g_APinDescription[ulPin].ulPinAttribute; - uint32_t pwm_name = g_APinDescription[ulPin].ulTCChannel; - uint8_t isTC = 0; - uint8_t Channelx; - Tc* TCx; - Tcc* TCCx; - - // if ((attr & PIN_ATTR_ANALOG) == PIN_ATTR_ANALOG) { - // 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 (g_APinDescription[ulPin].ulPinType == PIO_TIMER) - { - // Set selected Pin as TC/TCC Waveform out (PMUX : E ) - if(g_APinDescription[ulPin].ulPin <= 15) - { - PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = (uint32_t)(PORT_WRCONFIG_WRPINCFG |PORT_WRCONFIG_WRPMUX| 1 << (g_APinDescription[ulPin].ulPin)|(PORT_WRCONFIG_PMUXEN)|(0x4 << PORT_WRCONFIG_PMUX_Pos) ); - } else { - PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = (uint32_t)(PORT_WRCONFIG_WRPINCFG | PORT_WRCONFIG_WRPMUX| PORT_WRCONFIG_HWSEL| 1 << (g_APinDescription[ulPin].ulPin - 16)|(PORT_WRCONFIG_PMUXEN)|(0x4 << PORT_WRCONFIG_PMUX_Pos) ); - } - } - - if (g_APinDescription[ulPin].ulPinType == PIO_TIMER_ALT) - { - // Set selected Pin as TC/TCC Waveform out (PMUX : F ) - if(g_APinDescription[ulPin].ulPin <= 15) - { - PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = (uint32_t)(PORT_WRCONFIG_WRPINCFG |PORT_WRCONFIG_WRPMUX| 1 << (g_APinDescription[ulPin].ulPin)|(PORT_WRCONFIG_PMUXEN)|(0x5 << PORT_WRCONFIG_PMUX_Pos) ); - } else { - PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = (uint32_t)(PORT_WRCONFIG_WRPINCFG | PORT_WRCONFIG_WRPMUX| PORT_WRCONFIG_HWSEL| 1 << (g_APinDescription[ulPin].ulPin - 16)|(PORT_WRCONFIG_PMUXEN)|(0x5 << PORT_WRCONFIG_PMUX_Pos) ); - } - } - - - 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; - } - - // --Set PORT - - if (isTC) - { - // -- Enable clocks according to TCCx instance to use - switch ((uint32_t) TCx) - { - case (uint32_t) TC3 : - //Enable TCx Bus clock (Timer counter control clock) - PM->APBCMASK.reg |= PM_APBCMASK_TC3; - //Enable GCLK for TC3 (timer counter input clock) - GCLK->CLKCTRL.reg = (uint16_t) ((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | ( 0x1B << GCLK_CLKCTRL_ID_Pos))); - break; - - case (uint32_t) TC4 : - //Enable TCx Bus clock (Timer counter control clock) - PM->APBCMASK.reg |= PM_APBCMASK_TC4; - //Enable GCLK for TC4 (timer counter input clock) - GCLK->CLKCTRL.reg = (uint16_t) ((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | ( 0x1C << GCLK_CLKCTRL_ID_Pos))); - break; - - case (uint32_t) TC5 : - //Enable TCx Bus clock (Timer counter control clock) - PM->APBCMASK.reg |= PM_APBCMASK_TC5; - //Enable GCLK for TC5 (timer counter input clock) - GCLK->CLKCTRL.reg = (uint16_t) ((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | ( 0x1C << GCLK_CLKCTRL_ID_Pos))); - break; - - } - - // -- Configure TC - //DISABLE TCx - TCx->COUNT8.CTRLA.reg &=~(TC_CTRLA_ENABLE); - //Set Timer counter Mode to 8 bits - TCx->COUNT8.CTRLA.reg |= TC_CTRLA_MODE_COUNT8; - //Set TCx as normal PWM - TCx->COUNT8.CTRLA.reg |= TC_CTRLA_WAVEGEN_NPWM; - //Set TCx in waveform mode Normal PWM - TCx->COUNT8.CC[Channelx].reg = (uint8_t) ulValue; - //Set PER to maximum counter value (resolution : 0xFF) - TCx->COUNT8.PER.reg = 0xFF; - // Enable TCx - TCx->COUNT8.CTRLA.reg |= TC_CTRLA_ENABLE; - - } else { - - // -- Enable clocks according to TCCx instance to use - switch ((uint32_t) TCCx) - { - case (uint32_t) TCC0 : - //Enable TCC0 Bus clock (Timer counter control clock) - PM->APBCMASK.reg |= PM_APBCMASK_TCC0; - //Enable GCLK for TCC0 (timer counter input clock) - GCLK->CLKCTRL.reg = (uint16_t) ((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | ( 0x1A << GCLK_CLKCTRL_ID_Pos))); - break; - - case (uint32_t) TCC1 : - //Enable TCC1 Bus clock (Timer counter control clock) - PM->APBCMASK.reg |= PM_APBCMASK_TCC1; - //Enable GCLK for TCC1 (timer counter input clock) - GCLK->CLKCTRL.reg = (uint16_t) ((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | ( 0x1A << GCLK_CLKCTRL_ID_Pos))); - break; - - case (uint32_t) TCC2 : - //Enable TCC2 Bus clock (Timer counter control clock) - PM->APBCMASK.reg |= PM_APBCMASK_TCC2; - //Enable GCLK for TCC2 (timer counter input clock) - GCLK->CLKCTRL.reg = (uint16_t) ((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | ( 0x1B << GCLK_CLKCTRL_ID_Pos))); - break; - } - - // -- Configure TCC - - //DISABLE TCCx - TCCx->CTRLA.reg &=~(TCC_CTRLA_ENABLE); - //Set TCx as normal PWM - TCCx->WAVE.reg |= TCC_WAVE_WAVEGEN_NPWM; - //Set TCx in waveform mode Normal PWM - TCCx->CC[Channelx].reg = (uint32_t)ulValue; - //Set PER to maximum counter value (resolution : 0xFF) - TCCx->PER.reg = 0xFF; - //ENABLE TCCx - TCCx->CTRLA.reg |= TCC_CTRLA_ENABLE ; - } - return; - } - - // -- Defaults to digital write - pinMode(ulPin, OUTPUT); - //ulValue = mapResolution(ulValue, _writeResolution, 8); - if (ulValue < 128) - digitalWrite(ulPin, LOW); - else - digitalWrite(ulPin, HIGH); +void analogWrite( uint32_t ulPin, uint32_t ulValue ) + { + uint32_t attr = g_APinDescription[ulPin].ulPinAttribute ; + uint32_t pwm_name = g_APinDescription[ulPin].ulTCChannel ; + uint8_t isTC = 0 ; + uint8_t Channelx ; + Tc* TCx ; + Tcc* TCCx ; + + if ( (attr & PIN_ATTR_ANALOG) == PIN_ATTR_ANALOG ) + { + // 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 ( (g_APinDescription[ulPin].ulPinType == PIO_TIMER) || g_APinDescription[ulPin].ulPinType == PIO_TIMER_ALT ) + { + pinPeripheral( ulPin, g_APinDescription[ulPin].ulPinType ) ; + } + + 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; + } + + // --Set PORT + + if ( isTC ) + { + // -- Enable clocks according to TCCx instance to use + switch ( (uint32_t)TCx ) + { + case (uint32_t)TC3 : + //Enable TCx Bus clock (Timer counter control clock) + PM->APBCMASK.reg |= PM_APBCMASK_TC3; + //Enable GCLK for TC3 (timer counter input clock) + GCLK->CLKCTRL.reg = (uint16_t) ((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | ( 0x1B << GCLK_CLKCTRL_ID_Pos))); + break ; + + case (uint32_t) TC4 : + //Enable TCx Bus clock (Timer counter control clock) + PM->APBCMASK.reg |= PM_APBCMASK_TC4; + //Enable GCLK for TC4 (timer counter input clock) + GCLK->CLKCTRL.reg = (uint16_t) ((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | ( 0x1C << GCLK_CLKCTRL_ID_Pos))); + break ; + + case (uint32_t) TC5 : + //Enable TCx Bus clock (Timer counter control clock) + PM->APBCMASK.reg |= PM_APBCMASK_TC5; + //Enable GCLK for TC5 (timer counter input clock) + GCLK->CLKCTRL.reg = (uint16_t) ((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | ( 0x1C << GCLK_CLKCTRL_ID_Pos))); + break ; + } + + // -- Configure TC + //DISABLE TCx + TCx->COUNT8.CTRLA.reg &=~(TC_CTRLA_ENABLE); + //Set Timer counter Mode to 8 bits + TCx->COUNT8.CTRLA.reg |= TC_CTRLA_MODE_COUNT8; + //Set TCx as normal PWM + TCx->COUNT8.CTRLA.reg |= TC_CTRLA_WAVEGEN_NPWM; + //Set TCx in waveform mode Normal PWM + TCx->COUNT8.CC[Channelx].reg = (uint8_t) ulValue; + //Set PER to maximum counter value (resolution : 0xFF) + TCx->COUNT8.PER.reg = 0xFF; + // Enable TCx + TCx->COUNT8.CTRLA.reg |= TC_CTRLA_ENABLE; + + } + else + { + // -- Enable clocks according to TCCx instance to use + switch ( (uint32_t) TCCx ) + { + case (uint32_t) TCC0 : + //Enable TCC0 Bus clock (Timer counter control clock) + PM->APBCMASK.reg |= PM_APBCMASK_TCC0; + //Enable GCLK for TCC0 (timer counter input clock) + GCLK->CLKCTRL.reg = (uint16_t) ((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | ( 0x1A << GCLK_CLKCTRL_ID_Pos))); + break; + + case (uint32_t) TCC1 : + //Enable TCC1 Bus clock (Timer counter control clock) + PM->APBCMASK.reg |= PM_APBCMASK_TCC1; + //Enable GCLK for TCC1 (timer counter input clock) + GCLK->CLKCTRL.reg = (uint16_t) ((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | ( 0x1A << GCLK_CLKCTRL_ID_Pos))); + break; + + case (uint32_t) TCC2 : + //Enable TCC2 Bus clock (Timer counter control clock) + PM->APBCMASK.reg |= PM_APBCMASK_TCC2; + //Enable GCLK for TCC2 (timer counter input clock) + GCLK->CLKCTRL.reg = (uint16_t) ((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | ( 0x1B << GCLK_CLKCTRL_ID_Pos))); + break; + } + + // -- Configure TCC + + //DISABLE TCCx + TCCx->CTRLA.reg &=~(TCC_CTRLA_ENABLE); + //Set TCx as normal PWM + TCCx->WAVE.reg |= TCC_WAVE_WAVEGEN_NPWM; + //Set TCx in waveform mode Normal PWM + TCCx->CC[Channelx].reg = (uint32_t)ulValue; + //Set PER to maximum counter value (resolution : 0xFF) + TCCx->PER.reg = 0xFF; + //ENABLE TCCx + TCCx->CTRLA.reg |= TCC_CTRLA_ENABLE ; + } + + return ; + } + + // -- Defaults to digital write + pinMode( ulPin, OUTPUT ) ; + + //ulValue = mapResolution(ulValue, _writeResolution, 8); + + if ( ulValue < 128 ) + { + digitalWrite( ulPin, LOW ) ; + } + else + { + digitalWrite( ulPin, HIGH ) ; + } } #ifdef __cplusplus diff --git a/cores/arduino/wiring_analog.h b/cores/arduino/wiring_analog.h index ce732b24..a87e7d35 100644 --- a/cores/arduino/wiring_analog.h +++ b/cores/arduino/wiring_analog.h @@ -19,6 +19,8 @@ #ifndef _WIRING_ANALOG_ #define _WIRING_ANALOG_ +#include <stdint.h> + #ifdef __cplusplus extern "C" { #endif diff --git a/cores/validation/validation_core/build_as6/test.cppproj b/cores/validation/validation_core/build_as6/test.cppproj new file mode 100644 index 00000000..1f5cc024 --- /dev/null +++ b/cores/validation/validation_core/build_as6/test.cppproj @@ -0,0 +1,462 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <SchemaVersion>2.0</SchemaVersion> + <ProjectVersion>6.2</ProjectVersion> + <ToolchainName>com.Atmel.ARMGCC.CPP</ToolchainName> + <ProjectGuid>{b3f859ad-e162-4c2f-9684-eac6932fec80}</ProjectGuid> + <avrdevice>ATSAMD21G18A</avrdevice> + <avrdeviceseries>none</avrdeviceseries> + <OutputType>Executable</OutputType> + <Language>CPP</Language> + <OutputFileName>$(MSBuildProjectName)</OutputFileName> + <OutputFileExtension>.elf</OutputFileExtension> + <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory> + <AssemblyName>test</AssemblyName> + <Name>test</Name> + <RootNamespace>test</RootNamespace> + <ToolchainFlavour>Native</ToolchainFlavour> + <KeepTimersRunning>true</KeepTimersRunning> + <OverrideVtor>false</OverrideVtor> + <CacheFlash>false</CacheFlash> + <ProgFlashFromRam>true</ProgFlashFromRam> + <RamSnippetAddress>0x20000000</RamSnippetAddress> + <UncachedRange /> + <OverrideVtorValue>exception_table</OverrideVtorValue> + <BootSegment>2</BootSegment> + <eraseonlaunchrule>1</eraseonlaunchrule> + <AsfFrameworkConfig> + <framework-data xmlns=""> + <options /> + <configurations /> + <files /> + <documentation help="" /> + <offline-documentation help="" /> + <dependencies> + <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.17.0" /> + </dependencies> + </framework-data> + </AsfFrameworkConfig> + <avrtool>com.atmel.avrdbg.tool.edbg</avrtool> + <avrtoolinterface>SWD</avrtoolinterface> + <com_atmel_avrdbg_tool_samice> + <ToolOptions> + <InterfaceProperties> + </InterfaceProperties> + <InterfaceName>SWD</InterfaceName> + </ToolOptions> + <ToolType>com.atmel.avrdbg.tool.samice</ToolType> + <ToolNumber>28001042</ToolNumber> + <ToolName>SAM-ICE</ToolName> + </com_atmel_avrdbg_tool_samice> + <UseGdb>True</UseGdb> + <com_atmel_avrdbg_tool_edbg> + <ToolOptions> + <InterfaceProperties> + <SwdClock>4000000</SwdClock> + </InterfaceProperties> + <InterfaceName>SWD</InterfaceName> + </ToolOptions> + <ToolType>com.atmel.avrdbg.tool.edbg</ToolType> + <ToolNumber>ATML2320021800000012</ToolNumber> + <ToolName>EDBG</ToolName> + </com_atmel_avrdbg_tool_edbg> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> + <ToolchainSettings> + <ArmGccCpp> + <armgcc.common.outputfiles.hex>True</armgcc.common.outputfiles.hex> + <armgcc.common.outputfiles.lss>True</armgcc.common.outputfiles.lss> + <armgcc.common.outputfiles.eep>True</armgcc.common.outputfiles.eep> + <armgcc.common.outputfiles.bin>True</armgcc.common.outputfiles.bin> + <armgcc.common.outputfiles.srec>True</armgcc.common.outputfiles.srec> + <armgcc.compiler.symbols.DefSymbols> + <ListValues> + <Value>NDEBUG</Value> + </ListValues> + </armgcc.compiler.symbols.DefSymbols> + <armgcc.compiler.directories.IncludePaths> + <ListValues> + <Value>../../../../../../../tools/CMSIS/Device/ATMEL</Value> + <Value>../../../../../../../tools/CMSIS/CMSIS/Include</Value> + <Value>../../../../arduino</Value> + <Value>../../../../arduino/USB</Value> + <Value>../../../../../variants/arduino_zero</Value> + <Value>../../../../../libraries/SPI</Value> + <Value>../../../../../libraries/Wire</Value> + </ListValues> + </armgcc.compiler.directories.IncludePaths> + <armgcc.compiler.optimization.level>Optimize for size (-Os)</armgcc.compiler.optimization.level> + <armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection> + <armgcc.compiler.warnings.AllWarnings>True</armgcc.compiler.warnings.AllWarnings> + <armgcccpp.compiler.symbols.DefSymbols> + <ListValues> + <Value>NDEBUG</Value> + </ListValues> + </armgcccpp.compiler.symbols.DefSymbols> + <armgcccpp.compiler.directories.IncludePaths> + <ListValues> + <Value>../../../../../../../tools/CMSIS/Device/ATMEL</Value> + <Value>../../../../../../../tools/CMSIS/CMSIS/Include</Value> + <Value>../../../../arduino</Value> + <Value>../../../../arduino/USB</Value> + <Value>../../../../../variants/arduino_zero</Value> + <Value>../../../../../libraries/SPI</Value> + <Value>../../../../../libraries/Wire</Value> + </ListValues> + </armgcccpp.compiler.directories.IncludePaths> + <armgcccpp.compiler.optimization.level>Optimize for size (-Os)</armgcccpp.compiler.optimization.level> + <armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection> + <armgcccpp.compiler.warnings.AllWarnings>True</armgcccpp.compiler.warnings.AllWarnings> + <armgcccpp.linker.libraries.Libraries> + <ListValues> + <Value>libm</Value> + </ListValues> + </armgcccpp.linker.libraries.Libraries> + <armgcccpp.linker.libraries.LibrarySearchPaths> + <ListValues> + <Value>../cmsis/linkerScripts</Value> + </ListValues> + </armgcccpp.linker.libraries.LibrarySearchPaths> + <armgcccpp.linker.optimization.GarbageCollectUnusedSections>True</armgcccpp.linker.optimization.GarbageCollectUnusedSections> + <armgcccpp.linker.miscellaneous.LinkerFlags>-Tsamd21g18a_flash.ld</armgcccpp.linker.miscellaneous.LinkerFlags> + <armgcccpp.preprocessingassembler.general.IncludePaths> + <ListValues> + <Value>../../../../../../../tools/CMSIS/Device/ATMEL</Value> + <Value>../../../../../../../tools/CMSIS/CMSIS/Include</Value> + <Value>../../../../arduino</Value> + <Value>../../../../arduino/USB</Value> + <Value>../../../../../variants/arduino_zero</Value> + <Value>../../../../../libraries/SPI</Value> + <Value>../../../../../libraries/Wire</Value> + </ListValues> + </armgcccpp.preprocessingassembler.general.IncludePaths> + </ArmGccCpp> + </ToolchainSettings> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> + <ToolchainSettings> + <ArmGccCpp> + <armgcc.common.outputfiles.hex>True</armgcc.common.outputfiles.hex> + <armgcc.common.outputfiles.lss>True</armgcc.common.outputfiles.lss> + <armgcc.common.outputfiles.eep>True</armgcc.common.outputfiles.eep> + <armgcc.common.outputfiles.bin>True</armgcc.common.outputfiles.bin> + <armgcc.common.outputfiles.srec>True</armgcc.common.outputfiles.srec> + <armgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</armgcc.compiler.general.ChangeDefaultCharTypeUnsigned> + <armgcc.compiler.symbols.DefSymbols> + <ListValues> + <Value>DEBUG</Value> + </ListValues> + </armgcc.compiler.symbols.DefSymbols> + <armgcc.compiler.directories.DefaultIncludePath>False</armgcc.compiler.directories.DefaultIncludePath> + <armgcc.compiler.directories.IncludePaths> + <ListValues> + <Value>../../../../../../../tools/CMSIS/Device/ATMEL</Value> + <Value>../../../../../../../tools/CMSIS/CMSIS/Include</Value> + <Value>../../../../arduino</Value> + <Value>../../../../arduino/USB</Value> + <Value>../../../../../variants/arduino_zero</Value> + <Value>../../../../../libraries/SPI</Value> + <Value>../../../../../libraries/Wire</Value> + </ListValues> + </armgcc.compiler.directories.IncludePaths> + <armgcc.compiler.optimization.level>Optimize (-O1)</armgcc.compiler.optimization.level> + <armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection> + <armgcc.compiler.optimization.PrepareDataForGarbageCollection>True</armgcc.compiler.optimization.PrepareDataForGarbageCollection> + <armgcc.compiler.optimization.DebugLevel>Maximum (-g3)</armgcc.compiler.optimization.DebugLevel> + <armgcc.compiler.warnings.AllWarnings>True</armgcc.compiler.warnings.AllWarnings> + <armgcc.compiler.miscellaneous.OtherFlags>-std=c99</armgcc.compiler.miscellaneous.OtherFlags> + <armgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</armgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned> + <armgcccpp.compiler.symbols.DefSymbols> + <ListValues> + <Value>DEBUG</Value> + <Value>USB_VID=0x2341</Value> + <Value>USB_PID=0x004d</Value> + </ListValues> + </armgcccpp.compiler.symbols.DefSymbols> + <armgcccpp.compiler.directories.DefaultIncludePath>False</armgcccpp.compiler.directories.DefaultIncludePath> + <armgcccpp.compiler.directories.IncludePaths> + <ListValues> + <Value>../../../../../../../tools/CMSIS/Device/ATMEL</Value> + <Value>../../../../../../../tools/CMSIS/CMSIS/Include</Value> + <Value>../../../../arduino</Value> + <Value>../../../../arduino/USB</Value> + <Value>../../../../../variants/arduino_zero</Value> + <Value>../../../../../libraries/SPI</Value> + <Value>../../../../../libraries/Wire</Value> + </ListValues> + </armgcccpp.compiler.directories.IncludePaths> + <armgcccpp.compiler.optimization.level>Optimize (-O1)</armgcccpp.compiler.optimization.level> + <armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection> + <armgcccpp.compiler.optimization.PrepareDataForGarbageCollection>True</armgcccpp.compiler.optimization.PrepareDataForGarbageCollection> + <armgcccpp.compiler.optimization.DebugLevel>Maximum (-g3)</armgcccpp.compiler.optimization.DebugLevel> + <armgcccpp.compiler.warnings.AllWarnings>True</armgcccpp.compiler.warnings.AllWarnings> + <armgcccpp.compiler.miscellaneous.OtherFlags>-std=c++98</armgcccpp.compiler.miscellaneous.OtherFlags> + <armgcccpp.linker.general.UseNewlibNano>True</armgcccpp.linker.general.UseNewlibNano> + <armgcccpp.linker.libraries.Libraries> + <ListValues> + <Value>libm</Value> + </ListValues> + </armgcccpp.linker.libraries.Libraries> + <armgcccpp.linker.libraries.LibrarySearchPaths> + <ListValues> + <Value>../../../../../variants/arduino_zero/linker_scripts/gcc</Value> + </ListValues> + </armgcccpp.linker.libraries.LibrarySearchPaths> + <armgcccpp.linker.optimization.GarbageCollectUnusedSections>True</armgcccpp.linker.optimization.GarbageCollectUnusedSections> + <armgcccpp.linker.memorysettings.ExternalRAM /> + <armgcccpp.linker.miscellaneous.LinkerFlags>-Tflash.ld</armgcccpp.linker.miscellaneous.LinkerFlags> + <armgcccpp.assembler.general.IncludePaths> + <ListValues> + <Value>../../../arduino</Value> + </ListValues> + </armgcccpp.assembler.general.IncludePaths> + <armgcccpp.assembler.debugging.DebugLevel>Default (-g)</armgcccpp.assembler.debugging.DebugLevel> + <armgcccpp.preprocessingassembler.general.DefaultIncludePath>False</armgcccpp.preprocessingassembler.general.DefaultIncludePath> + <armgcccpp.preprocessingassembler.general.IncludePaths> + <ListValues> + <Value>../../../arduino</Value> + </ListValues> + </armgcccpp.preprocessingassembler.general.IncludePaths> + <armgcccpp.preprocessingassembler.debugging.DebugLevel>Default (-Wa,-g)</armgcccpp.preprocessingassembler.debugging.DebugLevel> + </ArmGccCpp> + </ToolchainSettings> + </PropertyGroup> + <ItemGroup> + <Folder Include="core" /> + <Folder Include="Wire" /> + <Folder Include="SPI" /> + <Folder Include="variant" /> + </ItemGroup> + <ItemGroup> + <Compile Include="..\..\..\..\libraries\SPI\SPI.cpp"> + <SubType>compile</SubType> + <Link>SPI\SPI.cpp</Link> + </Compile> + <Compile Include="..\..\..\..\libraries\SPI\SPI.h"> + <SubType>compile</SubType> + <Link>SPI\SPI.h</Link> + </Compile> + <Compile Include="..\..\..\..\libraries\Wire\Wire.cpp"> + <SubType>compile</SubType> + <Link>Wire\Wire.cpp</Link> + </Compile> + <Compile Include="..\..\..\..\libraries\Wire\Wire.h"> + <SubType>compile</SubType> + <Link>Wire\Wire.h</Link> + </Compile> + <Compile Include="..\..\..\..\variants\arduino_zero\pins_arduino.h"> + <SubType>compile</SubType> + <Link>variant\pins_arduino.h</Link> + </Compile> + <Compile Include="..\..\..\..\variants\arduino_zero\variant.cpp"> + <SubType>compile</SubType> + <Link>variant\variant.cpp</Link> + </Compile> + <Compile Include="..\..\..\..\variants\arduino_zero\variant.h"> + <SubType>compile</SubType> + <Link>variant\variant.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\Arduino.h"> + <SubType>compile</SubType> + <Link>core\Arduino.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\binary.h"> + <SubType>compile</SubType> + <Link>core\binary.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\Client.h"> + <SubType>compile</SubType> + <Link>core\Client.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\delay.c"> + <SubType>compile</SubType> + <Link>core\delay.c</Link> + </Compile> + <Compile Include="..\..\..\arduino\delay.h"> + <SubType>compile</SubType> + <Link>core\delay.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\HardwareSerial.h"> + <SubType>compile</SubType> + <Link>core\HardwareSerial.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\hooks.c"> + <SubType>compile</SubType> + <Link>core\hooks.c</Link> + </Compile> + <Compile Include="..\..\..\arduino\IPAddress.cpp"> + <SubType>compile</SubType> + <Link>core\IPAddress.cpp</Link> + </Compile> + <Compile Include="..\..\..\arduino\IPAddress.h"> + <SubType>compile</SubType> + <Link>core\IPAddress.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\itoa.c"> + <SubType>compile</SubType> + <Link>core\itoa.c</Link> + </Compile> + <Compile Include="..\..\..\arduino\itoa.h"> + <SubType>compile</SubType> + <Link>core\itoa.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\main.cpp"> + <SubType>compile</SubType> + <Link>core\main.cpp</Link> + </Compile> + <Compile Include="..\..\..\arduino\Print.cpp"> + <SubType>compile</SubType> + <Link>core\Print.cpp</Link> + </Compile> + <Compile Include="..\..\..\arduino\Print.h"> + <SubType>compile</SubType> + <Link>core\Print.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\Printable.h"> + <SubType>compile</SubType> + <Link>core\Printable.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\Reset.cpp"> + <SubType>compile</SubType> + <Link>core\Reset.cpp</Link> + </Compile> + <Compile Include="..\..\..\arduino\Reset.h"> + <SubType>compile</SubType> + <Link>core\Reset.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\RingBuffer.cpp"> + <SubType>compile</SubType> + <Link>core\RingBuffer.cpp</Link> + </Compile> + <Compile Include="..\..\..\arduino\RingBuffer.h"> + <SubType>compile</SubType> + <Link>core\RingBuffer.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\SERCOM.cpp"> + <SubType>compile</SubType> + <Link>core\SERCOM.cpp</Link> + </Compile> + <Compile Include="..\..\..\arduino\SERCOM.h"> + <SubType>compile</SubType> + <Link>core\SERCOM.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\Server.h"> + <SubType>compile</SubType> + <Link>core\Server.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\startup.c"> + <SubType>compile</SubType> + <Link>core\startup.c</Link> + </Compile> + <Compile Include="..\..\..\arduino\Stream.cpp"> + <SubType>compile</SubType> + <Link>core\Stream.cpp</Link> + </Compile> + <Compile Include="..\..\..\arduino\Stream.h"> + <SubType>compile</SubType> + <Link>core\Stream.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\syscalls.c"> + <SubType>compile</SubType> + <Link>core\syscalls.c</Link> + </Compile> + <Compile Include="..\..\..\arduino\syscalls.h"> + <SubType>compile</SubType> + <Link>core\syscalls.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\Tone.h"> + <SubType>compile</SubType> + <Link>core\Tone.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\Uart.cpp"> + <SubType>compile</SubType> + <Link>core\Uart.cpp</Link> + </Compile> + <Compile Include="..\..\..\arduino\Uart.h"> + <SubType>compile</SubType> + <Link>core\Uart.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\Udp.h"> + <SubType>compile</SubType> + <Link>core\Udp.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\WCharacter.h"> + <SubType>compile</SubType> + <Link>core\WCharacter.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\WInterrupts.h"> + <SubType>compile</SubType> + <Link>core\WInterrupts.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\wiring.c"> + <SubType>compile</SubType> + <Link>core\wiring.c</Link> + </Compile> + <Compile Include="..\..\..\arduino\wiring.h"> + <SubType>compile</SubType> + <Link>core\wiring.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\wiring_analog.c"> + <SubType>compile</SubType> + <Link>core\wiring_analog.c</Link> + </Compile> + <Compile Include="..\..\..\arduino\wiring_analog.h"> + <SubType>compile</SubType> + <Link>core\wiring_analog.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\wiring_constants.h"> + <SubType>compile</SubType> + <Link>core\wiring_constants.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\wiring_digital.c"> + <SubType>compile</SubType> + <Link>core\wiring_digital.c</Link> + </Compile> + <Compile Include="..\..\..\arduino\wiring_digital.h"> + <SubType>compile</SubType> + <Link>core\wiring_digital.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\wiring_private.h"> + <SubType>compile</SubType> + <Link>core\wiring_private.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\wiring_pulse.h"> + <SubType>compile</SubType> + <Link>core\wiring_pulse.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\wiring_shift.c"> + <SubType>compile</SubType> + <Link>core\wiring_shift.c</Link> + </Compile> + <Compile Include="..\..\..\arduino\wiring_shift.h"> + <SubType>compile</SubType> + <Link>core\wiring_shift.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\WMath.cpp"> + <SubType>compile</SubType> + <Link>core\WMath.cpp</Link> + </Compile> + <Compile Include="..\..\..\arduino\WMath.h"> + <SubType>compile</SubType> + <Link>core\WMath.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\WString.cpp"> + <SubType>compile</SubType> + <Link>core\WString.cpp</Link> + </Compile> + <Compile Include="..\..\..\arduino\WString.h"> + <SubType>compile</SubType> + <Link>core\WString.h</Link> + </Compile> + <Compile Include="..\..\..\arduino\WVariant.h"> + <SubType>compile</SubType> + <Link>core\WVariant.h</Link> + </Compile> + <Compile Include="..\test.cpp"> + <SubType>compile</SubType> + <Link>test.cpp</Link> + </Compile> + </ItemGroup> + <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" /> +</Project> \ No newline at end of file diff --git a/cores/validation/validation_core/test - Copy.cpp b/cores/validation/validation_core/test - Copy.cpp new file mode 100644 index 00000000..ac1e28d1 --- /dev/null +++ b/cores/validation/validation_core/test - Copy.cpp @@ -0,0 +1,100 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "Arduino.h" + +void setup( void ) +{ + // Initialize the digital pin as an output. + // Pin PIN_LED has a LED connected on most Arduino boards: + //pinMode( PIN_LED, OUTPUT ) ; + //digitalWrite( PIN_LED, LOW ) ; + + // Initialize the PIN_LED2 digital pin as an output. + pinMode( PIN_LED2, OUTPUT ) ; + digitalWrite( PIN_LED2, HIGH ) ; + + // Initialize the PIN_LED2 digital pin as an output. + pinMode( PIN_LED3, OUTPUT ) ; + digitalWrite( PIN_LED3, LOW ) ; + + // Initialize the PIN 2 digital pin as an input. + pinMode( 2, INPUT ) ; + +//********************************************** +// Clock output on pin 4 for measure + + pinPeripheral( 4, PIO_AC_CLK ) ; // Clock Gen 0 + pinPeripheral( 5, PIO_AC_CLK ) ; // Clock Gen 1 + pinPeripheral( 13, PIO_AC_CLK ) ; // Clock Gen 3 + +//********************************************** + + Serial.begin( 115200 ) ; +} + +static void led_step1( void ) +{ +// digitalWrite( PIN_LED, LOW ) ; // set the LED on + digitalWrite( PIN_LED2, LOW ) ; // set the red LED off + digitalWrite( PIN_LED3, HIGH ) ; // set the red LED off +} + +static void led_step2( void ) +{ +// digitalWrite( PIN_LED, HIGH ) ; // set the LED off + digitalWrite( PIN_LED2, HIGH ) ; // set the red LED on + digitalWrite( PIN_LED3, LOW ) ; // set the red LED on +} + +void loop( void ) +{ + volatile int pin_value=0 ; + + // Test digitalWrite + led_step1() ; + delay( 1000 ) ; // wait for a second + led_step2() ; + delay( 1000 ) ; // wait for a second + + // Test Serial output + Serial.write( '-' ) ; // send a char + Serial.write( "test1\n" ) ; // send a string + Serial.write( "test2" ) ; // send another string + + // Test digitalRead: connect pin 2 to either GND or 3.3V. !!!! NOT on 5V pin !!!! + pin_value=digitalRead( 2 ) ; + Serial.write( "pin 2 value is " ) ; + Serial.write( (pin_value == LOW)?"LOW\n":"HIGH\n" ) ; + delay( 1000 ) ; // wait for a second + + +/* + Serial.print("Analog pins: "); + + for ( int i = A1 ; i <= A0+NUM_ANALOG_INPUTS ; i++ ) + { + int a = analogRead(i); + Serial.print(a, DEC); + Serial.print(" "); + } + Serial.println(); + delay(100); +*/ + +} diff --git a/cores/validation/validation_core/test.cpp b/cores/validation/validation_core/test.cpp index e3387a8b..9202715c 100644 --- a/cores/validation/validation_core/test.cpp +++ b/cores/validation/validation_core/test.cpp @@ -21,7 +21,7 @@ void setup( void ) { // Initialize the digital pin as an output. - // Pin PIN_LED has a LED connected on most Arduino boards: + // Pin PIN_LED has an LED connected on most Arduino boards: //pinMode( PIN_LED, OUTPUT ) ; //digitalWrite( PIN_LED, LOW ) ; @@ -62,27 +62,28 @@ static void led_step2( void ) digitalWrite( PIN_LED3, LOW ) ; // set the red LED on } -static void analog_write_step (void) +static void analog_write_step( void ) { + uint8_t duty_cycle ; + // test PWM generation on all PWM pins (duty cycle from 0x00 to 0xFF) - for( uint8_t duty_cycle = 0x00;duty_cycle<=0xFF;duty_cycle++) + for( duty_cycle = 0x00 ; duty_cycle <= 0xFF ; duty_cycle++ ) { - analogWrite(13,duty_cycle); - analogWrite(12,duty_cycle); - analogWrite(11,duty_cycle); - analogWrite(10,duty_cycle); - analogWrite(9,duty_cycle); - analogWrite(8,duty_cycle); - analogWrite(7,duty_cycle); - analogWrite(6,duty_cycle); - analogWrite(5,duty_cycle); - analogWrite(4,duty_cycle); - analogWrite(3,duty_cycle); - analogWrite(2,duty_cycle); + analogWrite( 13, duty_cycle ) ; + analogWrite( 12, duty_cycle ) ; + analogWrite( 11, duty_cycle ) ; + analogWrite( 10 ,duty_cycle ) ; + analogWrite( 9, duty_cycle ) ; + analogWrite( 8, duty_cycle ) ; + analogWrite( 7, duty_cycle ) ; + analogWrite( 6, duty_cycle ) ; + analogWrite( 5, duty_cycle ) ; + analogWrite( 4, duty_cycle ) ; + analogWrite( 3, duty_cycle ) ; +// analogWrite( 2, duty_cycle ) ; + delay( 10 ) ; } - - } void loop( void ) @@ -120,5 +121,4 @@ void loop( void ) Serial.println(); delay(100); */ - } diff --git a/variants/arduino_zero/variant.cpp b/variants/arduino_zero/variant.cpp index 34ed553d..224f8851 100644 --- a/variants/arduino_zero/variant.cpp +++ b/variants/arduino_zero/variant.cpp @@ -111,33 +111,33 @@ const PinDescription g_APinDescription[]= { PORTA, 10, PIO_SERCOM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // RX: SERCOM0/PAD[2] { PORTA, 11, PIO_SERCOM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // TX: SERCOM0/PAD[3] - // 2..12 - { PORTA, 8, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH0, TCC0_CH0 }, // TCC0/WO[0] - { PORTA, 9, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH1, TCC0_CH1 }, // TCC0/WO[1] - { PORTA, 14, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH4, TCC0_CH4 }, // TCC0/WO[4] - { PORTA, 15, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH5, TCC0_CH5 }, // TCC0/WO[5] - { PORTA, 20, PIO_TIMER_ALT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH6, TCC0_CH6 }, // TCC0/WO[6] - { PORTA, 21, PIO_TIMER_ALT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH7, TCC0_CH7 }, // TCC0/WO[7] - { PORTA, 6, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM1_CH0, TCC1_CH0 }, // TCC1/WO[0] - { PORTA, 7, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM1_CH1, TCC1_CH1 }, // TCC1/WO[1] - { PORTA, 18, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM3_CH0, TC3_CH0 }, // TC3/WO[0] - { PORTA, 16, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM2_CH0, TCC2_CH0 }, // TCC2/WO[0] - { PORTA, 19, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM3_CH1, TC3_CH1 }, // TC3/WO[1] - - // 13 (LED) - { PORTA, 17, PIO_PWM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM2_CH1, NOT_ON_TIMER }, // TCC2/WO[1] - - // 14 (GND) - { NOT_A_PORT, 0, PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, - - // 15 (AREF) - { PORTA, 3, PIO_ANALOG, PIN_ATTR_ANALOG, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // DAC/VREFP - - // 16..17 I2C (SDA/SCL and also EDBG:SDA/SCL) + // 2..12 + { PORTA, 8, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH0, TCC0_CH0 }, // TCC0/WO[0] + { PORTA, 9, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH1, TCC0_CH1 }, // TCC0/WO[1] + { PORTA, 14, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH4, TCC0_CH4 }, // TCC0/WO[4] + { PORTA, 15, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH5, TCC0_CH5 }, // TCC0/WO[5] + { PORTA, 20, PIO_TIMER_ALT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH6, TCC0_CH6 }, // TCC0/WO[6] + { PORTA, 21, PIO_TIMER_ALT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH7, TCC0_CH7 }, // TCC0/WO[7] + { PORTA, 6, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM1_CH0, TCC1_CH0 }, // TCC1/WO[0] + { PORTA, 7, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM1_CH1, TCC1_CH1 }, // TCC1/WO[1] + { PORTA, 18, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM3_CH0, TC3_CH0 }, // TC3/WO[0] + { PORTA, 16, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM2_CH0, TCC2_CH0 }, // TCC2/WO[0] + { PORTA, 19, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM3_CH1, TC3_CH1 }, // TC3/WO[1] + + // 13 (LED) + { PORTA, 17, PIO_PWM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM2_CH1, NOT_ON_TIMER }, // TCC2/WO[1] + + // 14 (GND) + { NOT_A_PORT, 0, PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, + + // 15 (AREF) + { PORTA, 3, PIO_ANALOG, PIN_ATTR_ANALOG, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // DAC/VREFP + + // 16..17 I2C (SDA/SCL and also EDBG:SDA/SCL) { PORTA, 22, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SDA: SERCOM3/PAD[0] { PORTA, 23, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SCL: SERCOM3/PAD[1] - // 18..23 SPI (ICSP:MISO,SCK,MOSI) + // 18..23 SPI (ICSP:MISO,SCK,MOSI) { PORTA, 12, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // MISO: SERCOM4/PAD[0] { NOT_A_PORT, 0, PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // 5V0 { PORTB, 11, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SCK: SERCOM4/PAD[3] @@ -146,25 +146,25 @@ const PinDescription g_APinDescription[]= { NOT_A_PORT, 0, PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // GND // 24..29 - Analog pins - // -------------------- - // 24 - A0 (DAC output) - { PORTA, 2, PIO_ANALOG, PIN_ATTR_ANALOG, DAC_Channel0, NOT_ON_PWM, NOT_ON_TIMER }, // DAC/VOUT + // -------------------- + // 24 - A0 (DAC output) + { PORTA, 2, PIO_ANALOG, PIN_ATTR_ANALOG, DAC_Channel0, NOT_ON_PWM, NOT_ON_TIMER }, // DAC/VOUT - // 25..29 - A1-A5 + // 25..29 - A1-A5 { PORTB, 8, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel2, NOT_ON_PWM, NOT_ON_TIMER }, // ADC/AIN[2] { PORTB, 9, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel3, NOT_ON_PWM, NOT_ON_TIMER }, // ADC/AIN[3] { PORTA, 4, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel4, NOT_ON_PWM, NOT_ON_TIMER }, // ADC/AIN[4] { PORTA, 5, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel5, NOT_ON_PWM, NOT_ON_TIMER }, // ADC/AIN[5] { PORTA, 2, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel10, NOT_ON_PWM, NOT_ON_TIMER }, // ADC/AIN[10] - // 30..31 - RX/TX LEDS (PB03/PA27) - { PORTB, 3, PIO_OUTPUT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // use as pure output - { PORTA, 27, PIO_OUTPUT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // use as pure output + // 30..31 - RX/TX LEDS (PB03/PA27) + { PORTB, 3, PIO_OUTPUT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // use as pure output + { PORTA, 27, PIO_OUTPUT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // use as pure output - // 32..33 - USB - { PORTA, 28, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // USB/SOF - { PORTA, 24, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // USB/DM - { PORTA, 25, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // USB/DP + // 32..33 - USB + { PORTA, 28, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // USB/SOF + { PORTA, 24, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // USB/DM + { PORTA, 25, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // USB/DP // 35 .. 46 - EDBG // ---------------------- @@ -172,19 +172,19 @@ const PinDescription g_APinDescription[]= { PORTB, 22, PIO_SERCOM_ALT, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // TX: SERCOM5/PAD[2] { PORTB, 23, PIO_SERCOM_ALT, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // RX: SERCOM5/PAD[3] - // 37/38 I2C (SDA/SCL and also EDBG:SDA/SCL) + // 37/38 I2C (SDA/SCL and also EDBG:SDA/SCL) { PORTA, 22, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SDA: SERCOM3/PAD[0] { PORTA, 23, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SCL: SERCOM3/PAD[1] - // 39 .. 42 - EDBG/SPI - { PORTA, 19, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // MISO: SERCOM1/PAD[3] - { PORTA, 16, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // MOSI: SERCOM1/PAD[0] - { PORTA, 18, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SS: SERCOM1/PAD[2] - { PORTA, 17, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SCK: SERCOM1/PAD[1] - - // 43 .. 46 - EDBG/Digital - { PORTA, 13, PIO_PWM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM0_CH5, NOT_ON_TIMER }, // EIC/EXTINT[13] *TCC2/WO[1] TCC0/WO[7] - { PORTA, 21, PIO_PWM_ALT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM0_CH7, NOT_ON_TIMER }, // Pin 7 - { PORTA, 6, PIO_PWM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM1_CH0, NOT_ON_TIMER }, // Pin 8 - { PORTA, 7, PIO_PWM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM1_CH1, NOT_ON_TIMER }, // Pin 9 + // 39 .. 42 - EDBG/SPI + { PORTA, 19, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // MISO: SERCOM1/PAD[3] + { PORTA, 16, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // MOSI: SERCOM1/PAD[0] + { PORTA, 18, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SS: SERCOM1/PAD[2] + { PORTA, 17, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SCK: SERCOM1/PAD[1] + + // 43 .. 46 - EDBG/Digital + { PORTA, 13, PIO_PWM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM0_CH5, NOT_ON_TIMER }, // EIC/EXTINT[13] *TCC2/WO[1] TCC0/WO[7] + { PORTA, 21, PIO_PWM_ALT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM0_CH7, NOT_ON_TIMER }, // Pin 7 + { PORTA, 6, PIO_PWM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM1_CH0, NOT_ON_TIMER }, // Pin 8 + { PORTA, 7, PIO_PWM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM1_CH1, NOT_ON_TIMER }, // Pin 9 } ; diff --git a/variants/arduino_zero/variant.h b/variants/arduino_zero/variant.h index def09d70..aa76bd06 100644 --- a/variants/arduino_zero/variant.h +++ b/variants/arduino_zero/variant.h @@ -62,7 +62,7 @@ extern "C"{ #define digitalPinToPort(P) ( &(PORT->Group[g_APinDescription[P].ulPort]) ) #define digitalPinToBitMask(P) ( 1 << g_APinDescription[P].ulPin ) -#define digitalPinToTimer(P) ( ) +#define digitalPinToTimer(P) ( ) //#define analogInPinToBit(P) ( ) #define portOutputRegister(port) ( &(port->OUT) ) #define portInputRegister(port) ( &(port->IN) ) @@ -70,7 +70,7 @@ extern "C"{ #define digitalPinHasPWM(P) ( g_APinDescription[P].ulPWMChannel != NOT_ON_PWM || g_APinDescription[P].ulTCChannel != NOT_ON_TIMER ) // Interrupts -#define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1) +#define digitalPinToInterrupt(p) (-1) // ((p) < NUM_DIGITAL_PINS ? (p) : -1) // LEDs #define PIN_LED_13 (13u) -- GitLab