forked from forks/qmk_firmware
9632360caa
* Add ARRAY_SIZE and CEILING utility macros * Apply a coccinelle patch to use ARRAY_SIZE * fix up some straggling items * Fix 'make test:secure' * Enhance ARRAY_SIZE macro to reject acting on pointers The previous definition would not produce a diagnostic for ``` int *p; size_t num_elem = ARRAY_SIZE(p) ``` but the new one will. * explicitly get definition of ARRAY_SIZE * Convert to ARRAY_SIZE when const is involved The following spatch finds additional instances where the array is const and the division is by the size of the type, not the size of the first element: ``` @ rule5a using "empty.iso" @ type T; const T[] E; @@ - (sizeof(E)/sizeof(T)) + ARRAY_SIZE(E) @ rule6a using "empty.iso" @ type T; const T[] E; @@ - sizeof(E)/sizeof(T) + ARRAY_SIZE(E) ``` * New instances of ARRAY_SIZE added since initial spatch run * Use `ARRAY_SIZE` in docs (found by grep) * Manually use ARRAY_SIZE hs_set is expected to be the same size as uint16_t, though it's made of two 8-bit integers * Just like char, sizeof(uint8_t) is guaranteed to be 1 This is at least true on any plausible system where qmk is actually used. Per my understanding it's universally true, assuming that uint8_t exists: https://stackoverflow.com/questions/48655310/can-i-assume-that-sizeofuint8-t-1 * Run qmk-format on core C files touched in this branch Co-authored-by: Stefan Kerkmann <karlk90@pm.me>
136 lines
6.4 KiB
C
136 lines
6.4 KiB
C
/* Copyright 2020 RGBKB
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#include "pan.h"
|
|
#include "quantum.h"
|
|
#include "rgb_matrix_types.h"
|
|
|
|
#if defined RGB_MATRIX_ENABLE
|
|
# if defined(KEYBOARD_rgbkb_pan_rev1)
|
|
# include "ws2812.h"
|
|
|
|
// LED color buffer
|
|
LED_TYPE rgb_matrix_ws2812_array[DRIVER_LED_TOTAL];
|
|
|
|
static void init(void) {}
|
|
|
|
static void flush(void) {
|
|
// Assumes use of RGB_DI_PIN
|
|
ws2812_setleds(rgb_matrix_ws2812_array, DRIVER_LED_TOTAL);
|
|
}
|
|
|
|
// Set an led in the buffer to a color
|
|
static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) {
|
|
# if defined(RGB_ENCODERS) || defined(STAGGERED_RGB_ENCODERS)
|
|
if (i == 0 || i == 1) { // if encoder LEDs, change LEDs
|
|
rgb_matrix_ws2812_array[i].r = g;
|
|
rgb_matrix_ws2812_array[i].g = b;
|
|
rgb_matrix_ws2812_array[i].b = r;
|
|
} else
|
|
# endif
|
|
{
|
|
rgb_matrix_ws2812_array[i].r = r;
|
|
rgb_matrix_ws2812_array[i].g = g;
|
|
rgb_matrix_ws2812_array[i].b = b;
|
|
}
|
|
# ifdef RGBW
|
|
convert_rgb_to_rgbw(&rgb_matrix_ws2812_array[i]);
|
|
# endif
|
|
}
|
|
|
|
static void setled_all(uint8_t r, uint8_t g, uint8_t b) {
|
|
for (int i = 0; i < ARRAY_SIZE(rgb_matrix_ws2812_array); i++) {
|
|
setled(i, r, g, b);
|
|
}
|
|
}
|
|
|
|
const rgb_matrix_driver_t rgb_matrix_driver = {
|
|
.init = init,
|
|
.flush = flush,
|
|
.set_color = setled,
|
|
.set_color_all = setled_all,
|
|
};
|
|
# endif
|
|
|
|
// clang-format off
|
|
led_config_t g_led_config = { {
|
|
{ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 },
|
|
{ 0, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15 },
|
|
{ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 1 },
|
|
{ 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40 },
|
|
{ 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, NO_LED }
|
|
}, {
|
|
# ifdef STAGGERED_RGB_ENCODERS
|
|
{0, -19},{228, -19},
|
|
{0, 0}, {14, 0}, {33, 0}, {52, 0}, {71, 0}, {90, 0}, {109, 0}, {128, 0}, {147, 0}, {166, 0}, {185, 0}, {204, 0}, {223, 0},
|
|
{209, 19}, {190, 19}, {171, 19}, {152, 19}, {133, 19}, {114, 19}, {95, 19}, {76, 19}, {57, 19}, {38, 19}, {19, 19}, {0, 19},
|
|
{0, 38}, {19, 38}, {38, 38}, {57, 38}, {76, 38}, {95, 38}, {114, 38}, {133, 38}, {152, 38}, {171, 38}, {190, 38}, {209, 38},
|
|
{223, 57}, {204, 57}, {185, 57}, {171, 57}, {147, 57}, {128, 57}, {109, 57}, {90, 57}, {71, 57}, {52, 57}, {33, 57}, {14, 57}, {0, 57},
|
|
{0, 76}, {19, 76}, {38, 76}, {57, 76}, {76, 76}, {95, 76}, {114, 76}, {133, 76}, {152, 76}, {171, 76}, {190, 76}, {209, 76},
|
|
# elif defined RGB_ENCODERS
|
|
{0, -19},{228, -19},
|
|
{0, 0}, {19, 0}, {38, 0}, {57, 0}, {76, 0}, {95, 0}, {114, 0}, {133, 0}, {152, 0}, {171, 0}, {190, 0}, {209, 0},
|
|
{209, 19}, {190, 19}, {171, 19}, {152, 19}, {133, 19}, {114, 19}, {95, 19}, {76, 19}, {57, 19}, {38, 19}, {19, 19}, {0, 19},
|
|
{0, 38}, {19, 38}, {38, 38}, {57, 38}, {76, 38}, {95, 38}, {114, 38}, {133, 38}, {152, 38}, {171, 38}, {190, 38}, {209, 38},
|
|
{209, 57}, {190, 57}, {171, 57}, {152, 57}, {133, 57}, {114, 57}, {95, 57}, {76, 57}, {57, 57}, {38, 57}, {19, 57}, {0, 57},
|
|
{0, 76}, {19, 76}, {38, 76}, {57, 76}, {76, 76}, {95, 76}, {114, 76}, {133, 76}, {152, 76}, {171, 76}, {190, 76}, {209, 76},
|
|
{0, 95},{19, 95}, //not used
|
|
# elif defined STAGGERED_LAYOUT
|
|
{0, 0}, {19, 0}, {38, 0}, {57, 0}, {76, 0}, {95, 0}, {114, 0}, {133, 0}, {152, 0}, {171, 0}, {190, 0}, {209, 0}, {0, 0},
|
|
{209, 19}, {190, 19}, {171, 19}, {152, 19}, {133, 19}, {114, 19}, {95, 19}, {76, 19}, {57, 19}, {38, 19}, {19, 19}, {0, 19},
|
|
{0, 38}, {19, 38}, {38, 38}, {57, 38}, {76, 38}, {95, 38}, {114, 38}, {133, 38}, {152, 38}, {171, 38}, {190, 38}, {209, 38},
|
|
{209, 57}, {190, 57}, {171, 57}, {152, 57}, {133, 57}, {114, 57}, {95, 57}, {76, 57}, {57, 57}, {38, 57}, {19, 57}, {0, 57}, {0, 0},
|
|
{0, 76}, {19, 76}, {38, 76}, {57, 76}, {76, 76}, {95, 76}, {114, 76}, {133, 76}, {152, 76}, {171, 76}, {190, 76}, {209, 76},
|
|
{0, 95},{19, 95},//not used
|
|
# else
|
|
{0, 0}, {19, 0}, {38, 0}, {57, 0}, {76, 0}, {95, 0}, {114, 0}, {133, 0}, {152, 0}, {171, 0}, {190, 0}, {209, 0},
|
|
{209, 19}, {190, 19}, {171, 19}, {152, 19}, {133, 19}, {114, 19}, {95, 19}, {76, 19}, {57, 19}, {38, 19}, {19, 19}, {0, 19},
|
|
{0, 38}, {19, 38}, {38, 38}, {57, 38}, {76, 38}, {95, 38}, {114, 38}, {133, 38}, {152, 38}, {171, 38}, {190, 38}, {209, 38},
|
|
{209, 57}, {190, 57}, {171, 57}, {152, 57}, {133, 57}, {114, 57}, {95, 57}, {76, 57}, {57, 57}, {38, 57}, {19, 57}, {0, 57},
|
|
{0, 76}, {19, 76}, {38, 76}, {57, 76}, {76, 76}, {95, 76}, {114, 76}, {133, 76}, {152, 76}, {171, 76}, {190, 76}, {209, 76},
|
|
{0, 0},{0, 0}, {0, 0},{0, 0},//not used
|
|
# endif
|
|
}, {
|
|
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