Simple USBHost library for STM32F746NG Discovery board. Only either the Fastspeed or the Highspeed port can be used( not both together)
Dependents: DISCO-F746NG_USB_Host
Fork of KL46Z-USBHost by
USBHost/USBEndpoint.h@9:7f9f64cf5ded, 2014-02-03 (annotated)
- Committer:
- va009039
- Date:
- Mon Feb 03 13:00:16 2014 +0000
- Revision:
- 9:7f9f64cf5ded
- Parent:
- 8:6463cd1964c0
- Child:
- 10:40c7f6788902
add interrupt write transfer.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 8:6463cd1964c0 | 1 | /* mbed USBHost Library |
va009039 | 8:6463cd1964c0 | 2 | * Copyright (c) 2006-2013 ARM Limited |
va009039 | 8:6463cd1964c0 | 3 | * |
va009039 | 8:6463cd1964c0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
va009039 | 8:6463cd1964c0 | 5 | * you may not use this file except in compliance with the License. |
va009039 | 8:6463cd1964c0 | 6 | * You may obtain a copy of the License at |
va009039 | 8:6463cd1964c0 | 7 | * |
va009039 | 8:6463cd1964c0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
va009039 | 8:6463cd1964c0 | 9 | * |
va009039 | 8:6463cd1964c0 | 10 | * Unless required by applicable law or agreed to in writing, software |
va009039 | 8:6463cd1964c0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
va009039 | 8:6463cd1964c0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
va009039 | 8:6463cd1964c0 | 13 | * See the License for the specific language governing permissions and |
va009039 | 8:6463cd1964c0 | 14 | * limitations under the License. |
va009039 | 8:6463cd1964c0 | 15 | */ |
va009039 | 8:6463cd1964c0 | 16 | |
va009039 | 5:10bfc10afcc8 | 17 | #pragma once |
va009039 | 9:7f9f64cf5ded | 18 | #include "FunctionPointer.h" |
va009039 | 5:10bfc10afcc8 | 19 | #include "USBHostTypes.h" |
va009039 | 8:6463cd1964c0 | 20 | #include "USBDeviceConnected.h" |
va009039 | 9:7f9f64cf5ded | 21 | |
va009039 | 8:6463cd1964c0 | 22 | class USBDeviceConnected; |
va009039 | 5:10bfc10afcc8 | 23 | |
va009039 | 9:7f9f64cf5ded | 24 | /** |
va009039 | 9:7f9f64cf5ded | 25 | * USBEndpoint class |
va009039 | 9:7f9f64cf5ded | 26 | */ |
va009039 | 5:10bfc10afcc8 | 27 | class USBEndpoint { |
va009039 | 5:10bfc10afcc8 | 28 | public: |
va009039 | 9:7f9f64cf5ded | 29 | /** |
va009039 | 9:7f9f64cf5ded | 30 | * Constructor |
va009039 | 9:7f9f64cf5ded | 31 | */ |
va009039 | 8:6463cd1964c0 | 32 | USBEndpoint() : data01_toggle(DATA0),address(0),MaxPacketSize(8) { |
va009039 | 8:6463cd1964c0 | 33 | dev = NULL; |
va009039 | 8:6463cd1964c0 | 34 | } |
va009039 | 9:7f9f64cf5ded | 35 | |
va009039 | 9:7f9f64cf5ded | 36 | /** |
va009039 | 9:7f9f64cf5ded | 37 | * Attach a member function to call when a transfer is finished |
va009039 | 9:7f9f64cf5ded | 38 | * |
va009039 | 9:7f9f64cf5ded | 39 | * @param tptr pointer to the object to call the member function on |
va009039 | 9:7f9f64cf5ded | 40 | * @param mptr pointer to the member function to be called |
va009039 | 9:7f9f64cf5ded | 41 | */ |
va009039 | 9:7f9f64cf5ded | 42 | template<typename T> |
va009039 | 9:7f9f64cf5ded | 43 | inline void attach(T* tptr, void (T::*mptr)(void)) { |
va009039 | 9:7f9f64cf5ded | 44 | if((mptr != NULL) && (tptr != NULL)) { |
va009039 | 9:7f9f64cf5ded | 45 | rx.attach(tptr, mptr); |
va009039 | 9:7f9f64cf5ded | 46 | } |
va009039 | 9:7f9f64cf5ded | 47 | } |
va009039 | 9:7f9f64cf5ded | 48 | |
va009039 | 9:7f9f64cf5ded | 49 | /** |
va009039 | 9:7f9f64cf5ded | 50 | * Attach a callback called when a transfer is finished |
va009039 | 9:7f9f64cf5ded | 51 | * |
va009039 | 9:7f9f64cf5ded | 52 | * @param fptr function pointer |
va009039 | 9:7f9f64cf5ded | 53 | */ |
va009039 | 9:7f9f64cf5ded | 54 | inline void attach(void (*fptr)(void)) { |
va009039 | 9:7f9f64cf5ded | 55 | if(fptr != NULL) { |
va009039 | 9:7f9f64cf5ded | 56 | rx.attach(fptr); |
va009039 | 9:7f9f64cf5ded | 57 | } |
va009039 | 9:7f9f64cf5ded | 58 | } |
va009039 | 9:7f9f64cf5ded | 59 | |
va009039 | 9:7f9f64cf5ded | 60 | /** |
va009039 | 9:7f9f64cf5ded | 61 | * Call the handler associted to the end of a transfer |
va009039 | 9:7f9f64cf5ded | 62 | */ |
va009039 | 9:7f9f64cf5ded | 63 | inline void call() { |
va009039 | 9:7f9f64cf5ded | 64 | rx.call(); |
va009039 | 9:7f9f64cf5ded | 65 | }; |
va009039 | 9:7f9f64cf5ded | 66 | |
va009039 | 8:6463cd1964c0 | 67 | void setDevice(USBDeviceConnected* _dev) { dev = _dev; } |
va009039 | 5:10bfc10afcc8 | 68 | void setState(uint8_t st){}; // dummy |
va009039 | 9:7f9f64cf5ded | 69 | void setBuffer(uint8_t* buf, int size) { buf_start = buf, buf_size = size; } |
va009039 | 8:6463cd1964c0 | 70 | void setLengthTransferred(int len) { transferred = len; }; |
va009039 | 5:10bfc10afcc8 | 71 | void setSize(int size) { MaxPacketSize = size; } |
va009039 | 8:6463cd1964c0 | 72 | void setType(ENDPOINT_TYPE _type) { type = _type; }; |
va009039 | 5:10bfc10afcc8 | 73 | void setAddress(uint8_t addr) { address = addr; } |
va009039 | 5:10bfc10afcc8 | 74 | void setData01(uint8_t data01) { data01_toggle = data01; } |
va009039 | 8:6463cd1964c0 | 75 | |
va009039 | 8:6463cd1964c0 | 76 | USBDeviceConnected* getDevice() { return dev; } |
va009039 | 8:6463cd1964c0 | 77 | ENDPOINT_TYPE getType() { return type; }; |
va009039 | 8:6463cd1964c0 | 78 | int getLengthTransferred() { return transferred; } |
va009039 | 9:7f9f64cf5ded | 79 | uint8_t *getBufStart() { return buf_start; } |
va009039 | 9:7f9f64cf5ded | 80 | int getBufSize() { return buf_size; } |
va009039 | 5:10bfc10afcc8 | 81 | uint8_t getAddress(){ return address; }; |
va009039 | 5:10bfc10afcc8 | 82 | int getSize() { return MaxPacketSize; } |
va009039 | 8:6463cd1964c0 | 83 | ENDPOINT_DIRECTION getDir() { return (address & 0x80) ? IN : OUT; } |
va009039 | 5:10bfc10afcc8 | 84 | uint8_t getData01() { return data01_toggle; } |
va009039 | 5:10bfc10afcc8 | 85 | void toggleData01() { |
va009039 | 5:10bfc10afcc8 | 86 | data01_toggle = (data01_toggle == DATA0) ? DATA1 : DATA0; |
va009039 | 5:10bfc10afcc8 | 87 | } |
va009039 | 5:10bfc10afcc8 | 88 | |
va009039 | 5:10bfc10afcc8 | 89 | private: |
va009039 | 8:6463cd1964c0 | 90 | ENDPOINT_TYPE type; |
va009039 | 8:6463cd1964c0 | 91 | ENDPOINT_DIRECTION dir; |
va009039 | 8:6463cd1964c0 | 92 | USBDeviceConnected* dev; |
va009039 | 5:10bfc10afcc8 | 93 | uint8_t data01_toggle; // DATA0,DATA1 |
va009039 | 5:10bfc10afcc8 | 94 | uint8_t address; |
va009039 | 9:7f9f64cf5ded | 95 | |
va009039 | 8:6463cd1964c0 | 96 | int transferred; |
va009039 | 9:7f9f64cf5ded | 97 | uint8_t * buf_start; |
va009039 | 9:7f9f64cf5ded | 98 | int buf_size; |
va009039 | 9:7f9f64cf5ded | 99 | |
va009039 | 9:7f9f64cf5ded | 100 | FunctionPointer rx; |
va009039 | 9:7f9f64cf5ded | 101 | |
va009039 | 5:10bfc10afcc8 | 102 | int MaxPacketSize; |
va009039 | 5:10bfc10afcc8 | 103 | }; |