Skip to content

Commit

Permalink
hw/adc: Fix configuration for ADC on nRF5x
Browse files Browse the repository at this point in the history
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
    };

    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 = (struct adc_dev *) os_dev_open("adc0", 0, &adc_config);

This patch removes MYNEWT_VALs ADC_0_RESOLUTION, ADC_0_OVERSAMPLE,
ADC_0_INTERRUPT_PRIORITY in favour of using nrfx specific defines.
  • Loading branch information
jacobrosenthal authored and rymanluk committed Apr 25, 2018
1 parent 80c5e7f commit d1e6307
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 194 deletions.
20 changes: 9 additions & 11 deletions hw/bsp/ada_feather_nrf52/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ static const struct nrf52_hal_spi_cfg os_bsp_spi0s_cfg = {

#if MYNEWT_VAL(ADC_0)
static struct adc_dev os_bsp_adc0;
static nrfx_saadc_config_t os_bsp_adc0_config = {
.resolution = MYNEWT_VAL(ADC_0_RESOLUTION),
.oversample = MYNEWT_VAL(ADC_0_OVERSAMPLE),
.interrupt_priority = MYNEWT_VAL(ADC_0_INTERRUPT_PRIORITY),
static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
.nadc_refmv = MYNEWT_VAL(ADC_0_REFMV_0),
};
#endif

Expand Down Expand Up @@ -220,13 +218,13 @@ hal_bsp_init(void)
#endif

#if MYNEWT_VAL(ADC_0)
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
#endif

#if MYNEWT_VAL(PWM_0)
Expand Down
20 changes: 9 additions & 11 deletions hw/bsp/arduino_primo_nrf52/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ static const struct nrf52_hal_spi_cfg os_bsp_spi0s_cfg = {

#if MYNEWT_VAL(ADC_0)
static struct adc_dev os_bsp_adc0;
static nrfx_saadc_config_t os_bsp_adc0_config = {
.resolution = MYNEWT_VAL(ADC_0_RESOLUTION),
.oversample = MYNEWT_VAL(ADC_0_OVERSAMPLE),
.interrupt_priority = MYNEWT_VAL(ADC_0_INTERRUPT_PRIORITY),
static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
.nadc_refmv = MYNEWT_VAL(ADC_0_REFMV_0),
};
#endif

Expand Down Expand Up @@ -217,13 +215,13 @@ hal_bsp_init(void)
#endif

#if MYNEWT_VAL(ADC_0)
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
#endif

#if MYNEWT_VAL(PWM_0)
Expand Down
6 changes: 2 additions & 4 deletions hw/bsp/bmd300eval/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ static const struct nrf52_hal_i2c_cfg hal_i2c_cfg = {

#if MYNEWT_VAL(ADC_0)
static struct adc_dev os_bsp_adc0;
static nrfx_saadc_config_t os_bsp_adc0_config = {
.resolution = MYNEWT_VAL(ADC_0_RESOLUTION),
.oversample = MYNEWT_VAL(ADC_0_OVERSAMPLE),
.interrupt_priority = MYNEWT_VAL(ADC_0_INTERRUPT_PRIORITY),
static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
.nadc_refmv = MYNEWT_VAL(ADC_0_REFMV_0),
};
#endif

Expand Down
20 changes: 9 additions & 11 deletions hw/bsp/dwm1001-dev/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@ static const struct nrf52_hal_spi_cfg os_bsp_spi1s_cfg = {

#if MYNEWT_VAL(ADC_0)
static struct adc_dev os_bsp_adc0;
static nrfx_saadc_config_t os_bsp_adc0_config = {
.resolution = MYNEWT_VAL(ADC_0_RESOLUTION),
.oversample = MYNEWT_VAL(ADC_0_OVERSAMPLE),
.interrupt_priority = MYNEWT_VAL(ADC_0_INTERRUPT_PRIORITY),
static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
.nadc_refmv = MYNEWT_VAL(ADC_0_REFMV_0),
};
#endif

Expand Down Expand Up @@ -232,13 +230,13 @@ hal_bsp_init(void)
#endif

#if MYNEWT_VAL(ADC_0)
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
#endif

#if MYNEWT_VAL(PWM_0)
Expand Down
20 changes: 9 additions & 11 deletions hw/bsp/nina-b1/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ static const struct nrf52_hal_spi_cfg os_bsp_spi0s_cfg = {

#if MYNEWT_VAL(ADC_0)
static struct adc_dev os_bsp_adc0;
static nrfx_saadc_config_t os_bsp_adc0_config = {
.resolution = MYNEWT_VAL(ADC_0_RESOLUTION),
.oversample = MYNEWT_VAL(ADC_0_OVERSAMPLE),
.interrupt_priority = MYNEWT_VAL(ADC_0_INTERRUPT_PRIORITY),
static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
.nadc_refmv = MYNEWT_VAL(ADC_0_REFMV_0),
};
#endif

Expand Down Expand Up @@ -220,13 +218,13 @@ hal_bsp_init(void)
#endif

#if MYNEWT_VAL(ADC_0)
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
#endif

#if MYNEWT_VAL(PWM_0)
Expand Down
10 changes: 0 additions & 10 deletions hw/bsp/nrf51-arduino_101/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ syscfg.defs:
description: 'CTS pin for UART0'
value: 10

ADC_0_REFMV_0:
description: 'reference mV in AREF0 if used'
value: 0
ADC_0_REFMV_1:
description: 'reference mV in AREF1 if used'
value: 0
ADC_0_REFMV_VDD:
description: 'reference mV in VDD if used'
value: 0

SPI_0_MASTER_PIN_SCK:
description: 'SCK pin for SPI_0_MASTER'
value: 29
Expand Down
10 changes: 0 additions & 10 deletions hw/bsp/nrf51-blenano/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ syscfg.defs:
description: 'CTS pin for UART0'
value: 10

ADC_0_REFMV_0:
description: 'reference mV in AREF0 if used'
value: 0
ADC_0_REFMV_1:
description: 'reference mV in AREF1 if used'
value: 0
ADC_0_REFMV_VDD:
description: 'reference mV in VDD if used'
value: 0

I2C_0_SDA_PIN:
description: 'Data pin for I2C0'
value: 6
Expand Down
11 changes: 0 additions & 11 deletions hw/bsp/nrf51dk-16kbram/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ syscfg.defs:
description: 'CTS pin for UART0'
value: 10

ADC_0_REFMV_0:
description: 'reference mV in AREF0 if used'
value: 0
ADC_0_REFMV_1:
description: 'reference mV in AREF1 if used'
value: 0
ADC_0_REFMV_VDD:
description: 'reference mV in VDD if used'
value: 0


SPI_0_MASTER_PIN_SCK:
description: 'SCK pin for SPI_0_MASTER'
value: 29
Expand Down
9 changes: 0 additions & 9 deletions hw/bsp/nrf51dk/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ syscfg.defs:
description: 'CTS pin for UART0'
value: 10

ADC_0_REFMV_0:
description: 'reference mV in AREF0 if used'
value: 0
ADC_0_REFMV_1:
description: 'reference mV in AREF1 if used'
value: 0
ADC_0_REFMV_VDD:
description: 'reference mV in VDD if used'
value: 0
SPI_0_MASTER_PIN_SCK:
description: 'SCK pin for SPI_0_MASTER'
value: 29
Expand Down
21 changes: 14 additions & 7 deletions hw/bsp/nrf52-thingy/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ static const struct nrf52_hal_spi_cfg os_bsp_spi0s_cfg = {
};
#endif

#if MYNEWT_VAL(ADC_0)
static struct adc_dev os_bsp_adc0;
static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
.nadc_refmv = MYNEWT_VAL(ADC_0_REFMV_0),
};
#endif

#if MYNEWT_VAL(PWM_0)
static struct pwm_dev os_bsp_pwm0;
int pwm0_idx;
Expand Down Expand Up @@ -269,13 +276,13 @@ hal_bsp_init(void)
#endif

#if MYNEWT_VAL(ADC_0)
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
#endif

#if MYNEWT_VAL(PWM_0)
Expand Down
20 changes: 9 additions & 11 deletions hw/bsp/nrf52840pdk/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ static const struct nrf52_hal_spi_cfg os_bsp_spi0s_cfg = {

#if MYNEWT_VAL(ADC_0)
static struct adc_dev os_bsp_adc0;
static nrfx_saadc_config_t os_bsp_adc0_config = {
.resolution = MYNEWT_VAL(ADC_0_RESOLUTION),
.oversample = MYNEWT_VAL(ADC_0_OVERSAMPLE),
.interrupt_priority = MYNEWT_VAL(ADC_0_INTERRUPT_PRIORITY),
static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
.nadc_refmv = MYNEWT_VAL(ADC_0_REFMV_0),
};
#endif

Expand Down Expand Up @@ -232,13 +230,13 @@ hal_bsp_init(void)
#endif

#if MYNEWT_VAL(ADC_0)
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
#endif

#if MYNEWT_VAL(PWM_0)
Expand Down
20 changes: 9 additions & 11 deletions hw/bsp/nrf52dk/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ static const struct nrf52_hal_spi_cfg os_bsp_spi0s_cfg = {

#if MYNEWT_VAL(ADC_0)
static struct adc_dev os_bsp_adc0;
static nrfx_saadc_config_t os_bsp_adc0_config = {
.resolution = MYNEWT_VAL(ADC_0_RESOLUTION),
.oversample = MYNEWT_VAL(ADC_0_OVERSAMPLE),
.interrupt_priority = MYNEWT_VAL(ADC_0_INTERRUPT_PRIORITY),
static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
.nadc_refmv = MYNEWT_VAL(ADC_0_REFMV_0),
};
#endif

Expand Down Expand Up @@ -220,13 +218,13 @@ hal_bsp_init(void)
#endif

#if MYNEWT_VAL(ADC_0)
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
#endif

#if MYNEWT_VAL(PWM_0)
Expand Down
20 changes: 9 additions & 11 deletions hw/bsp/puckjs/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ static const struct nrf52_hal_spi_cfg os_bsp_spi0s_cfg = {

#if MYNEWT_VAL(ADC_0)
static struct adc_dev os_bsp_adc0;
static nrfx_saadc_config_t os_bsp_adc0_config = {
.resolution = MYNEWT_VAL(ADC_0_RESOLUTION),
.oversample = MYNEWT_VAL(ADC_0_OVERSAMPLE),
.interrupt_priority = MYNEWT_VAL(ADC_0_INTERRUPT_PRIORITY),
static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
.nadc_refmv = MYNEWT_VAL(ADC_0_REFMV_0),
};
#endif

Expand Down Expand Up @@ -220,13 +218,13 @@ hal_bsp_init(void)
#endif

#if MYNEWT_VAL(ADC_0)
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
#endif

#if MYNEWT_VAL(PWM_0)
Expand Down
20 changes: 9 additions & 11 deletions hw/bsp/rb-blend2/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ static const struct nrf52_hal_spi_cfg os_bsp_spi0s_cfg = {

#if MYNEWT_VAL(ADC_0)
static struct adc_dev os_bsp_adc0;
static nrfx_saadc_config_t os_bsp_adc0_config = {
.resolution = MYNEWT_VAL(ADC_0_RESOLUTION),
.oversample = MYNEWT_VAL(ADC_0_OVERSAMPLE),
.interrupt_priority = MYNEWT_VAL(ADC_0_INTERRUPT_PRIORITY),
static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
.nadc_refmv = MYNEWT_VAL(ADC_0_REFMV_0),
};
#endif

Expand Down Expand Up @@ -220,13 +218,13 @@ hal_bsp_init(void)
#endif

#if MYNEWT_VAL(ADC_0)
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
"adc0",
OS_DEV_INIT_KERNEL,
OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init,
&os_bsp_adc0_config);
assert(rc == 0);
#endif

#if MYNEWT_VAL(PWM_0)
Expand Down

0 comments on commit d1e6307

Please sign in to comment.