You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2016/08/18 22:50:25 UTC
incubator-mynewt-core git commit: Add ADC for nrf51
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/sterly_refactor 7ef74cd32 -> f1d3b7688
Add ADC for nrf51
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/f1d3b768
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f1d3b768
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f1d3b768
Branch: refs/heads/sterly_refactor
Commit: f1d3b76884393ece39c946ca77ac9e86c4bfb2e4
Parents: 7ef74cd
Author: William San Filippo <wi...@runtime.io>
Authored: Thu Aug 18 15:50:00 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Thu Aug 18 15:50:17 2016 -0700
----------------------------------------------------------------------
apps/sblinky/pkg.yml | 9 +-
apps/sblinky/src/main.c | 55 ++-
.../adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h | 30 ++
drivers/adc/adc_nrf51/pkg.yml | 33 ++
drivers/adc/adc_nrf51/src/adc_nrf51.c | 400 +++++++++++++++++++
drivers/adc/adc_nrf52/src/adc_nrf52.c | 2 +-
hw/bsp/nrf51dk/pkg.yml | 2 +
.../src/arch/cortex_m0/gcc_startup_nrf51.s | 4 +-
hw/bsp/nrf51dk/src/hal_bsp.c | 40 +-
hw/bsp/nrf52dk/pkg.yml | 2 +
hw/bsp/nrf52dk/src/hal_bsp.c | 2 +-
hw/hal/include/hal/hal_bsp.h | 3 +-
12 files changed, 564 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1d3b768/apps/sblinky/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/sblinky/pkg.yml b/apps/sblinky/pkg.yml
index a089b99..c45b5b4 100644
--- a/apps/sblinky/pkg.yml
+++ b/apps/sblinky/pkg.yml
@@ -6,7 +6,7 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
@@ -33,10 +33,15 @@ pkg.feature_blacklist:
pkg.feature_whitelist:
".*newtmgr.*": SHELL
+pkg.deps.ADC_NRF51:
+ - drivers/adc/adc_nrf51
+
+pkg.deps.ADC_NRF52:
+ - drivers/adc/adc_nrf52
+
pkg.deps:
- libs/newtmgr
- hw/mcu/nordic
- - drivers/adc/adc_nrf52
- drivers/adc
- libs/console/full
- libs/os
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1d3b768/apps/sblinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/sblinky/src/main.c b/apps/sblinky/src/main.c
index 03583c4..155476a 100755
--- a/apps/sblinky/src/main.c
+++ b/apps/sblinky/src/main.c
@@ -26,20 +26,32 @@
#include "config/config.h"
#include <os/os_dev.h>
#include <adc/adc.h>
-#include <adc_nrf52/adc_nrf52.h>
#include <assert.h>
#include <string.h>
#ifdef ARCH_sim
#include <mcu/mcu_sim.h>
#endif
#include "nrf.h"
-#include "nrf_drv_saadc.h"
#include "app_util_platform.h"
#include "app_error.h"
+#ifdef NRF51
+#include <adc_nrf51/adc_nrf51.h>
+#include "nrf_drv_adc.h"
+nrf_drv_adc_config_t adc_config = NRF_DRV_ADC_DEFAULT_CONFIG;
+nrf_drv_adc_channel_t g_nrf_adc_chan =
+ NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_2);
+#endif
+
+#ifdef NRF52
+#include <adc_nrf52/adc_nrf52.h>
+#include "nrf_drv_saadc.h"
+nrf_drv_saadc_config_t adc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
+#endif
+
int g_result_mv;
int g_result;
-nrf_drv_saadc_config_t adc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
+
/* Init all tasks */
volatile int tasks_initialized;
@@ -156,37 +168,52 @@ err:
void
task1_handler(void *arg)
{
+ //int rc;
struct os_task *t;
struct adc_dev *adc;
+#ifdef NRF52
nrf_saadc_channel_config_t cc =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1);
cc.gain = NRF_SAADC_GAIN1_4;
cc.reference = NRF_SAADC_REFERENCE_VDD4;
+#endif
+
/* Set the led pin for the E407 devboard */
g_led_pin = LED_BLINK_PIN;
hal_gpio_init_out(g_led_pin, 1);
- adc = (struct adc_dev *) os_dev_open("adc0", 1, NULL);
+ adc = (struct adc_dev *) os_dev_open("adc0", 1, &adc_config);
assert(adc != NULL);
+#ifdef NRF51
+ adc_chan_config(adc, 0, &g_nrf_adc_chan);
+#endif
+#ifdef NRF52
adc_chan_config(adc, 0, &cc);
+#endif
sample_buffer1 = malloc(adc_buf_size(adc, ADC_NUMBER_CHANNELS, ADC_NUMBER_SAMPLES));
sample_buffer2 = malloc(adc_buf_size(adc, ADC_NUMBER_CHANNELS, ADC_NUMBER_SAMPLES));
+ memset(sample_buffer1, 0, adc_buf_size(adc, ADC_NUMBER_CHANNELS, ADC_NUMBER_SAMPLES));
+ memset(sample_buffer2, 0, adc_buf_size(adc, ADC_NUMBER_CHANNELS, ADC_NUMBER_SAMPLES));
+#if 1
adc_buf_set(adc, sample_buffer1, sample_buffer2,
adc_buf_size(adc, ADC_NUMBER_CHANNELS, ADC_NUMBER_SAMPLES));
adc_event_handler_set(adc, adc_read_event, (void *) NULL);
+#endif
+
+#if 0
+ rc = adc_chan_read(adc, 0, &g_result);
+ assert(rc == 0);
+ g_result_mv = adc_result_mv(adc, 0, g_result);
+#endif
while (1) {
t = os_sched_get_current_task();
assert(t->t_func == task1_handler);
-/*
- rc = adc_read_channel(adc, 0, &g_result);
- assert(rc == 0);
- g_result_mv = adc_result_mv(adc, 0, g_result);
-*/
+
adc_sample(adc);
++g_task1_loops;
@@ -205,7 +232,7 @@ task1_handler(void *arg)
#endif
}
- os_dev_close((struct os_dev *) adc);
+ os_dev_close((struct os_dev *) adc);
}
void
@@ -291,10 +318,18 @@ main(int argc, char **argv)
stats_module_init();
+#ifdef NRF52
rc = os_dev_create((struct os_dev *) &my_dev, "adc0",
OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
nrf52_adc_dev_init, &adc_config);
assert(rc == 0);
+#endif
+#ifdef NRF51
+ rc = os_dev_create((struct os_dev *) &my_dev, "adc0",
+ OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
+ nrf51_adc_dev_init, &adc_config);
+ assert(rc == 0);
+#endif
#if 0
saadc_test();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1d3b768/drivers/adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h
----------------------------------------------------------------------
diff --git a/drivers/adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h b/drivers/adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h
new file mode 100644
index 0000000..0006b89
--- /dev/null
+++ b/drivers/adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __ADC_NRF51_H__
+#define __ADC_NRF51_H__
+
+#include <adc/adc.h>
+
+#include <nrf.h>
+#include <nrf_adc.h>
+
+int nrf51_adc_dev_init(struct os_dev *, void *);
+
+#endif /* __ADC_NRF51_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1d3b768/drivers/adc/adc_nrf51/pkg.yml
----------------------------------------------------------------------
diff --git a/drivers/adc/adc_nrf51/pkg.yml b/drivers/adc/adc_nrf51/pkg.yml
new file mode 100644
index 0000000..93ee635
--- /dev/null
+++ b/drivers/adc/adc_nrf51/pkg.yml
@@ -0,0 +1,33 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: drivers/adc/adc_nrf51
+pkg.description: ADC driver for the NRF51
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+pkg.features:
+ - ADC_NRF51
+pkg.apis:
+ - ADC_HW_IMPL
+pkg.deps.TEST:
+ - hw/hal
+ - hw/mcu/nordic
+ - drivers/adc
+ - libs/testutil
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1d3b768/drivers/adc/adc_nrf51/src/adc_nrf51.c
----------------------------------------------------------------------
diff --git a/drivers/adc/adc_nrf51/src/adc_nrf51.c b/drivers/adc/adc_nrf51/src/adc_nrf51.c
new file mode 100644
index 0000000..cf57de6
--- /dev/null
+++ b/drivers/adc/adc_nrf51/src/adc_nrf51.c
@@ -0,0 +1,400 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <hal/hal_bsp.h>
+#include <adc/adc.h>
+#include <assert.h>
+#include <os/os.h>
+#include <bsp/cmsis_nvic.h>
+
+/* Nordic headers */
+#include <nrf.h>
+#include <nrf_adc.h>
+#include <nrf_drv_adc.h>
+#include <app_error.h>
+
+/**
+ * Weak symbol, this is defined in Nordic drivers but not exported.
+ * Needed for NVIC_SetVector().
+ */
+extern void ADC_IRQHandler(void);
+
+#define NRF_ADC_CHANNEL_COUNT (1)
+
+struct nrf51_adc_stats {
+ uint16_t adc_events;
+ uint16_t adc_events_failed;
+};
+static struct nrf51_adc_stats nrf51_adc_stats;
+
+struct adc_dev *global_adc_dev;
+
+nrf_adc_config_t adc_cfg;
+nrf_drv_adc_config_t *global_adc_config;
+
+struct adc_chan_config nrf51_adc_chans[NRF_ADC_CHANNEL_COUNT];
+nrf_drv_adc_channel_t *nrf_adc_chan;
+
+static void
+nrf51_adc_event_handler(const nrf_drv_adc_evt_t *event)
+{
+ nrf_drv_adc_done_evt_t *done_ev;
+ int rc;
+
+ if (global_adc_dev == NULL) {
+ ++nrf51_adc_stats.adc_events_failed;
+ return;
+ }
+
+ ++nrf51_adc_stats.adc_events;
+
+ /* Right now only data reads supported, assert for unknown event
+ * type.
+ */
+ assert(event->type == NRF_DRV_ADC_EVT_DONE);
+
+ done_ev = (nrf_drv_adc_done_evt_t * const) &event->data.done;
+
+ rc = global_adc_dev->ad_event_handler_func(global_adc_dev,
+ global_adc_dev->ad_event_handler_arg,
+ ADC_EVENT_RESULT, done_ev->p_buffer,
+ done_ev->size * sizeof(nrf_adc_value_t));
+ if (rc != 0) {
+ ++nrf51_adc_stats.adc_events_failed;
+ }
+}
+
+/**
+ * Open the NRF51 ADC device
+ *
+ * This function locks the device for access from other tasks.
+ *
+ * @param odev The OS device to open
+ * @param wait The time in MS to wait. If 0 specified, returns immediately
+ * if resource unavailable. If OS_WAIT_FOREVER specified, blocks
+ * until resource is available.
+ * @param arg Argument provided by higher layer to open, in this case
+ * it can be a nrf_drv_saadc_config_t, to override the default
+ * configuration.
+ *
+ * @return 0 on success, non-zero on failure.
+ */
+static int
+nrf51_adc_open(struct os_dev *odev, uint32_t wait, void *arg)
+{
+ struct adc_dev *dev;
+ nrf_drv_adc_config_t *cfg;
+ int rc;
+
+ dev = (struct adc_dev *) odev;
+
+ if (os_started()) {
+ rc = os_mutex_pend(&dev->ad_lock, wait);
+ if (rc != OS_OK) {
+ goto err;
+ }
+ }
+
+ /* Initialize the device */
+ cfg = (nrf_drv_adc_config_t *)arg;
+ rc = nrf_drv_adc_init(cfg, nrf51_adc_event_handler);
+ if (rc != 0) {
+ goto err;
+ }
+
+ global_adc_dev = dev;
+ global_adc_config = arg;
+
+ return (0);
+err:
+ return (rc);
+}
+
+
+/**
+ * Close the NRF51 ADC device.
+ *
+ * This function unlocks the device.
+ *
+ * @param odev The device to close.
+ */
+static int
+nrf51_adc_close(struct os_dev *odev)
+{
+ struct adc_dev *dev;
+
+ dev = (struct adc_dev *) odev;
+
+ nrf_drv_adc_uninit();
+
+ global_adc_dev = NULL;
+ global_adc_config = NULL;
+
+ if (os_started()) {
+ os_mutex_release(&dev->ad_lock);
+ }
+
+ return (0);
+}
+
+/**
+ * Configure an ADC channel on the Nordic ADC.
+ *
+ * @param dev The ADC device to configure
+ * @param cnum The channel on the ADC device to configure
+ * @param cfgdata An opaque pointer to channel config, expected to be
+ * a nrf_drv_adc_channel_config_t
+ *
+ * @return 0 on success, non-zero on failure.
+ */
+static int
+nrf51_adc_configure_channel(struct adc_dev *dev, uint8_t cnum,
+ void *cfgdata)
+{
+ nrf_drv_adc_channel_t *cc;
+ nrf_drv_adc_channel_config_t *cc_cfg;
+ nrf_adc_config_t adc_cfg;
+ uint16_t refmv;
+ uint8_t res;
+ int rc;
+
+ rc = -1;
+ if (global_adc_config == NULL) {
+ goto err;
+ }
+
+ cc = (nrf_drv_adc_channel_t *)cfgdata;
+ nrf_adc_chan = cc;
+ cc_cfg = &cc->config.config;
+
+ adc_cfg.reference = cc_cfg->reference |
+ (cc_cfg->external_reference << ADC_CONFIG_EXTREFSEL_Pos);
+ adc_cfg.resolution = cc_cfg->resolution;
+ adc_cfg.scaling = cc_cfg->input;
+ nrf_adc_configure(&adc_cfg);
+ nrf_drv_adc_channel_enable(cc);
+
+ /* Set the resolution and reference voltage for this channel to
+ * enable conversion functions.
+ */
+ switch (adc_cfg.resolution) {
+ case NRF_ADC_CONFIG_RES_8BIT:
+ res = 8;
+ break;
+ case NRF_ADC_CONFIG_RES_9BIT:
+ res = 9;
+ break;
+ case NRF_ADC_CONFIG_RES_10BIT:
+ res = 10;
+ break;
+ default:
+ assert(0);
+ }
+
+ switch (adc_cfg.reference) {
+ case NRF_ADC_CONFIG_REF_VBG:
+ refmv = 1200; /* 1.2V for NRF51 */
+ break;
+ case NRF_ADC_CONFIG_REF_EXT_REF0:
+ refmv = bsp_get_refmv(cc_cfg);
+ break;
+ case NRF_ADC_CONFIG_REF_EXT_REF1:
+ refmv = bsp_get_refmv(cc_cfg);
+ break;
+ case NRF_ADC_CONFIG_REF_SUPPLY_ONE_HALF:
+ refmv = bsp_get_refmv(cc_cfg) / 2;
+ break;
+ case NRF_ADC_CONFIG_REF_SUPPLY_ONE_THIRD:
+ refmv = bsp_get_refmv(cc_cfg) / 3;
+ break;
+ default:
+ assert(0);
+ }
+
+ /* Adjust reference voltage for gain. */
+ switch (cc_cfg->input) {
+ case NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE:
+ break;
+ case NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD:
+ refmv *= 3;
+ break;
+ case NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS:
+ refmv = (refmv * 3) / 2;
+ break;
+ case NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD:
+ refmv = refmv * 3;
+ break;
+ case NRF_ADC_CONFIG_SCALING_SUPPLY_TWO_THIRDS:
+ refmv = (refmv * 3) / 2;
+ break;
+ default:
+ break;
+ }
+
+ /* Store these values in channel definitions, for conversions to
+ * milivolts.
+ */
+ dev->ad_chans[cnum].c_res = res;
+ dev->ad_chans[cnum].c_refmv = refmv;
+ dev->ad_chans[cnum].c_configured = 1;
+
+ return (0);
+err:
+ return (rc);
+}
+
+/**
+ * Set buffer to read data into. Implementation of setbuffer handler.
+ * Sets both the primary and secondary buffers for DMA.
+ */
+static int
+nrf51_adc_set_buffer(struct adc_dev *dev, void *buf1, void *buf2,
+ int buf_len)
+{
+ int rc;
+
+ /* XXX: If this is called in blocking mode, it will result in a wait. */
+
+ /* Convert overall buffer length, into a total number of samples which
+ * Nordic APIs expect.
+ */
+ buf_len /= sizeof(nrf_adc_value_t);
+
+ rc = nrf_drv_adc_buffer_convert((nrf_adc_value_t *) buf1, buf_len);
+ if (rc != 0) {
+ goto err;
+ }
+
+ /* XXX: For now, only support one buffer */
+#if 0
+ if (buf2) {
+ rc = nrf_drv_adc_buffer_convert((nrf_adc_value_t *) buf2,
+ buf_len);
+ if (rc != 0) {
+ goto err;
+ }
+ }
+#endif
+ return (0);
+err:
+ return (rc);
+}
+
+static int
+nrf51_adc_release_buffer(struct adc_dev *dev, void *buf, int buf_len)
+{
+ int rc;
+
+ buf_len /= sizeof(nrf_adc_value_t);
+
+ rc = nrf_drv_adc_buffer_convert((nrf_adc_value_t *) buf, buf_len);
+ if (rc != 0) {
+ goto err;
+ }
+
+ return (0);
+err:
+ return (rc);
+}
+
+/**
+ * Trigger an ADC sample.
+ */
+static int
+nrf51_adc_sample(struct adc_dev *dev)
+{
+ nrf_drv_adc_sample();
+
+ return (0);
+}
+
+/**
+ * Blocking read of an ADC channel, returns result as an integer.
+ */
+static int
+nrf51_adc_read_channel(struct adc_dev *dev, uint8_t cnum, int *result)
+{
+ nrf_adc_value_t adc_value;
+ int rc;
+
+ rc = nrf_drv_adc_sample_convert(nrf_adc_chan, &adc_value);
+ if (rc == 0) {
+ *result = (int) adc_value;
+ }
+ return (rc);
+}
+
+static int
+nrf51_adc_read_buffer(struct adc_dev *dev, void *buf, int buf_len, int off,
+ int *result)
+{
+ nrf_adc_value_t val;
+ int data_off;
+
+ data_off = off * sizeof(nrf_adc_value_t);
+ assert(data_off < buf_len);
+
+ val = *(nrf_adc_value_t *) ((uint8_t *) buf + data_off);
+ *result = val;
+
+ return (0);
+}
+
+static int
+nrf51_adc_size_buffer(struct adc_dev *dev, int chans, int samples)
+{
+ return (sizeof(nrf_adc_value_t) * chans * samples);
+}
+
+
+/**
+ * Callback to initialize an adc_dev structure from the os device
+ * initialization callback. This sets up a nrf51_adc_device(), so that
+ * subsequent lookups to this device allow us to manipulate it.
+ */
+int
+nrf51_adc_dev_init(struct os_dev *odev, void *arg)
+{
+ struct adc_dev *dev;
+ struct adc_driver_funcs *af;
+
+ dev = (struct adc_dev *) odev;
+
+ os_mutex_init(&dev->ad_lock);
+
+ dev->ad_chans = (void *) nrf51_adc_chans;
+ dev->ad_chan_count = NRF_ADC_CHANNEL_COUNT;
+
+ OS_DEV_SETHANDLERS(odev, nrf51_adc_open, nrf51_adc_close);
+
+ af = &dev->ad_funcs;
+
+ af->af_configure_channel = nrf51_adc_configure_channel;
+ af->af_sample = nrf51_adc_sample;
+ af->af_read_channel = nrf51_adc_read_channel;
+ af->af_set_buffer = nrf51_adc_set_buffer;
+ af->af_release_buffer = nrf51_adc_release_buffer;
+ af->af_read_buffer = nrf51_adc_read_buffer;
+ af->af_size_buffer = nrf51_adc_size_buffer;
+
+ NVIC_SetVector(ADC_IRQn, (uint32_t) ADC_IRQHandler);
+
+ return (0);
+}
+
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1d3b768/drivers/adc/adc_nrf52/src/adc_nrf52.c
----------------------------------------------------------------------
diff --git a/drivers/adc/adc_nrf52/src/adc_nrf52.c b/drivers/adc/adc_nrf52/src/adc_nrf52.c
index 3bd5eba..60a9228 100644
--- a/drivers/adc/adc_nrf52/src/adc_nrf52.c
+++ b/drivers/adc/adc_nrf52/src/adc_nrf52.c
@@ -205,7 +205,7 @@ nrf52_adc_configure_channel(struct adc_dev *dev, uint8_t cnum,
refmv = 600; /* 0.6V for NRF52 */
break;
case NRF_SAADC_REFERENCE_VDD4:
- refmv = bsp_get_refmv() / 4;
+ refmv = bsp_get_refmv(NULL) / 4;
break;
default:
assert(0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1d3b768/hw/bsp/nrf51dk/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/pkg.yml b/hw/bsp/nrf51dk/pkg.yml
index 4a1a93b..72dae70 100644
--- a/hw/bsp/nrf51dk/pkg.yml
+++ b/hw/bsp/nrf51dk/pkg.yml
@@ -38,3 +38,5 @@ pkg.deps:
- libs/baselibc
pkg.deps.BLE_DEVICE:
- net/nimble/drivers/nrf51
+pkg.features:
+ - ADC_NRF51
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1d3b768/hw/bsp/nrf51dk/src/arch/cortex_m0/gcc_startup_nrf51.s
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/arch/cortex_m0/gcc_startup_nrf51.s b/hw/bsp/nrf51dk/src/arch/cortex_m0/gcc_startup_nrf51.s
index 431849d..881c773 100755
--- a/hw/bsp/nrf51dk/src/arch/cortex_m0/gcc_startup_nrf51.s
+++ b/hw/bsp/nrf51dk/src/arch/cortex_m0/gcc_startup_nrf51.s
@@ -93,7 +93,7 @@ __isr_vector:
.long _SPI1_TWI1_IRQHandler
.long 0 /*Reserved */
.long _GPIOTE_IRQHandler
- .long _ADC_IRQHandler
+ .long ADC_IRQHandler
.long _TIMER0_IRQHandler
.long _TIMER1_IRQHandler
.long _TIMER2_IRQHandler
@@ -244,7 +244,7 @@ Default_Handler:
IRQ _SPI0_TWI0_IRQHandler
IRQ _SPI1_TWI1_IRQHandler
IRQ _GPIOTE_IRQHandler
- IRQ _ADC_IRQHandler
+ IRQ ADC_IRQHandler
IRQ _TIMER0_IRQHandler
IRQ _TIMER1_IRQHandler
IRQ _TIMER2_IRQHandler
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1d3b768/hw/bsp/nrf51dk/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/hal_bsp.c b/hw/bsp/nrf51dk/src/hal_bsp.c
index 3bc833e..71e29b5 100644
--- a/hw/bsp/nrf51dk/src/hal_bsp.c
+++ b/hw/bsp/nrf51dk/src/hal_bsp.c
@@ -6,7 +6,7 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
@@ -22,6 +22,8 @@
#include <hal/hal_bsp.h>
#include <mcu/nrf51_hal.h>
#include "bsp/bsp.h"
+#include <nrf_adc.h>
+#include <nrf_drv_adc.h>
static const struct nrf51_uart_cfg uart_cfg = {
.suc_pin_tx = 9,
@@ -63,3 +65,39 @@ bsp_core_dump(int *area_cnt)
*area_cnt = sizeof(dump_cfg) / sizeof(dump_cfg[0]);
return dump_cfg;
}
+
+uint16_t
+bsp_get_refmv(void *cfgdata)
+{
+ uint16_t refmv;
+ nrf_drv_adc_channel_config_t *cc;
+ nrf_adc_config_reference_t cref;
+
+ cc = (nrf_drv_adc_channel_config_t *) cfgdata;
+ cref = cc->reference | (cc->external_reference << ADC_CONFIG_EXTREFSEL_Pos);
+ switch (cref) {
+ case NRF_ADC_CONFIG_REF_VBG:
+ refmv = 1200;
+ break;
+/* XXX: fill these out if using an external reference */
+#if 0
+ case NRF_ADC_CONFIG_REF_EXT_REF0:
+ refmv = XXX;
+ break;
+ case NRF_ADC_CONFIG_REF_EXT_REF1:
+ refmv = YYY;
+ break;
+#endif
+ case NRF_ADC_CONFIG_REF_SUPPLY_ONE_HALF:
+ refmv = 2800 / 2;
+ break;
+ case NRF_ADC_CONFIG_REF_SUPPLY_ONE_THIRD:
+ refmv = 2800 / 3;
+ break;
+ default:
+ refmv = 0;
+ break;
+ }
+
+ return refmv;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1d3b768/hw/bsp/nrf52dk/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/pkg.yml b/hw/bsp/nrf52dk/pkg.yml
index d998894..b85f5d4 100644
--- a/hw/bsp/nrf52dk/pkg.yml
+++ b/hw/bsp/nrf52dk/pkg.yml
@@ -39,3 +39,5 @@ pkg.deps:
- libs/baselibc
pkg.deps.BLE_DEVICE:
- net/nimble/drivers/nrf52
+pkg.features:
+ - ADC_NRF52
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1d3b768/hw/bsp/nrf52dk/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/src/hal_bsp.c b/hw/bsp/nrf52dk/src/hal_bsp.c
index 41b4760..cc5d7b6 100644
--- a/hw/bsp/nrf52dk/src/hal_bsp.c
+++ b/hw/bsp/nrf52dk/src/hal_bsp.c
@@ -66,7 +66,7 @@ bsp_core_dump(int *area_cnt)
}
uint16_t
-bsp_get_refmv(void)
+bsp_get_refmv(void *cfgdata)
{
return (2800);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1d3b768/hw/hal/include/hal/hal_bsp.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_bsp.h b/hw/hal/include/hal/hal_bsp.h
index e41e4bf..8ca8a69 100644
--- a/hw/hal/include/hal/hal_bsp.h
+++ b/hw/hal/include/hal/hal_bsp.h
@@ -65,7 +65,8 @@ const struct bsp_mem_dump *bsp_core_dump(int *area_cnt);
#define BSP_MAX_ID_LEN 32
int bsp_hw_id(uint8_t *id, int max_len);
-uint16_t bsp_get_refmv(void);
+struct adc_dev;
+uint16_t bsp_get_refmv(void *cfgdata);
#ifdef __cplusplus
}