diff options
| author | tmk <nobody@nowhere> | 2013-03-26 16:55:45 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-03-27 15:18:08 +0900 |
| commit | afc3148e2341e4be982cdb628543e30923cfdaf7 (patch) | |
| tree | 523679724e32be013ba461a779c088912c5a72f8 /protocol/lufa/lufa.c | |
| parent | 2c0bb5e7e620b0472f110d2cbc5768bb6d97eec5 (diff) | |
| download | qmk_firmware-afc3148e2341e4be982cdb628543e30923cfdaf7.tar.gz qmk_firmware-afc3148e2341e4be982cdb628543e30923cfdaf7.zip | |
Add supsend and wakeup to pjrc stack
Diffstat (limited to 'protocol/lufa/lufa.c')
| -rw-r--r-- | protocol/lufa/lufa.c | 87 |
1 files changed, 4 insertions, 83 deletions
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index 127dece54..7c7072090 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c | |||
| @@ -36,20 +36,18 @@ | |||
| 36 | this software. | 36 | this software. |
| 37 | */ | 37 | */ |
| 38 | 38 | ||
| 39 | #include <avr/sleep.h> | ||
| 40 | #include <avr/wdt.h> | ||
| 41 | #include "report.h" | 39 | #include "report.h" |
| 42 | #include "host.h" | 40 | #include "host.h" |
| 43 | #include "host_driver.h" | 41 | #include "host_driver.h" |
| 44 | #include "keyboard.h" | 42 | #include "keyboard.h" |
| 45 | #include "action.h" | 43 | #include "action.h" |
| 46 | #include "matrix.h" | ||
| 47 | #include "led.h" | 44 | #include "led.h" |
| 48 | #include "sendchar.h" | 45 | #include "sendchar.h" |
| 49 | #include "debug.h" | 46 | #include "debug.h" |
| 50 | #ifdef SLEEP_LED_ENABLE | 47 | #ifdef SLEEP_LED_ENABLE |
| 51 | #include "sleep_led.h" | 48 | #include "sleep_led.h" |
| 52 | #endif | 49 | #endif |
| 50 | #include "suspend.h" | ||
| 53 | 51 | ||
| 54 | #include "descriptor.h" | 52 | #include "descriptor.h" |
| 55 | #include "lufa.h" | 53 | #include "lufa.h" |
| @@ -170,9 +168,7 @@ void EVENT_USB_Device_Suspend() | |||
| 170 | 168 | ||
| 171 | void EVENT_USB_Device_WakeUp() | 169 | void EVENT_USB_Device_WakeUp() |
| 172 | { | 170 | { |
| 173 | // initialize | 171 | suspend_wakeup_init(); |
| 174 | matrix_init(); | ||
| 175 | clear_keyboard(); | ||
| 176 | 172 | ||
| 177 | #ifdef SLEEP_LED_ENABLE | 173 | #ifdef SLEEP_LED_ENABLE |
| 178 | sleep_led_disable(); | 174 | sleep_led_disable(); |
| @@ -503,32 +499,6 @@ static void SetupHardware(void) | |||
| 503 | USB_Device_EnableSOFEvents(); | 499 | USB_Device_EnableSOFEvents(); |
| 504 | } | 500 | } |
| 505 | 501 | ||
| 506 | |||
| 507 | static bool wakeup_condition(void) | ||
| 508 | { | ||
| 509 | matrix_scan(); | ||
| 510 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { | ||
| 511 | if (matrix_get_row(r)) return true; | ||
| 512 | } | ||
| 513 | return false; | ||
| 514 | } | ||
| 515 | |||
| 516 | #define wdt_intr_enable(value) \ | ||
| 517 | __asm__ __volatile__ ( \ | ||
| 518 | "in __tmp_reg__,__SREG__" "\n\t" \ | ||
| 519 | "cli" "\n\t" \ | ||
| 520 | "wdr" "\n\t" \ | ||
| 521 | "sts %0,%1" "\n\t" \ | ||
| 522 | "out __SREG__,__tmp_reg__" "\n\t" \ | ||
| 523 | "sts %0,%2" "\n\t" \ | ||
| 524 | : /* no outputs */ \ | ||
| 525 | : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ | ||
| 526 | "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \ | ||
| 527 | "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \ | ||
| 528 | _BV(WDIE) | (value & 0x07)) ) \ | ||
| 529 | : "r0" \ | ||
| 530 | ) | ||
| 531 | |||
| 532 | int main(void) __attribute__ ((weak)); | 502 | int main(void) __attribute__ ((weak)); |
| 533 | int main(void) | 503 | int main(void) |
| 534 | { | 504 | { |
| @@ -541,42 +511,10 @@ int main(void) | |||
| 541 | sei(); | 511 | sei(); |
| 542 | 512 | ||
| 543 | while (1) { | 513 | while (1) { |
| 544 | // while suspend | ||
| 545 | while (USB_DeviceState == DEVICE_STATE_Suspended) { | 514 | while (USB_DeviceState == DEVICE_STATE_Suspended) { |
| 546 | #ifndef NO_SUSPEND_POWER_DOWN | 515 | suspend_power_down(); |
| 547 | // Enable watchdog to wake from MCU sleep | 516 | if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { |
| 548 | cli(); | ||
| 549 | wdt_reset(); | ||
| 550 | |||
| 551 | // Watchdog Interrupt and System Reset Mode | ||
| 552 | //wdt_enable(WDTO_1S); | ||
| 553 | //WDTCSR |= _BV(WDIE); | ||
| 554 | |||
| 555 | // Watchdog Interrupt Mode | ||
| 556 | wdt_intr_enable(WDTO_120MS); | ||
| 557 | |||
| 558 | // TODO: more power saving | ||
| 559 | // See PicoPower application note | ||
| 560 | // - I/O port input with pullup | ||
| 561 | // - prescale clock | ||
| 562 | // - BOD disable | ||
| 563 | // - Power Reduction Register PRR | ||
| 564 | // sleep in power down mode | ||
| 565 | set_sleep_mode(SLEEP_MODE_PWR_DOWN); | ||
| 566 | sleep_enable(); | ||
| 567 | sei(); | ||
| 568 | sleep_cpu(); | ||
| 569 | sleep_disable(); | ||
| 570 | |||
| 571 | // Disable watchdog after sleep | ||
| 572 | wdt_disable(); | ||
| 573 | #endif | ||
| 574 | |||
| 575 | // Send request of USB Wakeup from Suspend to host | ||
| 576 | if (USB_Device_RemoteWakeupEnabled) { | ||
| 577 | if (wakeup_condition()) { | ||
| 578 | USB_Device_SendRemoteWakeup(); | 517 | USB_Device_SendRemoteWakeup(); |
| 579 | } | ||
| 580 | } | 518 | } |
| 581 | } | 519 | } |
| 582 | 520 | ||
| @@ -587,20 +525,3 @@ int main(void) | |||
| 587 | #endif | 525 | #endif |
| 588 | } | 526 | } |
| 589 | } | 527 | } |
| 590 | |||
| 591 | #ifndef NO_SUSPEND_POWER_DOWN | ||
| 592 | /* watchdog timeout */ | ||
| 593 | ISR(WDT_vect) | ||
| 594 | { | ||
| 595 | /* wakeup from MCU sleep mode */ | ||
| 596 | /* | ||
| 597 | // blink LED | ||
| 598 | static uint8_t led_state = 0; | ||
| 599 | static uint8_t led_count = 0; | ||
| 600 | led_count++; | ||
| 601 | if ((led_count & 0x07) == 0) { | ||
| 602 | led_set((led_state ^= (1<<USB_LED_CAPS_LOCK))); | ||
| 603 | } | ||
| 604 | */ | ||
| 605 | } | ||
| 606 | #endif | ||
