Skip to content
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

hw/nrf/adc: Fix adc device configuration #1052

Merged
merged 2 commits into from Apr 25, 2018

Conversation

rymanluk
Copy link
Contributor

This PR reverts #951 and introduce proper fix for the same problem
This is basically copy of #957 but with fixed commit message.

This reverts commit ce57073, reversing
changes made to 316a2ec.
This patch fixes the way ADC is configured for nRF5x boards as it was
confused what configuration should be provided when created adc device
and how to configure it on open.

With this patch when ADC os_dev is created (what happens in hal_bsp.c),
It is expected to provide 'struct nrf52_adc_dev_cfg' or 'struct
nrf51_adc_dev_cfg'  which contains reference mv which can be
configured by MYNEWT_VALs e.g. ADC_0_REFMV_0

When opening adc os_device (what happens in application), user needs
to provide 'nrfx_saadc_config_t' with appropriate resolution, oversample
etc. e.g.

    nrfx_saadc_config_t adc_config = {
        .resolution         = NRF_SAADC_RESOLUTION_8BIT,
        .oversample         = NRF_SAADC_OVERSAMPLE_DISABLED,
        .interrupt_priority = 7,
        .low_power_mode     = NRFX_SAADC_CONFIG_LP_MODE
    };

    adc = (struct adc_dev *) os_dev_open("adc0", 0, &adc_config);

and later channel config using 'nrf_saadc_channel_config_t':

    nrf_saadc_channel_config_t cc =
NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);

    cc.gain = NRF_SAADC_GAIN1_5;
    cc.reference = NRF_SAADC_REFERENCE_INTERNAL;

    adc_chan_config(adc, cnum, &cc);

This patch removes MYNEWT_VALs ADC_0_RESOLUTION, ADC_0_OVERSAMPLE,
ADC_0_INTERRUPT_PRIORITY in favour of using nrfx specific defines.
@rymanluk rymanluk merged commit 6477ea5 into apache:master Apr 25, 2018
@rymanluk rymanluk deleted the jacob_adc_fix branch April 25, 2018 09:38
@rymanluk rymanluk mentioned this pull request Apr 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants