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

[mynewt-core] branch master updated (095f330 -> 77fe40e)

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

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


    from 095f330  [STM32F0] Fix stm32_hal_timer_get_freq
     new 7afa66b  hw/battery: Only build shell when enabled
     new 77fe40e  hw/bsp/pinetime: Add battery for voltage measurement

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 hw/battery/src/battery_shell.c |  5 +++++
 hw/bsp/pinetime/pkg.yml        |  2 ++
 hw/bsp/pinetime/src/hal_bsp.c  | 50 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)


[mynewt-core] 02/02: hw/bsp/pinetime: Add battery for voltage measurement

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 77fe40ee09caf4c26355ad20ac3ffe765ed382bf
Author: Casper Meijn <ca...@meijn.net>
AuthorDate: Sun Apr 5 08:47:01 2020 +0200

    hw/bsp/pinetime: Add battery for voltage measurement
---
 hw/bsp/pinetime/pkg.yml       |  2 ++
 hw/bsp/pinetime/src/hal_bsp.c | 50 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/hw/bsp/pinetime/pkg.yml b/hw/bsp/pinetime/pkg.yml
index 8099201..656f688 100644
--- a/hw/bsp/pinetime/pkg.yml
+++ b/hw/bsp/pinetime/pkg.yml
@@ -36,3 +36,5 @@ pkg.deps:
     - '@apache-mynewt-core/kernel/os'
     - '@apache-mynewt-core/libc/baselibc'
     - '@apache-mynewt-core/hw/drivers/chg_ctrl/sgm4056'
+    - '@apache-mynewt-core/hw/battery'
+    - '@apache-mynewt-core/hw/drivers/adc'
diff --git a/hw/bsp/pinetime/src/hal_bsp.c b/hw/bsp/pinetime/src/hal_bsp.c
index 00e9601..1a2e537 100644
--- a/hw/bsp/pinetime/src/hal_bsp.c
+++ b/hw/bsp/pinetime/src/hal_bsp.c
@@ -30,6 +30,9 @@
 #include "mcu/nrf52_hal.h"
 #include "mcu/nrf52_periph.h"
 #include "sgm4056/sgm4056.h"
+#include "battery/battery_adc.h"
+#include "adc_nrf52/adc_nrf52.h"
+#include <nrf_saadc.h>
 
 /** What memory to include in coredump. */
 static const struct hal_bsp_mem_dump dump_cfg[] = {
@@ -89,6 +92,51 @@ hal_bsp_get_nvic_priority(int irq_num, uint32_t pri)
     return cfg_pri;
 }
 
+static struct adc_dev_cfg hal_bsp_adc_dev_config = {
+    .resolution = ADC_RESOLUTION_10BIT,
+    .oversample = ADC_OVERSAMPLE_DISABLED,
+    .calibrate = false,
+};
+
+static struct adc_chan_cfg hal_bsp_adc_channel_config = {
+    .gain = ADC_GAIN1_6,
+    .reference = ADC_REFERENCE_INTERNAL,
+    .acq_time = ADC_ACQTIME_10US,
+    .pin = NRF_SAADC_INPUT_AIN7,
+    .differential = false,
+    .pin_negative = -1,
+};
+
+static struct battery hal_bsp_battery_dev;
+
+static struct battery_adc hal_bsp_battery_adc_dev;
+
+static struct battery_adc_cfg hal_bsp_battery_config = {
+    .battery = &hal_bsp_battery_dev.b_dev,
+    .adc_dev_name = "adc0",
+    .adc_open_arg = &hal_bsp_adc_dev_config,
+    .adc_channel_cfg = &hal_bsp_adc_channel_config,
+    .channel = 0,
+    .mul = 2,
+    .div = 1,
+};
+
+static void
+hal_bsp_battery_init(void)
+{
+    int rc;
+
+    rc = os_dev_create(&hal_bsp_battery_dev.b_dev, "battery",
+                       OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
+                       battery_init, NULL);
+    assert(rc == 0);
+
+    rc = os_dev_create(&hal_bsp_battery_adc_dev.dev.dev, "battery_adc",
+                       OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
+                       battery_adc_init, &hal_bsp_battery_config);
+    assert(rc == 0);
+}
+
 static struct sgm4056_dev os_bsp_charger;
 static struct sgm4056_dev_config os_bsp_charger_config = {
     .power_presence_pin = CHARGER_POWER_PRESENCE_PIN,
@@ -111,4 +159,6 @@ hal_bsp_init(void)
                        OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
                        sgm4056_dev_init, &os_bsp_charger_config);
     assert(rc == 0);
+
+    hal_bsp_battery_init();
 }


[mynewt-core] 01/02: hw/battery: Only build shell when enabled

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7afa66b2513b2a86e965b2ad6ce3c4cabf53ed61
Author: Casper Meijn <ca...@meijn.net>
AuthorDate: Sun Apr 5 08:26:58 2020 +0200

    hw/battery: Only build shell when enabled
    
    If application doesn't use shell, then build will fail because of
    missing #include <shell/shell.h>
---
 hw/battery/src/battery_shell.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/battery/src/battery_shell.c b/hw/battery/src/battery_shell.c
index 33243d6..8e4ee83 100644
--- a/hw/battery/src/battery_shell.c
+++ b/hw/battery/src/battery_shell.c
@@ -17,6 +17,9 @@
  * under the License.
  */
 
+#include "syscfg/syscfg.h"
+#if MYNEWT_VAL(BATTERY_SHELL)
+
 #include <stdio.h>
 #include <string.h>
 #include <limits.h>
@@ -539,3 +542,5 @@ battery_shell_register(void)
     rc = shell_cmd_register(&bat_cli_cmd);
     SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to register battery shell");
 }
+
+#endif