Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB-USB: suspend/wake support for keyboard #769

Closed
4 tasks done
tmk opened this issue Dec 11, 2023 · 4 comments
Closed
4 tasks done

USB-USB: suspend/wake support for keyboard #769

tmk opened this issue Dec 11, 2023 · 4 comments

Comments

@tmk
Copy link
Owner

tmk commented Dec 11, 2023

Problem

The converter does not support to suspend a keyboard. MAX3421E and keyboard keep drawing power while computer is sleeping.

TODO

  • Add suspend and wake support to USB_Host_Shield_2.0
  • Add retmote wakeup support to USB_Host_Shield_2.0
  • Converter suspends a keyboard while sleeping
  • MAX3421E power saving
@tmk tmk added the TODO label Dec 11, 2023
@tmk
Copy link
Owner Author

tmk commented Dec 14, 2023

MAX3421e RWUIRQ issue

Seemingly RWUIRQ is not triggered with remote wakeup from some devices. This seems to depend on remote wake implementation and singnal term(1-15ms).

RWUIRQ does not work with:

  • TMK Alps64(LUFA) - full speed
  • HHKB Classic - full speed
  • Realforce RGB - full speed

OK with:

  • VARMILO MA109C - full speed
  • Cherry G80-3600 - low speed
  • ThinkPad keyboard 55Y9053 - low speed
  • Poker X - low speed

https://electronics.stackexchange.com/questions/372236/bugs-in-maxim-chip-max3421e-used-as-usb-host

WORK AROUND

Check bus state using SAMPLEBUS and detect remote wakeup signal when bus is K state.

This does not detect remote wakeup signal every time. This can miss it and you will have to hold a key a while or press several times in that case.

        // sample bus
        regWr(rHCTL, bmSAMPLEBUS);
        while(!(regRd(rHCTL) & bmSAMPLEBUS));

        uint8_t bus_sample;
        bus_sample = regRd(rHRSL);
        bus_sample &= (bmJSTATUS | bmKSTATUS);
                  
        if (bus_sample == bmKSTATUS) {
            // K-state means remote wakeup when suspended
        }

tmk/USB_Host_Shield_2.0@001fe4c

@tmk
Copy link
Owner Author

tmk commented Dec 17, 2023

DEVICE_REMOTE_WAKEUP

To enable Remote Wakeup on a device/keyboard
we need to send SET_FEATURE request using ctrlReq() :

        // SET_FEATURE(DEVICE_REMOTE_WAKEUP)                    
        rcode = pUsb->ctrlReq(bAddress,                        
                        0, // End Point: 0                                                                            
                        (USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_STANDARD | USB_SETUP_RECIPIENT_DEVICE), // bmRequestType                                                                                                                 
                        USB_REQUEST_SET_FEATURE,    // bRequest                             
                        USB_FEATURE_DEVICE_REMOTE_WAKEUP, 0,    // wValue             
                        0,  // wIndex                                                             
                        0, 0, NULL, NULL);  // wLength                   
        USBTRACE2("RWU: ", rcode); 

tmk/USB_Host_Shield_2.0@3baa2f0

@tmk
Copy link
Owner Author

tmk commented Dec 20, 2023

Power Saving

Even in host mode MAX3421E can enter into low-power state using PWRDOWN bit,

though document says:

This bit is designed only for peripheral mode usage, although it is accessible in host mode. The
CPU should never set POWERDOWN = 1 when operating as a host.

In low-power state the chip cannot detect and handle any USB events such like remote wakeup, attach and detach. You will have to enumerate and intialize a device after putting out of low-power state.

When enabling remote wakeup we cannot put the chip into the low-power state.

tmk/USB_Host_Shield_2.0@d6d26f9

0966463

tmk added a commit to tmk/USB_Host_Shield_2.0 that referenced this issue Dec 20, 2023
@tmk tmk removed the TODO label Dec 30, 2023
@tmk tmk closed this as completed Dec 30, 2023
@tmk
Copy link
Owner Author

tmk commented Jan 9, 2024

Current the converter draws while in "configured"

around 22.3mA in active state

Current the converter draws while in "suspended"

when Remote Wakeup is enabled

The converter draws around 7.8mA(without keyboard) or 8.2mA(with keyboard).

MAX3421 is powered up.

when Remote Wakeup is disabled

The converter draws around 0.1mA.

MAX3421 is powered down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant