Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

drivers/nrf24l01p: fix potentially undefined return value #12587

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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