summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorNick <nick.win999@gmail.com>2020-10-24 18:52:34 -0500
committerNick <nick.win999@gmail.com>2020-10-24 18:52:34 -0500
commitadb07926b1d6760e63e19134b338f8b1ba460483 (patch)
treeba8c8bcfdaa3e81b327438ffb2ad76d127b3aec5 /app
parenta67a8cd3b87e67176fb88c1d04d95004f7ff905d (diff)
Remove newlib dep
Diffstat (limited to 'app')
-rw-r--r--app/boards/arm/bluemicro840/bluemicro840_v1_defconfig2
-rw-r--r--app/boards/arm/nice_nano/nice_nano_defconfig2
-rw-r--r--app/boards/arm/nrfmicro/nrfmicro_13_defconfig2
-rw-r--r--app/drivers/zephyr/battery_voltage_divider.c18
4 files changed, 11 insertions, 13 deletions
diff --git a/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig b/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig
index 2a79981..00d5661 100644
--- a/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig
+++ b/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig
@@ -12,8 +12,6 @@ CONFIG_GPIO=y
CONFIG_ADC=y
-CONFIG_NEWLIB_LIBC=y
-
CONFIG_USE_DT_CODE_PARTITION=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
diff --git a/app/boards/arm/nice_nano/nice_nano_defconfig b/app/boards/arm/nice_nano/nice_nano_defconfig
index b727fe0..a888cb3 100644
--- a/app/boards/arm/nice_nano/nice_nano_defconfig
+++ b/app/boards/arm/nice_nano/nice_nano_defconfig
@@ -12,8 +12,6 @@ CONFIG_GPIO=y
CONFIG_ADC=y
-CONFIG_NEWLIB_LIBC=y
-
CONFIG_USE_DT_CODE_PARTITION=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
diff --git a/app/boards/arm/nrfmicro/nrfmicro_13_defconfig b/app/boards/arm/nrfmicro/nrfmicro_13_defconfig
index 0421653..4e44ea3 100644
--- a/app/boards/arm/nrfmicro/nrfmicro_13_defconfig
+++ b/app/boards/arm/nrfmicro/nrfmicro_13_defconfig
@@ -12,8 +12,6 @@ CONFIG_GPIO=y
CONFIG_ADC=y
-CONFIG_NEWLIB_LIBC=y
-
CONFIG_USE_DT_CODE_PARTITION=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
diff --git a/app/drivers/zephyr/battery_voltage_divider.c b/app/drivers/zephyr/battery_voltage_divider.c
index 6139d46..5bac544 100644
--- a/app/drivers/zephyr/battery_voltage_divider.c
+++ b/app/drivers/zephyr/battery_voltage_divider.c
@@ -7,12 +7,10 @@
#define DT_DRV_COMPAT zmk_battery_voltage_divider
#include <device.h>
-#include <drivers/kscan.h>
#include <drivers/gpio.h>
#include <drivers/adc.h>
#include <drivers/sensor.h>
#include <logging/log.h>
-#include <math.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
@@ -47,10 +45,16 @@ struct bvd_data {
};
static uint8_t lithium_ion_mv_to_pct(int16_t bat_mv) {
- // Magic function that maps mV to this discharge graph from adafruit:
+ // Simple linear approximation of a battery based off adafruit's discharge graph:
// https://learn.adafruit.com/li-ion-and-lipoly-batteries/voltages
- return round(106.818 +
- (-0.032685 - 106.818) / pow(1 + pow(bat_mv / 3679.35, 58.979), 0.347386));
+
+ if (bat_mv >= 4200) {
+ return 100;
+ } else if (bat_mv <= 3450) {
+ return 0;
+ }
+
+ return bat_mv * 2 / 15 - 459;
}
static int bvd_sample_fetch(struct device *dev, enum sensor_channel chan) {
@@ -142,7 +146,7 @@ static int bvd_init(struct device *dev) {
if (drv_data->adc == NULL) {
LOG_ERR("ADC %s failed to retrieve", drv_cfg->io_channel.label);
- return -ENOENT;
+ return -ENODEV;
}
int rc = 0;
@@ -151,7 +155,7 @@ static int bvd_init(struct device *dev) {
drv_data->gpio = device_get_binding(drv_cfg->power_gpios.label);
if (drv_data->gpio == NULL) {
LOG_ERR("Failed to get GPIO %s", drv_cfg->power_gpios.label);
- return -ENOENT;
+ return -ENODEV;
}
rc = gpio_pin_configure(drv_data->gpio, drv_cfg->power_gpios.pin,
GPIO_OUTPUT_INACTIVE | drv_cfg->power_gpios.flags);