Skip to content

Commit

Permalink
Add getDataRate, add DISABLED to data rate enum
Browse files Browse the repository at this point in the history
  • Loading branch information
maniacbug committed Aug 5, 2011
1 parent 4833610 commit 8f17e63
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
40 changes: 32 additions & 8 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,23 +911,47 @@ 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 ) ;
}

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

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) ;
Expand Down
9 changes: 8 additions & 1 deletion RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -481,6 +481,13 @@ class RF24
*/
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
*
Expand Down

0 comments on commit 8f17e63

Please sign in to comment.