2020-01-01 18:09:20 +00:00
|
|
|
/*
|
2020-01-02 15:58:20 +00:00
|
|
|
xdrv_33_nrf24l01.ino - nrf24l01 support for Tasmota
|
|
|
|
|
|
|
|
Copyright (C) 2020 Christian Baars and Theo Arends
|
|
|
|
|
2020-01-01 18:09:20 +00:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2020-01-02 15:58:20 +00:00
|
|
|
|
2020-01-01 18:09:20 +00:00
|
|
|
This program 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 General Public License for more details.
|
2020-01-02 15:58:20 +00:00
|
|
|
|
2020-01-01 18:09:20 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------------------
|
|
|
|
Version yyyymmdd Action Description
|
|
|
|
--------------------------------------------------------------------------------------------
|
|
|
|
|
2020-06-24 15:20:07 +01:00
|
|
|
0.9.0.1 20200624 changes - removed unused legacy code
|
2020-01-01 18:09:20 +00:00
|
|
|
---
|
|
|
|
0.9.0.0 20191127 started - further development by Christian Baars
|
|
|
|
forked - from arendst/tasmota - https://github.com/arendst/Tasmota
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef USE_SPI
|
|
|
|
#ifdef USE_NRF24
|
|
|
|
|
|
|
|
/*********************************************************************************************\
|
|
|
|
* NRF24l01(+)
|
|
|
|
*
|
2020-12-31 15:17:30 +00:00
|
|
|
* Usage: 5 SPI-data-wires plus VVC/ground, use hardware SPI, select GPIO_NRF24_CS/GPIO_NRF24_DC
|
2020-01-01 18:09:20 +00:00
|
|
|
\*********************************************************************************************/
|
|
|
|
|
|
|
|
#define XDRV_33 33
|
|
|
|
|
|
|
|
#include <RF24.h>
|
|
|
|
|
|
|
|
const char NRF24type[] PROGMEM = "NRF24";
|
|
|
|
|
|
|
|
struct {
|
|
|
|
uint8_t chipType = 0; // NRF24l01 active: 32 - NRF24L01 , 43- NRF24L01+ ... we mis-use ascii-codes
|
|
|
|
} NRF24;
|
|
|
|
|
|
|
|
/********************************************************************************************/
|
|
|
|
|
|
|
|
RF24 NRF24radio;
|
|
|
|
|
2020-12-31 15:17:30 +00:00
|
|
|
bool NRF24initRadio() {
|
|
|
|
NRF24radio.begin(Pin(GPIO_NRF24_CS), Pin(GPIO_NRF24_DC));
|
2020-01-01 18:09:20 +00:00
|
|
|
NRF24radio.powerUp();
|
|
|
|
|
2020-12-31 15:17:30 +00:00
|
|
|
if (NRF24radio.isChipConnected()) {
|
|
|
|
DEBUG_DRIVER_LOG(PSTR("NRF: Chip connected"));
|
2020-01-01 18:09:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-12-31 15:17:30 +00:00
|
|
|
DEBUG_DRIVER_LOG(PSTR("NRF: Chip NOT !!!! connected"));
|
2020-01-01 18:09:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-31 15:17:30 +00:00
|
|
|
void NRF24Detect(void) {
|
|
|
|
if (PinUsed(GPIO_NRF24_CS) && PinUsed(GPIO_NRF24_DC) && TasmotaGlobal.spi_enabled) {
|
|
|
|
if (NRF24initRadio()) {
|
2020-01-01 18:09:20 +00:00
|
|
|
NRF24.chipType = 32; // SPACE
|
2020-12-31 15:17:30 +00:00
|
|
|
AddLog_P(LOG_LEVEL_INFO, PSTR("NRF: Model 24L01 initialized"));
|
|
|
|
if (NRF24radio.isPVariant()) {
|
2020-01-01 18:09:20 +00:00
|
|
|
NRF24.chipType = 43; // +
|
2020-12-31 15:17:30 +00:00
|
|
|
AddLog_P(LOG_LEVEL_INFO, PSTR("NRF: Model 24L01+ detected"));
|
2020-01-01 18:09:20 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-02 15:58:20 +00:00
|
|
|
}
|
2020-01-01 18:09:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************************************\
|
|
|
|
* Interface
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2020-12-31 15:17:30 +00:00
|
|
|
bool Xdrv33(uint8_t function) {
|
2020-01-01 18:09:20 +00:00
|
|
|
bool result = false;
|
|
|
|
|
2020-12-30 16:52:05 +00:00
|
|
|
if (FUNC_INIT == function) {
|
2020-12-31 15:17:30 +00:00
|
|
|
NRF24Detect();
|
2020-01-01 18:09:20 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_NRF24
|
|
|
|
#endif // USE_SPI
|
|
|
|
|