Keyboard firmwares for Atmel AVR and Cortex-M
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

USBHAL.h 4.8KB

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