qmk_firmware

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

abelx.c (2986B)


      1 /**
      2  * abelx.c
      3  *
      4  * Copyright 2020 astro <yuleiz@gmail.com>
      5  *
      6  * This program is free software: you can redistribute it and/or modify
      7  * it under the terms of the GNU General Public License as published by
      8  * the Free Software Foundation, either version 2 of the License, or
      9  * (at your option) any later version.
     10  *
     11  * This program is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  * GNU General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU General Public License
     17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     18  */
     19 
     20 #include "abelx.h"
     21 #include "tca6424.h"
     22 #include "aw9523b.h"
     23 
     24 void set_pin(uint16_t pin)
     25 {
     26     uint8_t data = tca6424_read_port(GET_PORT(pin));
     27     data |= ( 1 << GET_PIN(pin));
     28     tca6424_write_port(GET_PORT(pin), data);
     29 }
     30 
     31 void clear_pin(uint16_t pin)
     32 {
     33     uint8_t data = tca6424_read_port(GET_PORT(pin));
     34     data &= ~( 1 << GET_PIN(pin));
     35     tca6424_write_port(GET_PORT(pin), data);
     36 }
     37 
     38 uint8_t read_pin(uint16_t pin)
     39 {
     40     uint8_t data = tca6424_read_port(GET_PORT(pin));
     41     return (data & (1<<GET_PIN(pin))) ? 1 : 0;
     42 }
     43 
     44 #ifdef RGBLIGHT_ENABLE
     45 #include "rgblight.h"
     46 #include "ws2812.h"
     47 #include "i2c_master.h"
     48 
     49 const aw9523b_led g_aw9523b_leds[AW9523B_RGB_NUM] = {
     50     {AW9523B_P12_PWM, AW9523B_P11_PWM, AW9523B_P10_PWM},
     51     {AW9523B_P01_PWM, AW9523B_P00_PWM, AW9523B_P13_PWM},
     52     {AW9523B_P04_PWM, AW9523B_P03_PWM, AW9523B_P02_PWM},
     53     {AW9523B_P07_PWM, AW9523B_P06_PWM, AW9523B_P05_PWM},
     54 };
     55 
     56 void init_custom(void) {
     57     aw9523b_init(AW9523B_ADDR);
     58     ws2812_init();
     59 }
     60 
     61 void set_color_custom(int index, uint8_t red, uint8_t green, uint8_t blue) {
     62     if (index < AW9523B_RGB_NUM) {
     63         aw9523b_set_color(index, red, green, blue);
     64     } else {
     65         ws2812_set_color(index - AW9523B_RGB_NUM, red, green, blue);
     66     }
     67 }
     68 
     69 void set_color_all_custom(uint8_t red, uint8_t green, uint8_t blue) {
     70     for (int i = 0; i < RGBLIGHT_LED_COUNT; i++) {
     71         set_color_custom(i, red, green, blue);
     72     }
     73 }
     74 
     75 void flush_custom(void) {
     76     aw9523b_update_pwm_buffers(AW9523B_ADDR);
     77     ws2812_flush();
     78 }
     79 
     80 const rgblight_driver_t rgblight_driver = {
     81     .init          = init_custom,
     82     .set_color     = set_color_custom,
     83     .set_color_all = set_color_all_custom,
     84     .flush         = flush_custom,
     85 };
     86 
     87 #endif
     88 
     89 static uint16_t caps_lock_pin = DEF_PIN(TCA6424_PORT2, 3);
     90 static uint16_t scroll_lock_pin = DEF_PIN(TCA6424_PORT0, 0);
     91 
     92 bool led_update_kb(led_t led_state) {
     93     bool res = led_update_user(led_state);
     94     if (res) {
     95         led_state.caps_lock ? set_pin(caps_lock_pin) : clear_pin(caps_lock_pin);
     96         led_state.scroll_lock ? set_pin(scroll_lock_pin) : clear_pin(scroll_lock_pin);
     97     }
     98     return res;
     99 }
    100 
    101 #define REBOOT_MAGIC 0x41544B42
    102 
    103 void bootloader_jump(void) {
    104     *(uint32_t *)(&(RTCD1.rtc->BKP0R)) = REBOOT_MAGIC;
    105     NVIC_SystemReset();
    106 }