diff options
91 files changed, 178 insertions, 165 deletions
diff --git a/docs/feature_combo.md b/docs/feature_combo.md index 42d965509b..bb0b5d7aa0 100644 --- a/docs/feature_combo.md +++ b/docs/feature_combo.md @@ -255,7 +255,7 @@ bool combo_should_trigger(uint16_t combo_index, combo_t *combo, uint16_t keycode ``` ## Variable Length Combos -If you leave `COMBO_COUNT` undefined in `config.h`, it allows you to programmatically declare the size of the Combo data structure and avoid updating `COMBO_COUNT`. Instead a variable called `COMBO_LEN` has to be set. It can be set with something similar to the following in `keymap.c`: `uint16_t COMBO_LEN = sizeof(key_combos) / sizeof(key_combos[0]);` or by adding `COMBO_LENGTH` as the *last* entry in the combo enum and then `uint16_t COMBO_LEN = COMBO_LENGTH;` as such: +If you leave `COMBO_COUNT` undefined in `config.h`, it allows you to programmatically declare the size of the Combo data structure and avoid updating `COMBO_COUNT`. Instead a variable called `COMBO_LEN` has to be set. It can be set with something similar to the following in `keymap.c`: `uint16_t COMBO_LEN = ARRAY_SIZE(key_combos);` or by adding `COMBO_LENGTH` as the *last* entry in the combo enum and then `uint16_t COMBO_LEN = COMBO_LENGTH;` as such: ```c enum myCombos { ..., diff --git a/drivers/haptic/solenoid.c b/drivers/haptic/solenoid.c index 637a77da3d..4e43903255 100644 --- a/drivers/haptic/solenoid.c +++ b/drivers/haptic/solenoid.c @@ -20,11 +20,12 @@ #include "haptic.h" #include "gpio.h" #include "usb_device_state.h" +#include "util.h" #include <stdlib.h> uint8_t solenoid_dwell = SOLENOID_DEFAULT_DWELL; static pin_t solenoid_pads[] = SOLENOID_PINS; -#define NUMBER_OF_SOLENOIDS (sizeof(solenoid_pads) / sizeof(pin_t)) +#define NUMBER_OF_SOLENOIDS ARRAY_SIZE(solenoid_pads) bool solenoid_on[NUMBER_OF_SOLENOIDS] = {false}; bool solenoid_buzzing[NUMBER_OF_SOLENOIDS] = {false}; uint16_t solenoid_start[NUMBER_OF_SOLENOIDS] = {0}; @@ -147,7 +148,7 @@ void solenoid_check(void) { void solenoid_setup(void) { #ifdef SOLENOID_PINS_ACTIVE_STATE bool state_temp[] = SOLENOID_PINS_ACTIVE_STATE; - uint8_t bound_check = (sizeof(state_temp) / sizeof(bool)); + uint8_t bound_check = ARRAY_SIZE(state_temp); #endif for (uint8_t i = 0; i < NUMBER_OF_SOLENOIDS; i++) { diff --git a/drivers/sensors/pmw33xx_common.c b/drivers/sensors/pmw33xx_common.c index 4993cc2d34..b8d4e532ca 100644 --- a/drivers/sensors/pmw33xx_common.c +++ b/drivers/sensors/pmw33xx_common.c @@ -17,10 +17,10 @@ extern const uint8_t pmw33xx_firmware_data[PMW33XX_FIRMWARE_LENGTH] PROGMEM; extern const uint8_t pmw33xx_firmware_signature[3] PROGMEM; -static const pin_t cs_pins[] = PMW33XX_CS_PINS; -static bool in_burst[sizeof(cs_pins) / sizeof(pin_t)] = {0}; +static const pin_t cs_pins[] = PMW33XX_CS_PINS; +static bool in_burst[ARRAY_SIZE(cs_pins)] = {0}; -const size_t pmw33xx_number_of_sensors = sizeof(cs_pins) / sizeof(pin_t); +const size_t pmw33xx_number_of_sensors = ARRAY_SIZE(cs_pins); bool __attribute__((cold)) pmw33xx_upload_firmware(uint8_t sensor); bool __attribute__((cold)) pmw33xx_check_signature(uint8_t sensor); diff --git a/keyboards/25keys/zinc/keymaps/ginjake/keymap.c b/keyboards/25keys/zinc/keymaps/ginjake/keymap.c index 93dfc590e9..26190a2a91 100644 --- a/keyboards/25keys/zinc/keymaps/ginjake/keymap.c +++ b/keyboards/25keys/zinc/keymaps/ginjake/keymap.c @@ -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; } } diff --git a/keyboards/acheron/shark/beta/keymaps/gondolindrim/keymap.c b/keyboards/acheron/shark/beta/keymaps/gondolindrim/keymap.c index cae98411d6..fd7f556b56 100755 --- a/keyboards/acheron/shark/beta/keymaps/gondolindrim/keymap.c +++ b/keyboards/acheron/shark/beta/keymaps/gondolindrim/keymap.c @@ -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; diff --git a/keyboards/adafruit/macropad/lib/ssd1306_sh1106.c b/keyboards/adafruit/macropad/lib/ssd1306_sh1106.c index dc1289fdb1..1b05809640 100644 --- a/keyboards/adafruit/macropad/lib/ssd1306_sh1106.c +++ b/keyboards/adafruit/macropad/lib/ssd1306_sh1106.c @@ -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 diff --git a/keyboards/crkbd/keymaps/gotham/oled.c b/keyboards/crkbd/keymaps/gotham/oled.c index c4ac5e736c..c285a37c5b 100644 --- a/keyboards/crkbd/keymaps/gotham/oled.c +++ b/keyboards/crkbd/keymaps/gotham/oled.c @@ -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]); } } diff --git a/keyboards/crkbd/keymaps/thunderbird2086/oled.c b/keyboards/crkbd/keymaps/thunderbird2086/oled.c index bee9bc26de..108f3e0cdd 100644 --- a/keyboards/crkbd/keymaps/thunderbird2086/oled.c +++ b/keyboards/crkbd/keymaps/thunderbird2086/oled.c @@ -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]); } } diff --git a/keyboards/dm9records/plaid/keymaps/brickbots/keymap.c b/keyboards/dm9records/plaid/keymaps/brickbots/keymap.c index 819b76e739..0442c930fe 100644 --- a/keyboards/dm9records/plaid/keymaps/brickbots/keymap.c +++ b/keyboards/dm9records/plaid/keymaps/brickbots/keymap.c @@ -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); diff --git a/keyboards/dm9records/plaid/keymaps/default/keymap.c b/keyboards/dm9records/plaid/keymaps/default/keymap.c index d96c250609..aa0bd8b093 100644 --- a/keyboards/dm9records/plaid/keymaps/default/keymap.c +++ b/keyboards/dm9records/plaid/keymaps/default/keymap.c @@ -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); diff --git a/keyboards/dm9records/plaid/keymaps/stephen-huan/keymap.c b/keyboards/dm9records/plaid/keymaps/stephen-huan/keymap.c index 354599f340..9a0e89bd89 100644 --- a/keyboards/dm9records/plaid/keymaps/stephen-huan/keymap.c +++ b/keyboards/dm9records/plaid/keymaps/stephen-huan/keymap.c @@ -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); diff --git a/keyboards/dmqdesign/spin/keymaps/spidey3_pad/keymap.c b/keyboards/dmqdesign/spin/keymaps/spidey3_pad/keymap.c index 8c9af7202b..77534b9a75 100644 --- a/keyboards/dmqdesign/spin/keymaps/spidey3_pad/keymap.c +++ b/keyboards/dmqdesign/spin/keymaps/spidey3_pad/keymap.c @@ -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"); diff --git a/keyboards/evolv/keymaps/gondolindrim/keymap.c b/keyboards/evolv/keymaps/gondolindrim/keymap.c index 3ab66bd056..bf0944fbd1 100755 --- a/keyboards/evolv/keymaps/gondolindrim/keymap.c +++ b/keyboards/evolv/keymaps/gondolindrim/keymap.c @@ -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; diff --git a/keyboards/gboards/butterstick/keymaps/default/keymap.c b/keyboards/gboards/butterstick/keymaps/default/keymap.c index 749e9ba071..d0c6af65df 100644 --- a/keyboards/gboards/butterstick/keymaps/default/keymap.c +++ b/keyboards/gboards/butterstick/keymaps/default/keymap.c @@ -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); diff --git a/keyboards/gboards/butterstick/sten.c b/keyboards/gboards/butterstick/sten.c index 197abaf92f..8820127848 100644 --- a/keyboards/gboards/butterstick/sten.c +++ b/keyboards/gboards/butterstick/sten.c @@ -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 diff --git a/keyboards/gboards/engine/keymap_engine.h b/keyboards/gboards/engine/keymap_engine.h index c8a42a052b..599c1ca3e4 100644 --- a/keyboards/gboards/engine/keymap_engine.h +++ b/keyboards/gboards/engine/keymap_engine.h @@ -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); diff --git a/keyboards/gboards/g/keymap_engine.h b/keyboards/gboards/g/keymap_engine.h index 93a4423340..055b5941e4 100644 --- a/keyboards/gboards/g/keymap_engine.h +++ b/keyboards/gboards/g/keymap_engine.h @@ -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_ |