atmel-samd: Slim down the pin struct to save ~1200 bytes.

This commit is contained in:
Scott Shawcroft 2016-12-01 13:47:18 -08:00
parent f4a1da4be9
commit 03f49f8209
6 changed files with 200 additions and 186 deletions

View File

@ -40,30 +40,30 @@
#include "py/obj.h" #include "py/obj.h"
typedef struct { typedef struct {
Sercom *const sercom; Sercom *const sercom;
uint8_t pad; uint8_t pad;
uint32_t pinmux;
} pin_sercom_t; } pin_sercom_t;
typedef struct { typedef struct {
Tc *const tc; union {
Tcc *const tcc; Tc *const tc;
uint8_t channel; Tcc *const tcc;
uint8_t wave_output; };
uint32_t pin; bool is_tc:1;
uint32_t mux; uint8_t channel:3;
uint8_t wave_output:4;
} pin_timer_t; } pin_timer_t;
#define NUM_SERCOMS_PER_PIN 2 #define NUM_SERCOMS_PER_PIN 2
typedef struct { typedef struct {
mp_obj_base_t base; mp_obj_base_t base;
qstr name; qstr name;
uint32_t pin; uint8_t pin;
bool has_adc; bool has_adc:1;
enum adc_positive_input adc_input; enum adc_positive_input adc_input:7;
pin_timer_t primary_timer; pin_timer_t primary_timer; // Mux E
pin_timer_t secondary_timer; pin_timer_t secondary_timer; // Mux F
pin_sercom_t sercom[NUM_SERCOMS_PER_PIN]; pin_sercom_t sercom[NUM_SERCOMS_PER_PIN]; // Mux C and D
} mcu_pin_obj_t; } mcu_pin_obj_t;
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_TYPES_H__ #endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_TYPES_H__

View File

@ -31,6 +31,7 @@
#include "py/nlr.h" #include "py/nlr.h"
#include "asf/sam0/drivers/sercom/i2c/i2c_master.h" #include "asf/sam0/drivers/sercom/i2c/i2c_master.h"
#include "samd21_pins.h"
// We use ENABLE registers below we don't want to treat as a macro. // We use ENABLE registers below we don't want to treat as a macro.
#undef ENABLE #undef ENABLE
@ -54,11 +55,11 @@ void common_hal_nativeio_i2c_construct(nativeio_i2c_obj_t *self,
sda->sercom[i].pad != 0) { sda->sercom[i].pad != 0) {
continue; continue;
} }
sda_pinmux = sda->sercom[i].pinmux; sda_pinmux = PINMUX(sda->pin, (i == 0) ? MUX_C : MUX_D);
for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) { for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) {
if (potential_sercom == scl->sercom[j].sercom && if (potential_sercom == scl->sercom[j].sercom &&
scl->sercom[j].pad == 1) { scl->sercom[j].pad == 1) {
scl_pinmux = scl->sercom[j].pinmux; scl_pinmux = PINMUX(scl->pin, (j == 0) ? MUX_C : MUX_D);
sercom = potential_sercom; sercom = potential_sercom;
break; break;
} }

View File

@ -29,35 +29,20 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-bindings/nativeio/PWMOut.h" #include "shared-bindings/nativeio/PWMOut.h"
#include "samd21_pins.h"
void common_hal_nativeio_pwmout_construct(nativeio_pwmout_obj_t* self, const mcu_pin_obj_t* pin, uint16_t duty) { void common_hal_nativeio_pwmout_construct(nativeio_pwmout_obj_t* self, const mcu_pin_obj_t* pin, uint16_t duty) {
self->pin = pin; self->pin = pin;
self->using_primary_timer = true; self->using_primary_timer = true;
if (pin->primary_timer.tc == 0 && pin->primary_timer.tcc == 0 && if (pin->primary_timer.tc == 0 && pin->secondary_timer.tc == 0) {
pin->secondary_timer.tc == 0 && pin->secondary_timer.tcc == 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"PWM not supported on pin %q", self->pin->name)); "PWM not supported on pin %q", self->pin->name));
} }
// TODO(tannewt): Support output on multiple timer channels at once. // TODO(tannewt): Support output on multiple timer channels at once.
const pin_timer_t* t = &pin->primary_timer; const pin_timer_t* t = &pin->primary_timer;
if (t->tcc != 0) { if (t->is_tc) {
struct tcc_config config_tcc;
tcc_get_config_defaults(&config_tcc, t->tcc);
config_tcc.counter.clock_prescaler = TCC_CLOCK_PRESCALER_DIV256;
config_tcc.counter.period = 0xFF;
config_tcc.compare.wave_generation = TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM;
config_tcc.compare.match[t->channel] = duty;
config_tcc.pins.enable_wave_out_pin[t->wave_output] = true;
config_tcc.pins.wave_out_pin[t->wave_output] = t->pin;
config_tcc.pins.wave_out_pin_mux[t->wave_output] = t->mux;
tcc_init(&self->tcc_instance, t->tcc, &config_tcc);
tcc_enable(&self->tcc_instance);
} else {
struct tc_config config_tc; struct tc_config config_tc;
tc_get_config_defaults(&config_tc); tc_get_config_defaults(&config_tc);
@ -68,12 +53,28 @@ void common_hal_nativeio_pwmout_construct(nativeio_pwmout_obj_t* self, const mcu
config_tc.counter_8_bit.compare_capture_channel[t->channel] = duty; config_tc.counter_8_bit.compare_capture_channel[t->channel] = duty;
config_tc.pwm_channel[t->wave_output].enabled = true; config_tc.pwm_channel[t->wave_output].enabled = true;
config_tc.pwm_channel[t->wave_output].pin_out = t->pin; config_tc.pwm_channel[t->wave_output].pin_out = pin->pin;
config_tc.pwm_channel[t->wave_output].pin_mux = t->mux; config_tc.pwm_channel[t->wave_output].pin_mux = MUX_E;
tc_init(&self->tc_instance, t->tc, &config_tc); tc_init(&self->tc_instance, t->tc, &config_tc);
tc_enable(&self->tc_instance); tc_enable(&self->tc_instance);
} else {
struct tcc_config config_tcc;
tcc_get_config_defaults(&config_tcc, t->tcc);
config_tcc.counter.clock_prescaler = TCC_CLOCK_PRESCALER_DIV256;
config_tcc.counter.period = 0xFF;
config_tcc.compare.wave_generation = TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM;
config_tcc.compare.match[t->channel] = duty;
config_tcc.pins.enable_wave_out_pin[t->wave_output] = true;
config_tcc.pins.wave_out_pin[t->wave_output] = pin->pin;
config_tcc.pins.wave_out_pin_mux[t->wave_output] = MUX_E;
tcc_init(&self->tcc_instance, t->tcc, &config_tcc);
tcc_enable(&self->tcc_instance);
} }
} }
@ -82,10 +83,10 @@ extern void common_hal_nativeio_pwmout_deinit(nativeio_pwmout_obj_t* self) {
if (!self->using_primary_timer) { if (!self->using_primary_timer) {
t = &self->pin->secondary_timer; t = &self->pin->secondary_timer;
} }
if (t->tcc != 0) { if (t->is_tc) {
tcc_disable(&self->tcc_instance);
} else {
tc_disable(&self->tc_instance); tc_disable(&self->tc_instance);
} else {
tcc_disable(&self->tcc_instance);
} }
} }

