summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-06-25 14:16:53 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2019-06-25 14:16:53 +0200
commite50587344e4977fcc04c04df53caee9b6ebf85f6 (patch)
tree6330470ac71f2678294f475c38a7a9dc4547904f /src
parentf0ad73ff8fe391d2aac4bc437128618647d46b4f (diff)
RF24: toggles, add setPayloadSize
Diffstat (limited to 'src')
-rw-r--r--src/app/nrf24l01test/main.cc12
-rw-r--r--src/driver/nrf24l01.cc42
2 files changed, 32 insertions, 22 deletions
diff --git a/src/app/nrf24l01test/main.cc b/src/app/nrf24l01test/main.cc
index 187a9c1..9dddb58 100644
--- a/src/app/nrf24l01test/main.cc
+++ b/src/app/nrf24l01test/main.cc
@@ -35,12 +35,12 @@ void loop(void)
kout << "write: ";
nrf24l01.setRetries(0, 0);
- nrf24l01.enableDynamicPayloads();
- nrf24l01.enableDynamicAck();
- TIMEIT("blocking write(3)", nrf24l01.write("foo", 3, false, true));
- TIMEIT("blocking write(10)", nrf24l01.write("123456789", 10, false, true));
- TIMEIT("blocking write(20)", nrf24l01.write("123456789123456789", 20, false, true));
- TIMEIT("blocking write(30)", nrf24l01.write("123456789123456789123456789", 30, false, true));
+ nrf24l01.enableDynamicPayloads(false);
+ nrf24l01.enableDynamicAck(false);
+ TIMEIT("blocking write(3)", nrf24l01.write("foo", 3, true, true));
+ TIMEIT("blocking write(10)", nrf24l01.write("123456789", 10, true, true));
+ TIMEIT("blocking write(20)", nrf24l01.write("123456789123456789", 20, true, true));
+ //TIMEIT("blocking write(30)", nrf24l01.write("123456789123456789123456789", 30, true, true));
nrf24l01.startListening();
arch.delay_ms(10);
nrf24l01.stopListening();
diff --git a/src/driver/nrf24l01.cc b/src/driver/nrf24l01.cc
index a678655..0bb4656 100644
--- a/src/driver/nrf24l01.cc
+++ b/src/driver/nrf24l01.cc
@@ -100,6 +100,11 @@ void Nrf24l01::setRetries(uint8_t delay, uint8_t count)
writeRegister(SETUP_RETR, (delay & 0xf) << ARD | (count & 0xf) << ARC);
}
+void Nrf24l01::setPayloadSize(uint8_t size)
+{
+ payload_size = rf24_min(size, 32);
+}
+
void Nrf24l01::setPALevel(uint8_t level)
{
uint8_t setup = readRegister(RF_SETUP) & 0b11111000;
@@ -327,27 +332,32 @@ uint8_t Nrf24l01::writeRegister(uint8_t reg, uint8_t value)
return rxbuf[0];
}
-void Nrf24l01::enableDynamicPayloads(void)
+void Nrf24l01::enableDynamicPayloads(const bool enabled)
{
- // Enable dynamic payload throughout the system
-
- //toggle_features();
- writeRegister(FEATURE, readRegister(FEATURE) | (1 << EN_DPL));
-
- //IF_SERIAL_DEBUG(printf("FEATURE=%i\r\n",read_register(FEATURE)));
-
- // Enable dynamic payload on all pipes
- //
- // Not sure the use case of only having dynamic payload on certain
- // pipes, so the library does not support it.
- writeRegister(DYNPD, readRegister(DYNPD) | (1 << DPL_P5) | (1 << DPL_P4) | (1 << DPL_P3) | (1 << DPL_P2) | (1 << DPL_P1) | (1 << DPL_P0));
+ if (enabled)
+ {
+ writeRegister(FEATURE, readRegister(FEATURE) | (1 << EN_DPL));
+ writeRegister(DYNPD, readRegister(DYNPD) | (1 << DPL_P5) | (1 << DPL_P4) | (1 << DPL_P3) | (1 << DPL_P2) | (1 << DPL_P1) | (1 << DPL_P0));
+ }
+ else
+ {
+ writeRegister(FEATURE, readRegister(FEATURE) & ~(1 << EN_DPL));
+ writeRegister(DYNPD, readRegister(DYNPD) & ~((1 << DPL_P5) | (1 << DPL_P4) | (1 << DPL_P3) | (1 << DPL_P2) | (1 << DPL_P1) | (1 << DPL_P0)));
+ }
- dynamic_payloads_enabled = true;
+ dynamic_payloads_enabled = enabled;
}
-void Nrf24l01::enableDynamicAck(void)
+void Nrf24l01::enableDynamicAck(const bool enabled)
{
- writeRegister(FEATURE, readRegister(FEATURE) | (1 << EN_DYN_ACK));
+ if (enabled)
+ {
+ writeRegister(FEATURE, readRegister(FEATURE) | (1 << EN_DYN_ACK));
+ }
+ else
+ {
+ writeRegister(FEATURE, readRegister(FEATURE) & ~(1 << EN_DYN_ACK));
+ }
}
uint8_t Nrf24l01::writePayload(const void *buf, uint8_t data_len, const uint8_t writeType)