Teensy 4.1 core updated for C++20
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

102 lines
2.6KB

  1. #ifndef USBaudio_h_
  2. #define USBaudio_h_
  3. #include "usb_desc.h"
  4. #ifdef AUDIO_INTERFACE
  5. #define FEATURE_MAX_VOLUME 0xFFF // volume accepted from 0 to 0xFFF
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. extern uint16_t usb_audio_receive_buffer[];
  10. extern uint16_t usb_audio_transmit_buffer[];
  11. extern void usb_audio_receive_callback(unsigned int len);
  12. extern unsigned int usb_audio_transmit_callback(void);
  13. int usb_audio_set_feature(void *stp, uint8_t *buf);
  14. int usb_audio_get_feature(void *stp, uint8_t *data, uint32_t *datalen);
  15. extern uint32_t usb_audio_sync_feedback;
  16. extern uint8_t usb_audio_receive_setting;
  17. extern uint8_t usb_audio_transmit_setting;
  18. #ifdef __cplusplus
  19. }
  20. // setup struct definition could be moved from usb_dev.c to usb_dev.h so we can reuse
  21. // it instead of redefining it here
  22. struct setup_struct {
  23. union {
  24. struct {
  25. uint8_t bmRequestType;
  26. uint8_t bRequest;
  27. union {
  28. struct {
  29. uint8_t bChannel; // 0=main, 1=left, 2=right
  30. uint8_t bCS; // Control Selector
  31. };
  32. uint16_t wValue;
  33. };
  34. union {
  35. struct {
  36. uint8_t bIfEp; // type of entity
  37. uint8_t bEntityId; // UnitID, TerminalID, etc.
  38. };
  39. uint16_t wIndex;
  40. };
  41. uint16_t wLength;
  42. };
  43. };
  44. };
  45. // audio features supported
  46. struct usb_audio_features_struct {
  47. int change; // set to 1 when any value is changed
  48. int mute; // 1=mute, 0=unmute
  49. int volume; // volume from 0 to FEATURE_MAX_VOLUME, maybe should be float from 0.0 to 1.0
  50. };
  51. #include "AudioStream.h"
  52. class AudioInputUSB : public AudioStream
  53. {
  54. public:
  55. AudioInputUSB(void) : AudioStream(0, NULL) { begin(); }
  56. virtual void update(void);
  57. void begin(void);
  58. friend void usb_audio_receive_callback(unsigned int len);
  59. friend int usb_audio_set_feature(void *stp, uint8_t *buf);
  60. friend int usb_audio_get_feature(void *stp, uint8_t *data, uint32_t *datalen);
  61. static struct usb_audio_features_struct features;
  62. private:
  63. static bool update_responsibility;
  64. static audio_block_t *incoming_left;
  65. static audio_block_t *incoming_right;
  66. static audio_block_t *ready_left;
  67. static audio_block_t *ready_right;
  68. static uint16_t incoming_count;
  69. static uint8_t receive_flag;
  70. };
  71. class AudioOutputUSB : public AudioStream
  72. {
  73. public:
  74. AudioOutputUSB(void) : AudioStream(2, inputQueueArray) { begin(); }
  75. virtual void update(void);
  76. void begin(void);
  77. friend unsigned int usb_audio_transmit_callback(void);
  78. private:
  79. static bool update_responsibility;
  80. static audio_block_t *left_1st;
  81. static audio_block_t *left_2nd;
  82. static audio_block_t *right_1st;
  83. static audio_block_t *right_2nd;
  84. static uint16_t offset_1st;
  85. audio_block_t *inputQueueArray[2];
  86. };
  87. #endif // __cplusplus
  88. #endif // AUDIO_INTERFACE
  89. #endif // USBaudio_h_