Skip to content

Commit

Permalink
Preliminary fix for #6
Browse files Browse the repository at this point in the history
- Need to use different packet format for static payloads when AA is disabled
  • Loading branch information
TMRh20 committed May 13, 2023
1 parent 825843d commit 632b06f
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/nrf_to_nrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ bool nrf_to_nrf::available(uint8_t *pipe_num) {
if (NRF_RADIO->EVENTS_CRCOK) {
NRF_RADIO->EVENTS_CRCOK = 0;
*pipe_num = (uint8_t)NRF_RADIO->RXMATCH;
memcpy(&rxBuffer[1], &radioData[2], staticPayloadSize);
if(!DPL && acksEnabled(*pipe_num) == false){
memcpy(&rxBuffer[1],&radioData[0], staticPayloadSize);
}else{
memcpy(&rxBuffer[1], &radioData[2], staticPayloadSize);
}
rxBuffer[0] = radioData[0];
rxFifoAvailable = true;
uint8_t packetCtr = 0;
Expand Down Expand Up @@ -243,8 +247,13 @@ bool nrf_to_nrf::write(void *buf, uint8_t len, bool multicast) {
radioData[1] = 0;
radioData[0] = PID;
}
memset(&radioData[2], 0, staticPayloadSize);
memcpy(&radioData[2], buf, len);
if(!DPL && acksEnabled(0) == false){
memset(&radioData[0], 0, staticPayloadSize);
memcpy(&radioData[0],buf,len);
}else{
memset(&radioData[2], 0, staticPayloadSize);
memcpy(&radioData[2], buf, len);
}

if(NRF_RADIO->STATE < 9){
NRF_RADIO->EVENTS_TXREADY = 0;
Expand Down Expand Up @@ -417,13 +426,19 @@ void nrf_to_nrf::setAutoAck(bool enable) {
for (int i = 0; i < 8; i++) {
acksPerPipe[i] = enable;
}
if(!DPL){
disableDynamicPayloads(); //Called to re-configure the PCNF0 register
}
}

/**********************************************************************************************************/

void nrf_to_nrf::setAutoAck(uint8_t pipe, bool enable) {

acksPerPipe[pipe] = enable;
if(!DPL){
disableDynamicPayloads(); //Called to re-configure the PCNF0 register
}
}

/**********************************************************************************************************/
Expand Down Expand Up @@ -453,9 +468,14 @@ void nrf_to_nrf::enableDynamicPayloads(uint8_t payloadSize) {

void nrf_to_nrf::disableDynamicPayloads() {
DPL = false;
NRF_RADIO->PCNF0 = (1 << RADIO_PCNF0_S0LEN_Pos) |

uint8_t lenConfig = 0;
if(acksEnabled(0)){
lenConfig = 1;
}
NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) |
(0 << RADIO_PCNF0_LFLEN_Pos) |
(1 << RADIO_PCNF0_S1LEN_Pos);
(lenConfig << RADIO_PCNF0_S1LEN_Pos);

NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) |
(RADIO_PCNF1_ENDIAN_Big << RADIO_PCNF1_ENDIAN_Pos) |
Expand All @@ -469,9 +489,14 @@ void nrf_to_nrf::disableDynamicPayloads() {
void nrf_to_nrf::setPayloadSize(uint8_t size) {
staticPayloadSize = size;
DPL = false;
NRF_RADIO->PCNF0 = (1 << RADIO_PCNF0_S0LEN_Pos) |

uint8_t lenConfig = 0;
if(acksEnabled(0)){
lenConfig = 1;
}
NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) |
(0 << RADIO_PCNF0_LFLEN_Pos) |
(1 << RADIO_PCNF0_S1LEN_Pos);
(lenConfig << RADIO_PCNF0_S1LEN_Pos);

NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) |
(RADIO_PCNF1_ENDIAN_Big << RADIO_PCNF1_ENDIAN_Pos) |
Expand Down

0 comments on commit 632b06f

Please sign in to comment.