]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/handwired/promethium/promethium.c
Merge branch 'master' into layouts/adam-lee
[qmk_firmware.git] / keyboards / handwired / promethium / promethium.c
1 #include "promethium.h"
2 #include "analog.h"
3 #include "timer.h"
4 #include "matrix.h"
5
6 // 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}
7
8 uint8_t battery_level(void) {
9     float voltage = analogRead(BATTERY_PIN) * 2 * 3.3 / 1024;
10     if (voltage < MIN_VOLTAGE) return 0;
11     if (voltage > MAX_VOLTAGE) return 255;
12     return (voltage - MIN_VOLTAGE) / (MAX_VOLTAGE - MIN_VOLTAGE) * 255;
13 }
14
15 __attribute__ ((weak))
16 void battery_poll(uint8_t level) {
17 }
18
19 void matrix_init_kb(void) {
20         matrix_init_user();
21 }
22
23 void matrix_scan_kb(void) {
24     static uint16_t counter = BATTERY_POLL;
25     counter++;
26
27     if (counter > BATTERY_POLL) {
28         counter = 0;
29         battery_poll(battery_level());
30     }
31
32     matrix_scan_user();
33 }
34
35 void led_set_kb(uint8_t usb_led) {
36     led_set_user(usb_led);
37 }
38
39 __attribute__ ((weak))
40 void led_set_user(uint8_t usb_led) {
41 }
42