adds a USB serial port to your design
Dependents: Example_WatchDog_Timer
targets/TARGET_STM/USBHAL_STM32.cpp@71:53949e6131f6, 2017-07-27 (annotated)
- Committer:
- Kojto
- Date:
- Thu Jul 27 12:14:04 2017 +0100
- Revision:
- 71:53949e6131f6
- Child:
- 72:08cd983d075e
Update libraries
Fixes the previous commmit, as some devices were not copied. USBDevice contains
now targets directory with all targets implementations
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 | |
Kojto | 71:53949e6131f6 | 37 | #include "USBHAL_STM_TARGET.h" |
Kojto | 71:53949e6131f6 | 38 | |
Kojto | 71:53949e6131f6 | 39 | |
Kojto | 71:53949e6131f6 | 40 | /* this call at device reception completion on a Out Enpoint */ |
Kojto | 71:53949e6131f6 | 41 | void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
Kojto | 71:53949e6131f6 | 42 | { |
Kojto | 71:53949e6131f6 | 43 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 44 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 45 | uint8_t endpoint = ADDR_EPOUT(epnum); |
Kojto | 71:53949e6131f6 | 46 | priv->epComplete[endpoint] = 1; |
Kojto | 71:53949e6131f6 | 47 | /* -2 endpoint 0 In out are not in call back list */ |
Kojto | 71:53949e6131f6 | 48 | if (epnum) { |
Kojto | 71:53949e6131f6 | 49 | bool (USBHAL::*func)(void) = priv->epCallback[endpoint-2]; |
Kojto | 71:53949e6131f6 | 50 | (obj->*func)(); |
Kojto | 71:53949e6131f6 | 51 | } else { |
Kojto | 71:53949e6131f6 | 52 | void (USBHAL::*func)(void) = priv->ep0_out; |
Kojto | 71:53949e6131f6 | 53 | (obj->*func)(); |
Kojto | 71:53949e6131f6 | 54 | } |
Kojto | 71:53949e6131f6 | 55 | } |
Kojto | 71:53949e6131f6 | 56 | |
Kojto | 71:53949e6131f6 | 57 | /* this is call at device transmission completion on In endpoint */ |
Kojto | 71:53949e6131f6 | 58 | void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
Kojto | 71:53949e6131f6 | 59 | { |
Kojto | 71:53949e6131f6 | 60 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 61 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 62 | uint8_t endpoint = ADDR_EPIN(epnum); |
Kojto | 71:53949e6131f6 | 63 | priv->epComplete[endpoint] = 1; |
Kojto | 71:53949e6131f6 | 64 | /* -2 endpoint 0 In out are not in call back list */ |
Kojto | 71:53949e6131f6 | 65 | if (epnum) { |
Kojto | 71:53949e6131f6 | 66 | bool (USBHAL::*func)(void) = priv->epCallback[endpoint-2]; |
Kojto | 71:53949e6131f6 | 67 | (obj->*func)(); |
Kojto | 71:53949e6131f6 | 68 | } else { |
Kojto | 71:53949e6131f6 | 69 | void (USBHAL::*func)(void) = priv->ep0_in; |
Kojto | 71:53949e6131f6 | 70 | (obj->*func)(); |
Kojto | 71:53949e6131f6 | 71 | } |
Kojto | 71:53949e6131f6 | 72 | } |
Kojto | 71:53949e6131f6 | 73 | /* This is call at device set up reception */ |
Kojto | 71:53949e6131f6 | 74 | void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) |
Kojto | 71:53949e6131f6 | 75 | { |
Kojto | 71:53949e6131f6 | 76 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 77 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 78 | void (USBHAL::*func)(void)=priv->ep0_setup; |
Kojto | 71:53949e6131f6 | 79 | void (USBHAL::*func1)(void)=priv->ep0_read; |
Kojto | 71:53949e6131f6 | 80 | (obj->*func)(); |
Kojto | 71:53949e6131f6 | 81 | (obj->*func1)(); |
Kojto | 71:53949e6131f6 | 82 | } |
Kojto | 71:53949e6131f6 | 83 | |
Kojto | 71:53949e6131f6 | 84 | void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) |
Kojto | 71:53949e6131f6 | 85 | { |
Kojto | 71:53949e6131f6 | 86 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 87 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 88 | void (USBHAL::*func)(unsigned int suspended) = priv->suspend_change; |
Kojto | 71:53949e6131f6 | 89 | (obj->*func)(1); |
Kojto | 71:53949e6131f6 | 90 | } |
Kojto | 71:53949e6131f6 | 91 | |
Kojto | 71:53949e6131f6 | 92 | void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) |
Kojto | 71:53949e6131f6 | 93 | { |
Kojto | 71:53949e6131f6 | 94 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 95 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 96 | void (USBHAL::*func)(unsigned int suspended) = priv->suspend_change; |
Kojto | 71:53949e6131f6 | 97 | (obj->*func)(0); |
Kojto | 71:53949e6131f6 | 98 | } |
Kojto | 71:53949e6131f6 | 99 | |
Kojto | 71:53949e6131f6 | 100 | void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) |
Kojto | 71:53949e6131f6 | 101 | { |
Kojto | 71:53949e6131f6 | 102 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 103 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 104 | void (USBHAL::*func)(unsigned int suspended) = priv->connect_change; |
Kojto | 71:53949e6131f6 | 105 | (obj->*func)(1); |
Kojto | 71:53949e6131f6 | 106 | } |
Kojto | 71:53949e6131f6 | 107 | |
Kojto | 71:53949e6131f6 | 108 | void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) |
Kojto | 71:53949e6131f6 | 109 | { |
Kojto | 71:53949e6131f6 | 110 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 111 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 112 | void (USBHAL::*func)(unsigned int suspended) = priv->connect_change; |
Kojto | 71:53949e6131f6 | 113 | (obj->*func)(0); |
Kojto | 71:53949e6131f6 | 114 | } |
Kojto | 71:53949e6131f6 | 115 | |
Kojto | 71:53949e6131f6 | 116 | void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) |
Kojto | 71:53949e6131f6 | 117 | { |
Kojto | 71:53949e6131f6 | 118 | USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData)); |
Kojto | 71:53949e6131f6 | 119 | USBHAL *obj= priv->inst; |
Kojto | 71:53949e6131f6 | 120 | unsigned int i; |
Kojto | 71:53949e6131f6 | 121 | for(i=0;i<hpcd->Init.dev_endpoints;i++) { |
Kojto | 71:53949e6131f6 | 122 | priv->epComplete[2*i]=0; |
Kojto | 71:53949e6131f6 | 123 | HAL_PCD_EP_Close(hpcd,EP_ADDR(2*i)); |
Kojto | 71:53949e6131f6 | 124 | HAL_PCD_EP_Flush(hpcd,EP_ADDR(2*i)); |
Kojto | 71:53949e6131f6 | 125 | priv->epComplete[2*i+1]=0; |
Kojto | 71:53949e6131f6 | 126 | HAL_PCD_EP_Close(hpcd,EP_ADDR(2*i+1)); |
Kojto | 71:53949e6131f6 | 127 | HAL_PCD_EP_Flush(hpcd,EP_ADDR(2*i+1)); |
Kojto | 71:53949e6131f6 | 128 | |
Kojto | 71:53949e6131f6 | 129 | } |
Kojto | 71:53949e6131f6 | 130 | void (USBHAL::*func)(void)=priv->bus_reset; |
Kojto | 71:53949e6131f6 | 131 | bool (USBHAL::*ep_realise)(uint8_t endpoint, uint32_t maxPacket, uint32_t flags) = priv->ep_realise; |
Kojto | 71:53949e6131f6 | 132 | (obj->*func)(); |
Kojto | 71:53949e6131f6 | 133 | (obj->*ep_realise)(EP0IN, MAX_PACKET_SIZE_EP0,0); |
Kojto | 71:53949e6131f6 | 134 | (obj->*ep_realise)(EP0OUT, MAX_PACKET_SIZE_EP0,0); |
Kojto | 71:53949e6131f6 | 135 | } |
Kojto | 71:53949e6131f6 | 136 | |
Kojto | 71:53949e6131f6 | 137 | |
Kojto | 71:53949e6131f6 | 138 | /* hal pcd handler , used for STM32 HAL PCD Layer */ |
Kojto | 71:53949e6131f6 | 139 | |
Kojto | 71:53949e6131f6 | 140 | uint32_t USBHAL::endpointReadcore(uint8_t endpoint, uint8_t *buffer) { |
Kojto | 71:53949e6131f6 | 141 | return 0; |
Kojto | 71:53949e6131f6 | 142 | } |
Kojto | 71:53949e6131f6 | 143 | |
Kojto | 71:53949e6131f6 | 144 | USBHAL::~USBHAL(void) { |
Kojto | 71:53949e6131f6 | 145 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData); |
Kojto | 71:53949e6131f6 | 146 | HAL_PCD_DeInit(&hpcd); |
Kojto | 71:53949e6131f6 | 147 | delete HALPriv; |
Kojto | 71:53949e6131f6 | 148 | } |
Kojto | 71:53949e6131f6 | 149 | |
Kojto | 71:53949e6131f6 | 150 | void USBHAL::connect(void) { |
Kojto | 71:53949e6131f6 | 151 | NVIC_EnableIRQ(USBHAL_IRQn); |
Kojto | 71:53949e6131f6 | 152 | } |
Kojto | 71:53949e6131f6 | 153 | |
Kojto | 71:53949e6131f6 | 154 | void USBHAL::disconnect(void) { |
Kojto | 71:53949e6131f6 | 155 | NVIC_DisableIRQ(USBHAL_IRQn); |
Kojto | 71:53949e6131f6 | 156 | } |
Kojto | 71:53949e6131f6 | 157 | |
Kojto | 71:53949e6131f6 | 158 | void USBHAL::configureDevice(void) { |
Kojto | 71:53949e6131f6 | 159 | // Not needed |
Kojto | 71:53949e6131f6 | 160 | } |
Kojto | 71:53949e6131f6 | 161 | |
Kojto | 71:53949e6131f6 | 162 | void USBHAL::unconfigureDevice(void) { |
Kojto | 71:53949e6131f6 | 163 | // Not needed |
Kojto | 71:53949e6131f6 | 164 | } |
Kojto | 71:53949e6131f6 | 165 | |
Kojto | 71:53949e6131f6 | 166 | void USBHAL::setAddress(uint8_t address) { |
Kojto | 71:53949e6131f6 | 167 | HAL_PCD_SetAddress(&hpcd, address); |
Kojto | 71:53949e6131f6 | 168 | EP0write(0, 0); |
Kojto | 71:53949e6131f6 | 169 | } |
Kojto | 71:53949e6131f6 | 170 | |
Kojto | 71:53949e6131f6 | 171 | bool USBHAL::realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t flags) { |
Kojto | 71:53949e6131f6 | 172 | uint32_t epIndex = EP_ADDR(endpoint); |
Kojto | 71:53949e6131f6 | 173 | uint32_t type; |
Kojto | 71:53949e6131f6 | 174 | uint32_t len; |
Kojto | 71:53949e6131f6 | 175 | HAL_StatusTypeDef ret; |
Kojto | 71:53949e6131f6 | 176 | switch (endpoint) { |
Kojto | 71:53949e6131f6 | 177 | case EP0IN: |
Kojto | 71:53949e6131f6 | 178 | case EP0OUT: |
Kojto | 71:53949e6131f6 | 179 | type = 0; |
Kojto | 71:53949e6131f6 | 180 | break; |
Kojto | 71:53949e6131f6 | 181 | case EPISO_IN: |
Kojto | 71:53949e6131f6 | 182 | case EPISO_OUT: |
Kojto | 71:53949e6131f6 | 183 | type = 1; |
Kojto | 71:53949e6131f6 | 184 | break; |
Kojto | 71:53949e6131f6 | 185 | case EPBULK_IN: |
Kojto | 71:53949e6131f6 | 186 | case EPBULK_OUT: |
Kojto | 71:53949e6131f6 | 187 | type = 2; |
Kojto | 71:53949e6131f6 | 188 | break; |
Kojto | 71:53949e6131f6 | 189 | case EPINT_IN: |
Kojto | 71:53949e6131f6 | 190 | case EPINT_OUT: |
Kojto | 71:53949e6131f6 | 191 | type = 3; |
Kojto | 71:53949e6131f6 | 192 | break; |
Kojto | 71:53949e6131f6 | 193 | } |
Kojto | 71:53949e6131f6 | 194 | if (maxPacket > MAXTRANSFER_SIZE) return false; |
Kojto | 71:53949e6131f6 | 195 | if (epIndex & 0x80) { |
Kojto | 71:53949e6131f6 | 196 | len = HAL_PCDEx_GetTxFiFo(&hpcd,epIndex & 0x7f); |
Kojto | 71:53949e6131f6 | 197 | MBED_ASSERT(len >= maxPacket); |
Kojto | 71:53949e6131f6 | 198 | } |
Kojto | 71:53949e6131f6 | 199 | ret = HAL_PCD_EP_Open(&hpcd, epIndex, maxPacket, type); |
Kojto | 71:53949e6131f6 | 200 | MBED_ASSERT(ret!=HAL_BUSY); |
Kojto | 71:53949e6131f6 | 201 | return (ret == HAL_OK) ? true:false; |
Kojto | 71:53949e6131f6 | 202 | } |
Kojto | 71:53949e6131f6 | 203 | |
Kojto | 71:53949e6131f6 | 204 | // read setup packet |
Kojto | 71:53949e6131f6 | 205 | void USBHAL::EP0setup(uint8_t *buffer) { |
Kojto | 71:53949e6131f6 | 206 | memcpy(buffer, hpcd.Setup, MAX_PACKET_SIZE_SETUP); |
Kojto | 71:53949e6131f6 | 207 | memset(hpcd.Setup,0,MAX_PACKET_SIZE_SETUP); |
Kojto | 71:53949e6131f6 | 208 | } |
Kojto | 71:53949e6131f6 | 209 | |
Kojto | 71:53949e6131f6 | 210 | void USBHAL::EP0readStage(void) { |
Kojto | 71:53949e6131f6 | 211 | } |
Kojto | 71:53949e6131f6 | 212 | |
Kojto | 71:53949e6131f6 | 213 | void USBHAL::EP0read(void) { |
Kojto | 71:53949e6131f6 | 214 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)hpcd.pData; |
Kojto | 71:53949e6131f6 | 215 | uint32_t epIndex = EP_ADDR(EP0OUT); |
Kojto | 71:53949e6131f6 | 216 | uint8_t *pBuf = (uint8_t *)HALPriv->pBufRx0; |
Kojto | 71:53949e6131f6 | 217 | HAL_StatusTypeDef ret; |
Kojto | 71:53949e6131f6 | 218 | HALPriv->epComplete[EP0OUT] = 2; |
Kojto | 71:53949e6131f6 | 219 | ret = HAL_PCD_EP_Receive(&hpcd, epIndex, pBuf, MAX_PACKET_SIZE_EP0 ); |
Kojto | 71:53949e6131f6 | 220 | MBED_ASSERT(ret!=HAL_BUSY); |
Kojto | 71:53949e6131f6 | 221 | |
Kojto | 71:53949e6131f6 | 222 | } |
Kojto | 71:53949e6131f6 | 223 | |
Kojto | 71:53949e6131f6 | 224 | uint32_t USBHAL::EP0getReadResult(uint8_t *buffer) { |
Kojto | 71:53949e6131f6 | 225 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)hpcd.pData; |
Kojto | 71:53949e6131f6 | 226 | uint32_t length = (uint32_t) HAL_PCD_EP_GetRxCount(&hpcd, 0); |
Kojto | 71:53949e6131f6 | 227 | HALPriv->epComplete[EP0OUT] = 0; |
Kojto | 71:53949e6131f6 | 228 | if (length) { |
Kojto | 71:53949e6131f6 | 229 | uint8_t *buff = (uint8_t *)HALPriv->pBufRx0; |
Kojto | 71:53949e6131f6 | 230 | memcpy(buffer, buff, length); |
Kojto | 71:53949e6131f6 | 231 | } |
Kojto | 71:53949e6131f6 | 232 | return length; |
Kojto | 71:53949e6131f6 | 233 | } |
Kojto | 71:53949e6131f6 | 234 | |
Kojto | 71:53949e6131f6 | 235 | void USBHAL::EP0write(uint8_t *buffer, uint32_t size) { |
Kojto | 71:53949e6131f6 | 236 | /* check that endpoint maximum size is not exceeding TX fifo */ |
Kojto | 71:53949e6131f6 | 237 | MBED_ASSERT(hpcd.IN_ep[0].maxpacket >= size); |
Kojto | 71:53949e6131f6 | 238 | endpointWrite(EP0IN, buffer, size); |
Kojto | 71:53949e6131f6 | 239 | } |
Kojto | 71:53949e6131f6 | 240 | |
Kojto | 71:53949e6131f6 | 241 | void USBHAL::EP0getWriteResult(void) { |
Kojto | 71:53949e6131f6 | 242 | |
Kojto | 71:53949e6131f6 | 243 | } |
Kojto | 71:53949e6131f6 | 244 | |
Kojto | 71:53949e6131f6 | 245 | void USBHAL::EP0stall(void) { |
Kojto | 71:53949e6131f6 | 246 | stallEndpoint(EP0IN); |
Kojto | 71:53949e6131f6 | 247 | } |
Kojto | 71:53949e6131f6 | 248 | |
Kojto | 71:53949e6131f6 | 249 | EP_STATUS USBHAL::endpointRead(uint8_t endpoint, uint32_t maximumSize) { |
Kojto | 71:53949e6131f6 | 250 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData); |
Kojto | 71:53949e6131f6 | 251 | uint32_t epIndex = EP_ADDR(endpoint); |
Kojto | 71:53949e6131f6 | 252 | uint8_t* pBuf = (uint8_t *)HALPriv->pBufRx; |
Kojto | 71:53949e6131f6 | 253 | HAL_StatusTypeDef ret; |
Kojto | 71:53949e6131f6 | 254 | // clean reception end flag before requesting reception |
Kojto | 71:53949e6131f6 | 255 | HALPriv->epComplete[endpoint] = 2; |
Kojto | 71:53949e6131f6 | 256 | ret = HAL_PCD_EP_Receive(&hpcd, epIndex, pBuf, maximumSize); |
Kojto | 71:53949e6131f6 | 257 | MBED_ASSERT(ret!=HAL_BUSY); |
Kojto | 71:53949e6131f6 | 258 | return EP_PENDING; |
Kojto | 71:53949e6131f6 | 259 | } |
Kojto | 71:53949e6131f6 | 260 | |
Kojto | 71:53949e6131f6 | 261 | EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t * buffer, uint32_t *bytesRead) { |
Kojto | 71:53949e6131f6 | 262 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData); |
Kojto | 71:53949e6131f6 | 263 | if (HALPriv->epComplete[endpoint]==0) { |
Kojto | 71:53949e6131f6 | 264 | /* no reception possible !!! */ |
Kojto | 71:53949e6131f6 | 265 | bytesRead = 0; |
Kojto | 71:53949e6131f6 | 266 | return EP_COMPLETED; |
Kojto | 71:53949e6131f6 | 267 | }else if ((HALPriv->epComplete[endpoint]!=1)) |
Kojto | 71:53949e6131f6 | 268 | return EP_PENDING; |
Kojto | 71:53949e6131f6 | 269 | uint32_t epIndex = EP_ADDR(endpoint); |
Kojto | 71:53949e6131f6 | 270 | uint8_t *buff = (uint8_t *)HALPriv->pBufRx; |
Kojto | 71:53949e6131f6 | 271 | uint32_t length = (uint32_t) HAL_PCD_EP_GetRxCount(&hpcd, epIndex); |
Kojto | 71:53949e6131f6 | 272 | memcpy(buffer, buff, length); |
Kojto | 71:53949e6131f6 | 273 | *bytesRead = length; |
Kojto | 71:53949e6131f6 | 274 | HALPriv->epComplete[endpoint]= 0; |
Kojto | 71:53949e6131f6 | 275 | return EP_COMPLETED; |
Kojto | 71:53949e6131f6 | 276 | } |
Kojto | 71:53949e6131f6 | 277 | |
Kojto | 71:53949e6131f6 | 278 | EP_STATUS USBHAL::endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size) { |
Kojto | 71:53949e6131f6 | 279 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData); |
Kojto | 71:53949e6131f6 | 280 | uint32_t epIndex = EP_ADDR(endpoint); |
Kojto | 71:53949e6131f6 | 281 | HAL_StatusTypeDef ret; |
Kojto | 71:53949e6131f6 | 282 | // clean transmission end flag before requesting transmission |
Kojto | 71:53949e6131f6 | 283 | HALPriv->epComplete[endpoint] = 2; |
Kojto | 71:53949e6131f6 | 284 | ret = HAL_PCD_EP_Transmit(&hpcd, epIndex, data, size); |
Kojto | 71:53949e6131f6 | 285 | MBED_ASSERT(ret!=HAL_BUSY); |
Kojto | 71:53949e6131f6 | 286 | // update the status |
Kojto | 71:53949e6131f6 | 287 | if (ret != HAL_OK) return EP_INVALID; |
Kojto | 71:53949e6131f6 | 288 | // fix me return is too simple |
Kojto | 71:53949e6131f6 | 289 | return EP_PENDING; |
Kojto | 71:53949e6131f6 | 290 | } |
Kojto | 71:53949e6131f6 | 291 | |
Kojto | 71:53949e6131f6 | 292 | EP_STATUS USBHAL::endpointWriteResult(uint8_t endpoint) { |
Kojto | 71:53949e6131f6 | 293 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData); |
Kojto | 71:53949e6131f6 | 294 | if (HALPriv->epComplete[endpoint] == 1) |
Kojto | 71:53949e6131f6 | 295 | return EP_COMPLETED; |
Kojto | 71:53949e6131f6 | 296 | return EP_PENDING; |
Kojto | 71:53949e6131f6 | 297 | } |
Kojto | 71:53949e6131f6 | 298 | |
Kojto | 71:53949e6131f6 | 299 | void USBHAL::stallEndpoint(uint8_t endpoint) { |
Kojto | 71:53949e6131f6 | 300 | USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData); |
Kojto | 71:53949e6131f6 | 301 | HAL_StatusTypeDef ret; |
Kojto | 71:53949e6131f6 | 302 | HALPriv->epComplete[endpoint] = 0; |
Kojto | 71:53949e6131f6 | 303 | ret = HAL_PCD_EP_SetStall(&hpcd, EP_ADDR(endpoint)); |
Kojto | 71:53949e6131f6 | 304 | MBED_ASSERT(ret!=HAL_BUSY); |
Kojto | 71:53949e6131f6 | 305 | } |
Kojto | 71:53949e6131f6 | 306 | |
Kojto | 71:53949e6131f6 | 307 | void USBHAL::unstallEndpoint(uint8_t endpoint) { |
Kojto | 71:53949e6131f6 | 308 | HAL_StatusTypeDef ret; |
Kojto | 71:53949e6131f6 | 309 | ret = HAL_PCD_EP_ClrStall(&hpcd, EP_ADDR(endpoint)); |
Kojto | 71:53949e6131f6 | 310 | MBED_ASSERT(ret!=HAL_BUSY); |
Kojto | 71:53949e6131f6 | 311 | |
Kojto | 71:53949e6131f6 | 312 | } |
Kojto | 71:53949e6131f6 | 313 | |
Kojto | 71:53949e6131f6 | 314 | bool USBHAL::getEndpointStallState(uint8_t endpoint) { |
Kojto | 71:53949e6131f6 | 315 | return false; |
Kojto | 71:53949e6131f6 | 316 | } |
Kojto | 71:53949e6131f6 | 317 | |
Kojto | 71:53949e6131f6 | 318 | void USBHAL::remoteWakeup(void) { |
Kojto | 71:53949e6131f6 | 319 | } |
Kojto | 71:53949e6131f6 | 320 | |
Kojto | 71:53949e6131f6 | 321 | |
Kojto | 71:53949e6131f6 | 322 | void USBHAL::_usbisr(void) { |
Kojto | 71:53949e6131f6 | 323 | instance->usbisr(); |
Kojto | 71:53949e6131f6 | 324 | } |
Kojto | 71:53949e6131f6 | 325 | |
Kojto | 71:53949e6131f6 | 326 | |
Kojto | 71:53949e6131f6 | 327 | void USBHAL::usbisr(void) { |
Kojto | 71:53949e6131f6 | 328 | |
Kojto | 71:53949e6131f6 | 329 | HAL_PCD_IRQHandler(&instance->hpcd); |
Kojto | 71:53949e6131f6 | 330 | } |
Kojto | 71:53949e6131f6 | 331 | #endif |
Kojto | 71:53949e6131f6 | 332 |