Commit cd52d61b authored by TMRh20's avatar TMRh20

ESP8266 Support per @crcastle

Per comments by @crcastle #125 add support for ESP8266 SOC devices
1. Redefine STATUS as NRF_STATUS
2. Add ESP8266 specific defines to Arduino config:
#if defined (ARDUINO_ARCH_ESP8266)
#include <pgmspace.h>
#define PRIPSTR "%S"
#define printf_P printf
parent 594a949b
...@@ -675,7 +675,7 @@ bool RF24::begin(void) ...@@ -675,7 +675,7 @@ bool RF24::begin(void)
// Reset current status // Reset current status
// Notice reset and flush is the last thing we do // Notice reset and flush is the last thing we do
write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) ); write_register(NRF_STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
// Set up default configuration. Callers can always change it later. // Set up default configuration. Callers can always change it later.
// This channel should be universally safe and not bleed over into adjacent // This channel should be universally safe and not bleed over into adjacent
...@@ -704,7 +704,7 @@ void RF24::startListening(void) ...@@ -704,7 +704,7 @@ void RF24::startListening(void)
powerUp(); powerUp();
#endif #endif
write_register(CONFIG, read_register(CONFIG) | _BV(PRIM_RX)); write_register(CONFIG, read_register(CONFIG) | _BV(PRIM_RX));
write_register(STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) ); write_register(NRF_STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
ce(HIGH); ce(HIGH);
// Restore the pipe0 adddress, if exists // Restore the pipe0 adddress, if exists
if (pipe0_reading_address[0] > 0){ if (pipe0_reading_address[0] > 0){
...@@ -822,7 +822,7 @@ bool RF24::write( const void* buf, uint8_t len, const bool multicast ) ...@@ -822,7 +822,7 @@ bool RF24::write( const void* buf, uint8_t len, const bool multicast )
ce(LOW); ce(LOW);
uint8_t status = write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) ); uint8_t status = write_register(NRF_STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
//Max retries exceeded //Max retries exceeded
if( status & _BV(MAX_RT)){ if( status & _BV(MAX_RT)){
...@@ -874,7 +874,7 @@ bool RF24::writeBlocking( const void* buf, uint8_t len, uint32_t timeout ) ...@@ -874,7 +874,7 @@ bool RF24::writeBlocking( const void* buf, uint8_t len, uint32_t timeout )
/****************************************************************************/ /****************************************************************************/
void RF24::reUseTX(){ void RF24::reUseTX(){
write_register(STATUS,_BV(MAX_RT) ); //Clear max retry flag write_register(NRF_STATUS,_BV(MAX_RT) ); //Clear max retry flag
spiTrans( REUSE_TX_PL ); spiTrans( REUSE_TX_PL );
ce(LOW); //Re-Transfer packet ce(LOW); //Re-Transfer packet
ce(HIGH); ce(HIGH);
...@@ -897,7 +897,7 @@ bool RF24::writeFast( const void* buf, uint8_t len, const bool multicast ) ...@@ -897,7 +897,7 @@ bool RF24::writeFast( const void* buf, uint8_t len, const bool multicast )
if( get_status() & _BV(MAX_RT)){ if( get_status() & _BV(MAX_RT)){
//reUseTX(); //Set re-transmit //reUseTX(); //Set re-transmit
write_register(STATUS,_BV(MAX_RT) ); //Clear max retry flag write_register(NRF_STATUS,_BV(MAX_RT) ); //Clear max retry flag
return 0; //Return 0. The previous payload has been retransmitted return 0; //Return 0. The previous payload has been retransmitted
//From the user perspective, if you get a 0, just keep trying to send the same payload //From the user perspective, if you get a 0, just keep trying to send the same payload
} }
...@@ -970,7 +970,7 @@ bool RF24::txStandBy(){ ...@@ -970,7 +970,7 @@ bool RF24::txStandBy(){
#endif #endif
while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){ while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){
if( get_status() & _BV(MAX_RT)){ if( get_status() & _BV(MAX_RT)){
write_register(STATUS,_BV(MAX_RT) ); write_register(NRF_STATUS,_BV(MAX_RT) );
ce(LOW); ce(LOW);
flush_tx(); //Non blocking, flush the data flush_tx(); //Non blocking, flush the data
return 0; return 0;
...@@ -1001,7 +1001,7 @@ bool RF24::txStandBy(uint32_t timeout, bool startTx){ ...@@ -1001,7 +1001,7 @@ bool RF24::txStandBy(uint32_t timeout, bool startTx){
while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){ while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){
if( get_status() & _BV(MAX_RT)){ if( get_status() & _BV(MAX_RT)){
write_register(STATUS,_BV(MAX_RT) ); write_register(NRF_STATUS,_BV(MAX_RT) );
ce(LOW); //Set re-transmit ce(LOW); //Set re-transmit
ce(HIGH); ce(HIGH);
if(millis() - start >= timeout){ if(millis() - start >= timeout){
...@@ -1090,7 +1090,7 @@ void RF24::read( void* buf, uint8_t len ){ ...@@ -1090,7 +1090,7 @@ void RF24::read( void* buf, uint8_t len ){
read_payload( buf, len ); read_payload( buf, len );
//Clear the two possible interrupt flags with one command //Clear the two possible interrupt flags with one command
write_register(STATUS,_BV(RX_DR) | _BV(MAX_RT) | _BV(TX_DS) ); write_register(NRF_STATUS,_BV(RX_DR) | _BV(MAX_RT) | _BV(TX_DS) );
} }
...@@ -1100,7 +1100,7 @@ void RF24::whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready) ...@@ -1100,7 +1100,7 @@ void RF24::whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready)
{ {
// Read the status & reset the status in one easy call // Read the status & reset the status in one easy call
// Or is that such a good idea? // Or is that such a good idea?
uint8_t status = write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) ); uint8_t status = write_register(NRF_STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
// Report to the user what happened // Report to the user what happened
tx_ok = status & _BV(TX_DS); tx_ok = status & _BV(TX_DS);
......
...@@ -114,7 +114,11 @@ ...@@ -114,7 +114,11 @@
// Progmem is Arduino-specific // Progmem is Arduino-specific
// Arduino DUE is arm and does not include avr/pgmspace // Arduino DUE is arm and does not include avr/pgmspace
#if defined(ARDUINO) && ! defined(__arm__) && !defined (__ARDUINO_X86__) #if defined (ARDUINO_ARCH_ESP8266)
#include <pgmspace.h>
#define PRIPSTR "%S"
#define printf_P printf
#elif defined(ARDUINO) && ! defined(__arm__) && !defined (__ARDUINO_X86__)
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#define PRIPSTR "%S" #define PRIPSTR "%S"
#else #else
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#define SETUP_RETR 0x04 #define SETUP_RETR 0x04
#define RF_CH 0x05 #define RF_CH 0x05
#define RF_SETUP 0x06 #define RF_SETUP 0x06
#define STATUS 0x07 #define NRF_STATUS 0x07
#define OBSERVE_TX 0x08 #define OBSERVE_TX 0x08
#define CD 0x09 #define CD 0x09
#define RX_ADDR_P0 0x0A #define RX_ADDR_P0 0x0A
......
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