|
|
@@ -8,6 +8,7 @@ Nrf24L01::Nrf24L01(NrfSettings_t *settings, SpiManager *spi_manager,
|
|
|
_spiManager = spi_manager;
|
|
|
_ce_port = port_ce;
|
|
|
_ce_pin = pin_ce;
|
|
|
+ _settings = settings;
|
|
|
|
|
|
PIN_LOW(_ce_port, _ce_pin);
|
|
|
|
|
|
@@ -36,10 +37,16 @@ Nrf24L01::Nrf24L01(NrfSettings_t *settings, SpiManager *spi_manager,
|
|
|
this->setDataRate(settings->datarate);
|
|
|
this->setCRCScheme(settings->crcScheme);
|
|
|
this->setAddrWidth(settings->addrWidth);
|
|
|
- this->setAddr(settings->pipe, settings->address);
|
|
|
+ this->setAddr(nRF24_PIPETX, settings->address_tx); // set TX addr
|
|
|
+ this->setAddr(settings->pipe_A, settings->address_rx_A);
|
|
|
|
|
|
- if(settings->operationalMode == nRF24_MODE_RX) {
|
|
|
- this->setRXPipe(settings->pipe, nRF24_AA_OFF, settings->payoladLength);
|
|
|
+// if(settings->operationalMode == nRF24_MODE_RX) {
|
|
|
+ this->setRXPipe(settings->pipe_A, nRF24_AA_OFF, settings->payoladLength);
|
|
|
+// }
|
|
|
+
|
|
|
+ if (settings->pipe_B != nRF24_PIPE_None) {
|
|
|
+ this->setAddr(settings->pipe_B, settings->address_rx_B);
|
|
|
+ this->setRXPipe(settings->pipe_B, nRF24_AA_OFF, settings->payoladLength);
|
|
|
}
|
|
|
|
|
|
this->setTXPower(settings->txPower);
|
|
|
@@ -47,10 +54,40 @@ Nrf24L01::Nrf24L01(NrfSettings_t *settings, SpiManager *spi_manager,
|
|
|
this->setOperationalMode(settings->operationalMode);
|
|
|
this->clearIRQFlags();
|
|
|
|
|
|
+ this->flushRX();
|
|
|
+ this->flushTX();
|
|
|
+
|
|
|
+ this->disable();
|
|
|
this->setPowerMode(nRF24_PWR_UP);
|
|
|
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Change operational mode:
|
|
|
+ * For nRF24L01+ to go from power down mode to TX or RX mode it must first pass through stand-by mode.
|
|
|
+ * There must be a delay of Tpd2stby (see Table 16.) after the nRF24L01+ leaves power down mode before
|
|
|
+ * the CEis set high. - Tpd2stby can be up to 5ms per the 1.0 datasheet
|
|
|
+ */
|
|
|
+void Nrf24L01::changeMode(NrfOperationalMode mode) {
|
|
|
+
|
|
|
+ this->disable();
|
|
|
+ this->setPowerMode(nRF24_PWR_DOWN);
|
|
|
+
|
|
|
+// if(mode == nRF24_MODE_RX) { // TODO toto dat prec.
|
|
|
+// this->setRXPipe(_settings->pipe_A, nRF24_AA_OFF, _settings->payoladLength);
|
|
|
+// if (_settings->pipe_B != nRF24_PIPE_None) {
|
|
|
+// this->setAddr(_settings->pipe_B, _settings->address_rx_B);
|
|
|
+// this->setRXPipe(_settings->pipe_B, nRF24_AA_OFF, _settings->payoladLength);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ this->clearIRQFlags();
|
|
|
+ this->setOperationalMode(mode);
|
|
|
+// this->enable();
|
|
|
+
|
|
|
+ this->setPowerMode(nRF24_PWR_UP);
|
|
|
+}
|
|
|
+
|
|
|
uint8_t Nrf24L01::init() {
|
|
|
// Write to registers their initial values
|
|
|
writeReg(nRF24_REG_CONFIG, 0x08);
|
|
|
@@ -170,8 +207,8 @@ void Nrf24L01::setOperationalMode(NrfOperationalMode mode) {
|
|
|
|
|
|
// Set transceiver DynamicPayloadLength feature for all the pipes
|
|
|
// input:
|
|
|
-// mode - status, one of nRF24_DPL_xx values
|
|
|
-void Nrf24L01::setDynamicPayloadLength(uint8_t mode) {
|
|
|
+// mode - status, one of nRF24_DPL_ON/nRF24_DPL_OFF values
|
|
|
+void Nrf24L01::setDynamicPayloadLength(NrfDPLStatus mode) {
|
|
|
uint8_t reg;
|
|
|
reg = readReg(nRF24_REG_FEATURE);
|
|
|
if(mode) {
|
|
|
@@ -539,10 +576,11 @@ nRF24_TXResult Nrf24L01::transmitPayload(uint8_t *pBuf, uint8_t length) {
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
} while (wait--);
|
|
|
|
|
|
// Deassert the CE pin (Standby-II --> Standby-I)
|
|
|
- PIN_LOW(_ce_port, _ce_pin);
|
|
|
+ PIN_LOW(_ce_port, _ce_pin);
|
|
|
|
|
|
if (!wait) {
|
|
|
// Timeout
|