//############################################################################# // FILE: usbhhub.c // TITLE: This file contains the host HID driver //############################################################################# // $TI Release: F2837xD Support Library v3.05.00.00 $ // $Release Date: Thu Oct 18 15:48:42 CDT 2018 $ // $Copyright: // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //############################################################################# /* * Copyright (c) 2000 Jeroen Ruigrok van der Werven * All rights reserved. * * Copyright (c) 2014-2014 Texas Instruments Incorporated * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD: release/10.0.0/include/stdbool.h 228878 2011-12-25 20:15:41Z ed $ */ /*****************************************************************************/ /* STDINT.H */ /* */ /* Copyright (c) 2002 Texas Instruments Incorporated */ /* http://www.ti.com/ */ /* */ /* Redistribution and use in source and binary forms, with or without */ /* modification, are permitted provided that the following conditions */ /* are met: */ /* */ /* Redistributions of source code must retain the above copyright */ /* notice, this list of conditions and the following disclaimer. */ /* */ /* Redistributions in binary form must reproduce the above copyright */ /* notice, this list of conditions and the following disclaimer in */ /* the documentation and/or other materials provided with the */ /* distribution. */ /* */ /* Neither the name of Texas Instruments Incorporated nor the names */ /* of its contributors may be used to endorse or promote products */ /* derived from this software without specific prior written */ /* permission. */ /* */ /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */ /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */ /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */ /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */ /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */ /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */ /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */ /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* */ /*****************************************************************************/ /* 7.18.1.1 Exact-width integer types */ typedef int int16_t; typedef unsigned int uint16_t; typedef long int32_t; typedef unsigned long uint32_t; typedef long long int64_t; typedef unsigned long long uint64_t; /* 7.18.1.2 Minimum-width integer types */ typedef int16_t int_least8_t; typedef uint16_t uint_least8_t; typedef int16_t int_least16_t; typedef uint16_t uint_least16_t; typedef int32_t int_least32_t; typedef uint32_t uint_least32_t; typedef int64_t int_least64_t; typedef uint64_t uint_least64_t; /* 7.18.1.3 Fastest minimum-width integer types */ typedef int16_t int_fast8_t; typedef uint16_t uint_fast8_t; typedef int16_t int_fast16_t; typedef uint16_t uint_fast16_t; typedef int32_t int_fast32_t; typedef uint32_t uint_fast32_t; typedef int64_t int_fast64_t; typedef uint64_t uint_fast64_t; /* 7.18.1.4 Integer types capable of holding object pointers */ typedef long intptr_t; typedef unsigned long uintptr_t; /* 7.18.1.5 Greatest-width integer types */ typedef long long intmax_t; typedef unsigned long long uintmax_t; /* According to footnotes in the 1999 C standard, "C++ implementations should define these macros only when __STDC_LIMIT_MACROS is defined before is included." */ /* 7.18.2 Limits of specified width integer types */ /* 7.18.3 Limits of other integer types */ /* 7.18.4.1 Macros for minimum-width integer constants */ /* There is a defect report filed against the C99 standard concerning how the (U)INTN_C macros should be implemented. Please refer to -- http://wwwold.dkuug.dk/JTC1/SC22/WG14/www/docs/dr_209.htm for more information. These macros are implemented according to the suggestion given at this web site. */ /* 7.18.4.2 Macros for greatest-width integer constants */ //########################################################################### // // FILE: hw_types.h // // TITLE: Type definitions used in ALL driverlib functions. // //########################################################################### // $TI Release: F2837xD Support Library v3.05.00.00 $ // $Release Date: Thu Oct 18 15:48:42 CDT 2018 $ // $Copyright: // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //########################################################################### //***************************************************************************** // // Define fake 8 bit types for USB related code. // //***************************************************************************** typedef uint16_t uint8_t; typedef int16_t int8_t; //***************************************************************************** // // Macros for hardware access, both direct and via the bit-band region. // //***************************************************************************** //Emulated Bitbanded write //Emulated Bitbanded read //Emulated Bitbanded write //Emulated Bitbanded read //########################################################################### // // FILE: hw_ints.h // // TITLE: Definitions of interrupt numbers for use with interrupt.c. // //########################################################################### // $TI Release: F2837xD Support Library v3.05.00.00 $ // $Release Date: Thu Oct 18 15:48:42 CDT 2018 $ // $Copyright: // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //########################################################################### //***************************************************************************** // // PIE Interrupt Numbers // // 0x00FF = PIE Table Row # // 0xFF00 = PIE Table Column # // 0xFFFF0000 = PIE Vector ID // //***************************************************************************** // Lower PIE Group 1 // Lower PIE Group 2 // Lower PIE Group 3 // Lower PIE Group 4 // Lower PIE Group 5 // Lower PIE Group 6 // Lower PIE Group 7 // Lower PIE Group 8 // Lower PIE Group 9 // Lower PIE Group 10 // Lower PIE Group 11 // Lower PIE Group 12 // Upper PIE Group 1 // Upper PIE Group 2 // Upper PIE Group 3 // Upper PIE Group 4 // Upper PIE Group 5 // Upper PIE Group 6 // Upper PIE Group 8 // Upper PIE Group 9 // Upper PIE Group 10 // Upper PIE Group 11 // Upper PIE Group 12 //Workaround for Stellaris code //Workaround for other interrupts //########################################################################### // // FILE: usb.h // // TITLE: Prototypes for the USB Interface Driver. // //########################################################################### // $TI Release: F2837xD Support Library v3.05.00.00 $ // $Release Date: Thu Oct 18 15:48:42 CDT 2018 $ // $Copyright: // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //########################################################################### //***************************************************************************** // // If building with a C++ compiler, make all of the definitions in this header // have a C binding. // //***************************************************************************** //***************************************************************************** // // The following are defines for the g_usUSBFlags variable // //***************************************************************************** //***************************************************************************** // // The following are values that can be passed to USBIntEnableControl() and // USBIntDisableControl() as the ui32Flags parameter, and are returned from // USBIntStatusControl(). // //***************************************************************************** //***************************************************************************** // // The following are values that can be passed to USBIntEnableEndpoint() and // USBIntDisableEndpoint() as the ui32Flags parameter, and are returned from // USBIntStatusEndpoint(). // //***************************************************************************** //***************************************************************************** // // The following are values that are returned from USBSpeedGet(). // //***************************************************************************** //***************************************************************************** // // The following are values that are returned from USBEndpointStatus(). The // USB_HOST_* values are used when the USB controller is in host mode and the // USB_DEV_* values are used when the USB controller is in device mode. // //***************************************************************************** // (ISOC Mode) // specified timeout period // device // specified timeout period // (ISOC mode) // device // specified timeout period // device // transfer // a full FIFO // to come // Data End seen //***************************************************************************** // // The following are values that can be passed to USBHostEndpointConfig() and // USBDevEndpointConfigSet() as the ui32Flags parameter. // //***************************************************************************** //***************************************************************************** // // The following are values that can be passed to USBHostPwrConfig() as the // ui32Flags parameter. // //***************************************************************************** //***************************************************************************** // // The following are special values that can be passed to // USBHostEndpointConfig() as the ui32NAKPollInterval parameter. // //***************************************************************************** //***************************************************************************** // // This value specifies the maximum size of transfers on endpoint 0 as 64 // bytes. This value is fixed in hardware as the FIFO size for endpoint 0. // //***************************************************************************** //***************************************************************************** // // These values are used to indicate which endpoint to access. // //***************************************************************************** //***************************************************************************** // // These macros allow conversion between 0-based endpoint indices and the // USB_EP_x values required when calling various USB APIs. // //***************************************************************************** //***************************************************************************** // // The following are values that can be passed to USBFIFOConfigSet() as the // ui32FIFOSize parameter. // //***************************************************************************** // (occupying 16 bytes) // (occupying 32 bytes) // (occupying 64 bytes) // (occupying 128 bytes) // (occupying 256 bytes) // (occupying 512 bytes) // (occupying 1024 bytes) // (occupying 2048 bytes) // (occupying 4096 bytes) //***************************************************************************** // // This macro allow conversion from a FIFO size label as defined above to // a number of bytes // //***************************************************************************** //***************************************************************************** // // The following are values that can be passed to USBEndpointDataSend() as the // ui32TransType parameter. // //***************************************************************************** // endpoint 0 in device mode) // 0) // 0) //***************************************************************************** // // The following are values are returned by the USBModeGet function. // //***************************************************************************** // mode. // Device mode. // set. // the cable. // the cable. // the cable Session Valid. // the cable A valid. // the cable. // the cable. // the cable. // the cable. //***************************************************************************** // // Prototypes for the APIs. // //***************************************************************************** extern uint32_t USBDevAddrGet(uint32_t ui32Base); extern void USBDevAddrSet(uint32_t ui32Base, uint32_t ui32Address); extern void USBDevConnect(uint32_t ui32Base); extern void USBDevDisconnect(uint32_t ui32Base); extern void USBDevEndpointConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32MaxPacketSize, uint32_t ui32Flags); extern void USBDevEndpointConfigGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t *pui32MaxPacketSize, uint32_t *pui32Flags); extern void USBDevEndpointDataAck(uint32_t ui32Base, uint32_t ui32Endpoint, _Bool bIsLastPacket); extern void USBDevEndpointStall(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags); extern void USBDevEndpointStallClear(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags); extern void USBDevEndpointStatusClear(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags); extern uint32_t USBEndpointDataAvail(uint32_t ui32Base, uint32_t ui32Endpoint); extern void USBEndpointDMAEnable(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags); extern void USBEndpointDMADisable(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags); extern void USBEndpointDMAConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Config); extern int32_t USBEndpointDataGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint8_t *pui8Data, uint32_t *pui32Size); extern int32_t USBEndpointDataPut(uint32_t ui32Base, uint32_t ui32Endpoint, uint8_t *pui8Data, uint32_t ui32Size); extern int32_t USBEndpointDataSend(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32TransType); extern void USBEndpointDataToggleClear(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags); extern void USBEndpointPacketCountSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Count); extern uint32_t USBEndpointStatus(uint32_t ui32Base, uint32_t ui32Endpoint); extern uint32_t USBFIFOAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint); extern void USBFIFOConfigGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t *pui32FIFOAddress, uint32_t *pui32FIFOSize, uint32_t ui32Flags); extern void USBFIFOConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32FIFOAddress, uint32_t ui32FIFOSize, uint32_t ui32Flags); extern void USBFIFOFlush(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags); extern uint32_t USBFrameNumberGet(uint32_t ui32Base); extern uint32_t USBHostAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags); extern void USBHostAddrSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Addr, uint32_t ui32Flags); extern void USBHostEndpointConfig(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32MaxPacketSize, uint32_t ui32NAKPollInterval, uint32_t ui32TargetEndpoint, uint32_t ui32Flags); extern void USBHostEndpointDataAck(uint32_t ui32Base, uint32_t ui32Endpoint); extern void USBHostEndpointDataToggle(uint32_t ui32Base, uint32_t ui32Endpoint, _Bool bDataToggle, uint32_t ui32Flags); extern void USBHostEndpointStatusClear(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags); extern uint32_t USBHostHubAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags); extern void USBHostHubAddrSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Addr, uint32_t ui32Flags); extern void USBHostPwrDisable(uint32_t ui32Base); extern void USBHostPwrEnable(uint32_t ui32Base); extern void USBHostPwrConfig(uint32_t ui32Base, uint32_t ui32Flags); extern void USBHostPwrFaultDisable(uint32_t ui32Base); extern void USBHostPwrFaultEnable(uint32_t ui32Base); extern void USBHostRequestIN(uint32_t ui32Base, uint32_t ui32Endpoint); extern void USBHostRequestINClear(uint32_t ui32Base, uint32_t ui32Endpoint); extern void USBHostRequestStatus(uint32_t ui32Base); extern void USBHostReset(uint32_t ui32Base, _Bool bStart); extern void USBHostResume(uint32_t ui32Base, _Bool bStart); extern uint32_t USBHostSpeedGet(uint32_t ui32Base); extern void USBHostSuspend(uint32_t ui32Base); extern void USBIntDisableControl(uint32_t ui32Base, uint32_t ui32IntFlags); extern void USBIntEnableControl(uint32_t ui32Base, uint32_t ui32IntFlags); extern uint32_t USBIntStatus(uint32_t ui32Base, uint32_t *ui32IntStatusEP); extern uint32_t USBIntStatusControl(uint32_t ui32Base); extern void USBIntDisableEndpoint(uint32_t ui32Base, uint32_t ui32IntFlags); extern void USBIntEnableEndpoint(uint32_t ui32Base, uint32_t ui32IntFlags); extern uint32_t USBIntStatusEndpoint(uint32_t ui32Base); extern void USBIntRegister(uint32_t ui32Base, void (*pfnHandler)(void)); extern void USBIntUnregister(uint32_t ui32Base); extern void USBOTGSessionRequest(uint32_t ui32Base, _Bool bStart); extern uint32_t USBModeGet(uint32_t ui32Base); extern void USBEndpointDMAChannel(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Channel); extern void USBHostMode(uint32_t ui32Base); extern void USBDevMode(uint32_t ui32Base); extern void USBOTGMode(uint32_t ui32Base); extern void USBPHYPowerOff(uint32_t ui32Base); extern void USBPHYPowerOn(uint32_t ui32Base); extern uint32_t USBNumEndpointsGet(uint32_t ui32Base); //***************************************************************************** // The following are values that can be passed to USBIntEnable() and // USBIntDisable() as the ulIntFlags parameter, and are returned from // USBIntStatus(). //***************************************************************************** //***************************************************************************** // // Mark the end of the C bindings section for C++ compilers. // //***************************************************************************** //########################################################################### // // FILE: interrupt.h // // TITLE: Stellaris style wrapper driver for C28x PIE Interrupt Controller. // //########################################################################### // $TI Release: F2837xD Support Library v3.05.00.00 $ // $Release Date: Thu Oct 18 15:48:42 CDT 2018 $ // $Copyright: // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //########################################################################### //***************************************************************************** // // If building with a C++ compiler, make all of the definitions in this header // have a C binding. // //***************************************************************************** //***************************************************************************** // // Prototypes for the APIs. // //***************************************************************************** extern _Bool IntMasterEnable(void); extern _Bool IntMasterDisable(void); extern void IntRegister(uint32_t ui32Interrupt, void (*pfnHandler)(void)); extern void IntUnregister(uint32_t ui32Interrupt); extern void IntEnable(uint32_t ui32Interrupt); extern void IntDisable(uint32_t ui32Interrupt); extern void IntIFRClear(uint16_t ui16Interrupts); //***************************************************************************** // // Mark the end of the C bindings section for C++ compilers. // //***************************************************************************** //***************************************************************************** // // rom_map.h - Macros to facilitate calling functions in the ROM when they are // available and in flash otherwise. // // Copyright (c) 2008-2012 Texas Instruments Incorporated. All rights reserved. // Software License Agreement // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // This is part of revision 9453 of the Stellaris Peripheral Driver Library. // //***************************************************************************** //***************************************************************************** // // Macros for the ADC API. // //***************************************************************************** //***************************************************************************** // // Macros for the CAN API. // //***************************************************************************** //***************************************************************************** // // Macros for the Comparator API. // //***************************************************************************** //***************************************************************************** // // Macros for the EEPROM API. // //***************************************************************************** //***************************************************************************** // // Macros for the EPI API. // //***************************************************************************** //***************************************************************************** // // Macros for the Ethernet API. // //***************************************************************************** //***************************************************************************** // // Macros for the Fan API. // //***************************************************************************** //***************************************************************************** // // Macros for the Flash API. // //***************************************************************************** //***************************************************************************** // // Macros for the FPU API. // //***************************************************************************** //***************************************************************************** // // Macros for the GPIO API. // //***************************************************************************** //***************************************************************************** // // Macros for the Hibernate API. // //***************************************************************************** //***************************************************************************** // // Macros for the I2C API. // //***************************************************************************** //***************************************************************************** // // Macros for the I2S API. // //***************************************************************************** //***************************************************************************** // // Macros for the Interrupt API. // //***************************************************************************** //***************************************************************************** // // Macros for the LPC API. // //***************************************************************************** //***************************************************************************** // // Macros for the MPU API. // //***************************************************************************** //***************************************************************************** // // Macros for the PECI API. // //***************************************************************************** //***************************************************************************** // // Macros for the PWM API. // //***************************************************************************** //***************************************************************************** // // Macros for the QEI API. // //***************************************************************************** //***************************************************************************** // // Macros for the SMBus API. // //***************************************************************************** //***************************************************************************** // // Macros for the SSI API. // //***************************************************************************** //***************************************************************************** // // Macros for the SysCtl API. // //***************************************************************************** //***************************************************************************** // // Macros for the SysExc API. // //***************************************************************************** //***************************************************************************** // // Macros for the SysTick API. // //***************************************************************************** //***************************************************************************** // // Macros for the Timer API. // //***************************************************************************** //***************************************************************************** // // Macros for the UART API. // //***************************************************************************** //***************************************************************************** // // Macros for the uDMA API. // //***************************************************************************** //***************************************************************************** // // Macros for the USB API. // //***************************************************************************** //***************************************************************************** // // Macros for the Watchdog API. // //***************************************************************************** //***************************************************************************** // // Macros for the Software API. // //***************************************************************************** //***************************************************************************** // // rtos_bindings.h - Macros ulIntIDended to aid porting of StellarisWare modules // for use with an RTOS. // // Copyright (c) 2012 Texas Instruments Incorporated. All rights reserved. // Software License Agreement // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // This is part of revision 9453 of the Stellaris Peripheral Driver Library. // //***************************************************************************** //***************************************************************************** // // When no RTOS is in use, the follow macros compile to either nothing or a // minimal implementation that works in a bare-metal environment. // // Each of these macros must be redefined in stellaris_rtos.h if you are using // StellarisWare under an RTOS. // //***************************************************************************** //***************************************************************************** // // A simple macro used to yield within polling loops. In the default, non-RTOS // implementation, this compiles to nothing. // //***************************************************************************** //***************************************************************************** // // A simple macro around the SysCtlDelay function. The parameter is the number // of 3 cycle loops to wait before returning (as for SysCtlDelay). In an RTOS // implementation, this could be replaced with an OS delay call with // appropriate parameter scaling. // //***************************************************************************** //***************************************************************************** // // Wrappers around low level interrupt control functions. For information // on each of these functions, please see the appropriate API documentation // for the DriverLib Interrupt driver. // // The macros defined here represent interrupt-control functions that may be // called from within StellarisWare code. It is expected that application // code will use RTOS-specific functions to control interrupt priority, to // pend interrupts and to perform runtime vector manipulation. As a result, // no macros are defined to wrap any of these functions from interrupt.c. // //***************************************************************************** //############################################################################# // FILE: usblib.h // TITLE: Main header file for the USB Library //############################################################################# // $TI Release: F2837xD Support Library v3.05.00.00 $ // $Release Date: Thu Oct 18 15:48:42 CDT 2018 $ // $Copyright: // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //############################################################################# //***************************************************************************** // // If building with a C++ compiler, make all of the definitions in this header // have a C binding. // //***************************************************************************** //***************************************************************************** // // This is the maximum number of devices we can support when in host mode and // using a hub. By default, we support up to 4 devices (plus 1 internally for // the hub itself). // //***************************************************************************** //***************************************************************************** // // This is the maximum number of endpoints supported by the usblib. // //***************************************************************************** //***************************************************************************** // // The following macro allows compiler-independent syntax to be used to // define packed structures. A typical structure definition using these // macros will look similar to the following example: // // #ifdef ewarm // #pragma pack(1) // #endif // // typedef struct _PackedStructName // { // uint32_t ui32FirstField; // int8_t i8CharMember; // uint16_t ui16Short; // } // PACKED tPackedStructName; // // #ifdef ewarm // #pragma pack() // #endif // // The conditional blocks related to ewarm include the #pragma pack() lines // only if the IAR Embedded Workbench compiler is being used. Unfortunately, // it is not possible to emit a #pragma from within a macro definition so this // must be done explicitly. // //***************************************************************************** //***************************************************************************** // // Assorted language IDs from the document "USB_LANGIDs.pdf" provided by the // USB Implementers' Forum (Version 1.0). // //***************************************************************************** //***************************************************************************** // //! \addtogroup c2000_specific //! @{ // //***************************************************************************** //***************************************************************************** // //! This struct is used to ensure that data passed up from the driver layer //! is interpretted correctly by the protocol stack. This is a workaround //! specifically for C2000 devices. // //***************************************************************************** typedef struct { uint16_t LSB; uint16_t MSB; } usb16_t; //***************************************************************************** // //! This struct is used to ensure that data passed up from the driver layer //! is interpretted correctly by the protocol stack. This is a workaround //! specifically for C2000 devices. // //***************************************************************************** typedef struct { usb16_t LSW; usb16_t MSW; } usb32_t; //***************************************************************************** // //! This define is used to write data to a tShort variable. This is a //! is a workaround specific to C2000 devices. // //***************************************************************************** //***************************************************************************** // //! This define is used to read data from a tShort variable. This is a //! is a workaround specific to C2000 devices. // //***************************************************************************** //***************************************************************************** // //! This define is used to write data to a tLong variable. This is a //! is a workaround specific to C2000 devices. // //***************************************************************************** //***************************************************************************** // //! This define is used to read data from a tLong variable. This is a //! is a workaround specific to C2000 devices. // //***************************************************************************** //***************************************************************************** // // Close the c2000_specific group. //! @} // //***************************************************************************** //***************************************************************************** // //! \addtogroup usbchap9_src //! @{ // //***************************************************************************** //***************************************************************************** // // Note: // // Structure definitions which are derived directly from the USB specification // use field names from the specification. Since a somewhat different version // of Hungarian prefix notation is used from the standard, beware of making // assumptions about field sizes based on the field prefix when using // these structures. Of particular note is the difference in the meaning of // the 'i' prefix. In USB structures, this indicates a single byte index // whereas in other code, this is an integer or enumeration variable. // //***************************************************************************** //***************************************************************************** // // All structures defined in this section of the header require byte packing of // fields. This is usually accomplished using the PACKED macro but, for IAR // Embedded Workbench, this requires a pragma. // //***************************************************************************** //***************************************************************************** // // Definitions related to standard USB device requests (sections 9.3 & 9.4) // //***************************************************************************** //***************************************************************************** // //! The standard USB request header as defined in section 9.3 of the USB 2.0 //! specification. // //***************************************************************************** typedef struct { // //! Determines the type and direction of the request. // uint8_t bmRequestType; // //! Identifies the specific request being made. // uint8_t bRequest; // //! Word-sized field that varies according to the request. // usb16_t wValue; // //! Word-sized field that varies according to the request; typically used //! to pass an index or offset. // usb16_t wIndex; // //! The number of bytes to transfer if there is a data stage to the //! request. // usb16_t wLength; } tUSBRequest; //***************************************************************************** // // The following defines are used with the bmRequestType member of tUSBRequest. // // Request types have 3 bit fields: // 4:0 - Is the recipient type. // 6:5 - Is the request type. // 7 - Is the direction of the request. // //***************************************************************************** //***************************************************************************** // // Standard USB requests IDs used in the bRequest field of tUSBRequest. // //***************************************************************************** //***************************************************************************** // // Data returned from a USBREQ_GET_STATUS request to a device. // //***************************************************************************** //***************************************************************************** // // Feature Selectors (tUSBRequest.wValue) passed on USBREQ_CLEAR_FEATURE and // USBREQ_SET_FEATURE. // //***************************************************************************** //***************************************************************************** // // Endpoint Selectors (tUSBRequest.wIndex) passed on USBREQ_CLEAR_FEATURE, // USBREQ_SET_FEATURE and USBREQ_GET_STATUS. // //***************************************************************************** //***************************************************************************** // // Standard USB descriptor types. These values are passed in the upper bytes // of tUSBRequest.wValue on USBREQ_GET_DESCRIPTOR and also appear in the // bDescriptorType field of standard USB descriptors. // //***************************************************************************** //***************************************************************************** // // Definitions related to USB descriptors (sections 9.5 & 9.6) // //***************************************************************************** //***************************************************************************** // //! This structure describes a generic descriptor header. These fields are to //! be found at the beginning of all valid USB descriptors. // //***************************************************************************** typedef struct { // //! The length of this descriptor (including this length byte) expressed //! in bytes. // uint8_t bLength; // //! The type identifier of the descriptor whose information follows. For //! standard descriptors, this field could contain, for example, //! USB_DTYPE_DEVICE to identify a device descriptor or USB_DTYPE_ENDPOINT //! to identify an endpoint descriptor. // uint8_t bDescriptorType; } tDescriptorHeader; //***************************************************************************** // //! This structure describes the USB device descriptor as defined in USB //! 2.0 specification section 9.6.1. // //***************************************************************************** typedef struct { // //! The length of this descriptor in bytes. All device descriptors are //! 18 bytes long. // uint8_t bLength; // //! The type of the descriptor. For a device descriptor, this will be //! USB_DTYPE_DEVICE (1). // uint8_t bDescriptorType; // //! The USB Specification Release Number in BCD format. For USB 2.0, this //! will be 0x0200. // usb16_t bcdUSB; // //! The device class code. // uint8_t bDeviceClass; // //! The device subclass code. This value qualifies the value found in the //! bDeviceClass field. // uint8_t bDeviceSubClass; // //! The device protocol code. This value is qualified by the values of //! bDeviceClass and bDeviceSubClass. // uint8_t bDeviceProtocol; // //! The maximum packet size for endpoint zero. Valid values are 8, 16, 32 //! and 64. // uint8_t bMaxPacketSize0; // //! The device Vendor ID (VID) as assigned by the USB-IF. // usb16_t idVendor; // //! The device Product ID (PID) as assigned by the manufacturer. // usb16_t idProduct; // //! The device release number in BCD format. // usb16_t bcdDevice; // //! The index of a string descriptor describing the manufacturer. // uint8_t iManufacturer; // //! The index of a string descriptor describing the product. // uint8_t iProduct; // //! The index of a string descriptor describing the device's serial //! number. // uint8_t iSerialNumber; // //! The number of possible configurations offered by the device. This //! field indicates the number of distinct configuration descriptors that //! the device offers. // uint8_t bNumConfigurations; } tDeviceDescriptor; //***************************************************************************** // // USB Device Class codes used in the tDeviceDescriptor.bDeviceClass field. // Definitions for the bDeviceSubClass and bDeviceProtocol fields are device // specific and can be found in the appropriate device class header files. // //***************************************************************************** //***************************************************************************** // // Generic values for undefined subclass and protocol. // //***************************************************************************** //***************************************************************************** // // The following are the miscellaneous subclass values. // //***************************************************************************** //***************************************************************************** // // These following are miscellaneous protocol values. // //***************************************************************************** //***************************************************************************** // // These following are hub protocol values. // //***************************************************************************** //***************************************************************************** // //! This structure describes the USB device qualifier descriptor as defined in //! the USB 2.0 specification, section 9.6.2. // //***************************************************************************** typedef struct { // //! The length of this descriptor in bytes. All device qualifier //! descriptors are 10 bytes long. // uint8_t bLength; // //! The type of the descriptor. For a device descriptor, this will be //! USB_DTYPE_DEVICE_QUAL (6). // uint8_t bDescriptorType; // //! The USB Specification Release Number in BCD format. For USB 2.0, this //! will be 0x0200. // usb16_t bcdUSB; // //! The device class code. // uint8_t bDeviceClass; // //! The device subclass code. This value qualifies the value found in the //! bDeviceClass field. // uint8_t bDeviceSubClass; // //! The device protocol code. This value is qualified by the values of //! bDeviceClass and bDeviceSubClass. // uint8_t bDeviceProtocol; // //! The maximum packet size for endpoint zero when operating at a speed //! other than high speed. // uint8_t bMaxPacketSize0; // //! The number of other-speed configurations supported. // uint8_t bNumConfigurations; // //! Reserved for future use. Must be set to zero. // uint8_t bReserved; } tDeviceQualifierDescriptor; //***************************************************************************** // //! This structure describes the USB configuration descriptor as defined in //! USB 2.0 specification section 9.6.3. This structure also applies to the //! USB other speed configuration descriptor defined in section 9.6.4. // //***************************************************************************** typedef struct { // //! The length of this descriptor in bytes. All configuration descriptors //! are 9 bytes long. // uint8_t bLength; // //! The type of the descriptor. For a configuration descriptor, this will //! be USB_DTYPE_CONFIGURATION (2). // uint8_t bDescriptorType; // //! The total length of data returned for this configuration. This //! includes the combined length of all descriptors (configuration, //! interface, endpoint and class- or vendor-specific) returned for this //! configuration. // usb16_t wTotalLength; // //! The number of interface supported by this configuration. // uint8_t bNumInterfaces; // //! The value used as an argument to the SetConfiguration standard request //! to select this configuration. // uint8_t bConfigurationValue; // //! The index of a string descriptor describing this configuration. // uint8_t iConfiguration; // //! Attributes of this configuration. // uint8_t bmAttributes; // //! The maximum power consumption of the USB device from the bus in this //! configuration when the device is fully operational. This is expressed //! in units of 2mA so, for example, 100 represents 200mA. // uint8_t bMaxPower; } tConfigDescriptor; //***************************************************************************** // // Flags used in constructing the value assigned to the field // tConfigDescriptor.bmAttributes. Note that bit 7 is reserved and must be set // to 1. // //***************************************************************************** //***************************************************************************** // //! This structure describes the USB interface descriptor as defined in USB //! 2.0 specification section 9.6.5. // //***************************************************************************** typedef struct { // //! The length of this descriptor in bytes. All interface descriptors //! are 9 bytes long. // uint8_t bLength; // //! The type of the descriptor. For an interface descriptor, this will //! be USB_DTYPE_INTERFACE (4). // uint8_t bDescriptorType; // //! The number of this interface. This is a zero based index into the //! array of concurrent interfaces supported by this configuration. // uint8_t bInterfaceNumber; // //! The value used to select this alternate setting for the interface //! defined in bInterfaceNumber. // uint8_t bAlternateSetting; // //! The number of endpoints used by this interface (excluding endpoint //! zero). // uint8_t bNumEndpoints; // //! The interface class code as assigned by the USB-IF. // uint8_t bInterfaceClass; // //! The interface subclass code as assigned by the USB-IF. // uint8_t bInterfaceSubClass; // //! The interface protocol code as assigned by the USB-IF. // uint8_t bInterfaceProtocol; // //! The index of a string descriptor describing this interface. // uint8_t iInterface; } tInterfaceDescriptor; //***************************************************************************** // //! This structure describes the USB endpoint descriptor as defined in USB //! 2.0 specification section 9.6.6. // //***************************************************************************** typedef struct { // //! The length of this descriptor in bytes. All endpoint descriptors //! are 7 bytes long. // uint8_t bLength; // //! The type of the descriptor. For an endpoint descriptor, this will //! be USB_DTYPE_ENDPOINT (5). // uint8_t bDescriptorType; // //! The address of the endpoint. This field contains the endpoint number //! ORed with flag USB_EP_DESC_OUT or USB_EP_DESC_IN to indicate the //! endpoint direction. // uint8_t bEndpointAddress; // //! The endpoint transfer type, USB_EP_ATTR_CONTROL, USB_EP_ATTR_ISOC, //! USB_EP_ATTR_BULK or USB_EP_ATTR_INT and, if isochronous, additional //! flags indicating usage type and synchronization method. // uint8_t bmAttributes; // //! The maximum packet size this endpoint is capable of sending or //! receiving when this configuration is selected. For high speed //! isochronous or interrupt endpoints, bits 11 and 12 are used to //! pass additional information. // usb16_t wMaxPacketSize; // //! The polling interval for data transfers expressed in frames or //! micro frames depending upon the operating speed. // uint8_t bInterval; } tEndpointDescriptor; //***************************************************************************** // // Flags used in constructing the value assigned to the field // tEndpointDescriptor.bEndpointAddress. // //***************************************************************************** //***************************************************************************** // // Mask used to extract the maximum packet size (in bytes) from the // wMaxPacketSize field of the endpoint descriptor. // //***************************************************************************** //***************************************************************************** // // Endpoint attributes used in tEndpointDescriptor.bmAttributes. // //***************************************************************************** //***************************************************************************** // //! This structure describes the USB string descriptor for index 0 as defined //! in USB 2.0 specification section 9.6.7. Note that the number of language //! IDs is variable and can be determined by examining bLength. The number of //! language IDs present in the descriptor is given by ((bLength - 2) / 2). // //***************************************************************************** typedef struct { // //! The length of this descriptor in bytes. This value will vary //! depending upon the number of language codes provided in the descriptor. // uint8_t bLength; // //! The type of the descriptor. For a string descriptor, this will be //! USB_DTYPE_STRING (3). // uint8_t bDescriptorType; // //! The language code (LANGID) for the first supported language. Note that //! this descriptor may support multiple languages, in which case, the //! number of elements in the wLANGID array will increase and bLength will //! be updated accordingly. // usb16_t wLANGID[1]; } tString0Descriptor; //***************************************************************************** // //! This structure describes the USB string descriptor for all string indexes //! other than 0 as defined in USB 2.0 specification section 9.6.7. // //***************************************************************************** typedef struct { // //! The length of this descriptor in bytes. This value will be 2 greater //! than the number of bytes comprising the UNICODE string that the //! descriptor contains. // uint8_t bLength; // //! The type of the descriptor. For a string descriptor, this will be //! USB_DTYPE_STRING (3). // uint8_t bDescriptorType; // //! The first byte of the UNICODE string. This string is not NULL //! terminated. Its length (in bytes) can be computed by subtracting 2 //! from the value in the bLength field. // uint8_t bString; } tStringDescriptor; //***************************************************************************** // //! Write a 16-bit value to a USB descriptor block. //! //! \param ui16Value is the 16-bit value to write to the descriptor. //! //! This helper macro is used in descriptor definitions to write two-byte //! values. Since the configuration descriptor contains all interface and //! endpoint descriptors in a contiguous block of memory, these descriptors are //! typically defined using an array of bytes rather than as packed structures. //! //! \return Not a function. // //***************************************************************************** //***************************************************************************** // //! Write a 24-bit value to a USB descriptor block. //! //! \param ui32Value is the 24-bit value that to write to the descriptor. //! //! This helper macro is used in descriptor definitions to write three-byte //! values. Since the configuration descriptor contains all interface and //! endpoint descriptors in a contiguous block of memory, these descriptors are //! typically defined using an array of bytes rather than as packed structures. //! //! \return Not a function. // //***************************************************************************** //***************************************************************************** // //! Write a 32-bit value to a USB descriptor block. //! //! \param ui32Value is the 32-bit value that to write to the descriptor. //! //! This helper macro is used in descriptor definitions to write four-byte //! values. Since the configuration descriptor contains all interface and //! endpoint descriptors in a contiguous block of memory, these descriptors are //! typically defined using an array of bytes rather than as packed structures. //! //! \return Not a function. // //***************************************************************************** //***************************************************************************** // //! Traverse to the next USB descriptor in a block. //! //! \param ptr points to the first byte of a descriptor in a block of //! USB descriptors. //! //! This macro aids in traversing lists of descriptors by returning a pointer //! to the next descriptor in the list given a pointer to the current one. //! //! \return Returns a pointer to the next descriptor in the block following //! \e ptr. //! //***************************************************************************** //***************************************************************************** // // Return to default packing when using the IAR Embedded Workbench compiler. // //***************************************************************************** //***************************************************************************** // // Close the usbchap9_src Doxygen group. //! @} // //***************************************************************************** //***************************************************************************** // //! \addtogroup device_api //! @{ // //***************************************************************************** //***************************************************************************** // // Function prototype for any standard USB request. // //***************************************************************************** typedef void (* tStdRequest)(void *pvInstance, tUSBRequest *pUSBRequest); //***************************************************************************** // // Data callback for receiving data from an endpoint. // //***************************************************************************** typedef void (* tInfoCallback)(void *pvInstance, uint32_t ui32Info); //***************************************************************************** // // Callback made to indicate that an interface alternate setting change has // occurred. // //***************************************************************************** typedef void (* tInterfaceCallback)(void *pvInstance, uint8_t ui8InterfaceNum, uint8_t ui8AlternateSetting); //***************************************************************************** // // Generic interrupt handler callbacks. // //***************************************************************************** typedef void (* tUSBIntHandler)(void *pvInstance); //***************************************************************************** // // Interrupt handler callbacks that have status information. // //***************************************************************************** typedef void (* tUSBEPIntHandler)(void *pvInstance, uint32_t ui32Status); //***************************************************************************** // // Generic handler callbacks that are used when the callers needs to call into // an instance of class. // //***************************************************************************** typedef void (* tUSBDeviceHandler)(void *pvInstance, uint32_t ui32Request, void *pvRequestData); //***************************************************************************** // //! USB event handler functions used during enumeration and operation of the //! device stack. // //***************************************************************************** typedef struct { // //! This callback is made whenever the USB host requests a non-standard //! descriptor from the device. // tStdRequest pfnGetDescriptor; // //! This callback is made whenever the USB host makes a non-standard //! request. // tStdRequest pfnRequestHandler; // //! This callback is made in response to a SetInterface request from the //! host. // tInterfaceCallback pfnInterfaceChange; // //! This callback is made in response to a SetConfiguration request from //! the host. // tInfoCallback pfnConfigChange; // //! This callback is made when data has been received following to a call //! to USBDCDRequestDataEP0. // tInfoCallback pfnDataReceived; // //! This callback is made when data has been transmitted following a call //! to USBDCDSendDataEP0. // tInfoCallback pfnDataSent; // //! This callback is made when a USB reset is detected. // tUSBIntHandler pfnResetHandler; // //! This callback is made when the bus has been inactive long enough to //! trigger a suspend condition. // tUSBIntHandler pfnSuspendHandler; // //! This is called when resume signaling is detected. // tUSBIntHandler pfnResumeHandler; // //! This callback is made when the device is disconnected from the USB bus. // tUSBIntHandler pfnDisconnectHandler; // //! This callback is made to inform the device of activity on all endpoints //! other than endpoint zero. // tUSBEPIntHandler pfnEndpointHandler; // //! This generic handler is provided to allow requests based on //! a given instance to be passed into a device. This is commonly used //! by a top level composite device that is using multiple instances of //! a class. // tUSBDeviceHandler pfnDeviceHandler; } tCustomHandlers; //***************************************************************************** // //! This structure defines a contiguous block of data which contains a group //! of descriptors that form part of a configuration descriptor for a device. //! It is assumed that a config section contains only whole descriptors. It is //! not valid to split a single descriptor across multiple sections. //! //***************************************************************************** typedef struct { // //! The number of bytes of descriptor data pointed to by pui8Data. // uint16_t ui16Size; // //! A pointer to a block of data containing an integral number of //! USB descriptors which form part of a larger configuration descriptor. // const uint8_t *pui8Data; } tConfigSection; //***************************************************************************** // //! This is the top level structure defining a USB device configuration //! descriptor. A configuration descriptor contains a collection of device- //! specific descriptors in addition to the basic config, interface and //! endpoint descriptors. To allow flexibility in constructing the //! configuration, the descriptor is described in terms of a list of data //! blocks. The first block must contain the configuration descriptor itself //! and the following blocks are appended to this in order to produce the //! full descriptor sent to the host in response to a GetDescriptor request //! for the configuration descriptor. //! //***************************************************************************** typedef struct { // //! The number of sections comprising the full descriptor for this //! configuration. // uint8_t ui8NumSections; // //! A pointer to an array of ui8NumSections section pointers which must //! be concatenated to form the configuration descriptor. // const tConfigSection * const *psSections; } tConfigHeader; //***************************************************************************** // // Close the Doxygen group. //! @} // //***************************************************************************** //***************************************************************************** // //! \addtogroup general_usblib_api //! @{ // //***************************************************************************** //***************************************************************************** // // Predeclare of the DMA instance structure. // //***************************************************************************** typedef struct tUSBDMAInstance tUSBDMAInstance; //***************************************************************************** // // USB descriptor parsing functions found in usbdesc.c // //***************************************************************************** //***************************************************************************** // //! The USB_DESC_ANY label is used as a wild card in several of the descriptor //! parsing APIs to determine whether or not particular search criteria should //! be ignored. // //***************************************************************************** extern uint32_t USBDescGetNum(tDescriptorHeader *psDesc, uint32_t ui32Size, uint32_t ui32Type); extern tDescriptorHeader *USBDescGet(tDescriptorHeader *psDesc, uint32_t ui32Size, uint32_t ui32Type, uint32_t ui32Index); extern uint32_t USBDescGetNumAlternateInterfaces(tConfigDescriptor *psConfig, uint8_t ui8InterfaceNumber); extern tInterfaceDescriptor *USBDescGetInterface(tConfigDescriptor *psConfig, uint32_t ui32Index, uint32_t ui32AltCfg); extern tEndpointDescriptor * USBDescGetInterfaceEndpoint(tInterfaceDescriptor *psInterface, uint32_t ui32Index, uint32_t ui32Size); //***************************************************************************** // //! The operating mode required by the USB library client. This type is used //! by applications which wish to be able to switch between host and device //! modes by calling the USBStackModeSet() API. // //***************************************************************************** typedef enum { // //! Operate in USB device mode with active monitoring of VBUS and the //! ID pin must be pulled to a logic high value. // eUSBModeDevice = 0, // //! Operate in USB host mode with active monitoring of VBUS and the ID pin //! must be pulled to a logic low value. // eUSBModeHost, // //! Operate as an On-The-Go device which requires both VBUS and ID to be //! connected directly to the USB controller from the USB connector. // eUSBModeOTG, // //! A marker indicating that no USB mode has yet been set by the //! application. // eUSBModeNone, // //! Force host mode so that the VBUS and ID pins are not used or monitored //! by the USB controller. // eUSBModeForceHost, // //! Forcing device mode so that the VBUS and ID pins are not used or //! monitored by the USB controller. // eUSBModeForceDevice, } tUSBMode; //***************************************************************************** // // A pointer to a USB mode callback function. This function is called by the // USB library to indicate to the application which operating mode it should // use, host or device. // //***************************************************************************** typedef void (*tUSBModeCallback)(uint32_t ui32Index, tUSBMode iMode); //***************************************************************************** // //! USB callback function. //! //! \param pvCBData is the callback pointer associated with the instance //! generating the callback. This is a value provided by the client during //! initialization of the instance making the callback. //! \param ui32Event is the identifier of the asynchronous event which is being //! notified to the client. //! \param ui32MsgParam is an event-specific parameter. //! \param pvMsgData is an event-specific data pointer. //! //! A function pointer provided to the USB layer by the application //! which will be called to notify it of all asynchronous events relating to //! data transmission or reception. This callback is used by device class //! drivers and host pipe functions. //! //! \return Returns an event-dependent value. // //***************************************************************************** typedef uint32_t (* tUSBCallback)(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgParam, void *pvMsgData); //***************************************************************************** // // Error sources reported via USB_EVENT_ERROR. // //***************************************************************************** // //! The host received an invalid PID in a transaction. // // //! The host did not receive a response from a device. // // //! The host received a stall on an IN endpoint. // // //! The host detected a CRC or bit-stuffing error (isochronous mode). // // //! The host received NAK on an IN endpoint for longer than the specified //! timeout period (interrupt, bulk and control modes). // // //! The host failed to communicate with a device via an IN endpoint. // // //! The host receive FIFO is full. // // //! The host received NAK on an OUT endpoint for longer than the specified //! timeout period (bulk, interrupt and control modes). // // //! The host did not receive a response from a device (isochronous mode). // // //! The host received a stall on an OUT endpoint. // // //! The host failed to communicate with a device via an OUT endpoint. // // //! The host received NAK on endpoint 0 for longer than the configured //! timeout. // // //! The host failed to communicate with a device via an endpoint zero. // // //! The device detected a CRC error in received data. // // //! The device was unable to receive a packet from the host since the receive //! FIFO is full. // // //! The device receive FIFO is full. // //***************************************************************************** // // Close the general_usblib_api Doxygen group. //! @} // //***************************************************************************** //***************************************************************************** // //! \addtogroup usblib_events //! @{ // //***************************************************************************** //***************************************************************************** // //! This structure is used to return generic event based information to an //! application. The following events are currently supported: //! USB_EVENT_CONNECTED, USB_EVENT_DISCONNECTED, USB_EVENT_POWER_FAULT, //! USB_EVENT_POWER_FAULT, USB_EVENT_POWER_ENABLE, //! USB_EVENT_POWER_DISABLE and USB_EVENT_SOF. // //***************************************************************************** typedef struct { // //! One of the USB_EVENT_ values. // uint32_t ui32Event; // //! The caller supplied instance value that is passed to event handlers. // uint32_t ui32Instance; } tEventInfo; //***************************************************************************** // // Base identifiers for groups of USB events. These are used by both the // device class drivers and host layer. // // USB_CLASS_EVENT_BASE is the lowest identifier that should be used for // a class-specific event. Individual event bases are defined for each // of the supported device class drivers. Events with IDs between // USB_EVENT_BASE and USB_CLASS_EVENT_BASE are reserved for stack use. // //***************************************************************************** //***************************************************************************** // // Event base identifiers for the various device classes supported in host // and device modes. // The first 0x800 values of a range are reserved for the device specific // messages and the second 0x800 values of a range are used for the host // specific messages for a given class. // //***************************************************************************** //***************************************************************************** // // General events supported by device classes and host pipes. // //***************************************************************************** // //! The device is now attached to a USB host and ready to begin sending //! and receiving data (used by device classes only). // // //! The device has been disconnected from the USB host (used by device classes //! only). //! //! \note In device mode, the USB_EVENT_DISCONNECTED will not be reported if //! the MCU's PB1/USB0VBUS pin is connected to a fixed +5 Volts rather than //! directly to the VBUS pin on the USB connector. // // //! Data has been received and is in the buffer provided or is ready to be //! read from the FIFO. // // //! This event is sent by a lower layer to inquire about the amount of //! unprocessed data buffered in the layers above. It is used in cases //! where a low level driver needs to ensure that all preceding data has //! been processed prior to performing some action or making some notification. //! Clients receiving this event should return the number of bytes of data //! that are unprocessed or 0 if no outstanding data remains. // // //! This event is sent by a lower layer supporting DMA to request a buffer in //! which the next received packet may be stored. The \e ui32MsgValue //! parameter indicates the maximum size of packet that can be received in this //! channel and \e pvMsgData points to storage which should be written with the //! returned buffer pointer. The return value from the callback should be the //! size of the buffer allocated (which may be less than the maximum size //! passed in \e ui32MsgValue if the client knows that fewer bytes are expected //! to be received) or 0 if no buffer is being returned. // // //! Data has been sent and acknowledged. If this event is received via the //! USB buffer callback, the \e ui32MsgValue parameter indicates the number of //! bytes from the transmit buffer that have been successfully transmitted //! and acknowledged. // // //! An error has been reported on the channel or pipe. The \e ui32MsgValue //! parameter indicates the source(s) of the error and is the logical OR //! combination of "USBERR_" flags defined below. // // //! The bus has entered suspend state. // // //! The bus has left suspend state. // // //! A scheduler event has occurred. // // //! A device or host has detected a stall condition. // // //! The host detected a power fault condition. // // //! The controller has detected a A-Side cable and needs power applied This is //! only generated on OTG parts if automatic power control is disabled. // // //! The controller needs power removed, This is only generated on OTG parts //! if automatic power control is disabled. // // //! This define is used with a device class's pfnDeviceHandler handler function //! to indicate that the USB library has changed the interface number. This //! event is typically due to the class being included in a composite device. //! //! The \e pvInstance is a pointer to an instance of the device being accessed. //! //! The \e ui32Request is USB_EVENT_COMP_IFACE_CHANGE. //! //! The \e pvRequestData is a pointer to a two byte array where the first value //! is the old interface number and the second is the new interface number. // // //! This define is used with a device class's pfnDeviceHandler handler function //! to indicate that the USB library has changed the endpoint number. This //! event is typically due to the class being included in a composite device. //! //! The \e pvInstance is a pointer to an instance of the device being accessed. //! //! The \e ui32Request is USB_EVENT_COMP_EP_CHANGE. //! //! The \e pvRequestData is a pointer to a two byte array where the first value //! is the old endpoint number and the second is the new endpoint number. The //! endpoint numbers should be exactly as USB specification defines them and //! bit 7 set indicates an IN endpoint and bit 7 clear indicates an OUT //! endpoint. // // //! This define is used with a device class's pfnDeviceHandler handler function //! to indicate that the USB library has changed the string index number for a //! string. This event is typically due to the class being included in a //! composite device. //! //! The \e pvInstance is a pointer to an instance of the device being accessed. //! //! The \e ui32Request is USB_EVENT_COMP_STR_CHANGE. //! //! The \e pvRequestData is a pointer to a two byte array where the first value //! is the old string index and the second is the new string index. // // //! This define is used with a device class's pfnDeviceHandler handler function //! to indicate that the USB library has changed the configuration descriptor. //! This allows the class to make final adjustments to the configuration //! descriptor. This event is typically due to the class being included in a //! composite device. //! //! The \e pvInstance is a pointer to an instance of the device being accessed. //! //! The \e ui32Request is USB_EVENT_COMP_CONFIG. //! //! The \e pvRequestData is a pointer to the beginning of the configuration //! descriptor for the device instance. // // //! An unknown device is now attached to a USB host. This value is only valid //! for the generic event handler and not other device handlers. It is //! useful for applications that want to know when an unknown device is //! connected and what the class is of the unknown device. //! //! The \e ui32Instance is actually the class of the unsupported //! device that was connected. // // //! A start of frame event has occurred. This event is disabled by default //! and must be enabled via a call from the application to USBHCDEventEnable(). // //***************************************************************************** // // Close the usblib_events Doxygen group. //! @} // //***************************************************************************** //***************************************************************************** // //! \addtogroup usblib_buffer_api //! @{ // //***************************************************************************** //***************************************************************************** // //! A function pointer type which describes either a class driver packet read //! or packet write function (both have the same prototype) to the USB //! buffer object. // //***************************************************************************** typedef uint32_t (* tUSBPacketTransfer)(void *pvHandle, uint8_t *pi8Data, uint32_t ui32Length, _Bool bLast); //***************************************************************************** // //! A function pointer type which describes either a class driver transmit //! or receive packet available function (both have the same prototype) to the //! USB buffer object. // //***************************************************************************** typedef uint32_t (* tUSBPacketAvailable)(void *pvHandle); //***************************************************************************** // //! The number of bytes of workspace that each USB buffer object requires. //! This workspace memory is provided to the buffer on USBBufferInit() in //! the \e pvWorkspace field of the \e tUSBBuffer structure. // //***************************************************************************** //***************************************************************************** // //! The structure used by the application to initialize a buffer object that //! will provide buffered access to either a transmit or receive channel. // //***************************************************************************** typedef struct { // //! This field sets the mode of the buffer. If true, the buffer //! operates as a transmit buffer and supports calls to USBBufferWrite //! by the client. If false, the buffer operates as a receive buffer //! and supports calls to USBBufferRead. // _Bool bTransmitBuffer; // //! A pointer to the callback function which will be called to notify //! the application of all asynchronous events related to the operation //! of the buffer. // tUSBCallback pfnCallback; // //! A pointer that the buffer will pass back to the client in the //! first parameter of all callbacks related to this instance. // void *pvCBData; // //! The function which should be called to transmit a packet of data //! in transmit mode or receive a packet in receive mode. // tUSBPacketTransfer pfnTransfer; // //! The function which should be called to determine if the endpoint is //! ready to accept a new packet for transmission in transmit mode or //! to determine the size of the buffer required to read a packet in //! receive mode. // tUSBPacketAvailable pfnAvailable; // //! The handle to pass to the low level function pointers //! provided in the pfnTransfer and pfnAvailable members. For USB device //! use, this is the psDevice parameter required by the relevant device //! class driver APIs. For USB host use, this is the pipe identifier //! returned by USBHCDPipeAlloc. // void *pvHandle; // //! A pointer to memory to be used as the ring buffer for this //! instance. // uint8_t *pui8Buffer; // //! The size, in bytes, of the buffer pointed to by pi8Buffer. // uint32_t ui32BufferSize; // //! A pointer to USB_BUFFER_WORKSPACE_SIZE bytes of RAM that the buffer //! object can use for workspace. // void *pvWorkspace; } tUSBBuffer; //***************************************************************************** // //! The structure used for encapsulating all the items associated with a //! ring buffer. // //***************************************************************************** typedef struct { // //! The ring buffer size. // uint32_t ui32Size; // //! The ring buffer write index. // volatile uint32_t ui32WriteIndex; // //! The ring buffer read index. // volatile uint32_t ui32ReadIndex; // //! The ring buffer. // uint8_t *pui8Buf; } tUSBRingBufObject; //***************************************************************************** // // Close the Doxygen group. //! @} // //***************************************************************************** //***************************************************************************** // // USB buffer API function prototypes. // //***************************************************************************** extern const tUSBBuffer *USBBufferInit(const tUSBBuffer *psBuffer); extern void USBBufferZeroLengthPacketInsert(const tUSBBuffer *psBuffer, _Bool bSendZLP); extern void USBBufferInfoGet(const tUSBBuffer *psBuffer, tUSBRingBufObject *psRingBuf); extern void *USBBufferCallbackDataSet(tUSBBuffer *psBuffer, void *pvCBData); extern uint32_t USBBufferWrite(const tUSBBuffer *psBuffer, const uint8_t *pui8Data, uint32_t ui32Length); extern void USBBufferDataWritten(const tUSBBuffer *psBuffer, uint32_t ui32Length); extern void USBBufferDataRemoved(const tUSBBuffer *psBuffer, uint32_t ui32Length); extern void USBBufferFlush(const tUSBBuffer *psBuffer); extern uint32_t USBBufferRead(const tUSBBuffer *psBuffer, uint8_t *pui8Data, uint32_t ui32Length); extern uint32_t USBBufferDataAvailable(const tUSBBuffer *psBuffer); extern uint32_t USBBufferSpaceAvailable(const tUSBBuffer *psBuffer); extern uint32_t USBBufferEventCallback(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, void *pvMsgData); extern _Bool USBRingBufFull(tUSBRingBufObject *psUSBRingBuf); extern _Bool USBRingBufEmpty(tUSBRingBufObject *psUSBRingBuf); extern void USBRingBufFlush(tUSBRingBufObject *psUSBRingBuf); extern uint32_t USBRingBufUsed(tUSBRingBufObject *psUSBRingBuf); extern uint32_t USBRingBufFree(tUSBRingBufObject *psUSBRingBuf); extern uint32_t USBRingBufContigUsed(tUSBRingBufObject *psUSBRingBuf); extern uint32_t USBRingBufContigFree(tUSBRingBufObject *psUSBRingBuf); extern uint32_t USBRingBufSize(tUSBRingBufObject *psUSBRingBuf); extern uint8_t USBRingBufReadOne(tUSBRingBufObject *psUSBRingBuf); extern void USBRingBufRead(tUSBRingBufObject *psUSBRingBuf, uint8_t *pui8Data, uint32_t ui32Length); extern void USBRingBufWriteOne(tUSBRingBufObject *psUSBRingBuf, uint8_t ui8Data); extern void USBRingBufWrite(tUSBRingBufObject *psUSBRingBuf, const uint8_t *pui8Data, uint32_t ui32Length); extern void USBRingBufAdvanceWrite(tUSBRingBufObject *psUSBRingBuf, uint32_t ui32NumBytes); extern void USBRingBufAdvanceRead(tUSBRingBufObject *psUSBRingBuf, uint32_t ui32NumBytes); extern void USBRingBufInit(tUSBRingBufObject *psUSBRingBuf, uint8_t *pui8Buf, uint32_t ui32Size); //***************************************************************************** // // Mode selection and dual mode interrupt steering functions. // //***************************************************************************** extern void USBStackModeSet(uint32_t ui32Index, tUSBMode iUSBMode, tUSBModeCallback pfnCallback); extern void USBDualModeInit(uint32_t ui32Index); extern void USBDualModeTerm(uint32_t ui32Index); extern void USBOTGMain(uint32_t ui32MsTicks); extern void USBOTGPollRate(uint32_t ui32Index, uint32_t ui32PollRate); extern void USBOTGModeInit(uint32_t ui32Index, uint32_t ui32PollRate, void *pHostData, uint32_t ui32HostDataSize); extern void USBOTGModeTerm(uint32_t ui32Index); extern void USB0OTGModeIntHandler(void); extern void USB0DualModeIntHandler(void); //***************************************************************************** // // Mark the end of the C bindings section for C++ compilers. // //***************************************************************************** //############################################################################# // FILE: usbhost.h // TITLE: Host specific definitions for the USB host library //############################################################################# // $TI Release: F2837xD Support Library v3.05.00.00 $ // $Release Date: Thu Oct 18 15:48:42 CDT 2018 $ // $Copyright: // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //############################################################################# //***************************************************************************** // // If building with a C++ compiler, make all of the definitions in this header // have a C binding. // //***************************************************************************** //***************************************************************************** // //! \addtogroup usblib_hcd //! @{ // //***************************************************************************** //***************************************************************************** // // This is the type used to identify what the pipe is currently in use for. // //***************************************************************************** //***************************************************************************** // // These are the defines that are used with USBHCDPowerConfigInit(). // //***************************************************************************** //***************************************************************************** // //! This macro is used to declare an instance of an Event driver for the USB //! library. //! //! \param VarName is the name of the variable. //! \param pfnOpen is the callback for the Open call to this driver. This //! value is currently reserved and should be set to 0. //! \param pfnClose is the callback for the Close call to this driver. This //! value is currently reserved and should be set to 0. //! \param pfnEvent is the callback that will be called for various USB events. //! //! The first parameter is the actual name of the variable that will //! be declared by this macro. The second and third parameter are reserved //! for future functionality and are unused and should be set to zero. The //! last parameter is the actual callback function and is specified as //! a function pointer of the type: //! //! void (*pfnEvent)(void *pvData); //! //! When the \e pfnEvent function is called the void pointer that is passed in //! as a parameter should be cast to a pointer to a structure of type //! tEventInfo. This will contain the event that caused the pfnEvent function //! to be called. // //***************************************************************************** //***************************************************************************** // // This is the type definition a callback for events on USB Pipes allocated // by USBHCDPipeAlloc(). // // \param ui32Pipe is well the pipe // \param ui32Event is well the event // // This prototype is used by any Pipe callbacks that are used in the host // class drivers. These functions typically handle data events like // USB_EVENT_RX_AVAILABLE or USB_EVENT_TX_COMPLETE but can be sent other events // depending on the USB host class in use. See the documentation for the // individual classes for the valid events for that class. // // \return None. // //***************************************************************************** typedef void (* tHCDPipeCallback)(uint32_t ui32Pipe, uint32_t ui32Event); //***************************************************************************** // // Predeclare the private tUSBHostDevice structure. // //***************************************************************************** typedef struct tUSBHostDevice tUSBHostDevice; //***************************************************************************** // //! This structure defines a USB host class driver interface, it is parsed to //! find a USB class driver once a USB device is enumerated. // //***************************************************************************** typedef struct { // //! The interface class that this device class driver supports. // uint32_t ui32InterfaceClass; // //! The function is called when this class of device has been detected. // void *(*pfnOpen)(tUSBHostDevice *psDevice); // //! The function is called when the device, originally opened with a call //! to the pfnOpen function, is disconnected. // void (*pfnClose)(void *pvInstance); // //! This is the optional interrupt handler that will be called when an //! endpoint associated with this device instance generates an interrupt. // void (*pfnIntHandler)(void *pvInstance); } tUSBHostClassDriver; //***************************************************************************** // // Close the Doxygen group. //! @} // //***************************************************************************** //***************************************************************************** // // If the g_USBEventDriver is included in the host controller driver list then // this function must be provided by the application. // //***************************************************************************** extern void USBHCDEvents(void *pvData); //***************************************************************************** // // Prototypes for the USB Host controller APIs. // //***************************************************************************** extern void USBHCDMain(void); extern int32_t USBHCDEventEnable(uint32_t ui32Index, void *pvEventDriver, uint32_t ui32Event); extern int32_t USBHCDEventDisable(uint32_t ui32Index, void *pvEventDriver, uint32_t ui32Event); extern void USBHCDInit(uint32_t ui32Index, void *pvData, uint32_t ui32Size); extern void USBHCDPowerConfigInit(uint32_t ui32Index, uint32_t ui32Flags); extern uint32_t USBHCDPowerConfigGet(uint32_t ui32Index); extern uint32_t USBHCDPowerConfigSet(uint32_t ui32Index, uint32_t ui32Config); extern uint32_t USBHCDPowerAutomatic(uint32_t ui32Index); extern void USBHCDRegisterDrivers(uint32_t ui32Index, const tUSBHostClassDriver * const *ppsHClassDrvrs, uint32_t ui32NumDrivers); extern void USBHCDTerm(uint32_t ui32Index); extern void USBHCDSetConfig(uint32_t ui32Index, uint32_t ui32Device, uint32_t ui32Configuration); extern void USBHCDSetInterface(uint32_t ui32Index, uint32_t ui32Device, uint32_t ui32Interface, uint32_t ui32AltSetting); extern void USBHCDSuspend(uint32_t ui32Index); extern void USBHCDResume(uint32_t ui32Index); extern void USBHCDReset(uint32_t ui32Index); extern void USBHCDPipeFree(uint32_t ui32Pipe); extern uint32_t USBHCDPipeAlloc(uint32_t ui32Index, uint32_t ui32EndpointType, tUSBHostDevice *psDevice, tHCDPipeCallback pfnCallback); extern uint32_t USBHCDPipeAllocSize(uint32_t ui32Index, uint32_t ui32EndpointType, tUSBHostDevice *psDevice, uint32_t ui32FIFOSize, tHCDPipeCallback pfnCallback); extern uint32_t USBHCDPipeConfig(uint32_t ui32Pipe, uint32_t ui32MaxPayload, uint32_t ui32Interval, uint32_t ui32TargetEndpoint); extern uint32_t USBHCDPipeStatus(uint32_t ui32Pipe); extern uint32_t USBHCDPipeWrite(uint32_t ui32Pipe, uint8_t *pui8Data, uint32_t ui32Size); extern uint32_t USBHCDPipeRead(uint32_t ui32Pipe, uint8_t *pui8Data, uint32_t ui32Size); extern uint32_t USBHCDPipeSchedule(uint32_t ui32Pipe, uint8_t *pui8Data, uint32_t ui32Size); extern void USBHCDPipeDataAck(uint32_t ui32Pipe); extern uint32_t USBHCDPipeReadNonBlocking(uint32_t ui32Pipe, uint8_t *pui8Data, uint32_t ui32Size); extern uint32_t USBHCDControlTransfer(uint32_t ui32Index, tUSBRequest *psSetupPacket, tUSBHostDevice *psDevice, uint8_t *pui8Data, uint32_t ui32Size, uint32_t ui32MaxPacketSize); extern void USB0HostIntHandler(void); extern uint8_t USBHCDDevHubPort(uint32_t ui32Instance); extern uint8_t USBHCDDevAddress(uint32_t ui32Instance); extern uint8_t USBHCDDevClass(uint32_t ui32Instance, uint32_t ui32Interface); extern uint8_t USBHCDDevSubClass(uint32_t ui32Instance, uint32_t ui32Interface); extern uint8_t USBHCDDevProtocol(uint32_t ui32Instance, uint32_t ui32Interface); //***************************************************************************** // // The host class drivers supported by the USB library. // //***************************************************************************** extern const tUSBHostClassDriver g_sUSBHostMSCClassDriver; extern const tUSBHostClassDriver g_sUSBHIDClassDriver; extern const tUSBHostClassDriver g_sUSBHostAudioClassDriver; //***************************************************************************** // // Mark the end of the C bindings section for C++ compilers. // //***************************************************************************** //############################################################################# // FILE: usbhostpriv.h // TITLE: Internal header file for USB host functions //############################################################################# // $TI Release: F2837xD Support Library v3.05.00.00 $ // $Release Date: Thu Oct 18 15:48:42 CDT 2018 $ // $Copyright: // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //############################################################################# //***************************************************************************** // // If building with a C++ compiler, make all of the definitions in this header // have a C binding. // //***************************************************************************** //***************************************************************************** // // The states a hub port can be in during device connection. // //***************************************************************************** typedef enum { // // The port has no device connected. // ePortIdle, // // The port has a device present and is waiting for the enumeration // sequence to begin. // ePortConnected, // // A device connection notification has been received and we have initiated // a reset to the port. We are waiting for the reset to complete. // ePortResetActive, // // The Port reset has completed but now the hub is waiting the required // 10ms before accessing the device. // ePortResetWait, // // A device is connected and the port has been reset. Control has been // passed to the main host handling portion of USBLib to enumerate the // device. // ePortActive, // // A device has completed enumeration. // ePortEnumerated, // // A device is attached to the port but enumeration failed. // ePortError } tHubPortState; //***************************************************************************** // // The list of valid event flags in the g_sUSBHCD.ui32EventEnables member // variable. // //***************************************************************************** //***************************************************************************** // //! This is the structure that holds all of the information for devices //! that are enumerated in the system. It is passed in to Open function of //! USB host class drivers so that they can allocate any endpoints and parse //! out other information that the device class needs to complete enumeration. // //***************************************************************************** struct tUSBHostDevice { // //! The current device address for this device. // uint32_t ui32Address; // //! The current interface for this device. // uint32_t ui32Interface; // //! A flag used to record whether this is a low-speed or a full-speed //! device. // _Bool bLowSpeed; // //! A flag indicating whether or not we have read the device's //! configuration descriptor yet. // _Bool bConfigRead; // //! The hub number to which this device is attached. // uint8_t ui8Hub; // //! The hub port number to which the device is attached. // uint8_t ui8HubPort; // //! The device descriptor for this device. // tDeviceDescriptor sDeviceDescriptor; // //! A pointer to the configuration descriptor for this device. // tConfigDescriptor *psConfigDescriptor; // //! The size of the buffer allocated to psConfigDescriptor. // uint32_t ui32ConfigDescriptorSize; // //! Internal flags used by the host controller driver. // uint32_t ui32Flags; }; //***************************************************************************** // // Functions within the host controller that are called by the hub class driver // //***************************************************************************** extern uint32_t USBHCDHubDeviceConnected(uint32_t ui32Index, uint8_t ui8Hub, uint8_t ui8Port, _Bool bLowSpeed); extern void USBHCDHubDeviceDisconnected(uint32_t ui32Index, uint32_t ui32DevIndex); //***************************************************************************** // // Functions in the hub class driver that are called by the host controller. // //***************************************************************************** extern void USBHHubMain(void); extern void USBHHubInit(void); extern void USBHHubEnumerationComplete(uint8_t ui8Hub, uint8_t ui8Port); extern void USBHHubEnumerationError(uint8_t ui8Hub, uint8_t ui8Port); //***************************************************************************** // // Mark the end of the C bindings section for C++ compilers. // //***************************************************************************** //############################################################################# // FILE: usbhhub.h // TITLE: This hold the host driver for hid class //############################################################################# // $TI Release: F2837xD Support Library v3.05.00.00 $ // $Release Date: Thu Oct 18 15:48:42 CDT 2018 $ // $Copyright: // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //############################################################################# //***************************************************************************** // // If building with a C++ compiler, make all of the definitions in this header // have a C binding. // //***************************************************************************** typedef struct tHubInstance tHubInstance; extern const tUSBHostClassDriver g_sUSBHubClassDriver; //***************************************************************************** // // The USB standard allows for up to 127 downstream ports on a single hub. // This would require rather more memory than we would like to set aside so the // default configuration of the hub driver supports hubs with up to 7 // downstream-facing ports. In practice, this should be more than enough // since this covers the vast majority of consumer hubs. Note that, by // default, we will only support 4 devices so you can't fully populate a 7 port // hub and have everything work. // // Feel free to change this but bad things will happen if you increase it above // 31 since we assume the reports will always fit inside a 4 byte buffer. // //***************************************************************************** //***************************************************************************** // // Values used as the ui16Feature parameter to USBHHubClearHubFeature(). // //***************************************************************************** //***************************************************************************** // // Values used as the ui16Feature parameter to USBHHubSetPortFeature() and // USBHHubClearPortFeature(). // //***************************************************************************** //***************************************************************************** // // Values returned via the *pui16HubStatus and *pui16HubChange parameters // passed to USBHHubGetHubStatus(). These may be ORed together into the // returned status value. // //***************************************************************************** //***************************************************************************** // // Values returned via the *pui16PortStatus parameter passed to // USBHHubGetPortStatus(). These may be ORed together into the returned status // value. // //***************************************************************************** //***************************************************************************** // // Values returned via the *pui16PortChange parameter passed to // USBHHubGetPortStatus(). These may be ORed together into the returned status // value. // //***************************************************************************** //***************************************************************************** // // The prototype for the USB Hub host driver callback function. // //***************************************************************************** typedef void (*tUSBHHubCallback)(tHubInstance *psHubInstance, uint32_t ui32Event, uint32_t ui32MsgParam, void *pvMsgData); //***************************************************************************** // // Public function prototypes for the HUB class driver. // //***************************************************************************** extern tHubInstance * USBHHubOpen(tUSBHHubCallback pfnCallback); extern void USBHHubClose(tHubInstance *psHubInstance); extern uint32_t USBHHubGetReport(tHubInstance *psHIDInstance, uint32_t ui32Interface, uint8_t *pui8Data, uint32_t ui32Size); //########################################################################### // // FILE: uartstdio.h // // TITLE: Prototypes for the UART console functions. // //########################################################################### // $TI Release: F2837xD Support Library v3.05.00.00 $ // $Release Date: Thu Oct 18 15:48:42 CDT 2018 $ // $Copyright: // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //########################################################################### // // Included Files // /*****************************************************************************/ /* stdarg.h */ /* */ /* Copyright (c) 1996 Texas Instruments Incorporated */ /* http://www.ti.com/ */ /* */ /* Redistribution and use in source and binary forms, with or without */ /* modification, are permitted provided that the following conditions */ /* are met: */ /* */ /* Redistributions of source code must retain the above copyright */ /* notice, this list of conditions and the following disclaimer. */ /* */ /* Redistributions in binary form must reproduce the above copyright */ /* notice, this list of conditions and the following disclaimer in */ /* the documentation and/or other materials provided with the */ /* distribution. */ /* */ /* Neither the name of Texas Instruments Incorporated nor the names */ /* of its contributors may be used to endorse or promote products */ /* derived from this software without specific prior written */ /* permission. */ /* */ /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */ /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */ /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */ /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */ /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */ /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */ /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */ /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* */ /*****************************************************************************/ /*****************************************************************************/ /* _ti_config.h */ /* */ /* Copyright (c) 2017 Texas Instruments Incorporated */ /* http://www.ti.com/ */ /* */ /* Redistribution and use in source and binary forms, with or without */ /* modification, are permitted provided that the following conditions */ /* are met: */ /* */ /* Redistributions of source code must retain the above copyright */ /* notice, this list of conditions and the following disclaimer. */ /* */ /* Redistributions in binary form must reproduce the above copyright */ /* notice, this list of conditions and the following disclaimer in */ /* the documentation and/or other materials provided with the */ /* distribution. */ /* */ /* Neither the name of Texas Instruments Incorporated nor the names */ /* of its contributors may be used to endorse or promote products */ /* derived from this software without specific prior written */ /* permission. */ /* */ /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */ /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */ /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */ /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */ /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */ /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */ /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */ /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* */ /*****************************************************************************/ #pragma diag_push #pragma CHECK_MISRA("-19.4") #pragma CHECK_MISRA("-19.1") /* Common definitions */ /* C */ /* C89/C99 */ /* _TI_NOEXCEPT_CPP14 is defined to noexcept only when compiling for C++14. It is intended to be used for functions like abort and atexit that are supposed to be declared noexcept only in C++14 mode. */ /* Target-specific definitions */ /*****************************************************************************/ /* linkage.h */ /* */ /* Copyright (c) 1998 Texas Instruments Incorporated */ /* http://www.ti.com/ */ /* */ /* Redistribution and use in source and binary forms, with or without */ /* modification, are permitted provided that the following conditions */ /* are met: */ /* */ /* Redistributions of source code must retain the above copyright */ /* notice, this list of conditions and the following disclaimer. */ /* */ /* Redistributions in binary form must reproduce the above copyright */ /* notice, this list of conditions and the following disclaimer in */ /* the documentation and/or other materials provided with the */ /* distribution. */ /* */ /* Neither the name of Texas Instruments Incorporated nor the names */ /* of its contributors may be used to endorse or promote products */ /* derived from this software without specific prior written */ /* permission. */ /* */ /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */ /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */ /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */ /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */ /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */ /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */ /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */ /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* */ /*****************************************************************************/ #pragma diag_push #pragma CHECK_MISRA("-19.4") /* macros required for implementation */ /* No modifiers needed to access code */ /*--------------------------------------------------------------------------*/ /* Define _DATA_ACCESS ==> how to access RTS global or static data */ /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/ /* Define _OPTIMIZE_FOR_SPACE ==> Always optimize for space. */ /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/ /* Define _IDECL ==> how inline functions are declared */ /*--------------------------------------------------------------------------*/ #pragma diag_pop #pragma diag_pop #pragma diag_push #pragma CHECK_MISRA("-20.1") /* standard headers must define standard names */ #pragma CHECK_MISRA("-20.2") /* standard headers must define standard names */ #pragma CHECK_MISRA("-19.7") /* macros required for implementation */ #pragma CHECK_MISRA("-19.10") /* need types as macro arguments */ typedef char *va_list; /****************************************************************************/ /* RETURN THE NEXT VALUE ON THE STACK ... */ /* */ /* (, ) BECOMES ... */ /* */ /* ap -= 1 (stack grows toward high addresses) */ /* ap -= 1 more if type is long or float */ /* ap -= 1 more if type is long or float and to account for alignment */ /* if necessary */ /* */ /* if () return **ap; */ /* else if () return *ap; */ /* */ /* LONG/FLOATS ARE ALWAYS ALIGNED ON AN EVEN WORD BOUNDARY, EVEN WHEN */ /* PASSED AS PARAMETERS, THUS ap MUST BE ALIGNED FOR THOSE ACCESSES. */ /****************************************************************************/ #pragma diag_pop //***************************************************************************** // // If building with a C++ compiler, make all of the definitions in this header // have a C binding. // //***************************************************************************** // // If built for buffered operation, the following labels define the sizes of // the transmit and receive buffers respectively. // // // Function Prototypes // extern void UARTStdioConfig(uint32_t ui32Port, uint32_t ui32Baud, uint32_t ui32SrcClock); extern int UARTgets(char *pcBuf, uint32_t ui32Len); extern unsigned char UARTgetc(void); extern void UARTprintf(const char *pcString, ...); extern void UARTvprintf(const char *pcString, va_list vaArgP); extern int UARTwrite(const char *pcBuf, uint32_t ui32Len); //***************************************************************************** // // Mark the end of the C bindings section for C++ compilers. // //***************************************************************************** // // End of file // uint16_t gPortStatus = 0; uint16_t gPortChange = 0; //***************************************************************************** // //! \addtogroup usblib_host_class //! @{ // //***************************************************************************** //***************************************************************************** // //! The USB standard hub descriptor structure. Full documentation for the //! contents of this structure can be found in chapter 11.23.2.1 of the USB //! 2.0 specification. // //***************************************************************************** typedef struct { // //! The total number of bytes in the descriptor (including this field). // uint8_t bLength; // //! The descriptor type. For a hub descriptor, this will be USB_DTYPE_HUB //! (0x29 or 41 decimal). // uint8_t bDescType; // //! The number of downstream-facing ports that the hub supports. // uint8_t bNbrPorts; // //! Characteristics of the hub device including its power switching //! capabilities and over-current protection mode. // uint16_t wHubCharacteristics; // //! The time between the start of the power-on sequence for a port and //! the power to the port becoming stable. This is expressed in 2mS units. // uint8_t bPwrOn2PwrGood; // //! The maximum current requirement for the hub circuitry in mA. // uint8_t bHubContrCurrent; // //! The last two fields in the structure are bit masks indicating which //! downstream ports support removable devices and, following this, another //! obsolete field from USB1.0 related to port power control. Each field //! is byte aligned and contains a bit for each hub port. This structure //! definition is set up with enough storage to handle ROOT_HUB_MAX_PORTS //! ports but beware that the actual size of each field is dependent upon //! the bNbrPorts field above. // uint8_t PortInfo[((7 + 7) / 8) * 2]; } tUsbHubDescriptor; //***************************************************************************** // // This structure holds all data specific to a single hub port. // //***************************************************************************** typedef struct { // // The handle used by the HCD layer to identify this device. // uint32_t ui32DevHandle; // // The current state of the port. // volatile tHubPortState iState; // // General counter used in various states. // volatile uint32_t ui32Count; // // A flag used to indicate that the downstream device is a low speed // device. // _Bool bLowSpeed; // // This flag is set if the hub reports that a change is pending on this // port. // volatile _Bool bChanged; } tHubPort; //***************************************************************************** // // USB hub flags values for tHubInstance.ui32Flags. // //***************************************************************************** //***************************************************************************** // // This is the structure that holds all of the data for a given instance of // a Hub device. // //***************************************************************************** struct tHubInstance { // // Save the device instance. // tUSBHostDevice *psDevice; // // Used to save the callback function pointer. // tUSBHHubCallback pfnCallback; // // Callback data provided by caller. // uint32_t ui32CBData; // // Interrupt IN pipe. // uint32_t ui32IntInPipe; // // Hub characteristics as reported in the class-specific hub descriptor. // uint16_t ui16HubCharacteristics; // // The number of downstream-facing ports the hub supports. // uint8_t ui8NumPorts; // // The number of ports on the hub that we can actually talk to. This will // be the smaller of the number of ports on the hub and MAX_USB_DEVICES. // uint8_t ui8NumPortsInUse; // // The size of a status change packet sent by the hub. This is determined // from the number of ports supported by the hub. // uint8_t ui8ReportSize; // // Flags indicating whether the hub is connected. // uint32_t ui32Flags; // // Flag indicating that a device is currently in process of being // enumerated. // volatile _Bool bEnumerationBusy; // // This is valid if bEnumerationBusy is set and indicates the port // that is in the process of enumeration. // uint8_t ui8EnumIdx; // // The state of each of the ports we support on the hub. // tHubPort psPorts[5]; // // The interrupt number for this instance. // uint32_t ui32IntNum; }; //***************************************************************************** // //! Forward references to the hub class driver functions. // //***************************************************************************** static void *HubDriverOpen(tUSBHostDevice *psDevice); static void HubDriverClose(void *pvHubDevice); //***************************************************************************** // //! This constant global structure defines the Hub Class Driver that is //! provided with the USB library. // //***************************************************************************** const tUSBHostClassDriver g_sUSBHubClassDriver = { 0x09, HubDriverOpen, HubDriverClose, 0 }; //***************************************************************************** // // The instance data storage for attached hub. // //***************************************************************************** static tHubInstance g_sRootHub; //***************************************************************************** // // Hub and port state change flags as reported via the hub's IN endpoint. // //***************************************************************************** static volatile uint32_t g_ui32ChangeFlags; // // Note: The following assumes ROOT_HUB_MAX_PORTS is less than 32! // static uint32_t g_ui32HubChanges; //***************************************************************************** // //! This function is used to retrieve a report from a HID device. //! //! \param psHIDInstance is the value that was returned from the call to //! USBHHIDOpen(). //! \param ui32Interface is the interface to retrieve the report from. //! \param pui8Data is the memory buffer to use to store the report. //! \param ui32Size is the size in bytes of the buffer pointed to by //! \e pui8Buffer. //! //! This function is used to retrieve a report from a USB pipe. It is usually //! called when the USB HID layer has detected a new data available in a USB //! pipe. The USB HID host device code will receive a //! \b USB_EVENT_RX_AVAILABLE event when data is available, allowing the //! callback function to retrieve the data. //! //! \return Returns the number of bytes read from report. // //***************************************************************************** uint32_t USBHHubGetReport(tHubInstance *psHIDInstance, uint32_t ui32Interface, uint8_t *pui8Data, uint32_t ui32Size) { // // Read the Data out. // ui32Size = USBHCDPipeReadNonBlocking(psHIDInstance->ui32IntInPipe, pui8Data, ui32Size); // // Return the number of bytes read from the interrupt in pipe. // return(ui32Size); } //***************************************************************************** // // This function is called to send a request to the hub to set a feature on // a given port. // // \param psHubInstance is the hub device instance. // \param ui8Port is the port number for this request. // \param ui16Feature is one of the HUB_FEATURE_PORT_* values. // // This function will send the set feature request to the hub indicated by the // \e psHubInstance parameter. The \e ui8Port value indicates which port // number to send this request to and can range from 0 to the number of valid // ports on the given hub. A \e ui8Port value of 0 is an access to the hub // itself and not one of the hub ports. The \e ui16Feature is the feature // request toset on the given port. For example, a \e ui16Feature value of // \e HUB_FEATURE_PORT_RESET and \e ui8Port value of 1 will cause reset // signaling to hub port 1. // // \return None. // //***************************************************************************** static void HubSetPortFeature(tHubInstance *psHubInstance, uint8_t ui8Port, uint16_t ui16Feature) { tUSBRequest sSetupPacket; tUSBHostDevice *psDevice; // // Retrieve the hub instance and device pointer. // psDevice = psHubInstance->psDevice; // // This is a standard OUT request. // sSetupPacket.bmRequestType = 0x00 | 0x20 | 0x03; // // Set the field to clear the requested port feature. // sSetupPacket.bRequest = 0x03; {((usb16_t *)&(sSetupPacket . wValue))->LSB = ui16Feature & 0xFF; ((usb16_t *)&(sSetupPacket . wValue))->MSB = (ui16Feature & 0xFF00) >> 8;}; {((usb16_t *)&(sSetupPacket . wIndex))->LSB = ui8Port & 0xFF; ((usb16_t *)&(sSetupPacket . wIndex))->MSB = (ui8Port & 0xFF00) >> 8;}; {((usb16_t *)&(sSetupPacket . wLength))->LSB = 0 & 0xFF; ((usb16_t *)&(sSetupPacket . wLength))->MSB = (0 & 0xFF00) >> 8;}; // // Send the request. // USBHCDControlTransfer(0, &sSetupPacket, psDevice, 0, 0, psDevice->sDeviceDescriptor.bMaxPacketSize0); } //***************************************************************************** // // This function is called to send a request to the hub to clear a feature on // a given port. // // \param psHubInstance is the hub device instance. // \param ui8Port is the port number for this request. // \param ui16Feature is one of the HUB_FEATURE_PORT_* values. // // This function will send the clear feature request to the hub indicated by // the \e psHubInstance parameter. The \e ui8Port value indicates which port // number to send this request to and can range from 0 to the number of valid // ports on the given hub. A \e ui8Port value of 0 is an access to the hub // itself and not one of the hub ports. The \e ui16Feature is the feature // request to clear on the given port. For example, a \e ui16Feature value of // \e HUB_FEATURE_C_PORT_RESET and \e ui8Port value of 1 will clear the reset // complete signaling on hub port 1. Values like the reset feature will // remain set until actively cleared by this function. // // \return None. // //***************************************************************************** static void HubClearPortFeature(tHubInstance *psHubInstance, uint8_t ui8Port, uint16_t ui16Feature) { tUSBRequest sSetupPacket; tUSBHostDevice *psDevice; // // Retrieve the hub instance and device pointer. // psDevice = psHubInstance->psDevice; // // This is a standard OUT request. // sSetupPacket.bmRequestType = 0x00 | 0x20 | 0x03; // // Set the field to clear the requested port feature. // sSetupPacket.bRequest = 0x01; {((usb16_t *)&(sSetupPacket . wValue))->LSB = ui16Feature & 0xFF; ((usb16_t *)&(sSetupPacket . wValue))->MSB = (ui16Feature & 0xFF00) >> 8;}; {((usb16_t *)&(sSetupPacket . wIndex))->LSB = ui8Port & 0xFF; ((usb16_t *)&(sSetupPacket . wIndex))->MSB = (ui8Port & 0xFF00) >> 8;}; {((usb16_t *)&(sSetupPacket . wLength))->LSB = 0 & 0xFF; ((usb16_t *)&(sSetupPacket . wLength))->MSB = (0 & 0xFF00) >> 8;}; // // Send the request. // USBHCDControlTransfer(0, &sSetupPacket, psDevice, 0, 0, psDevice->sDeviceDescriptor.bMaxPacketSize0); } //***************************************************************************** // // This function is used to retrieve the current status of a port on the // hub. // // \param psHubInstance is the hub device instance. // \param ui8Port is the port number for this request. // \param pui16PortStatus is a pointer to the memory to store the current // status of the port. // \param pui16PortChange is a pointer to the memory to store the current // change status of the ports. // // This function is used to retrieve the current overall status and change // status for the port given in the \e ui8Port parameter. The \e ui8Port value // indicates which port number to send this request to and can range from 0 to // the number of valid ports on the given hub. A \e ui8Port value of 0 is an // access to the hub itself and not one of the hub ports. // // \return None. // //***************************************************************************** static _Bool HubGetPortStatus(tHubInstance *psHubInstance, uint8_t ui8Port, uint16_t *pui16PortStatus, uint16_t *pui16PortChange) { uint32_t ui32Data, ui32Read; tUSBRequest sSetupPacket; tUSBHostDevice *psDevice; // // Retrieve the device pointer. // psDevice = psHubInstance->psDevice; // // This is a standard OUT request. // sSetupPacket.bmRequestType = 0x80 | 0x20 | 0x03; // // Set the fields to get the hub status. // sSetupPacket.bRequest = 0x00; {((usb16_t *)&(sSetupPacket . wValue))->LSB = 0 & 0xFF; ((usb16_t *)&(sSetupPacket . wValue))->MSB = (0 & 0xFF00) >> 8;}; {((usb16_t *)&(sSetupPacket . wIndex))->LSB = (uint16_t)ui8Port & 0xFF; ((usb16_t *)&(sSetupPacket . wIndex))->MSB = ((uint16_t)ui8Port & 0xFF00) >> 8;}; {((usb16_t *)&(sSetupPacket . wLength))->LSB = 4 & 0xFF; ((usb16_t *)&(sSetupPacket . wLength))->MSB = (4 & 0xFF00) >> 8;}; // // Send the request. // ui32Read = USBHCDControlTransfer(0, &sSetupPacket, psDevice, (uint8_t *)&ui32Data, 4, psDevice->sDeviceDescriptor.bMaxPacketSize0); // // Check that we received the correct number of bytes. // if(ui32Read != 4) { return(0); } else { // // We got 4 bytes from the device. Now translate these into the 2 // 16-bit values we pass back to the caller. // // DEBUG_OUTPUT("Port %d, Data = %x\n", ui8Port, (uint32_t)ui32Data); *pui16PortStatus = (uint16_t)(ui32Data & 0xFFFF); *pui16PortChange = (uint16_t)(ui32Data >> 16); // gPortStatus = *pui16PortStatus; // gPortChange = *pui16PortChange; // DEBUG_OUTPUT("Port %d, Data = %d, status = %d, change = %d\n", ui8Port, ui32Data, // *pui16PortStatus, *pui16PortChange); UARTprintf("Port %d, status 0x%04x, change 0x%04x\n", ui8Port, *pui16PortStatus, *pui16PortChange); } // // All is well. // return(1); } //***************************************************************************** // // This function handles callbacks for the interrupt IN endpoint for the hub // device. // //***************************************************************************** static void HubIntINCallback(uint32_t ui32Pipe, uint32_t ui32Event) { switch (ui32Event) { // // Handles a request to schedule a new request on the interrupt IN // pipe. // case (0x0000 + 9): { // // Set things up to read the next change indication from the hub. // USBHCDPipeSchedule(ui32Pipe, (uint8_t *)&g_ui32HubChanges, (uint32_t)g_sRootHub.ui8ReportSize); break; } // // Called when new data is available on the interrupt IN pipe. // case (0x0000 + 2): { // // For data transfers on INT IN endpoints, we need to acknowledge // the data from this callback. // USBHCDPipeDataAck(ui32Pipe); // // Update our global "ports needing service" flags with the latest // information we have just received. // g_ui32ChangeFlags |= g_ui32HubChanges; // // Send the report data to the USB host hub device class driver if // we have been given a callback function. // if(g_sRootHub.pfnCallback) { g_sRootHub.pfnCallback((void *)g_sRootHub.ui32CBData, (0x0000 + 2), ui32Pipe, &g_ui32HubChanges); } break; } case (0x0000 + 6): { break; } } } //***************************************************************************** // // Query the class-specific hub descriptor. // //***************************************************************************** static _Bool GetHubDescriptor(tUsbHubDescriptor *psDesc) { uint32_t ui32Read; tUSBRequest sSetupPacket; tUSBHostDevice *psDevice; // // Retrieve the device pointer. // psDevice = g_sRootHub.psDevice; // // This is a standard OUT request. // sSetupPacket.bmRequestType = 0x80 | 0x20 | 0x00; // // Set the fields to get the hub descriptor. Initially, we request only // the first 4 bytes of the descriptor. This will give us the size which // we use to determine how many bytes to read to get the full descriptor. // This is necessary since we don't know how many ports the hub can support // and we only support up to MAX_USB_DEVICES. // sSetupPacket.bRequest = 0x06; {((usb16_t *)&(sSetupPacket . wValue))->LSB = ((uint32_t)41 << 8) & 0xFF; ((usb16_t *)&(sSetupPacket . wValue))->MSB = (((uint32_t)41 << 8) & 0xFF00) >> 8;}; {((usb16_t *)&(sSetupPacket . wIndex))->LSB = 0 & 0xFF; ((usb16_t *)&(sSetupPacket . wIndex))->MSB = (0 & 0xFF00) >> 8;}; {((usb16_t *)&(sSetupPacket . wLength))->LSB = sizeof(tUsbHubDescriptor) & 0xFF; ((usb16_t *)&(sSetupPacket . wLength))->MSB = (sizeof(tUsbHubDescriptor) & 0xFF00) >> 8;}; // // Send the request. // ui32Read = USBHCDControlTransfer(0, &sSetupPacket, psDevice, (void *)psDesc, sizeof(tUsbHubDescriptor), psDevice->sDeviceDescriptor.bMaxPacketSize0); // // Make sure we got at least some data. // if(ui32Read == 0) { return(0); } // // All is well. // return(1); } //***************************************************************************** // // Open an instance of the hub driver. This is called when the USB host // has enumerated a new hub device. // //***************************************************************************** static void * HubDriverOpen(tUSBHostDevice *psDevice) { tEndpointDescriptor *psEndpointDescriptor; tInterfaceDescriptor *psInterface; tUsbHubDescriptor sHubDesc; _Bool bRetcode; uint32_t ui32Loop; // // If we are already talking to a hub, fail the call. We only support // a single hub. // if(g_sRootHub.ui32Flags & 0x00000001) { return(0); } // // Get pointers to the device descriptors we need to look at. // psInterface = USBDescGetInterface(psDevice->psConfigDescriptor, 0, 0); psEndpointDescriptor = USBDescGetInterfaceEndpoint(psInterface, 0, psDevice->ui32ConfigDescriptorSize); // // If there are no endpoints, something is wrong since a hub must have // a single INT endpoint for signaling. // if(psEndpointDescriptor == 0) { return 0; } // // Make sure we really are talking to a hub. // if((psInterface->bInterfaceClass != 0x09) || (psInterface->bInterfaceSubClass != 0)) { // // Something is wrong - this isn't a hub or, if it is, we don't // understand the protocol it is using. // return(0); } // // Remember the device information for later. // g_sRootHub.psDevice = psDevice; // // A hub must support an interrupt endpoint so check this. // if((psEndpointDescriptor->bmAttributes & 0x03) == 0x03) { // // The endpoint is the correct type. Is it an IN endpoint? // if(psEndpointDescriptor->bEndpointAddress & 0x80) { // // Yes - all is well with the hub endpoint so allocate a pipe to // handle traffic from the hub. // g_sRootHub.ui32IntInPipe = USBHCDPipeAlloc(0, 0x00420000, psDevice, HubIntINCallback); USBHCDPipeConfig(g_sRootHub.ui32IntInPipe, ((unsigned short)(((usb16_t *)&(psEndpointDescriptor->wMaxPacketSize))->LSB | ((usb16_t *)&(psEndpointDescriptor->wMaxPacketSize))->MSB << 8)), psEndpointDescriptor->bInterval, psEndpointDescriptor->bEndpointAddress & 0x0f); } } // // Did we allocate the endpoint successfully? // if(!g_sRootHub.ui32IntInPipe) { // // No - return an error. // return 0; } // // Assuming we have a callback, call it to tell the owner that a hub is // now connected. // if(g_sRootHub.pfnCallback != 0) { g_sRootHub.pfnCallback((void *)g_sRootHub.ui32CBData, (0x0000 + 0), (uint32_t)&g_sRootHub, 0); } // // Get the hub descriptor and store information we'll need for later. // bRetcode = GetHubDescriptor(&sHubDesc); if(bRetcode) { // // We read the descriptor successfully so extract the parts we need. // g_sRootHub.ui8NumPorts = sHubDesc.bNbrPorts; g_sRootHub.ui16HubCharacteristics = sHubDesc.wHubCharacteristics; g_sRootHub.ui8NumPortsInUse = (sHubDesc.bNbrPorts > 5) ? 5 : sHubDesc.bNbrPorts; // // The size of the status change report that the hub sends is dependent // upon the number of ports that the hub supports. Calculate this by // adding 1 to the number of ports (bit 0 of the report is the hub // status, higher bits are one per port) then dividing by 8 (bits per // byte) and rounding up. // g_sRootHub.ui8ReportSize = ((sHubDesc.bNbrPorts + 1) + 7) / 8; // // Enable power to all ports on the hub. // for(ui32Loop = 1; ui32Loop <= sHubDesc.bNbrPorts; ui32Loop++) { // // Turn on power to this port. // HubSetPortFeature(&g_sRootHub, ui32Loop, 8); } // // Clear out our port state structures. // for(ui32Loop = 0; ui32Loop < 5; ui32Loop++) { g_sRootHub.psPorts[ui32Loop].bChanged = 0; g_sRootHub.psPorts[ui32Loop].iState = ePortIdle; } } else { // // Oops - we can't read the hub descriptor! Tidy up and return // an error. // USBHCDPipeFree(g_sRootHub.ui32IntInPipe); g_sRootHub.pfnCallback = 0; g_sRootHub.ui32Flags &= ~0x00000001; return(0); } // // If we get here, all is well so remember that the hub is connected and // active. // g_sRootHub.ui32Flags |= 0x00000001; // // Return our instance data pointer to the caller to use as a handle. // return((void *)&g_sRootHub); } //***************************************************************************** // // Close an instance of the hub driver. // //***************************************************************************** static void HubDriverClose(void *pvHubDevice) { uint32_t ui32Loop; // // No device so just exit. // if(g_sRootHub.psDevice == 0) { return; } // // Disconnect any devices that are currently connected to the hub. // for(ui32Loop = 0; ui32Loop < 5; ui32Loop++) { // // Does this port have a device connected to it that we have previously // reported to the host control layer?h // if((g_sRootHub.psPorts[ui32Loop].iState == ePortActive) || (g_sRootHub.psPorts[ui32Loop].iState == ePortResetWait) || (g_sRootHub.psPorts[ui32Loop].iState == ePortEnumerated) || (g_sRootHub.psPorts[ui32Loop].iState == ePortError)) { // // Yes - tell the host controller to disconnect the device. // USBHCDHubDeviceDisconnected(0, g_sRootHub.psPorts[ui32Loop].ui32DevHandle); } // // Make sure that the state returns to idle. // g_sRootHub.psPorts[ui32Loop].iState = ePortIdle; } // // Reset the device pointer. // g_sRootHub.psDevice = 0; // // Mark the hub as absent. // g_sRootHub.ui32Flags &= ~0x00000001; // // Note that we are not in the middle of enumerating anything. // g_sRootHub.bEnumerationBusy = 0; // // Free the Interrupt IN pipe. // if(g_sRootHub.ui32IntInPipe != 0) { USBHCDPipeFree(g_sRootHub.ui32IntInPipe); } // // If the callback exists, call it with a DISCONNECTED event. // if(g_sRootHub.pfnCallback != 0) { g_sRootHub.pfnCallback((void *)g_sRootHub.ui32CBData, (0x0000 + 1), (uint32_t)&g_sRootHub, 0); } } //***************************************************************************** // // Perform any processing required as a result of a change in the reset // signaling for a given port. // //***************************************************************************** static void HubDriverReset(uint8_t ui8Port, _Bool bResetActive) { // // Did the reset sequence end or begin? // if(!bResetActive) { // // The reset ended. Now wait for at least 10ms before signaling // USB enumeration code that a new device is waiting to be enumerated. // g_sRootHub.psPorts[ui8Port].iState = ePortResetWait; // // Set the wait to 10ms (10 frames) from now. // g_sRootHub.psPorts[ui8Port].ui32Count = 10; } else { // // Was this device previously active? // if(g_sRootHub.psPorts[ui8Port].iState == ePortActive) { USBHCDHubDeviceDisconnected(0, g_sRootHub.psPorts[ui8Port].ui32DevHandle); } // // The reset is active so mark our port as in reset. // g_sRootHub.psPorts[ui8Port].iState = ePortResetActive; } } //***************************************************************************** // // Start the process of enumerating a new device by issuing a reset to the // appropriate downstream port. // //***************************************************************************** static void HubDriverDeviceReset(uint8_t ui8Port) { UARTprintf("Starting enumeration for port %d\n", ui8Port); // // Record the fact that we are in the process of enumerating a device. // g_sRootHub.bEnumerationBusy = 1; // // Save the port that is being enumerated. // g_sRootHub.ui8EnumIdx = ui8Port; // // Mark the port as being reset. // g_sRootHub.psPorts[ui8Port].iState = ePortResetActive; // // Initiate a reset on the relevant port to start the enumeration process. // HubSetPortFeature(&g_sRootHub, ui8Port, 4); } //***************************************************************************** // // A new device has been connected to the hub. Allocate resources to manage // it and pass details back to the main USB host enumeration code to have the // device enumerated. // //***************************************************************************** static void HubDriverDeviceConnect(uint8_t ui8Port, _Bool bLowSpeed) { UARTprintf("HubDriverDeviceConnect\n"); // // We've allocated a port table entry so fill it in then initiate a reset // on the device. // g_sRootHub.psPorts[ui8Port].bChanged = 0; g_sRootHub.psPorts[ui8Port].bLowSpeed = bLowSpeed; // // Mark the port as having a device present but not enumerated. // UARTprintf("Deferring enumeration for port %d\n", ui8Port); g_sRootHub.psPorts[ui8Port].iState = ePortConnected; // // Wait 100ms to reset the device. // g_sRootHub.psPorts[ui8Port].ui32Count = 100; } //***************************************************************************** // // An existing device has been removed from the hub. Tidy up and let the main // USB host code know so that it can free device resources. // //***************************************************************************** static void HubDriverDeviceDisconnect(uint8_t ui8Port) { // // This is a device we are currently managing. Have we already informed // the host controller that it is present? // if((g_sRootHub.psPorts[ui8Port].iState == ePortActive) || (g_sRootHub.psPorts[ui8Port].iState == ePortResetWait) || (g_sRootHub.psPorts[ui8Port].iState == ePortEnumerated) || (g_sRootHub.psPorts[ui8Port].iState == ePortError)) { // // Yes - tell the host controller that the device is not longer // connected. // USBHCDHubDeviceDisconnected(0, g_sRootHub.psPorts[ui8Port].ui32DevHandle); } // // If the device was being enumerated, make sure we clear the flag // indicating that an enumeration is still ongoing. // if((g_sRootHub.psPorts[ui8Port].iState == ePortResetActive) || (g_sRootHub.psPorts[ui8Port].iState == ePortResetWait) || (g_sRootHub.psPorts[ui8Port].iState == ePortActive)) { g_sRootHub.bEnumerationBusy = 0; } // // Free up the port state structure. // g_sRootHub.psPorts[ui8Port].iState = ePortIdle; } //***************************************************************************** // // This function is called periodically by USBHCDMain(). We use it to handle // the hub port state machine. // //***************************************************************************** void USBHHubMain(void) { uint16_t ui16Status, ui16Changed; uint_fast8_t ui8Port; _Bool bRetcode; // // If the hub is not present, just return. // if((g_sRootHub.ui32Flags & 0x00000001) == 0) { return; } // // Initialize the status variables. // ui16Status = 0; ui16Changed = 0; // // The hub is active and something changed. Check to see which port changed // state and handle as necessary. // for(ui8Port = 0; ui8Port <= g_sRootHub.ui8NumPortsInUse; ui8Port++) { // // Decrement any wait counter if there is one present. // if(g_sRootHub.psPorts[ui8Port].ui32Count != 0) { g_sRootHub.psPorts[ui8Port].ui32Count--; } // // Is this port waiting to be enumerated and is the last device // enumeration finished? // if((g_sRootHub.psPorts[ui8Port].iState == ePortConnected) && (!g_sRootHub.bEnumerationBusy) && (g_sRootHub.psPorts[ui8Port].ui32Count == 0)) { // // Yes - start the enumeration processing for this device. // HubDriverDeviceReset(ui8Port); } // // If the state is ePortResetWait then the hub is waiting before // accessing device as the USB 2.0 specification requires. // if((g_sRootHub.psPorts[ui8Port].iState == ePortResetWait) && (g_sRootHub.psPorts[ui8Port].ui32Count == 0)) { // // Start the enumeration process if the timeout has passed and // the hub is waiting to start enumerating the device. // g_sRootHub.psPorts[ui8Port].iState = ePortActive; // // Call the main host controller layer to have it enumerate the // newly connected device. // g_sRootHub.psPorts[ui8Port].ui32DevHandle = USBHCDHubDeviceConnected(0, 1, ui8Port, g_sRootHub.psPorts[ui8Port].bLowSpeed); } // // If an enumeration is in progress and the loop is not on the port // being enumerated then skip the port. // if(g_sRootHub.bEnumerationBusy && (g_sRootHub.ui8EnumIdx != ui8Port)) { continue; } // // Did something change for this particular port? // if(g_ui32ChangeFlags & ((uint32_t)1 << ui8Port)) { // // Yes - query the port status. // bRetcode = HubGetPortStatus(&g_sRootHub, ui8Port, &ui16Status, &ui16Changed); // ui16Status = gPortStatus; // ui16Changed = gPortChange; // DEBUG_OUTPUT("Port %d, ui16Status = %d, ui16Changed = %d\n", ui8Port, // ui16Status, ui16Changed); // // Clear this change with the USB interrupt temporarily disabled to // ensure that we do not clear a flag that the interrupt routine // has just set. // IntDisable(g_sRootHub . ui32IntNum); g_ui32ChangeFlags &= ~((uint32_t)1 << ui8Port); IntEnable(g_sRootHub . ui32IntNum); // // If there was an error, go on and look at the next bit. // if(!bRetcode) { continue; } // // Now consider what changed and handle it as necessary. // // // Was a device connected to or disconnected from the port? // if(ui16Changed & 0x0001) { UARTprintf("Connection change on port %d\n", ui8Port); // // Clear the condition. // HubClearPortFeature(&g_sRootHub, ui8Port, 16); // // Was a device connected or disconnected? // if(ui16Status & 0x0001) { UARTprintf("Connected\n"); // // A device was connected. // HubDriverDeviceConnect(ui8Port, ((ui16Status & 0x0200) ? 1 : 0)); } else { UARTprintf("Disconnected\n"); // // A device was disconnected. // HubDriverDeviceDisconnect(ui8Port); } } // // Did a reset on the port complete? // if(ui16Changed & 0x0010) { // // Clear the condition. // HubClearPortFeature(&g_sRootHub, ui8Port, 20); // // Yes - query the port status. // bRetcode = HubGetPortStatus(&g_sRootHub, ui8Port, &ui16Status, &ui16Changed); // ui16Status = gPortStatus; // DEBUG_OUTPUT("ui16Status = %d\n", ui16Status); UARTprintf("Reset %s for port %d\n", ((ui16Status & 0x0010) ? "asserted" : "deasserted"), ui8Port); // // Handle the reset case. // HubDriverReset(ui8Port, (ui16Status & 0x0010) ? 1 : 0); } // // Did an over-current reset on the port complete? // if(ui16Changed & 0x0008) { UARTprintf("Port %d over current.\n", ui8Port); // // Currently we ignore this and just clear the condition. // HubClearPortFeature(&g_sRootHub, ui8Port, 19); } // // Has the port been enabled or disabled? // if(ui16Changed & 0x0002) { UARTprintf("Enable change for port %d.\n", ui8Port); // // Currently we ignore this and just clear the condition. // HubClearPortFeature(&g_sRootHub, ui8Port, 17); } // // Has the port been suspended or resumed? // if(ui16Changed & 0x0004) { UARTprintf("Suspend change for port %d.\n", ui8Port); // // Currently we ignore this and just clear the condition. // HubClearPortFeature(&g_sRootHub, ui8Port, 18); } } } } //***************************************************************************** // //! Informs the hub class driver that a downstream device has been enumerated. //! //! \param ui8Hub is the address of the hub to which the downstream device //! is attached. //! \param ui8Port is the port on the hub to which the downstream device is //! attached. //! //! This function is called by the host controller driver to inform the hub //! class driver that a downstream device has been enumerated successfully. //! The hub driver then moves on and continues enumeration of any other newly //! connected devices. //! //! \return None. // //***************************************************************************** void USBHHubEnumerationComplete(uint8_t ui8Hub, uint8_t ui8Port) { UARTprintf("Enumeration complete for hub %d, port %d\n", ui8Hub, ui8Port); // // Record the fact that the device is up and running. // g_sRootHub.psPorts[ui8Port].iState = ePortEnumerated; // // Clear the flag we use to defer further enumerations. This will cause // the next connected device (if any) to start enumeration on the next // call to USBHHubMain(). // g_sRootHub.bEnumerationBusy = 0; } //***************************************************************************** // //! Informs the hub class driver that a downstream device failed to enumerate. //! //! \param ui8Hub is the address of the hub to which the downstream device //! is attached. //! \param ui8Port is the port on the hub to which the downstream device is //! attached. //! //! This function is called by the host controller driver to inform the hub //! class driver that an attempt to enumerate a downstream device has failed. //! The hub driver then cleans up and continues enumeration of any other newly //! connected devices. //! //! \return None. // //***************************************************************************** void USBHHubEnumerationError(uint8_t ui8Hub, uint8_t ui8Port) { UARTprintf("Enumeration error for hub %d, port %d\n", ui8Hub, ui8Port); // // Record the fact that the device is not working correctly. // g_sRootHub.psPorts[ui8Port].iState = ePortError; // // Clear the flag we use to defer further enumerations. This will cause // the next connected device (if any) to start enumeration on the next // call to USBHHubMain(). // g_sRootHub.bEnumerationBusy = 0; } //***************************************************************************** // //! This function is used to enable the host hub class driver before any //! devices are present. //! //! \param pfnCallback is the driver call back for host hub events. //! //! This function is called to open an instance of a host hub device and //! provides a valid callback function for host hub events in the //! \e pfnCallback parameter. This function must be called before the USB //! host code can successfully enumerate a hub device or any devices attached //! to the hub. The \e pui8HubPool is memory provided to the hub class to //! manage the devices that are connected to the hub. The \e ui32PoolSize is //! the number of bytes and should be at least 32 bytes per device including //! the hub device itself. A simple formula for providing memory to the hub //! class is \b MAX_USB_DEVICES * 32 bytes of data to allow for proper //! enumeration of connected devices. The value for \b MAX_USB_DEVICES is //! defined in the usblib.h file and controls the number of devices //! supported by the USB library. The \e ui32NumHubs parameter //! defaults to one and only one buffer of size tHubInstance is required to //! be passed in the \e psHubInstance parameter. //! //! \note Changing the value of \b MAX_USB_DEVICES requires a rebuild of the //! USB library to have an effect on the library. //! //! \return This function returns the driver instance to use for the other //! host hub functions. If there is no instance available at the time of //! this call, this function returns zero. // //***************************************************************************** tHubInstance * USBHHubOpen(tUSBHHubCallback pfnCallback) { // // Only one hub is supported. // if(g_sRootHub.pfnCallback) { UARTprintf("USBHHubOpen failed - already connected.\n"); return(0); } // // Save the instance data for this device. // g_sRootHub.pfnCallback = pfnCallback; UARTprintf("USBHHubOpen completed.\n"); // // Return the device instance pointer. // return(&g_sRootHub); } //***************************************************************************** // //! This function is used to release a hub device instance. //! //! \param psHubInstance is the hub device instance that is to be released. //! //! This function is called when an instance of the hub device must be //! released. This function is typically made in preparation for shutdown or a //! switch to function as a USB device when in OTG mode. Following this call, //! the hub device is no longer available, but it can be opened again using a //! call to USBHHubOpen(). After calling USBHHubClose(), the host hub driver //! no longer provides any callbacks or accepts calls to other hub driver APIs. //! //! \return None. // //***************************************************************************** void USBHHubClose(tHubInstance *psHubInstance) { // // Forget the instance pointer and callback. // psHubInstance->psDevice = 0; psHubInstance->pfnCallback = 0; UARTprintf("USBHHubClose completed.\n"); } //***************************************************************************** // // This function is used to initialize the Hub driver. This is an internal // function that should not be called by the application. // //***************************************************************************** void USBHHubInit(void) { // // Initialize Hub state. // g_ui32ChangeFlags = 0; g_ui32HubChanges = 0; g_sRootHub.ui32Flags = 0; if(g_sRootHub.psDevice != 0) { // // Save the USB interrupt number. // g_sRootHub.ui32IntNum = 0xC6090F; } } //***************************************************************************** // //! @} // //*****************************************************************************