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(+)
|
|
|
|
*
|
|
|
|
* Usage: 5 SPI-data-wires plus VVC/ground, use hardware SPI, select GPIO_SPI_CS/GPIO_SPI_DC
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
|
|
|
#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-01-02 15:58:20 +00:00
|
|
|
bool NRF24initRadio()
|
2020-01-01 18:09:20 +00:00
|
|
|
{
|
2020-04-26 16:33:27 +01:00
|
|
|
NRF24radio.begin(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_DC));
|
2020-01-01 18:09:20 +00:00
|
|
|
NRF24radio.powerUp();
|
|
|
|
|
|
|
|
if(NRF24radio.isChipConnected()){
|
|
|
|
DEBUG_DRIVER_LOG(PSTR("NRF24 chip connected"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
DEBUG_DRIVER_LOG(PSTR("NRF24 chip NOT !!!! connected"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NRF24Detect(void)
|
2020-01-02 15:58:20 +00:00
|
|
|
{
|
2020-04-27 11:54:07 +01:00
|
|
|
if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_DC)) {
|
2020-01-01 18:09:20 +00:00
|
|
|
if(NRF24initRadio()){
|
|
|
|
NRF24.chipType = 32; // SPACE
|
2020-11-06 16:09:13 +00:00
|
|
|
AddLog_P(LOG_LEVEL_INFO,PSTR("NRF24L01 initialized"));
|
2020-01-01 18:09:20 +00:00
|
|
|
if(NRF24radio.isPVariant()){
|
|
|
|
NRF24.chipType = 43; // +
|
2020-11-06 16:09:13 +00:00
|
|
|
AddLog_P(LOG_LEVEL_INFO,PSTR("NRF24L01+ detected"));
|
2020-01-01 18:09:20 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2020-01-02 15:58:20 +00:00
|
|
|
}
|
2020-01-01 18:09:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************************************\
|
|
|
|
* Interface
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
|
|
|
bool Xdrv33(uint8_t function)
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
if (FUNC_INIT == function) {
|
|
|
|
result = NRF24Detect();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_NRF24
|
|
|
|
#endif // USE_SPI
|
|
|
|
|