Files
MySensors/drivers/NRF5/Radio.h
T
d00616 726a20dad9 Add nrf5 platform (#830)
* Add NVRAM support

This is an EEPROM replacement based on MCU's internal Flash memory.
The NVRAM class is designed to be stateless. Each operation is
written to flash immediately.

The last 16k(nRF51)/32k(nRF52) of Flash memory are managed by the
VirtualPage class.  This class allows writing a single emulated 4k
page up 40,000 times.

The NVRAM class is a log based byte-wise storage allowing up to
40,000,000 writes depending on the number of used addresses.  Each
four allocated addresses from the beginning of the NVRAM reduce the
write log by one.

When first 256 bytes of the emulated storage are used, there is an
average writing capacity of 145,000 cycles per byte.

When the write log is full, the NVRAM is compressed into a new flash
page. After a new page is ready, the old page is released. This
process can take up to 4500 ms and cannot be interrupted.

The NVRAM functionality can easily be ported to ESP8266 or SAMD by
providing a Flash interface.

* Add NRF5 platform support

This is the support of the Nordic Semiconductor NRF51 (nrf51822,
nrf51422) and NRF52 (nrf52832) platform. Based on arduino-nRF5
(https://github.com/sandeepmistry/arduino-nRF5).

The included radio driver is compatible with the NRF24 devices.
Using a SoftDevice (BLE)is not supported and must be removed before
flashing MySensors with a "mass_erase" operation.
2017-05-14 11:53:01 +02:00

83 lines
2.2 KiB
C

/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of
* the
* network topology allowing messages to be routed to nodes.
*
* Created by Frank Holtz
* Copyright (C) 2017 Frank Holtz
* Full contributor list:
* https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*/
#ifndef __NRF_RADIO_H__
#define __NRF_RADIO_H__
#if !defined(ARDUINO)
#error "NRF5 Radio is not supported for this platform."
#endif
#if defined(NRF5_SOFTDEVICE)
#warning "NRF5 SoftDevice cannot be used with NRF5 Radio."
#endif
#include <nrf.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
// Timer to use
#define NRF5_RADIO_TIMER NRF_TIMER2
#define NRF5_RADIO_TIMER_IRQ_HANDLER TIMER2_IRQHandler
#define NRF5_RADIO_TIMER_IRQN TIMER2_IRQn
// debug
#if defined(MY_DEBUG_VERBOSE_NRF5_ESB)
#define NRF5_RADIO_DEBUG(x, ...) debug(x, ##__VA_ARGS__)
#else
#define NRF5_RADIO_DEBUG(x, ...)
#endif
// tx power
typedef enum {
#ifdef NRF51
NRF5_PA_MIN = RADIO_TXPOWER_TXPOWER_Neg30dBm, // Deprecated
#else
NRF5_PA_MIN = RADIO_TXPOWER_TXPOWER_Neg40dBm,
#endif
NRF5_PA_LOW = RADIO_TXPOWER_TXPOWER_Neg16dBm,
NRF5_PA_HIGH = RADIO_TXPOWER_TXPOWER_0dBm,
#ifdef RADIO_TXPOWER_TXPOWER_Pos9dBm
// nRF52840
NRF5_PA_MAX = RADIO_TXPOWER_TXPOWER_Pos9dBm,
#else
// nRF51x22/nRF52822
NRF5_PA_MAX = RADIO_TXPOWER_TXPOWER_Pos4dBm,
#endif
} nrf5_txpower_e;
// Radio mode (Data rate)
typedef enum {
NRF5_1MBPS = RADIO_MODE_MODE_Nrf_1Mbit,
NRF5_2MBPS = RADIO_MODE_MODE_Nrf_2Mbit,
NRF5_250KBPS = RADIO_MODE_MODE_Nrf_250Kbit, // Deprecated!!!
NRF5_BLE_1MBPS = RADIO_MODE_MODE_Ble_1Mbit,
} nrf5_mode_e;
int16_t NRF5_getTxPowerPercent(void);
int16_t NRF5_getTxPowerLevel(void);
bool NRF5_setTxPowerPercent(const uint8_t powerPercent);
#endif // __NRF_RADIO_H__