Adds class implementation for use STM32F4xx OTG_HS in FS mode
Fork of USBDevice by
targets/TARGET_STM/USBHAL_STM32.cpp@76:a791d5373beb, 2018-07-30 (annotated)
- Committer:
- ua1arn
- Date:
- Mon Jul 30 12:30:04 2018 +0000
- Revision:
- 76:a791d5373beb
- Parent:
- 71:53949e6131f6
current state before add multi-configuration USB descriptors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 71:53949e6131f6 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
Kojto | 71:53949e6131f6 | 2 | * |
Kojto | 71:53949e6131f6 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
Kojto | 71:53949e6131f6 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
Kojto | 71:53949e6131f6 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
Kojto | 71:53949e6131f6 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
Kojto | 71:53949e6131f6 | 7 | * Software is furnished to do so, subject to the following conditions: |
Kojto | 71:53949e6131f6 | 8 | * |
Kojto | 71:53949e6131f6 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
Kojto | 71:53949e6131f6 | 10 | * substantial portions of the Software. |
Kojto | 71:53949e6131f6 | 11 | * |
Kojto | 71:53949e6131f6 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
Kojto | 71:53949e6131f6 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
Kojto | 71:53949e6131f6 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
Kojto | 71:53949e6131f6 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Kojto | 71:53949e6131f6 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Kojto | 71:53949e6131f6 | 17 | */ |
Kojto | 71:53949e6131f6 | 18 | /* TARGET NOT STM does not support this HAL */ |
Kojto | 71:53949e6131f6 | 19 | #ifndef TARGET_STM |
Kojto | 71:53949e6131f6 | 20 | #define USBSTM_HAL_UNSUPPORTED |
Kojto | 71:53949e6131f6 | 21 | #endif |
Kojto | 71:53949e6131f6 | 22 | /* F4 famlily wihtout USB_STM_HAL use another HAL*/ |
Kojto | 71:53949e6131f6 | 23 | #if defined(TARGET_STM) && defined(TARGET_STM32F4) && !defined(USB_STM_HAL) |
Kojto | 71:53949e6131f6 | 24 | #define USBSTM_HAL_UNSUPPORTED |
Kojto | 71:53949e6131f6 | 25 | #endif |
Kojto | 71:53949e6131f6 | 26 | |
Kojto | 71:53949e6131f6 | 27 | #ifndef USBSTM_HAL_UNSUPPORTED |
Kojto | 71:53949e6131f6 | 28 | #include "USBHAL.h" |
Kojto | 71:53949e6131f6 | 29 | #include "pinmap.h" |
Kojto | 71:53949e6131f6 | 30 | /* mbed endpoint definition to hal definition */ |
Kojto | 71:53949e6131f6 | 31 | #define EP_ADDR(ep) (((ep) >> 1)|((ep) & 1) << 7) |
Kojto | 71:53949e6131f6 | 32 | /* from hal definition to mbed definition */ |
Kojto | 71:53949e6131f6 | 33 | #define ADDR_EPIN(ep) (((ep) << 1) | 1) |
Kojto | 71:53949e6131f6 | 34 | #define ADDR_EPOUT(ep) (((ep) << 1)) |
Kojto | 71:53949e6131f6 | 35 | /* id to detect if rx buffer is used or not */ |
Kojto | 71:53949e6131f6 | 36 | |
ua1arn | 76:a791d5373beb | 37 | //#include "USBHAL_STM_TARGET.h" |
ua1arn | 76:a791d5373beb | 38 | #include "USBHAL_STM_HSFS_144_pins.h" |
Kojto | 71:53949e6131f6 | 39 | |
Kojto | 71:53949e6131f6 | 40 | |
Kojto | 71:53949e6131f6 | 41 | /* this call at device reception completion on a Out Enpoint */ |
Kojto | 71:53949e6131f6 | 42 | void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
Kojto | 71:53949e6131f6 | 43 | { |
Kojto | 71:53949e6131f6 | 44 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 45 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 46 | uint8_t endpoint = ADDR_EPOUT(epnum); |
Kojto | 71:53949e6131f6 | 47 | priv->epComplete[endpoint] = 1; |
Kojto | 71:53949e6131f6 | 48 | /* -2 endpoint 0 In out are not in call back list */ |
Kojto | 71:53949e6131f6 | 49 | if (epnum) { |
Kojto | 71:53949e6131f6 | 50 | bool (USBHAL::*func)(void) = priv->epCallback[endpoint-2]; |
Kojto | 71:53949e6131f6 | 51 | (obj->*func)(); |
Kojto | 71:53949e6131f6 | 52 | } else { |
Kojto | 71:53949e6131f6 | 53 | void (USBHAL::*func)(void) = priv->ep0_out; |
Kojto | 71:53949e6131f6 | 54 | (obj->*func)(); |
Kojto | 71:53949e6131f6 | 55 | } |
Kojto | 71:53949e6131f6 | 56 | } |
Kojto | 71:53949e6131f6 | 57 | |
Kojto | 71:53949e6131f6 | 58 | /* this is call at device transmission completion on In endpoint */ |
Kojto | 71:53949e6131f6 | 59 | void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
Kojto | 71:53949e6131f6 | 60 | { |
Kojto | 71:53949e6131f6 | 61 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 62 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 63 | uint8_t endpoint = ADDR_EPIN(epnum); |
Kojto | 71:53949e6131f6 | 64 | priv->epComplete[endpoint] = 1; |
Kojto | 71:53949e6131f6 | 65 | /* -2 endpoint 0 In out are not in call back list */ |
Kojto | 71:53949e6131f6 | 66 | if (epnum) { |
Kojto | 71:53949e6131f6 | 67 | bool (USBHAL::*func)(void) = priv->epCallback[endpoint-2]; |
Kojto | 71:53949e6131f6 | 68 | (obj->*func)(); |
Kojto | 71:53949e6131f6 | 69 | } else { |
Kojto | 71:53949e6131f6 | 70 | void (USBHAL::*func)(void) = priv->ep0_in; |
Kojto | 71:53949e6131f6 | 71 | (obj->*func)(); |
Kojto | 71:53949e6131f6 | 72 | } |
Kojto | 71:53949e6131f6 | 73 | } |
Kojto | 71:53949e6131f6 | 74 | /* This is call at device set up reception */ |
Kojto | 71:53949e6131f6 | 75 | void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) |
Kojto | 71:53949e6131f6 | 76 | { |
Kojto | 71:53949e6131f6 | 77 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 78 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 79 | void (USBHAL::*func)(void)=priv->ep0_setup; |
Kojto | 71:53949e6131f6 | 80 | void (USBHAL::*func1)(void)=priv->ep0_read; |
Kojto | 71:53949e6131f6 | 81 | (obj->*func)(); |
Kojto | 71:53949e6131f6 | 82 | (obj->*func1)(); |
Kojto | 71:53949e6131f6 | 83 | } |
Kojto | 71:53949e6131f6 | 84 | |
Kojto | 71:53949e6131f6 | 85 | void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) |
Kojto | 71:53949e6131f6 | 86 | { |
Kojto | 71:53949e6131f6 | 87 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 88 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 89 | void (USBHAL::*func)(unsigned int suspended) = priv->suspend_change; |
Kojto | 71:53949e6131f6 | 90 | (obj->*func)(1); |
Kojto | 71:53949e6131f6 | 91 | } |
Kojto | 71:53949e6131f6 | 92 | |
Kojto | 71:53949e6131f6 | 93 | void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) |
Kojto | 71:53949e6131f6 | 94 | { |
Kojto | 71:53949e6131f6 | 95 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 96 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 97 | void (USBHAL::*func)(unsigned int suspended) = priv->suspend_change; |
Kojto | 71:53949e6131f6 | 98 | (obj->*func)(0); |
Kojto | 71:53949e6131f6 | 99 | } |
Kojto | 71:53949e6131f6 | 100 | |
Kojto | 71:53949e6131f6 | 101 | void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) |
Kojto | 71:53949e6131f6 | 102 | { |
Kojto | 71:53949e6131f6 | 103 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 104 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 105 | void (USBHAL::*func)(unsigned int suspended) = priv->connect_change; |
Kojto | 71:53949e6131f6 | 106 | (obj->*func)(1); |
Kojto | 71:53949e6131f6 | 107 | } |
Kojto | 71:53949e6131f6 | 108 | |
Kojto | 71:53949e6131f6 | 109 | void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) |
Kojto | 71:53949e6131f6 | 110 | { |
Kojto | 71:53949e6131f6 | 111 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 112 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 113 | void (USBHAL::*func)(unsigned int suspended) = priv->connect_change; |
Kojto | 71:53949e6131f6 | 114 | (obj->*func)(0); |
Kojto | 71:53949e6131f6 | 115 | } |
Kojto | 71:53949e6131f6 | 116 | |
Kojto | 71:53949e6131f6 | 117 | void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) |
Kojto | 71:53949e6131f6 | 118 | { |
Kojto | 71:53949e6131f6 | 119 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 120 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 121 | unsigned int i; |
Kojto | 71:53949e6131f6 | 122 | for(i=0;i<hpcd->Init.dev_endpoints;i++) { |
Kojto | 71:53949e6131f6 | 123 | priv->epComplete[2*i]=0; |
Kojto | 71:53949e6131f6 | 124 | HAL_PCD_EP_Close(hpcd,EP_ADDR(2*i)); |
Kojto | 71:53949e6131f6 | 125 | HAL_PCD_EP_Flush(hpcd,EP_ADDR(2*i)); |
Kojto | 71:53949e6131f6 | 126 | priv->epComplete[2*i+1]=0; |
Kojto | 71:53949e6131f6 | 127 | HAL_PCD_EP_Close(hpcd,EP_ADDR(2*i+1)); |
Kojto | 71:53949e6131f6 | 128 | HAL_PCD_EP_Flush(hpcd,EP_ADDR(2*i+1)); |
Kojto | 71:53949e6131f6 | 129 | |
Kojto | 71:53949e6131f6 | 130 | } |
Kojto | 71:53949e6131f6 | 131 | void (USBHAL::*func)(void)=priv->bus_reset; |
Kojto | 71:53949e6131f6 | 132 | bool (USBHAL::*ep_realise)(uint8_t endpoint, uint32_t maxPacket, uint32_t flags) = priv->ep_realise; |
Kojto | 71:53949e6131f6 | 133 | (obj->*func)(); |
Kojto | 71:53949e6131f6 | 134 | (obj->*ep_realise)(EP0IN, MAX_PACKET_SIZE_EP0,0); |
Kojto | 71:53949e6131f6 | 135 | (obj->*ep_realise)(EP0OUT, MAX_PACKET_SIZE_EP0,0); |
Kojto | 71:53949e6131f6 | 136 | } |
Kojto | 71:53949e6131f6 | 137 | |
Kojto | 71:53949e6131f6 | 138 | |
Kojto | 71:53949e6131f6 | 139 | /* hal pcd handler , used for STM32 HAL PCD Layer */ |
Kojto | 71:53949e6131f6 | 140 | |
Kojto | 71:53949e6131f6 | 141 | uint32_t USBHAL::endpointReadcore(uint8_t endpoint, uint8_t *buffer) { |
Kojto | 71:53949e6131f6 | 142 | return 0; |
Kojto | 71:53949e6131f6 | 143 | } |
Kojto | 71:53949e6131f6 | 144 | |
Kojto | 71:53949e6131f6 | 145 | USBHAL::~USBHAL(void) { |
Kojto | 71:53949e6131f6 | 146 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData); |
Kojto | 71:53949e6131f6 | 147 | HAL_PCD_DeInit(&hpcd); |
Kojto | 71:53949e6131f6 | 148 | delete HALPriv; |
Kojto | 71:53949e6131f6 | 149 | } |
Kojto | 71:53949e6131f6 | 150 | |
Kojto | 71:53949e6131f6 | 151 | void USBHAL::connect(void) { |
Kojto | 71:53949e6131f6 | 152 | NVIC_EnableIRQ(USBHAL_IRQn); |
Kojto | 71:53949e6131f6 | 153 | } |
Kojto | 71:53949e6131f6 | 154 | |
Kojto | 71:53949e6131f6 | 155 | void USBHAL::disconnect(void) { |
Kojto | 71:53949e6131f6 | 156 | NVIC_DisableIRQ(USBHAL_IRQn); |
Kojto | 71:53949e6131f6 | 157 | } |
Kojto | 71:53949e6131f6 | 158 | |
Kojto | 71:53949e6131f6 | 159 | void USBHAL::configureDevice(void) { |
Kojto | 71:53949e6131f6 | 160 | // Not needed |
Kojto | 71:53949e6131f6 | 161 | } |
Kojto | 71:53949e6131f6 | 162 | |
Kojto | 71:53949e6131f6 | 163 | void USBHAL::unconfigureDevice(void) { |
Kojto | 71:53949e6131f6 | 164 | // Not needed |
Kojto | 71:53949e6131f6 | 165 | } |
Kojto | 71:53949e6131f6 | 166 | |
Kojto | 71:53949e6131f6 | 167 | void USBHAL::setAddress(uint8_t address) { |
Kojto | 71:53949e6131f6 | 168 | HAL_PCD_SetAddress(&hpcd, address); |
Kojto | 71:53949e6131f6 | 169 | EP0write(0, 0); |
Kojto | 71:53949e6131f6 | 170 | } |
Kojto | 71:53949e6131f6 | 171 | |
Kojto | 71:53949e6131f6 | 172 | bool USBHAL::realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t flags) { |
Kojto | 71:53949e6131f6 | 173 | uint32_t epIndex = EP_ADDR(endpoint); |
Kojto | 71:53949e6131f6 | 174 | uint32_t type; |
Kojto | 71:53949e6131f6 | 175 | uint32_t len; |
Kojto | 71:53949e6131f6 | 176 | HAL_StatusTypeDef ret; |
Kojto | 71:53949e6131f6 | 177 | switch (endpoint) { |
Kojto | 71:53949e6131f6 | 178 | case EP0IN: |
Kojto | 71:53949e6131f6 | 179 | case EP0OUT: |
Kojto | 71:53949e6131f6 | 180 | type = 0; |
Kojto | 71:53949e6131f6 | 181 | break; |
Kojto | 71:53949e6131f6 | 182 | case EPISO_IN: |
Kojto | 71:53949e6131f6 | 183 | case EPISO_OUT: |
Kojto | 71:53949e6131f6 | 184 | type = 1; |
Kojto | 71:53949e6131f6 | 185 | break; |
Kojto | 71:53949e6131f6 | 186 | case EPBULK_IN: |
Kojto | 71:53949e6131f6 | 187 | case EPBULK_OUT: |
Kojto | 71:53949e6131f6 | 188 | type = 2; |
Kojto | 71:53949e6131f6 | 189 | break; |
Kojto | 71:53949e6131f6 | 190 | case EPINT_IN: |
Kojto | 71:53949e6131f6 | 191 | case EPINT_OUT: |
Kojto | 71:53949e6131f6 | 192 | type = 3; |
Kojto | 71:53949e6131f6 | 193 | break; |
Kojto | 71:53949e6131f6 | 194 | } |
Kojto | 71:53949e6131f6 | 195 | if (maxPacket > MAXTRANSFER_SIZE) return false; |
Kojto | 71:53949e6131f6 | 196 | if (epIndex & 0x80) { |
Kojto | 71:53949e6131f6 | 197 | len = HAL_PCDEx_GetTxFiFo(&hpcd,epIndex & 0x7f); |
Kojto | 71:53949e6131f6 | 198 | MBED_ASSERT(len >= maxPacket); |
Kojto | 71:53949e6131f6 | 199 | } |
Kojto | 71:53949e6131f6 | 200 | ret = HAL_PCD_EP_Open(&hpcd, epIndex, maxPacket, type); |
Kojto | 71:53949e6131f6 | 201 | MBED_ASSERT(ret!=HAL_BUSY); |
Kojto | 71:53949e6131f6 | 202 | return (ret == HAL_OK) ? true:false; |
Kojto | 71:53949e6131f6 | 203 | } |
Kojto | 71:53949e6131f6 | 204 | |
Kojto | 71:53949e6131f6 | 205 | // read setup packet |
Kojto | 71:53949e6131f6 | 206 | void USBHAL::EP0setup(uint8_t *buffer) { |
Kojto | 71:53949e6131f6 | 207 | memcpy(buffer, hpcd.Setup, MAX_PACKET_SIZE_SETUP); |
Kojto | 71:53949e6131f6 | 208 | memset(hpcd.Setup,0,MAX_PACKET_SIZE_SETUP); |
Kojto | 71:53949e6131f6 | 209 | } |
Kojto | 71:53949e6131f6 | 210 | |
Kojto | 71:53949e6131f6 | 211 | void USBHAL::EP0readStage(void) { |
Kojto | 71:53949e6131f6 | 212 | } |
Kojto | 71:53949e6131f6 | 213 | |
Kojto | 71:53949e6131f6 | 214 | void USBHAL::EP0read(void) { |
Kojto | 71:53949e6131f6 | 215 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)hpcd.pData; |
Kojto | 71:53949e6131f6 | 216 | uint32_t epIndex = EP_ADDR(EP0OUT); |
Kojto | 71:53949e6131f6 | 217 | uint8_t *pBuf = (uint8_t *)HALPriv->pBufRx0; |
Kojto | 71:53949e6131f6 | 218 | HAL_StatusTypeDef ret; |
Kojto | 71:53949e6131f6 | 219 | HALPriv->epComplete[EP0OUT] = 2; |
Kojto | 71:53949e6131f6 | 220 | ret = HAL_PCD_EP_Receive(&hpcd, epIndex, pBuf, MAX_PACKET_SIZE_EP0 ); |
Kojto | 71:53949e6131f6 | 221 | MBED_ASSERT(ret!=HAL_BUSY); |
Kojto | 71:53949e6131f6 | 222 | |
Kojto | 71:53949e6131f6 | 223 | } |
Kojto | 71:53949e6131f6 | 224 | |
Kojto | 71:53949e6131f6 | 225 | uint32_t USBHAL::EP0getReadResult(uint8_t *buffer) { |
Kojto | 71:53949e6131f6 | 226 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)hpcd.pData; |
Kojto | 71:53949e6131f6 | 227 | uint32_t length = (uint32_t) HAL_PCD_EP_GetRxCount(&hpcd, 0); |
Kojto | 71:53949e6131f6 | 228 | HALPriv->epComplete[EP0OUT] = 0; |
Kojto | 71:53949e6131f6 | 229 | if (length) { |
Kojto | 71:53949e6131f6 | 230 | uint8_t *buff = (uint8_t *)HALPriv->pBufRx0; |
Kojto | 71:53949e6131f6 | 231 | memcpy(buffer, buff, length); |
Kojto | 71:53949e6131f6 | 232 | } |
Kojto | 71:53949e6131f6 | 233 | return length; |
Kojto | 71:53949e6131f6 | 234 | } |
Kojto | 71:53949e6131f6 | 235 | |
Kojto | 71:53949e6131f6 | 236 | void USBHAL::EP0write(uint8_t *buffer, uint32_t size) { |
Kojto | 71:53949e6131f6 | 237 | /* check that endpoint maximum size is not exceeding TX fifo */ |
Kojto | 71:53949e6131f6 | 238 | MBED_ASSERT(hpcd.IN_ep[0].maxpacket >= size); |
Kojto | 71:53949e6131f6 | 239 | endpointWrite(EP0IN, buffer, size); |
Kojto | 71:53949e6131f6 | 240 | } |
Kojto | 71:53949e6131f6 | 241 | |
Kojto | 71:53949e6131f6 | 242 | void USBHAL::EP0getWriteResult(void) { |
Kojto | 71:53949e6131f6 | 243 | |
Kojto | 71:53949e6131f6 | 244 | } |
Kojto | 71:53949e6131f6 | 245 | |
Kojto | 71:53949e6131f6 | 246 | void USBHAL::EP0stall(void) { |
Kojto | 71:53949e6131f6 | 247 | stallEndpoint(EP0IN); |
Kojto | 71:53949e6131f6 | 248 | } |
Kojto | 71:53949e6131f6 | 249 | |
Kojto | 71:53949e6131f6 | 250 | EP_STATUS USBHAL::endpointRead(uint8_t endpoint, uint32_t maximumSize) { |
Kojto | 71:53949e6131f6 | 251 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData); |
Kojto | 71:53949e6131f6 | 252 | uint32_t epIndex = EP_ADDR(endpoint); |
Kojto | 71:53949e6131f6 | 253 | uint8_t* pBuf = (uint8_t *)HALPriv->pBufRx; |
Kojto | 71:53949e6131f6 | 254 | HAL_StatusTypeDef ret; |
Kojto | 71:53949e6131f6 | 255 | // clean reception end flag before requesting reception |
Kojto | 71:53949e6131f6 | 256 | HALPriv->epComplete[endpoint] = 2; |
Kojto | 71:53949e6131f6 | 257 | ret = HAL_PCD_EP_Receive(&hpcd, epIndex, pBuf, maximumSize); |
Kojto | 71:53949e6131f6 | 258 | MBED_ASSERT(ret!=HAL_BUSY); |
Kojto | 71:53949e6131f6 | 259 | return EP_PENDING; |
Kojto | 71:53949e6131f6 | 260 | } |
Kojto | 71:53949e6131f6 | 261 | |
Kojto | 71:53949e6131f6 | 262 | EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t * buffer, uint32_t *bytesRead) { |
Kojto | 71:53949e6131f6 | 263 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData); |
Kojto | 71:53949e6131f6 | 264 | if (HALPriv->epComplete[endpoint]==0) { |
Kojto | 71:53949e6131f6 | 265 | /* no reception possible !!! */ |
Kojto | 71:53949e6131f6 | 266 | bytesRead = 0; |
Kojto | 71:53949e6131f6 | 267 | return EP_COMPLETED; |
Kojto | 71:53949e6131f6 | 268 | }else if ((HALPriv->epComplete[endpoint]!=1)) |
Kojto | 71:53949e6131f6 | 269 | return EP_PENDING; |
Kojto | 71:53949e6131f6 | 270 | uint32_t epIndex = EP_ADDR(endpoint); |
Kojto | 71:53949e6131f6 | 271 | uint8_t *buff = (uint8_t *)HALPriv->pBufRx; |
Kojto | 71:53949e6131f6 | 272 | uint32_t length = (uint32_t) HAL_PCD_EP_GetRxCount(&hpcd, epIndex); |
Kojto | 71:53949e6131f6 | 273 | memcpy(buffer, buff, length); |
Kojto | 71:53949e6131f6 | 274 | *bytesRead = length; |
Kojto | 71:53949e6131f6 | 275 | HALPriv->epComplete[endpoint]= 0; |
Kojto | 71:53949e6131f6 | 276 | return EP_COMPLETED; |
Kojto | 71:53949e6131f6 | 277 | } |
Kojto | 71:53949e6131f6 | 278 | |
Kojto | 71:53949e6131f6 | 279 | EP_STATUS USBHAL::endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size) { |
Kojto | 71:53949e6131f6 | 280 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData); |
Kojto | 71:53949e6131f6 | 281 | uint32_t epIndex = EP_ADDR(endpoint); |
Kojto | 71:53949e6131f6 | 282 | HAL_StatusTypeDef ret; |
Kojto | 71:53949e6131f6 | 283 | // clean transmission end flag before requesting transmission |
Kojto | 71:53949e6131f6 | 284 | HALPriv->epComplete[endpoint] = 2; |
Kojto | 71:53949e6131f6 | 285 | ret = HAL_PCD_EP_Transmit(&hpcd, epIndex, data, size); |
Kojto | 71:53949e6131f6 | 286 | MBED_ASSERT(ret!=HAL_BUSY); |
Kojto | 71:53949e6131f6 | 287 | // update the status |
Kojto | 71:53949e6131f6 | 288 | if (ret != HAL_OK) return EP_INVALID; |
Kojto | 71:53949e6131f6 | 289 | // fix me return is too simple |
Kojto | 71:53949e6131f6 | 290 | return EP_PENDING; |
Kojto | 71:53949e6131f6 | 291 | } |
Kojto | 71:53949e6131f6 | 292 | |
Kojto | 71:53949e6131f6 | 293 | EP_STATUS USBHAL::endpointWriteResult(uint8_t endpoint) { |
Kojto | 71:53949e6131f6 | 294 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData); |
Kojto | 71:53949e6131f6 | 295 | if (HALPriv->epComplete[endpoint] == 1) |
Kojto | 71:53949e6131f6 | 296 | return EP_COMPLETED; |
Kojto | 71:53949e6131f6 | 297 | return EP_PENDING; |
Kojto | 71:53949e6131f6 | 298 | } |
Kojto | 71:53949e6131f6 | 299 | |
Kojto | 71:53949e6131f6 | 300 | void USBHAL::stallEndpoint(uint8_t endpoint) { |
Kojto | 71:53949e6131f6 | 301 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData); |
Kojto | 71:53949e6131f6 | 302 | HAL_StatusTypeDef ret; |
Kojto | 71:53949e6131f6 | 303 | HALPriv->epComplete[endpoint] = 0; |
Kojto | 71:53949e6131f6 | 304 | ret = HAL_PCD_EP_SetStall(&hpcd, EP_ADDR(endpoint)); |
Kojto | 71:53949e6131f6 | 305 | MBED_ASSERT(ret!=HAL_BUSY); |
Kojto | 71:53949e6131f6 | 306 | } |
Kojto | 71:53949e6131f6 | 307 | |
Kojto | 71:53949e6131f6 | 308 | void USBHAL::unstallEndpoint(uint8_t endpoint) { |
Kojto | 71:53949e6131f6 | 309 | HAL_StatusTypeDef ret; |
Kojto | 71:53949e6131f6 | 310 | ret = HAL_PCD_EP_ClrStall(&hpcd, EP_ADDR(endpoint)); |
Kojto | 71:53949e6131f6 | 311 | MBED_ASSERT(ret!=HAL_BUSY); |
Kojto | 71:53949e6131f6 | 312 | |
Kojto | 71:53949e6131f6 | 313 | } |
Kojto | 71:53949e6131f6 | 314 | |
Kojto | 71:53949e6131f6 | 315 | bool USBHAL::getEndpointStallState(uint8_t endpoint) { |
Kojto | 71:53949e6131f6 | 316 | return false; |
Kojto | 71:53949e6131f6 | 317 | } |
Kojto | 71:53949e6131f6 | 318 | |
Kojto | 71:53949e6131f6 | 319 | void USBHAL::remoteWakeup(void) { |
Kojto | 71:53949e6131f6 | 320 | } |
Kojto | 71:53949e6131f6 | 321 | |
Kojto | 71:53949e6131f6 | 322 | |
Kojto | 71:53949e6131f6 | 323 | void USBHAL::_usbisr(void) { |
Kojto | 71:53949e6131f6 | 324 | instance->usbisr(); |
Kojto | 71:53949e6131f6 | 325 | } |
Kojto | 71:53949e6131f6 | 326 | |
Kojto | 71:53949e6131f6 | 327 | |
Kojto | 71:53949e6131f6 | 328 | void USBHAL::usbisr(void) { |
Kojto | 71:53949e6131f6 | 329 | |
Kojto | 71:53949e6131f6 | 330 | HAL_PCD_IRQHandler(&instance->hpcd); |
Kojto | 71:53949e6131f6 | 331 | } |
Kojto | 71:53949e6131f6 | 332 | #endif |
Kojto | 71:53949e6131f6 | 333 |