diff --git a/RF24.cpp b/RF24.cpp index 1cefa162f..37df60edc 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -101,12 +101,17 @@ void RF24::csn(bool mode) void RF24::ce(bool level) { - //Allow for 3-pin use on ATTiny - if (ce_pin != csn_pin) { +#if defined USE_MCP23XXX_AS_CE + USE_MCP23XXX_AS_CE.digitalWrite(ce_pin, level); +#else // !defined(USE_MCP23XXX_AS_CE) + if (ce_pin != csn_pin) + { digitalWrite(ce_pin, level); } +#endif // !defined(USE_MCP23XXX_AS_CE) } + /****************************************************************************/ inline void RF24::beginTransaction() @@ -820,6 +825,8 @@ bool RF24::begin(void) /****************************************************************************/ +// This modification assumes you passed the MCP23017 pin number to the RF24 constructor's _ce_pin parameter + bool RF24::_init_pins() { if (!isValid()) { @@ -854,9 +861,15 @@ bool RF24::_init_pins() // Initialize pins if (ce_pin != csn_pin) { + #if !defined (USE_MCP23XXX_AS_CE) pinMode(ce_pin, OUTPUT); + #endif // !defined (USE_MCP23XXX_AS_CE) pinMode(csn_pin, OUTPUT); } + + #if defined (USE_MCP23XXX_AS_CE) + USE_MCP23XXX_AS_CE.pinMode(ce_pin, OUTPUT); + #endif // defined(USE_MCP23XXX_AS_CE) ce(LOW); csn(HIGH); @@ -869,6 +882,7 @@ bool RF24::_init_pins() return true; // assuming pins are connected properly } + /****************************************************************************/ bool RF24::_init_radio() diff --git a/RF24_config.h b/RF24_config.h index 60d03d1f0..88720d45f 100644 --- a/RF24_config.h +++ b/RF24_config.h @@ -67,7 +67,10 @@ #else //Everything else #include + #include "Adafruit_MCP23X17.h" + // This macro assumes that MCP23017::begin() was called by the application prior to RF24::begin(). + #define USE_MCP23XXX_AS_CE mcp // the global MCP23017 object declared in main application's code space #if defined (ARDUINO) && !defined (__arm__) && !defined (__ARDUINO_X86__) #if defined SPI_UART