diff options
| author | blmorris <bryan.morrissey@gmail.com> | 2014-07-18 16:06:22 -0400 |
|---|---|---|
| committer | blmorris <bryan.morrissey@gmail.com> | 2014-07-18 16:06:22 -0400 |
| commit | 0f4ee2e44a1e47258a8b07fb25e28286d131390c (patch) | |
| tree | 7bfb507183544d14236c0be8a232a92f4113abb1 /teensy/core/pins_arduino.h | |
| parent | 0429d35f37532d2a981e704f014a248da9b157d8 (diff) | |
| parent | 5467186b0eaa6e856b00f60f807bb988ae2ef8c5 (diff) | |
Merge https://github.com/micropython/micropython
Diffstat (limited to 'teensy/core/pins_arduino.h')
| -rw-r--r-- | teensy/core/pins_arduino.h | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/teensy/core/pins_arduino.h b/teensy/core/pins_arduino.h new file mode 100644 index 000000000..03674933c --- /dev/null +++ b/teensy/core/pins_arduino.h @@ -0,0 +1,113 @@ +/* Teensyduino Core Library + * http://www.pjrc.com/teensy/ + * Copyright (c) 2013 PJRC.COM, LLC. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * 1. The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * 2. If the Software is incorporated into a build system that allows + * selection among a list of target devices, then similar target + * devices manufactured by PJRC.COM must be included in the list of + * target devices and selectable in the same manner. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef pins_macros_for_arduino_compatibility_h +#define pins_macros_for_arduino_compatibility_h + +#include <stdint.h> + +const static uint8_t A0 = 14; +const static uint8_t A1 = 15; +const static uint8_t A2 = 16; +const static uint8_t A3 = 17; +const static uint8_t A4 = 18; +const static uint8_t A5 = 19; +const static uint8_t A6 = 20; +const static uint8_t A7 = 21; +const static uint8_t A8 = 22; +const static uint8_t A9 = 23; +const static uint8_t A10 = 34; +const static uint8_t A11 = 35; +const static uint8_t A12 = 36; +const static uint8_t A13 = 37; +const static uint8_t A14 = 40; + +const static uint8_t A15 = 26; +const static uint8_t A16 = 27; +const static uint8_t A17 = 28; +const static uint8_t A18 = 29; +const static uint8_t A19 = 30; +const static uint8_t A20 = 31; + +const static uint8_t SS = 10; +const static uint8_t MOSI = 11; +const static uint8_t MISO = 12; +const static uint8_t SCK = 13; +const static uint8_t LED_BUILTIN = 13; +const static uint8_t SDA = 18; +const static uint8_t SCL = 19; + + +#define NUM_DIGITAL_PINS 34 +#define NUM_ANALOG_INPUTS 14 + +#define analogInputToDigitalPin(p) (((p) < 10) ? (p) + 14 : -1) +#define digitalPinHasPWM(p) (((p) >= 3 && (p) <= 6) || (p) == 9 || (p) == 10 || ((p) >= 20 && (p) <= 23)) + +#define NOT_AN_INTERRUPT -1 +#define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1) + + +struct digital_pin_bitband_and_config_table_struct { + volatile uint32_t *reg; + volatile uint32_t *config; +}; +extern const struct digital_pin_bitband_and_config_table_struct digital_pin_to_info_PGM[]; + +// compatibility macros +#define digitalPinToPort(pin) (pin) +#define digitalPinToBitMask(pin) (1) +#define portOutputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 0)) +#define portSetRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 32)) +#define portClearRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 64)) +#define portToggleRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 96)) +#define portInputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 128)) +#define portModeRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 160)) +#define portConfigRegister(pin) ((volatile uint32_t *)(digital_pin_to_info_PGM[(pin)].config)) + + +#define digitalPinToPortReg(pin) (portOutputRegister(pin)) +#define digitalPinToBit(pin) (1) + + +#define NOT_ON_TIMER 0 +static inline uint8_t digitalPinToTimer(uint8_t) __attribute__((always_inline, unused)); +static inline uint8_t digitalPinToTimer(uint8_t pin) +{ + if (pin >= 3 && pin <= 6) return pin - 2; + if (pin >= 9 && pin <= 10) return pin - 4; + if (pin >= 20 && pin <= 23) return pin - 13; + return NOT_ON_TIMER; +} + + + + +#endif |
