forked from mattairtech/ArduinoCore-samd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
variant.h
373 lines (305 loc) · 12.8 KB
/
variant.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/*
Copyright (c) 2014-2015 Arduino LLC. 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
*/
/*
* Modified 9 December 2016 by Justin Mattair
* for MattairTech boards (www.mattairtech.com)
*
* See README.md for documentation and pin mapping information
*/
#ifndef _VARIANT_GENERIC_XX1E_
#define _VARIANT_GENERIC_XX1E_
/* The definitions here need the MattairTech SAMD core >=1.6.8.
* The format is different than the stock Arduino SAMD core,
* which uses ARDUINO_SAMD_VARIANT_COMPLIANCE instead.
*/
#define MATTAIRTECH_ARDUINO_SAMD_VARIANT_COMPLIANCE 10608
/*----------------------------------------------------------------------------
* Clock Configuration
*----------------------------------------------------------------------------*/
/** Master clock frequency (also Fcpu frequency) */
#define VARIANT_MCK (48000000ul)
/* If CLOCKCONFIG_HS_CRYSTAL is defined, then HS_CRYSTAL_FREQUENCY_HERTZ
* must also be defined with the external crystal frequency in Hertz.
*/
#define HS_CRYSTAL_FREQUENCY_HERTZ 16000000UL
/* If the PLL is used (CLOCKCONFIG_32768HZ_CRYSTAL, or CLOCKCONFIG_HS_CRYSTAL
* defined), then PLL_FRACTIONAL_ENABLED can be defined, which will result in
* a more accurate 48MHz output frequency at the expense of increased jitter.
*/
//#define PLL_FRACTIONAL_ENABLED
/* If both PLL_FAST_STARTUP and CLOCKCONFIG_HS_CRYSTAL are defined, the crystal
* will be divided down to 1MHz - 2MHz, rather than 32KHz - 64KHz, before being
* multiplied by the PLL. This will result in a faster lock time for the PLL,
* however, it will also result in a less accurate PLL output frequency if the
* crystal is not divisible (without remainder) by 1MHz. In this case, define
* PLL_FRACTIONAL_ENABLED as well.
*/
//#define PLL_FAST_STARTUP
/* The fine calibration value for DFLL open-loop mode is defined here.
* The coarse calibration value is loaded from NVM OTP (factory calibration values).
*/
#define NVM_SW_CALIB_DFLL48M_FINE_VAL (512)
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
#include "WVariant.h"
#include "sam.h"
#ifdef __cplusplus
#include "SERCOM.h"
#include "Uart.h"
#endif // __cplusplus
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
/*----------------------------------------------------------------------------
* Pins
*----------------------------------------------------------------------------*/
// Number of pins defined in PinDescription array
#define NUM_PIN_DESCRIPTION_ENTRIES (32u)
#define PINS_COUNT NUM_PIN_DESCRIPTION_ENTRIES
#define NUM_DIGITAL_PINS PINS_COUNT
#define NUM_ANALOG_INPUTS (10u)
#define NUM_ANALOG_OUTPUTS (1u)
#define analogInputToDigitalPin(p) (p)
#define digitalPinToPort(P) ( &(PORT->Group[g_APinDescription[P].ulPort]) )
#define digitalPinToBitMask(P) ( 1 << g_APinDescription[P].ulPin )
//#define analogInPinToBit(P) ( )
#define portOutputRegister(port) ( &(port->OUT.reg) )
#define portInputRegister(port) ( &(port->IN.reg) )
#define portModeRegister(port) ( &(port->DIR.reg) )
#define digitalPinHasPWM(P) ( (g_APinDescription[P].ulPinAttribute & PIN_ATTR_TIMER_PWM) == PIN_ATTR_TIMER_PWM )
/*
* digitalPinToTimer(..) is AVR-specific and is not defined for SAMD
* architecture. If you need to check if a pin supports PWM you must
* use digitalPinHasPWM(..).
*
* https://github.com/arduino/Arduino/issues/1833
*/
// #define digitalPinToTimer(P)
/* LEDs
* None of these defines are currently used by the core.
* The MT-D21E onboard LED is on pin 28.
* The RX and TX LEDs are not present.
* You may optionally add them to any free pins.
*/
#define PIN_LED_13 (28u)
#define PIN_LED_RXL (30u)
#define PIN_LED_TXL (31u)
#define PIN_LED PIN_LED_13
#define PIN_LED2 PIN_LED_RXL
#define PIN_LED3 PIN_LED_TXL
#define LED_BUILTIN PIN_LED_13
/* Buttons
* Note that Button B is connected to Reset by default.
* A solder jumper can be changed to route Button B to pin 31 instead.
* There is a debouncing capacitor connected, so delay reading the pin for
* at least 6ms after turning on the pullup to allow the capacitor to charge.
*/
#define BUTTON_A (27u)
#define BUTTON_B (31u)
#define BUTTON_BUILTIN BUTTON_A
/*
* Analog pins
*/
#define PIN_A2 (2ul)
#define PIN_A3 (3ul)
#define PIN_A4 (4ul)
#define PIN_A5 (5ul)
#define PIN_A6 (6ul)
#define PIN_A7 (7ul)
#define PIN_A8 (8ul)
#define PIN_A9 (9ul)
#define PIN_A10 (10ul)
#define PIN_A11 (11ul)
#define PIN_DAC0 (2ul)
static const uint8_t A2 = PIN_A2;
static const uint8_t A3 = PIN_A3;
static const uint8_t A4 = PIN_A4;
static const uint8_t A5 = PIN_A5;
static const uint8_t A6 = PIN_A6;
static const uint8_t A7 = PIN_A7;
static const uint8_t A8 = PIN_A8;
static const uint8_t A9 = PIN_A9;
static const uint8_t A10 = PIN_A10;
static const uint8_t A11 = PIN_A11;
static const uint8_t DAC0 = PIN_DAC0;
#define ADC_RESOLUTION 12
// #define REMAP_ANALOG_PIN_ID(pin) if ( pin < A0 ) pin += A0
/* Set default analog voltage reference */
#define VARIANT_AR_DEFAULT AR_DEFAULT
/* Reference voltage pins (define even if not enabled with PIN_ATTR_REF in the PinDescription table) */
#define REFA_PIN (3ul)
#define REFB_PIN (4ul)
// The ATN pin may be used in the future as the first SPI chip select.
// On boards that do not have the Arduino physical form factor, it can to set to any free pin.
#define PIN_ATN (15ul)
static const uint8_t ATN = PIN_ATN;
/*
* Serial interfaces
*/
// Serial1
#define PIN_SERIAL1_RX (11ul)
#define PIN_SERIAL1_TX (10ul)
#define PAD_SERIAL1_TX (UART_TX_PAD_2)
#define PAD_SERIAL1_RX (SERCOM_RX_PAD_3)
#define SERCOM_INSTANCE_SERIAL1 &sercom0
// Serial2
#define PIN_SERIAL2_RX (15ul)
#define PIN_SERIAL2_TX (14ul)
#define PAD_SERIAL2_TX (UART_TX_PAD_2)
#define PAD_SERIAL2_RX (SERCOM_RX_PAD_3)
#define SERCOM_INSTANCE_SERIAL2 &sercom2
// Serial3
#define PIN_SERIAL3_RX (31ul)
#define PIN_SERIAL3_TX (30ul)
#define PAD_SERIAL3_TX (UART_TX_PAD_2)
#define PAD_SERIAL3_RX (SERCOM_RX_PAD_3)
#define SERCOM_INSTANCE_SERIAL3 &sercom1
// Serial4
#define PIN_SERIAL4_RX (17ul)
#define PIN_SERIAL4_TX (16ul)
#define PAD_SERIAL4_TX (UART_TX_PAD_0)
#define PAD_SERIAL4_RX (SERCOM_RX_PAD_1)
#define SERCOM_INSTANCE_SERIAL4 &sercom3
/*
* SPI Interfaces
*/
#if defined(TWO_SPI)
#define SPI_INTERFACES_COUNT 2
#else
#define SPI_INTERFACES_COUNT 1
#endif
#define PIN_SPI_MISO (22u)
#define PIN_SPI_MOSI (18u)
#define PIN_SPI_SCK (19u)
#define PIN_SPI_SS (23u)
#define PERIPH_SPI sercom3
#define PAD_SPI_TX SPI_PAD_2_SCK_3
#define PAD_SPI_RX SERCOM_RX_PAD_0
static const uint8_t SS = PIN_SPI_SS ; // The SERCOM SS PAD is available on this pin but HW SS isn't used. Set here only for reference.
static const uint8_t MOSI = PIN_SPI_MOSI ;
static const uint8_t MISO = PIN_SPI_MISO ;
static const uint8_t SCK = PIN_SPI_SCK ;
#define PIN_SPI1_MISO (8u)
#define PIN_SPI1_MOSI (14u)
#define PIN_SPI1_SCK (15u)
#define PIN_SPI1_SS (9u)
#define PERIPH_SPI1 sercom2
#define PAD_SPI1_TX SPI_PAD_2_SCK_3
#define PAD_SPI1_RX SERCOM_RX_PAD_0
static const uint8_t SS1 = PIN_SPI1_SS ; // The SERCOM SS PAD is available on this pin but HW SS isn't used. Set here only for reference.
static const uint8_t MOSI1 = PIN_SPI1_MOSI ;
static const uint8_t MISO1 = PIN_SPI1_MISO ;
static const uint8_t SCK1 = PIN_SPI1_SCK ;
/*
* Wire Interfaces
*/
#if defined(TWO_WIRE)
#define WIRE_INTERFACES_COUNT 2
#else
#define WIRE_INTERFACES_COUNT 1
#endif
#define PIN_WIRE_SDA (16u)
#define PIN_WIRE_SCL (17u)
#if defined(THREE_UART) && defined(ONE_WIRE) && defined(NO_SPI)
#define PERIPH_WIRE sercom3
#define WIRE_IT_HANDLER SERCOM3_Handler
#else
#define PERIPH_WIRE sercom1
#define WIRE_IT_HANDLER SERCOM1_Handler
#endif
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;
#define PIN_WIRE1_SDA (8u)
#define PIN_WIRE1_SCL (9u)
#define PERIPH_WIRE1 sercom2
#define WIRE1_IT_HANDLER SERCOM2_Handler
static const uint8_t SDA1 = PIN_WIRE1_SDA;
static const uint8_t SCL1 = PIN_WIRE1_SCL;
/*
* USB - Define PIN_USB_HOST_ENABLE to assert the defined pin to
* PIN_USB_HOST_ENABLE_VALUE during startup. Leave undefined to disable this pin.
*/
#define PIN_USB_DM (24ul)
#define PIN_USB_DP (25ul)
//#define PIN_USB_HOST_ENABLE (14ul)
#define PIN_USB_HOST_ENABLE_VALUE HIGH
/*
* I2S Interfaces
*/
#define I2S_INTERFACES_COUNT 1
#define I2S_DEVICE 0
#define I2S_CLOCK_GENERATOR 3
#define PIN_I2S_SD (7u)
#define PIN_I2S_SCK (10u)
#define PIN_I2S_FS (11u)
#ifdef __cplusplus
}
#endif
/*----------------------------------------------------------------------------
* Arduino objects - C++ only
*----------------------------------------------------------------------------*/
#ifdef __cplusplus
/* =========================
* ===== SERCOM DEFINITION
* =========================
*/
extern SERCOM sercom0;
extern SERCOM sercom1;
extern SERCOM sercom2;
extern SERCOM sercom3;
extern Uart Serial1;
extern Uart Serial2;
extern Uart Serial3;
extern Uart Serial4;
#endif
// These serial port names are intended to allow libraries and architecture-neutral
// sketches to automatically default to the correct port name for a particular type
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
//
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
//
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
//
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
//
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
//
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
// pins are NOT connected to anything by default.
#define SERIAL_PORT_USBVIRTUAL SerialUSB
// SERIAL_PORT_MONITOR seems to be used only by the USB Host library (as of 1.6.5).
// It normally allows debugging output on the USB programming port, while the USB host uses the USB native port.
// The programming port is connected to a hardware UART through a USB-Serial bridge (EDBG chip) on the Zero.
// Boards that do not have the EDBG chip will have to connect a USB-TTL serial adapter to 'Serial' to get
// the USB Host debugging output.
#define SERIAL_PORT_MONITOR Serial1
// Serial has no physical pins broken out, so it's not listed as HARDWARE port
#define SERIAL_PORT_HARDWARE Serial1
#define SERIAL_PORT_HARDWARE_OPEN Serial1
// The MT-D21E does not have the EDBG support chip, which provides a USB-UART bridge
// accessible using Serial (the Arduino serial monitor is normally connected to this).
// So, the USB virtual serial port (SerialUSB) must be used to communicate with the host.
// Because most sketches use Serial to print to the monitor, it is aliased to SerialUSB.
// Remember to use while(!Serial); to wait for a connection before Serial printing.
// When USB CDC is enabled, Serial refers to SerialUSB, otherwise it refers to Serial1.
#if defined(CDC_ONLY) || defined(CDC_HID) || defined(WITH_CDC)
#define Serial SerialUSB
#else
#define Serial Serial1
#endif
#endif /* _VARIANT_GENERIC_XX1E_ */