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>
64 lines
2 KiB
C
64 lines
2 KiB
C
/*
|
|
* Copyright 2018 Jack Humbert <jack.humb@gmail.com>
|
|
*
|
|
* 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/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "quantum.h"
|
|
#include "util.h"
|
|
|
|
void encoder_init(void);
|
|
bool encoder_read(void);
|
|
|
|
bool encoder_update_kb(uint8_t index, bool clockwise);
|
|
bool encoder_update_user(uint8_t index, bool clockwise);
|
|
|
|
#ifdef SPLIT_KEYBOARD
|
|
|
|
void encoder_state_raw(uint8_t* slave_state);
|
|
void encoder_update_raw(uint8_t* slave_state);
|
|
|
|
# if defined(ENCODERS_PAD_A_RIGHT)
|
|
# define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
|
|
# define NUM_ENCODERS_RIGHT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A_RIGHT))
|
|
# else
|
|
# define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
|
|
# define NUM_ENCODERS_RIGHT NUM_ENCODERS_LEFT
|
|
# endif
|
|
# define NUM_ENCODERS (NUM_ENCODERS_LEFT + NUM_ENCODERS_RIGHT)
|
|
|
|
#else // SPLIT_KEYBOARD
|
|
|
|
# define NUM_ENCODERS ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
|
|
# define NUM_ENCODERS_LEFT NUM_ENCODERS
|
|
# define NUM_ENCODERS_RIGHT 0
|
|
|
|
#endif // SPLIT_KEYBOARD
|
|
|
|
#ifndef NUM_ENCODERS
|
|
# define NUM_ENCODERS 0
|
|
# define NUM_ENCODERS_LEFT 0
|
|
# define NUM_ENCODERS_RIGHT 0
|
|
#endif // NUM_ENCODERS
|
|
|
|
#define NUM_ENCODERS_MAX_PER_SIDE MAX(NUM_ENCODERS_LEFT, NUM_ENCODERS_RIGHT)
|
|
|
|
#ifdef ENCODER_MAP_ENABLE
|
|
# define ENCODER_CCW_CW(ccw, cw) \
|
|
{ (cw), (ccw) }
|
|
extern const uint16_t encoder_map[][NUM_ENCODERS][2];
|
|
#endif // ENCODER_MAP_ENABLE
|