summaryrefslogtreecommitdiffstats
path: root/keyboards/keychron/bluetooth/battery.h
blob: 45de2bc23a8a8ae0163efbf5d9de068eb881f84b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Copyright 2022 @ lokher (https://www.keychron.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

enum {
    BAT_NOT_CHARGING = 0,
    BAT_CHARGING,
    BAT_CHARGING_FINISHED,
};

#ifndef FULL_VOLTAGE_VALUE
#    define FULL_VOLTAGE_VALUE 4100
#endif

#ifndef EMPTY_VOLTAGE_VALUE
#    define EMPTY_VOLTAGE_VALUE 3500
#endif

#ifndef SHUTDOWN_VOLTAGE_VALUE
#    define SHUTDOWN_VOLTAGE_VALUE 3300
#endif

#ifndef VOLTAGE_MEASURE_INTERVAL
#    define VOLTAGE_MEASURE_INTERVAL 3000
#endif

#ifndef VOLTAGE_POWER_ON_MEASURE_COUNT
#    define VOLTAGE_POWER_ON_MEASURE_COUNT 15
#endif

#ifndef BACKLIGHT_OFF_VOLTAGE_MEASURE_INTERVAL
#    define BACKLIGHT_OFF_VOLTAGE_MEASURE_INTERVAL 200
#endif

void battery_init(void);
void battery_measure(void);
void     battery_calculte_voltage(uint16_t value);
void     battery_set_voltage(uint16_t value);
uint16_t battery_get_voltage(void);
uint8_t battery_get_percentage(void);
void indicator_battery_low_enable(bool enable);
bool battery_is_empty(void);
bool battery_is_critical_low(void);
bool     battery_power_on_sample(void);

void battery_task(void);