Skip to content

Commit b09f01b

Browse files
kartbenThalley
authored andcommitted
drivers: adc: adopt new zephyr_count_bits util function
Adopt new zephyr_count_bits helper from util.h and avoid having conflicting definition Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org> Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
1 parent d3a287a commit b09f01b

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

drivers/adc/adc_sam.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <zephyr/logging/log.h>
1818
#include <zephyr/irq.h>
19+
#include <zephyr/sys/util.h>
1920
LOG_MODULE_REGISTER(adc_sam, CONFIG_ADC_LOG_LEVEL);
2021

2122
#define SAM_ADC_NUM_CHANNELS 16
@@ -51,18 +52,6 @@ struct adc_sam_data {
5152
uint8_t num_active_channels;
5253
};
5354

54-
static uint8_t count_bits(uint32_t val)
55-
{
56-
uint8_t res = 0;
57-
58-
while (val) {
59-
res += val & 1U;
60-
val >>= 1;
61-
}
62-
63-
return res;
64-
}
65-
6655
static int adc_sam_channel_setup(const struct device *dev,
6756
const struct adc_channel_cfg *channel_cfg)
6857
{
@@ -156,7 +145,8 @@ static void adc_context_start_sampling(struct adc_context *ctx)
156145
const struct adc_sam_config *const cfg = data->dev->config;
157146
Adc *const adc = cfg->regs;
158147

159-
data->num_active_channels = count_bits(ctx->sequence.channels);
148+
data->num_active_channels =
149+
zephyr_count_bits(&ctx->sequence.channels, sizeof(ctx->sequence.channels));
160150

161151
/* Disable all */
162152
adc->ADC_CHDR = 0xffff;
@@ -222,7 +212,7 @@ static int start_read(const struct device *dev,
222212
return -EINVAL;
223213
}
224214

225-
data->num_active_channels = count_bits(channels);
215+
data->num_active_channels = zephyr_count_bits(&channels, sizeof(channels));
226216

227217
error = check_buffer_size(sequence, data->num_active_channels);
228218
if (error) {

0 commit comments

Comments
 (0)