Add a keymatrix_t type
This contains both the matrix number and key position, in preparation for multi-matrix support
This commit is contained in:
		
							parent
							
								
									c11c7948e6
								
							
						
					
					
						commit
						f9c61b1bbe
					
				
					 14 changed files with 59 additions and 49 deletions
				
			
		| 
						 | 
				
			
			@ -892,7 +892,7 @@ void clear_keyboard_but_mods(void)
 | 
			
		|||
 *
 | 
			
		||||
 * FIXME: Needs documentation.
 | 
			
		||||
 */
 | 
			
		||||
bool is_tap_key(keypos_t key)
 | 
			
		||||
bool is_tap_key(keymatrix_t key)
 | 
			
		||||
{
 | 
			
		||||
    action_t action = layer_switch_get_action(key);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -50,7 +50,7 @@ typedef struct {
 | 
			
		|||
void action_exec(keyevent_t event);
 | 
			
		||||
 | 
			
		||||
/* action for key */
 | 
			
		||||
action_t action_for_key(uint8_t layer, keypos_t key);
 | 
			
		||||
action_t action_for_key(uint8_t layer, keymatrix_t key);
 | 
			
		||||
 | 
			
		||||
/* macro */
 | 
			
		||||
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt);
 | 
			
		||||
| 
						 | 
				
			
			@ -94,7 +94,7 @@ void unregister_mods(uint8_t mods);
 | 
			
		|||
void clear_keyboard(void);
 | 
			
		||||
void clear_keyboard_but_mods(void);
 | 
			
		||||
void layer_switch(uint8_t new_layer);
 | 
			
		||||
bool is_tap_key(keypos_t key);
 | 
			
		||||
bool is_tap_key(keymatrix_t key);
 | 
			
		||||
 | 
			
		||||
#ifndef NO_ACTION_TAPPING
 | 
			
		||||
void process_record_tap_hint(keyrecord_t *record);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -223,9 +223,9 @@ void layer_debug(void)
 | 
			
		|||
uint8_t source_layers_cache[(MATRIX_ROWS * MATRIX_COLS * MAX_LAYER_BITS + 7) / 8] = {0};
 | 
			
		||||
static const uint8_t layer_cache_mask = (1u << MAX_LAYER_BITS) - 1;
 | 
			
		||||
 | 
			
		||||
void update_source_layers_cache(keypos_t key, uint8_t layer)
 | 
			
		||||
void update_source_layers_cache(keymatrix_t key, uint8_t layer)
 | 
			
		||||
{
 | 
			
		||||
  const uint16_t key_number = key.col + (key.row * MATRIX_COLS);
 | 
			
		||||
  const uint16_t key_number = key.pos.col + (key.pos.row * MATRIX_COLS);
 | 
			
		||||
  const uint32_t bit_number = key_number * MAX_LAYER_BITS;
 | 
			
		||||
  const uint16_t byte_number = bit_number / 8;
 | 
			
		||||
  if (byte_number >= sizeof(source_layers_cache)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -261,9 +261,9 @@ void update_source_layers_cache(keypos_t key, uint8_t layer)
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8_t read_source_layers_cache(keypos_t key)
 | 
			
		||||
uint8_t read_source_layers_cache(keymatrix_t key)
 | 
			
		||||
{
 | 
			
		||||
  const uint16_t key_number = key.col + (key.row * MATRIX_COLS);
 | 
			
		||||
  const uint16_t key_number = key.pos.col + (key.pos.row * MATRIX_COLS);
 | 
			
		||||
  const uint32_t bit_number = key_number * MAX_LAYER_BITS;
 | 
			
		||||
  const uint16_t byte_number = bit_number / 8;
 | 
			
		||||
  if (byte_number >= sizeof(source_layers_cache)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -296,7 +296,7 @@ uint8_t read_source_layers_cache(keypos_t key)
 | 
			
		|||
 * when the layer is switched after the down event but before the up
 | 
			
		||||
 * event as they may get stuck otherwise.
 | 
			
		||||
 */
 | 
			
		||||
action_t store_or_get_action(bool pressed, keypos_t key)
 | 
			
		||||
action_t store_or_get_action(bool pressed, keymatrix_t key)
 | 
			
		||||
{
 | 
			
		||||
#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
 | 
			
		||||
    if (disable_action_cache) {
 | 
			
		||||
| 
						 | 
				
			
			@ -323,7 +323,7 @@ action_t store_or_get_action(bool pressed, keypos_t key)
 | 
			
		|||
 *
 | 
			
		||||
 * FIXME: Needs docs
 | 
			
		||||
 */
 | 
			
		||||
int8_t layer_switch_get_layer(keypos_t key)
 | 
			
		||||
int8_t layer_switch_get_layer(keymatrix_t key)
 | 
			
		||||
{
 | 
			
		||||
#ifndef NO_ACTION_LAYER
 | 
			
		||||
    action_t action;
 | 
			
		||||
| 
						 | 
				
			
			@ -350,7 +350,7 @@ int8_t layer_switch_get_layer(keypos_t key)
 | 
			
		|||
 *
 | 
			
		||||
 * FIXME: Needs docs
 | 
			
		||||
 */
 | 
			
		||||
action_t layer_switch_get_action(keypos_t key)
 | 
			
		||||
action_t layer_switch_get_action(keymatrix_t key)
 | 
			
		||||
{
 | 
			
		||||
    return action_for_key(layer_switch_get_layer(key), key);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -91,15 +91,15 @@ uint32_t layer_state_set_kb(uint32_t state);
 | 
			
		|||
#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
 | 
			
		||||
/* The number of bits needed to represent the layer number: log2(32). */
 | 
			
		||||
#define MAX_LAYER_BITS 5
 | 
			
		||||
void update_source_layers_cache(keypos_t key, uint8_t layer);
 | 
			
		||||
uint8_t read_source_layers_cache(keypos_t key);
 | 
			
		||||
void update_source_layers_cache(keymatrix_t key, uint8_t layer);
 | 
			
		||||
uint8_t read_source_layers_cache(keymatrix_t key);
 | 
			
		||||
#endif
 | 
			
		||||
action_t store_or_get_action(bool pressed, keypos_t key);
 | 
			
		||||
action_t store_or_get_action(bool pressed, keymatrix_t key);
 | 
			
		||||
 | 
			
		||||
/* return the topmost non-transparent layer currently associated with key */
 | 
			
		||||
int8_t layer_switch_get_layer(keypos_t key);
 | 
			
		||||
int8_t layer_switch_get_layer(keymatrix_t key);
 | 
			
		||||
 | 
			
		||||
/* return action depending on current layer status */
 | 
			
		||||
action_t layer_switch_get_action(keypos_t key);
 | 
			
		||||
action_t layer_switch_get_action(keymatrix_t key);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -116,7 +116,7 @@ static bool scan_keycode(uint8_t keycode)
 | 
			
		|||
        matrix_row_t matrix_row = matrix_get_row(r);
 | 
			
		||||
        for (uint8_t c = 0; c < MATRIX_COLS; c++) {
 | 
			
		||||
            if (matrix_row & ((matrix_row_t)1<<c)) {
 | 
			
		||||
                if (keycode == keymap_key_to_keycode(0, (keypos_t){ .row = r, .col = c })) {
 | 
			
		||||
                if (keycode == keymap_key_to_keycode(0, (keymatrix_t){ (keypos_t){.row = r, .col = c }, .matrix=0 })) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -238,7 +238,8 @@ void keyboard_task(void)
 | 
			
		|||
                for (uint8_t c = 0; c < MATRIX_COLS; c++) {
 | 
			
		||||
                    if (matrix_change & ((matrix_row_t)1<<c)) {
 | 
			
		||||
                        action_exec((keyevent_t){
 | 
			
		||||
                            .key = (keypos_t){ .row = r, .col = c },
 | 
			
		||||
                            // The main matrix is always 0
 | 
			
		||||
                            .key = (keymatrix_t){.pos = (keypos_t){ .row = r, .col = c }, .matrix = 0},
 | 
			
		||||
                            .pressed = (matrix_row & ((matrix_row_t)1<<c)),
 | 
			
		||||
                            .time = (timer_read() | 1) /* time should not be 0 */
 | 
			
		||||
                        });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,27 +32,33 @@ typedef struct {
 | 
			
		|||
    uint8_t row;
 | 
			
		||||
} keypos_t;
 | 
			
		||||
 | 
			
		||||
/* the key and matrix position */
 | 
			
		||||
typedef struct {
 | 
			
		||||
  keypos_t pos;
 | 
			
		||||
  uint8_t matrix;
 | 
			
		||||
} keymatrix_t;
 | 
			
		||||
 | 
			
		||||
/* key event */
 | 
			
		||||
typedef struct {
 | 
			
		||||
    keypos_t key;
 | 
			
		||||
    keymatrix_t    key;
 | 
			
		||||
    bool     pressed;
 | 
			
		||||
    uint16_t time;
 | 
			
		||||
} keyevent_t;
 | 
			
		||||
 | 
			
		||||
/* equivalent test of keypos_t */
 | 
			
		||||
#define KEYEQ(keya, keyb)       ((keya).row == (keyb).row && (keya).col == (keyb).col)
 | 
			
		||||
/* equivalent test of keymatrix_t */
 | 
			
		||||
#define KEYEQ(keya, keyb)       (keya.pos.row == keyb.pos.row && keya.pos.col == keyb.pos.col && keya.matrix == keyb.matrix)
 | 
			
		||||
 | 
			
		||||
/* Rules for No Event:
 | 
			
		||||
 * 1) (time == 0) to handle (keyevent_t){} as empty event
 | 
			
		||||
 * 2) Matrix(255, 255) to make TICK event available
 | 
			
		||||
 */
 | 
			
		||||
static inline bool IS_NOEVENT(keyevent_t event) { return event.time == 0 || (event.key.row == 255 && event.key.col == 255); }
 | 
			
		||||
static inline bool IS_NOEVENT(keyevent_t event) { return event.time == 0 || (event.key.pos.row == 255 && event.key.pos.col == 255); }
 | 
			
		||||
static inline bool IS_PRESSED(keyevent_t event) { return (!IS_NOEVENT(event) && event.pressed); }
 | 
			
		||||
static inline bool IS_RELEASED(keyevent_t event) { return (!IS_NOEVENT(event) && !event.pressed); }
 | 
			
		||||
 | 
			
		||||
/* Tick event */
 | 
			
		||||
#define TICK                    (keyevent_t){           \
 | 
			
		||||
    .key = (keypos_t){ .row = 255, .col = 255 },           \
 | 
			
		||||
    .key = (keymatrix_t){ .pos = (keypos_t){.row = 255, .col = 255}, .matrix = 0 },           \
 | 
			
		||||
    .pressed = false,                                   \
 | 
			
		||||
    .time = (timer_read() | 1)                          \
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue