You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2020/09/04 07:08:13 UTC

[mynewt-core] 02/06: hw/mcu/nordic: Add ADC support for nRF5340

This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit d573032507b035bc5d3316864ad8b435e76601ed
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Thu May 7 09:58:55 2020 +0200

    hw/mcu/nordic: Add ADC support for nRF5340
    
    nRF52 driver is using nrfx and can be use for nRF5340 without
    modifications.
---
 hw/mcu/nordic/nrf5340/pkg.yml              |  4 ++++
 hw/mcu/nordic/nrf5340/src/nrf5340_periph.c | 28 ++++++++++++++++++++++++++++
 hw/mcu/nordic/nrf5340/syscfg.yml           |  8 ++++++++
 3 files changed, 40 insertions(+)

diff --git a/hw/mcu/nordic/nrf5340/pkg.yml b/hw/mcu/nordic/nrf5340/pkg.yml
index 449e65d..2d3fdd5 100644
--- a/hw/mcu/nordic/nrf5340/pkg.yml
+++ b/hw/mcu/nordic/nrf5340/pkg.yml
@@ -49,6 +49,10 @@ pkg.deps.UART_3:
     - "@apache-mynewt-core/hw/drivers/uart/uart_hal"
 
 #nrf52 driver is using nrfx so we can just reuse it
+pkg.deps.ADC_0:
+    - "@apache-mynewt-core/hw/drivers/adc/adc_nrf52"
+
+#nrf52 driver is using nrfx so we can just reuse it
 pkg.deps.PWM_0:
     - "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf52"
 
diff --git a/hw/mcu/nordic/nrf5340/src/nrf5340_periph.c b/hw/mcu/nordic/nrf5340/src/nrf5340_periph.c
index 223b794..eabe477 100644
--- a/hw/mcu/nordic/nrf5340/src/nrf5340_periph.c
+++ b/hw/mcu/nordic/nrf5340/src/nrf5340_periph.c
@@ -24,6 +24,11 @@
 #include <bsp/bsp.h>
 #include <nrfx.h>
 
+#if MYNEWT_VAL(ADC_0)
+#include <adc/adc.h>
+#include <adc_nrf52/adc_nrf52.h>
+#endif
+
 #if MYNEWT_VAL(PWM_0) || MYNEWT_VAL(PWM_1) || MYNEWT_VAL(PWM_2) || MYNEWT_VAL(PWM_3)
 #include <pwm/pwm.h>
 #include <pwm_nrf52/pwm_nrf52.h>
@@ -34,6 +39,13 @@
 #include <uart_hal/uart_hal.h>
 #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;
 #endif
@@ -119,6 +131,21 @@ nrf5340_periph_create_timers(void)
 }
 
 static void
+nrf5340_periph_create_adc(void)
+{
+#if MYNEWT_VAL(ADC_0)
+    int rc;
+
+    (void)rc;
+
+    rc = os_dev_create(&os_bsp_adc0.ad_dev, "adc0",
+                       OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
+                       nrf52_adc_dev_init, &os_bsp_adc0_config);
+    assert(rc == 0);
+#endif
+}
+
+static void
 nrf5340_periph_create_pwm(void)
 {
     int rc;
@@ -188,6 +215,7 @@ void
 nrf5340_periph_create(void)
 {
     nrf5340_periph_create_timers();
+    nrf5340_periph_create_adc();
     nrf5340_periph_create_pwm();
     nrf5340_periph_create_uart();
 }
diff --git a/hw/mcu/nordic/nrf5340/syscfg.yml b/hw/mcu/nordic/nrf5340/syscfg.yml
index 1229768..87e45c4 100644
--- a/hw/mcu/nordic/nrf5340/syscfg.yml
+++ b/hw/mcu/nordic/nrf5340/syscfg.yml
@@ -55,6 +55,14 @@ syscfg.defs:
        value: 0
 
 # MCU peripherals definitions
+    ADC_0:
+        description: 'Enable nRF5340 ADC 0'
+        value:  0
+
+    ADC_0_REFMV_0:
+        description: 'reference mV in AREF0 if used'
+        value: 0
+
     PWM_0:
         description: 'Enable nRF5340 PWM 0'
         value: 0