Skip to content

Conversation

@attie-argentum
Copy link
Member

@attie-argentum attie-argentum commented Dec 19, 2021

The adc_sam0 driver previously expected sequence->channels == 1, which is not compatible with the ADC sample, and might be unexpected. In an attempt to avoid breaking changes, I have revised this to require a single bit set (with no confirmation as to whether it is the correct bit). The input channel for this driver needs to be set using the "configurable inputs" API instead - differential or not.

I have also revised adc_sam0 so that it supports devices with MCLK, but only one ADC. This will be important for SAML21 support (see #41308).

Finally, I have revised the drivers/adc sample so that it will operate the "configurable inputs" API correctly.

This PR is split out from #41308.

@github-actions github-actions bot added area: ADC Analog-to-Digital Converter (ADC) area: Samples Samples labels Dec 19, 2021
@attie-argentum attie-argentum changed the title Fixup SAM0 ADC Driver, and ADC Sample Fixup SAM0 ADC driver, and ADC sample Dec 19, 2021
@nandojve nandojve added the platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM) label Dec 19, 2021
@nandojve nandojve changed the title Fixup SAM0 ADC driver, and ADC sample drivers: adc: sam0: Fix driver and sample Dec 20, 2021
Copy link
Member

@nandojve nandojve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR @attie-argentum ,

I particulary don't like #if .. #endif in code but sometimes we need to use. Did you considered add a fixup for adc? It could be something similar to those at soc/arm/atmel_sam0/common.

#ifdef MCLK_APBAMASK_SERCOM0

@codecov-commenter
Copy link

Codecov Report

Merging #41319 (f076540) into main (5fda6a3) will increase coverage by 0.03%.
The diff coverage is 59.13%.

❗ Current head f076540 differs from pull request most recent head 05a0acd. Consider uploading reports for the commit 05a0acd to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main   #41319      +/-   ##
==========================================
+ Coverage   51.24%   51.27%   +0.03%     
==========================================
  Files         605      606       +1     
  Lines       70878    71042     +164     
  Branches    16333    16364      +31     
