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