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