Transistor Gijutsu, October 2014, Special Features Chapter 9, Software of the Function Generator トランジスタ技術2014年10月号 特集第9章のソフトウェア わがまま波形発生器のソフトウェア

Dependencies:   USBDevice mbed

Information

tg_201410s8_AD7714 トランジスタ技術 2014年 10月号 第9章のソフトウェア

Program for Section 9 in October. 2014 issue of the Transistor Gijutsu
(Japanese electronics magazine)

概要

このプログラムは、ソフトウエアDDSにより、任意の波形を出力(2ch)します。 特徴は次のとおりです。

  • PWM出力をDAコンバータとして利用します。
  • 周波数や波形、バースト条件などを個別に設定できる独立した出力を2チャネル持っています。
  • 周波数分解能0.023mHz
  • 周波数範囲0.023mHz~10kHz
  • 各チャネルにそれぞれ、波形の先頭で出力されるトリガ出力があります。
  • 出力波形を関数で定義できます。
  • 休止波数、出力波数、を設定することでバースト波形が出力できます。

ファイル

このソフトウエアは、次のファイルから構成されています。

  • DDS.cpp - DDSによる波形発生
  • main.cpp - main()関数

詳細については、10月号の記事および上記ファイル中のコメントを参照してください。

Committer:
Dance
Date:
Fri Aug 29 08:33:17 2014 +0000
Revision:
0:f1ecca559ec3
Transistor Gijutsu, October 2014, Special Features Chapter 9; ????????2014?10??????9????????

Who changed what in which revision?

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