I woke my Mac from sleep with a teensy 3.0

Status
Not open for further replies.

daperl

Well-known member
Here's the diff of usb_desc.c:

Code:
--- usb_desc.c.fail	2014-09-10 13:31:49.000000000 -0700
+++ usb_desc.c	2014-09-15 16:29:19.000000000 -0700
@@ -316,7 +316,8 @@
         NUM_INTERFACE,                          // bNumInterfaces
         1,                                      // bConfigurationValue
         0,                                      // iConfiguration
-        0xC0,                                   // bmAttributes
+        // daperl 0xC0,                         // bmAttributes
+        0xA0,                                   // bmAttributes
         50,                                     // bMaxPower
 
 #ifdef CDC_IAD_DESCRIPTOR

Here's an example sketch [Take note of the bold, blue code]:

Code:
/* Buttons to USB Keyboard Example - Special Media Player Keys

   You must select Keyboard from the "Tools > USB Type" menu

   This example code is in the public domain.
*/

#include <Bounce.h>

// Create Bounce objects for each button.  The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10);  // 10 ms debounce time is appropriate
Bounce button2 = Bounce(2, 10);  // for most mechanical pushbuttons
Bounce button3 = Bounce(3, 10);
Bounce button4 = Bounce(4, 10);  // if a button is too "sensitive" 
Bounce button5 = Bounce(5, 10);  // you can increase this time.

void setup() {
  // Configure the pins for input mode with pullup resistors.
  // The pushbuttons connect from each pin to ground.  When
  // the button is pressed, the pin reads LOW because the button
  // shorts it to ground.  When released, the pin reads HIGH
  // because the pullup resistor connects to +5 volts inside
  // the chip.
  //pinMode(0, INPUT_PULLUP);
  //pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  //pinMode(5, INPUT_PULLUP);
}

void loop() {
  // Update all the buttons.  There should not be any long
  // delays in loop(), so this runs repetitively at a rate
  // faster than the buttons could be pressed and released.
  button0.update();
  button1.update();
  button2.update();
  button3.update();
  button4.update();
  button5.update();

  // Check each button for "falling" edge.
  // falling = high (not pressed - voltage from pullup resistor)
  //           to low (pressed - button connects pin to ground)
  if (button0.fallingEdge()) {
    Keyboard.set_media(KEY_MEDIA_PREV_TRACK);
    Keyboard.send_now();	// send the button press
    Keyboard.set_media(0);
    Keyboard.send_now();	// send the button release
  }
  if (button1.fallingEdge()) {
    Keyboard.set_media(KEY_MEDIA_PLAY_PAUSE);
    Keyboard.send_now();
    Keyboard.set_media(0);
    Keyboard.send_now();
  }
  if (button2.fallingEdge()) {
    Keyboard.set_media(KEY_MEDIA_NEXT_TRACK);
    Keyboard.send_now();
    Keyboard.set_media(0);
    Keyboard.send_now();
  }
  if (button3.fallingEdge()) {
    Keyboard.set_media(KEY_MEDIA_VOLUME_DEC);
    Keyboard.send_now();
    Keyboard.set_media(0);
    Keyboard.send_now();
  }
  if (button4.fallingEdge()) {
[B][COLOR="#0000FF"]    uint8_t tmp = USB0_CTL;
    USB0_CTL |= USB_CTL_RESUME;
    delay(12);
    USB0_CTL = tmp;
[/COLOR][/B]#if 0
    Keyboard.set_media(KEY_MEDIA_VOLUME_INC);
    Keyboard.send_now();
    Keyboard.set_media(0);
    Keyboard.send_now();
#endif
  }
  if (button5.fallingEdge()) {
    Keyboard.set_media(KEY_MEDIA_EJECT);
    Keyboard.send_now();
    delay(300);  // Mac OS-X will not recognize a very short eject press
    Keyboard.set_media(0);
    Keyboard.send_now();
  }

}

This seems to be in line with the following text from the "7.1.4.5 Resume" section of the "Universal Serial Bus Specification, Rev. 1.0, January 15, 1996":

"The remote wake-up device must hold the resume signaling for at least 10 ms and no more than 15 ms."
 
Status
Not open for further replies.
Back
Top