View File

@ -29,6 +29,7 @@
#include "shared-bindings/nativeio/SPI.h" #include "shared-bindings/nativeio/SPI.h"
#include "py/nlr.h" #include "py/nlr.h"
#include "samd21_pins.h"
// We use ENABLE registers below we don't want to treat as a macro. // We use ENABLE registers below we don't want to treat as a macro.
#undef ENABLE #undef ENABLE
@ -57,12 +58,12 @@ void common_hal_nativeio_spi_construct(nativeio_spi_obj_t *self,
potential_sercom->SPI.CTRLA.bit.ENABLE != 0) { potential_sercom->SPI.CTRLA.bit.ENABLE != 0) {
continue; continue;
} }
clock_pinmux = clock->sercom[i].pinmux; clock_pinmux = PINMUX(clock->pin, (i == 0) ? MUX_C : MUX_D);
clock_pad = clock->sercom[i].pad; clock_pad = clock->sercom[i].pad;
for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) { for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) {
if (!mosi_none) { if (!mosi_none) {
if(potential_sercom == mosi->sercom[j].sercom) { if(potential_sercom == mosi->sercom[j].sercom) {
mosi_pinmux = mosi->sercom[j].pinmux; mosi_pinmux = PINMUX(mosi->pin, (j == 0) ? MUX_C : MUX_D);
mosi_pad = mosi->sercom[j].pad; mosi_pad = mosi->sercom[j].pad;
if (miso_none) { if (miso_none) {
sercom = potential_sercom; sercom = potential_sercom;
@ -74,7 +75,7 @@ void common_hal_nativeio_spi_construct(nativeio_spi_obj_t *self,
if (!miso_none) { if (!miso_none) {
for (int k = 0; k < NUM_SERCOMS_PER_PIN; k++) { for (int k = 0; k < NUM_SERCOMS_PER_PIN; k++) {
if (potential_sercom == miso->sercom[k].sercom) { if (potential_sercom == miso->sercom[k].sercom) {
miso_pinmux = miso->sercom[k].pinmux; miso_pinmux = PINMUX(miso->pin, (k == 0) ? MUX_C : MUX_D);
miso_pad = miso->sercom[k].pad; miso_pad = miso->sercom[k].pad;
sercom = potential_sercom; sercom = potential_sercom;
break; break;

View File

@ -2,26 +2,31 @@
#include "samd21_pins.h" #include "samd21_pins.h"
#define SERCOM(p_sercom, p_pad, p_pinmux) \ #define SERCOM(p_sercom, p_pad) \
{ \ { \
.sercom = p_sercom, \ .sercom = p_sercom, \
.pad = p_pad, \ .pad = p_pad \
.pinmux = p_pinmux \
} }
#define NO_SERCOM SERCOM(0, 0, 0) #define NO_SERCOM SERCOM(0, 0)
#define TIMER(p_tc, p_tcc, p_channel, p_wave_output, p_pin, p_mux) \ #define TCC(p_tcc, p_channel, p_wave_output) \
{ \
.tcc = p_tcc, \
.is_tc = false, \
.channel = p_channel, \
.wave_output = p_wave_output \
}
#define TC(p_tc, p_channel, p_wave_output) \
{ \ { \
.tc = p_tc, \ .tc = p_tc, \
.tcc = p_tcc, \ .is_tc = true, \
.channel = p_channel, \ .channel = p_channel, \
.wave_output = p_wave_output, \ .wave_output = p_wave_output \
.pin = p_pin, \
.mux = p_mux \
} }
#define NO_TIMER TIMER(0, 0, 0, 0, 0, 0) #define NO_TIMER TCC(0, 0, 0)
// This macro is used to simplify pin definition in boards/<board>/pins.c // This macro is used to simplify pin definition in boards/<board>/pins.c
#define PIN(p_name, p_has_adc, p_adc_input, p_primary_timer, \ #define PIN(p_name, p_has_adc, p_adc_input, p_primary_timer, \
@ -42,16 +47,16 @@ const mcu_pin_obj_t pin_## p_name = { \
// Pins in datasheet order. // Pins in datasheet order.
#ifdef PIN_PA00 #ifdef PIN_PA00
PIN(PA00, false, NO_ADC_INPUT, \ PIN(PA00, false, NO_ADC_INPUT, \
TIMER(0, TCC2, 0, 0, PIN_PA00E_TCC2_WO0, MUX_PA00E_TCC2_WO0), TCC(TCC2, 0, 0),
NO_TIMER, NO_TIMER,
SERCOM(SERCOM1, 0, PINMUX_PA00D_SERCOM1_PAD0), SERCOM(SERCOM1, 0),
NO_SERCOM); NO_SERCOM);
#endif #endif
#ifdef PIN_PA01 #ifdef PIN_PA01
PIN(PA01, false, NO_ADC_INPUT, PIN(PA01, false, NO_ADC_INPUT,
TIMER(0, TCC2, 1, 1, PIN_PA01E_TCC2_WO1, MUX_PA01E_TCC2_WO1), TCC(TCC2, 1, 1),
NO_TIMER, NO_TIMER,
SERCOM(SERCOM1, 1, PINMUX_PA01D_SERCOM1_PAD1), SERCOM(SERCOM1, 1),
NO_SERCOM); NO_SERCOM);
#endif #endif
#ifdef PIN_PA02 #ifdef PIN_PA02
@ -98,139 +103,139 @@ PIN(PB07, true, ADC_POSITIVE_INPUT_PIN15,
#endif #endif
#ifdef PIN_PB08 #ifdef PIN_PB08
PIN(PB08, true, ADC_POSITIVE_INPUT_PIN2, PIN(PB08, true, ADC_POSITIVE_INPUT_PIN2,
TIMER(TC4, 0, 0, 0, PIN_PB08E_TC4_WO0, MUX_PB08E_TC4_WO0), TC(TC4, 0, 0),
NO_TIMER, NO_TIMER,
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM4, 0, PINMUX_PB08D_SERCOM4_PAD0)); SERCOM(SERCOM4, 0));
#endif #endif
#ifdef PIN_PB09 #ifdef PIN_PB09
PIN(PB09, true, ADC_POSITIVE_INPUT_PIN3, PIN(PB09, true, ADC_POSITIVE_INPUT_PIN3,
TIMER(TC4, 0, 1, 1, PIN_PB09E_TC4_WO1, MUX_PB09E_TC4_WO1), TC(TC4, 1, 1),
NO_TIMER, NO_TIMER,
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM4, 1, PINMUX_PB09D_SERCOM4_PAD1)); SERCOM(SERCOM4, 1));
#endif #endif
#ifdef PIN_PA04 #ifdef PIN_PA04
PIN(PA04, true, ADC_POSITIVE_INPUT_PIN4, PIN(PA04, true, ADC_POSITIVE_INPUT_PIN4,
TIMER(0, TCC0, 0, 0, PIN_PA04E_TCC0_WO0, MUX_PA04E_TCC0_WO0), TCC(TCC0, 0, 0),
NO_TIMER, NO_TIMER,
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM0, 0, PINMUX_PA04D_SERCOM0_PAD0)); SERCOM(SERCOM0, 0));
#endif #endif
#ifdef PIN_PA05 #ifdef PIN_PA05
PIN(PA05, true, ADC_POSITIVE_INPUT_PIN5, PIN(PA05, true, ADC_POSITIVE_INPUT_PIN5,
TIMER(0, TCC0, 1, 1, PIN_PA05E_TCC0_WO1, MUX_PA05E_TCC0_WO1), TCC(TCC0, 1, 1),
NO_TIMER, NO_TIMER,
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM0, 1, PINMUX_PA05D_SERCOM0_PAD1)); SERCOM(SERCOM0, 1));
#endif #endif
#ifdef PIN_PA06 #ifdef PIN_PA06
PIN(PA06, true, ADC_POSITIVE_INPUT_PIN6, PIN(PA06, true, ADC_POSITIVE_INPUT_PIN6,
TIMER(0, TCC1, 0, 0, PIN_PA06E_TCC1_WO0, MUX_PA06E_TCC1_WO0), TCC(TCC1, 0, 0),
NO_TIMER, NO_TIMER,
SERCOM(SERCOM0, 2, PINMUX_PA06D_SERCOM0_PAD2), SERCOM(SERCOM0, 2),
NO_SERCOM); NO_SERCOM);
#endif #endif
#ifdef PIN_PA07 #ifdef PIN_PA07
PIN(PA07, true, ADC_POSITIVE_INPUT_PIN7, PIN(PA07, true, ADC_POSITIVE_INPUT_PIN7,
TIMER(0, TCC1, 1, 1, PIN_PA07E_TCC1_WO1, MUX_PA07E_TCC1_WO1), TCC(TCC1, 1, 1),
NO_TIMER, NO_TIMER,
SERCOM(SERCOM0, 3, PINMUX_PA07D_SERCOM0_PAD3), SERCOM(SERCOM0, 3),
NO_SERCOM); NO_SERCOM);
#endif #endif
#ifdef PIN_PA08 #ifdef PIN_PA08
PIN(PA08, true, ADC_POSITIVE_INPUT_PIN17, PIN(PA08, true, ADC_POSITIVE_INPUT_PIN17,
TIMER(0, TCC0, 0, 0, PIN_PA08E_TCC0_WO0, MUX_PA08E_TCC0_WO0), TCC(TCC0, 0, 0),
TIMER(0, TCC1, 2, 2, PIN_PA08F_TCC1_WO2, MUX_PA08F_TCC1_WO2), TCC(TCC1, 2, 2),
SERCOM(SERCOM0, 0, PINMUX_PA08C_SERCOM0_PAD0), SERCOM(SERCOM0, 0),
SERCOM(SERCOM2, 0, PINMUX_PA08D_SERCOM2_PAD0)); SERCOM(SERCOM2, 0));
#endif #endif
#ifdef PIN_PA09 #ifdef PIN_PA09
PIN(PA09, true, ADC_POSITIVE_INPUT_PIN17, PIN(PA09, true, ADC_POSITIVE_INPUT_PIN17,
TIMER(0, TCC0, 1, 1, PIN_PA09E_TCC0_WO1, MUX_PA09E_TCC0_WO1), TCC(TCC0, 1, 1),
TIMER(0, TCC1, 3, 3, PIN_PA09F_TCC1_WO3, MUX_PA09F_TCC1_WO3), TCC(TCC1, 3, 3),
SERCOM(SERCOM0, 1, PINMUX_PA09C_SERCOM0_PAD1), SERCOM(SERCOM0, 1),
SERCOM(SERCOM2, 1, PINMUX_PA09D_SERCOM2_PAD1)); SERCOM(SERCOM2, 1));
#endif #endif
#ifdef PIN_PA10 #ifdef PIN_PA10
PIN(PA10, true, ADC_POSITIVE_INPUT_PIN18, PIN(PA10, true, ADC_POSITIVE_INPUT_PIN18,
TIMER(0, TCC1, 0, 0, PIN_PA10E_TCC1_WO0, MUX_PA10E_TCC1_WO0), TCC(TCC1, 0, 0),
TIMER(0, TCC0, 2, 2, PIN_PA10F_TCC0_WO2, MUX_PA10F_TCC0_WO2), TCC(TCC0, 2, 2),
SERCOM(SERCOM0, 2, PINMUX_PA10C_SERCOM0_PAD2), SERCOM(SERCOM0, 2),
SERCOM(SERCOM2, 2, PINMUX_PA10D_SERCOM2_PAD2)); SERCOM(SERCOM2, 2));
#endif #endif
#ifdef PIN_PA11 #ifdef PIN_PA11
PIN(PA11, true, ADC_POSITIVE_INPUT_PIN19, PIN(PA11, true, ADC_POSITIVE_INPUT_PIN19,
TIMER(0, TCC1, 1, 1, PIN_PA11E_TCC1_WO1, MUX_PA11E_TCC1_WO1), TCC(TCC1, 1, 1),
TIMER(0, TCC0, 3, 3, PIN_PA11F_TCC0_WO3, MUX_PA11F_TCC0_WO3), TCC(TCC0, 3, 3),
SERCOM(SERCOM0, 3, PINMUX_PA11C_SERCOM0_PAD3), SERCOM(SERCOM0, 3),
SERCOM(SERCOM2, 3, PINMUX_PA11D_SERCOM2_PAD3)); SERCOM(SERCOM2, 3));
#endif #endif
#ifdef PIN_PB10 #ifdef PIN_PB10
PIN(PB10, false, NO_ADC_INPUT, PIN(PB10, false, NO_ADC_INPUT,
TIMER(TC5, 0, 0, 0, PIN_PB10E_TC5_WO0, MUX_PB10E_TC5_WO0), TC(TC5, 0, 0),
TIMER(0, TCC0, 0, 4, PIN_PB10F_TCC0_WO4, MUX_PB10F_TCC0_WO4), TCC(TCC0, 0, 4),
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM4, 2, PINMUX_PB10D_SERCOM4_PAD2)); SERCOM(SERCOM4, 2));
#endif #endif
#ifdef PIN_PB11 #ifdef PIN_PB11
PIN(PB11, false, NO_ADC_INPUT, PIN(PB11, false, NO_ADC_INPUT,
TIMER(TC5, 0, 1, 1, PIN_PB11E_TC5_WO1, MUX_PB11E_TC5_WO1), TC(TC5, 1, 1),
TIMER(0, TCC0, 1, 5, PIN_PB11F_TCC0_WO5, MUX_PB11F_TCC0_WO5), TCC(TCC0, 1, 5),
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM4, 3, PINMUX_PB11D_SERCOM4_PAD3)); SERCOM(SERCOM4, 3));
#endif #endif
#ifdef PIN_PB12 #ifdef PIN_PB12
PIN(PB12, false, NO_ADC_INPUT, PIN(PB12, false, NO_ADC_INPUT,
TIMER(TC4, 0, 0, 0, PIN_PB12E_TC4_WO0, MUX_PB12E_TC4_WO0), TC(TC4, 0, 0),
TIMER(0, TCC0, 2, 6, PIN_PB12F_TCC0_WO6, MUX_PB12F_TCC0_WO6), TCC(TCC0, 2, 6),
SERCOM(SERCOM4, 0, PINMUX_PB12C_SERCOM4_PAD0), SERCOM(SERCOM4, 0),
NO_SERCOM); NO_SERCOM);
#endif #endif
#ifdef PIN_PB13 #ifdef PIN_PB13
PIN(PB13, false, NO_ADC_INPUT, PIN(PB13, false, NO_ADC_INPUT,
TIMER(TC4, 0, 1, 1, PIN_PB13E_TC4_WO1, MUX_PB13E_TC4_WO1), TC(TC4, 1, 1),
TIMER(0, TCC0, 3, 7, PIN_PB13F_TCC0_WO7, MUX_PB13F_TCC0_WO7), TCC(TCC0, 3, 7),
SERCOM(SERCOM4, 1, PINMUX_PB13C_SERCOM4_PAD1), SERCOM(SERCOM4, 1),
NO_SERCOM); NO_SERCOM);
#endif #endif
#ifdef PIN_PB14 #ifdef PIN_PB14
PIN(PB14, false, NO_ADC_INPUT, PIN(PB14, false, NO_ADC_INPUT,
TIMER(TC5, 0, 0, 0, PIN_PB14E_TC5_WO0, MUX_PB14E_TC5_WO0), TC(TC5, 0, 0),
NO_TIMER, NO_TIMER,
SERCOM(SERCOM4, 2, PINMUX_PB14C_SERCOM4_PAD2), SERCOM(SERCOM4, 2),
NO_SERCOM); NO_SERCOM);
#endif #endif
// Second page. // Second page.
#ifdef PIN_PB15 #ifdef PIN_PB15
PIN(PB15, false, NO_ADC_INPUT, PIN(PB15, false, NO_ADC_INPUT,
TIMER(TC5, 0, 1, 1, PIN_PB15E_TC5_WO1, MUX_PB15E_TC5_WO1), TC(TC5, 1, 1),
NO_TIMER, NO_TIMER,
SERCOM(SERCOM4, 3, PINMUX_PB15C_SERCOM4_PAD3), SERCOM(SERCOM4, 3),
NO_SERCOM); NO_SERCOM);
#endif #endif
#ifdef PIN_PA12 #ifdef PIN_PA12
PIN(PA12, false, NO_ADC_INPUT, PIN(PA12, false, NO_ADC_INPUT,
TIMER(0, TCC2, 0, 0, PIN_PA12E_TCC2_WO0, MUX_PA12E_TCC2_WO0), TCC(TCC2, 0, 0),
TIMER(0, TCC0, 2, 6, PIN_PA12F_TCC0_WO6, MUX_PA12F_TCC0_WO6), TCC(TCC0, 2, 6),
SERCOM(SERCOM2, 0, PINMUX_PA12C_SERCOM2_PAD0), SERCOM(SERCOM2, 0),
SERCOM(SERCOM4, 0, PINMUX_PA12D_SERCOM4_PAD0)); SERCOM(SERCOM4, 0));
#endif #endif
#ifdef PIN_PA13 #ifdef PIN_PA13
PIN(PA13, false, NO_ADC_INPUT, PIN(PA13, false, NO_ADC_INPUT,
TIMER(0, TCC2, 1, 1, PIN_PA13E_TCC2_WO1, MUX_PA13E_TCC2_WO1), TCC(TCC2, 1, 1),
TIMER(0, TCC0, 3, 7, PIN_PA13F_TCC0_WO7, MUX_PA13F_TCC0_WO7), TCC(TCC0, 3, 7),
SERCOM(SERCOM2, 1, PINMUX_PA13C_SERCOM2_PAD1), SERCOM(SERCOM2, 1),
SERCOM(SERCOM4, 1, PINMUX_PA13D_SERCOM4_PAD1)); SERCOM(SERCOM4, 1));
#endif #endif
#ifdef PIN_PA14 #ifdef PIN_PA14
PIN(PA14, false, NO_ADC_INPUT, PIN(PA14, false, NO_ADC_INPUT,
TIMER(TC3, 0, 0, 0, PIN_PA14E_TC3_WO0, MUX_PA14E_TC3_WO0), TC(TC3, 0, 0),
TIMER(0, TCC0, 0, 4, PIN_PA14F_TCC0_WO4, MUX_PA14F_TCC0_WO4), TCC(TCC0, 0, 4),
SERCOM(SERCOM2, 2, PINMUX_PA14C_SERCOM2_PAD2), SERCOM(SERCOM2, 2),
#ifdef SERCOM4 #ifdef SERCOM4
SERCOM(SERCOM4, 2, PINMUX_PA14D_SERCOM4_PAD2) SERCOM(SERCOM4, 2)
#else #else
NO_SERCOM NO_SERCOM
#endif #endif
@ -238,11 +243,11 @@ PIN(PA14, false, NO_ADC_INPUT,
#endif #endif
#ifdef PIN_PA15 #ifdef PIN_PA15
PIN(PA15, false, NO_ADC_INPUT, PIN(PA15, false, NO_ADC_INPUT,
TIMER(TC3, 0, 1, 1, PIN_PA15E_TC3_WO1, MUX_PA15E_TC3_WO1), TC(TC3, 1, 1),
TIMER(0, TCC0, 1, 5, PIN_PA15F_TCC0_WO5, MUX_PA15F_TCC0_WO5), TCC(TCC0, 1, 5),
SERCOM(SERCOM2, 3, PINMUX_PA15C_SERCOM2_PAD3), SERCOM(SERCOM2, 3),
#ifdef SERCOM4 #ifdef SERCOM4
SERCOM(SERCOM4, 3, PINMUX_PA15D_SERCOM4_PAD3) SERCOM(SERCOM4, 3)
#else #else
NO_SERCOM NO_SERCOM
#endif #endif
@ -250,83 +255,83 @@ PIN(PA15, false, NO_ADC_INPUT,
#endif #endif
#ifdef PIN_PA16 #ifdef PIN_PA16
PIN(PA16, false, NO_ADC_INPUT, PIN(PA16, false, NO_ADC_INPUT,
TIMER(0, TCC2, 0, 0, PIN_PA16E_TCC2_WO0, MUX_PA16E_TCC2_WO0), TCC(TCC2, 0, 0),
TIMER(0, TCC0, 2, 6, PIN_PA16F_TCC0_WO6, MUX_PA16F_TCC0_WO6), TCC(TCC0, 2, 6),
SERCOM(SERCOM1, 0, PINMUX_PA16C_SERCOM1_PAD0), SERCOM(SERCOM1, 0),
SERCOM(SERCOM3, 0, PINMUX_PA16D_SERCOM3_PAD0)); SERCOM(SERCOM3, 0));
#endif #endif
#ifdef PIN_PA17 #ifdef PIN_PA17
PIN(PA17, false, NO_ADC_INPUT, PIN(PA17, false, NO_ADC_INPUT,
TIMER(0, TCC2, 1, 1, PIN_PA17E_TCC2_WO1, MUX_PA17E_TCC2_WO1), TCC(TCC2, 1, 1),
TIMER(0, TCC0, 3, 7, PIN_PA17F_TCC0_WO7, MUX_PA17F_TCC0_WO7), TCC(TCC0, 3, 7),
SERCOM(SERCOM1, 1, PINMUX_PA17C_SERCOM1_PAD1), SERCOM(SERCOM1, 1),
SERCOM(SERCOM3, 1, PINMUX_PA17D_SERCOM3_PAD1)); SERCOM(SERCOM3, 1));
#endif #endif
#ifdef PIN_PA18 #ifdef PIN_PA18
PIN(PA18, false, NO_ADC_INPUT, PIN(PA18, false, NO_ADC_INPUT,
TIMER(TC3, 0, 0, 0, PIN_PA18E_TC3_WO0, MUX_PA18E_TC3_WO0), TC(TC3, 0, 0),
TIMER(0, TCC0, 2, 2, PIN_PA18F_TCC0_WO2, MUX_PA18F_TCC0_WO2), TCC(TCC0, 2, 2),
SERCOM(SERCOM1, 2, PINMUX_PA18C_SERCOM1_PAD2), SERCOM(SERCOM1, 2),
SERCOM(SERCOM3, 2, PINMUX_PA18D_SERCOM3_PAD2)); SERCOM(SERCOM3, 2));
#endif #endif
#ifdef PIN_PA19 #ifdef PIN_PA19
PIN(PA19, false, NO_ADC_INPUT, PIN(PA19, false, NO_ADC_INPUT,
TIMER(TC3, 0, 1, 1, PIN_PA19E_TC3_WO1, MUX_PA19E_TC3_WO1), TC(TC3, 1, 1),
TIMER(0, TCC0, 3, 3, PIN_PA19F_TCC0_WO3, MUX_PA19F_TCC0_WO3), TCC(TCC0, 3, 3),
SERCOM(SERCOM1, 3, PINMUX_PA19C_SERCOM1_PAD3), SERCOM(SERCOM1, 3),
SERCOM(SERCOM3, 3, PINMUX_PA19C_SERCOM1_PAD3)); SERCOM(SERCOM3, 3));
#endif #endif
#ifdef PIN_PB16 #ifdef PIN_PB16
PIN(PB16, false, NO_ADC_INPUT, PIN(PB16, false, NO_ADC_INPUT,
#ifdef _SAMD21_TC6_INSTANCE_ #ifdef _SAMD21_TC6_INSTANCE_
TIMER(TC6, 0, 0, 0, PIN_PB16E_TC6_WO0, MUX_PB16E_TC6_WO0), TC(TC6, 0, 0),
#else #else
NO_TIMER, NO_TIMER,
#endif #endif
TIMER(0, TCC0, 0, 4, PIN_PB16F_TCC0_WO4, MUX_PB16F_TCC0_WO4), TCC(TCC0, 0, 4),
SERCOM(SERCOM5, 0, PINMUX_PB16C_SERCOM5_PAD0), SERCOM(SERCOM5, 0),
NO_SERCOM); NO_SERCOM);
#endif #endif
#ifdef PIN_PB17 #ifdef PIN_PB17
PIN(PB17, false, NO_ADC_INPUT, PIN(PB17, false, NO_ADC_INPUT,
#ifdef _SAMD21_TC6_INSTANCE_ #ifdef _SAMD21_TC6_INSTANCE_
TIMER(TC6, 0, 0, 0, PIN_PB17E_TC6_WO1, MUX_PB17E_TC6_WO1), TC(TC6, 0, 0),
#else #else
NO_TIMER, NO_TIMER,
#endif #endif
TIMER(0, TCC0, 1, 5, PIN_PB17F_TCC0_WO5, MUX_PB17F_TCC0_WO5), TCC(TCC0, 1, 5),
SERCOM(SERCOM5, 1, PINMUX_PB17C_SERCOM5_PAD1), SERCOM(SERCOM5, 1),
NO_SERCOM); NO_SERCOM);
#endif #endif
#ifdef PIN_PA20 #ifdef PIN_PA20
PIN(PA20, false, NO_ADC_INPUT, PIN(PA20, false, NO_ADC_INPUT,
#ifdef _SAMD21_TC7_INSTANCE_ #ifdef _SAMD21_TC7_INSTANCE_
TIMER(TC7, 0, 0, 0, PIN_PA20E_TC7_WO0, MUX_PA20E_TC7_WO0), TC(TC7, 0, 0),
#else #else
NO_TIMER, NO_TIMER,
#endif #endif
TIMER(0, TCC0, 2, 6, PIN_PA20F_TCC0_WO6, MUX_PA20F_TCC0_WO6), TCC(TCC0, 2, 6),
SERCOM(SERCOM5, 2, PINMUX_PA20C_SERCOM5_PAD2), SERCOM(SERCOM5, 2),
SERCOM(SERCOM3, 2, PINMUX_PA20D_SERCOM3_PAD2)); SERCOM(SERCOM3, 2));
#endif #endif
#ifdef PIN_PA21 #ifdef PIN_PA21
PIN(PA21, false, NO_ADC_INPUT, PIN(PA21, false, NO_ADC_INPUT,
#ifdef _SAMD21_TC7_INSTANCE_ #ifdef _SAMD21_TC7_INSTANCE_
TIMER(TC7, 0, 1, 1, PIN_PA21E_TC7_WO1, MUX_PA21E_TC7_WO1), TC(TC7, 1, 1),
#else #else
NO_TIMER, NO_TIMER,
#endif #endif
TIMER(0, TCC0, 3, 7, PIN_PA21F_TCC0_WO7, MUX_PA21F_TCC0_WO7), TCC(TCC0, 3, 7),
SERCOM(SERCOM5, 3, PINMUX_PA21C_SERCOM5_PAD3), SERCOM(SERCOM5, 3),
SERCOM(SERCOM3, 3, PINMUX_PA21D_SERCOM3_PAD3)); SERCOM(SERCOM3, 3));
#endif #endif
#ifdef PIN_PA22 #ifdef PIN_PA22
PIN(PA22, false, NO_ADC_INPUT, PIN(PA22, false, NO_ADC_INPUT,
TIMER(TC4, 0, 0, 0, PIN_PA22E_TC4_WO0, MUX_PA22E_TC4_WO0), TC(TC4, 0, 0),
TIMER(0, TCC0, 0, 4, PIN_PA22F_TCC0_WO4, MUX_PA22F_TCC0_WO4), TCC(TCC0, 0, 4),
SERCOM(SERCOM3, 0, PINMUX_PA22C_SERCOM3_PAD0), SERCOM(SERCOM3, 0),
#ifdef SERCOM5 #ifdef SERCOM5
SERCOM(SERCOM5, 0, PINMUX_PA22D_SERCOM5_PAD0) SERCOM(SERCOM5, 0)
#else #else
NO_SERCOM NO_SERCOM
#endif #endif
@ -334,11 +339,11 @@ PIN(PA22, false, NO_ADC_INPUT,
#endif #endif
#ifdef PIN_PA23 #ifdef PIN_PA23
PIN(PA23, false, NO_ADC_INPUT, PIN(PA23, false, NO_ADC_INPUT,
TIMER(TC4, 0, 1, 1, PIN_PA23E_TC4_WO1, MUX_PA23E_TC4_WO1), TC(TC4, 1, 1),
TIMER(0, TCC0, 1, 5, PIN_PA23F_TCC0_WO5, MUX_PA23F_TCC0_WO5), TCC(TCC0, 1, 5),
SERCOM(SERCOM3, 1, PINMUX_PA23C_SERCOM3_PAD1), SERCOM(SERCOM3, 1),
#ifdef SERCOM5 #ifdef SERCOM5
SERCOM(SERCOM5, 1, PINMUX_PA23D_SERCOM5_PAD1) SERCOM(SERCOM5, 1)
#else #else
NO_SERCOM NO_SERCOM
#endif #endif
@ -346,11 +351,11 @@ PIN(PA23, false, NO_ADC_INPUT,
#endif #endif
#ifdef PIN_PA24 #ifdef PIN_PA24
PIN(PA24, false, NO_ADC_INPUT, PIN(PA24, false, NO_ADC_INPUT,
TIMER(TC5, 0, 0, 0, PIN_PA24E_TC5_WO0, MUX_PA24E_TC5_WO0), TC(TC5, 0, 0),
TIMER(0, TCC0, 2, 2, PIN_PA24F_TCC1_WO2, MUX_PA24F_TCC1_WO2), TCC(TCC0, 2, 2),
SERCOM(SERCOM3, 2, PINMUX_PA24C_SERCOM3_PAD2), SERCOM(SERCOM3, 2),
#ifdef SERCOM5 #ifdef SERCOM5
SERCOM(SERCOM5, 2, PINMUX_PA24D_SERCOM5_PAD2) SERCOM(SERCOM5, 2)
#else #else
NO_SERCOM NO_SERCOM
#endif #endif
@ -358,11 +363,11 @@ PIN(PA24, false, NO_ADC_INPUT,
#endif #endif
#ifdef PIN_PA25 #ifdef PIN_PA25
PIN(PA25, false, NO_ADC_INPUT, PIN(PA25, false, NO_ADC_INPUT,
TIMER(TC5, 0, 1, 1, PIN_PA25E_TC5_WO1, MUX_PA25E_TC5_WO1), TC(TC5, 1, 1),
TIMER(0, TCC1, 3, 3, PIN_PA25F_TCC1_WO3, MUX_PA25F_TCC1_WO3), TCC(TCC1, 3, 3),
SERCOM(SERCOM3, 3, PINMUX_PA25C_SERCOM3_PAD3), SERCOM(SERCOM3, 3),
#ifdef SERCOM5 #ifdef SERCOM5
SERCOM(SERCOM5, 3, PINMUX_PA25C_SERCOM3_PAD3) SERCOM(SERCOM5, 3)
#else #else
NO_SERCOM NO_SERCOM
#endif #endif
@ -371,24 +376,24 @@ PIN(PA25, false, NO_ADC_INPUT,
#ifdef PIN_PB22 #ifdef PIN_PB22
PIN(PB22, false, NO_ADC_INPUT, PIN(PB22, false, NO_ADC_INPUT,
#ifdef _SAMD21_TC7_INSTANCE_ #ifdef _SAMD21_TC7_INSTANCE_
TIMER(TC7, 0, 1, 1, PIN_PB22E_TC7_WO0, MUX_PB22E_TC7_WO0), TC(TC7, 1, 1),
#else #else
NO_TIMER, NO_TIMER,
#endif #endif
NO_TIMER, NO_TIMER,
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM5, 2, PINMUX_PB22D_SERCOM5_PAD2)); SERCOM(SERCOM5, 2));
#endif #endif
#ifdef PIN_PB23 #ifdef PIN_PB23
PIN(PB23, false, NO_ADC_INPUT, PIN(PB23, false, NO_ADC_INPUT,
#ifdef _SAMD21_TC7_INSTANCE_ #ifdef _SAMD21_TC7_INSTANCE_
TIMER(TC7, 0, 1, 1, PIN_PB23E_TC7_WO1, MUX_PB23E_TC7_WO1), TC(TC7, 1, 1),
#else #else
NO_TIMER, NO_TIMER,
#endif #endif
NO_TIMER, NO_TIMER,
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM5, 3, PINMUX_PB23D_SERCOM5_PAD3)); SERCOM(SERCOM5, 3));
#endif #endif
#ifdef PIN_PA27 #ifdef PIN_PA27
PIN(PA27, false, NO_ADC_INPUT, PIN(PA27, false, NO_ADC_INPUT,
@ -406,73 +411,73 @@ PIN(PA28, false, NO_ADC_INPUT,
#endif #endif
#ifdef PIN_PA30 #ifdef PIN_PA30
PIN(PA30, false, NO_ADC_INPUT, PIN(PA30, false, NO_ADC_INPUT,
TIMER(0, TCC1, 0, 0, PIN_PA30E_TCC1_WO0, MUX_PA30E_TCC1_WO0), TCC(TCC1, 0, 0),
NO_TIMER, NO_TIMER,
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM1, 2, PINMUX_PA30D_SERCOM1_PAD2)); SERCOM(SERCOM1, 2));
#endif #endif
#ifdef PIN_PA31 #ifdef PIN_PA31
PIN(PA31, false, NO_ADC_INPUT, PIN(PA31, false, NO_ADC_INPUT,
TIMER(0, TCC1, 1, 1, PIN_PA31E_TCC1_WO1, MUX_PA31E_TCC1_WO1), TCC(TCC1, 1, 1),
NO_TIMER, NO_TIMER,
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM1, 3, PINMUX_PA31D_SERCOM1_PAD3)); SERCOM(SERCOM1, 3));
#endif #endif
#ifdef PIN_PB30 #ifdef PIN_PB30
PIN(PB30, false, NO_ADC_INPUT, PIN(PB30, false, NO_ADC_INPUT,
TIMER(TCC0, 0, 0, 0, PIN_PB30E_TCC0_WO0, MUX_PB30E_TCC0_WO0), TCC(TCC0, 0, 0),
TIMER(TCC1, 0, 2, 2, PIN_PB30F_TCC1_WO2, MUX_PB30F_TCC1_WO2), TCC(TCC1, 2, 2),
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM5, 0, PINMUX_PB30D_SERCOM5_PAD0)); SERCOM(SERCOM5, 0));
#endif #endif
#ifdef PIN_PB31 #ifdef PIN_PB31
PIN(PB31, false, NO_ADC_INPUT, PIN(PB31, false, NO_ADC_INPUT,
TIMER(TCC0, 0, 1, 1, PIN_PB31E_TCC0_WO1, MUX_PB31E_TCC0_WO1), TCC(TCC0, 1, 1),
TIMER(TCC1, 0, 3, 3, PIN_PB31F_TCC1_WO3, MUX_PB31F_TCC1_WO3), TCC(TCC1, 3, 3),
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM5, 1, PINMUX_PB31D_SERCOM5_PAD1)); SERCOM(SERCOM5, 1));
#endif #endif
#ifdef PIN_PB00 #ifdef PIN_PB00
PIN(PB00, true, ADC_POSITIVE_INPUT_PIN8, PIN(PB00, true, ADC_POSITIVE_INPUT_PIN8,
#ifdef _SAMD21_TC7_INSTANCE_ #ifdef _SAMD21_TC7_INSTANCE_
TIMER(TC7, 0, 0, 0, PIN_PB00E_TC7_WO0, MUX_PB00E_TC7_WO0), TC(TC7, 0, 0),
#else #else
NO_TIMER, NO_TIMER,
#endif #endif
NO_TIMER, NO_TIMER,
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM5, 2, PINMUX_PB00D_SERCOM5_PAD2)); SERCOM(SERCOM5, 2));
#endif #endif
#ifdef PIN_PB01 #ifdef PIN_PB01
PIN(PB01, true, ADC_POSITIVE_INPUT_PIN9, PIN(PB01, true, ADC_POSITIVE_INPUT_PIN9,
#ifdef _SAMD21_TC7_INSTANCE_ #ifdef _SAMD21_TC7_INSTANCE_
TIMER(TC7, 0, 1, 1, PIN_PB01E_TC7_WO1, MUX_PB01E_TC7_WO1), TC(TC7, 1, 1),
#else #else
NO_TIMER, NO_TIMER,
#endif #endif
NO_TIMER, NO_TIMER,
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM5, 3, PINMUX_PB01D_SERCOM5_PAD3)); SERCOM(SERCOM5, 3));
#endif #endif
#ifdef PIN_PB02 #ifdef PIN_PB02
PIN(PB02, true, ADC_POSITIVE_INPUT_PIN10, PIN(PB02, true, ADC_POSITIVE_INPUT_PIN10,
#ifdef _SAMD21_TC6_INSTANCE_ #ifdef _SAMD21_TC6_INSTANCE_
TIMER(TC6, 0, 0, 0, PIN_PB02E_TC6_WO0, MUX_PB02E_TC6_WO0), TC(TC6, 0, 0),
#else #else
NO_TIMER, NO_TIMER,
#endif #endif
NO_TIMER, NO_TIMER,
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM5, 0, PINMUX_PB02D_SERCOM5_PAD0)); SERCOM(SERCOM5, 0));
#endif #endif
#ifdef PIN_PB03 #ifdef PIN_PB03
PIN(PB03, true, ADC_POSITIVE_INPUT_PIN11, PIN(PB03, true, ADC_POSITIVE_INPUT_PIN11,
#ifdef _SAMD21_TC6_INSTANCE_ #ifdef _SAMD21_TC6_INSTANCE_
TIMER(TC6, 0, 1, 1, PIN_PB03E_TC6_WO1, MUX_PB03E_TC6_WO1), TC(TC6, 1, 1),
#else #else
NO_TIMER, NO_TIMER,
#endif #endif
NO_TIMER, NO_TIMER,
NO_SERCOM, NO_SERCOM,
SERCOM(SERCOM5, 1, PINMUX_PB03D_SERCOM5_PAD1)); SERCOM(SERCOM5, 1));
#endif #endif

View File

@ -3,6 +3,12 @@
#include "common-hal/microcontroller/types.h" #include "common-hal/microcontroller/types.h"
#define MUX_C 2
#define MUX_D 3
#define MUX_E 4
#define MUX_F 5
#define PINMUX(pin, mux) ((((uint32_t) pin) << 16) | (mux))
// Pins in datasheet order. // Pins in datasheet order.
#ifdef PIN_PA00 #ifdef PIN_PA00
extern const mcu_pin_obj_t pin_PA00; extern const mcu_pin_obj_t pin_PA00;