From ba12195a68f348244406ede5fce6b6b8361dae7e Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Mon, 15 Jul 2024 04:18:07 -0700 Subject: [PATCH] don't `reg & REGISTER_MASK` `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. --- RF24.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index d226cbca..6ad47ffa 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -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) @@ -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(len + 1); // Add register value to transmit buffer - *ptx++ = (W_REGISTER | (REGISTER_MASK & reg)); + *ptx++ = (W_REGISTER | reg); while (len--) { *ptx++ = *buf++; } @@ -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; @@ -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);