Skip to content

Commit

Permalink
don't reg & REGISTER_MASK
Browse files Browse the repository at this point in the history
`REGISTER_MASK` is defined as 0x1F.
All register offsets are all under 0x1F.
Any register offset masked with REGISTER_MASK results in the same register offset value, so we don't need to compute this at runtime.

Note: all register offsets used are a known number. There is no public API that allows users to read a register offset larger than 0x1F.
  • Loading branch information
2bndy5 committed Jul 15, 2024
1 parent 6990bad commit ba12195
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ uint8_t RF24::read_register(uint8_t reg)

beginTransaction();
#if defined(RF24_SPI_PTR)
status = _spi->transfer(R_REGISTER | reg);
status = _spi->transfer(reg);
result = _spi->transfer(0xff);

#else // !defined(RF24_SPI_PTR)
status = _SPI.transfer(R_REGISTER | reg);
status = _SPI.transfer(reg);
result = _SPI.transfer(0xff);

#endif // !defined(RF24_SPI_PTR)
Expand All @@ -247,7 +247,7 @@ void RF24::write_register(uint8_t reg, const uint8_t* buf, uint8_t len)
uint8_t* ptx = spi_txbuff;
uint8_t size = static_cast<uint8_t>(len + 1); // Add register value to transmit buffer

*ptx++ = (W_REGISTER | (REGISTER_MASK & reg));
*ptx++ = (W_REGISTER | reg);
while (len--) {
*ptx++ = *buf++;
}
Expand Down Expand Up @@ -527,7 +527,7 @@ void RF24::print_address_register(const char* name, uint8_t reg, uint8_t qty)
name);
while (qty--) {
uint8_t* buffer = new uint8_t[addr_width];
read_register(reg++ & REGISTER_MASK, buffer, addr_width);
read_register(reg++, buffer, addr_width);

printf_P(PSTR(" 0x"));
uint8_t* bufptr = buffer + addr_width;
Expand All @@ -546,7 +546,7 @@ uint8_t RF24::sprintf_address_register(char* out_buffer, uint8_t reg, uint8_t qt
uint8_t offset = 0;
uint8_t* read_buffer = new uint8_t[addr_width];
while (qty--) {
read_register(reg++ & REGISTER_MASK, read_buffer, addr_width);
read_register(reg++, read_buffer, addr_width);
uint8_t* bufptr = read_buffer + addr_width;
while (--bufptr >= read_buffer) {
offset += sprintf_P(out_buffer + offset, PSTR("%02X"), *bufptr);
Expand Down

0 comments on commit ba12195

Please sign in to comment.