Make debounce() signal changes in the cooked matrix as return value (#17554)
This commit is contained in:
		
							parent
							
								
									cca5d35321
								
							
						
					
					
						commit
						8224f62806
					
				
					 13 changed files with 83 additions and 39 deletions
				
			
		| 
						 | 
				
			
			@ -48,6 +48,7 @@ typedef uint8_t debounce_counter_t;
 | 
			
		|||
static debounce_counter_t *debounce_counters;
 | 
			
		||||
static fast_timer_t        last_time;
 | 
			
		||||
static bool                counters_need_update;
 | 
			
		||||
static bool                cooked_changed;
 | 
			
		||||
 | 
			
		||||
#    define DEBOUNCE_ELAPSED 0
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -70,8 +71,9 @@ void debounce_free(void) {
 | 
			
		|||
    debounce_counters = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) {
 | 
			
		||||
bool debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) {
 | 
			
		||||
    bool updated_last = false;
 | 
			
		||||
    cooked_changed    = false;
 | 
			
		||||
 | 
			
		||||
    if (counters_need_update) {
 | 
			
		||||
        fast_timer_t now          = timer_read_fast();
 | 
			
		||||
| 
						 | 
				
			
			@ -95,6 +97,8 @@ void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool
 | 
			
		|||
 | 
			
		||||
        start_debounce_counters(raw, cooked, num_rows);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return cooked_changed;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time) {
 | 
			
		||||
| 
						 | 
				
			
			@ -104,8 +108,10 @@ static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[],
 | 
			
		|||
        for (uint8_t col = 0; col < MATRIX_COLS; col++) {
 | 
			
		||||
            if (*debounce_pointer != DEBOUNCE_ELAPSED) {
 | 
			
		||||
                if (*debounce_pointer <= elapsed_time) {
 | 
			
		||||
                    *debounce_pointer = DEBOUNCE_ELAPSED;
 | 
			
		||||
                    cooked[row]       = (cooked[row] & ~(ROW_SHIFTER << col)) | (raw[row] & (ROW_SHIFTER << col));
 | 
			
		||||
                    *debounce_pointer        = DEBOUNCE_ELAPSED;
 | 
			
		||||
                    matrix_row_t cooked_next = (cooked[row] & ~(ROW_SHIFTER << col)) | (raw[row] & (ROW_SHIFTER << col));
 | 
			
		||||
                    cooked_changed |= cooked[row] ^ cooked_next;
 | 
			
		||||
                    cooked[row] = cooked_next;
 | 
			
		||||
                } else {
 | 
			
		||||
                    *debounce_pointer -= elapsed_time;
 | 
			
		||||
                    counters_need_update = true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue