power_down(WDTO_15MS); | power_down(WDTO_15MS); | ||||
} | } | ||||
__attribute__ ((weak)) void matrix_power_up(void) {} | |||||
__attribute__ ((weak)) void matrix_power_down(void) {} | |||||
bool suspend_wakeup_condition(void) | bool suspend_wakeup_condition(void) | ||||
{ | { | ||||
matrix_power_up(); | matrix_power_up(); |
#endif | #endif | ||||
__attribute__ ((weak)) void matrix_setup(void) {} | |||||
void keyboard_setup(void) | |||||
{ | |||||
matrix_setup(); | |||||
} | |||||
void keyboard_init(void) | void keyboard_init(void) | ||||
{ | { | ||||
timer_init(); | timer_init(); |
} | } | ||||
/* it runs once at early stage of startup before keyboard_init. */ | |||||
void keyboard_setup(void); | |||||
/* it runs once after initializing host side protocol, debug and MCU peripherals. */ | |||||
void keyboard_init(void); | void keyboard_init(void); | ||||
/* it runs repeatedly in main loop */ | |||||
void keyboard_task(void); | void keyboard_task(void); | ||||
/* it runs when host LED status is updated */ | |||||
void keyboard_set_leds(uint8_t leds); | void keyboard_set_leds(uint8_t leds); | ||||
__attribute__ ((weak)) void matrix_power_up(void) {} | |||||
__attribute__ ((weak)) void matrix_power_down(void) {} | |||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
} | } | ||||
#endif | #endif |
uint8_t matrix_rows(void); | uint8_t matrix_rows(void); | ||||
/* number of matrix columns */ | /* number of matrix columns */ | ||||
uint8_t matrix_cols(void); | uint8_t matrix_cols(void); | ||||
/* intialize matrix for scaning. should be called once. */ | |||||
/* should be called at early stage of startup before matrix_init.(optional) */ | |||||
void matrix_setup(void); | |||||
/* intialize matrix for scaning. */ | |||||
void matrix_init(void); | void matrix_init(void); | ||||
/* scan all key states on matrix */ | /* scan all key states on matrix */ | ||||
uint8_t matrix_scan(void); | uint8_t matrix_scan(void); |
/******************************************************************************* | /******************************************************************************* | ||||
* main | * main | ||||
******************************************************************************/ | ******************************************************************************/ | ||||
static void SetupHardware(void) | |||||
static void setup_mcu(void) | |||||
{ | { | ||||
/* Disable watchdog if enabled by bootloader/fuses */ | /* Disable watchdog if enabled by bootloader/fuses */ | ||||
MCUSR &= ~(1 << WDRF); | MCUSR &= ~(1 << WDRF); | ||||
/* Disable clock division */ | /* Disable clock division */ | ||||
clock_prescale_set(clock_div_1); | clock_prescale_set(clock_div_1); | ||||
} | |||||
static void setup_usb(void) | |||||
{ | |||||
// Leonardo needs. Without this USB device is not recognized. | // Leonardo needs. Without this USB device is not recognized. | ||||
USB_Disable(); | USB_Disable(); | ||||
int main(void) __attribute__ ((weak)); | int main(void) __attribute__ ((weak)); | ||||
int main(void) | int main(void) | ||||
{ | { | ||||
SetupHardware(); | |||||
setup_mcu(); | |||||
keyboard_setup(); | |||||
setup_usb(); | |||||
sei(); | sei(); | ||||
/* wait for USB startup & debug output */ | /* wait for USB startup & debug output */ |
// set for 16 MHz clock | // set for 16 MHz clock | ||||
CPU_PRESCALE(0); | CPU_PRESCALE(0); | ||||
keyboard_setup(); | |||||
// Initialize the USB, and then wait for the host to set configuration. | // Initialize the USB, and then wait for the host to set configuration. | ||||
// If the Teensy is powered without a PC connected to the USB port, | // If the Teensy is powered without a PC connected to the USB port, | ||||
// this will wait forever. | // this will wait forever. |