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