diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2025-03-16 13:16:44 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2025-03-16 13:16:44 +0800 |
| commit | 3255899476f04f628bcd49f6699ae51f37118d59 (patch) | |
| tree | a9d96f467a36de35c024f2865c362932f54b5b82 | |
| parent | c0241d727b59febba81f1855a45779e9a447928d (diff) | |
| download | avr-nrf24l01-driver-3255899476f04f628bcd49f6699ae51f37118d59.tar.gz | |
Refactor repeated code into a function.
| -rw-r--r-- | main.c | 17 |
1 files changed, 4 insertions, 13 deletions
@@ -38,9 +38,9 @@ static inline uint8_t read_reg(uint8_t reg) return SPDR; } -static inline void write_reg(uint8_t reg, uint8_t val) +static inline void write_reg_check(uint8_t reg, uint8_t val, uint8_t ref) { - while (read_reg(reg) != val) { + while (read_reg(reg) != ref) { SPI_PORT &= ~(1 << SPI_SS); SPDR = (reg & 0x1F) | 0x20; while (!(SPSR & (1 << SPIF))) @@ -52,18 +52,9 @@ static inline void write_reg(uint8_t reg, uint8_t val) } } -static inline void write_reg_check(uint8_t reg, uint8_t val, uint8_t ref) +static inline void write_reg(uint8_t reg, uint8_t val) { - while (read_reg(reg) != ref) { - SPI_PORT &= ~(1 << SPI_SS); - SPDR = (reg & 0x1F) | 0x20; - while (!(SPSR & (1 << SPIF))) - ; - SPDR = val; - while (!(SPSR & (1 << SPIF))) - ; - SPI_PORT |= (1 << SPI_SS); - } + write_reg_check(reg, val, val); } static inline void print_config(void) |
