You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

  1. /**
  2. * m20add.c
  3. */
  4. #include "m20add.h"
  5. #include "tca6424.h"
  6. #include "rgb_ring.h"
  7. #include "i2c_master.h"
  8. void set_pin(uint16_t pin)
  9. {
  10. uint8_t data = tca6424_read_port(GET_PORT(pin));
  11. data |= ( 1 << GET_PIN(pin));
  12. tca6424_write_port(GET_PORT(pin), data);
  13. }
  14. void clear_pin(uint16_t pin)
  15. {
  16. uint8_t data = tca6424_read_port(GET_PORT(pin));
  17. data &= ~( 1 << GET_PIN(pin));
  18. tca6424_write_port(GET_PORT(pin), data);
  19. }
  20. uint8_t read_pin(uint16_t pin)
  21. {
  22. uint8_t data = tca6424_read_port(GET_PORT(pin));
  23. return (data & (1<<GET_PIN(pin))) ? 1 : 0;
  24. }
  25. void matrix_init_kb(void) {
  26. #ifdef RGBLIGHT_ENABLE
  27. rgb_ring_init();
  28. #endif
  29. matrix_init_user();
  30. }
  31. void matrix_scan_kb(void) {
  32. #ifdef RGBLIGHT_ENABLE
  33. rgb_ring_task();
  34. #endif
  35. matrix_scan_user();
  36. }
  37. static uint16_t caps_lock_pin = DEF_PIN(TCA6424_PORT2, 3);
  38. static uint16_t scroll_lock_pin = DEF_PIN(TCA6424_PORT0, 1);
  39. bool led_update_kb(led_t led_state) {
  40. bool res = led_update_user(led_state);
  41. if (res) {
  42. led_state.caps_lock ? set_pin(caps_lock_pin) : clear_pin(caps_lock_pin);
  43. led_state.scroll_lock ? set_pin(scroll_lock_pin) : clear_pin(scroll_lock_pin);
  44. }
  45. return res;
  46. }
  47. #define REBOOT_MAGIC 0x41544B42
  48. void bootloader_jump(void) {
  49. // set the magic number for resetting to the bootloader
  50. *(uint32_t *)(&(RTCD1.rtc->BKP0R)) = REBOOT_MAGIC;
  51. NVIC_SystemReset();
  52. }