Skip to content

Commit

Permalink
Merge pull request #12587 from aabadie/pr/drivers/nrf24l01p_scan_build
Browse files Browse the repository at this point in the history
drivers/nrf24l01p: fix potentially undefined return value
  • Loading branch information
aabadie authored Oct 28, 2019
2 parents d4adcfd + 808e442 commit e075d97
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions drivers/nrf24l01p/nrf24l01p.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,30 +618,13 @@ int nrf24l01p_set_power(const nrf24l01p_t *dev, int pwr)
return nrf24l01p_write_reg(dev, REG_RF_SETUP, rf_setup);
}

static const int8_t _nrf24l01p_power_map[4] = { -18, -12, -6, 0 };

int nrf24l01p_get_power(const nrf24l01p_t *dev)
{
char rf_setup;
int pwr;

nrf24l01p_read_reg(dev, REG_RF_SETUP, &rf_setup);

if ((rf_setup & 0x6) == 0) {
pwr = -18;
}

if ((rf_setup & 0x6) == 2) {
pwr = -12;
}

if ((rf_setup & 0x6) == 4) {
pwr = -6;
}

if ((rf_setup & 0x6) == 6) {
pwr = 0;
}

return pwr;
return _nrf24l01p_power_map[(rf_setup & 0x6) >> 1];
}


Expand Down

0 comments on commit e075d97

Please # to comment.