mirror of
				https://github.com/mfulz/qmk_firmware.git
				synced 2025-11-04 07:12:33 +01:00 
			
		
		
		
	support LEDs
This commit is contained in:
		
							parent
							
								
									a43ae7c92f
								
							
						
					
					
						commit
						7e9ca9a976
					
				@ -1,28 +1,46 @@
 | 
				
			|||||||
#include "frosty_flake.h"
 | 
					#include "frosty_flake.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void matrix_init_kb(void) {
 | 
					void matrix_init_kb(void) {
 | 
				
			||||||
	// put your keyboard start-up code here
 | 
					    // put your keyboard start-up code here
 | 
				
			||||||
	// runs once when the firmware starts up
 | 
					    // runs once when the firmware starts up
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	matrix_init_user();
 | 
					    matrix_init_user();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void matrix_scan_kb(void) {
 | 
					void matrix_scan_kb(void) {
 | 
				
			||||||
	// put your looping keyboard code here
 | 
					    // put your looping keyboard code here
 | 
				
			||||||
	// runs every cycle (a lot)
 | 
					    // runs every cycle (a lot)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	matrix_scan_user();
 | 
					    matrix_scan_user();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
 | 
					bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
 | 
				
			||||||
	// put your per-action keyboard code here
 | 
					    // put your per-action keyboard code here
 | 
				
			||||||
	// runs for every action, just before processing by the firmware
 | 
					    // runs for every action, just before processing by the firmware
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return process_record_user(keycode, record);
 | 
					    return process_record_user(keycode, record);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void led_set_kb(uint8_t usb_led) {
 | 
					void led_set_kb(uint8_t usb_led) {
 | 
				
			||||||
	// put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
 | 
					    DDRB |= (1<<7);
 | 
				
			||||||
 | 
					    DDRC |= (1<<5) | (1<<6);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	led_set_user(usb_led);
 | 
					    print_dec(usb_led);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (usb_led & (1<<USB_LED_CAPS_LOCK))
 | 
				
			||||||
 | 
					        PORTC &= ~(1<<5);
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        PORTC |=  (1<<5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (usb_led & (1<<USB_LED_NUM_LOCK))
 | 
				
			||||||
 | 
					        PORTB &= ~(1<<7);
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        PORTB |=  (1<<7);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (usb_led & (1<<USB_LED_SCROLL_LOCK))
 | 
				
			||||||
 | 
					        PORTC &= ~(1<<6);
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        PORTC |=  (1<<6);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    led_set_user(usb_led);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -24,17 +24,6 @@
 | 
				
			|||||||
#include "util.h"
 | 
					#include "util.h"
 | 
				
			||||||
#include "matrix.h"
 | 
					#include "matrix.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define CONFIG_LED_IO \
 | 
					 | 
				
			||||||
  DDRB |= (1<<7); \
 | 
					 | 
				
			||||||
  DDRC |= (1<<5) | (1<<6);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define USB_LED_CAPS_LOCK_ON    PORTC &= ~(1<<5)
 | 
					 | 
				
			||||||
#define USB_LED_CAPS_LOCK_OFF   PORTC |=  (1<<5)
 | 
					 | 
				
			||||||
#define USB_LED_NUM_LOCK_ON     PORTB &= ~(1<<7)
 | 
					 | 
				
			||||||
#define USB_LED_NUM_LOCK_OFF    PORTB |=  (1<<7)
 | 
					 | 
				
			||||||
#define USB_LED_SCROLL_LOCK_ON  PORTC &= ~(1<<6)
 | 
					 | 
				
			||||||
#define USB_LED_SCROLL_LOCK_OFF PORTC |=  (1<<6)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef DEBOUNCING_DELAY
 | 
					#ifndef DEBOUNCING_DELAY
 | 
				
			||||||
#   define DEBOUNCING_DELAY 5
 | 
					#   define DEBOUNCING_DELAY 5
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@ -62,34 +51,34 @@ void matrix_init(void) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint8_t matrix_scan(void) {
 | 
					uint8_t matrix_scan(void) {
 | 
				
			||||||
  for (uint8_t col = 0; col < MATRIX_COLS; col++) {
 | 
					    for (uint8_t col = 0; col < MATRIX_COLS; col++) {
 | 
				
			||||||
    select_col(col);
 | 
					        select_col(col);
 | 
				
			||||||
    _delay_us(3);
 | 
					        _delay_us(3);
 | 
				
			||||||
    matrix_row_t col_scan = scan_col();
 | 
					        matrix_row_t col_scan = scan_col();
 | 
				
			||||||
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
 | 
					        for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
 | 
				
			||||||
      bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1<<col);
 | 
					            bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1<<col);
 | 
				
			||||||
      bool curr_bit = col_scan & (1<<row);
 | 
					            bool curr_bit = col_scan & (1<<row);
 | 
				
			||||||
      if (prev_bit != curr_bit) {
 | 
					            if (prev_bit != curr_bit) {
 | 
				
			||||||
        matrix_debouncing[row] ^= ((matrix_row_t)1<<col);
 | 
					                matrix_debouncing[row] ^= ((matrix_row_t)1<<col);
 | 
				
			||||||
        debouncing = DEBOUNCING_DELAY;
 | 
					                debouncing = DEBOUNCING_DELAY;
 | 
				
			||||||
      }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (debouncing) {
 | 
					    if (debouncing) {
 | 
				
			||||||
    if (--debouncing)
 | 
					        if (--debouncing)
 | 
				
			||||||
      _delay_ms(1);
 | 
					            _delay_ms(1);
 | 
				
			||||||
    else
 | 
					        else
 | 
				
			||||||
      for (uint8_t i = 0; i < MATRIX_ROWS; i++)
 | 
					            for (uint8_t i = 0; i < MATRIX_ROWS; i++)
 | 
				
			||||||
        matrix[i] = matrix_debouncing[i];
 | 
					                matrix[i] = matrix_debouncing[i];
 | 
				
			||||||
  }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  matrix_scan_quantum();
 | 
					    matrix_scan_quantum();
 | 
				
			||||||
  return 1;
 | 
					    return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
inline matrix_row_t matrix_get_row(uint8_t row) {
 | 
					inline matrix_row_t matrix_get_row(uint8_t row) {
 | 
				
			||||||
  return matrix[row];
 | 
					    return matrix[row];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void matrix_print(void) {
 | 
					void matrix_print(void) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user