Skip to content

Commit abdf822

Browse files
committed
[nrf fromtree] drivers: adc: nrf: add support for nrf54l internal SAADC inputs
SAADC peripheral for nRF54L Series allows to choose internal voltages as positive inputs. Signed-off-by: Nikodem Kastelik <[email protected]> (cherry picked from commit ece7da5)
1 parent e906c81 commit abdf822

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

drivers/adc/adc_nrfx_saadc.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static const uint8_t saadc_psels[NRF_SAADC_AIN7 + 1] = {
3232
[NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1),
3333
};
3434
#elif defined(CONFIG_SOC_NRF54L15)
35-
static const uint8_t saadc_psels[NRF_SAADC_AIN7 + 1] = {
35+
static const uint32_t saadc_psels[NRF_SAADC_DVDD + 1] = {
3636
[NRF_SAADC_AIN0] = NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1),
3737
[NRF_SAADC_AIN1] = NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1),
3838
[NRF_SAADC_AIN2] = NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1),
@@ -41,6 +41,9 @@ static const uint8_t saadc_psels[NRF_SAADC_AIN7 + 1] = {
4141
[NRF_SAADC_AIN5] = NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1),
4242
[NRF_SAADC_AIN6] = NRF_PIN_PORT_TO_PIN_NUMBER(13U, 1),
4343
[NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(14U, 1),
44+
[NRF_SAADC_VDD] = NRF_SAADC_INPUT_VDD,
45+
[NRF_SAADC_AVDD] = NRF_SAADC_INPUT_AVDD,
46+
[NRF_SAADC_DVDD] = NRF_SAADC_INPUT_DVDD,
4447
};
4548
#endif
4649

@@ -274,13 +277,8 @@ static int adc_nrfx_channel_setup(const struct device *dev,
274277
m_data.single_ended_channels |= BIT(channel_cfg->channel_id);
275278
}
276279

277-
/* Keep the channel disabled in hardware (set positive input to
278-
* NRF_SAADC_INPUT_DISABLED) until it is selected to be included
279-
* in a sampling sequence.
280-
*/
281-
282280
#if (NRF_SAADC_HAS_AIN_AS_PIN)
283-
if ((channel_cfg->input_positive > NRF_SAADC_AIN7) ||
281+
if ((channel_cfg->input_positive >= ARRAY_SIZE(saadc_psels)) ||
284282
(channel_cfg->input_positive < NRF_SAADC_AIN0)) {
285283
return -EINVAL;
286284
}
@@ -295,17 +293,18 @@ static int adc_nrfx_channel_setup(const struct device *dev,
295293
} else {
296294
input_negative = NRF_SAADC_INPUT_DISABLED;
297295
}
298-
296+
#endif
299297
/* Store the positive input selection in a dedicated array,
300298
* to get it later when the channel is selected for a sampling
301299
* and to mark the channel as configured (ready to be selected).
302300
*/
303-
m_data.positive_inputs[channel_id] = saadc_psels[channel_cfg->input_positive];
304-
#else
305301
m_data.positive_inputs[channel_id] = channel_cfg->input_positive;
306-
#endif
307302

308303
nrf_saadc_channel_init(NRF_SAADC, channel_id, &config);
304+
/* Keep the channel disabled in hardware (set positive input to
305+
* NRF_SAADC_INPUT_DISABLED) until it is selected to be included
306+
* in a sampling sequence.
307+
*/
309308
nrf_saadc_channel_input_set(NRF_SAADC,
310309
channel_id,
311310
NRF_SAADC_INPUT_DISABLED,
@@ -532,7 +531,12 @@ static int start_read(const struct device *dev,
532531
nrf_saadc_channel_pos_input_set(
533532
NRF_SAADC,
534533
channel_id,
535-
m_data.positive_inputs[channel_id]);
534+
#if NRF_SAADC_HAS_AIN_AS_PIN
535+
saadc_psels[m_data.positive_inputs[channel_id]]
536+
#else
537+
m_data.positive_inputs[channel_id]
538+
#endif
539+
);
536540
++active_channels;
537541
} else {
538542
nrf_saadc_burst_set(

0 commit comments

Comments
 (0)