Support USB Suspend.
authorNIIBE Yutaka <gniibe@fsij.org>
Thu, 18 Jan 2018 06:07:00 +0000 (15:07 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Thu, 18 Jan 2018 06:07:00 +0000 (15:07 +0900)
ChangeLog
src/main.c

index 6693ffc..d9973c3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2018-01-18  NIIBE Yutaka  <gniibe@fsij.org>
 
+       * src/main.c (main, usb_main): Support USB suspend.
+
+2018-01-18  NIIBE Yutaka  <gniibe@fsij.org>
+
        * src/neug.c: Update from Gnuk.
 
        * src/Makefile (USE_EVENTFLAG): Enable.
index 6fe943c..e55a2ef 100644 (file)
@@ -44,6 +44,9 @@
 #endif
 #include "adc.h"
 
+#define RANDOM_BYTES_LENGTH 64
+static uint32_t random_word[RANDOM_BYTES_LENGTH/sizeof (uint32_t)];
+
 enum {
   FSIJ_DEVICE_RUNNING = 0,
   FSIJ_DEVICE_EXITED,
@@ -806,62 +809,73 @@ usb_main (void *arg)
              {
              case USB_EVENT_DEVICE_RESET:
                usb_device_reset (&dev);
-               continue;
+               break;
 
              case USB_EVENT_DEVICE_ADDRESSED:
                chopstx_mutex_lock (&usb_mtx);
                bDeviceState = USB_DEVICE_STATE_ADDRESSED;
                chopstx_cond_signal (&usb_cnd);
                chopstx_mutex_unlock (&usb_mtx);
-               continue;
+               break;
 
              case USB_EVENT_GET_DESCRIPTOR:
                if (usb_get_descriptor (&dev) < 0)
                  usb_lld_ctrl_error (&dev);
-               continue;
+               break;
 
              case USB_EVENT_SET_CONFIGURATION:
                if (usb_set_configuration (&dev) < 0)
                  usb_lld_ctrl_error (&dev);
-               continue;
+               break;
 
              case USB_EVENT_SET_INTERFACE:
                if (usb_set_interface (&dev) < 0)
                  usb_lld_ctrl_error (&dev);
-               continue;
+               break;
 
              case USB_EVENT_CTRL_REQUEST:
                /* Device specific device request.  */
                if (usb_setup (&dev) < 0)
                  usb_lld_ctrl_error (&dev);
-               continue;
+               break;
 
              case USB_EVENT_GET_STATUS_INTERFACE:
                if (usb_get_status_interface (&dev) < 0)
                  usb_lld_ctrl_error (&dev);
-               continue;
+               break;
 
              case USB_EVENT_GET_INTERFACE:
                if (usb_get_interface (&dev) < 0)
                  usb_lld_ctrl_error (&dev);
-               continue;
+               break;
 
              case USB_EVENT_SET_FEATURE_DEVICE:
              case USB_EVENT_SET_FEATURE_ENDPOINT:
              case USB_EVENT_CLEAR_FEATURE_DEVICE:
              case USB_EVENT_CLEAR_FEATURE_ENDPOINT:
                usb_lld_ctrl_ack (&dev);
-               continue;
+               break;
 
              case USB_EVENT_CTRL_WRITE_FINISH:
                /* Control WRITE transfer finished.  */
                usb_ctrl_write_finish (&dev);
-               continue;
+               break;
 
-             case USB_EVENT_OK:
              case USB_EVENT_DEVICE_SUSPEND:
+               neug_fini ();
+               chopstx_conf_idle (2);
+               bDeviceState |= USB_DEVICE_STATE_SUSPEND;
+               break;
+
+             case USB_EVENT_DEVICE_WAKEUP:
+               chopstx_conf_idle (1);
+               neug_init (random_word, RANDOM_BYTES_LENGTH/sizeof (uint32_t));
+               bDeviceState &= ~USB_DEVICE_STATE_SUSPEND;
+               break;
+
+             case USB_EVENT_OK:
              default:
-               continue;
+               break;
              }
        }
     }
@@ -988,9 +1002,6 @@ led_blinker (void *arg)
   return NULL;
 }
 \f
-#define RANDOM_BYTES_LENGTH 64
-static uint32_t random_word[RANDOM_BYTES_LENGTH/sizeof (uint32_t)];
-
 #ifdef GNU_LINUX_EMULATION
 static uint8_t endp1_buf[RANDOM_BYTES_LENGTH];
 #endif
@@ -1089,6 +1100,8 @@ main (int argc, char **argv)
 
   fill_serial_no_by_unique_id ();
 
+  chopstx_conf_idle (1);
+
   adc_init ();
 
   eventflag_init (&led_event);