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>
This commit is contained in:
@@ -333,7 +333,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
aqours_num++;
|
||||
aqours_next_color_timer_count = 0;
|
||||
target_col = 0;
|
||||
if (aqours_num == sizeof(aqours_h) / sizeof(int)) {
|
||||
if (aqours_num == ARRAY_SIZE(aqours_h)) {
|
||||
aqours_num = 0;
|
||||
}
|
||||
}
|
||||
|
@@ -94,7 +94,7 @@ encoder_mode_t encoder_modes[] = {
|
||||
// Insert your custom encoder mode here
|
||||
};
|
||||
|
||||
#define NUM_ENCODER_MODES (sizeof(encoder_modes)/sizeof(encoder_modes[0]))
|
||||
#define NUM_ENCODER_MODES ARRAY_SIZE(encoder_modes)
|
||||
|
||||
// This counter is used to track what encoder mode is being used at a certain time
|
||||
int encoder_mode_count = 0;
|
||||
|
@@ -94,8 +94,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#define OLED_ALL_BLOCKS_MASK (((((OLED_BLOCK_TYPE)1 << (OLED_BLOCK_COUNT - 1)) - 1) << 1) | 1)
|
||||
|
||||
#define ARRAY_SIZE(arr) sizeof(arr)/sizeof(arr[0])
|
||||
|
||||
// spi defines
|
||||
#define OLED_STATUS_SUCCESS SPI_STATUS_SUCCESS
|
||||
|
||||
|
@@ -176,7 +176,7 @@ void add_keylog(uint16_t keycode) {
|
||||
keylog_str[i] = keylog_str[i - 1];
|
||||
}
|
||||
|
||||
if (keycode < (sizeof(code_to_name) / sizeof(char))) {
|
||||
if (keycode < ARRAY_SIZE(code_to_name)) {
|
||||
keylog_str[0] = pgm_read_byte(&code_to_name[keycode]);
|
||||
}
|
||||
}
|
||||
|
@@ -189,7 +189,7 @@ void add_keylog(uint16_t keycode) {
|
||||
keylog_str[i] = keylog_str[i - 1];
|
||||
}
|
||||
|
||||
if (keycode < (sizeof(code_to_name) / sizeof(char))) {
|
||||
if (keycode < ARRAY_SIZE(code_to_name)) {
|
||||
keylog_str[0] = pgm_read_byte(&code_to_name[keycode]);
|
||||
}
|
||||
}
|
||||
|
@@ -242,7 +242,7 @@ layer_state_t layer_state_set_user(layer_state_t state) {
|
||||
void led_keypress_update(uint8_t led, uint8_t led_mode, uint16_t keycode, keyrecord_t *record) {
|
||||
switch (led_mode) {
|
||||
case LEDMODE_MODS:
|
||||
for (int i=0;i<sizeof(modifiers) / sizeof(modifiers[0]);i++) {
|
||||
for (int i=0;i<ARRAY_SIZE(modifiers);i++) {
|
||||
if(keycode==modifiers[i]) {
|
||||
if (record->event.pressed) {
|
||||
writePinHigh(led);
|
||||
|
@@ -245,7 +245,7 @@ layer_state_t layer_state_set_user(layer_state_t state) {
|
||||
void led_keypress_update(uint8_t led, uint8_t led_mode, uint16_t keycode, keyrecord_t *record) {
|
||||
switch (led_mode) {
|
||||
case LEDMODE_MODS:
|
||||
for (int i=0;i<sizeof(modifiers) / sizeof(modifiers[0]);i++) {
|
||||
for (int i=0;i<ARRAY_SIZE(modifiers);i++) {
|
||||
if(keycode==modifiers[i]) {
|
||||
if (record->event.pressed) {
|
||||
writePinHigh(led);
|
||||
|
@@ -184,7 +184,7 @@ layer_state_t layer_state_set_user(layer_state_t state) {
|
||||
void led_keypress_update(uint8_t led, uint8_t led_mode, uint16_t keycode, keyrecord_t *record) {
|
||||
switch (led_mode) {
|
||||
case LEDMODE_MODS:
|
||||
for (int i=0;i<sizeof(modifiers) / sizeof(modifiers[0]);i++) {
|
||||
for (int i=0;i<ARRAY_SIZE(modifiers);i++) {
|
||||
if(keycode==modifiers[i]) {
|
||||
if (record->event.pressed) {
|
||||
writePinHigh(led);
|
||||
|
@@ -111,7 +111,7 @@ const rgblight_segment_t *const PROGMEM _rgb_layers[] = {
|
||||
};
|
||||
// clang-format off
|
||||
|
||||
const uint8_t PROGMEM _n_rgb_layers = sizeof(_rgb_layers) / sizeof(_rgb_layers[0]) - 1;
|
||||
const uint8_t PROGMEM _n_rgb_layers = ARRAY_SIZE(_rgb_layers) - 1;
|
||||
|
||||
void clear_rgb_layers(void) {
|
||||
dprint("clear_rgb_layers()\n");
|
||||
|
@@ -129,7 +129,7 @@ const encoder_mode_t encoder_modes[] = {
|
||||
// Insert your custom encoder mode here
|
||||
};
|
||||
|
||||
#define NUM_ENCODER_MODES (sizeof(encoder_modes)/sizeof(encoder_modes[0])) // DO NOT CHANGE THIS. NUM_ENCODER_MODES calculates how many modes there are.
|
||||
#define NUM_ENCODER_MODES ARRAY_SIZE(encoder_modes) // DO NOT CHANGE THIS. NUM_ENCODER_MODES calculates how many modes there are.
|
||||
|
||||
// This counter is used to track what encoder mode is being used at a certain time
|
||||
int encoder_mode_count = 0;
|
||||
|
@@ -180,4 +180,4 @@ uint32_t processQwerty(bool lookup) {
|
||||
}
|
||||
|
||||
// Don't fuck with this, thanks.
|
||||
size_t keymapsCount = sizeof(keymaps)/sizeof(keymaps[0]);
|
||||
size_t keymapsCount = ARRAY_SIZE(keymaps);
|
||||
|
@@ -21,7 +21,7 @@ uint32_t tChord = 0; // Protects state of cChord
|
||||
|
||||
#ifndef STENOLAYERS
|
||||
uint32_t stenoLayers[] = { PWR };
|
||||
size_t stenoLayerCount = sizeof(stenoLayers)/sizeof(stenoLayers[0]);
|
||||
size_t stenoLayerCount = ARRAY_SIZE(stenoLayers);
|
||||
#endif
|
||||
|
||||
// Mode state
|
||||
|
@@ -114,8 +114,8 @@ void testCollisions(void) {
|
||||
#include "dicts.def"
|
||||
|
||||
// Get size data back into the engine
|
||||
size_t funcsLen = sizeof(funDict) / sizeof(funDict[0]);
|
||||
size_t stringLen = sizeof(strDict) / sizeof(strDict[0]);
|
||||
size_t keyLen = sizeof(keyDict) / sizeof(keyDict[0]);
|
||||
size_t comboLen = sizeof(cmbDict) / sizeof(cmbDict[0]);
|
||||
size_t specialLen = sizeof(spcDict) / sizeof(spcDict[0]);
|
||||
size_t funcsLen = ARRAY_SIZE(funDict);
|
||||
size_t stringLen = ARRAY_SIZE(strDict);
|
||||
size_t keyLen = ARRAY_SIZE(keyDict);
|
||||
size_t comboLen = ARRAY_SIZE(cmbDict);
|
||||
size_t specialLen = ARRAY_SIZE(spcDict);
|
||||
|
@@ -115,8 +115,8 @@ void testCollisions(void) {
|
||||
#include "dicts.def"
|
||||
|
||||
// Get size data back into the engine
|
||||
size_t funcsLen = sizeof(funDict) / sizeof(funDict[0]);
|
||||
size_t stringLen = sizeof(strDict) / sizeof(strDict[0]);
|
||||
size_t keyLen = sizeof(keyDict) / sizeof(keyDict[0]);
|
||||
size_t comboLen = sizeof(cmbDict) / sizeof(cmbDict[0]);
|
||||
size_t specialLen = sizeof(spcDict) / sizeof(spcDict[0]);
|
||||
size_t funcsLen = ARRAY_SIZE(funDict);
|
||||
size_t stringLen = ARRAY_SIZE(strDict);
|
||||
size_t keyLen = ARRAY_SIZE(keyDict);
|
||||
size_t comboLen = ARRAY_SIZE(cmbDict);
|
||||
size_t specialLen = ARRAY_SIZE(spcDict);
|
||||
|
@@ -302,5 +302,5 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
};
|
||||
|
||||
// Don't fuck with this, thanks.
|
||||
size_t keymapsCount = sizeof(keymaps)/sizeof(keymaps[0]);
|
||||
size_t stenoLayerCount = sizeof(stenoLayers)/sizeof(stenoLayers[0]);
|
||||
size_t keymapsCount = ARRAY_SIZE(keymaps);
|
||||
size_t stenoLayerCount = ARRAY_SIZE(stenoLayers);
|
||||
|
@@ -234,4 +234,4 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
};
|
||||
|
||||
// Don't fuck with this, thanks.
|
||||
size_t keymapsCount = sizeof(keymaps)/sizeof(keymaps[0]);
|
||||
size_t keymapsCount = ARRAY_SIZE(keymaps);
|
||||
|
@@ -244,4 +244,4 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
};
|
||||
|
||||
// Don't fuck with this, thanks.
|
||||
size_t keymapsCount = sizeof(keymaps)/sizeof(keymaps[0]);
|
||||
size_t keymapsCount = ARRAY_SIZE(keymaps);
|
||||
|
@@ -219,4 +219,4 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
)
|
||||
};
|
||||
// Don't fuck with this, thanks.
|
||||
size_t keymapsCount = sizeof(keymaps)/sizeof(keymaps[0]);
|
||||
size_t keymapsCount = ARRAY_SIZE(keymaps);
|
||||
|
@@ -263,4 +263,4 @@ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGDN, KC_LEFT, KC
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS)
|
||||
};
|
||||
// Don't fuck with this, thanks.
|
||||
size_t keymapsCount = sizeof(keymaps)/sizeof(keymaps[0]);
|
||||
size_t keymapsCount = ARRAY_SIZE(keymaps);
|
||||
|
@@ -21,7 +21,7 @@ uint32_t tChord = 0; // Protects state of cChord
|
||||
|
||||
#ifndef STENOLAYERS
|
||||
uint32_t stenoLayers[] = { PWR };
|
||||
size_t stenoLayerCount = sizeof(stenoLayers)/sizeof(stenoLayers[0]);
|
||||
size_t stenoLayerCount = ARRAY_SIZE(stenoLayers);
|
||||
#endif
|
||||
|
||||
// Mode state
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -118,7 +118,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
{{205, 250, 255}, {140, 215, 125}, false },
|
||||
};
|
||||
|
||||
uint8_t gp_length = sizeof(gradient_presets)/sizeof(gradient_presets[0]);
|
||||
uint8_t gp_length = ARRAY_SIZE(gradient_presets);
|
||||
|
||||
switch (keycode) {
|
||||
case G1_HUI:
|
||||
|
@@ -69,7 +69,7 @@ void add_keylog(uint16_t keycode) {
|
||||
keycode = 0;
|
||||
}
|
||||
|
||||
if (keycode < (sizeof(code_to_name) / sizeof(char))) {
|
||||
if (keycode < ARRAY_SIZE(code_to_name)) {
|
||||
char log_char = pgm_read_byte(&code_to_name[keycode]);
|
||||
|
||||
for (uint8_t j = 0; j < OLED_FONT_WIDTH; j++) {
|
||||
|
@@ -191,8 +191,8 @@ void keyboard_post_init_user(void) {
|
||||
const pin_t pins[] = {D0, D1, D2};
|
||||
uint8_t i, j;
|
||||
|
||||
for (i = 0 ; i < sizeof(pins) / sizeof(pins[0]) + 2 ; i += 1) {
|
||||
for (j = 0 ; j < sizeof(pins) / sizeof(pins[0]) ; j += 1) {
|
||||
for (i = 0 ; i < ARRAY_SIZE(pins) + 2 ; i += 1) {
|
||||
for (j = 0 ; j < ARRAY_SIZE(pins); j += 1) {
|
||||
setPinOutput(pins[j]);
|
||||
writePin(pins[j], (j == i || j == i - 1));
|
||||
}
|
||||
|
@@ -183,7 +183,7 @@ void add_keylog(uint16_t keycode) {
|
||||
keylog_str[i] = keylog_str[i - 1];
|
||||
}
|
||||
|
||||
if (keycode < (sizeof(code_to_name) / sizeof(char))) {
|
||||
if (keycode < ARRAY_SIZE(code_to_name)) {
|
||||
keylog_str[0] = pgm_read_byte(&code_to_name[keycode]);
|
||||
}
|
||||
}
|
||||
|
@@ -116,7 +116,7 @@ PGM_P const sentences[] PROGMEM = {
|
||||
|
||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
if (record->event.pressed) {
|
||||
int sentences_size = sizeof(sentences) / sizeof(sentences[0]);
|
||||
int sentences_size = ARRAY_SIZE(sentences);
|
||||
int i = rand() % sentences_size;
|
||||
|
||||
switch (keycode) {
|
||||
|
@@ -34,11 +34,11 @@ static const uint32_t waiting_values[] = {0, 1, 5, 10, 25, 50, 100, 150, 200, 50
|
||||
void housekeeping_task_user(void) {
|
||||
static uint32_t last_bench = 0;
|
||||
if (timer_elapsed32(last_bench) > 500) {
|
||||
for (int i = 0; i < (sizeof(waiting_values) / sizeof(waiting_values[0])); i++) {
|
||||
for (int i = 0; i < ARRAY_SIZE(waiting_values); i++) {
|
||||
wait_us_polling_with_strobe(waiting_values[i]);
|
||||
wait_us(10);
|
||||
}
|
||||
for (int i = 0; i < (sizeof(waiting_values) / sizeof(waiting_values[0])); i++) {
|
||||
for (int i = 0; i < ARRAY_SIZE(waiting_values); i++) {
|
||||
wait_us_yield_with_strobe(waiting_values[i]);
|
||||
wait_us(10);
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#endif
|
||||
#include "outputselect.h"
|
||||
#include "led.h"
|
||||
#define COUNT(x) (sizeof (x) / sizeof (*(x)))
|
||||
#define COUNT(x) ARRAY_SIZE((x))
|
||||
|
||||
#define KC_WWWB KC_WWW_BACK
|
||||
#define KC_WWWF KC_WWW_FORWARD
|
||||
|
@@ -57,7 +57,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "outputselect.h"
|
||||
#endif
|
||||
#include "led.h"
|
||||
#define COUNT(x) (sizeof (x) / sizeof (*(x)))
|
||||
#define COUNT(x) ARRAY_SIZE((x))
|
||||
|
||||
#define KC_WWWB KC_WWW_BACK
|
||||
#define KC_WWWF KC_WWW_FORWARD
|
||||
|
@@ -159,7 +159,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
|
||||
do {
|
||||
MATRIX_DEBUG_DELAY_START();
|
||||
is_pressed = false;
|
||||
for (uint8_t i = 0; i < sizeof(delay_ports) / sizeof(pin_t); i++) {
|
||||
for (uint8_t i = 0; i < ARRAY_SIZE(delay_ports); i++) {
|
||||
# ifdef MATRIX_IO_DELAY_MULSEL
|
||||
writePin(MATRIX_MUL_SELECT, delay_sel[i]);
|
||||
waitInputPinDelay();
|
||||
|
@@ -110,7 +110,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
{{205, 250, 255}, {140, 215, 125}, false },
|
||||
};
|
||||
|
||||
uint8_t gp_length = sizeof(gradient_presets)/sizeof(gradient_presets[0]);
|
||||
uint8_t gp_length = ARRAY_SIZE(gradient_presets);
|
||||
|
||||
switch (keycode) {
|
||||
case G1_HUI:
|
||||
|
@@ -110,7 +110,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
{{205, 250, 255}, {140, 215, 125}, false },
|
||||
};
|
||||
|
||||
uint8_t gp_length = sizeof(gradient_presets)/sizeof(gradient_presets[0]);
|
||||
uint8_t gp_length = ARRAY_SIZE(gradient_presets);
|
||||
|
||||
switch (keycode) {
|
||||
case G1_HUI:
|
||||
|
@@ -68,7 +68,7 @@ void add_keylog(uint16_t keycode) {
|
||||
keycode = 0;
|
||||
}
|
||||
|
||||
if (keycode < (sizeof(code_to_name) / sizeof(char))) {
|
||||
if (keycode < ARRAY_SIZE(code_to_name)) {
|
||||
char log_char = pgm_read_byte(&code_to_name[keycode]);
|
||||
|
||||
for (uint8_t j = 0; j < OLED_FONT_WIDTH; j++) {
|
||||
|
@@ -58,7 +58,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
};
|
||||
|
||||
const uint8_t number_leds[] = {8, 9, 10, 11, 12, 13, 15, 16, 17};
|
||||
const uint8_t number_leds_size = sizeof(number_leds) / sizeof(uint8_t);
|
||||
const uint8_t number_leds_size = ARRAY_SIZE(number_leds);
|
||||
|
||||
bool led_update_user(led_t led_state) {
|
||||
for (uint8_t i = 0; i < number_leds_size; i++)
|
||||
|
@@ -129,8 +129,7 @@ static uint8_t COLOR_PATTERNS[][COLOR_PATTERN_RGB_COUNT][3] = {
|
||||
{ 66, 66, 66}, { 45, 45, 45}, { 23, 23, 23},
|
||||
},
|
||||
};
|
||||
static const uint8_t COLOR_PATTERNS_COUNT = (
|
||||
sizeof(COLOR_PATTERNS) / sizeof(COLOR_PATTERNS[0]));
|
||||
static const uint8_t COLOR_PATTERNS_COUNT = ARRAY_SIZE(COLOR_PATTERNS);
|
||||
|
||||
/**
|
||||
* trimed down version of `ISSI3733_LED_MAP`:
|
||||
|
@@ -83,7 +83,7 @@ static const encoder_key PROGMEM encoder_keys[] = {
|
||||
{"Play", "", "", KC_MEDIA_PLAY_PAUSE}
|
||||
};
|
||||
|
||||
#define NUMBER_OF_ENCODER_KEYS sizeof(encoder_keys)/sizeof(encoder_keys[0])
|
||||
#define NUMBER_OF_ENCODER_KEYS ARRAY_SIZE(encoder_keys)
|
||||
|
||||
static uint8_t selected_encoder_key_id = 0;
|
||||
static encoder_key selected_encoder_key;
|
||||
|
@@ -82,7 +82,7 @@ static const encoder_key PROGMEM encoder_keys[] = {
|
||||
{"Play", "", "", KC_MEDIA_PLAY_PAUSE}
|
||||
};
|
||||
|
||||
#define NUMBER_OF_ENCODER_KEYS sizeof(encoder_keys)/sizeof(encoder_keys[0])
|
||||
#define NUMBER_OF_ENCODER_KEYS ARRAY_SIZE(encoder_keys)
|
||||
|
||||
static uint8_t selected_encoder_key_id = 0;
|
||||
static encoder_key selected_encoder_key;
|
||||
|
@@ -71,7 +71,7 @@ static const keycodedescType PROGMEM keyselection[] = {
|
||||
{"FLASH", QK_BOOT}, // firmware flash mode
|
||||
};
|
||||
|
||||
#define MAX_KEYSELECTION sizeof(keyselection)/sizeof(keyselection[0])
|
||||
#define MAX_KEYSELECTION ARRAY_SIZE(keyselection)
|
||||
|
||||
static uint8_t selectedkey_idx = 0;
|
||||
static keycodedescType selectedkey_rec;
|
||||
|
@@ -178,7 +178,7 @@ static const keycodedescType PROGMEM keyselection[] = {
|
||||
{"QK_BOOT", QK_BOOT}, // firmware flash mode
|
||||
};
|
||||
|
||||
#define MAX_KEYSELECTION sizeof(keyselection)/sizeof(keyselection[0])
|
||||
#define MAX_KEYSELECTION ARRAY_SIZE(keyselection)
|
||||
|
||||
static uint8_t selectedkey_idx = 0;
|
||||
static keycodedescType selectedkey_rec;
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
keyboard_config_t keyboard_config;
|
||||
uint16_t dpi_array[] = GLIDEPOINT_DPI_OPTIONS;
|
||||
#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
|
||||
#define DPI_OPTION_SIZE ARRAY_SIZE(dpi_array)
|
||||
|
||||
void board_init(void) {
|
||||
// B9 is configured as I2C1_SDA in the board file; that function must be
|
||||
|
@@ -97,7 +97,7 @@ const bool defaultlayers[] = {
|
||||
[_xN] = false,
|
||||
[_xF] = false,
|
||||
};
|
||||
const size_t defaultlayers_n = sizeof(defaultlayers) / sizeof(defaultlayers[0]);
|
||||
const size_t defaultlayers_n = ARRAY_SIZE(defaultlayers);
|
||||
|
||||
// New keycode KC_LAYO rotates between available default layers (for e.g.,
|
||||
// selecting a base layout). Shift+KC_LAYO makes the current one persistent.
|
||||
|
@@ -116,7 +116,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
{{205, 250, 255}, {140, 215, 125}, false },
|
||||
};
|
||||
|
||||
uint8_t gp_length = sizeof(gradient_presets)/sizeof(gradient_presets[0]);
|
||||
uint8_t gp_length = ARRAY_SIZE(gradient_presets);
|
||||
|
||||
switch (keycode) {
|
||||
case G1_HUI:
|
||||
|
@@ -27,7 +27,7 @@ hs_set layer_colors[4] = {
|
||||
[2] = {.hue = 36, .sat = 255}, // Color for Layer 2
|
||||
[3] = {.hue = 185, .sat = 255}, // Color for Layer 3
|
||||
};
|
||||
size_t lc_size = sizeof(layer_colors) / sizeof(uint16_t);
|
||||
size_t lc_size = ARRAY_SIZE(layer_colors);
|
||||
|
||||
// Use NEW_SAFE_RANGE to define new custom keycodes in order to not overwrite the ones used for front LED control
|
||||
enum custom_keycodes {
|
||||
|
@@ -36,7 +36,7 @@ __attribute__ ((weak))
|
||||
hs_set caps_color;
|
||||
|
||||
__attribute__ ((weak))
|
||||
size_t lc_size = sizeof(layer_colors) / sizeof(hs_set);
|
||||
size_t lc_size = ARRAY_SIZE(layer_colors);
|
||||
|
||||
void fled_init(void) {
|
||||
// This checks both an EEPROM reset (from bootmagic lite, keycodes)
|
||||
|
@@ -27,7 +27,7 @@ hs_set layer_colors[4] = {
|
||||
[2] = {.hue = 36, .sat = 255}, // Color for Layer 2
|
||||
[3] = {.hue = 185, .sat = 255}, // Color for Layer 3
|
||||
};
|
||||
size_t lc_size = sizeof(layer_colors) / sizeof(uint16_t);
|
||||
size_t lc_size = ARRAY_SIZE(layer_colors);
|
||||
|
||||
// Use NEW_SAFE_RANGE to define new custom keycodes in order to not overwrite the ones used for front LED control
|
||||
enum custom_keycodes {
|
||||
|
@@ -49,7 +49,7 @@
|
||||
|
||||
keyboard_config_t keyboard_config;
|
||||
uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
|
||||
#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
|
||||
#define DPI_OPTION_SIZE ARRAY_SIZE(dpi_array)
|
||||
|
||||
// TODO: Implement libinput profiles
|
||||
// https://wayland.freedesktop.org/libinput/doc/latest/pointer-acceleration.html
|
||||
@@ -202,7 +202,7 @@ void keyboard_pre_init_kb(void) {
|
||||
#ifdef UNUSABLE_PINS
|
||||
const pin_t unused_pins[] = UNUSABLE_PINS;
|
||||
|
||||
for (uint8_t i = 0; i < (sizeof(unused_pins) / sizeof(pin_t)); i++) {
|
||||
for (uint8_t i = 0; i < ARRAY_SIZE(unused_pins); i++) {
|
||||
setPinOutput(unused_pins[i]);
|
||||
writePinLow(unused_pins[i]);
|
||||
}
|
||||
|
@@ -49,7 +49,7 @@
|
||||
|
||||
keyboard_config_t keyboard_config;
|
||||
uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
|
||||
#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
|
||||
#define DPI_OPTION_SIZE ARRAY_SIZE(dpi_array)
|
||||
|
||||
// TODO: Implement libinput profiles
|
||||
// https://wayland.freedesktop.org/libinput/doc/latest/pointer-acceleration.html
|
||||
@@ -207,7 +207,7 @@ void keyboard_pre_init_kb(void) {
|
||||
#ifdef UNUSABLE_PINS
|
||||
const pin_t unused_pins[] = UNUSABLE_PINS;
|
||||
|
||||
for (uint8_t i = 0; i < (sizeof(unused_pins) / sizeof(pin_t)); i++) {
|
||||
for (uint8_t i = 0; i < ARRAY_SIZE(unused_pins); i++) {
|
||||
setPinOutput(unused_pins[i]);
|
||||
writePinLow(unused_pins[i]);
|
||||
}
|
||||
|
@@ -57,7 +57,7 @@
|
||||
|
||||
keyboard_config_t keyboard_config;
|
||||
uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
|
||||
#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
|
||||
#define DPI_OPTION_SIZE ARRAY_SIZE(dpi_array)
|
||||
|
||||
// TODO: Implement libinput profiles
|
||||
// https://wayland.freedesktop.org/libinput/doc/latest/pointer-acceleration.html
|
||||
@@ -203,7 +203,7 @@ void keyboard_pre_init_kb(void) {
|
||||
#ifdef UNUSABLE_PINS
|
||||
const pin_t unused_pins[] = UNUSABLE_PINS;
|
||||
|
||||
for (uint8_t i = 0; i < (sizeof(unused_pins) / sizeof(pin_t)); i++) {
|
||||
for (uint8_t i = 0; i < ARRAY_SIZE(unused_pins); i++) {
|
||||
setPinOutput(unused_pins[i]);
|
||||
writePinLow(unused_pins[i]);
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@
|
||||
|
||||
keyboard_config_t keyboard_config;
|
||||
uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
|
||||
#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
|
||||
#define DPI_OPTION_SIZE ARRAY_SIZE(dpi_array)
|
||||
|
||||
void cycle_dpi(void) {
|
||||
keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
|
||||
@@ -89,7 +89,7 @@ void keyboard_pre_init_kb(void) {
|
||||
#ifdef UNUSABLE_PINS
|
||||
const pin_t unused_pins[] = UNUSABLE_PINS;
|
||||
|
||||
for (uint8_t i = 0; i < (sizeof(unused_pins) / sizeof(pin_t)); i++) {
|
||||
for (uint8_t i = 0; i < ARRAY_SIZE(unused_pins); i++) {
|
||||
setPinOutput(unused_pins[i]);
|
||||
writePinLow(unused_pins[i]);
|
||||
}
|
||||
|
@@ -51,7 +51,7 @@ static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) {
|
||||
}
|
||||
|
||||
static void setled_all(uint8_t r, uint8_t g, uint8_t b) {
|
||||
for (int i = 0; i < sizeof(rgb_matrix_ws2812_array) / sizeof(rgb_matrix_ws2812_array[0]); i++) {
|
||||
for (int i = 0; i < ARRAY_SIZE(rgb_matrix_ws2812_array); i++) {
|
||||
setled(i, r, g, b);
|
||||
}
|
||||
}
|
||||
|
@@ -202,7 +202,7 @@ const rgb_matrix_f rgb_matrix_functions[6][2] = {
|
||||
#ifdef ENCODER_ENABLE
|
||||
|
||||
static pin_t encoders_pad_a[] = ENCODERS_PAD_A;
|
||||
#define NUMBER_OF_ENCODERS (sizeof(encoders_pad_a)/sizeof(pin_t))
|
||||
#define NUMBER_OF_ENCODERS ARRAY_SIZE(encoders_pad_a)
|
||||
|
||||
const uint16_t PROGMEM encoders[][NUMBER_OF_ENCODERS * 2][2] = {
|
||||
[_QWERTY] = ENCODER_LAYOUT(
|
||||
|
@@ -232,7 +232,7 @@ const rgb_matrix_f rgb_matrix_functions[6][2] = {
|
||||
#ifdef ENCODER_ENABLE
|
||||
|
||||
static pin_t encoders_pad_a[] = ENCODERS_PAD_A;
|
||||
#define NUMBER_OF_ENCODERS (sizeof(encoders_pad_a)/sizeof(pin_t))
|
||||
#define NUMBER_OF_ENCODERS ARRAY_SIZE(encoders_pad_a)
|
||||
|
||||
const uint16_t PROGMEM encoders[][NUMBER_OF_ENCODERS * 2][2] = {
|
||||
[_QWERTY] = ENCODER_LAYOUT( \
|
||||
|
@@ -18,7 +18,7 @@
|
||||
#include "print.h"
|
||||
#include "via.h"
|
||||
|
||||
#define num_keycodes (sizeof(lookup_table)/sizeof(lookup_table[0]))
|
||||
#define num_keycodes ARRAY_SIZE(lookup_table)
|
||||
static char UNKNOWN_KEYCODE[] = "UNKNOWN";
|
||||
|
||||
int cmp(const void *v1, const void *v2)
|
||||
|
@@ -18,8 +18,6 @@
|
||||
|
||||
#ifdef OLED_ENABLE
|
||||
|
||||
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
|
||||
|
||||
#define IDLE_SPEED 20 // idle below this wpm
|
||||
#define TAP_SPEED 60 // tap above this wpm
|
||||
|
||||
|
@@ -92,11 +92,11 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
|
||||
|
||||
void matrix_wait_for_interrupt(void) {
|
||||
// Set up row/col pins and attach callback
|
||||
for (int i = 0; i < sizeof(col_pins) / sizeof(pin_t); ++i) {
|
||||
for (int i = 0; i < ARRAY_SIZE(col_pins); ++i) {
|
||||
setPinOutput(col_pins[i]);
|
||||
writePinLow(col_pins[i]);
|
||||
}
|
||||
for (int i = 0; i < sizeof(row_pins) / sizeof(pin_t); ++i) {
|
||||
for (int i = 0; i < ARRAY_SIZE(row_pins); ++i) {
|
||||
setPinInputHigh(row_pins[i]);
|
||||
palEnableLineEvent(row_pins[i], PAL_EVENT_MODE_BOTH_EDGES);
|
||||
}
|
||||
@@ -105,12 +105,12 @@ void matrix_wait_for_interrupt(void) {
|
||||
__WFI();
|
||||
|
||||
// Now that the interrupt has woken us up, reset all the row/col pins back to defaults
|
||||
for (int i = 0; i < sizeof(row_pins) / sizeof(pin_t); ++i) {
|
||||
for (int i = 0; i < ARRAY_SIZE(row_pins); ++i) {
|
||||
palDisableLineEvent(row_pins[i]);
|
||||
writePinHigh(row_pins[i]);
|
||||
setPinInputHigh(row_pins[i]);
|
||||
}
|
||||
for (int i = 0; i < sizeof(col_pins) / sizeof(pin_t); ++i) {
|
||||
for (int i = 0; i < ARRAY_SIZE(col_pins); ++i) {
|
||||
writePinHigh(col_pins[i]);
|
||||
setPinInputHigh(col_pins[i]);
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#include "konstantin.h"
|
||||
|
||||
static const HSV *colors[] = { &godspeed_blue, &godspeed_yellow };
|
||||
static const size_t cnum = sizeof colors / sizeof *colors;
|
||||
static const size_t cnum = ARRAY_SIZE(colors);
|
||||
static size_t cidx = 0;
|
||||
|
||||
enum keycodes_keymap {
|
||||
|
Reference in New Issue
Block a user