1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers: make use of ARRAY_SIZE macro

This commit is contained in:
Benjamin Valentin 2019-07-18 15:17:31 +02:00
parent e8dc1119b8
commit 9d6d93ef2f
9 changed files with 12 additions and 12 deletions

View File

@ -72,12 +72,12 @@ static int16_t _tx_pow_to_dbm_212b(uint8_t channel, uint8_t page, uint8_t reg)
if (channel == 0) {
/* Channel 0 is 868.3 MHz */
dbm_to_tx_pow = &dbm_to_tx_pow_868[0];
nelem = sizeof(dbm_to_tx_pow_868) / sizeof(dbm_to_tx_pow_868[0]);
nelem = ARRAY_SIZE(dbm_to_tx_pow_868);
}
else {
/* Channels 1+ are 915 MHz */
dbm_to_tx_pow = &dbm_to_tx_pow_915[0];
nelem = sizeof(dbm_to_tx_pow_915) / sizeof(dbm_to_tx_pow_915[0]);
nelem = ARRAY_SIZE(dbm_to_tx_pow_915);
}
for (size_t i = 0; i < nelem; ++i) {

View File

@ -69,7 +69,7 @@ static const bmx280_params_t bmx280_params[] =
/**
* @brief The number of configured sensors
*/
#define BMX280_NUMOF (sizeof(bmx280_params) / sizeof(bmx280_params[0]))
#define BMX280_NUMOF ARRAY_SIZE(bmx280_params)
/**
* @brief Configuration details of SAUL registry entries

View File

@ -45,7 +45,7 @@ void kw2xrf_disable_interrupts(kw2xrf_t *dev)
void kw2xrf_update_overwrites(kw2xrf_t *dev)
{
kw2xrf_write_dreg(dev, MKW2XDM_OVERWRITE_VER, overwrites_direct[0].data);
for (uint8_t i = 0; i < sizeof(overwrites_indirect)/sizeof(overwrites_t); i++) {
for (uint8_t i = 0; i < ARRAY_SIZE(overwrites_indirect); i++) {
kw2xrf_write_iregs(dev, overwrites_indirect[i].address,
(uint8_t *)&(overwrites_indirect[i].data), 1);
}

View File

@ -50,7 +50,7 @@ static void update_ringbuffer(ltc4150_last_minute_data_t *data,
data->last_rotate_sec += 10;
data->charged += data->buf_charged[data->ring_pos];
data->discharged += data->buf_discharged[data->ring_pos];
if (++data->ring_pos >= sizeof(data->buf_charged)/sizeof(data->buf_charged[0])) {
if (++data->ring_pos >= ARRAY_SIZE(data->buf_charged)) {
data->ring_pos = 0;
}
data->charged -= data->buf_charged[data->ring_pos];

View File

@ -422,7 +422,7 @@ int sht1x_init(sht1x_dev_t *dev, const sht1x_params_t *params)
if (
!dev ||
!params ||
(((uint8_t)params->vdd) >= sizeof(sht1x_d1) / sizeof(sht1x_d1[0]))
(((uint8_t)params->vdd) >= ARRAY_SIZE(sht1x_d1))
) {
return -EINVAL;
}
@ -443,7 +443,7 @@ int sht1x_init(sht1x_dev_t *dev, const sht1x_params_t *params)
/*---------------------------------------------------------------------------*/
int16_t sht1x_temperature(const sht1x_dev_t *dev, uint16_t raw)
{
if (!dev || (dev->vdd >= sizeof(sht1x_d1) / sizeof(sht1x_d1[0]))) {
if (!dev || (dev->vdd >= ARRAY_SIZE(sht1x_d1))) {
return INT16_MIN;
}
@ -520,7 +520,7 @@ int sht1x_read(const sht1x_dev_t *dev, int16_t *temp, int16_t *rel_hum)
if (
!dev ||
(dev->vdd >= sizeof(sht1x_d1) / sizeof(sht1x_d1[0])) ||
(dev->vdd >= ARRAY_SIZE(sht1x_d1)) ||
(!temp && !rel_hum)
) {
return -EINVAL;

View File

@ -77,7 +77,7 @@ static const sht2x_params_t sht2x_params[] =
/**
* @brief Get the number of configured SHT2X devices
*/
#define SHT2X_NUMOF (sizeof(sht2x_params) / sizeof(sht2x_params[0]))
#define SHT2X_NUMOF ARRAY_SIZE(sht2x_params)
/**
* @brief Configuration details of SAUL registry entries

View File

@ -22,7 +22,7 @@
#include "sht3x.h"
#include "sht3x_params.h"
#define SHT3X_NUM (sizeof(sht3x_params) / sizeof(sht3x_params[0]))
#define SHT3X_NUM ARRAY_SIZE(sht3x_params)
extern sht3x_dev_t sht3x_devs[SHT3X_NUM];
/**

View File

@ -39,7 +39,7 @@ static inline bool soft_spi_bus_is_valid(soft_spi_t bus)
{
unsigned int soft_spi_num = (unsigned int) bus;
if (sizeof(soft_spi_config) / sizeof(soft_spi_config[0]) < soft_spi_num) {
if (ARRAY_SIZE(soft_spi_config) < soft_spi_num) {
return false;
}
return true;

View File

@ -55,7 +55,7 @@ static const srf04_params_t srf04_params[] = {
/**
* @brief Number of SRF04 devices
*/
#define SRF04_NUMOF (sizeof(srf04_params) / sizeof(srf04_params[0]))
#define SRF04_NUMOF ARRAY_SIZE(srf04_params)
#ifdef __cplusplus
}