support LEDs

This commit is contained in:
Gabriel Young 2017-03-19 20:45:10 -07:00
parent a43ae7c92f
commit 7e9ca9a976
2 changed files with 51 additions and 44 deletions

View file

@ -1,28 +1,46 @@
#include "frosty_flake.h"
void matrix_init_kb(void) {
// put your keyboard start-up code here
// runs once when the firmware starts up
// put your keyboard start-up code here
// runs once when the firmware starts up
matrix_init_user();
matrix_init_user();
}
void matrix_scan_kb(void) {
// put your looping keyboard code here
// runs every cycle (a lot)
// put your looping keyboard code here
// runs every cycle (a lot)
matrix_scan_user();
matrix_scan_user();
}
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
// put your per-action keyboard code here
// runs for every action, just before processing by the firmware
// put your per-action keyboard code here
// 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) {
// 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);
}

View file

@ -24,17 +24,6 @@
#include "util.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
# define DEBOUNCING_DELAY 5
#endif
@ -62,34 +51,34 @@ void matrix_init(void) {
}
uint8_t matrix_scan(void) {
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
select_col(col);
_delay_us(3);
matrix_row_t col_scan = scan_col();
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1<<col);
bool curr_bit = col_scan & (1<<row);
if (prev_bit != curr_bit) {
matrix_debouncing[row] ^= ((matrix_row_t)1<<col);
debouncing = DEBOUNCING_DELAY;
}
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
select_col(col);
_delay_us(3);
matrix_row_t col_scan = scan_col();
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1<<col);
bool curr_bit = col_scan & (1<<row);
if (prev_bit != curr_bit) {
matrix_debouncing[row] ^= ((matrix_row_t)1<<col);
debouncing = DEBOUNCING_DELAY;
}
}
}
}
if (debouncing) {
if (--debouncing)
_delay_ms(1);
else
for (uint8_t i = 0; i < MATRIX_ROWS; i++)
matrix[i] = matrix_debouncing[i];
}
if (debouncing) {
if (--debouncing)
_delay_ms(1);
else
for (uint8_t i = 0; i < MATRIX_ROWS; i++)
matrix[i] = matrix_debouncing[i];
}
matrix_scan_quantum();
return 1;
matrix_scan_quantum();
return 1;
}
inline matrix_row_t matrix_get_row(uint8_t row) {
return matrix[row];
return matrix[row];
}
void matrix_print(void) {