qmk_firmware

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

ap2_led.h (3714B)


      1  /* Copyright 2021 OpenAnnePro community
      2   *
      3   * This program is free software: you can redistribute it and/or modify
      4   * it under the terms of the GNU General Public License as published by
      5   * the Free Software Foundation, either version 2 of the License, or
      6   * (at your option) any later version.
      7   *
      8   * This program is distributed in the hope that it will be useful,
      9   * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11   * GNU General Public License for more details.
     12   *
     13   * You should have received a copy of the GNU General Public License
     14   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15   */
     16 
     17 #pragma once
     18 
     19 #include "protocol.h"
     20 
     21 // Struct defining an LED and its RGB color components
     22 // Compatible with Shine firmware.
     23 typedef union {
     24     struct {
     25         /* Little endian ordering to match uint32_t */
     26         uint8_t blue, green, red;
     27         /* Used in mask; nonzero means - use color from mask. */
     28         uint8_t alpha;
     29     } p; /* parts */
     30     /* Parts vector access: 0 - blue, 1 - green, 2 - red */
     31     uint8_t pv[4];
     32     /* 0xrgb in mem is b g r a */
     33     uint32_t rgb;
     34 } ap2_led_t;
     35 
     36 #define ROWCOL2IDX(row, col) (NUM_COLUMN * (row) + (col))
     37 #define NUM_COLUMN 14
     38 #define NUM_ROW 5
     39 #define KEY_COUNT 70
     40 
     41 /* Local copy of led_mask, used to override colors on the board */
     42 extern ap2_led_t led_mask[KEY_COUNT];
     43 extern ap2_led_t led_colors[KEY_COUNT];
     44 
     45 /* Handle incoming messages */
     46 extern void led_command_callback(const message_t *msg);
     47 
     48 void ap2_set_IAP(void);
     49 void ap2_led_disable(void);
     50 void ap2_led_enable(void);
     51 void ap2_led_set_profile(uint8_t prof);
     52 void ap2_led_next_profile(void);
     53 void ap2_led_prev_profile(void);
     54 void ap2_led_next_intensity(void);
     55 void ap2_led_next_animation_speed(void);
     56 void ap2_led_forward_keypress(uint8_t row, uint8_t col);
     57 
     58 /* Set single key to a given color; alpha controls which is displayed */
     59 void ap2_led_mask_set_key(uint8_t row, uint8_t col, ap2_led_t color);
     60 /* Push a whole local row to the shine */
     61 void ap2_led_mask_set_row(uint8_t row);
     62 /* Synchronize all rows */
     63 void ap2_led_mask_set_all(void);
     64 
     65 /* Set all keys to a given color */
     66 void ap2_led_mask_set_mono(ap2_led_t color);
     67 
     68 /* Set single key to a given color; alpha controls which is displayed */
     69 void ap2_led_colors_set_key(uint8_t row, uint8_t col, ap2_led_t color);
     70 /* Push a whole local row to the shine */
     71 void ap2_led_colors_set_row(uint8_t row);
     72 /* Synchronize all rows */
     73 void ap2_led_colors_set_all(void);
     74 
     75 /* Set all keys to a given color */
     76 void ap2_led_colors_set_mono(ap2_led_t color);
     77 
     78 void ap2_led_set_manual_control(uint8_t manual);
     79 
     80 /* Blink given key `count` times by masking it with a `color`. Blink takes `hundredths` of a second */
     81 void ap2_led_blink(uint8_t row, uint8_t col, ap2_led_t color, uint8_t count, uint8_t hundredths);
     82 
     83 /* Kept for compatibility, but implemented using masks */
     84 void ap2_led_set_foreground_color(uint8_t red, uint8_t green, uint8_t blue);
     85 void ap2_led_reset_foreground_color(void);
     86 
     87 void ap2_led_sticky_set_key(uint8_t row, uint8_t col, ap2_led_t color);
     88 void ap2_led_unset_sticky_key(uint8_t row, uint8_t col);
     89 void ap2_led_unset_sticky_row(uint8_t row);
     90 void ap2_led_unset_sticky_all(void);
     91 
     92 typedef struct {
     93     uint8_t amount_of_profiles;
     94     uint8_t current_profile;
     95     uint8_t matrix_enabled;
     96     uint8_t is_reactive;
     97     uint8_t led_intensity;
     98     uint8_t errors;
     99 } ap2_led_status_t;
    100 
    101 extern ap2_led_status_t ap2_led_status;
    102 
    103 #ifdef RGB_MATRIX_ENABLE
    104 /* RGB driver functions */
    105 void init(void);
    106 void flush(void);
    107 void set_color(int index, uint8_t r, uint8_t g, uint8_t b);
    108 void set_color_all(uint8_t r, uint8_t g, uint8_t b);
    109 #endif