aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorbwhelm <bwhelm@users.noreply.github.com>2019-09-03 14:29:23 -0400
committerfauxpark <fauxpark@gmail.com>2019-09-04 04:29:23 +1000
commitfa71c4c91e8b822e2d78d420d7d6fe2ca32245af (patch)
treeda88278bb1da73b00288db9a1feb7b8f97c41b0e /tmk_core
parente6a6b1f122e72d58fbb14f5752929fe489d0e828 (diff)
downloadqmk_firmware-fa71c4c91e8b822e2d78d420d7d6fe2ca32245af.tar.gz
qmk_firmware-fa71c4c91e8b822e2d78d420d7d6fe2ca32245af.zip
Fix battery level code in adafruit_ble.cpp (#6648)
* Fix battery level code in adafruit_ble.cpp The code in tsk_core/protocol/lufa/adafluit_ble.cpp that polls the battery level for the Adafruit feather BLE controller reads the regulated voltage, not the raw voltage coming from the battery. To do that, the Adafruit Feather docs say you should read from pin A9: https://learn.adafruit.com/adafruit-feather-32u4-basic-proto/power-management#measuring-battery-4-9. (See also https://learn.adafruit.com/adafruit-feather-32u4-bluefruit-le/pinouts#logic-pins-2-9.) I'm not sure why, but analogRead(9); doesn't read the correct pin. Checking all available analog pins experimentally, it turns out that analogRead(7); returns the correct value. So the code above should read: state.vbat = analogRead(7); * Update tmk_core/protocol/lufa/adafruit_ble.cpp Co-Authored-By: Drashna Jaelre <drashna@live.com> * Remove old comment * Fix linking error * Remove `#ifdef` around `#include analog.h`. * Really fix linking error
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/protocol/lufa.mk2
-rw-r--r--tmk_core/protocol/lufa/adafruit_ble.cpp14
2 files changed, 10 insertions, 6 deletions
diff --git a/tmk_core/protocol/lufa.mk b/tmk_core/protocol/lufa.mk
index bb82a31e1..d7d1d9ffc 100644
--- a/tmk_core/protocol/lufa.mk
+++ b/tmk_core/protocol/lufa.mk
@@ -29,6 +29,7 @@ ifeq ($(strip $(BLUETOOTH_ENABLE)), yes)
29endif 29endif
30 30
31ifeq ($(strip $(BLUETOOTH)), AdafruitBLE) 31ifeq ($(strip $(BLUETOOTH)), AdafruitBLE)
32 LUFA_SRC += analog.c
32 LUFA_SRC += $(LUFA_DIR)/adafruit_ble.cpp 33 LUFA_SRC += $(LUFA_DIR)/adafruit_ble.cpp
33endif 34endif
34 35
@@ -51,6 +52,7 @@ SRC += $(LUFA_SRC)
51# Search Path 52# Search Path
52VPATH += $(TMK_PATH)/$(LUFA_DIR) 53VPATH += $(TMK_PATH)/$(LUFA_DIR)
53VPATH += $(LUFA_PATH) 54VPATH += $(LUFA_PATH)
55VPATH += $(DRIVER_PATH)/avr
54 56
55# Option modules 57# Option modules
56#ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE) 58#ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE)
diff --git a/tmk_core/protocol/lufa/adafruit_ble.cpp b/tmk_core/protocol/lufa/adafruit_ble.cpp
index 71d0936f8..1d8ae1038 100644
--- a/tmk_core/protocol/lufa/adafruit_ble.cpp
+++ b/tmk_core/protocol/lufa/adafruit_ble.cpp
@@ -10,6 +10,7 @@
10#include "action_util.h" 10#include "action_util.h"
11#include "ringbuffer.hpp" 11#include "ringbuffer.hpp"
12#include <string.h> 12#include <string.h>
13#include "analog.h"
13 14
14// These are the pin assignments for the 32u4 boards. 15// These are the pin assignments for the 32u4 boards.
15// You may define them to something else in your config.h 16// You may define them to something else in your config.h
@@ -29,6 +30,12 @@
29#define SAMPLE_BATTERY 30#define SAMPLE_BATTERY
30#define ConnectionUpdateInterval 1000 /* milliseconds */ 31#define ConnectionUpdateInterval 1000 /* milliseconds */
31 32
33#ifdef SAMPLE_BATTERY
34#ifndef BATTERY_LEVEL_PIN
35# define BATTERY_LEVEL_PIN 7
36#endif
37#endif
38
32static struct { 39static struct {
33 bool is_connected; 40 bool is_connected;
34 bool initialized; 41 bool initialized;
@@ -631,15 +638,10 @@ void adafruit_ble_task(void) {
631 } 638 }
632 639
633#ifdef SAMPLE_BATTERY 640#ifdef SAMPLE_BATTERY
634 // I don't know if this really does anything useful yet; the reported
635 // voltage level always seems to be around 3200mV. We may want to just rip
636 // this code out.
637 if (timer_elapsed(state.last_battery_update) > BatteryUpdateInterval && resp_buf.empty()) { 641 if (timer_elapsed(state.last_battery_update) > BatteryUpdateInterval && resp_buf.empty()) {
638 state.last_battery_update = timer_read(); 642 state.last_battery_update = timer_read();
639 643
640 if (at_command_P(PSTR("AT+HWVBAT"), resbuf, sizeof(resbuf))) { 644 state.vbat = analogRead(BATTERY_LEVEL_PIN);
641 state.vbat = atoi(resbuf);
642 }
643 } 645 }
644#endif 646#endif
645} 647}