works!

Dependencies:   mbed

Committer:
kchhouk
Date:
Fri Feb 21 21:03:41 2020 +0000
Revision:
2:5e5cdc3504fe
Parent:
1:6e512faaa17c
Added the functionality of scanf

Who changed what in which revision?

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