From 8f17e63a22ac01f03a3923b139799baec8256443 Mon Sep 17 00:00:00 2001 From: maniacbug Date: Thu, 4 Aug 2011 20:14:27 -0700 Subject: [PATCH] Add getDataRate, add DISABLED to data rate enum --- RF24.cpp | 40 ++++++++++++++++++++++++++++++++-------- RF24.h | 9 ++++++++- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index 729a309..401715c 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -911,16 +911,22 @@ rf24_datarate_e RF24::getDataRate( void ) void RF24::setCRCLength(rf24_crclength_e length) { - uint8_t config = read_register(CONFIG) & ~_BV(CRCO) ; + uint8_t config = read_register(CONFIG) & ~( _BV(CRCO) | _BV(EN_CRC)) ; - // Always make sure CRC hardware validation is actually on - config |= _BV(EN_CRC) ; - - // Now config 8 or 16 bit CRCs - only 16bit need be turned on - // 8b is the default. - if( length == RF24_CRC_16 ) + switch (length) { - config |= _BV( CRCO ) ; + case RF24_CRC_DISABLED: + break; + + case RF24_CRC_8: + config |= _BV(EN_CRC); + break; + + case RF24_CRC_16: + default: + config |= _BV(EN_CRC); + config |= _BV( CRCO ); + break; } write_register( CONFIG, config ) ; @@ -928,6 +934,24 @@ void RF24::setCRCLength(rf24_crclength_e length) /****************************************************************************/ +rf24_crclength_e RF24::getCRCLength(void) +{ + rf24_crclength_e result = RF24_CRC_DISABLED; + uint8_t config = read_register(CONFIG) & ( _BV(CRCO) | _BV(EN_CRC)) ; + + if ( config & _BV(EN_CRC ) ) + { + if ( config & _BV(CRCO) ) + result = RF24_CRC_16; + else + result = RF24_CRC_8; + } + + return result; +} + +/****************************************************************************/ + void RF24::disableCRC( void ) { uint8_t disable = read_register(CONFIG) & ~_BV(EN_CRC) ; diff --git a/RF24.h b/RF24.h index 9e32939..2c7dce8 100644 --- a/RF24.h +++ b/RF24.h @@ -14,7 +14,7 @@ typedef enum { RF24_PA_MIN = 0,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR } rf24_pa_dbm_e ; typedef enum { RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS } rf24_datarate_e; -typedef enum { RF24_CRC_8 = 0, RF24_CRC_16 } rf24_crclength_e; +typedef enum { RF24_CRC_DISABLED = 0, RF24_CRC_8, RF24_CRC_16 } rf24_crclength_e; /** * Driver for nRF24L01(+) 2.4GHz Wireless Transceiver @@ -481,6 +481,13 @@ public: */ void setCRCLength(rf24_crclength_e length); + /** + * Get the CRC length + * + * @return RF24_DISABLED if disabled or RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit + */ + rf24_crclength_e getCRCLength(void); + /** * Disable CRC validation *