Commit 17c42550 authored by Benjamin Cabé's avatar Benjamin Cabé Committed by Benjamin Cabé
Browse files

drivers: adc: adopt new count_bits util function

Adopt new count_bits helper from util.h and avoid
having conflicting definition

Signed-off-by: default avatarBenjamin Cabé <benjamin@zephyrproject.org>
parent ee335399
Loading
Loading
Loading
Loading
+4 −14
Changes for drivers/adc/adc_sam.c: 4 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include <zephyr/logging/log.h>
#include <zephyr/irq.h>
#include <zephyr/sys/util.h>
LOG_MODULE_REGISTER(adc_sam, CONFIG_ADC_LOG_LEVEL);

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

static uint8_t count_bits(uint32_t val)
{
	uint8_t res = 0;

	while (val) {
		res += val & 1U;
		val >>= 1;
	}

	return res;
}

static int adc_sam_channel_setup(const struct device *dev,
				 const struct adc_channel_cfg *channel_cfg)
{
@@ -156,7 +145,8 @@ static void adc_context_start_sampling(struct adc_context *ctx)
	const struct adc_sam_config *const cfg = data->dev->config;
	Adc *const adc = cfg->regs;

	data->num_active_channels = count_bits(ctx->sequence.channels);
	data->num_active_channels =
		count_bits(&ctx->sequence.channels, sizeof(ctx->sequence.channels));

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

	data->num_active_channels = count_bits(channels);
	data->num_active_channels = count_bits(&channels, sizeof(channels));

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