Skip to content

Commit 970460e

Browse files
sreeramIfxkartben
authored andcommitted
drivers: adc: Update configuration values for CAT1B ADC
- Update resolution and inter reference mV - make unused code conditional Signed-off-by: Sreeram Tatapudi <[email protected]>
1 parent 062e6e1 commit 970460e

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

drivers/adc/adc_ifx_cat1.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ LOG_MODULE_REGISTER(ifx_cat1_adc, CONFIG_ADC_LOG_LEVEL);
3232
#define ADC_CAT1_EVENTS_MASK (CYHAL_ADC_EOS | CYHAL_ADC_ASYNC_READ_COMPLETE)
3333

3434
#define ADC_CAT1_DEFAULT_ACQUISITION_NS (1000u)
35+
#if defined(CONFIG_SOC_FAMILY_INFINEON_CAT1A)
3536
#define ADC_CAT1_RESOLUTION (12u)
3637
#define ADC_CAT1_REF_INTERNAL_MV (1200u)
38+
#elif defined(CONFIG_SOC_FAMILY_INFINEON_CAT1B)
39+
#define ADC_CAT1_RESOLUTION (16u)
40+
#define ADC_CAT1_REF_INTERNAL_MV (3600u)
41+
#endif
3742

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

63-
static void _cyhal_adc_event_callback(void *callback_arg, cyhal_adc_event_t event)
68+
#ifdef CONFIG_SOC_FAMILY_INFINEON_CAT1B
69+
static void ifx_cat1_adc_worker(struct k_work *adc_worker_thread)
6470
{
65-
const struct device *dev = (const struct device *) callback_arg;
66-
struct ifx_cat1_adc_data *data = dev->data;
71+
struct ifx_cat1_adc_data *data =
72+
CONTAINER_OF(adc_worker_thread, struct ifx_cat1_adc_data, adc_worker_thread);
73+
6774
uint32_t channels = data->channels;
6875
int32_t result;
6976
uint32_t channel_id;
@@ -72,26 +79,20 @@ static void _cyhal_adc_event_callback(void *callback_arg, cyhal_adc_event_t even
7279
channel_id = find_lsb_set(channels) - 1;
7380
channels &= ~BIT(channel_id);
7481

75-
result = Cy_SAR_GetResult32(data->adc_chan_obj[channel_id].adc->base,
76-
data->adc_chan_obj[channel_id].channel_idx);
82+
result = cyhal_adc_read(&data->adc_chan_obj[channel_id]);
7783
/* Legacy API for BWC. Convert from signed to unsigned by adding 0x800 to
7884
* convert the lowest signed 12-bit number to 0x0.
7985
*/
8086
*data->buffer = (uint16_t)(result + 0x800);
8187
data->buffer++;
8288
}
83-
84-
adc_context_on_sampling_done(&data->ctx, dev);
85-
86-
LOG_DBG("%s ISR triggered.", dev->name);
89+
adc_context_on_sampling_done(&data->ctx, data->dev);
8790
}
88-
89-
#ifdef CONFIG_SOC_FAMILY_INFINEON_CAT1B
90-
static void ifx_cat1_adc_worker(struct k_work *adc_worker_thread)
91+
#else
92+
static void _cyhal_adc_event_callback(void *callback_arg, cyhal_adc_event_t event)
9193
{
92-
struct ifx_cat1_adc_data *data =
93-
CONTAINER_OF(adc_worker_thread, struct ifx_cat1_adc_data, adc_worker_thread);
94-
94+
const struct device *dev = (const struct device *) callback_arg;
95+
struct ifx_cat1_adc_data *data = dev->data;
9596
uint32_t channels = data->channels;
9697
int32_t result;
9798
uint32_t channel_id;
@@ -100,14 +101,18 @@ static void ifx_cat1_adc_worker(struct k_work *adc_worker_thread)
100101
channel_id = find_lsb_set(channels) - 1;
101102
channels &= ~BIT(channel_id);
102103

103-
result = cyhal_adc_read(&data->adc_chan_obj[channel_id]);
104+
result = Cy_SAR_GetResult32(data->adc_chan_obj[channel_id].adc->base,
105+
data->adc_chan_obj[channel_id].channel_idx);
104106
/* Legacy API for BWC. Convert from signed to unsigned by adding 0x800 to
105107
* convert the lowest signed 12-bit number to 0x0.
106108
*/
107109
*data->buffer = (uint16_t)(result + 0x800);
108110
data->buffer++;
109111
}
110-
adc_context_on_sampling_done(&data->ctx, data->dev);
112+
113+
adc_context_on_sampling_done(&data->ctx, dev);
114+
115+
LOG_DBG("%s ISR triggered.", dev->name);
111116
}
112117
#endif
113118

@@ -300,7 +305,10 @@ static int ifx_cat1_adc_init(const struct device *dev)
300305
/* Enable ADC Interrupt */
301306
cyhal_adc_enable_event(&data->adc_obj, (cyhal_adc_event_t)ADC_CAT1_EVENTS_MASK,
302307
config->irq_priority, true);
308+
309+
#ifndef CONFIG_SOC_FAMILY_INFINEON_CAT1B
303310
cyhal_adc_register_callback(&data->adc_obj, _cyhal_adc_event_callback, (void *) dev);
311+
#endif
304312

305313
adc_context_unlock_unconditionally(&data->ctx);
306314

modules/hal_infineon/mtb-pdl-cat1/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ zephyr_library_sources(${pdl_drv_dir}/source/TOOLCHAIN_GCC_ARM/cy_syslib_ext.S)
3333

3434
# Peripheral drivers
3535
zephyr_library_sources_ifdef(CONFIG_SOC_FAMILY_PSOC6_LEGACY ${pdl_drv_dir}/source/cy_sysint.c)
36-
zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_ADC ${pdl_drv_dir}/source/cy_sar.c)
3736
zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_I2C ${pdl_drv_dir}/source/cy_scb_i2c.c)
3837
zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_LPTIMER ${pdl_drv_dir}/source/cy_mcwdt.c)
3938
zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_PWM ${pdl_drv_dir}/source/cy_tcpwm_pwm.c)

samples/drivers/adc/adc_dt/boards/cyw920829m2evk_02.overlay

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
2424
zephyr,gain = "ADC_GAIN_1";
2525
zephyr,reference = "ADC_REF_INTERNAL";
26-
zephyr,resolution = <12>;
26+
zephyr,resolution = <16>;
2727
zephyr,input-positive = <4>; /* P3.4 */
2828
};
2929

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

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

@@ -50,7 +50,7 @@
5050
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
5151
zephyr,gain = "ADC_GAIN_1";
5252
zephyr,reference = "ADC_REF_INTERNAL";
53-
zephyr,resolution = <12>;
53+
zephyr,resolution = <16>;
5454
zephyr,input-positive = <7>; /* P3.7 */
5555
};
5656
};

tests/drivers/adc/adc_api/boards/cyw920829m2evk_02.overlay

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
2424
zephyr,gain = "ADC_GAIN_1";
2525
zephyr,reference = "ADC_REF_INTERNAL";
26-
zephyr,resolution = <12>;
26+
zephyr,resolution = <16>;
2727
zephyr,input-positive = <4>; /* P3.4 */
2828
};
2929

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

0 commit comments

Comments
 (0)