Skip to content

Remove bluefruit_le_read_battery_voltage function #25129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,6 @@ ifeq ($(strip $(BLUETOOTH_ENABLE)), yes)

ifeq ($(strip $(BLUETOOTH_DRIVER)), bluefruit_le)
SPI_DRIVER_REQUIRED = yes
ANALOG_DRIVER_REQUIRED = yes
SRC += $(DRIVER_PATH)/bluetooth/bluetooth.c
SRC += $(DRIVER_PATH)/bluetooth/bluefruit_le.cpp
endif
Expand Down
21 changes: 0 additions & 21 deletions drivers/bluetooth/bluefruit_le.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@
# define BLUEFRUIT_LE_SCK_DIVISOR 2 // 4MHz SCK/8MHz CPU, calculated for Feather 32U4 BLE
#endif

#define SAMPLE_BATTERY
#define ConnectionUpdateInterval 1000 /* milliseconds */

#ifndef BATTERY_LEVEL_PIN
# define BATTERY_LEVEL_PIN B5
#endif

static struct {
bool is_connected;
bool initialized;
Expand All @@ -48,10 +43,6 @@ static struct {
#define UsingEvents 2
bool event_flags;

#ifdef SAMPLE_BATTERY
uint16_t last_battery_update;
uint32_t vbat;
#endif
uint16_t last_connection_update;
} state;

Expand Down Expand Up @@ -549,14 +540,6 @@ void bluefruit_le_task(void) {
set_connected(atoi(resbuf));
}
}

#ifdef SAMPLE_BATTERY
if (timer_elapsed(state.last_battery_update) > BatteryUpdateInterval && resp_buf.empty()) {
state.last_battery_update = timer_read();

state.vbat = analogReadPin(BATTERY_LEVEL_PIN);
}
#endif
}

static bool process_queue_item(struct queue_item *item, uint16_t timeout) {
Expand Down Expand Up @@ -655,10 +638,6 @@ void bluefruit_le_send_mouse(report_mouse_t *report) {
}
}

uint32_t bluefruit_le_read_battery_voltage(void) {
return state.vbat;
}

bool bluefruit_le_set_mode_leds(bool on) {
if (!state.configured) {
return false;
Expand Down
4 changes: 0 additions & 4 deletions drivers/bluetooth/bluefruit_le.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ extern void bluefruit_le_send_consumer(uint16_t usage);
* change. */
extern void bluefruit_le_send_mouse(report_mouse_t *report);

/* Compute battery voltage by reading an analog pin.
* Returns the integer number of millivolts */
extern uint32_t bluefruit_le_read_battery_voltage(void);

extern bool bluefruit_le_set_mode_leds(bool on);
extern bool bluefruit_le_set_power_level(int8_t level);

Expand Down
5 changes: 2 additions & 3 deletions keyboards/handwired/promethium/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define NO_ACTION_ONESHOT

#define PS2_MOUSE_INIT_DELAY 2000
#define BATTERY_POLL 30000
#define MAX_VOLTAGE 4.2
#define MIN_VOLTAGE 3.2

#define BATTERY_PIN B5

#ifndef __ASSEMBLER__ // assembler doesn't like enum in .h file
enum led_sequence {
Expand Down
17 changes: 8 additions & 9 deletions keyboards/handwired/promethium/promethium.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#include "promethium.h"
#include "analog.h"
#include "keyboard.h"
#include "timer.h"
#include "matrix.h"
#include "bluefruit_le.h"
#include "battery.h"

// cubic fit {3.3, 0}, {3.5, 2.9}, {3.6, 5}, {3.7, 8.6}, {3.8, 36}, {3.9, 62}, {4.0, 73}, {4.05, 83}, {4.1, 89}, {4.15, 94}, {4.2, 100}
#ifndef BATTERY_POLL
# define BATTERY_POLL 30000
#endif

uint8_t battery_level(void) {
float voltage = bluefruit_le_read_battery_voltage() * 2 * 3.3 / 1024;
if (voltage < MIN_VOLTAGE) return 0;
if (voltage > MAX_VOLTAGE) return 255;
return (voltage - MIN_VOLTAGE) / (MAX_VOLTAGE - MIN_VOLTAGE) * 255;
// maintain legacy behaviour and scale 0-100 percent to 0-255
uint16_t percent = battery_get_percent();
return (percent * 255) / 100;
}

__attribute__ ((weak))
Expand Down
2 changes: 1 addition & 1 deletion keyboards/handwired/promethium/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PS2_DRIVER = interrupt
CUSTOM_MATRIX = yes

WS2812_DRIVER_REQUIRED = yes
ANALOG_DRIVER_REQUIRED = yes
BATTERY_DRIVER_REQUIRED = yes

SRC += rgbsps.c
SRC += matrix.c
1 change: 0 additions & 1 deletion keyboards/matrix/falcon/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@
//pin setting
#define LED_POWER_PIN D5
#define CHG_EN_PIN E6
#define BATTERY_LEVEL_PIN F0
18 changes: 0 additions & 18 deletions keyboards/tokyokeyboard/alix40/config.h

This file was deleted.

Loading