diff --git a/.ci/arduino.groovy b/.ci/arduino.groovy index 65df8c7..0be35cd 100644 --- a/.ci/arduino.groovy +++ b/.ci/arduino.groovy @@ -42,7 +42,7 @@ def buildnRF52832(config, sketches, String key) { def fqbn = '-fqbn=MySensors:nRF5:MyBoard_nRF52832:bootcode=none,lfclk=lfxo,reset=notenable -prefs build.f_cpu=16000000 -prefs build.mcu=cortex-m4' config.pr.setBuildStatus(config, 'PENDING', 'Toll gate (nRF52832 - '+key+')', 'Building...', '${BUILD_URL}flowGraphTable/') try { - buildArduino(config, fqbn, config.repository_root+'libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.ino', key+'_nRF52832') + buildArduino(config, fqbn, config.repository_root+'libraries/MyBoardNRF5/examples/MyBoardNRF5/MyBoardNRF5.ino', key+'_nRF52832') } catch (ex) { echo "Build failed with: "+ ex.toString() config.pr.setBuildStatus(config, 'FAILURE', 'Toll gate (nRF52832 - '+key+')', 'Build error', '${BUILD_URL}') @@ -66,7 +66,7 @@ def buildnRF51822(config, sketches, String key) { def fqbn = '-fqbn=MySensors:nRF5:MyBoard_nRF51822:chip=xxaa,bootcode=none,lfclk=lfxo -prefs build.f_cpu=16000000 -prefs build.mcu=cortex-m0' config.pr.setBuildStatus(config, 'PENDING', 'Toll gate (nRF51822 - '+key+')', 'Building...', '${BUILD_URL}flowGraphTable/') try { - buildArduino(config, fqbn, config.repository_root+'libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.ino', key+'_nRF51822') + buildArduino(config, fqbn, config.repository_root+'libraries/MyBoardNRF5/examples/MyBoardNRF5/MyBoardNRF5.ino', key+'_nRF51822') } catch (ex) { echo "Build failed with: "+ ex.toString() config.pr.setBuildStatus(config, 'FAILURE', 'Toll gate (nRF51822 - '+key+')', 'Build error', '${BUILD_URL}') diff --git a/README.md b/README.md index 42b2616..c7db0f4 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Current build status of master branch with respect to the master and development Current build status of master branch with respect to the master and development branch of the MySensors library using the nightly build of the Arduino IDE: [![Build Status](https://ci.mysensors.org/job/MySensors-nightly-IDE/job/ArduinoHwNRF5/job/master/badge/icon)](https://ci.mysensors.org/job/MySensors-nightly-IDE/job/ArduinoHwNRF5/job/master/) -## MyNRF5Board +## MyBoardNRF5 This repository allows managing the nRF5 pin mapping as part of your code. You can use the method for any nRF51822 or nRF52832 board or module. @@ -24,27 +24,27 @@ To use the custom pin mapping you have to do following steps: https://github.com/sandeepmistry/arduino-nRF5/ 2. Install the "My Sensors nRF5 Boards" with the board manager like explained at https://github.com/mysensors/ArduinoBoards - 3. Copy the files "MyNRF5Board.cpp" and "MyNRF5Board.h" from - "MyNRF5Board" example into your sketch. - 4. Modify pin mappings in "MyNRF5Board.cpp" and "MyNRF5Board.h" to fit + 3. Copy the files "MyBoardNRF5.cpp" and "MyBoardNRF5.h" from + "MyBoardNRF5" example into your sketch. + 4. Modify pin mappings in "MyBoardNRF5.cpp" and "MyBoardNRF5.h" to fit your requirements. - 5. Select "MyNRF5Board nrf52832" or "MyNRF5Board nrf52822" as your board. + 5. Select "MyBoardNRF5 nrf52832" or "MyBoardNRF5 nrf52822" as your board. Choose the correct parameters and programmer in the Tools menu. -### MyNRF5Board.h +### MyBoardNRF5.h This file allows you to change the pins of internal hardware, like the serial port, SPI bus or Wire bus. All pins referenced here are mapped via the "g_ADigitalPinMap" Array -defined in "MyNRF5Board.cpp" to pins of the MCU. +defined in "MyBoardNRF5.cpp" to pins of the MCU. As an example, if you have at the third position in "g_ADigitalPinMap" the 12, then all ports referenced in Arduino with 2 are mapped to P0.12. If you don't change the "g_ADigitalPinMap" Array, the Arduino pins 0..31 are translated to P0.00..P0..31. -### MyNRF5Board.cpp +### MyBoardNRF5.cpp This file allows you to change the relation between pins referenced in the Arduino IDE (0..31) and pins of the nRF5 MCU (P0.00..P0.31). @@ -65,7 +65,7 @@ The pin mapping effects commands like "pinMode()", "digitalWrite()", "analogRead()" and "analogWrite()". If you change the pin mapping, you have to modify the pins in -"MyNRF5Board.h". Especially the analog pin mapping must be replaced with +"MyBoardNRF5.h". Especially the analog pin mapping must be replaced with your pin numbers by replacing PIN_AIN0..7 with a number of your mapping array. You can use the constants PIN_AIN0..7 in the "g_ADigitalPinMap" Array if you want to reference analog ports MCU independent. You cannot diff --git a/boards.txt b/boards.txt index 485fbb8..8e40a80 100644 --- a/boards.txt +++ b/boards.txt @@ -21,13 +21,13 @@ menu.bootcode=Bootloader/SD menu.lfclk=Low Frequency Clock menu.reset=Reset -# MyNRF5Board nRF52832 +# MyBoardNRF5 nRF52832 # Board definition is expected in # MyBoard.cpp and MyBoard.h as part # of the sketch ################################### -MyBoard_nRF52832.name=MyNRF5Board nRF52832 +MyBoard_nRF52832.name=MyBoardNRF5 nRF52832 MyBoard_nRF52832.bootloader.tool=sandeepmistry:openocd @@ -39,9 +39,9 @@ MyBoard_nRF52832.build.mcu=cortex-m4 MyBoard_nRF52832.build.f_cpu=16000000 MyBoard_nRF52832.build.board=GENERIC MyBoard_nRF52832.build.core=sandeepmistry:nRF5 -MyBoard_nRF52832.build.variant=MyNRF5Board +MyBoard_nRF52832.build.variant=MyBoardNRF5 MyBoard_nRF52832.build.variant_system_lib= -# -I{build.path} and -DMYNRF5BOARD is only required by MyNRF5Board +# -I{build.path} and -DMYNRF5BOARD is only required by MyBoardNRF5 MyBoard_nRF52832.build.extra_flags=-DNRF52 -DMYNRF5BOARD -I{build.path} MyBoard_nRF52832.build.float_flags=-mfloat-abi=hard -mfpu=fpv4-sp-d16 MyBoard_nRF52832.build.ldscript=nrf52_xxaa.ld @@ -68,13 +68,13 @@ MyBoard_nRF52832.menu.reset.enabled=Enable MyBoard_nRF52832.menu.reset.enabled.build.reset_flags=-DCONFIG_GPIO_AS_PINRESET -# MyNRF5Board nRF51822 +# MyBoardNRF5 nRF51822 # Board definition is expected in # MyBoard.cpp and MyBoard.h as part # of the sketch ################################### -MyBoard_nRF51822.name=MyNRF5Board nRF51822 +MyBoard_nRF51822.name=MyBoardNRF5 nRF51822 MyBoard_nRF51822.bootloader.tool=sandeepmistry:openocd MyBoard_nRF51822.upload.tool=sandeepmistry:openocd MyBoard_nRF51822.upload.target=nrf51 @@ -84,9 +84,9 @@ MyBoard_nRF51822.build.mcu=cortex-m0 MyBoard_nRF51822.build.f_cpu=16000000 MyBoard_nRF51822.build.board=GENERIC MyBoard_nRF51822.build.core=sandeepmistry:nRF5 -MyBoard_nRF51822.build.variant=MyNRF5Board +MyBoard_nRF51822.build.variant=MyBoardNRF5 MyBoard_nRF51822.build.variant_system_lib= -# -I{build.path} and -DMYNRF5BOARD is only required by MyNRF5Board +# -I{build.path} and -DMYNRF5BOARD is only required by MyBoardNRF5 MyBoard_nRF51822.build.extra_flags=-DNRF51 -DMYNRF5BOARD -I{build.path} MyBoard_nRF51822.build.float_flags= MyBoard_nRF51822.build.ldscript=nrf51_{build.chip}.ld diff --git a/libraries/MyNRF5Board/dummy.h b/libraries/MyBoardNRF5/dummy.h similarity index 100% rename from libraries/MyNRF5Board/dummy.h rename to libraries/MyBoardNRF5/dummy.h diff --git a/libraries/MyBoardNRF5/examples/MyBoardNRF5/MyBoardNRF5.cpp b/libraries/MyBoardNRF5/examples/MyBoardNRF5/MyBoardNRF5.cpp new file mode 100644 index 0000000..c3cf250 --- /dev/null +++ b/libraries/MyBoardNRF5/examples/MyBoardNRF5/MyBoardNRF5.cpp @@ -0,0 +1,107 @@ +/* + If you don't use an nRF5 board, you can ignore this file. + + This file was part of the "My Sensors nRF5 Boards" board repository + available at https://github.com/mysensors/ArduinoBoards If you have + questions, please refer the documentation at + https://github.com/mysensors/ArduinoHwNRF5 first. + + This file is compatible with ArduinoHwNRF5 >= 0.2.0 + + This file allows you to change the relation between pins referenced in + the Arduino IDE (0..31) and pins of the nRF5 MCU (P0.00..P0.31). + + If you can live with addressing the GPIO pins by using the Arduino pins + 0..31 instead of a custom mapping, don't change this file. If you have + a lot of Arduino code with fixed pin numbers and you need to map these + pins to specific pins of the nRF5 MCU; you need to change this file. + + If you fill the "g_APinDescription" Array with numbers between 0..31, + the Arduino pins 0..31 are assigned to pins P0.00..P0.31 of the MCU. + + As an example, if you need to change the pin mapping for Arduino pin 5 + to P0.12 of the MCU, you have to write the 12 after PORT0 into the sixth + position in the "g_APinDescription" Array. + + The extended attributes only affects the nRF5 variants provided with + official Arduino boards. The arduino-nrf5 variant ignores the extended + attributes. + + The pin mapping effects commands like "pinMode()", "digitalWrite()", + "analogRead()" and "analogWrite()". + + If you change the pin mapping, you have to modify the pins in + "MyBoardNRF5.h". Especially the analog pin mapping must be replaced with + your pin numbers by replacing PIN_AIN0..7 with a number of your mapping + array. You can use the constants PIN_AIN0..7 in the "g_APinDescription" + Array if you want to reference analog ports MCU independent. You cannot + use the pins P0.00 and P0.01 for GPIO, when the 32kHz crystal is connected. + + + ########################################################################### + + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Arduino Srl. All right reserved. + Copyright (c) 2017 Sensnology AB. 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 +*/ + + + +#ifdef MYNRF5BOARD +#include + +/* + * Pins descriptions. Attributes are ignored by arduino-nrf5 variant. + * Definition taken from Arduino Primo Core with ordered ports + */ +const PinDescription g_APinDescription[]= +{ + { NOT_A_PORT, 0, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // LFCLK + { NOT_A_PORT, 1, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // LFCLK + { PORT0, 2, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A0, PWM4, NOT_ON_TIMER}, + { PORT0, 3, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A1, PWM5, NOT_ON_TIMER}, + { PORT0, 4, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A2, PWM6, NOT_ON_TIMER}, + { PORT0, 5, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A3, PWM7, NOT_ON_TIMER}, + { PORT0, 6, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT3 + { PORT0, 7, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT4 + { PORT0, 8, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM10, NOT_ON_TIMER}, //USER_LED + { PORT0, 9, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // NFC1 + { PORT0, 10, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // NFC2 + { PORT0, 11, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // TX + { PORT0, 12, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // RX + { PORT0, 13, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // SDA + { PORT0, 14, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // SCL + { PORT0, 15, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // SDA1 + { PORT0, 16, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // SCL1 + { PORT0, 17, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // TP4 + { PORT0, 18, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // TP5 + { PORT0, 19, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT2 + { PORT0, 20, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT1 + { PORT0, 21, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT1 + { PORT0, 22, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM9, NOT_ON_TIMER}, + { PORT0, 23, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM8, NOT_ON_TIMER}, + { PORT0, 24, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT + { PORT0, 25, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER}, //RED_LED + { PORT0, 26, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER}, //GREEN_LED + { PORT0, 27, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER}, //BLUE_LED + { PORT0, 28, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A4, PWM3, NOT_ON_TIMER}, + { PORT0, 29, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A5, PWM2, NOT_ON_TIMER}, + { PORT0, 30, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A6, PWM1, NOT_ON_TIMER}, + { PORT0, 31, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A7, PWM0, NOT_ON_TIMER} +}; + +#endif diff --git a/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.h b/libraries/MyBoardNRF5/examples/MyBoardNRF5/MyBoardNRF5.h similarity index 68% rename from libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.h rename to libraries/MyBoardNRF5/examples/MyBoardNRF5/MyBoardNRF5.h index 7834699..f78ff9f 100644 --- a/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.h +++ b/libraries/MyBoardNRF5/examples/MyBoardNRF5/MyBoardNRF5.h @@ -6,13 +6,13 @@ questions, please refer the documentation at https://github.com/mysensors/ArduinoHwNRF5 first. - This file is compatible with ArduinoHwNRF5 > 0.1.0 + This file is compatible with ArduinoHwNRF5 >= 0.2.0 This file allows you to change the pins of internal hardware, like the serial port, SPI bus or Wire bus. All pins referenced here are mapped via the "g_ADigitalPinMap" Array - defined in "MyNRF5Board.cpp" to pins of the MCU. + defined in "MyBoardNRF5.cpp" to pins of the MCU. As an example, if you have at the third position in "g_ADigitalPinMap" the 12, then all ports referenced in Arduino with 2 are mapped to P0.12. If you @@ -64,14 +64,19 @@ extern "C" * https://github.com/mysensors/MySensors/blob/development/drivers/NRF5/nrf5_wiring_constants.h * */ -#define PIN_LED1 (13) -// #define PIN_LED2 (9) -// #define PIN_LED3 (10) -// #define PIN_LED4 (11) -// #define PIN_LED5 (12) -// #define PIN_LED6 (14) -// #define PIN_LED7 (15) -// #define PIN_LED8 (16) +#define PIN_LED1 (8) +// #define PIN_LED2 (25) +// #define PIN_LED3 (26) +// #define PIN_LED4 (27) +// #define PIN_LED5 (12) +// #define PIN_LED6 (14) +// #define PIN_LED7 (15) +// #define PIN_LED8 (16) +// #define USER_LED (PIN_LED2) +// #define RED_LED (PIN_LED3) +// #define GREEN_LED (PIN_LED4) +// #define BLUE_LED (PIN_LED1) +// #define BLE_LED BLUE_LED #define LED_BUILTIN PIN_LED1 /* @@ -91,21 +96,21 @@ extern "C" /* * Analog ports * - * If you change g_ADigitalPinMap, replace PIN_AIN0 with - * port numbers mapped by the g_ADigitalPinMap Array. - * You can add PIN_AIN0 to the g_ADigitalPinMap Array if + * If you change g_APinDescription, replace PIN_AIN0 with + * port numbers mapped by the g_APinDescription Array. + * You can add PIN_AIN0 to the g_APinDescription Array if * you want provide analog ports MCU independed, you can add - * PIN_AIN0..PIN_AIN7 to your custom g_ADigitalPinMap Array - * defined in MyNRF5Board.cpp + * PIN_AIN0..PIN_AIN7 to your custom g_APinDescription Array + * defined in MyBoardNRF5.cpp */ -static const uint8_t A0 = PIN_AIN0; -static const uint8_t A1 = PIN_AIN1; -static const uint8_t A2 = PIN_AIN2; -static const uint8_t A3 = PIN_AIN3; -static const uint8_t A4 = PIN_AIN4; -static const uint8_t A5 = PIN_AIN5; -static const uint8_t A6 = PIN_AIN6; -static const uint8_t A7 = PIN_AIN7; +static const uint8_t A0 = ADC_A0; +static const uint8_t A1 = ADC_A1; +static const uint8_t A2 = ADC_A2; +static const uint8_t A3 = ADC_A3; +static const uint8_t A4 = ADC_A4; +static const uint8_t A5 = ADC_A5; +static const uint8_t A6 = ADC_A6; +static const uint8_t A7 = ADC_A7; /* * Serial interfaces @@ -114,10 +119,10 @@ static const uint8_t A7 = PIN_AIN7; * If you have no serial port, use unused pins * CTS and RTS are optional. */ -#define PIN_SERIAL_RX (2) -#define PIN_SERIAL_TX (3) -// #define PIN_SERIAL_CTS (4) -// #define PIN_SERIAL_RTS (5) +#define PIN_SERIAL_RX (12) +#define PIN_SERIAL_TX (11) +// #define PIN_SERIAL_CTS (13) +// #define PIN_SERIAL_RTS (14) /* * SPI Interfaces @@ -129,10 +134,10 @@ static const uint8_t A7 = PIN_AIN7; */ #define SPI_INTERFACES_COUNT 1 -#define PIN_SPI_MISO (22) -#define PIN_SPI_MOSI (23) -#define PIN_SPI_SCK (24) -#define PIN_SPI_SS (21) +#define PIN_SPI_MISO (2) +#define PIN_SPI_MOSI (3) +#define PIN_SPI_SCK (4) +#define PIN_SPI_SS (5) static const uint8_t SS = PIN_SPI_SS; static const uint8_t MOSI = PIN_SPI_MOSI; @@ -144,10 +149,13 @@ static const uint8_t SCK = PIN_SPI_SCK; * * This is optional */ -#define WIRE_INTERFACES_COUNT 1 +#define WIRE_INTERFACES_COUNT 2 + +#define PIN_WIRE_SDA (13u) +#define PIN_WIRE_SCL (14u) -#define PIN_WIRE_SDA (20u) -#define PIN_WIRE_SCL (21u) +#define PIN_WIRE_SDA1 (15u) +#define PIN_WIRE_SCL1 (16u) static const uint8_t SDA = PIN_WIRE_SDA; static const uint8_t SCL = PIN_WIRE_SCL; diff --git a/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.ino b/libraries/MyBoardNRF5/examples/MyBoardNRF5/MyBoardNRF5.ino similarity index 79% rename from libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.ino rename to libraries/MyBoardNRF5/examples/MyBoardNRF5/MyBoardNRF5.ino index 49c340d..c19f633 100644 --- a/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.ino +++ b/libraries/MyBoardNRF5/examples/MyBoardNRF5/MyBoardNRF5.ino @@ -13,11 +13,11 @@ * https://github.com/sandeepmistry/arduino-nRF5/ * 2. Install the "My Sensors nRF5 Boards" with the board manager like * explained at https://github.com/mysensors/ArduinoBoards - * 3. Copy the files "MyNRF5Board.cpp" and "MyNRF5Board.h" from - * "MyNRF5Board" example into your sketch. - * 4. Modify pin mappings in "MyNRF5Board.cpp" and "MyNRF5Board.h" to fit + * 3. Copy the files "MyBoardNRF5.cpp" and "MyBoardNRF5.h" from + * "MyBoardNRF5" example into your sketch. + * 4. Modify pin mappings in "MyBoardNRF5.cpp" and "MyBoardNRF5.h" to fit * your requirements. - * 5. Select "MyNRF5Board nrf52832" or "MyNRF5Board nrf52822" as your board. + * 5. Select "MyBoardNRF5 nrf52832" or "MyBoardNRF5 nrf52822" as your board. * Choose the correct parameters and programmer in the Tools menu. */ diff --git a/libraries/MyBoardNRF5/examples/mass_erase/MyBoardNRF5.cpp b/libraries/MyBoardNRF5/examples/mass_erase/MyBoardNRF5.cpp new file mode 100644 index 0000000..c3cf250 --- /dev/null +++ b/libraries/MyBoardNRF5/examples/mass_erase/MyBoardNRF5.cpp @@ -0,0 +1,107 @@ +/* + If you don't use an nRF5 board, you can ignore this file. + + This file was part of the "My Sensors nRF5 Boards" board repository + available at https://github.com/mysensors/ArduinoBoards If you have + questions, please refer the documentation at + https://github.com/mysensors/ArduinoHwNRF5 first. + + This file is compatible with ArduinoHwNRF5 >= 0.2.0 + + This file allows you to change the relation between pins referenced in + the Arduino IDE (0..31) and pins of the nRF5 MCU (P0.00..P0.31). + + If you can live with addressing the GPIO pins by using the Arduino pins + 0..31 instead of a custom mapping, don't change this file. If you have + a lot of Arduino code with fixed pin numbers and you need to map these + pins to specific pins of the nRF5 MCU; you need to change this file. + + If you fill the "g_APinDescription" Array with numbers between 0..31, + the Arduino pins 0..31 are assigned to pins P0.00..P0.31 of the MCU. + + As an example, if you need to change the pin mapping for Arduino pin 5 + to P0.12 of the MCU, you have to write the 12 after PORT0 into the sixth + position in the "g_APinDescription" Array. + + The extended attributes only affects the nRF5 variants provided with + official Arduino boards. The arduino-nrf5 variant ignores the extended + attributes. + + The pin mapping effects commands like "pinMode()", "digitalWrite()", + "analogRead()" and "analogWrite()". + + If you change the pin mapping, you have to modify the pins in + "MyBoardNRF5.h". Especially the analog pin mapping must be replaced with + your pin numbers by replacing PIN_AIN0..7 with a number of your mapping + array. You can use the constants PIN_AIN0..7 in the "g_APinDescription" + Array if you want to reference analog ports MCU independent. You cannot + use the pins P0.00 and P0.01 for GPIO, when the 32kHz crystal is connected. + + + ########################################################################### + + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Arduino Srl. All right reserved. + Copyright (c) 2017 Sensnology AB. 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 +*/ + + + +#ifdef MYNRF5BOARD +#include + +/* + * Pins descriptions. Attributes are ignored by arduino-nrf5 variant. + * Definition taken from Arduino Primo Core with ordered ports + */ +const PinDescription g_APinDescription[]= +{ + { NOT_A_PORT, 0, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // LFCLK + { NOT_A_PORT, 1, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // LFCLK + { PORT0, 2, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A0, PWM4, NOT_ON_TIMER}, + { PORT0, 3, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A1, PWM5, NOT_ON_TIMER}, + { PORT0, 4, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A2, PWM6, NOT_ON_TIMER}, + { PORT0, 5, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A3, PWM7, NOT_ON_TIMER}, + { PORT0, 6, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT3 + { PORT0, 7, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT4 + { PORT0, 8, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM10, NOT_ON_TIMER}, //USER_LED + { PORT0, 9, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // NFC1 + { PORT0, 10, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // NFC2 + { PORT0, 11, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // TX + { PORT0, 12, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // RX + { PORT0, 13, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // SDA + { PORT0, 14, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // SCL + { PORT0, 15, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // SDA1 + { PORT0, 16, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // SCL1 + { PORT0, 17, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // TP4 + { PORT0, 18, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // TP5 + { PORT0, 19, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT2 + { PORT0, 20, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT1 + { PORT0, 21, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT1 + { PORT0, 22, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM9, NOT_ON_TIMER}, + { PORT0, 23, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM8, NOT_ON_TIMER}, + { PORT0, 24, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT + { PORT0, 25, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER}, //RED_LED + { PORT0, 26, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER}, //GREEN_LED + { PORT0, 27, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER}, //BLUE_LED + { PORT0, 28, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A4, PWM3, NOT_ON_TIMER}, + { PORT0, 29, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A5, PWM2, NOT_ON_TIMER}, + { PORT0, 30, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A6, PWM1, NOT_ON_TIMER}, + { PORT0, 31, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A7, PWM0, NOT_ON_TIMER} +}; + +#endif diff --git a/libraries/MyBoardNRF5/examples/mass_erase/MyBoardNRF5.h b/libraries/MyBoardNRF5/examples/mass_erase/MyBoardNRF5.h new file mode 100644 index 0000000..f78ff9f --- /dev/null +++ b/libraries/MyBoardNRF5/examples/mass_erase/MyBoardNRF5.h @@ -0,0 +1,168 @@ +/* + If you don't use an nRF5 board, you can ignore this file. + + This file was part of the "My Sensors nRF5 Boards" board repository + available at https://github.com/mysensors/ArduinoBoards If you have + questions, please refer the documentation at + https://github.com/mysensors/ArduinoHwNRF5 first. + + This file is compatible with ArduinoHwNRF5 >= 0.2.0 + + This file allows you to change the pins of internal hardware, like the + serial port, SPI bus or Wire bus. + + All pins referenced here are mapped via the "g_ADigitalPinMap" Array + defined in "MyBoardNRF5.cpp" to pins of the MCU. + + As an example, if you have at the third position in "g_ADigitalPinMap" the + 12, then all ports referenced in Arduino with 2 are mapped to P0.12. If you + don't change the "g_ADigitalPinMap" Array, the Arduino pins 0..31 are + translated to P0.00..P0..31. + + ########################################################################### + + This file is compatible with ArduinoHwNRF5 > 0.1.0 + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry. All right reserved. + Copyright (c) 2017 Sensnology AB. 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 +*/ + +#ifndef _MYNRF5BOARD_H_ +#define _MYNRF5BOARD_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif // __cplusplus + +// Number of pins defined in PinDescription array +#define PINS_COUNT (32u) +#define NUM_DIGITAL_PINS (32u) +#define NUM_ANALOG_INPUTS (8u) +#define NUM_ANALOG_OUTPUTS (8u) + +/* + * LEDs + * + * This is optional + * + * With My Sensors, you can use + * hwPinMode() instead of pinMode() + * hwPinMode() allows to use advanced modes like OUTPUT_H0H1 to drive LEDs. + * https://github.com/mysensors/MySensors/blob/development/drivers/NRF5/nrf5_wiring_constants.h + * + */ +#define PIN_LED1 (8) +// #define PIN_LED2 (25) +// #define PIN_LED3 (26) +// #define PIN_LED4 (27) +// #define PIN_LED5 (12) +// #define PIN_LED6 (14) +// #define PIN_LED7 (15) +// #define PIN_LED8 (16) +// #define USER_LED (PIN_LED2) +// #define RED_LED (PIN_LED3) +// #define GREEN_LED (PIN_LED4) +// #define BLUE_LED (PIN_LED1) +// #define BLE_LED BLUE_LED +#define LED_BUILTIN PIN_LED1 + +/* + * Buttons + * + * This is optional + */ +// #define PIN_BUTTON1 (3) +// #define PIN_BUTTON2 (4) +// #define PIN_BUTTON3 (5) +// #define PIN_BUTTON4 (6) +// #define PIN_BUTTON5 (7) +// #define PIN_BUTTON6 (8) +// #define PIN_BUTTON7 (9) +// #define PIN_BUTTON8 (10) + +/* + * Analog ports + * + * If you change g_APinDescription, replace PIN_AIN0 with + * port numbers mapped by the g_APinDescription Array. + * You can add PIN_AIN0 to the g_APinDescription Array if + * you want provide analog ports MCU independed, you can add + * PIN_AIN0..PIN_AIN7 to your custom g_APinDescription Array + * defined in MyBoardNRF5.cpp + */ +static const uint8_t A0 = ADC_A0; +static const uint8_t A1 = ADC_A1; +static const uint8_t A2 = ADC_A2; +static const uint8_t A3 = ADC_A3; +static const uint8_t A4 = ADC_A4; +static const uint8_t A5 = ADC_A5; +static const uint8_t A6 = ADC_A6; +static const uint8_t A7 = ADC_A7; + +/* + * Serial interfaces + * + * RX and TX are required. + * If you have no serial port, use unused pins + * CTS and RTS are optional. + */ +#define PIN_SERIAL_RX (12) +#define PIN_SERIAL_TX (11) +// #define PIN_SERIAL_CTS (13) +// #define PIN_SERIAL_RTS (14) + +/* + * SPI Interfaces + * + * This is optional + * + * If SPI is defined MISO, MOSI, SCK are required + * SS is optional and can be used in your sketch. + */ +#define SPI_INTERFACES_COUNT 1 + +#define PIN_SPI_MISO (2) +#define PIN_SPI_MOSI (3) +#define PIN_SPI_SCK (4) +#define PIN_SPI_SS (5) + +static const uint8_t SS = PIN_SPI_SS; +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; + +/* + * Wire Interfaces + * + * This is optional + */ +#define WIRE_INTERFACES_COUNT 2 + +#define PIN_WIRE_SDA (13u) +#define PIN_WIRE_SCL (14u) + +#define PIN_WIRE_SDA1 (15u) +#define PIN_WIRE_SCL1 (16u) + +static const uint8_t SDA = PIN_WIRE_SDA; +static const uint8_t SCL = PIN_WIRE_SCL; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/libraries/MyBoardNRF5/examples/mass_erase/mass_erase.ino b/libraries/MyBoardNRF5/examples/mass_erase/mass_erase.ino new file mode 100644 index 0000000..6134029 --- /dev/null +++ b/libraries/MyBoardNRF5/examples/mass_erase/mass_erase.ino @@ -0,0 +1,15 @@ +/* + * This Sketch removes any contents of the nRF5 MCU. + * If you don't have an programming adapter, the board can be become useless! + */ +#include +void setup() { + // Enable erasing flash + NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos; + while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { + }; + // Erase Flash and UICR + NRF_NVMC->ERASEALL = 1; +} +void loop () { +} diff --git a/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.cpp b/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.cpp deleted file mode 100644 index 4be2b7c..0000000 --- a/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - If you don't use an nRF5 board, you can ignore this file. - - This file was part of the "My Sensors nRF5 Boards" board repository - available at https://github.com/mysensors/ArduinoBoards If you have - questions, please refer the documentation at - https://github.com/mysensors/ArduinoHwNRF5 first. - - This file is compatible with ArduinoHwNRF5 > 0.1.0 - - This file allows you to change the relation between pins referenced in - the Arduino IDE (0..31) and pins of the nRF5 MCU (P0.00..P0.31). - - If you can live with addressing the GPIO pins by using the Arduino pins - 0..31 instead of a custom mapping, don't change this file. If you have - a lot of Arduino code with fixed pin numbers and you need to map these - pins to specific pins of the nRF5 MCU; you need to change this file. - - If you fill the "g_ADigitalPinMap" Array with numbers between 0..31, - the Arduino pins 0..31 are assigned to pins P0.00..P0.31 of the MCU. - - As an example, if you need to change the pin mapping for Arduino pin 5 - to P0.12 of the MCU, you have to write the 12 into the sixth position - in the "g_ADigitalPinMap" Array. - - The pin mapping effects commands like "pinMode()", "digitalWrite()", - "analogRead()" and "analogWrite()". - - If you change the pin mapping, you have to modify the pins in - "MyNRF5Board.h". Especially the analog pin mapping must be replaced with - your pin numbers by replacing PIN_AIN0..7 with a number of your mapping - array. You can use the constants PIN_AIN0..7 in the "g_ADigitalPinMap" - Array if you want to reference analog ports MCU independent. You cannot - use the pins P0.00 and P0.01 for GPIO, when the 32kHz crystal is connected. - - - ########################################################################### - - Copyright (c) 2014-2015 Arduino LLC. All right reserved. - Copyright (c) 2016 Sandeep Mistry. All right reserved. - Copyright (c) 2017 Sensnology AB. 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 -*/ - - - -#ifdef MYNRF5BOARD -#include - -const uint32_t g_ADigitalPinMap[] = { - 0, - 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 -}; -#endif diff --git a/variants/MyBoardNRF5/WVariant_arduino.h b/variants/MyBoardNRF5/WVariant_arduino.h new file mode 100644 index 0000000..7b3307d --- /dev/null +++ b/variants/MyBoardNRF5/WVariant_arduino.h @@ -0,0 +1,149 @@ +// Modification of arduino/hardware/nrf52/cores/arduino/WVariant.h to support arduino-nrf5 variant. + +#ifndef _VARIANTS_ARDUINO_ +#define _VARIANTS_ARDUINO_ + +#include +#include + +#ifdef __cplusplus +extern "C"{ +#endif // __cplusplus + +//number of channel: 8 +typedef enum _EAnalogChannel +{ + No_ADC_Channel=-1, +#ifdef NRF51 + ADC_A0=ADC_CONFIG_PSEL_AnalogInput0, + ADC_A1=ADC_CONFIG_PSEL_AnalogInput1, + ADC_A2=ADC_CONFIG_PSEL_AnalogInput2, + ADC_A3=ADC_CONFIG_PSEL_AnalogInput3, + ADC_A4=ADC_CONFIG_PSEL_AnalogInput4, + ADC_A5=ADC_CONFIG_PSEL_AnalogInput5, + ADC_A6=ADC_CONFIG_PSEL_AnalogInput6, + ADC_A7=ADC_CONFIG_PSEL_AnalogInput7 +#else + ADC_A0=SAADC_CH_PSELP_PSELP_AnalogInput0, + ADC_A1=SAADC_CH_PSELP_PSELP_AnalogInput1, + ADC_A2=SAADC_CH_PSELP_PSELP_AnalogInput2, + ADC_A3=SAADC_CH_PSELP_PSELP_AnalogInput3, + ADC_A4=SAADC_CH_PSELP_PSELP_AnalogInput4, + ADC_A5=SAADC_CH_PSELP_PSELP_AnalogInput5, + ADC_A6=SAADC_CH_PSELP_PSELP_AnalogInput6, + ADC_A7=SAADC_CH_PSELP_PSELP_AnalogInput7 +#endif +} EAnalogChannel ; + +typedef enum _ETCChannel +{ + NOT_ON_TIMER=-1, +} ETCChannel ; + +// Definitions for PWM channels +// MSB = PWM module (0 - NRF_PWM0, 1 - NRF_PWM1, 2 - NRF_PWM2) +// LSB = PWM channel (0 to 3) +// ex: 0x10 = PWM1 channel 0 +typedef enum _EPWMChannel +{ + NOT_ON_PWM=-1, + PWM0=0x00, + PWM1=0x01, + PWM2=0x02, + PWM3=0x03, + PWM4=0x10, + PWM5=0x11, + PWM6=0x12, + PWM7=0x13, + PWM8=0x20, + PWM9=0x21, + PWM10=0x22, + PWM11=0x23 +} EPWMChannel ; + + +typedef enum _EPortType +{ + NOT_A_PORT=-1, + PORT0=0 +} EPortType ; + + +typedef enum _EPioType +{ + PIO_NOT_A_PIN=-1, /* Not under control of a peripheral. */ + PIO_ANALOG, /* The pin is controlled by the associated signal of peripheral B. */ + PIO_DIGITAL, /* The pin is controlled by PORT. */ + PIO_INPUT, /* The pin is controlled by PORT and is an input. */ + PIO_INPUT_PULLUP, /* The pin is controlled by PORT and is an input with internal pull-up resistor enabled. */ + PIO_OUTPUT, /* The pin is controlled by PORT and is an output. */ + + } EPioType ; + +/** + * Pin Attributes to be OR-ed + */ +#define PIN_ATTR_NONE (0UL<<0) +#define PIN_ATTR_COMBO (1UL<<0) +#define PIN_ATTR_ANALOG (1UL<<1) +#define PIN_ATTR_DIGITAL (1UL<<2) +#define PIN_ATTR_PWM (1UL<<3) +#define PIN_ATTR_TIMER (1UL<<4) +#define PIN_ATTR_EXTINT (1UL<<5) + +/* Types used for the table below */ +typedef struct _PinDescription +{ + EPortType ulPort ; + uint32_t ulPin ; + EPioType ulPinType ; + uint32_t ulPinAttribute ; + EAnalogChannel ulADCChannelNumber ; + EPWMChannel ulPWMChannel ; + ETCChannel ulTCChannel ; +// EExt_Interrupts ulExtInt ; +} PinDescription ; + +/* Pins table to be instantiated into variant.cpp */ +extern const PinDescription g_APinDescription[] ; + +// reference voltages for LPCOMP +#ifdef NRF51 +#define REF_VDD_1_8 LPCOMP_REFSEL_REFSEL_SupplyOneEighthPrescaling +#define REF_VDD_1_4 LPCOMP_REFSEL_REFSEL_SupplyTwoEighthsPrescaling +#define REF_VDD_3_8 LPCOMP_REFSEL_REFSEL_SupplyThreeEighthsPrescaling +#define REF_VDD_1_2 LPCOMP_REFSEL_REFSEL_SupplyFourEighthsPrescaling +#define REF_VDD_5_8 LPCOMP_REFSEL_REFSEL_SupplyFiveEighthsPrescaling +#define REF_VDD_3_4 LPCOMP_REFSEL_REFSEL_SupplySixEighthsPrescaling +#define REF_VDD_7_8 LPCOMP_REFSEL_REFSEL_SupplySevenEighthsPrescaling +#else +#define REF_VDD_1_8 LPCOMP_REFSEL_REFSEL_Ref1_8Vdd +#define REF_VDD_1_4 LPCOMP_REFSEL_REFSEL_Ref2_8Vdd +#define REF_VDD_3_8 LPCOMP_REFSEL_REFSEL_Ref3_8Vdd +#define REF_VDD_1_2 LPCOMP_REFSEL_REFSEL_Ref4_8Vdd +#define REF_VDD_5_8 LPCOMP_REFSEL_REFSEL_Ref5_8Vdd +#define REF_VDD_3_4 LPCOMP_REFSEL_REFSEL_Ref6_8Vdd +#define REF_VDD_7_8 LPCOMP_REFSEL_REFSEL_Ref7_8Vdd +#define REF_VDD_1_16 LPCOMP_REFSEL_REFSEL_Ref1_16Vdd +#define REF_VDD_3_16 LPCOMP_REFSEL_REFSEL_Ref1_16Vdd +#define REF_VDD_5_16 LPCOMP_REFSEL_REFSEL_Ref1_16Vdd +#define REF_VDD_7_16 LPCOMP_REFSEL_REFSEL_Ref1_16Vdd +#define REF_VDD_9_16 LPCOMP_REFSEL_REFSEL_Ref1_16Vdd +#define REF_VDD_11_16 LPCOMP_REFSEL_REFSEL_Ref1_16Vdd +#define REF_VDD_13_16 LPCOMP_REFSEL_REFSEL_Ref1_16Vdd +#define REF_VDD_15_16 LPCOMP_REFSEL_REFSEL_Ref1_16Vdd +#endif +#define AREF LPCOMP_REFSEL_REFSEL_ARef | (LPCOMP_EXTREFSEL_EXTREFSEL_AnalogReference0 << 16) + +typedef enum{ + UP = LPCOMP_ANADETECT_ANADETECT_Up, + DOWN = LPCOMP_ANADETECT_ANADETECT_Down, + CROSS = LPCOMP_ANADETECT_ANADETECT_Cross +}detect_mode; + + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + +#endif // _VARIANTS_ARDUINO_ diff --git a/variants/MyNRF5Board/pins_arduino.h b/variants/MyBoardNRF5/pins_arduino.h similarity index 100% rename from variants/MyNRF5Board/pins_arduino.h rename to variants/MyBoardNRF5/pins_arduino.h diff --git a/variants/MyBoardNRF5/variant.cpp b/variants/MyBoardNRF5/variant.cpp new file mode 100644 index 0000000..ba4601a --- /dev/null +++ b/variants/MyBoardNRF5/variant.cpp @@ -0,0 +1,125 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry 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 +*/ + +#include "variant.h" + +#ifndef MY_ARDUINO_CORE_NRF5 +const uint32_t g_ADigitalPinMap[] = { +#if PINS_COUNT>(0u) + g_APinDescription[0].ulPin +#endif +#if PINS_COUNT>(1u) + ,g_APinDescription[1].ulPin +#endif +#if PINS_COUNT>(2u) + ,g_APinDescription[2].ulPin +#endif +#if PINS_COUNT>(3u) + ,g_APinDescription[3].ulPin +#endif +#if PINS_COUNT>(4u) + ,g_APinDescription[4].ulPin +#endif +#if PINS_COUNT>(5u) + ,g_APinDescription[5].ulPin +#endif +#if PINS_COUNT>(6u) + ,g_APinDescription[6].ulPin +#endif +#if PINS_COUNT>(7u) + ,g_APinDescription[7].ulPin +#endif +#if PINS_COUNT>(8u) + ,g_APinDescription[8].ulPin +#endif +#if PINS_COUNT>(9u) + ,g_APinDescription[9].ulPin +#endif +#if PINS_COUNT>(10u) + ,g_APinDescription[10].ulPin +#endif +#if PINS_COUNT>(11u) + ,g_APinDescription[11].ulPin +#endif +#if PINS_COUNT>(12u) + ,g_APinDescription[12].ulPin +#endif +#if PINS_COUNT>(13u) + ,g_APinDescription[13].ulPin +#endif +#if PINS_COUNT>(14u) + ,g_APinDescription[14].ulPin +#endif +#if PINS_COUNT>(15u) + ,g_APinDescription[15].ulPin +#endif +#if PINS_COUNT>(16u) + ,g_APinDescription[16].ulPin +#endif +#if PINS_COUNT>(17u) + ,g_APinDescription[17].ulPin +#endif +#if PINS_COUNT>(18u) + ,g_APinDescription[18].ulPin +#endif +#if PINS_COUNT>(19u) + ,g_APinDescription[19].ulPin +#endif +#if PINS_COUNT>(20u) + ,g_APinDescription[20].ulPin +#endif +#if PINS_COUNT>(21u) + ,g_APinDescription[21].ulPin +#endif +#if PINS_COUNT>(22u) + ,g_APinDescription[22].ulPin +#endif +#if PINS_COUNT>(23u) + ,g_APinDescription[23].ulPin +#endif +#if PINS_COUNT>(24u) + ,g_APinDescription[24].ulPin +#endif +#if PINS_COUNT>(25u) + ,g_APinDescription[25].ulPin +#endif +#if PINS_COUNT>(26u) + ,g_APinDescription[26].ulPin +#endif +#if PINS_COUNT>(27u) + ,g_APinDescription[27].ulPin +#endif +#if PINS_COUNT>(28u) + ,g_APinDescription[28].ulPin +#endif +#if PINS_COUNT>(29u) + ,g_APinDescription[29].ulPin +#endif +#if PINS_COUNT>(30u) + ,g_APinDescription[30].ulPin +#endif +#if PINS_COUNT>(31u) + ,g_APinDescription[31].ulPin +#endif +}; +#endif + +#if defined(MY_ARDUINO_CORE_NRF5) && defined(PIN_SERIAL_RX) && defined(PIN_SERIAL_TX) +Uart Serial(PIN_SERIAL_RX, PIN_SERIAL_TX); +#endif diff --git a/variants/MyBoardNRF5/variant.h b/variants/MyBoardNRF5/variant.h new file mode 100644 index 0000000..67fc2d4 --- /dev/null +++ b/variants/MyBoardNRF5/variant.h @@ -0,0 +1,130 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2016 Arduino Srl. 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 +*/ + +#ifndef _VARIANT_MYNRF5BOARD_ +#define _VARIANT_MYNRF5BOARD_ + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef MY_ARDUINO_CORE_NRF5 +#ifdef __cplusplus + #include "Uart.h" +#endif // __cplusplus +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif // __cplusplus + + +#ifdef MY_ARDUINO_CORE_NRF5 +/** + * Libc porting layers + */ +#if defined ( __GNUC__ ) +# include /** RedHat Newlib minimal stub */ +#endif +#endif + +/*---------------------------------------------------------------------------- + * Definitions + *----------------------------------------------------------------------------*/ + +/** Master clock frequency */ +#ifdef NRF52 +#define VARIANT_MCK (64000000ul) +#else +#define VARIANT_MCK (16000000ul) +#endif + +/** Frequency of the board main oscillator */ +#define VARIANT_MAINOSC (32768ul) + +#ifndef PIN_ATTR_NONE +#include "WVariant_arduino.h" +#endif + +/*---------------------------------------------------------------------------- + * Pins + *----------------------------------------------------------------------------*/ +#ifdef MY_ARDUINO_CORE_NRF5 +#define digitalPinToPort(P) ( NRF_P0 ) +#define digitalPinToBitMask(P) ( 1 << g_APinDescription[P].ulPin ) +#define digitalPinToTimer(P) ( ) +#define portOutputRegister(port) ( &(port->OUT) ) +#define portInputRegister(port) ( &(port->IN) ) +#define portModeRegister(port) ( &(port->DIR) ) +#define analogInPinToBit(P) ( g_APinDescription[P].ulPin ) +#define digitalPinHasPWM(P) ( g_APinDescription[P].ulPWMChannel != NOT_ON_PWM ) +#define digitalPinToInterrupt(P) ( P ) +#endif + +/* + * Analog pins + */ +#ifdef NRF51 +#define PIN_A0 (26) +#define PIN_A1 (27) +#define PIN_A2 (1) +#define PIN_A3 (2) +#define PIN_A4 (3) +#define PIN_A5 (4) +#define PIN_A6 (5) +#define PIN_A7 (6) +#else +#define PIN_A0 (2) +#define PIN_A1 (3) +#define PIN_A2 (4) +#define PIN_A3 (5) +#define PIN_A4 (28) +#define PIN_A5 (29) +#define PIN_A6 (30) +#define PIN_A7 (31) +#endif + +#ifdef NRF52 +#define PIN_RESOLUTION 14 +#else +#define PIN_RESOLUTION 10 +#endif + +#ifdef __cplusplus +} +#endif // __cplusplus + +#include + +#ifdef MY_ARDUINO_CORE_NRF5 +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ +#ifdef __cplusplus + +extern Uart Serial; + +#endif + +#define SERIAL_PORT_MONITOR Serial +#endif + +#endif diff --git a/variants/MyNRF5Board/variant.cpp b/variants/MyNRF5Board/variant.cpp deleted file mode 100644 index 8801769..0000000 --- a/variants/MyNRF5Board/variant.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - Copyright (c) 2014-2015 Arduino LLC. All right reserved. - Copyright (c) 2016 Sandeep Mistry 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 -*/ - -#include "variant.h" diff --git a/variants/MyNRF5Board/variant.h b/variants/MyNRF5Board/variant.h deleted file mode 100644 index 57c703a..0000000 --- a/variants/MyNRF5Board/variant.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - Copyright (c) 2014-2015 Arduino LLC. All right reserved. - Copyright (c) 2016 Sandeep Mistry 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 -*/ - -#ifndef _VARIANT_MYNRF5BOARD_ -#define _VARIANT_MYNRF5BOARD_ - -/*---------------------------------------------------------------------------- - * Headers - *----------------------------------------------------------------------------*/ - -#include "WVariant.h" - -#ifdef __cplusplus -extern "C" -{ -#endif // __cplusplus - -/** Master clock frequency */ -#ifdef NRF52 -#define VARIANT_MCK (64000000ul) -#else -#define VARIANT_MCK (16000000ul) -#endif - -/* - * Analog pins - */ -#ifdef NRF51 -#define PIN_AIN0 (26) -#define PIN_AIN1 (27) -#define PIN_AIN2 (1) -#define PIN_AIN3 (2) -#define PIN_AIN4 (3) -#define PIN_AIN5 (4) -#define PIN_AIN6 (5) -#define PIN_AIN7 (6) -#else -#define PIN_AIN0 (2) -#define PIN_AIN1 (3) -#define PIN_AIN2 (4) -#define PIN_AIN3 (5) -#define PIN_AIN4 (28) -#define PIN_AIN5 (29) -#define PIN_AIN6 (30) -#define PIN_AIN7 (31) -#endif - -#ifdef NRF52 -#define ADC_RESOLUTION 14 -#else -#define ADC_RESOLUTION 10 -#endif - -#ifdef __cplusplus -} -#endif // __cplusplus - -#include -#endif