-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update adc driver to support nRF54L15 #68692
Update adc driver to support nRF54L15 #68692
Conversation
7e04c33
to
540cab8
Compare
Needs to be rebased. @anangl please take a look |
540cab8
to
e145427
Compare
Twister tests issues are not related to this PR. Bug raised: #71437 |
BUILD_ASSERT((NRF_SAADC_AIN0 == NRF_SAADC_INPUT_AIN0) && | ||
(NRF_SAADC_AIN1 == NRF_SAADC_INPUT_AIN1) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to change the indentation here.
drivers/adc/adc_nrfx_saadc.c
Outdated
(NRF_SAADC_VDDHDIV5 == NRF_SAADC_INPUT_VDDHDIV5) && | ||
&& (NRF_SAADC_VDDHDIV5 == NRF_SAADC_INPUT_VDDHDIV5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing this, I'd rather suggest to use the following below:
#if defined(SAADC_CH_PSELP_PSELP_VDD)
(NRF_SAADC_VDD == NRF_SAADC_INPUT_VDD) &&
#endif
1,
This way we'll limit the amount of changes.
drivers/adc/adc_nrfx_saadc.c
Outdated
case ADC_GAIN_1: | ||
config.gain = NRF_SAADC_GAIN1; | ||
break; | ||
case ADC_GAIN_2: | ||
config.gain = NRF_SAADC_GAIN2; | ||
break; | ||
#if defined(NRF_SAADC_GAIN4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#if defined(NRF_SAADC_GAIN4) | |
#if defined(SAADC_CH_CONFIG_GAIN_Gain4) |
drivers/adc/adc_nrfx_saadc.c
Outdated
@@ -6,7 +6,7 @@ | |||
|
|||
#define ADC_CONTEXT_USES_KERNEL_TIMER | |||
#include "adc_context.h" | |||
#include <hal/nrf_saadc.h> | |||
#include <nrfx_saadc.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is misleading. The nrfx_saadc driver is not used here.
#include <nrfx_saadc.h> | |
#include <haly/nrfy_saadc.h> |
Regarding NRFX_SAADC_SAMPLES_TO_BYTES()
macro, see the next comment.
drivers/adc/adc_nrfx_saadc.c
Outdated
nrf_saadc_value_t *buffer; | ||
|
||
#if (NRF_SAADC_8BIT_SAMPLE_WIDTH == 8) | ||
if (nrfy_saadc_resolution_get(NRF_SAADC) == NRF_SAADC_RESOLUTION_8BIT) { | ||
buffer = (uint8_t *)nrfy_saadc_buffer_pointer_get(NRF_SAADC) + | ||
nrfy_saadc_amount_get(NRF_SAADC); | ||
} else | ||
#endif | ||
{ | ||
buffer = (uint16_t *)nrfy_saadc_buffer_pointer_get(NRF_SAADC) + | ||
nrfy_saadc_amount_get(NRF_SAADC); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this, I'd suggest to add a function like:
static uint32_t samples_to_bytes(const struct adc_sequence *sequence,
uint16_t number_of_samples)
{
if (NRF_SAADC_8BIT_SAMPLE_WIDTH == 8 && sequence->resolution == 8) {
return number_of_samples;
} else {
return number_of_samples * 2;
}
}
and use it here:
nrf_saadc_value_t *buffer =
(uint8_t *)nrf_saadc_buffer_pointer_get(NRF_SAADC) +
samples_to_bytes(&ctx->sequence,
nrfy_saadc_amount_get(NRF_SAADC));
and in check_buffer_size()
:
needed_buffer_size = samples_to_bytes(sequence, active_channels);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. It makes the code more readable
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright (c) 2023 Nordic Semiconductor ASA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Copyright (c) 2023 Nordic Semiconductor ASA | |
* Copyright (c) 2024 Nordic Semiconductor ASA |
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright (c) 2023 Karol Lasończyk <[email protected]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Copyright (c) 2023 Karol Lasończyk <[email protected]> | |
* Copyright (c) 2024 Nordic Semiconductor ASA |
drivers/adc/adc_nrfx_saadc.c
Outdated
: 1))); | ||
|
||
tacq = (nrf_saadc_acqtime_t)(acq_time / MINIMUM_ACQ_TIME_IN_NS) - 1; | ||
if ((tacq > SAADC_CH_CONFIG_TACQ_Max) || (acq_time < MINIMUM_ACQ_TIME_IN_NS)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ((tacq > SAADC_CH_CONFIG_TACQ_Max) || (acq_time < MINIMUM_ACQ_TIME_IN_NS)) { | |
if ((tacq > NRF_SAADC_ACQTIME_MAX) || (acq_time < MINIMUM_ACQ_TIME_IN_NS)) { |
Need to rebase and resolve conflicts |
Simple enabling adc node. Upstream PR: zephyrproject-rtos/zephyr#68692 Applied as noup because it can't be applied cleanly. Signed-off-by: Karol Lasończyk <[email protected]> (cherry picked from commit 88adda3b14f726645c0a3ebac6d6fab571144f11)
Simple enabling adc node. Upstream PR: zephyrproject-rtos/zephyr#68692 Applied as noup because it can't be applied cleanly. Signed-off-by: Karol Lasończyk <[email protected]> (cherry picked from commit 88adda3b14f726645c0a3ebac6d6fab571144f11)
f42e1eb
to
b2b09d5
Compare
@@ -147,4 +147,7 @@ | |||
t-enter-dpd = <10000>; | |||
t-exit-dpd = <35000>; | |||
}; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}; | |
@@ -147,4 +147,7 @@ | |||
t-enter-dpd = <10000>; | |||
t-exit-dpd = <35000>; | |||
}; | |||
|
|||
&adc { | |||
status = "okay"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason to enable adc at board level?
Can't this be moved to board overlay for individual tests/samples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enabling it on board level is consistent with other Nordic DKs
Expand supported list. Upstream PR: zephyrproject-rtos/zephyr#68692. Signed-off-by: Bartlomiej Buczek <[email protected]>
Expands driver to cover nRF54L15 features like AIN as GPIO configuration, new reference voltage, different set of supported gain options. Signed-off-by: Karol Lasończyk <[email protected]>
Simple enabling adc node. Signed-off-by: Karol Lasończyk <[email protected]>
b2b09d5
to
d944384
Compare
New file with ADC configuration for nRF54L15 PDK. Signed-off-by: Karol Lasończyk <[email protected]>
New file to make test works. Signed-off-by: Karol Lasończyk <[email protected]>
Expand supported list. Signed-off-by: Karol Lasończyk <[email protected]>
d944384
to
3441974
Compare
Expand supported list. Upstream PR: zephyrproject-rtos/zephyr#68692. Signed-off-by: Bartlomiej Buczek <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, some additions in nrfx will be needed to tidy up in the future.
static const uint8_t saadc_psels[NRF_SAADC_AIN7 + 1] = { | ||
[NRF_SAADC_AIN0] = NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), | ||
[NRF_SAADC_AIN1] = NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), | ||
[NRF_SAADC_AIN2] = NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), | ||
[NRF_SAADC_AIN3] = NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), | ||
[NRF_SAADC_AIN4] = NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1), | ||
[NRF_SAADC_AIN5] = NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1), | ||
[NRF_SAADC_AIN6] = NRF_PIN_PORT_TO_PIN_NUMBER(13U, 1), | ||
[NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(14U, 1), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need to find a better solution for AIN lookup in the future, this does not scale well.
nrf_saadc_acqtime_t tacq = 0; | ||
uint16_t acq_time = | ||
(acquisition_time == ADC_ACQ_TIME_DEFAULT | ||
? DEFAULT_ACQ_TIME_IN_NS | ||
: (ADC_ACQ_TIME_VALUE(acquisition_time) * | ||
(ADC_ACQ_TIME_UNIT(acquisition_time) == ADC_ACQ_TIME_MICROSECONDS | ||
? 1000 | ||
: 1))); | ||
|
||
tacq = (nrf_saadc_acqtime_t)(acq_time / MINIMUM_ACQ_TIME_IN_NS) - 1; | ||
if ((tacq > NRF_SAADC_ACQTIME_MAX) || (acq_time < MINIMUM_ACQ_TIME_IN_NS)) { | ||
result = -EINVAL; | ||
} else { | ||
*p_tacq_val = tacq; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we need a function for that in HAL.
|
||
if (channel_id >= SAADC_CH_NUM) { | ||
return -EINVAL; | ||
} | ||
|
||
switch (channel_cfg->gain) { | ||
#if defined(SAADC_CH_CONFIG_GAIN_Gain1_6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MDK use should be avoided, but I don't see a real alternative for now.
No description provided.