1ae42fd11SThibaut VIARD/*
21a1856c2SCristian Maglie  Copyright (c) 2015 Arduino LLC.  All right reserved.
3ae42fd11SThibaut VIARD
4ae42fd11SThibaut VIARD  This library is free software; you can redistribute it and/or
5ae42fd11SThibaut VIARD  modify it under the terms of the GNU Lesser General Public
6ae42fd11SThibaut VIARD  License as published by the Free Software Foundation; either
7ae42fd11SThibaut VIARD  version 2.1 of the License, or (at your option) any later version.
8ae42fd11SThibaut VIARD
9ae42fd11SThibaut VIARD  This library is distributed in the hope that it will be useful,
10ae42fd11SThibaut VIARD  but WITHOUT ANY WARRANTY; without even the implied warranty of
11ae42fd11SThibaut VIARD  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12ae42fd11SThibaut VIARD  See the GNU Lesser General Public License for more details.
13ae42fd11SThibaut VIARD
14ae42fd11SThibaut VIARD  You should have received a copy of the GNU Lesser General Public
15ae42fd11SThibaut VIARD  License along with this library; if not, write to the Free Software
16ae42fd11SThibaut VIARD  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17ae42fd11SThibaut VIARD*/
18ae42fd11SThibaut VIARD
191a1856c2SCristian Maglie#pragma once
2030614228SThibaut VIARD
2130614228SThibaut VIARD#include <stdint.h>
2230e5b3feSMatthijs Kooijman#include <samd.h>
2330614228SThibaut VIARD
2430614228SThibaut VIARD#ifdef __cplusplus
253d1a2e1cSThibaut VIARDextern "C" {
261a1856c2SCristian Maglie#endif
2730614228SThibaut VIARD
2830614228SThibaut VIARD/* Definitions and types for pins */
2930614228SThibaut VIARDtypedef enum _EAnalogChannel
3030614228SThibaut VIARD{
3130614228SThibaut VIARD  No_ADC_Channel=-1,
3230614228SThibaut VIARD  ADC_Channel0=0,
3330614228SThibaut VIARD  ADC_Channel1=1,
3430614228SThibaut VIARD  ADC_Channel2=2,
3530614228SThibaut VIARD  ADC_Channel3=3,
3630614228SThibaut VIARD  ADC_Channel4=4,
3730614228SThibaut VIARD  ADC_Channel5=5,
3830614228SThibaut VIARD  ADC_Channel6=6,
3930614228SThibaut VIARD  ADC_Channel7=7,
40132b2198SThibaut VIARD#if defined __SAMD21J18A__
41132b2198SThibaut VIARD  ADC_Channel8=8,
42132b2198SThibaut VIARD  ADC_Channel9=9,
43132b2198SThibaut VIARD#endif // __SAMD21J18A__
4430614228SThibaut VIARD  ADC_Channel10=10,
450d83c969SCristian Maglie  ADC_Channel11=11,
460d83c969SCristian Maglie#if defined __SAMD21J18A__
470d83c969SCristian Maglie  ADC_Channel12=12,
480d83c969SCristian Maglie  ADC_Channel13=13,
490d83c969SCristian Maglie  ADC_Channel14=14,
500d83c969SCristian Maglie  ADC_Channel15=15,
51132b2198SThibaut VIARD#endif // __SAMD21J18A__
5230614228SThibaut VIARD  ADC_Channel16=16,
5330614228SThibaut VIARD  ADC_Channel17=17,
5430614228SThibaut VIARD  ADC_Channel18=18,
5530614228SThibaut VIARD  ADC_Channel19=19,
5630614228SThibaut VIARD  DAC_Channel0,
5730614228SThibaut VIARD} EAnalogChannel ;
5830614228SThibaut VIARD
5930614228SThibaut VIARD// Definitions for TC channels
6030614228SThibaut VIARDtypedef enum _ETCChannel
6130614228SThibaut VIARD{
6230614228SThibaut VIARD  NOT_ON_TIMER=-1,
63908d1030SThibaut VIARD  TCC0_CH0 = (0<<8)|(0),
64908d1030SThibaut VIARD  TCC0_CH1 = (0<<8)|(1),
65908d1030SThibaut VIARD  TCC0_CH2 = (0<<8)|(2),
66908d1030SThibaut VIARD  TCC0_CH3 = (0<<8)|(3),
671d251a33SThibaut VIARD  TCC0_CH4 = (0<<8)|(0), // Channel 4 is 0!
681d251a33SThibaut VIARD  TCC0_CH5 = (0<<8)|(1), // Channel 5 is 1!
691d251a33SThibaut VIARD  TCC0_CH6 = (0<<8)|(2), // Channel 6 is 2!
701d251a33SThibaut VIARD  TCC0_CH7 = (0<<8)|(3), // Channel 7 is 3!
71908d1030SThibaut VIARD  TCC1_CH0 = (1<<8)|(0),
72908d1030SThibaut VIARD  TCC1_CH1 = (1<<8)|(1),
732a9cbd4cSCristian Maglie  TCC1_CH2 = (1<<8)|(0), // Channel 2 is 0!
742a9cbd4cSCristian Maglie  TCC1_CH3 = (1<<8)|(1), // Channel 3 is 1!
75908d1030SThibaut VIARD  TCC2_CH0 = (2<<8)|(0),
76b2db3a76SThibaut VIARD  TCC2_CH1 = (2<<8)|(1),
772a9cbd4cSCristian Maglie  TCC2_CH2 = (2<<8)|(0), // Channel 2 is 0!
782a9cbd4cSCristian Maglie  TCC2_CH3 = (2<<8)|(1), // Channel 3 is 1!
793d1a2e1cSThibaut VIARD  TC3_CH0  = (3<<8)|(0),
803d1a2e1cSThibaut VIARD  TC3_CH1  = (3<<8)|(1),
812a9cbd4cSCristian Maglie  TC4_CH0  = (4<<8)|(0),
822a9cbd4cSCristian Maglie  TC4_CH1  = (4<<8)|(1),
83b18634edSThibaut VIARD  TC5_CH0  = (5<<8)|(0),
84b18634edSThibaut VIARD  TC5_CH1  = (5<<8)|(1),
85b18634edSThibaut VIARD#if defined __SAMD21J18A__
862a9cbd4cSCristian Maglie  TC6_CH0  = (6<<8)|(0),
872a9cbd4cSCristian Maglie  TC6_CH1  = (6<<8)|(1),
88b18634edSThibaut VIARD  TC7_CH0  = (7<<8)|(0),
892a9cbd4cSCristian Maglie  TC7_CH1  = (7<<8)|(1),
90132b2198SThibaut VIARD#endif // __SAMD21J18A__
9130614228SThibaut VIARD} ETCChannel ;
9230614228SThibaut VIARD
93d300278cSThibaut VIARDextern const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM] ;
94d300278cSThibaut VIARD
95d300278cSThibaut VIARD#define GetTCNumber( x ) ( (x) >> 8 )
961d251a33SThibaut VIARD#define GetTCChannelNumber( x ) ( (x) & 0xff )
97d300278cSThibaut VIARD#define GetTC( x ) ( g_apTCInstances[(x) >> 8] )
98d300278cSThibaut VIARD
9930614228SThibaut VIARD// Definitions for PWM channels
10030614228SThibaut VIARDtypedef enum _EPWMChannel
10130614228SThibaut VIARD{
10230614228SThibaut VIARD  NOT_ON_PWM=-1,
103908d1030SThibaut VIARD  PWM0_CH0=TCC0_CH0,
104908d1030SThibaut VIARD  PWM0_CH1=TCC0_CH1,
105908d1030SThibaut VIARD  PWM0_CH2=TCC0_CH2,
106908d1030SThibaut VIARD  PWM0_CH3=TCC0_CH3,
107908d1030SThibaut VIARD  PWM0_CH4=TCC0_CH4,
108908d1030SThibaut VIARD  PWM0_CH5=TCC0_CH5,
109908d1030SThibaut VIARD  PWM0_CH6=TCC0_CH6,
110908d1030SThibaut VIARD  PWM0_CH7=TCC0_CH7,
111908d1030SThibaut VIARD  PWM1_CH0=TCC1_CH0,
112908d1030SThibaut VIARD  PWM1_CH1=TCC1_CH1,
1132a9cbd4cSCristian Maglie  PWM1_CH2=TCC1_CH2,
1142a9cbd4cSCristian Maglie  PWM1_CH3=TCC1_CH3,
115908d1030SThibaut VIARD  PWM2_CH0=TCC2_CH0,
116908d1030SThibaut VIARD  PWM2_CH1=TCC2_CH1,
1172a9cbd4cSCristian Maglie  PWM2_CH2=TCC2_CH2,
1182a9cbd4cSCristian Maglie  PWM2_CH3=TCC2_CH3,
119b2db3a76SThibaut VIARD  PWM3_CH0=TC3_CH0,
120b2db3a76SThibaut VIARD  PWM3_CH1=TC3_CH1,
1212a9cbd4cSCristian Maglie  PWM4_CH0=TC4_CH0,
1222a9cbd4cSCristian Maglie  PWM4_CH1=TC4_CH1,
123b18634edSThibaut VIARD  PWM5_CH0=TC5_CH0,
124b18634edSThibaut VIARD  PWM5_CH1=TC5_CH1,
125b18634edSThibaut VIARD#if defined __SAMD21J18A__
1262a9cbd4cSCristian Maglie  PWM6_CH0=TC6_CH0,
1272a9cbd4cSCristian Maglie  PWM6_CH1=TC6_CH1,
128b18634edSThibaut VIARD  PWM7_CH0=TC7_CH0,
1292a9cbd4cSCristian Maglie  PWM7_CH1=TC7_CH1,
130132b2198SThibaut VIARD#endif // __SAMD21J18A__
13130614228SThibaut VIARD} EPWMChannel ;
13230614228SThibaut VIARD
13330614228SThibaut VIARDtypedef enum _EPortType
13430614228SThibaut VIARD{
135908d1030SThibaut VIARD  NOT_A_PORT=-1,
136908d1030SThibaut VIARD  PORTA=0,
137908d1030SThibaut VIARD  PORTB=1,
138908d1030SThibaut VIARD  PORTC=2,
13930614228SThibaut VIARD} EPortType ;
14030614228SThibaut VIARD
141d654db22SCristian Maglietypedef enum
1423cd1d4e6SThibaut VIARD{
143d654db22SCristian Maglie  EXTERNAL_INT_0 = 0,
144d654db22SCristian Maglie  EXTERNAL_INT_1,
145d654db22SCristian Maglie  EXTERNAL_INT_2,
146d654db22SCristian Maglie  EXTERNAL_INT_3,
147d654db22SCristian Maglie  EXTERNAL_INT_4,
148d654db22SCristian Maglie  EXTERNAL_INT_5,
149d654db22SCristian Maglie  EXTERNAL_INT_6,
150d654db22SCristian Maglie  EXTERNAL_INT_7,
151d654db22SCristian Maglie  EXTERNAL_INT_8,
152d654db22SCristian Maglie  EXTERNAL_INT_9,
153d654db22SCristian Maglie  EXTERNAL_INT_10,
154d654db22SCristian Maglie  EXTERNAL_INT_11,
155d654db22SCristian Maglie  EXTERNAL_INT_12,
156d654db22SCristian Maglie  EXTERNAL_INT_13,
157d654db22SCristian Maglie  EXTERNAL_INT_14,
158d654db22SCristian Maglie  EXTERNAL_INT_15,
159d654db22SCristian Maglie  EXTERNAL_INT_NMI,
1603cd1d4e6SThibaut VIARD  EXTERNAL_NUM_INTERRUPTS,
1613cd1d4e6SThibaut VIARD  NOT_AN_INTERRUPT = -1,
1623cd1d4e6SThibaut VIARD  EXTERNAL_INT_NONE = NOT_AN_INTERRUPT,
1633cd1d4e6SThibaut VIARD} EExt_Interrupts ;
16430614228SThibaut VIARD
16530614228SThibaut VIARD//A    B                 C       D          E      F   G   H
16630614228SThibaut VIARD//EIC REF ADC AC PTC DAC SERCOM SERCOM_ALT TC/TCC TCC COM AC/GCLK
16730614228SThibaut VIARD
16830614228SThibaut VIARDtypedef enum _EPioType
16930614228SThibaut VIARD{
1703d1a2e1cSThibaut VIARD  PIO_NOT_A_PIN=-1,     /* Not under control of a peripheral. */
1713d1a2e1cSThibaut VIARD  PIO_EXTINT=0,         /* The pin is controlled by the associated signal of peripheral A. */
1723d1a2e1cSThibaut VIARD  PIO_ANALOG,           /* The pin is controlled by the associated signal of peripheral B. */
1733d1a2e1cSThibaut VIARD  PIO_SERCOM,           /* The pin is controlled by the associated signal of peripheral C. */
1743d1a2e1cSThibaut VIARD  PIO_SERCOM_ALT,       /* The pin is controlled by the associated signal of peripheral D. */
1753d1a2e1cSThibaut VIARD  PIO_TIMER,            /* The pin is controlled by the associated signal of peripheral E. */
1763d1a2e1cSThibaut VIARD  PIO_TIMER_ALT,        /* The pin is controlled by the associated signal of peripheral F. */
1773d1a2e1cSThibaut VIARD  PIO_COM,              /* The pin is controlled by the associated signal of peripheral G. */
1783d1a2e1cSThibaut VIARD  PIO_AC_CLK,           /* The pin is controlled by the associated signal of peripheral H. */
1793d1a2e1cSThibaut VIARD  PIO_DIGITAL,          /* The pin is controlled by PORT. */
1803d1a2e1cSThibaut VIARD  PIO_INPUT,            /* The pin is controlled by PORT and is an input. */
1813d1a2e1cSThibaut VIARD  PIO_INPUT_PULLUP,     /* The pin is controlled by PORT and is an input with internal pull-up resistor enabled. */
1823d1a2e1cSThibaut VIARD  PIO_OUTPUT,           /* The pin is controlled by PORT and is an output. */
18330614228SThibaut VIARD
18430614228SThibaut VIARD  PIO_PWM=PIO_TIMER,
18530614228SThibaut VIARD  PIO_PWM_ALT=PIO_TIMER_ALT,
18630614228SThibaut VIARD} EPioType ;
18730614228SThibaut VIARD
18830614228SThibaut VIARD/**
18930614228SThibaut VIARD * Pin Attributes to be OR-ed
19030614228SThibaut VIARD */
19130614228SThibaut VIARD#define PIN_ATTR_NONE          (0UL<<0)
19230614228SThibaut VIARD#define PIN_ATTR_COMBO         (1UL<<0)
19330614228SThibaut VIARD#define PIN_ATTR_ANALOG        (1UL<<1)
19430614228SThibaut VIARD#define PIN_ATTR_DIGITAL       (1UL<<2)
19530614228SThibaut VIARD#define PIN_ATTR_PWM           (1UL<<3)
19630614228SThibaut VIARD#define PIN_ATTR_TIMER         (1UL<<4)
19746ca790fSCristian Maglie#define PIN_ATTR_TIMER_ALT     (1UL<<5)
19846ca790fSCristian Maglie#define PIN_ATTR_EXTINT        (1UL<<6)
19930614228SThibaut VIARD
20030614228SThibaut VIARD/* Types used for the table below */
20130614228SThibaut VIARDtypedef struct _PinDescription
20230614228SThibaut VIARD{
2033d1a2e1cSThibaut VIARD  EPortType       ulPort ;
2043d1a2e1cSThibaut VIARD  uint32_t        ulPin ;
2053d1a2e1cSThibaut VIARD  EPioType        ulPinType ;
2063d1a2e1cSThibaut VIARD  uint32_t        ulPinAttribute ;
2073d1a2e1cSThibaut VIARD  EAnalogChannel  ulADCChannelNumber ; /* ADC Channel number in the SAM device */
2083d1a2e1cSThibaut VIARD  EPWMChannel     ulPWMChannel ;
2093d1a2e1cSThibaut VIARD  ETCChannel      ulTCChannel ;
2103cd1d4e6SThibaut VIARD  EExt_Interrupts ulExtInt ;
21130614228SThibaut VIARD} PinDescription ;
21230614228SThibaut VIARD
2133cd1d4e6SThibaut VIARD/* Pins table to be instantiated into variant.cpp */
21430614228SThibaut VIARDextern const PinDescription g_APinDescription[] ;
21530614228SThibaut VIARD
2163cd1d4e6SThibaut VIARD/* Generic Clock Multiplexer IDs */
2173cd1d4e6SThibaut VIARD#define GCM_DFLL48M_REF           (0x00U)
2183cd1d4e6SThibaut VIARD#define GCM_FDPLL96M_INPUT        (0x01U)
2193cd1d4e6SThibaut VIARD#define GCM_FDPLL96M_32K          (0x02U)
2203cd1d4e6SThibaut VIARD#define GCM_WDT                   (0x03U)
2213cd1d4e6SThibaut VIARD#define GCM_RTC                   (0x04U)
2223cd1d4e6SThibaut VIARD#define GCM_EIC                   (0x05U)
2233cd1d4e6SThibaut VIARD#define GCM_USB                   (0x06U)
2243cd1d4e6SThibaut VIARD#define GCM_EVSYS_CHANNEL_0       (0x07U)
2253cd1d4e6SThibaut VIARD#define GCM_EVSYS_CHANNEL_1       (0x08U)
2263cd1d4e6SThibaut VIARD#define GCM_EVSYS_CHANNEL_2       (0x09U)
2273cd1d4e6SThibaut VIARD#define GCM_EVSYS_CHANNEL_3       (0x0AU)
2283cd1d4e6SThibaut VIARD#define GCM_EVSYS_CHANNEL_4       (0x0BU)
2293cd1d4e6SThibaut VIARD#define GCM_EVSYS_CHANNEL_5       (0x0CU)
2303cd1d4e6SThibaut VIARD#define GCM_EVSYS_CHANNEL_6       (0x0DU)
2313cd1d4e6SThibaut VIARD#define GCM_EVSYS_CHANNEL_7       (0x0EU)
2323cd1d4e6SThibaut VIARD#define GCM_EVSYS_CHANNEL_8       (0x0FU)
2333cd1d4e6SThibaut VIARD#define GCM_EVSYS_CHANNEL_9       (0x10U)
2343cd1d4e6SThibaut VIARD#define GCM_EVSYS_CHANNEL_10      (0x11U)
2353cd1d4e6SThibaut VIARD#define GCM_EVSYS_CHANNEL_11      (0x12U)
2363cd1d4e6SThibaut VIARD#define GCM_SERCOMx_SLOW          (0x13U)
2373cd1d4e6SThibaut VIARD#define GCM_SERCOM0_CORE          (0x14U)
2383cd1d4e6SThibaut VIARD#define GCM_SERCOM1_CORE          (0x15U)
2393cd1d4e6SThibaut VIARD#define GCM_SERCOM2_CORE          (0x16U)
2403cd1d4e6SThibaut VIARD#define GCM_SERCOM3_CORE          (0x17U)
2413cd1d4e6SThibaut VIARD#define GCM_SERCOM4_CORE          (0x18U)
2423cd1d4e6SThibaut VIARD#define GCM_SERCOM5_CORE          (0x19U)
2433cd1d4e6SThibaut VIARD#define GCM_TCC0_TCC1             (0x1AU)
2443cd1d4e6SThibaut VIARD#define GCM_TCC2_TC3              (0x1BU)
2453cd1d4e6SThibaut VIARD#define GCM_TC4_TC5               (0x1CU)
2463cd1d4e6SThibaut VIARD#define GCM_TC6_TC7               (0x1DU)
2473cd1d4e6SThibaut VIARD#define GCM_ADC                   (0x1EU)
2483cd1d4e6SThibaut VIARD#define GCM_AC_DIG                (0x1FU)
2493cd1d4e6SThibaut VIARD#define GCM_AC_ANA                (0x20U)
2503cd1d4e6SThibaut VIARD#define GCM_DAC                   (0x21U)
2513cd1d4e6SThibaut VIARD#define GCM_PTC                   (0x22U)
2523cd1d4e6SThibaut VIARD#define GCM_I2S_0                 (0x23U)
2533cd1d4e6SThibaut VIARD#define GCM_I2S_1                 (0x24U)
2543cd1d4e6SThibaut VIARD
25530614228SThibaut VIARD#ifdef __cplusplus
25630614228SThibaut VIARD} // extern "C"
2571a1856c2SCristian Maglie#endif
258