Commit 970460e8 authored by Sreeram Tatapudi's avatar Sreeram Tatapudi Committed by Benjamin Cabé
Browse files

drivers: adc: Update configuration values for CAT1B ADC

	- Update resolution and inter reference mV
	- make unused code conditional

Signed-off-by: default avatarSreeram Tatapudi <sreeram.praveen@infineon.com>
parent 062e6e19
Loading
Loading
Loading
Loading
+25 −17
Changes for drivers/adc/adc_ifx_cat1.c: 25 added lines, 17 removed lines.
Original line number Diff line number Diff line
@@ -32,8 +32,13 @@ LOG_MODULE_REGISTER(ifx_cat1_adc, CONFIG_ADC_LOG_LEVEL);
#define ADC_CAT1_EVENTS_MASK (CYHAL_ADC_EOS | CYHAL_ADC_ASYNC_READ_COMPLETE)

#define ADC_CAT1_DEFAULT_ACQUISITION_NS (1000u)
#if defined(CONFIG_SOC_FAMILY_INFINEON_CAT1A)
#define ADC_CAT1_RESOLUTION             (12u)
#define ADC_CAT1_REF_INTERNAL_MV        (1200u)
#elif defined(CONFIG_SOC_FAMILY_INFINEON_CAT1B)
#define ADC_CAT1_RESOLUTION             (16u)
#define ADC_CAT1_REF_INTERNAL_MV        (3600u)
#endif

#if defined(CONFIG_SOC_FAMILY_INFINEON_CAT1B)
#define IFX_ADC_NUM_CHANNELS                                                                       \
@@ -60,10 +65,12 @@ struct ifx_cat1_adc_config {
	uint8_t irq_priority;
};

static void _cyhal_adc_event_callback(void *callback_arg, cyhal_adc_event_t event)
#ifdef CONFIG_SOC_FAMILY_INFINEON_CAT1B
static void ifx_cat1_adc_worker(struct k_work *adc_worker_thread)
{
	const struct device *dev = (const struct device *) callback_arg;
	struct ifx_cat1_adc_data *data = dev->data;
	struct ifx_cat1_adc_data *data =
		CONTAINER_OF(adc_worker_thread, struct ifx_cat1_adc_data, adc_worker_thread);

	uint32_t channels = data->channels;
	int32_t result;
	uint32_t channel_id;
@@ -72,26 +79,20 @@ static void _cyhal_adc_event_callback(void *callback_arg, cyhal_adc_event_t even
		channel_id = find_lsb_set(channels) - 1;
		channels &= ~BIT(channel_id);

		result = Cy_SAR_GetResult32(data->adc_chan_obj[channel_id].adc->base,
					    data->adc_chan_obj[channel_id].channel_idx);
		result = cyhal_adc_read(&data->adc_chan_obj[channel_id]);
		/* Legacy API for BWC. Convert from signed to unsigned by adding 0x800 to
		 * convert the lowest signed 12-bit number to 0x0.
		 */
		*data->buffer = (uint16_t)(result + 0x800);
		data->buffer++;
	}

	adc_context_on_sampling_done(&data->ctx, dev);

	LOG_DBG("%s ISR triggered.", dev->name);
	adc_context_on_sampling_done(&data->ctx, data->dev);
}

#ifdef CONFIG_SOC_FAMILY_INFINEON_CAT1B
static void ifx_cat1_adc_worker(struct k_work *adc_worker_thread)
#else
static void _cyhal_adc_event_callback(void *callback_arg, cyhal_adc_event_t event)
{
	struct ifx_cat1_adc_data *data =
		CONTAINER_OF(adc_worker_thread, struct ifx_cat1_adc_data, adc_worker_thread);

	const struct device *dev = (const struct device *) callback_arg;
	struct ifx_cat1_adc_data *data = dev->data;
	uint32_t channels = data->channels;
	int32_t result;
	uint32_t channel_id;
@@ -100,14 +101,18 @@ static void ifx_cat1_adc_worker(struct k_work *adc_worker_thread)
		channel_id = find_lsb_set(channels) - 1;
		channels &= ~BIT(channel_id);

		result = cyhal_adc_read(&data->adc_chan_obj[channel_id]);
		result = Cy_SAR_GetResult32(data->adc_chan_obj[channel_id].adc->base,
					    data->adc_chan_obj[channel_id].channel_idx);
		/* Legacy API for BWC. Convert from signed to unsigned by adding 0x800 to
		 * convert the lowest signed 12-bit number to 0x0.
		 */
		*data->buffer = (uint16_t)(result + 0x800);
		data->buffer++;
	}
	adc_context_on_sampling_done(&data->ctx, data->dev);

	adc_context_on_sampling_done(&data->ctx, dev);

	LOG_DBG("%s ISR triggered.", dev->name);
}
#endif

