-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Introduce reworked API for ADC drivers #7691
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7691 +/- ##
=======================================
Coverage 52.12% 52.12%
=======================================
Files 212 212
Lines 25939 25939
Branches 5590 5590
=======================================
Hits 13521 13521
Misses 10177 10177
Partials 2241 2241 Continue to review full report at Codecov.
|
c657298
to
7a19df3
Compare
include/adc.h
Outdated
u8_t channel_id : 5; | ||
|
||
/** Channel type: single-ended or differential. */ | ||
bool differential : 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.
Keep u8_t here, I am not entirely sure compiler will properly pack it with previous byte.
9878e45
to
1a8b1f1
Compare
|
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.
Use DT for IRQ info, should have DT nodes for adc controllers.
drivers/adc/adc_nrfx_adc.c
Outdated
return -EBUSY; | ||
} | ||
|
||
IRQ_CONNECT(ADC_IRQn, CONFIG_ADC_0_IRQ_PRI, |
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 should get IRQ info from DT
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.
done
drivers/adc/adc_nrfx_adc.c
Outdated
static nrfx_adc_channel_t m_channels[CONFIG_ADC_NRFX_ADC_CHANNEL_COUNT]; | ||
|
||
|
||
static int adc_nrfx_channel_setup(struct device *dev, |
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.
use nrfx_adc_ as a function prefix, its a bit confusing when seeing adc_ and thinking maybe that's an adc core function, and not a driver specific one.
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.
But the nrfx_
prefix is used for stuff that comes from nrfx, and in particular all API functions of the nrfx driver for ADC peripheral are prefixed with nrfx_adc_
. So that would be confusing as well. On the other hand, adc_nrfx_
is consistent with the scheme we use for naming implementation files.
And as I see such approach is commonly used. See for example: spi_dw_transceive
, i2c_mcux_configure
, uart_stm32_poll_in
. Thus, I would prefer to stay with this naming.
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.
ok, that makes sense.
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 guess my comment is about being consistent in this file, so either everything should be prefixed adc_nrfx_ or not.
drivers/adc/adc_nrfx_saadc.c
Outdated
nrf_saadc_int_enable(NRF_SAADC_INT_END); | ||
NRFX_IRQ_ENABLE(SAADC_IRQn); | ||
|
||
IRQ_CONNECT(SAADC_IRQn, CONFIG_ADC_0_IRQ_PRI, |
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.
IRQ num and priority should come from DT.
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.
done
|
|
Rebased on master to resolve a conflict in "boards/arm/nrf52_pca20020/Kconfig.board". |
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.
Some comments on the DTS support and minor comments on code style for the NRF drivers.
@@ -6,4 +6,5 @@ | |||
|
|||
config BOARD_NRF51_PCA10028 | |||
bool "nRF51 PCA10028" | |||
select HAS_DTS_ADC |
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.
select HAS_DTS_ADC, should be with the driver, not the board.
@@ -6,5 +6,6 @@ | |||
|
|||
config BOARD_NRF52810_PCA10040 | |||
bool "nRF52810 PCA10040" | |||
select HAS_DTS_ADC |
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.
remove this, just do the select in the driver's Kconfig.
drivers/adc/adc_nrfx_adc.c
Outdated
static nrfx_adc_channel_t m_channels[CONFIG_ADC_NRFX_ADC_CHANNEL_COUNT]; | ||
|
||
|
||
static int adc_nrfx_channel_setup(struct device *dev, |
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 guess my comment is about being consistent in this file, so either everything should be prefixed adc_nrfx_ or not.
drivers/adc/adc_nrfx_saadc.c
Outdated
*/ | ||
channel_id = 0; | ||
do { | ||
if (channels & 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.
seems like the 1 here could be replaced w/define or some support. Is this an enable bit?
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.
Bits set to 1 in this bit-mask indicate that the corresponding channels are selected for the sampling sequence.
I refactored a bit this part of code (in both implementations). Hopefully, it will be clearer now.
drivers/adc/Kconfig
Outdated
@@ -13,10 +13,16 @@ menuconfig ADC | |||
bool | |||
prompt "ADC drivers" |
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.
add select HAS_DTS_ADC
so that all ADC drivers require DTS support.
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.
But what would be the point in having HAS_DTS_ADC
at all then? Right now it only excludes from Kconfig the options providing information that can be taken from DT, and these options are dependent on the same menuconfig entry that would select HAS_DTS_ADC
. They should be rather removed then.
And this would be inconsistent with what we've got in other drivers. Is this a new approach that we want to take?
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.
As agreed on the API call, I'll add another commit with this change.
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.
done
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.
Doc change LGTM. Commit message should be updated (still talks about being marked as DNM).
Which commit? |
I am aware that I am very late to the review, unfortunately I was not able to devote much time to the Zephyr project in last months. The new ADC API is definitely the step in the right direction, however its design has some problems. The main one is the lack of support for triggers. ADC hardware comes in an overwhelming variety of design variants often with a distinctively different architectures. It makes it difficult to design universal API, there are however some fairly common features. One of such features is the concept of a trigger. Once the ADC module is configured - using the nomenclature of this API - the sequence is defined, the measurement can be started by a trigger whereas trigger is typically:
of those the new API supports software trigger and makes an attempt to support timer trigger. The pin trigger and subsystem trigger is missing. The subsystem trigger is popular on many low power MCUs where it is possible to start ADC measurement on some internal, predefined condition without waking up the CPU. Unfortunately this API can not be easily extended. The next time a project needs to trigger ADC measurement on the pin level change the ADC API would need to be completely reworked. In Linux the ADC driver is handled by Industrial I/O driver (IIO) subsystem. Its API is build around the concept of triggers. |
This commit adds ADC nodes to DTS files for nRF SoCs and introduces corresponding bindings for these nodes. Signed-off-by: Andrzej Głąbek <[email protected]>
ADC nodes are enabled in DTS for the following nRF development kits: - nrf51_pca10028 - nrf52_pca10040 - nrf52_pca20020 - nrf52810_pca10040 - nrf52840_pca10056 Signed-off-by: Andrzej Głąbek <[email protected]>
This commit replaces the API for ADC drivers with a reworked one. As requested in the issue zephyrproject-rtos#3980, the adc_enable/adc_disable functions are removed. Additionaly, some new features are introduced, like: - asynchronous calls - configuration of channels - multi-channel sampling Common parts of code that are supposed to appear in each implementation of the driver (like locking, synchronization, triggering of consecutive samplings) are provided in the "adc_context.h" file to keep consistency with the SPI driver. Syscalls are no longer present in the API because the functions starting read requests cannot use them, since they can be provided with a callback that is executed in the ISR context, and there is no point in supporting syscalls only for the channels configuration. "adc_api" test is updated and extended with additional test cases, with intention to show how the API is supposed to be used. "adc_simple" test is removed as it does not seem to add much value. Signed-off-by: Andrzej Głąbek <[email protected]>
This commit adds translation layers to make nrfx drivers for the nRF ADC (nRF51 series) and SAADC (nRF52 series) peripherals accessible via the Zephyr's API. The SAADC peripheral is accessed using nrfx HAL only as it turns out that usage of the nrfx driver in this case would be inconvenient and would unnecessarily complicate the shim. Signed-off-by: Andrzej Głąbek <[email protected]>
This adds to the adc_api test board-specific configurations for the following boards: - nrf51_pca10028 - nrf52_pca10040 - nrf52840_pca10056 "adc" is indicated as supported in the yaml files for these boards so that they are included in sanitycheck. Signed-off-by: Andrzej Głąbek <[email protected]>
To require relevant DTS entries on all platforms providing the ADC driver. Signed-off-by: Andrzej Głąbek <[email protected]>
Major rework of the mcux adc16 driver to convert it to the new adc api. Currently supports a subset of the api features including synchronous and asynchronous reads, and consecutive reads triggered by the kernel timer. Does not yet support some of the channel configuration options such as gain and reference voltage because the hardware only allows these options to be configured by peripheral instance rather than by channel. The values are currently hardcoded in the driver, but in the future we could introduce some flexibility per instance via device tree attributes. Does not yet support consecutive reads triggered by a hardware timer. Signed-off-by: Maureen Helm <[email protected]>
Adds board-specific macros to enable the adc_api test to run on kinetis boards. This restores the test to support all the nxp boards that were supported before the new adc api was introduced. Signed-off-by: Maureen Helm <[email protected]>
Updated to work with new ADC API. Signed-off-by: Justin Watson <[email protected]>
Remove adc_qmsi_ss to use designware driver for sensor subsystem Signed-off-by: Punit Vara <[email protected]>
Get required data from dts tree. Signed-off-by: Punit Vara <[email protected]>
Enable ADC node in dts. Signed-off-by: Punit Vara <[email protected]>
Replace new ADC apis for designware driver Signed-off-by: Punit Vara <[email protected]>
Remove Kconfig which are replaced by dts and unnecessary macros which is not useful anymore. Signed-off-by: Punit Vara <[email protected]>
Replace old ADC apis with new ones. Signed-off-by: Punit Vara <[email protected]>
Replace old ADC driver APIs with new ones. Signed-off-by: Punit Vara <[email protected]>
Add ARC related parameters and modified test case to work this test case on arc sensor subsystem. Signed-off-by: Punit Vara <[email protected]>
check return value for sample fetch. Conditional printk added to print adc value. Signed-off-by: Punit Vara <[email protected]>
Use Kconfig to get device name. Make LIBC conditional to get output. Signed-off-by: Punit Vara <[email protected]>
Remove ADC support from d2000 as it is not migrated to new ADC apis. Signed-off-by: Punit Vara <[email protected]>
Remove unnecessary sample width scenario. Signed-off-by: Punit Vara <[email protected]>
ec5676f
to
47dfd81
Compare
This replaces #6176 and introduces a new API for ADC drivers basing on the feedback gathered there.
Implementations of drivers for ADC peripherals present in nRF chips are included, as well as updated and extended adc_api test to present the way the API is supposed to be used.
Marked as DNM, since existing ADC drivers (and "grove" sensors) need to be updated for this one to be merged.
List of drivers to be converted
Fixes #3980