Add getDataRate, add DISABLED to data rate enum

This commit is contained in:
maniacbug 2011-08-04 20:14:27 -07:00
parent 483361029e
commit 8f17e63a22
2 changed files with 40 additions and 9 deletions

View File

@ -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)
{
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) ;

9
RF24.h
View File

@ -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
*