MySensors Library & Examples  2.3.2
Radio.h
1 /*
2  * The MySensors Arduino library handles the wireless radio link and protocol
3  * between your home built sensors/actuators and HA controller of choice.
4  * The sensors forms a self healing radio network with optional repeaters. Each
5  * repeater and gateway builds a routing tables in EEPROM which keeps track of
6  * the
7  * network topology allowing messages to be routed to nodes.
8  *
9  * Created by Frank Holtz
10  * Copyright (C) 2017 Frank Holtz
11  * Full contributor list:
12  * https://github.com/mysensors/MySensors/graphs/contributors
13  *
14  * Documentation: http://www.mysensors.org
15  * Support Forum: http://forum.mysensors.org
16  *
17  * This program is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU General Public License
19  * version 2 as published by the Free Software Foundation.
20  */
21 
22 #ifndef __NRF_RADIO_H__
23 #define __NRF_RADIO_H__
24 
25 #if !defined(ARDUINO_ARCH_NRF5)
26 #error "NRF5 Radio is not supported for this platform."
27 #endif
28 
29 #include <nrf.h>
30 #include <stdint.h>
31 #include <stdio.h>
32 #include <string.h>
33 
34 // Timer to use
35 #define NRF5_RADIO_TIMER NRF_TIMER0
36 #define NRF5_RADIO_TIMER_IRQ_HANDLER TIMER0_IRQHandler
37 #define NRF5_RADIO_TIMER_IRQN TIMER0_IRQn
38 
39 // debug
40 #if defined(MY_DEBUG_VERBOSE_NRF5_ESB)
41 #define NRF5_RADIO_DEBUG(x, ...) DEBUG_OUTPUT(x, ##__VA_ARGS__)
42 #else
43 #define NRF5_RADIO_DEBUG(x, ...)
44 #endif
45 
46 // tx power
47 typedef enum {
48 #ifdef NRF51
49  NRF5_PA_MIN = RADIO_TXPOWER_TXPOWER_Neg30dBm, // Deprecated
50 #else
51  NRF5_PA_MIN = RADIO_TXPOWER_TXPOWER_Neg40dBm,
52 #endif
53  NRF5_PA_LOW = RADIO_TXPOWER_TXPOWER_Neg16dBm,
54  NRF5_PA_HIGH = RADIO_TXPOWER_TXPOWER_0dBm,
55 #ifdef RADIO_TXPOWER_TXPOWER_Pos9dBm
56  // nRF52840
57  NRF5_PA_MAX = RADIO_TXPOWER_TXPOWER_Pos9dBm,
58 #else
59  // nRF51x22/nRF52822
60  NRF5_PA_MAX = RADIO_TXPOWER_TXPOWER_Pos4dBm,
61 #endif
62 } nrf5_txpower_e;
63 
64 // Radio mode (Data rate)
65 typedef enum {
66  NRF5_1MBPS = RADIO_MODE_MODE_Nrf_1Mbit,
67  NRF5_2MBPS = RADIO_MODE_MODE_Nrf_2Mbit,
68  NRF5_250KBPS = RADIO_MODE_MODE_Nrf_250Kbit, // Deprecated!!!
69  NRF5_BLE_1MBPS = RADIO_MODE_MODE_Ble_1Mbit,
70 } nrf5_mode_e;
71 
72 int16_t NRF5_getTxPowerPercent(void);
73 int16_t NRF5_getTxPowerLevel(void);
74 bool NRF5_setTxPowerPercent(const uint8_t powerPercent);
75 
76 
77 #endif // __NRF_RADIO_H__