promethium.c 930 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "promethium.h"
  2. #include "analog.h"
  3. #include "timer.h"
  4. #include "matrix.h"
  5. // 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}
  6. uint8_t battery_level(void) {
  7. float voltage = analogRead(BATTERY_PIN) * 2 * 3.3 / 1024;
  8. if (voltage < MIN_VOLTAGE) return 0;
  9. if (voltage > MAX_VOLTAGE) return 255;
  10. return (voltage - MIN_VOLTAGE) / (MAX_VOLTAGE - MIN_VOLTAGE) * 255;
  11. }
  12. __attribute__ ((weak))
  13. void battery_poll(uint8_t level) {
  14. }
  15. void matrix_init_kb(void) {
  16. matrix_init_user();
  17. }
  18. void matrix_scan_kb(void) {
  19. static uint16_t counter = BATTERY_POLL;
  20. counter++;
  21. if (counter > BATTERY_POLL) {
  22. counter = 0;
  23. battery_poll(battery_level());
  24. }
  25. matrix_scan_user();
  26. }
  27. void led_set_kb(uint8_t usb_led) {
  28. led_set_user(usb_led);
  29. }
  30. __attribute__ ((weak))
  31. void led_set_user(uint8_t usb_led) {
  32. }