mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/sx127x: reduce use of floats
This commit is contained in:
parent
35d3896d47
commit
826095d56e
@ -117,9 +117,10 @@ void sx127x_set_syncword(sx127x_t *dev, uint8_t syncword)
|
|||||||
|
|
||||||
uint32_t sx127x_get_channel(const sx127x_t *dev)
|
uint32_t sx127x_get_channel(const sx127x_t *dev)
|
||||||
{
|
{
|
||||||
return (((uint32_t)sx127x_reg_read(dev, SX127X_REG_FRFMSB) << 16) |
|
uint32_t raw = ((uint32_t)sx127x_reg_read(dev, SX127X_REG_FRFMSB) << 16)
|
||||||
(sx127x_reg_read(dev, SX127X_REG_FRFMID) << 8) |
|
| ((uint32_t)sx127x_reg_read(dev, SX127X_REG_FRFMID) << 8)
|
||||||
(sx127x_reg_read(dev, SX127X_REG_FRFLSB))) * LORA_FREQUENCY_RESOLUTION_DEFAULT;
|
| ((uint32_t)sx127x_reg_read(dev, SX127X_REG_FRFLSB));
|
||||||
|
return (uint64_t)raw * LORA_FREQUENCY_RESOLUTION_NANOHERTZ_DEFAULT / 1000000000U;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sx127x_set_channel(sx127x_t *dev, uint32_t channel)
|
void sx127x_set_channel(sx127x_t *dev, uint32_t channel)
|
||||||
@ -129,7 +130,7 @@ void sx127x_set_channel(sx127x_t *dev, uint32_t channel)
|
|||||||
/* Save current operating mode */
|
/* Save current operating mode */
|
||||||
dev->settings.channel = channel;
|
dev->settings.channel = channel;
|
||||||
|
|
||||||
channel = (uint32_t)((double)channel / (double)LORA_FREQUENCY_RESOLUTION_DEFAULT);
|
channel = (uint64_t)channel * 1000000000U / LORA_FREQUENCY_RESOLUTION_NANOHERTZ_DEFAULT;
|
||||||
|
|
||||||
/* Write frequency settings into chip */
|
/* Write frequency settings into chip */
|
||||||
sx127x_reg_write(dev, SX127X_REG_FRFMSB, (uint8_t)((channel >> 16) & 0xFF));
|
sx127x_reg_write(dev, SX127X_REG_FRFMSB, (uint8_t)((channel >> 16) & 0xFF));
|
||||||
|
@ -120,11 +120,10 @@ void sx1276_rx_chain_calibration(sx127x_t *dev)
|
|||||||
|
|
||||||
/* Save context */
|
/* Save context */
|
||||||
reg_pa_config_init_val = sx127x_reg_read(dev, SX127X_REG_PACONFIG);
|
reg_pa_config_init_val = sx127x_reg_read(dev, SX127X_REG_PACONFIG);
|
||||||
initial_freq = (double)(((uint32_t)sx127x_reg_read(dev, SX127X_REG_FRFMSB) << 16)
|
initial_freq = ((uint32_t)sx127x_reg_read(dev, SX127X_REG_FRFMSB) << 16)
|
||||||
| ((uint32_t)sx127x_reg_read(dev, SX127X_REG_FRFMID) << 8)
|
| ((uint32_t)sx127x_reg_read(dev, SX127X_REG_FRFMID) << 8)
|
||||||
| ((uint32_t)sx127x_reg_read(dev,
|
| ((uint32_t)sx127x_reg_read(dev, SX127X_REG_FRFLSB));
|
||||||
SX127X_REG_FRFLSB))) *
|
initial_freq = (uint64_t)initial_freq * LORA_FREQUENCY_RESOLUTION_NANOHERTZ_DEFAULT / 1000000000U;
|
||||||
(double)LORA_FREQUENCY_RESOLUTION_DEFAULT;
|
|
||||||
|
|
||||||
/* Cut the PA just in case, RFO output, power = -1 dBm */
|
/* Cut the PA just in case, RFO output, power = -1 dBm */
|
||||||
sx127x_reg_write(dev, SX127X_REG_PACONFIG, 0x00);
|
sx127x_reg_write(dev, SX127X_REG_PACONFIG, 0x00);
|
||||||
|
@ -35,9 +35,13 @@ extern "C" {
|
|||||||
* @ingroup config
|
* @ingroup config
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
/** @brief Frequency resolution in Hz */
|
#ifndef LORA_FREQUENCY_RESOLUTION_NANOHERTZ_DEFAULT
|
||||||
#ifndef LORA_FREQUENCY_RESOLUTION_DEFAULT
|
/**
|
||||||
#define LORA_FREQUENCY_RESOLUTION_DEFAULT (61.03515625)
|
* @brief Frequency resolution in nano Hz
|
||||||
|
*
|
||||||
|
* This is the same as `(32 * 10^15) >> 19`
|
||||||
|
*/
|
||||||
|
#define LORA_FREQUENCY_RESOLUTION_NANOHERTZ_DEFAULT 61035156250
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** @brief Preamble length, same for Tx and Rx
|
/** @brief Preamble length, same for Tx and Rx
|
||||||
|
Loading…
Reference in New Issue
Block a user