Il y avait des problèmes dans la libraire...

Fork of USBDEVICE by ST

Committer:
jamike
Date:
Fri Dec 16 15:12:14 2016 +0000
Revision:
2:760da2befbf5
Parent:
1:2a3ae13b45ef
USBMOUSE : ok for all supported except DISCO_L476VG
; this board requires clock change at init

Who changed what in which revision?

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