==========================================
+ Hits        36318    36425     +107     
- Misses      28572    28607      +35     
- Partials     5988     6010      +22     
Impacted Files Coverage Δ
include/device.h 84.61% <ø> (ø)
include/net/ethernet.h 51.28% <ø> (ø)
subsys/net/ip/ipv6.c 56.75% <0.00%> (ø)
subsys/net/ip/net_shell.c 6.67% <0.00%> (-0.04%) ⬇️
subsys/net/lib/sockets/sockets_packet.c 36.76% <0.00%> (-0.28%) ⬇️
subsys/net/ip/ipv6_nbr.c 33.49% <41.17%> (+0.42%) ⬆️
subsys/net/ip/route.c 56.10% <64.70%> (+5.13%) ⬆️
kernel/userspace.c 87.50% <75.00%> (-0.27%) ⬇️
lib/os/heap_listener.c 88.23% <88.23%> (ø)
lib/libc/newlib/libc-hooks.c 52.41% <100.00%> (+0.38%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5fda6a3...05a0acd. Read the comment docs.

@attie-argentum
Copy link
Member Author

attie-argentum commented Dec 21, 2021

@nandojve thanks for your comments.

I didn't consider a fixup.h, because I didn't know they existed... I'll look into it.

Regarding your 4x remaining comments, I hope my reasoning stands. If not, I'll do what I think you're after...

@attie-argentum
Copy link
Member Author

attie-argentum commented Dec 21, 2021

@nandojve I believe I have now implemented an adc_fixup.h as requested. I've left this as a separate patch, as it's quite far-reaching...

I've confirmed that this runs on a SAML21 XPro, and that it builds for a SAMD21 XPro, and a SAME54 XPro - I believe this should cover the bases on variants.

Copy link
Member

@nandojve nandojve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @attie-argentum ,

I think fixups makes code far more clean to read. Thank you for doing it!

@nandojve I believe I have now implemented an adc_fixup.h as requested. I've left this as a separate patch, as it's quite far-reaching...

I will suggest that if you are willing to do, you could mode fixups before you introduce SAML21 support. This will clean the path to add the new SoC support.

@attie-argentum attie-argentum force-pushed the adc-fixup branch 2 times, most recently from d079c40 to a527b91 Compare January 5, 2022 00:43
@attie-argentum
Copy link
Member Author

attie-argentum commented Jan 5, 2022

@nandojve I've now re-worked the fixup header.

The SAML21 support is added transparently, as I felt this was acceptable and actually makes the most sense... it won't be usable until #41308 is merged (unless another existing part has the same shape ADC).

I've also rebased on main.

Copy link
Member

@nandojve nandojve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @attie-argentum ,

Fixup file helped to read code. Thank you for introduce it.

@attie-argentum attie-argentum force-pushed the adc-fixup branch 2 times, most recently from c88fe84 to 97e3c68 Compare January 15, 2022 22:32
@attie-argentum attie-argentum force-pushed the adc-fixup branch 2 times, most recently from 36fec91 to 932378a Compare January 17, 2022 23:52
@nandojve nandojve mentioned this pull request Jan 18, 2022
@attie-argentum attie-argentum force-pushed the adc-fixup branch 2 times, most recently from 064c4b3 to a6e18a7 Compare January 19, 2022 01:33
@attie-argentum
Copy link
Member Author

attie-argentum commented Jan 20, 2022

I have some more fixes for the ADC driver coming - are is it okay for me to roll them into this PR, or would a new PR be preferred?

  • REFCTRL is enable-protected on the SAML21, meaning that the ADC needs to be disabled before changing it.
    • Docs indicate that this is probably true for SAMD21 too (along with the "discard next sample after reference change")
    • SAME54 seems to not have this restriction
  • On SAML21, the reference mapping is different
    • Zephyr's ADC_REF_VDD_1_2 -> ASF's ADC_REFCTRL_REFSEL_INTVCC1
    • Zephyr's ADC_REF_VDD_1 -> ASF's ADC_REFCTRL_REFSEL_INTVCC2
    • I'd propose putting this into a new per-soc fixup header.

On second thought, this should mostly live in #41308

I have however made some minor cleanup and rebased on main.

@attie-argentum attie-argentum force-pushed the adc-fixup branch 2 times, most recently from 1f301eb to c792ab3 Compare January 20, 2022 02:46
@nandojve nandojve added this to the v3.0.0 milestone Jan 20, 2022
@attie-argentum attie-argentum force-pushed the adc-fixup branch 2 times, most recently from 2e5a9df to eb421ef Compare January 28, 2022 01:02
@nandojve
Copy link
Member

Hi @anangl , @stephanosio , @mnkp,

Should this fix be at v3.0?

Previously this was expected to be equal to 1 at all times. This doesn't
play well with the sample or other users (e.g: adc_shell). Instead, we
should count the number of active channels in the bitfield, and ensure
that only one is identified.

Signed-off-by: Attie Grande <[email protected]>
All drivers that require input_positive to be set should be given it.
Some parts may require an offset, so abstract this away too.

Signed-off-by: Attie Grande <[email protected]>
Add a basic device tree overlay to support the use of the ATSAMD21 XPro
dev board with the ADC sample application.

Signed-off-by: Attie Grande <[email protected]>
The ADC driver now supports three different implementations. To maintain
readability, this patch implements an adc_fixup.h that permits more
generic access to relevant registers.

This patch also introduces support for a new third shape ADC - as found
in the SAML21 for example.

Signed-off-by: Attie Grande <[email protected]>
Local variables should not be in capitals.

Signed-off-by: Attie Grande <[email protected]>
@attie-argentum
Copy link
Member Author

Rebase

@carlescufi carlescufi merged commit 24478c8 into zephyrproject-rtos:main Feb 4, 2022
@attie-argentum attie-argentum deleted the adc-fixup branch February 4, 2022 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ADC Analog-to-Digital Converter (ADC) area: Samples Samples platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants