Add encoder abstraction. (#21548)
This commit is contained in:
		
							parent
							
								
									2eb9ff8efd
								
							
						
					
					
						commit
						9d9cdaaa2d
					
				
					 50 changed files with 863 additions and 653 deletions
				
			
		| 
						 | 
				
			
			@ -66,8 +66,6 @@ uint8_t  OptLowPin         = OPT_ENC1;
 | 
			
		|||
bool     debug_encoder     = false;
 | 
			
		||||
bool     is_drag_scroll    = false;
 | 
			
		||||
 | 
			
		||||
__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { return true; }
 | 
			
		||||
 | 
			
		||||
bool encoder_update_kb(uint8_t index, bool clockwise) {
 | 
			
		||||
    if (!encoder_update_user(index, clockwise)) {
 | 
			
		||||
        return false;
 | 
			
		||||
| 
						 | 
				
			
			@ -83,7 +81,15 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
 | 
			
		|||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void process_wheel(void) {
 | 
			
		||||
 | 
			
		||||
void encoder_driver_init(void) {
 | 
			
		||||
    setPinInput(OPT_ENC1);
 | 
			
		||||
    setPinInput(OPT_ENC2);
 | 
			
		||||
 | 
			
		||||
    opt_encoder_init();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void encoder_driver_task(void) {
 | 
			
		||||
    // TODO: Replace this with interrupt driven code,  polling is S L O W
 | 
			
		||||
    // Lovingly ripped from the Ploopy Source
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -112,11 +118,10 @@ void process_wheel(void) {
 | 
			
		|||
    int dir = opt_encoder_handler(p1, p2);
 | 
			
		||||
 | 
			
		||||
    if (dir == 0) return;
 | 
			
		||||
    encoder_update_kb(0, dir > 0);
 | 
			
		||||
    encoder_queue_event(0, dir == 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
 | 
			
		||||
    process_wheel();
 | 
			
		||||
 | 
			
		||||
    if (is_drag_scroll) {
 | 
			
		||||
#ifdef PLOOPY_DRAGSCROLL_H_INVERT
 | 
			
		||||
| 
						 | 
				
			
			@ -189,9 +194,6 @@ void keyboard_pre_init_kb(void) {
 | 
			
		|||
    // debug_mouse   = true;
 | 
			
		||||
    // debug_encoder = true;
 | 
			
		||||
 | 
			
		||||
    setPinInput(OPT_ENC1);
 | 
			
		||||
    setPinInput(OPT_ENC2);
 | 
			
		||||
 | 
			
		||||
    /* Ground all output pins connected to ground. This provides additional
 | 
			
		||||
     * pathways to ground. If you're messing with this, know this: driving ANY
 | 
			
		||||
     * of these pins high will cause a short. On the MCU. Ka-blooey.
 | 
			
		||||
| 
						 | 
				
			
			@ -216,8 +218,6 @@ void keyboard_pre_init_kb(void) {
 | 
			
		|||
 | 
			
		||||
void pointing_device_init_kb(void) {
 | 
			
		||||
    pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
 | 
			
		||||
    // initialize the scroll wheel's optical encoder
 | 
			
		||||
    opt_encoder_init();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void eeconfig_init_kb(void) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue