summaryrefslogtreecommitdiff
path: root/protocol/pjrc
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-03-26 16:55:45 +0900
committertmk <nobody@nowhere>2013-03-27 15:18:08 +0900
commitafc3148e2341e4be982cdb628543e30923cfdaf7 (patch)
tree523679724e32be013ba461a779c088912c5a72f8 /protocol/pjrc
parent2c0bb5e7e620b0472f110d2cbc5768bb6d97eec5 (diff)
Add supsend and wakeup to pjrc stack
Diffstat (limited to 'protocol/pjrc')
-rw-r--r--protocol/pjrc/main.c17
-rw-r--r--protocol/pjrc/usb.c23
2 files changed, 32 insertions, 8 deletions
diff --git a/protocol/pjrc/main.c b/protocol/pjrc/main.c
index 776bfee9d6..5f15dbf892 100644
--- a/protocol/pjrc/main.c
+++ b/protocol/pjrc/main.c
@@ -31,10 +31,7 @@
#include "print.h"
#include "debug.h"
#include "util.h"
-#include "bootloader.h"
-#ifdef PS2_MOUSE_ENABLE
-# include "ps2_mouse.h"
-#endif
+#include "suspend.h"
#include "host.h"
#include "pjrc.h"
@@ -55,7 +52,17 @@ int main(void)
keyboard_init();
host_set_driver(pjrc_driver());
+#ifdef SLEEP_LED_ENABLE
+ sleep_led_init();
+#endif
while (1) {
- keyboard_task();
+ while (suspend) {
+ suspend_power_down();
+ if (remote_wakeup && suspend_wakeup_condition()) {
+ usb_remote_wakeup();
+ }
+ }
+
+ keyboard_task();
}
}
diff --git a/protocol/pjrc/usb.c b/protocol/pjrc/usb.c
index f4c6f81f5c..a9fbc4638e 100644
--- a/protocol/pjrc/usb.c
+++ b/protocol/pjrc/usb.c
@@ -33,6 +33,8 @@
#include "usb_extra.h"
#include "print.h"
#include "util.h"
+#include "sleep_led.h"
+#include "suspend.h"
/**************************************************************************
@@ -595,7 +597,8 @@ void usb_init(void)
USB_CONFIG(); // start USB clock
UDCON = 0; // enable attach resistor
usb_configuration = 0;
- UDIEN = (1<<EORSTE)|(1<<SOFE)|(1<<SUSPE);
+ suspend = false;
+ UDIEN = (1<<EORSTE)|(1<<SOFE)|(1<<SUSPE)|(1<<WAKEUPE);
sei();
}
@@ -631,9 +634,23 @@ ISR(USB_GEN_vect)
intbits = UDINT;
UDINT = 0;
- if (intbits & (1<<SUSPI)) {
+ if ((intbits & (1<<SUSPI)) && (UDIEN & (1<<SUSPE)) && usb_configuration) {
+#ifdef SLEEP_LED_ENABLE
+ sleep_led_enable();
+#endif
+ UDIEN &= ~(1<<SUSPE);
+ UDIEN |= (1<<WAKEUPE);
suspend = true;
- } else {
+ }
+ if ((intbits & (1<<WAKEUPI)) && (UDIEN & (1<<WAKEUPE)) && usb_configuration) {
+ suspend_wakeup_init();
+#ifdef SLEEP_LED_ENABLE
+ sleep_led_disable();
+#endif
+ led_set(host_keyboard_leds());
+
+ UDIEN |= (1<<SUSPE);
+ UDIEN &= ~(1<<WAKEUPE);
suspend = false;
}
if (intbits & (1<<EORSTI)) {