USBDevice for STM support

Dependents:   Nucleo_Usb_JoyMouse Nucleo_usbmouse ELEC350_1-referral-2018-usb-hid USBJoystick_HelloWorld2_wip ... more

This library contains all mbed usb device library (mbed-os\features\unsupported\USBDevice).

Committer:
frq08711@LMECWL0871.LME.ST.COM
Date:
Tue Mar 28 11:00:57 2017 +0200
Branch:
master
Revision:
4:50ec00aa4515
Parent:
1:2a3ae13b45ef
update for 5.4.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 2 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 4 * and associated documentation files (the "Software"), to deal in the Software without
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 7 * Software is furnished to do so, subject to the following conditions:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 8 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 9 * The above copyright notice and this permission notice shall be included in all copies or
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 10 * substantial portions of the Software.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 11 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 17 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 18
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 19 #if defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 20
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 21 #include "USBHAL.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 22
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 23
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 24 // Get endpoint direction
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 25 #define IN_EP(endpoint) ((endpoint) & 1U ? true : false)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 26 #define OUT_EP(endpoint) ((endpoint) & 1U ? false : true)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 27
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 28 // Convert physical endpoint number to register bit
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 29 #define EP(endpoint) (1UL<<endpoint)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 30
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 31 // Power Control for Peripherals register
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 32 #define PCUSB (1UL<<31)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 33
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 34 // USB Clock Control register
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 35 #define DEV_CLK_EN (1UL<<1)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 36 #define PORT_CLK_EN (1UL<<3)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 37 #define AHB_CLK_EN (1UL<<4)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 38
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 39 // USB Clock Status register
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 40 #define DEV_CLK_ON (1UL<<1)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 41 #define AHB_CLK_ON (1UL<<4)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 42
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 43 // USB Device Interupt registers
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 44 #define FRAME (1UL<<0)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 45 #define EP_FAST (1UL<<1)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 46 #define EP_SLOW (1UL<<2)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 47 #define DEV_STAT (1UL<<3)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 48 #define CCEMPTY (1UL<<4)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 49 #define CDFULL (1UL<<5)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 50 #define RxENDPKT (1UL<<6)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 51 #define TxENDPKT (1UL<<7)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 52 #define EP_RLZED (1UL<<8)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 53 #define ERR_INT (1UL<<9)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 54
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 55 // USB Control register
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 56 #define RD_EN (1<<0)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 57 #define WR_EN (1<<1)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 58 #define LOG_ENDPOINT(endpoint) ((endpoint>>1)<<2)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 59
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 60 // USB Receive Packet Length register
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 61 #define DV (1UL<<10)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 62 #define PKT_RDY (1UL<<11)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 63 #define PKT_LNGTH_MASK (0x3ff)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 64
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 65 // Serial Interface Engine (SIE)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 66 #define SIE_WRITE (0x01)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 67 #define SIE_READ (0x02)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 68 #define SIE_COMMAND (0x05)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 69 #define SIE_CMD_CODE(phase, data) ((phase<<8)|(data<<16))
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 70
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 71 // SIE Command codes
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 72 #define SIE_CMD_SET_ADDRESS (0xD0)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 73 #define SIE_CMD_CONFIGURE_DEVICE (0xD8)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 74 #define SIE_CMD_SET_MODE (0xF3)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 75 #define SIE_CMD_READ_FRAME_NUMBER (0xF5)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 76 #define SIE_CMD_READ_TEST_REGISTER (0xFD)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 77 #define SIE_CMD_SET_DEVICE_STATUS (0xFE)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 78 #define SIE_CMD_GET_DEVICE_STATUS (0xFE)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 79 #define SIE_CMD_GET_ERROR_CODE (0xFF)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 80 #define SIE_CMD_READ_ERROR_STATUS (0xFB)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 81
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 82 #define SIE_CMD_SELECT_ENDPOINT(endpoint) (0x00+endpoint)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 83 #define SIE_CMD_SELECT_ENDPOINT_CLEAR_INTERRUPT(endpoint) (0x40+endpoint)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 84 #define SIE_CMD_SET_ENDPOINT_STATUS(endpoint) (0x40+endpoint)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 85
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 86 #define SIE_CMD_CLEAR_BUFFER (0xF2)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 87 #define SIE_CMD_VALIDATE_BUFFER (0xFA)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 88
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 89 // SIE Device Status register
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 90 #define SIE_DS_CON (1<<0)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 91 #define SIE_DS_CON_CH (1<<1)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 92 #define SIE_DS_SUS (1<<2)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 93 #define SIE_DS_SUS_CH (1<<3)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 94 #define SIE_DS_RST (1<<4)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 95
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 96 // SIE Device Set Address register
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 97 #define SIE_DSA_DEV_EN (1<<7)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 98
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 99 // SIE Configue Device register
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 100 #define SIE_CONF_DEVICE (1<<0)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 101
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 102 // Select Endpoint register
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 103 #define SIE_SE_FE (1<<0)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 104 #define SIE_SE_ST (1<<1)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 105 #define SIE_SE_STP (1<<2)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 106 #define SIE_SE_PO (1<<3)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 107 #define SIE_SE_EPN (1<<4)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 108 #define SIE_SE_B_1_FULL (1<<5)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 109 #define SIE_SE_B_2_FULL (1<<6)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 110
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 111 // Set Endpoint Status command
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 112 #define SIE_SES_ST (1<<0)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 113 #define SIE_SES_DA (1<<5)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 114 #define SIE_SES_RF_MO (1<<6)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 115 #define SIE_SES_CND_ST (1<<7)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 116
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 117
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 118 USBHAL * USBHAL::instance;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 119
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 120 static volatile int epComplete;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 121 static uint32_t endpointStallState;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 122
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 123 static void SIECommand(uint32_t command) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 124 // The command phase of a SIE transaction
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 125 LPC_USB->DevIntClr = CCEMPTY;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 126 LPC_USB->CmdCode = SIE_CMD_CODE(SIE_COMMAND, command);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 127 while (!(LPC_USB->DevIntSt & CCEMPTY));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 128 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 129
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 130 static void SIEWriteData(uint8_t data) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 131 // The data write phase of a SIE transaction
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 132 LPC_USB->DevIntClr = CCEMPTY;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 133 LPC_USB->CmdCode = SIE_CMD_CODE(SIE_WRITE, data);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 134 while (!(LPC_USB->DevIntSt & CCEMPTY));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 135 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 136
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 137 static uint8_t SIEReadData(uint32_t command) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 138 // The data read phase of a SIE transaction
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 139 LPC_USB->DevIntClr = CDFULL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 140 LPC_USB->CmdCode = SIE_CMD_CODE(SIE_READ, command);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 141 while (!(LPC_USB->DevIntSt & CDFULL));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 142 return (uint8_t)LPC_USB->CmdData;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 143 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 144
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 145 static void SIEsetDeviceStatus(uint8_t status) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 146 // Write SIE device status register
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 147 SIECommand(SIE_CMD_SET_DEVICE_STATUS);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 148 SIEWriteData(status);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 149 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 150
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 151 static uint8_t SIEgetDeviceStatus(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 152 // Read SIE device status register
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 153 SIECommand(SIE_CMD_GET_DEVICE_STATUS);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 154 return SIEReadData(SIE_CMD_GET_DEVICE_STATUS);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 155 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 156
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 157 void SIEsetAddress(uint8_t address) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 158 // Write SIE device address register
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 159 SIECommand(SIE_CMD_SET_ADDRESS);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 160 SIEWriteData((address & 0x7f) | SIE_DSA_DEV_EN);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 161 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 162
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 163 static uint8_t SIEselectEndpoint(uint8_t endpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 164 // SIE select endpoint command
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 165 SIECommand(SIE_CMD_SELECT_ENDPOINT(endpoint));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 166 return SIEReadData(SIE_CMD_SELECT_ENDPOINT(endpoint));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 167 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 168
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 169 static uint8_t SIEclearBuffer(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 170 // SIE clear buffer command
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 171 SIECommand(SIE_CMD_CLEAR_BUFFER);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 172 return SIEReadData(SIE_CMD_CLEAR_BUFFER);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 173 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 174
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 175 static void SIEvalidateBuffer(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 176 // SIE validate buffer command
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 177 SIECommand(SIE_CMD_VALIDATE_BUFFER);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 178 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 179
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 180 static void SIEsetEndpointStatus(uint8_t endpoint, uint8_t status) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 181 // SIE set endpoint status command
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 182 SIECommand(SIE_CMD_SET_ENDPOINT_STATUS(endpoint));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 183 SIEWriteData(status);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 184 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 185
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 186 static uint16_t SIEgetFrameNumber(void) __attribute__ ((unused));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 187 static uint16_t SIEgetFrameNumber(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 188 // Read current frame number
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 189 uint16_t lowByte;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 190 uint16_t highByte;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 191
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 192 SIECommand(SIE_CMD_READ_FRAME_NUMBER);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 193 lowByte = SIEReadData(SIE_CMD_READ_FRAME_NUMBER);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 194 highByte = SIEReadData(SIE_CMD_READ_FRAME_NUMBER);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 195
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 196 return (highByte << 8) | lowByte;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 197 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 198
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 199 static void SIEconfigureDevice(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 200 // SIE Configure device command
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 201 SIECommand(SIE_CMD_CONFIGURE_DEVICE);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 202 SIEWriteData(SIE_CONF_DEVICE);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 203 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 204
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 205 static void SIEunconfigureDevice(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 206 // SIE Configure device command
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 207 SIECommand(SIE_CMD_CONFIGURE_DEVICE);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 208 SIEWriteData(0);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 209 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 210
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 211 static void SIEconnect(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 212 // Connect USB device
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 213 uint8_t status = SIEgetDeviceStatus();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 214 SIEsetDeviceStatus(status | SIE_DS_CON);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 215 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 216
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 217
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 218 static void SIEdisconnect(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 219 // Disconnect USB device
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 220 uint8_t status = SIEgetDeviceStatus();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 221 SIEsetDeviceStatus(status & ~SIE_DS_CON);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 222 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 223
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 224
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 225 static uint8_t selectEndpointClearInterrupt(uint8_t endpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 226 // Implemented using using EP_INT_CLR.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 227 LPC_USB->EpIntClr = EP(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 228 while (!(LPC_USB->DevIntSt & CDFULL));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 229 return (uint8_t)LPC_USB->CmdData;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 230 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 231
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 232
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 233 static void enableEndpointEvent(uint8_t endpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 234 // Enable an endpoint interrupt
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 235 LPC_USB->EpIntEn |= EP(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 236 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 237
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 238 static void disableEndpointEvent(uint8_t endpoint) __attribute__ ((unused));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 239 static void disableEndpointEvent(uint8_t endpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 240 // Disable an endpoint interrupt
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 241 LPC_USB->EpIntEn &= ~EP(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 242 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 243
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 244 static volatile uint32_t __attribute__((used)) dummyRead;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 245 uint32_t USBHAL::endpointReadcore(uint8_t endpoint, uint8_t *buffer) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 246 // Read from an OUT endpoint
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 247 uint32_t size;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 248 uint32_t i;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 249 uint32_t data = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 250 uint8_t offset;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 251
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 252 LPC_USB->Ctrl = LOG_ENDPOINT(endpoint) | RD_EN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 253 while (!(LPC_USB->RxPLen & PKT_RDY));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 254
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 255 size = LPC_USB->RxPLen & PKT_LNGTH_MASK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 256
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 257 offset = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 258
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 259 if (size > 0) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 260 for (i=0; i<size; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 261 if (offset==0) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 262 // Fetch up to four bytes of data as a word
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 263 data = LPC_USB->RxData;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 264 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 265
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 266 // extract a byte
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 267 *buffer = (data>>offset) & 0xff;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 268 buffer++;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 269
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 270 // move on to the next byte
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 271 offset = (offset + 8) % 32;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 272 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 273 } else {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 274 dummyRead = LPC_USB->RxData;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 275 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 276
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 277 LPC_USB->Ctrl = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 278
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 279 if ((endpoint >> 1) % 3 || (endpoint >> 1) == 0) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 280 SIEselectEndpoint(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 281 SIEclearBuffer();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 282 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 283
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 284 return size;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 285 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 286
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 287 static void endpointWritecore(uint8_t endpoint, uint8_t *buffer, uint32_t size) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 288 // Write to an IN endpoint
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 289 uint32_t temp, data;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 290 uint8_t offset;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 291
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 292 LPC_USB->Ctrl = LOG_ENDPOINT(endpoint) | WR_EN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 293
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 294 LPC_USB->TxPLen = size;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 295 offset = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 296 data = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 297
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 298 if (size>0) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 299 do {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 300 // Fetch next data byte into a word-sized temporary variable
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 301 temp = *buffer++;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 302
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 303 // Add to current data word
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 304 temp = temp << offset;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 305 data = data | temp;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 306
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 307 // move on to the next byte
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 308 offset = (offset + 8) % 32;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 309 size--;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 310
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 311 if ((offset==0) || (size==0)) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 312 // Write the word to the endpoint
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 313 LPC_USB->TxData = data;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 314 data = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 315 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 316 } while (size>0);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 317 } else {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 318 LPC_USB->TxData = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 319 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 320
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 321 // Clear WR_EN to cover zero length packet case
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 322 LPC_USB->Ctrl=0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 323
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 324 SIEselectEndpoint(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 325 SIEvalidateBuffer();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 326 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 327
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 328 USBHAL::USBHAL(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 329 // Disable IRQ
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 330 NVIC_DisableIRQ(USB_IRQn);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 331
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 332 // fill in callback array
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 333 epCallback[0] = &USBHAL::EP1_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 334 epCallback[1] = &USBHAL::EP1_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 335 epCallback[2] = &USBHAL::EP2_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 336 epCallback[3] = &USBHAL::EP2_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 337 epCallback[4] = &USBHAL::EP3_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 338 epCallback[5] = &USBHAL::EP3_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 339 epCallback[6] = &USBHAL::EP4_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 340 epCallback[7] = &USBHAL::EP4_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 341 epCallback[8] = &USBHAL::EP5_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 342 epCallback[9] = &USBHAL::EP5_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 343 epCallback[10] = &USBHAL::EP6_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 344 epCallback[11] = &USBHAL::EP6_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 345 epCallback[12] = &USBHAL::EP7_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 346 epCallback[13] = &USBHAL::EP7_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 347 epCallback[14] = &USBHAL::EP8_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 348 epCallback[15] = &USBHAL::EP8_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 349 epCallback[16] = &USBHAL::EP9_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 350 epCallback[17] = &USBHAL::EP9_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 351 epCallback[18] = &USBHAL::EP10_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 352 epCallback[19] = &USBHAL::EP10_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 353 epCallback[20] = &USBHAL::EP11_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 354 epCallback[21] = &USBHAL::EP11_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 355 epCallback[22] = &USBHAL::EP12_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 356 epCallback[23] = &USBHAL::EP12_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 357 epCallback[24] = &USBHAL::EP13_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 358 epCallback[25] = &USBHAL::EP13_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 359 epCallback[26] = &USBHAL::EP14_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 360 epCallback[27] = &USBHAL::EP14_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 361 epCallback[28] = &USBHAL::EP15_OUT_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 362 epCallback[29] = &USBHAL::EP15_IN_callback;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 363
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 364 // Enable power to USB device controller
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 365 LPC_SC->PCONP |= PCUSB;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 366
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 367 // Enable USB clocks
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 368 LPC_USB->USBClkCtrl |= DEV_CLK_EN | AHB_CLK_EN | PORT_CLK_EN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 369 while ((LPC_USB->USBClkSt & (DEV_CLK_EN | AHB_CLK_EN | PORT_CLK_EN)) != (DEV_CLK_ON | AHB_CLK_ON | PORT_CLK_EN));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 370
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 371 // Select port USB2
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 372 LPC_USB->StCtrl |= 3;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 373
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 374
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 375 // Configure pin P0.31 to be USB2
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 376 LPC_IOCON->P0_31 &= ~0x07;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 377 LPC_IOCON->P0_31 |= 0x01;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 378
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 379 // Disconnect USB device
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 380 SIEdisconnect();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 381
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 382 // Configure pin P0.14 to be Connect
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 383 LPC_IOCON->P0_14 &= ~0x07;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 384 LPC_IOCON->P0_14 |= 0x03;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 385
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 386 // Connect must be low for at least 2.5uS
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 387 wait(0.3);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 388
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 389 // Set the maximum packet size for the control endpoints
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 390 realiseEndpoint(EP0IN, MAX_PACKET_SIZE_EP0, 0);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 391 realiseEndpoint(EP0OUT, MAX_PACKET_SIZE_EP0, 0);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 392
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 393 // Attach IRQ
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 394 instance = this;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 395 NVIC_SetVector(USB_IRQn, (uint32_t)&_usbisr);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 396
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 397 // Enable interrupts for device events and EP0
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 398 LPC_USB->DevIntEn = EP_SLOW | DEV_STAT | FRAME;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 399 enableEndpointEvent(EP0IN);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 400 enableEndpointEvent(EP0OUT);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 401 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 402
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 403 USBHAL::~USBHAL(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 404 // Ensure device disconnected
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 405 SIEdisconnect();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 406 // Disable USB interrupts
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 407 NVIC_DisableIRQ(USB_IRQn);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 408 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 409
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 410 void USBHAL::connect(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 411 NVIC_EnableIRQ(USB_IRQn);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 412 // Connect USB device
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 413 SIEconnect();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 414 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 415
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 416 void USBHAL::disconnect(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 417 NVIC_DisableIRQ(USB_IRQn);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 418 // Disconnect USB device
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 419 SIEdisconnect();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 420 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 421
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 422 void USBHAL::configureDevice(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 423 SIEconfigureDevice();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 424 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 425
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 426 void USBHAL::unconfigureDevice(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 427 SIEunconfigureDevice();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 428 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 429
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 430 void USBHAL::setAddress(uint8_t address) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 431 SIEsetAddress(address);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 432 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 433
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 434 void USBHAL::EP0setup(uint8_t *buffer) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 435 endpointReadcore(EP0OUT, buffer);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 436 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 437
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 438 void USBHAL::EP0read(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 439 // Not required
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 440 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 441
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 442 void USBHAL::EP0readStage(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 443 // Not required
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 444 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 445
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 446 uint32_t USBHAL::EP0getReadResult(uint8_t *buffer) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 447 return endpointReadcore(EP0OUT, buffer);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 448 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 449
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 450 void USBHAL::EP0write(uint8_t *buffer, uint32_t size) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 451 endpointWritecore(EP0IN, buffer, size);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 452 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 453
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 454 void USBHAL::EP0getWriteResult(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 455 // Not required
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 456 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 457
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 458 void USBHAL::EP0stall(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 459 // This will stall both control endpoints
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 460 stallEndpoint(EP0OUT);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 461 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 462
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 463 EP_STATUS USBHAL::endpointRead(uint8_t endpoint, uint32_t maximumSize) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 464 return EP_PENDING;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 465 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 466
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 467 EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t * buffer, uint32_t *bytesRead) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 468
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 469 //for isochronous endpoint, we don't wait an interrupt
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 470 if ((endpoint >> 1) % 3 || (endpoint >> 1) == 0) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 471 if (!(epComplete & EP(endpoint)))
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 472 return EP_PENDING;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 473 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 474
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 475 *bytesRead = endpointReadcore(endpoint, buffer);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 476 epComplete &= ~EP(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 477 return EP_COMPLETED;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 478 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 479
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 480 EP_STATUS USBHAL::endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 481 if (getEndpointStallState(endpoint)) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 482 return EP_STALLED;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 483 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 484
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 485 epComplete &= ~EP(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 486
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 487 endpointWritecore(endpoint, data, size);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 488 return EP_PENDING;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 489 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 490
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 491 EP_STATUS USBHAL::endpointWriteResult(uint8_t endpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 492 if (epComplete & EP(endpoint)) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 493 epComplete &= ~EP(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 494 return EP_COMPLETED;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 495 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 496
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 497 return EP_PENDING;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 498 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 499
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 500 bool USBHAL::realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t flags) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 501 // Realise an endpoint
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 502 LPC_USB->DevIntClr = EP_RLZED;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 503 LPC_USB->ReEp |= EP(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 504 LPC_USB->EpInd = endpoint;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 505 LPC_USB->MaxPSize = maxPacket;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 506
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 507 while (!(LPC_USB->DevIntSt & EP_RLZED));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 508 LPC_USB->DevIntClr = EP_RLZED;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 509
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 510 // Clear stall state
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 511 endpointStallState &= ~EP(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 512
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 513 enableEndpointEvent(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 514 return true;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 515 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 516
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 517 void USBHAL::stallEndpoint(uint8_t endpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 518 // Stall an endpoint
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 519 if ( (endpoint==EP0IN) || (endpoint==EP0OUT) ) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 520 // Conditionally stall both control endpoints
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 521 SIEsetEndpointStatus(EP0OUT, SIE_SES_CND_ST);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 522 } else {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 523 SIEsetEndpointStatus(endpoint, SIE_SES_ST);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 524
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 525 // Update stall state
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 526 endpointStallState |= EP(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 527 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 528 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 529
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 530 void USBHAL::unstallEndpoint(uint8_t endpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 531 // Unstall an endpoint. The endpoint will also be reinitialised
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 532 SIEsetEndpointStatus(endpoint, 0);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 533
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 534 // Update stall state
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 535 endpointStallState &= ~EP(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 536 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 537
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 538 bool USBHAL::getEndpointStallState(uint8_t endpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 539 // Returns true if endpoint stalled
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 540 return endpointStallState & EP(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 541 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 542
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 543 void USBHAL::remoteWakeup(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 544 // Remote wakeup
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 545 uint8_t status;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 546
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 547 // Enable USB clocks
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 548 LPC_USB->USBClkCtrl |= DEV_CLK_EN | AHB_CLK_EN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 549 while (LPC_USB->USBClkSt != (DEV_CLK_ON | AHB_CLK_ON));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 550
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 551 status = SIEgetDeviceStatus();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 552 SIEsetDeviceStatus(status & ~SIE_DS_SUS);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 553 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 554
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 555 void USBHAL::_usbisr(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 556 instance->usbisr();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 557 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 558
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 559
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 560 void USBHAL::usbisr(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 561 uint8_t devStat;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 562
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 563 if (LPC_USB->DevIntSt & FRAME) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 564 // Start of frame event
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 565 SOF(SIEgetFrameNumber());
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 566 // Clear interrupt status flag
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 567 LPC_USB->DevIntClr = FRAME;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 568 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 569
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 570 if (LPC_USB->DevIntSt & DEV_STAT) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 571 // Device Status interrupt
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 572 // Must clear the interrupt status flag before reading the device status from the SIE
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 573 LPC_USB->DevIntClr = DEV_STAT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 574
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 575 // Read device status from SIE
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 576 devStat = SIEgetDeviceStatus();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 577 //printf("devStat: %d\r\n", devStat);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 578
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 579 if (devStat & SIE_DS_SUS_CH) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 580 // Suspend status changed
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 581 if((devStat & SIE_DS_SUS) != 0) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 582 suspendStateChanged(0);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 583 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 584 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 585
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 586 if (devStat & SIE_DS_RST) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 587 // Bus reset
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 588 if((devStat & SIE_DS_SUS) == 0) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 589 suspendStateChanged(1);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 590 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 591 busReset();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 592 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 593 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 594
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 595 if (LPC_USB->DevIntSt & EP_SLOW) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 596 // (Slow) Endpoint Interrupt
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 597
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 598 // Process each endpoint interrupt
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 599 if (LPC_USB->EpIntSt & EP(EP0OUT)) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 600 if (selectEndpointClearInterrupt(EP0OUT) & SIE_SE_STP) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 601 // this is a setup packet
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 602 EP0setupCallback();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 603 } else {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 604 EP0out();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 605 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 606 LPC_USB->DevIntClr = EP_SLOW;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 607 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 608
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 609 if (LPC_USB->EpIntSt & EP(EP0IN)) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 610 selectEndpointClearInterrupt(EP0IN);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 611 LPC_USB->DevIntClr = EP_SLOW;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 612 EP0in();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 613 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 614
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 615 for (uint8_t num = 2; num < 16*2; num++) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 616 if (LPC_USB->EpIntSt & EP(num)) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 617 selectEndpointClearInterrupt(num);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 618 epComplete |= EP(num);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 619 LPC_USB->DevIntClr = EP_SLOW;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 620 if ((instance->*(epCallback[num - 2]))()) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 621 epComplete &= ~EP(num);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 622 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 623 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 624 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 625 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 626 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 627
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 628 #endif