Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. use crate::audio_buffer::{WriteBuffer, WritePacket};
  2. use crate::usb_audio::UsbAudioClass;
  3. use rp2040_hal::pac::USBCTRL_REGS;
  4. use rp2040_hal::timer::Timer;
  5. use rp2040_hal::usb::UsbBus;
  6. use usb_device::{class_prelude::*, prelude::*};
  7. pub struct Usb {
  8. usb_audio: UsbAudioClass<'static, UsbBus, WritePacket<4>>,
  9. usb_dev: UsbDevice<'static, UsbBus>,
  10. in_buffer: WriteBuffer<4>,
  11. timer: Timer,
  12. }
  13. impl Usb {
  14. pub fn init(
  15. bus: &'static UsbBusAllocator<UsbBus>,
  16. in_buffer: WriteBuffer<4>,
  17. timer: Timer,
  18. ) -> Usb {
  19. let usb_audio = UsbAudioClass::new(bus);
  20. // This PID/VID combination is selected from the pid.codes PID space and only intended for
  21. // software development. It is not universally unique and should not be used outside of
  22. // test environments!
  23. let usb_dev = UsbDeviceBuilder::new(bus, UsbVidPid(0x1209, 0x000d))
  24. .manufacturer("TEST")
  25. .product("USB audio test")
  26. .serial_number("TEST")
  27. .build();
  28. // TODO
  29. Usb {
  30. usb_audio,
  31. usb_dev,
  32. in_buffer,
  33. timer,
  34. }
  35. }
  36. pub fn poll(&mut self) {
  37. // Safety: The read access does not have any side effect, and this function is the only one
  38. // using the USB peripheral at this time.
  39. let sof = unsafe { (&*USBCTRL_REGS::ptr()).intr.read().dev_sof().bit_is_set() };
  40. if sof {
  41. // Calculate the frequency difference (frames versus 1kHz derived from the system
  42. // clock) and update the synchronization data for the USB audio class accordingly.
  43. // Also, add a correction factor if the buffers are running low or high.
  44. // TODO
  45. /*let mut buffer = [0u8; 64];
  46. for i in 0..64 {
  47. buffer[i] = i as u8 * 4;
  48. }
  49. let _err = self.usb_audio.write_packet(&buffer);*/
  50. }
  51. if self.usb_dev.poll(&mut [&mut self.usb_audio]) {
  52. // If we received audio data, move it into the buffer.
  53. // TODO
  54. }
  55. }
  56. }