USB Host port Turn off power from user code

yeahtuna

Well-known member
I'm playing around with using a USB C connector for my USB host port. As part of the USB C spec, power needs to be turned off until you verify that the connected device is an upstream device. How can I toggle the power on/off for the USB host port on T4.1?
 
Looking at T_4.1 schematic EMC_40, it matches this code:
Code:
// void USBHost::begin() :: {??}\arduino-1.8.19\hardware\teensy\avr\libraries\USBHost_t36\ehci.cpp
...
	#ifdef ARDUINO_TEENSY41
	IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_40 = 5;
	IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_40 = 0x0008; // slow speed, weak 150 ohm drive
	GPIO8_GDIR |= 1<<26;
	GPIO8_DR_SET = 1<<26;
	#endif

AFAIK - this 'pin' enables the USB_HOST 5V output control.
 
Works.
Code:
void USBHost::setPower(bool state) {
    if (state) {
        #ifdef ARDUINO_TEENSY41
        IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_40 = 5;
        IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_40 = 0x0008; // slow speed, weak 150 ohm drive
        GPIO8_GDIR |= 1 << 26;
        GPIO8_DR_SET = 1 << 26;
        #endif
    }

    else {
        #ifdef ARDUINO_TEENSY41
        GPIO8_DR_CLEAR = 1 << 26;  // turn off USB host power
        delay(100);  // allow time for 100uF capacitor to discharge
        #endif
    }
}
 
Back
Top