Skip to content

Commit 4340d93

Browse files
committed
Lib now passes all tests
Added back original startWrite function for when users want to use manual methods. The library uses startFastWrite for its internal functions. Provides compatibility with prev. code while still using the new methods for everything else.
1 parent f3b3fb1 commit 4340d93

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

RF24.cpp

+23-5
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ void RF24::powerUp(void)
448448
bool RF24::write( const void* buf, uint8_t len )
449449
{
450450
//Start Writing
451-
startWrite(buf,len);
451+
startFastWrite(buf,len);
452452

453453
//Wait until complete or failed
454454
//ACK payloads that are handled improperly will cause this to hang
@@ -487,7 +487,7 @@ bool RF24::writeBlocking( const void* buf, uint8_t len )
487487

488488
}
489489
//Start Writing
490-
startWrite(buf,len);
490+
startFastWrite(buf,len);
491491

492492
return 1;
493493
}
@@ -525,7 +525,7 @@ bool RF24::writeFast( const void* buf, uint8_t len )
525525

526526
}
527527
//Start Writing
528-
startWrite(buf,len);
528+
startFastWrite(buf,len);
529529

530530
return 1;
531531
}
@@ -539,14 +539,32 @@ bool RF24::writeFast( const void* buf, uint8_t len )
539539
//Otherwise we enter Standby-II mode, which is still faster than standby mode
540540
//Also, we remove the need to keep writing the config register over and over and delaying for 150 us each time if sending a stream of data
541541

542-
void RF24::startWrite( const void* buf, uint8_t len ){ //TMRh20
542+
void RF24::startFastWrite( const void* buf, uint8_t len ){ //TMRh20
543543

544544
write_payload( buf,len);
545545
ce(HIGH);
546546

547547
}
548548

549549

550+
//Added the original startWrite back in so users can still use interrupts, ack payloads, etc
551+
//Allows the library to pass all tests
552+
void RF24::startWrite( const void* buf, uint8_t len )
553+
{
554+
// Transmitter power-up
555+
write_register(CONFIG, ( read_register(CONFIG) | _BV(PWR_UP) ) & ~_BV(PRIM_RX) );
556+
delayMicroseconds(150);
557+
558+
// Send the payload
559+
write_payload( buf, len );
560+
561+
// Allons!
562+
ce(HIGH);
563+
delayMicroseconds(15);
564+
ce(LOW);
565+
}
566+
567+
550568
bool RF24::txStandBy(){
551569

552570
if ( (read_register(FIFO_STATUS) & _BV(TX_EMPTY))){
@@ -613,7 +631,7 @@ void RF24::read( void* buf, uint8_t len ){
613631
read_payload( buf, len );
614632

615633
//Clear the two possible interrupt flags with one command
616-
write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) );
634+
write_register(STATUS,_BV(RX_DR) | _BV(MAX_RT) | _BV(TX_DS) );
617635

618636
}
619637

RF24.h

+21-4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ class RF24
6666
*/
6767
/**@{*/
6868

69+
/**
70+
* Non-blocking write to the open writing pipe used for buffered writes
71+
*
72+
* @note Optimization: This function now leaves the CE pin high, so the radio
73+
* will remain in TX or STANDBY-II Mode until a txStandBy() command is issued.
74+
* This allows the chip to be used to its full potential in TX mode.
75+
*
76+
* @see writeFast()
77+
* @see writeBlocking()
78+
*
79+
* @param buf Pointer to the data to be sent
80+
* @param len Number of bytes to be sent
81+
* @return True if the payload was delivered successfully false if not
82+
*/
83+
void startFastWrite( const void* buf, uint8_t len );
84+
6985
/**
7086
* Set chip select pin
7187
*
@@ -692,16 +708,16 @@ class RF24
692708
* Just like write(), but it returns immediately. To find out what happened
693709
* to the send, catch the IRQ and then call whatHappened().
694710
*
695-
* @note Optimization: This function now leaves the CE pin high, so the radio
696-
* will remain in TX or STANDBY-II Mode until a txStandBy() command is issued.
697-
* This allows the chip to be used to its full potential in TX mode.
711+
* @note Optimization: This function again behaves as it did previously.
712+
* startFastWrite() has been moved to an internal function
698713
*
699714
* @see write()
715+
* @see startFastWrite()
700716
* @see whatHappened()
701717
*
702718
* @param buf Pointer to the data to be sent
703719
* @param len Number of bytes to be sent
704-
* @return True if the payload was delivered successfully false if not
720+
*
705721
*/
706722
void startWrite( const void* buf, uint8_t len );
707723

@@ -934,6 +950,7 @@ class RF24
934950
*
935951
* @li Project blog:
936952
* @li <a href="http://TMRh20.blogspot.com"> TMRh20.blogspot.com </a>
953+
* @li <a href="https://github.com/maniacbug/RF24"> ManiacBug on GitHub (Original Library Author)</a>
937954
*/
938955

939956
#endif // __RF24_H__

0 commit comments

Comments
 (0)