Robobo
variant.h
1 /*
2  Copyright (c) 2011 Arduino. All right reserved.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  See the GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef _VARIANT_ARDUINO_DUE_X_
20 #define _VARIANT_ARDUINO_DUE_X_
21 
22 /*----------------------------------------------------------------------------
23  * Definitions
24  *----------------------------------------------------------------------------*/
25 
27 #define VARIANT_MAINOSC 12000000
28 
30 #define VARIANT_MCK 84000000
31 
32 /*----------------------------------------------------------------------------
33  * Headers
34  *----------------------------------------------------------------------------*/
35 
36 #include "Arduino.h"
37 #ifdef __cplusplus
38 #include "UARTClass.h"
39 #include "USARTClass.h"
40 #endif
41 
42 #ifdef __cplusplus
43 extern "C"{
44 #endif // __cplusplus
45 
49 #if defined ( __GNUC__ ) /* GCC CS3 */
50 # include <syscalls.h>
51 #endif
52 
53 /*----------------------------------------------------------------------------
54  * Pins
55  *----------------------------------------------------------------------------*/
56 
57 // Number of pins defined in PinDescription array
58 #define PINS_COUNT (79u)
59 #define NUM_DIGITAL_PINS (66u)
60 #define NUM_ANALOG_INPUTS (12u)
61 #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
62 
63 #define digitalPinToPort(P) ( g_APinDescription[P].pPort )
64 #define digitalPinToBitMask(P) ( g_APinDescription[P].ulPin )
65 //#define analogInPinToBit(P) ( )
66 #define portOutputRegister(port) ( &(port->PIO_ODSR) )
67 #define portInputRegister(port) ( &(port->PIO_PDSR) )
68 #define digitalPinHasPWM(P) ( g_APinDescription[P].ulPWMChannel != NOT_ON_PWM || g_APinDescription[P].ulTCChannel != NOT_ON_TIMER )
69 
70 /*
71  * portModeRegister(..) should return a register to set pin mode
72  * INPUT or OUTPUT by setting the corresponding bit to 0 or 1.
73  * Unfortunately on SAM architecture the PIO_OSR register is
74  * read-only and can be set only through the enable/disable registers
75  * pair PIO_OER/PIO_ODR.
76  */
77 // #define portModeRegister(port) ( &(port->PIO_OSR) )
78 
79 /*
80  * digitalPinToTimer(..) is AVR-specific and is not defined for SAM
81  * architecture. If you need to check if a pin supports PWM you must
82  * use digitalPinHasPWM(..).
83  *
84  * https://github.com/arduino/Arduino/issues/1833
85  */
86 // #define digitalPinToTimer(P)
87 
88 // Interrupts
89 #define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
90 
91 // LEDs
92 #define PIN_LED_13 (13u)
93 #define PIN_LED_RXL (72u)
94 #define PIN_LED_TXL (73u)
95 #define PIN_LED PIN_LED_13
96 #define PIN_LED2 PIN_LED_RXL
97 #define PIN_LED3 PIN_LED_TXL
98 #define LED_BUILTIN 13
99 
100 /*
101  * SPI Interfaces
102  */
103 #define SPI_INTERFACES_COUNT 1
104 
105 #define SPI_INTERFACE SPI0
106 #define SPI_INTERFACE_ID ID_SPI0
107 #define SPI_CHANNELS_NUM 4
108 #define PIN_SPI_SS0 (77u)
109 #define PIN_SPI_SS1 (87u)
110 #define PIN_SPI_SS2 (86u)
111 #define PIN_SPI_SS3 (78u)
112 #define PIN_SPI_MOSI (75u)
113 #define PIN_SPI_MISO (74u)
114 #define PIN_SPI_SCK (76u)
115 #define BOARD_SPI_SS0 (10u)
116 #define BOARD_SPI_SS1 (4u)
117 #define BOARD_SPI_SS2 (52u)
118 #define BOARD_SPI_SS3 PIN_SPI_SS3
119 #define BOARD_SPI_DEFAULT_SS BOARD_SPI_SS3
120 
121 #define BOARD_PIN_TO_SPI_PIN(x) \
122  (x==BOARD_SPI_SS0 ? PIN_SPI_SS0 : \
123  (x==BOARD_SPI_SS1 ? PIN_SPI_SS1 : \
124  (x==BOARD_SPI_SS2 ? PIN_SPI_SS2 : PIN_SPI_SS3 )))
125 #define BOARD_PIN_TO_SPI_CHANNEL(x) \
126  (x==BOARD_SPI_SS0 ? 0 : \
127  (x==BOARD_SPI_SS1 ? 1 : \
128  (x==BOARD_SPI_SS2 ? 2 : 3)))
129 
130 static const uint8_t SS = BOARD_SPI_SS0;
131 static const uint8_t SS1 = BOARD_SPI_SS1;
132 static const uint8_t SS2 = BOARD_SPI_SS2;
133 static const uint8_t SS3 = BOARD_SPI_SS3;
134 static const uint8_t MOSI = PIN_SPI_MOSI;
135 static const uint8_t MISO = PIN_SPI_MISO;
136 static const uint8_t SCK = PIN_SPI_SCK;
137 
138 /*
139  * Wire Interfaces
140  */
141 #define WIRE_INTERFACES_COUNT 2
142 
143 #define PIN_WIRE_SDA (20u)
144 #define PIN_WIRE_SCL (21u)
145 #define WIRE_INTERFACE TWI1
146 #define WIRE_INTERFACE_ID ID_TWI1
147 #define WIRE_ISR_HANDLER TWI1_Handler
148 #define WIRE_ISR_ID TWI1_IRQn
149 
150 #define PIN_WIRE1_SDA (70u)
151 #define PIN_WIRE1_SCL (71u)
152 #define WIRE1_INTERFACE TWI0
153 #define WIRE1_INTERFACE_ID ID_TWI0
154 #define WIRE1_ISR_HANDLER TWI0_Handler
155 #define WIRE1_ISR_ID TWI0_IRQn
156 
157 static const uint8_t SDA = PIN_WIRE_SDA;
158 static const uint8_t SCL = PIN_WIRE_SCL;
159 static const uint8_t SDA1 = PIN_WIRE1_SDA;
160 static const uint8_t SCL1 = PIN_WIRE1_SCL;
161 
162 /*
163  * UART/USART Interfaces
164  */
165 // Serial
166 #define PINS_UART (81u)
167 // Serial1
168 #define PINS_USART0 (82u)
169 // Serial2
170 #define PINS_USART1 (83u)
171 // Serial3
172 #define PINS_USART3 (84u)
173 
174 /*
175  * USB Interfaces
176  */
177 #define PINS_USB (85u)
178 
179 /*
180  * Analog pins
181  */
182 static const uint8_t A0 = 54;
183 static const uint8_t A1 = 55;
184 static const uint8_t A2 = 56;
185 static const uint8_t A3 = 57;
186 static const uint8_t A4 = 58;
187 static const uint8_t A5 = 59;
188 static const uint8_t A6 = 60;
189 static const uint8_t A7 = 61;
190 static const uint8_t A8 = 62;
191 static const uint8_t A9 = 63;
192 static const uint8_t A10 = 64;
193 static const uint8_t A11 = 65;
194 static const uint8_t DAC0 = 66;
195 static const uint8_t DAC1 = 67;
196 static const uint8_t CANRX = 68;
197 static const uint8_t CANTX = 69;
198 #define ADC_RESOLUTION 12
199 
200 /*
201  * Complementary CAN pins
202  */
203 static const uint8_t CAN1RX = 88;
204 static const uint8_t CAN1TX = 89;
205 
206 // CAN0
207 #define PINS_CAN0 (90u)
208 // CAN1
209 #define PINS_CAN1 (91u)
210 
211 
212 /*
213  * DACC
214  */
215 #define DACC_INTERFACE DACC
216 #define DACC_INTERFACE_ID ID_DACC
217 #define DACC_RESOLUTION 12
218 #define DACC_ISR_HANDLER DACC_Handler
219 #define DACC_ISR_ID DACC_IRQn
220 
221 /*
222  * PWM
223  */
224 #define PWM_INTERFACE PWM
225 #define PWM_INTERFACE_ID ID_PWM
226 #define PWM_FREQUENCY 1000
227 #define PWM_MAX_DUTY_CYCLE 255
228 #define PWM_MIN_DUTY_CYCLE 0
229 #define PWM_RESOLUTION 8
230 
231 /*
232  * TC
233  */
234 #define TC_INTERFACE TC0
235 #define TC_INTERFACE_ID ID_TC0
236 #define TC_FREQUENCY 1000
237 #define TC_MAX_DUTY_CYCLE 255
238 #define TC_MIN_DUTY_CYCLE 0
239 #define TC_RESOLUTION 8
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 
245 /*----------------------------------------------------------------------------
246  * Arduino objects - C++ only
247  *----------------------------------------------------------------------------*/
248 
249 #ifdef __cplusplus
250 
251 extern UARTClass Serial;
252 extern USARTClass Serial1;
253 extern USARTClass Serial2;
254 extern USARTClass Serial3;
255 
256 #endif
257 
258 // These serial port names are intended to allow libraries and architecture-neutral
259 // sketches to automatically default to the correct port name for a particular type
260 // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
261 // the first hardware serial port whose RX/TX pins are not dedicated to another use.
262 //
263 // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
264 //
265 // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
266 //
267 // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
268 //
269 // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
270 //
271 // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
272 // pins are NOT connected to anything by default.
273 #define SERIAL_PORT_MONITOR Serial
274 #define SERIAL_PORT_USBVIRTUAL SerialUSB
275 #define SERIAL_PORT_HARDWARE_OPEN Serial1
276 #define SERIAL_PORT_HARDWARE_OPEN1 Serial2
277 #define SERIAL_PORT_HARDWARE_OPEN2 Serial3
278 #define SERIAL_PORT_HARDWARE Serial
279 #define SERIAL_PORT_HARDWARE1 Serial1
280 #define SERIAL_PORT_HARDWARE2 Serial2
281 #define SERIAL_PORT_HARDWARE3 Serial3
282 
283 #endif /* _VARIANT_ARDUINO_DUE_X_ */
284