Keyboard firmwares for Atmel AVR and Cortex-M
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

USBMIDI.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 USBMIDI_H
  19. #define USBMIDI_H
  20. /* These headers are included for child class. */
  21. #include "USBEndpoints.h"
  22. #include "USBDescriptor.h"
  23. #include "USBDevice_Types.h"
  24. #include "USBDevice.h"
  25. #include "MIDIMessage.h"
  26. #define DEFAULT_CONFIGURATION (1)
  27. /**
  28. * USBMIDI example
  29. *
  30. * @code
  31. * #include "mbed.h"
  32. * #include "USBMIDI.h"
  33. *
  34. * USBMIDI midi;
  35. *
  36. * int main() {
  37. * while (1) {
  38. * for(int i=48; i<83; i++) { // send some messages!
  39. * midi.write(MIDIMessage::NoteOn(i));
  40. * wait(0.25);
  41. * midi.write(MIDIMessage::NoteOff(i));
  42. * wait(0.5);
  43. * }
  44. * }
  45. * }
  46. * @endcode
  47. */
  48. class USBMIDI: public USBDevice {
  49. public:
  50. /**
  51. * Constructor
  52. *
  53. * @param vendor_id Your vendor_id
  54. * @param product_id Your product_id
  55. * @param product_release Your preoduct_release
  56. */
  57. USBMIDI(uint16_t vendor_id = 0x0700, uint16_t product_id = 0x0101, uint16_t product_release = 0x0001);
  58. /**
  59. * Send a MIDIMessage
  60. *
  61. * @param m The MIDIMessage to send
  62. */
  63. void write(MIDIMessage m);
  64. /**
  65. * Attach a callback for when a MIDIEvent is received
  66. *
  67. * @param fptr function pointer
  68. */
  69. void attach(void (*fptr)(MIDIMessage));
  70. protected:
  71. virtual bool EPBULK_OUT_callback();
  72. virtual bool USBCallback_setConfiguration(uint8_t configuration);
  73. /*
  74. * Get string product descriptor
  75. *
  76. * @returns pointer to the string product descriptor
  77. */
  78. virtual uint8_t * stringIproductDesc();
  79. /*
  80. * Get string interface descriptor
  81. *
  82. * @returns pointer to the string interface descriptor
  83. */
  84. virtual uint8_t * stringIinterfaceDesc();
  85. /*
  86. * Get configuration descriptor
  87. *
  88. * @returns pointer to the configuration descriptor
  89. */
  90. virtual uint8_t * configurationDesc();
  91. private:
  92. uint8_t data[MAX_MIDI_MESSAGE_SIZE+1];
  93. uint8_t cur_data;
  94. bool data_end;
  95. void (*midi_evt)(MIDIMessage);
  96. };
  97. #endif