/* Copyright 2012 Jun Wako * * This is heavily based on phantom/board.{c|h}. * https://github.com/BathroomEpiphanies/AVR-Keyboard * * Copyright (c) 2012 Fredrik Atmer, Bathroom Epiphanies Inc * http://bathroomepiphanies.com * * As for liscensing consult with the original files or its author. */ #include #include #include #include #include "print.h" #include "debug.h" #include "util.h" #include "matrix.h" #ifndef DEBOUNCE # define DEBOUNCE 0 #endif static uint8_t debouncing = DEBOUNCE; // bit array of key state(1:on, 0:off) static matrix_row_t matrix[MATRIX_ROWS]; static matrix_row_t matrix_debouncing[MATRIX_ROWS]; static uint8_t read_rows(void); static void init_rows(void); static void unselect_cols(void); static void select_col(uint8_t col); #ifndef SLEEP_LED_ENABLE /* LEDs are on output compare pins OC1B OC1C This activates fast PWM mode on them. Prescaler 256 and 8-bit counter results in 16000000/256/256 = 244 Hz blink frequency. LED_A: Caps Lock LED_B: Scroll Lock */ /* Output on PWM pins are turned off when the timer reaches the value in the output compare register, and are turned on when it reaches TOP (=256). */ static void setup_leds(void) { TCCR1A |= // Timer control register 1A (1< PORTB6, LED_B -> PORTB7 DDRB |= (1<<6) | (1<<7); PORTB &= ~((1<<6) | (1<<7)); } #endif inline uint8_t matrix_rows(void) { return MATRIX_ROWS; } inline uint8_t matrix_cols(void) { return MATRIX_COLS; } void matrix_init(void) { // To use PORTF disable JTAG with writing JTD bit twice within four cycles. MCUCR |= (1<