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
Diff: USBHost/USBEndpoint.h
- Revision:
- 9:7f9f64cf5ded
- Parent:
- 8:6463cd1964c0
- Child:
- 10:40c7f6788902
diff -r 6463cd1964c0 -r 7f9f64cf5ded USBHost/USBEndpoint.h --- a/USBHost/USBEndpoint.h Fri Jan 31 13:45:07 2014 +0000 +++ b/USBHost/USBEndpoint.h Mon Feb 03 13:00:16 2014 +0000 @@ -15,17 +15,58 @@ */ #pragma once +#include "FunctionPointer.h" #include "USBHostTypes.h" #include "USBDeviceConnected.h" + class USBDeviceConnected; +/** +* USBEndpoint class +*/ class USBEndpoint { public: + /** + * Constructor + */ USBEndpoint() : data01_toggle(DATA0),address(0),MaxPacketSize(8) { dev = NULL; } + + /** + * Attach a member function to call when a transfer is finished + * + * @param tptr pointer to the object to call the member function on + * @param mptr pointer to the member function to be called + */ + template<typename T> + inline void attach(T* tptr, void (T::*mptr)(void)) { + if((mptr != NULL) && (tptr != NULL)) { + rx.attach(tptr, mptr); + } + } + + /** + * Attach a callback called when a transfer is finished + * + * @param fptr function pointer + */ + inline void attach(void (*fptr)(void)) { + if(fptr != NULL) { + rx.attach(fptr); + } + } + + /** + * Call the handler associted to the end of a transfer + */ + inline void call() { + rx.call(); + }; + void setDevice(USBDeviceConnected* _dev) { dev = _dev; } void setState(uint8_t st){}; // dummy + void setBuffer(uint8_t* buf, int size) { buf_start = buf, buf_size = size; } void setLengthTransferred(int len) { transferred = len; }; void setSize(int size) { MaxPacketSize = size; } void setType(ENDPOINT_TYPE _type) { type = _type; }; @@ -35,6 +76,8 @@ USBDeviceConnected* getDevice() { return dev; } ENDPOINT_TYPE getType() { return type; }; int getLengthTransferred() { return transferred; } + uint8_t *getBufStart() { return buf_start; } + int getBufSize() { return buf_size; } uint8_t getAddress(){ return address; }; int getSize() { return MaxPacketSize; } ENDPOINT_DIRECTION getDir() { return (address & 0x80) ? IN : OUT; } @@ -49,6 +92,12 @@ USBDeviceConnected* dev; uint8_t data01_toggle; // DATA0,DATA1 uint8_t address; + int transferred; + uint8_t * buf_start; + int buf_size; + + FunctionPointer rx; + int MaxPacketSize; };