USB BARCODE READER
Fork of USBHOST by
USBHost/TARGET_STM/USBEndpoint_STM.cpp@3:1c76b46ad779, 2017-02-17 (annotated)
- Committer:
- frq08711@LMECWL0871.LME.ST.COM
- Date:
- Fri Feb 17 12:40:57 2017 +0100
- Revision:
- 3:1c76b46ad779
- Parent:
- 1:ab240722d7ef
- Child:
- 5:fc157e6bd5a5
fixes for USBMSD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1 | /* mbed USBHost Library |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 2 | * Copyright (c) 2006-2013 ARM Limited |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 3 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 5 | * you may not use this file except in compliance with the License. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 6 | * You may obtain a copy of the License at |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 7 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 9 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 10 | * Unless required by applicable law or agreed to in writing, software |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 13 | * See the License for the specific language governing permissions and |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 14 | * limitations under the License. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 15 | */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 16 | #if defined(TARGET_STM) && defined(USBHOST_OTHER) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 17 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 18 | #include "dbg.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 19 | #include "USBEndpoint.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 20 | extern uint32_t HAL_HCD_HC_GetMaxPacket(HCD_HandleTypeDef *hhcd, uint8_t chn_num); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 21 | extern uint32_t HAL_HCD_HC_GetType(HCD_HandleTypeDef *hhcd, uint8_t chn_num); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 22 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 23 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 24 | void USBEndpoint::init(HCED * hced_, ENDPOINT_TYPE type_, ENDPOINT_DIRECTION dir_, uint32_t size, uint8_t ep_number, HCTD* td_list_[2]) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 25 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 26 | hced = hced_; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 27 | type = type_; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 28 | dir = dir_; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 29 | setup = (type == CONTROL_ENDPOINT) ? true : false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 30 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 31 | //TDs have been allocated by the host |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 32 | memcpy((HCTD**)td_list, td_list_, sizeof(HCTD*)*2); //TODO: Maybe should add a param for td_list size... at least a define |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 33 | memset(td_list_[0], 0, sizeof(HCTD)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 34 | memset(td_list_[1], 0, sizeof(HCTD)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 35 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 36 | td_list[0]->ep = this; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 37 | td_list[1]->ep = this; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 38 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 39 | address = (ep_number & 0x7F) | ((dir - 1) << 7); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 40 | this->size = size; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 41 | this->ep_number = ep_number; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 42 | transfer_len = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 43 | transferred = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 44 | buf_start = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 45 | nextEp = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 46 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 47 | td_current = td_list[0]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 48 | td_next = td_list[1]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 49 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 50 | intf_nb = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 51 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 52 | state = USB_TYPE_IDLE; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 53 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 54 | void USBEndpoint::setSize(uint32_t size) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 55 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 56 | this->size = size; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 57 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 58 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 59 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 60 | void USBEndpoint::setDeviceAddress(uint8_t addr) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 61 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 62 | this->device_address = addr; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 63 | HAL_HCD_HC_Init((HCD_HandleTypeDef*)hced->hhcd,hced->ch_num, address, addr, HCD_SPEED_FULL, type, size); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 64 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 65 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 66 | void USBEndpoint::setSpeed(uint8_t speed) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 67 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 68 | this->speed = speed; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 69 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 70 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 71 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 72 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 73 | void USBEndpoint::setState(uint8_t st) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 74 | if (st > 18) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 75 | return; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 76 | if (state == USB_TYPE_FREE) HAL_HCD_HC_Halt((HCD_HandleTypeDef*)hced->hhcd, hced->ch_num); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 77 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 78 | state = (USB_TYPE)st; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 79 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 80 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 81 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 82 | extern uint32_t HAL_HCD_HC_GetMaxPacket(HCD_HandleTypeDef *hhcd, uint8_t chn_num); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 83 | extern uint32_t HAL_HCD_HC_GetType(HCD_HandleTypeDef *hhcd, uint8_t chn_num); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 84 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 85 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 86 | USB_TYPE USBEndpoint::queueTransfer() |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 87 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 88 | HCD_HandleTypeDef *hhcd = (HCD_HandleTypeDef*)hced->hhcd; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 89 | uint32_t *addr = &((uint32_t *)hhcd->pData)[hced->ch_num]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 90 | uint32_t type = HAL_HCD_HC_GetType(hhcd, hced->ch_num); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 91 | uint32_t max_size = HAL_HCD_HC_GetMaxPacket(hhcd, hced->ch_num); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 92 | /* if a packet is queue on disconnected ; no solution for now */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 93 | if(*addr == (uint32_t) -1) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 94 | /* set td as disconnected */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 95 | td_current->state = USB_TYPE_DISCONNECTED; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 96 | return USB_TYPE_DISCONNECTED; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 97 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 98 | MBED_ASSERT(*addr ==0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 99 | if ((type == EP_TYPE_BULK) || (type== EP_TYPE_CTRL)) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 100 | transfer_len = td_current->size <= max_size ? td_current->size : max_size; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 101 | transferred = td_current->size; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 102 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 103 | transfer_len = td_current->size; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 104 | transferred = td_current->size; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 105 | MBED_ASSERT(transferred <= (int)max_size); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 106 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 107 | buf_start = (uint8_t *)td_current->currBufPtr; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 108 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 109 | //Now add this free TD at this end of the queue |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 110 | state = USB_TYPE_PROCESSING; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 111 | /* one request */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 112 | td_current->nextTD = (hcTd*)0; |
frq08711@LMECWL0871.LME.ST.COM | 3:1c76b46ad779 | 113 | td_current->retry = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 114 | *addr = (uint32_t)td_current; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 115 | /* dir /setup is inverted for ST */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 116 | /* token is useful only ctrl endpoint */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 117 | /* last parameter is ping ? */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 118 | MBED_ASSERT(HAL_HCD_HC_SubmitRequest((HCD_HandleTypeDef*)hced->hhcd, hced->ch_num, dir-1, type,!setup,(uint8_t*) td_current->currBufPtr, transfer_len, 0)==HAL_OK); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 119 | return USB_TYPE_PROCESSING; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 120 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 121 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 122 | void USBEndpoint::unqueueTransfer(volatile HCTD * td) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 123 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 124 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 125 | uint32_t *addr = &((uint32_t *)((HCD_HandleTypeDef*)hced->hhcd)->pData)[hced->ch_num]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 126 | td->state=0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 127 | td->currBufPtr=0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 128 | td->size=0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 129 | td->nextTD=0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 130 | *addr = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 131 | td_current = td_next; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 132 | td_next = td; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 133 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 134 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 135 | void USBEndpoint::queueEndpoint(USBEndpoint * ed) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 136 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 137 | nextEp = ed; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 138 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 139 | #endif |