update teensy3 lib to latest, use new vector change mechanism
[teensytas.git] / teensy3 / pins_arduino.h
CommitLineData
35f00b6c 1/* Teensyduino Core Library
2 * http://www.pjrc.com/teensy/
3 * Copyright (c) 2013 PJRC.COM, LLC.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
a773ac06 13 * 1. The above copyright notice and this permission notice shall be
35f00b6c 14 * included in all copies or substantial portions of the Software.
15 *
a773ac06 16 * 2. If the Software is incorporated into a build system that allows
35f00b6c 17 * selection among a list of target devices, then similar target
18 * devices manufactured by PJRC.COM must be included in the list of
19 * target devices and selectable in the same manner.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
25 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * SOFTWARE.
29 */
30
31#ifndef pins_macros_for_arduino_compatibility_h
32#define pins_macros_for_arduino_compatibility_h
33
34#include <stdint.h>
35
36const static uint8_t A0 = 14;
37const static uint8_t A1 = 15;
38const static uint8_t A2 = 16;
39const static uint8_t A3 = 17;
40const static uint8_t A4 = 18;
41const static uint8_t A5 = 19;
42const static uint8_t A6 = 20;
43const static uint8_t A7 = 21;
44const static uint8_t A8 = 22;
45const static uint8_t A9 = 23;
46const static uint8_t A10 = 34;
47const static uint8_t A11 = 35;
48const static uint8_t A12 = 36;
49const static uint8_t A13 = 37;
50const static uint8_t A14 = 40;
51
52const static uint8_t A15 = 26;
53const static uint8_t A16 = 27;
54const static uint8_t A17 = 28;
55const static uint8_t A18 = 29;
56const static uint8_t A19 = 30;
57const static uint8_t A20 = 31;
58
59const static uint8_t SS = 10;
60const static uint8_t MOSI = 11;
61const static uint8_t MISO = 12;
62const static uint8_t SCK = 13;
63const static uint8_t LED_BUILTIN = 13;
64const static uint8_t SDA = 18;
65const static uint8_t SCL = 19;
66
67
68#define NUM_DIGITAL_PINS 34
69#define NUM_ANALOG_INPUTS 14
70
71#define analogInputToDigitalPin(p) (((p) < 10) ? (p) + 14 : -1)
72#define digitalPinHasPWM(p) (((p) >= 3 && (p) <= 6) || (p) == 9 || (p) == 10 || ((p) >= 20 && (p) <= 23))
73
74#define NOT_AN_INTERRUPT -1
75#define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
76
77
78struct digital_pin_bitband_and_config_table_struct {
79 volatile uint32_t *reg;
80 volatile uint32_t *config;
81};
82extern const struct digital_pin_bitband_and_config_table_struct digital_pin_to_info_PGM[];
83
84// compatibility macros
85#define digitalPinToPort(pin) (pin)
86#define digitalPinToBitMask(pin) (1)
87#define portOutputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 0))
88#define portSetRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 32))
89#define portClearRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 64))
90#define portToggleRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 96))
91#define portInputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 128))
92#define portModeRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 160))
93#define portConfigRegister(pin) ((volatile uint32_t *)(digital_pin_to_info_PGM[(pin)].config))
94
95
96#define digitalPinToPortReg(pin) (portOutputRegister(pin))
97#define digitalPinToBit(pin) (1)
98
99
100#define NOT_ON_TIMER 0
101static inline uint8_t digitalPinToTimer(uint8_t) __attribute__((always_inline, unused));
102static inline uint8_t digitalPinToTimer(uint8_t pin)
103{
104 if (pin >= 3 && pin <= 6) return pin - 2;
105 if (pin >= 9 && pin <= 10) return pin - 4;
106 if (pin >= 20 && pin <= 23) return pin - 13;
107 return NOT_ON_TIMER;
108}
109
a773ac06 110// These serial port names are intended to allow libraries and architecture-neutral
111// sketches to automatically default to the correct port name for a particular type
112// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
113// the first hardware serial port whose RX/TX pins are not dedicated to another use.
114//
115// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
116//
117// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
118//
119// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
120//
121// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
122//
123// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
124// pins are NOT connected to anything by default.
125//
126#define SERIAL_PORT_MONITOR Serial
127#define SERIAL_PORT_USBVIRTUAL Serial
128#define SERIAL_PORT_HARDWARE Serial1
129#define SERIAL_PORT_HARDWARE1 Serial2
130#define SERIAL_PORT_HARDWARE2 Serial3
131#define SERIAL_PORT_HARDWARE_OPEN Serial1
132#define SERIAL_PORT_HARDWARE_OPEN1 Serial2
133#define SERIAL_PORT_HARDWARE_OPEN2 Serial3
35f00b6c 134
135
136#endif