partly working USB Device lib for STM32F746NG Discovery both Interface are working

Dependents:   DISCO-F746NG-USB_Device McLighTT project_Keyboard_to_the_Keyboard MIDIInstrumentPADProject ... more

Committer:
DieterGraef
Date:
Sun Jul 31 17:47:35 2016 +0000
Revision:
0:0a2eaa300982
partly working USB Device library - serial and MIDI is working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DieterGraef 0:0a2eaa300982 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
DieterGraef 0:0a2eaa300982 2 *
DieterGraef 0:0a2eaa300982 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
DieterGraef 0:0a2eaa300982 4 * and associated documentation files (the "Software"), to deal in the Software without
DieterGraef 0:0a2eaa300982 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
DieterGraef 0:0a2eaa300982 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
DieterGraef 0:0a2eaa300982 7 * Software is furnished to do so, subject to the following conditions:
DieterGraef 0:0a2eaa300982 8 *
DieterGraef 0:0a2eaa300982 9 * The above copyright notice and this permission notice shall be included in all copies or
DieterGraef 0:0a2eaa300982 10 * substantial portions of the Software.
DieterGraef 0:0a2eaa300982 11 *
DieterGraef 0:0a2eaa300982 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
DieterGraef 0:0a2eaa300982 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
DieterGraef 0:0a2eaa300982 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DieterGraef 0:0a2eaa300982 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
DieterGraef 0:0a2eaa300982 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
DieterGraef 0:0a2eaa300982 17 */
DieterGraef 0:0a2eaa300982 18
DieterGraef 0:0a2eaa300982 19 #ifndef USBBUSINTERFACE_H
DieterGraef 0:0a2eaa300982 20 #define USBBUSINTERFACE_H
DieterGraef 0:0a2eaa300982 21
DieterGraef 0:0a2eaa300982 22 #include "mbed.h"
DieterGraef 0:0a2eaa300982 23 #include "USBEndpoints.h"
DieterGraef 0:0a2eaa300982 24 #include "toolchain.h"
DieterGraef 0:0a2eaa300982 25
DieterGraef 0:0a2eaa300982 26 //#ifdef __GNUC__
DieterGraef 0:0a2eaa300982 27 //#define __packed __attribute__ ((__packed__))
DieterGraef 0:0a2eaa300982 28 //#endif
DieterGraef 0:0a2eaa300982 29
DieterGraef 0:0a2eaa300982 30 class USBHAL {
DieterGraef 0:0a2eaa300982 31 public:
DieterGraef 0:0a2eaa300982 32 /* Configuration */
DieterGraef 0:0a2eaa300982 33 uint16_t HW_Interfaces;
DieterGraef 0:0a2eaa300982 34 USBHAL(uint16_t HW_Interface);
DieterGraef 0:0a2eaa300982 35 ~USBHAL(void);
DieterGraef 0:0a2eaa300982 36 void connect(void);
DieterGraef 0:0a2eaa300982 37 void disconnect(void);
DieterGraef 0:0a2eaa300982 38 void configureDevice(void);
DieterGraef 0:0a2eaa300982 39 void unconfigureDevice(void);
DieterGraef 0:0a2eaa300982 40 void setAddress(uint8_t address);
DieterGraef 0:0a2eaa300982 41 void remoteWakeup(void);
DieterGraef 0:0a2eaa300982 42
DieterGraef 0:0a2eaa300982 43 /* Endpoint 0 */
DieterGraef 0:0a2eaa300982 44 void EP0setup(uint8_t *buffer);
DieterGraef 0:0a2eaa300982 45 void EP0read(void);
DieterGraef 0:0a2eaa300982 46 void EP0readStage(void);
DieterGraef 0:0a2eaa300982 47 uint32_t EP0getReadResult(uint8_t *buffer);
DieterGraef 0:0a2eaa300982 48 void EP0write(uint8_t *buffer, uint32_t size);
DieterGraef 0:0a2eaa300982 49 void EP0getWriteResult(void);
DieterGraef 0:0a2eaa300982 50 void EP0stall(void);
DieterGraef 0:0a2eaa300982 51
DieterGraef 0:0a2eaa300982 52 /* Other endpoints */
DieterGraef 0:0a2eaa300982 53 EP_STATUS endpointRead(uint8_t endpoint, uint32_t maximumSize);
DieterGraef 0:0a2eaa300982 54 EP_STATUS endpointReadResult(uint8_t endpoint, uint8_t *data, uint32_t *bytesRead);
DieterGraef 0:0a2eaa300982 55 EP_STATUS endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size);
DieterGraef 0:0a2eaa300982 56 EP_STATUS endpointWriteResult(uint8_t endpoint);
DieterGraef 0:0a2eaa300982 57 void stallEndpoint(uint8_t endpoint);
DieterGraef 0:0a2eaa300982 58 void unstallEndpoint(uint8_t endpoint);
DieterGraef 0:0a2eaa300982 59 bool realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t options);
DieterGraef 0:0a2eaa300982 60 bool getEndpointStallState(unsigned char endpoint);
DieterGraef 0:0a2eaa300982 61 uint32_t endpointReadcore(uint8_t endpoint, uint8_t *buffer);
DieterGraef 0:0a2eaa300982 62
DieterGraef 0:0a2eaa300982 63 protected:
DieterGraef 0:0a2eaa300982 64 virtual void busReset(void){};
DieterGraef 0:0a2eaa300982 65 virtual void EP0setupCallback(void){};
DieterGraef 0:0a2eaa300982 66 virtual void EP0out(void){};
DieterGraef 0:0a2eaa300982 67 virtual void EP0in(void){};
DieterGraef 0:0a2eaa300982 68 virtual void connectStateChanged(unsigned int connected){};
DieterGraef 0:0a2eaa300982 69 virtual void suspendStateChanged(unsigned int suspended){};
DieterGraef 0:0a2eaa300982 70 virtual void SOF(int frameNumber){};
DieterGraef 0:0a2eaa300982 71
DieterGraef 0:0a2eaa300982 72 virtual bool EP1_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 73 virtual bool EP1_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 74 virtual bool EP2_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 75 virtual bool EP2_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 76 virtual bool EP3_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 77 virtual bool EP3_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 78 #if !defined(TARGET_STM32F4)
DieterGraef 0:0a2eaa300982 79 virtual bool EP4_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 80 virtual bool EP4_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 81 #if !(defined(TARGET_LPC11UXX) || defined(TARGET_LPC11U6X) || defined(TARGET_LPC1347) || defined(TARGET_LPC1549))
DieterGraef 0:0a2eaa300982 82 virtual bool EP5_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 83 virtual bool EP5_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 84 virtual bool EP6_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 85 virtual bool EP6_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 86 virtual bool EP7_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 87 virtual bool EP7_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 88 virtual bool EP8_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 89 virtual bool EP8_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 90 virtual bool EP9_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 91 virtual bool EP9_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 92 virtual bool EP10_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 93 virtual bool EP10_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 94 virtual bool EP11_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 95 virtual bool EP11_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 96 virtual bool EP12_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 97 virtual bool EP12_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 98 virtual bool EP13_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 99 virtual bool EP13_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 100 virtual bool EP14_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 101 virtual bool EP14_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 102 virtual bool EP15_OUT_callback(){return false;};
DieterGraef 0:0a2eaa300982 103 virtual bool EP15_IN_callback(){return false;};
DieterGraef 0:0a2eaa300982 104 #endif
DieterGraef 0:0a2eaa300982 105 #endif
DieterGraef 0:0a2eaa300982 106
DieterGraef 0:0a2eaa300982 107 private:
DieterGraef 0:0a2eaa300982 108 void usbisr(void);
DieterGraef 0:0a2eaa300982 109 static void _usbisrFS(void);
DieterGraef 0:0a2eaa300982 110 static void _usbisrHS(void);
DieterGraef 0:0a2eaa300982 111 static USBHAL * instance;
DieterGraef 0:0a2eaa300982 112 static uint32_t DevInterface;
DieterGraef 0:0a2eaa300982 113 #if defined(TARGET_LPC11UXX) || defined(TARGET_LPC11U6X) || defined(TARGET_LPC1347) || defined(TARGET_LPC1549)
DieterGraef 0:0a2eaa300982 114 bool (USBHAL::*epCallback[10 - 2])(void);
DieterGraef 0:0a2eaa300982 115 #elif defined(TARGET_STM32F4) || defined (TARGET_DISCO_F746NG)
DieterGraef 0:0a2eaa300982 116 bool (USBHAL::*epCallback[8 - 2])(void);
DieterGraef 0:0a2eaa300982 117 #else
DieterGraef 0:0a2eaa300982 118 bool (USBHAL::*epCallback[32 - 2])(void);
DieterGraef 0:0a2eaa300982 119 #endif
DieterGraef 0:0a2eaa300982 120 #if defined(TARGET_STM32L1)||defined(TARGET_STM32F1)||defined(TARGET_STM32F0)|| defined (TARGET_DISCO_F746NG)
DieterGraef 0:0a2eaa300982 121 public: // HAL_PCD
DieterGraef 0:0a2eaa300982 122 void SetupStageCallback();
DieterGraef 0:0a2eaa300982 123 void DataInStageCallback(uint8_t epnum);
DieterGraef 0:0a2eaa300982 124 void DataOutStageCallback(uint8_t epnum);
DieterGraef 0:0a2eaa300982 125 void ResetCallback();
DieterGraef 0:0a2eaa300982 126 void SOFCallback();
DieterGraef 0:0a2eaa300982 127 #endif // TARGET_STM32L1
DieterGraef 0:0a2eaa300982 128
DieterGraef 0:0a2eaa300982 129 };
DieterGraef 0:0a2eaa300982 130 #endif