qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

m20add.c (1277B)


      1 /**
      2  * m20add.c
      3  */
      4 
      5 #include "m20add.h"
      6 #include "tca6424.h"
      7 #include "rgb_ring.h"
      8 #include "i2c_master.h"
      9 
     10 void set_pin(uint16_t pin)
     11 {
     12     uint8_t data = tca6424_read_port(GET_PORT(pin));
     13     data |= ( 1 << GET_PIN(pin));
     14     tca6424_write_port(GET_PORT(pin), data);
     15 }
     16 
     17 void clear_pin(uint16_t pin)
     18 {
     19     uint8_t data = tca6424_read_port(GET_PORT(pin));
     20     data &= ~( 1 << GET_PIN(pin));
     21     tca6424_write_port(GET_PORT(pin), data);
     22 }
     23 
     24 uint8_t read_pin(uint16_t pin)
     25 {
     26     uint8_t data = tca6424_read_port(GET_PORT(pin));
     27     return (data & (1<<GET_PIN(pin))) ? 1 : 0;
     28 }
     29 
     30 void housekeeping_task_kb(void) {
     31 #ifdef RGBLIGHT_ENABLE
     32     rgb_ring_task();
     33 #endif
     34 }
     35 
     36 static uint16_t caps_lock_pin = DEF_PIN(TCA6424_PORT2, 3);
     37 static uint16_t scroll_lock_pin = DEF_PIN(TCA6424_PORT0, 1);
     38 
     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 
     48 #define REBOOT_MAGIC 0x41544B42
     49 
     50 void bootloader_jump(void) {
     51     // set the magic number for resetting to the bootloader
     52     *(uint32_t *)(&(RTCD1.rtc->BKP0R)) = REBOOT_MAGIC;
     53     NVIC_SystemReset();
     54 }