qmk_firmware

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

rgb_driver.c (1786B)


      1 /* Copyright 2022 Jose Pablo Ramirez <jp.ramangulo@gmail.com>
      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 #ifdef RGB_MATRIX_ENABLE
     18 
     19 #    include "rgb_matrix.h"
     20 #    include "ap2_led.h"
     21 
     22 uint8_t led_pos[RGB_MATRIX_LED_COUNT];
     23 
     24 void init(void) {
     25     unsigned int i = 0;
     26     for (unsigned int y = 0; y < NUM_ROW; y++) {
     27         for (unsigned int x = 0; x < NUM_COLUMN; x++) {
     28             if (g_led_config.matrix_co[y][x] != NO_LED) {
     29                 led_pos[g_led_config.matrix_co[y][x]] = i;
     30             }
     31             i++;
     32         }
     33     }
     34 }
     35 
     36 void flush(void) {
     37     for (uint8_t row = 0; row < NUM_ROW; row++)
     38         ap2_led_colors_set_row(row);
     39 }
     40 
     41 void set_color(int index, uint8_t r, uint8_t g, uint8_t b) {
     42     led_colors[led_pos[index]] = (ap2_led_t){
     43         .p.blue  = b,
     44         .p.red   = r,
     45         .p.green = g,
     46         .p.alpha = 0xff,
     47     };
     48 }
     49 
     50 void set_color_all(uint8_t r, uint8_t g, uint8_t b) {
     51     for (int i = 0; i < RGB_MATRIX_LED_COUNT; i++)
     52         set_color(i, r, g, b);
     53 }
     54 
     55 const rgb_matrix_driver_t rgb_matrix_driver = {
     56     .init          = init,
     57     .flush         = flush,
     58     .set_color     = set_color,
     59     .set_color_all = set_color_all,
     60 };
     61 
     62 #endif