@@ -300,7 +305,10 @@ static int ifx_cat1_adc_init(const struct device *dev)
	/* Enable ADC Interrupt */
	cyhal_adc_enable_event(&data->adc_obj, (cyhal_adc_event_t)ADC_CAT1_EVENTS_MASK,
			       config->irq_priority, true);

#ifndef CONFIG_SOC_FAMILY_INFINEON_CAT1B
	cyhal_adc_register_callback(&data->adc_obj, _cyhal_adc_event_callback, (void *) dev);
#endif

	adc_context_unlock_unconditionally(&data->ctx);

+0 −1
Changes for modules/hal_infineon/mtb-pdl-cat1/CMakeLists.txt: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ zephyr_library_sources(${pdl_drv_dir}/source/TOOLCHAIN_GCC_ARM/cy_syslib_ext.S)

# Peripheral drivers
zephyr_library_sources_ifdef(CONFIG_SOC_FAMILY_PSOC6_LEGACY      ${pdl_drv_dir}/source/cy_sysint.c)
zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_ADC      ${pdl_drv_dir}/source/cy_sar.c)
zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_I2C      ${pdl_drv_dir}/source/cy_scb_i2c.c)
zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_LPTIMER  ${pdl_drv_dir}/source/cy_mcwdt.c)
zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_PWM      ${pdl_drv_dir}/source/cy_tcpwm_pwm.c)
+4 −4
Changes for samples/drivers/adc/adc_dt/boards/cyw920829m2evk_02.overlay: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
		zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
		zephyr,gain = "ADC_GAIN_1";
		zephyr,reference = "ADC_REF_INTERNAL";
		zephyr,resolution = <12>;
		zephyr,resolution = <16>;
		zephyr,input-positive = <4>;   /* P3.4 */
	};

@@ -32,7 +32,7 @@
		zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
		zephyr,gain = "ADC_GAIN_1";
		zephyr,reference = "ADC_REF_INTERNAL";
		zephyr,resolution = <12>;
		zephyr,resolution = <16>;
		zephyr,input-positive = <5>;   /* P3.5 */
	};

@@ -41,7 +41,7 @@
		zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
		zephyr,gain = "ADC_GAIN_1";
		zephyr,reference = "ADC_REF_INTERNAL";
		zephyr,resolution = <12>;
		zephyr,resolution = <16>;
		zephyr,input-positive = <6>;   /* P3.6 */
	};

@@ -50,7 +50,7 @@
		zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
		zephyr,gain = "ADC_GAIN_1";
		zephyr,reference = "ADC_REF_INTERNAL";
		zephyr,resolution = <12>;
		zephyr,resolution = <16>;
		zephyr,input-positive = <7>;   /* P3.7 */
	};
};
+2 −2
Changes for tests/drivers/adc/adc_api/boards/cyw920829m2evk_02.overlay: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
		zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
		zephyr,gain = "ADC_GAIN_1";
		zephyr,reference = "ADC_REF_INTERNAL";
		zephyr,resolution = <12>;
		zephyr,resolution = <16>;
		zephyr,input-positive = <4>;   /* P3.4 */
	};

@@ -32,7 +32,7 @@
		zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
		zephyr,gain = "ADC_GAIN_1";
		zephyr,reference = "ADC_REF_INTERNAL";
		zephyr,resolution = <12>;
		zephyr,resolution = <16>;
		zephyr,input-positive = <5>;   /* P3.5 */
	};
};