summaryrefslogtreecommitdiffstats
path: root/keyboards/gmmk/pro
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2022-08-30 03:20:04 -0500
committerGitHub <noreply@github.com>2022-08-30 10:20:04 +0200
commit9632360caa5e6511b0ec13cb4c55eb64408232b5 (patch)
treedb4e0d47fb8d4918a3f7361647a4afca13da23e0 /keyboards/gmmk/pro
parent2c5aa98143fc1bb76299033042b374b2ce148d93 (diff)
Use a macro to compute the size of arrays at compile time (#18044)
* 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>
Diffstat (limited to 'keyboards/gmmk/pro')
-rw-r--r--keyboards/gmmk/pro/rev1/ansi/keymaps/cedrikl/keymap.c21
-rw-r--r--keyboards/gmmk/pro/rev1/ansi/keymaps/gourdo1/keymap.c2
-rw-r--r--keyboards/gmmk/pro/rev1/ansi/keymaps/paddlegame/keymap.c12
-rw-r--r--keyboards/gmmk/pro/rev1/iso/keymaps/chofstede/keymap.c4
-rw-r--r--keyboards/gmmk/pro/rev1/iso/keymaps/gourdo1/keymap.c2
5 files changed, 24 insertions, 17 deletions
diff --git a/keyboards/gmmk/pro/rev1/ansi/keymaps/cedrikl/keymap.c b/keyboards/gmmk/pro/rev1/ansi/keymaps/cedrikl/keymap.c
index 09f8aa147a..3aa3fd828e 100644
--- a/keyboards/gmmk/pro/rev1/ansi/keymaps/cedrikl/keymap.c
+++ b/keyboards/gmmk/pro/rev1/ansi/keymaps/cedrikl/keymap.c
@@ -107,16 +107,22 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// Capslock, Scroll lock and Numlock indicator on Left side lights.
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
- loop_colorset(LED_REGION_A, (sizeof(LED_REGION_A) / sizeof(LED_REGION_A[0])), hsv_cl_blue);
- loop_colorset(LED_REGION_B, (sizeof(LED_REGION_B) / sizeof(LED_REGION_B[0])), hsv_cl_purple);
- loop_colorset(LED_REGION_L_SIDE, (sizeof(LED_REGION_L_SIDE) / sizeof(LED_REGION_L_SIDE[0])), hsv_cl_purple);
- loop_colorset(LED_REGION_R_SIDE, (sizeof(LED_REGION_R_SIDE) / sizeof(LED_REGION_R_SIDE[0])), hsv_cl_purple);
+ loop_colorset(LED_REGION_A, ARRAY_SIZE(LED_REGION_A),
+ hsv_cl_blue);
+ loop_colorset(LED_REGION_B, ARRAY_SIZE(LED_REGION_B),
+ hsv_cl_purple);
+ loop_colorset(LED_REGION_L_SIDE, ARRAY_SIZE(LED_REGION_L_SIDE),
+ hsv_cl_purple);
+ loop_colorset(LED_REGION_R_SIDE, ARRAY_SIZE(LED_REGION_R_SIDE),
+ hsv_cl_purple);
switch(get_highest_layer(layer_state)){ // special handling per layer
case 1: //layer 1
//rgb_matrix_set_color_all(RGB_AZURE);
- loop_colorset(LED_REGION_NUMPAD, (sizeof(LED_REGION_NUMPAD) / sizeof(LED_REGION_NUMPAD[0])), hsv_cl_numpad);
- loop_colorset(LED_REGION_OTHER, (sizeof(LED_REGION_OTHER) / sizeof(LED_REGION_OTHER[0])), hsv_cl_mods);
+ loop_colorset(LED_REGION_NUMPAD,
+ ARRAY_SIZE(LED_REGION_NUMPAD), hsv_cl_numpad);
+ loop_colorset(LED_REGION_OTHER, ARRAY_SIZE(LED_REGION_OTHER),
+ hsv_cl_mods);
break;
default: //layer 0
//
@@ -148,7 +154,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
rgb_matrix_set_color(LED_L6, bad_rgb.r, bad_rgb.g, bad_rgb.b);
rgb_matrix_set_color(LED_L7, bad_rgb.r, bad_rgb.g, bad_rgb.b);
rgb_matrix_set_color(LED_L8, bad_rgb.r, bad_rgb.g, bad_rgb.b);
- loop_colorset(LED_REGION_CAPS, (sizeof(LED_REGION_CAPS) / sizeof(LED_REGION_CAPS[0])), hsv_cl_bad);
+ loop_colorset(LED_REGION_CAPS, ARRAY_SIZE(LED_REGION_CAPS),
+ hsv_cl_bad);
}
}
#endif
diff --git a/keyboards/gmmk/pro/rev1/ansi/keymaps/gourdo1/keymap.c b/keyboards/gmmk/pro/rev1/ansi/keymaps/gourdo1/keymap.c
index ab98693649..9b20399e00 100644
--- a/keyboards/gmmk/pro/rev1/ansi/keymaps/gourdo1/keymap.c
+++ b/keyboards/gmmk/pro/rev1/ansi/keymaps/gourdo1/keymap.c
@@ -538,7 +538,7 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
} else if (paddle_lives == 0) {
// Game over
- for (uint8_t i = 0; i < sizeof(LED_GAME_OVER) / sizeof(LED_GAME_OVER[0]); i++) {
+ for (uint8_t i = 0; i < ARRAY_SIZE(LED_GAME_OVER); i++) {
rgb_matrix_set_color(LED_GAME_OVER[i], RGB_RED);
}
diff --git a/keyboards/gmmk/pro/rev1/ansi/keymaps/paddlegame/keymap.c b/keyboards/gmmk/pro/rev1/ansi/keymaps/paddlegame/keymap.c
index e59db7b984..164ff67e22 100644
--- a/keyboards/gmmk/pro/rev1/ansi/keymaps/paddlegame/keymap.c
+++ b/keyboards/gmmk/pro/rev1/ansi/keymaps/paddlegame/keymap.c
@@ -201,15 +201,15 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
else { ++rgb_value.r; }
}
- for (uint8_t i=0; i<sizeof(LED_RGB)/sizeof(LED_RGB[0]); i++) {
+ for (uint8_t i=0; i<ARRAY_SIZE(LED_RGB); i++) {
rgb_matrix_set_color(LED_RGB[i], rgb_value.r, rgb_value.g, rgb_value.b);
}
- for (uint8_t i=0; i<sizeof(LED_WHITE)/sizeof(LED_WHITE[0]); i++) {
+ for (uint8_t i=0; i<ARRAY_SIZE(LED_WHITE); i++) {
rgb_matrix_set_color(LED_WHITE[i], RGB_WHITE);
}
- for (uint8_t i=0; i<sizeof(LED_GREEN)/sizeof(LED_GREEN[0]); i++) {
+ for (uint8_t i=0; i<ARRAY_SIZE(LED_GREEN); i++) {
rgb_matrix_set_color(LED_GREEN[i], RGB_GREEN);
}
@@ -274,7 +274,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
} else if (paddle_lives == 0) {
// Game over
- for (uint8_t i=0; i<sizeof(LED_GAME_OVER)/sizeof(LED_GAME_OVER[0]); i++) {
+ for (uint8_t i=0; i<ARRAY_SIZE(LED_GAME_OVER); i++) {
rgb_matrix_set_color(LED_GAME_OVER[i], RGB_RED);
}
@@ -439,12 +439,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
rgb_matrix_set_color(LED_CAPS, RGB_WHITE);
if (caps_flash_on) {
- for (uint8_t i=0; i<sizeof(LED_SIDE_LEFT)/sizeof(LED_SIDE_LEFT[0]); i++) {
+ for (uint8_t i=0; i<ARRAY_SIZE(LED_SIDE_LEFT); i++) {
rgb_matrix_set_color(LED_SIDE_LEFT[i], RGB_RED);
rgb_matrix_set_color(LED_SIDE_RIGHT[i], RGB_RED);
}
} else {
- for (uint8_t i=0; i<sizeof(LED_SIDE_LEFT)/sizeof(LED_SIDE_LEFT[0]); i++) {
+ for (uint8_t i=0; i<ARRAY_SIZE(LED_SIDE_LEFT); i++) {
rgb_matrix_set_color(LED_SIDE_LEFT[i], 0, 0, 0);
rgb_matrix_set_color(LED_SIDE_RIGHT[i], 0, 0, 0);
}
diff --git a/keyboards/gmmk/pro/rev1/iso/keymaps/chofstede/keymap.c b/keyboards/gmmk/pro/rev1/iso/keymaps/chofstede/keymap.c
index b28809fdf6..fd941883c5 100644
--- a/keyboards/gmmk/pro/rev1/iso/keymaps/chofstede/keymap.c
+++ b/keyboards/gmmk/pro/rev1/iso/keymaps/chofstede/keymap.c
@@ -84,7 +84,7 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
}
HSV tempHSV = {.h = 0, .s = 255, .v = current_value};
RGB tempRGB = hsv_to_rgb(tempHSV);
- for (uint8_t i = 0; i < sizeof(left_side_leds) / sizeof(left_side_leds[0]); i++) {
+ for (uint8_t i = 0; i < ARRAY_SIZE(left_side_leds); i++) {
rgb_matrix_set_color(left_side_leds[i], tempRGB.r, tempRGB.g, tempRGB.b);
rgb_matrix_set_color(right_side_leds[i], tempRGB.r, tempRGB.g, tempRGB.b);
}
@@ -95,7 +95,7 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
case 2: //layer one
break;
case 1:
- for (uint8_t i = 0; i < sizeof(l2_functions) / sizeof(l2_functions[0]); i++) {
+ for (uint8_t i = 0; i < ARRAY_SIZE(l2_functions); i++) {
RGB_MATRIX_INDICATOR_SET_COLOR(l2_functions[i], 255, 0, 0);
}
break;
diff --git a/keyboards/gmmk/pro/rev1/iso/keymaps/gourdo1/keymap.c b/keyboards/gmmk/pro/rev1/iso/keymaps/gourdo1/keymap.c
index 30e8fc5f44..004a8c2014 100644
--- a/keyboards/gmmk/pro/rev1/iso/keymaps/gourdo1/keymap.c
+++ b/keyboards/gmmk/pro/rev1/iso/keymaps/gourdo1/keymap.c
@@ -551,7 +551,7 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
} else if (paddle_lives == 0) {
// Game over
- for (uint8_t i = 0; i < sizeof(LED_GAME_OVER) / sizeof(LED_GAME_OVER[0]); i++) {
+ for (uint8_t i = 0; i < ARRAY_SIZE(LED_GAME_OVER); i++) {
rgb_matrix_set_color(LED_GAME_OVER[i], RGB_RED);
}