Commit ecaf4f85 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Update to latest NodeManager code

parent 58e8625f
/*
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 MYBOARDNRF5
#include <variant.h>
/*
* 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}
};
// Don't remove this line
#include <compat_pin_mapping.h>
#endif
/*
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 _MYBOARDNRF5_H_
#define _MYBOARDNRF5_H_
/* BOARD LAYOUT of the MultiSensor V9 board by NeverDie:
* P0.01 ... LED => LED_BUILTIN
* P0.02 ... Water sensor (1M pullup to VIN, 3 contact sensors in parallel, signal is PULL LOW)
* P0.03 ... INT pin of 5-pin header
* P0.04 ... SDA
* P0.09 ... OUT Signal of Hall sensor
* P0.10 ... SCL
* P0.13 ... Debug TX UART pin (no corresponding RX pin!)
* SWDIO ... SWD data lines
* SWDCLK .. SWD data lines
*/
#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 (1)
// #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 (8)
#define PIN_SERIAL_TX (13)
// #define PIN_SERIAL_CTS (4)
// #define PIN_SERIAL_RTS (5)
/*
* 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 (22)
#define PIN_SPI_MOSI (23)
#define PIN_SPI_SCK (24)
#define PIN_SPI_SS (21)
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 (4u)
#define PIN_WIRE_SCL (10u)
#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
......@@ -35,7 +35,8 @@ NodeManager provides built-in implementation of a number of sensors through ad-h
#define MY_NODE_ID 53
//#define USE_DISPLAY
#define USE_BATTERY
#define USE_SIGNAL
#define MY_RADIO_NRF5_ESB
......@@ -47,19 +48,25 @@ NodeManager provides built-in implementation of a number of sensors through ad-h
//#define MY_DEBUG_VERBOSE_RF24
// Advanced settings
//#define My_BAUD_RATE 115200
#define My_BAUD_RATE 57600
#define MY_SMART_SLEEP_WAIT_DURATION_MS 500
#define MY_SPLASH_SCREEN_DISABLED
//#define MY_DISABLE_RAM_ROUTING_TABLE_FEATURE
//#define MY_SIGNAL_REPORT_ENABLED
// Optimizations when running on 2032 Coin Cell. Also set nodeManager.setSleepBetweenSend(500) and run the board at 1Mhz
#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
// Settings to avoid killing coin cell in case of connection problem
#define MY_TRANSPORT_WAIT_READY_MS 10000
#define MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS 5000
#define MY_PARENT_NODE_ID 0
#define MY_PARENT_NODE_IS_STATIC
// Optimizations when running on 2032 Coin Cell. Also set nodeManager.setSleepBetweenSend(500) and run the board at 1Mhz
//#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
//#define MY_TRANSPORT_WAIT_READY_MS 10000
//#define MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS 5000
//#define MY_PARENT_NODE_ID 0
//#define MY_PARENT_NODE_IS_STATIC
//#include <Wire.h>
//#include <MySensors.h>
/***********************************
* NodeManager configuration
......@@ -68,8 +75,8 @@ NodeManager provides built-in implementation of a number of sensors through ad-h
#define NODEMANAGER_DEBUG ON
#define NODEMANAGER_INTERRUPTS ON
#define NODEMANAGER_SLEEP ON
#define NODEMANAGER_RECEIVE ON
#define NODEMANAGER_DEBUG_VERBOSE OFF
#define NODEMANAGER_RECEIVE OFF
#define NODEMANAGER_DEBUG_VERBOSE ON
#define NODEMANAGER_POWER_MANAGER OFF
#define NODEMANAGER_CONDITIONAL_REPORT OFF
#define NODEMANAGER_EEPROM OFF
......@@ -87,22 +94,21 @@ NodeManager provides built-in implementation of a number of sensors through ad-h
* Add your sensors
*/
//PowerManager power(5,6);
#include <sensors/SensorBattery.h>
SensorBattery battery;
#include <sensors/SensorConfiguration.h>
SensorConfiguration configuration;
#ifdef USE_BATTERY
#include <sensors/SensorBattery.h>
SensorBattery battery;
#endif
#include <sensors/SensorSignal.h>
SensorSignal signal;
#ifdef USE_SIGNAL
#include <sensors/SensorSignal.h>
SensorSignal signal;
#endif
#define XSHUT_PIN (03u)
//#include <sensors/SensorVL53L0X.h>
//SensorVL53L0X vl53l0x(XSHUT_PIN);
#include "SensorVL53L0X_WaterLevel.h"
SensorVL53L0X_WaterLevel vl53l0x(XSHUT_PIN, 200, 60);
#include <sensors/SensorVL53L0X.h>
SensorVL53L0X vl53l0x(XSHUT_PIN);
//#include "SensorVL53L0X_WaterLevel.h"
//SensorVL53L0X_WaterLevel vl53l0x(XSHUT_PIN, 200, 60);
#ifdef USE_DISPLAY
#include <sensors/DisplaySSD1306.h>
......@@ -112,8 +118,6 @@ SensorVL53L0X_WaterLevel vl53l0x(XSHUT_PIN, 200, 60);
#endif
void blinkLED(uint16_t len = 50, uint16_t pause = 50, uint8_t pin = LED_BUILTIN) {
digitalWrite(pin, HIGH);
delay(len);
......@@ -137,7 +141,6 @@ void blinkityBlink(uint8_t repetitions) {
// before
void before() {
nodeManager.setSleepBetweenSend(500);
// sleep 20 sec, report 20 sec
......@@ -146,12 +149,13 @@ void before() {
blinkityBlink(1);
blinkityBlink(1);
blinkityBlink(1);
// setup the serial port baud rate
#ifdef CHIP_NRF5
// Reassign Serial Pins as given in the board definition
Serial.setPins(PIN_SERIAL_RX, PIN_SERIAL_TX);
// MY_SERIALDEVICE.setPins(PIN_SERIAL_RX, 13);
#endif
Serial.begin(MY_BAUD_RATE);
// setup the serial port baud rate
// MY_SERIALDEVICE.begin(MY_BAUD_RATE);
/*
* Configure your sensors
......@@ -163,10 +167,6 @@ void before() {
#ifdef USE_SIGNAL
signal.setReportIntervalSeconds(reportSecs);
#endif
#ifdef USE_CONFIGURATION
configuration.setReportIntervalSeconds(reportSecs);
// configuration.children.get(1)->setDescription("Configuration");
#endif
#ifdef USE_BATTERY
battery.setReportIntervalSeconds(reportSecs);
......@@ -195,23 +195,25 @@ void presentation() {
// setup
void setup() {
hwPinMode(LED_BUILTIN,OUTPUT_D0H1);
blinkityBlink(3); //signify power-up and start of operations
NRF_CLOCK->INTENSET = B11; // enable interrupts for EVENTS_HFCLKSTARTED and EVENTS_LFCLKSTARTED
NRF_CLOCK->TASKS_HFCLKSTART = 1; //start the high frequency crystal oscillator clock
while (!(NRF_CLOCK->EVENTS_HFCLKSTARTED)) {} //wait until high frequency crystal oscillator clock is up to speed and working
// NRF_CLOCK->INTENSET = B11; // enable interrupts for EVENTS_HFCLKSTARTED and EVENTS_LFCLKSTARTED
// NRF_CLOCK->TASKS_HFCLKSTART = 1; //start the high frequency crystal oscillator clock
// while (!(NRF_CLOCK->EVENTS_HFCLKSTARTED)) {} //wait until high frequency crystal oscillator clock is up to speed and working
#ifdef CHIP_NRF5
// Setup I2C pins (custom pins given in the board definition!)
Wire.setPins(SDA, SCL);
// Wire.setPins(SDA, SCL);
// Wire.begin();
#endif
// call NodeManager setup routine
nodeManager.setup();
#ifdef USE_DISPLAY
// ssd1306.rotateDisplay(true);
ssd1306.rotateDisplay(true);
#endif
}
......@@ -220,17 +222,9 @@ void setup() {
void loop() {
blinkityBlink(1);
Wire.begin();
NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
// call NodeManager loop routine
nodeManager.loop();
Wire.end();
NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
}
#if NODEMANAGER_RECEIVE == ON
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment