Browse Source

Add intial code of RemoteWakeUp

led_matrix
tmk 11 years ago
parent
commit
c8cfde0138
1 changed files with 36 additions and 4 deletions
  1. 36
    4
      protocol/lufa/lufa.c

+ 36
- 4
protocol/lufa/lufa.c View File

/******************************************************************************* /*******************************************************************************
* USB Events * USB Events
******************************************************************************/ ******************************************************************************/
/** Event handler for the USB_Connect event. */
#include "led.h"
void EVENT_USB_Device_Connect(void) void EVENT_USB_Device_Connect(void)
{ {
} }


/** Event handler for the USB_Disconnect event. */
void EVENT_USB_Device_Disconnect(void) void EVENT_USB_Device_Disconnect(void)
{ {
} }


void EVENT_USB_Device_Reset(void)
{
}

void EVENT_USB_Device_Suspend()
{
led_set(1<<USB_LED_CAPS_LOCK);
}

void EVENT_USB_Device_WakeUp()
{
led_set(0);
}

void EVENT_USB_Device_StartOfFrame(void) void EVENT_USB_Device_StartOfFrame(void)
{ {
Console_Task(); Console_Task();
USB_Device_EnableSOFEvents(); USB_Device_EnableSOFEvents();
} }



#include "matrix.h"
static bool wakeup_condition(void)
{
matrix_scan();
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
if (matrix_get_row(r)) return true;
}
return false;
}

int main(void) __attribute__ ((weak)); int main(void) __attribute__ ((weak));
int main(void) int main(void)
{ {
host_set_driver(&lufa_driver); host_set_driver(&lufa_driver);
sei(); sei();


// TODO: can't print here
debug("LUFA init\n");
while (1) { while (1) {
while (USB_DeviceState == DEVICE_STATE_Suspended) {
// TODO: power saving

if (USB_Device_RemoteWakeupEnabled) {
if (wakeup_condition()) {
USB_Device_SendRemoteWakeup();
}
}
}

keyboard_task(); keyboard_task();


#if !defined(INTERRUPT_CONTROL_ENDPOINT) #if !defined(INTERRUPT_CONTROL_ENDPOINT)