summaryrefslogtreecommitdiff
path: root/usb-fast-audio-source/fast_source.c
diff options
context:
space:
mode:
Diffstat (limited to 'usb-fast-audio-source/fast_source.c')
-rw-r--r--usb-fast-audio-source/fast_source.c140
1 files changed, 140 insertions, 0 deletions
diff --git a/usb-fast-audio-source/fast_source.c b/usb-fast-audio-source/fast_source.c
new file mode 100644
index 0000000..7d20c7e
--- /dev/null
+++ b/usb-fast-audio-source/fast_source.c
@@ -0,0 +1,140 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include <board.h>
+#include <utility/trace.h>
+#include <utility/led.h>
+
+#include <usb/common/core/USBGenericRequest.h>
+#include <usb/device/core/USBD.h>
+#include <usb/device/core/USBDDriver.h>
+#include <usb/device/core/USBDDriverDescriptors.h>
+#include <usb/device/core/USBDCallbacks.h>
+#include <usb/common/audio/AUDGenericRequest.h>
+#include <usb/common/audio/AUDFeatureUnitRequest.h>
+
+#include <AUDDFastSourceDescriptors.h>
+#include <fast_source.h>
+
+extern const USBDDriverDescriptors auddFastSourceDriverDescriptors;
+static unsigned char driver_interfaces[3];
+static USBDDriver fast_source_driver;
+
+/* callback */
+void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
+{
+ fastsource_req_hdlr(request);
+}
+
+void USBDDriverCallbacks_InterfaceSettingChanged(unsigned char interface,
+ unsigned char setting)
+{
+ if ((interface == AUDDLoopRecDriverDescriptors_STREAMING)
+ && (setting == 0))
+ LED_Clear(USBD_LEDOTHER);
+ else
+ LED_Set(USBD_LEDOTHER);
+}
+
+static void fastsource_get_feat_cur_val(uint8_t entity, uint8_t channel,
+ uint8_t control, uint8_t length)
+{
+ /* FIXME */
+ USBD_Stall(0);
+}
+
+static void fastsource_set_feat_cur_val(uint8_t entity, uint8_t channel,
+ uint8_t control, uint8_t length)
+{
+ /* FIXME */
+ USBD_Stall(0);
+}
+
+void fastsource_req_hdlr(const USBGenericRequest *request)
+{
+ unsigned char entity;
+ unsigned char interface;
+
+ switch (USBGenericRequest_GetType(request)) {
+ case USBGenericRequest_STANDARD:
+ USBDDriver_RequestHandler(&fast_source_driver, request);
+ return;
+ case USBGenericRequest_CLASS:
+ /* continue below */
+ break;
+ default:
+ TRACE_WARNING("Unsupported request type %u\n\r",
+ USBGenericRequest_GetType(request));
+ USBD_Stall(0);
+ return;
+ }
+
+ switch (USBGenericRequest_GetRequest(request)) {
+ case AUDGenericRequest_SETCUR:
+ entity = AUDGenericRequest_GetEntity(request);
+ interface = AUDGenericRequest_GetInterface(request);
+ if (((entity == AUDDLoopRecDriverDescriptors_FEATUREUNIT) ||
+ (entity == AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC)) &&
+ (interface == AUDDLoopRecDriverDescriptors_CONTROL)) {
+ fastsource_set_feat_cur_val(entity,
+ AUDFeatureUnitRequest_GetChannel(request),
+ AUDFeatureUnitRequest_GetControl(request),
+ USBGenericRequest_GetLength(request));
+ } else {
+ TRACE_WARNING("Unsupported entity/interface combination 0x%04x\n\r",
+ USBGenericRequest_GetIndex(request));
+ USBD_Stall(0);
+ }
+ break;
+ case AUDGenericRequest_GETCUR:
+ entity = AUDGenericRequest_GetEntity(request);
+ interface = AUDGenericRequest_GetInterface(request);
+ if (((entity == AUDDLoopRecDriverDescriptors_FEATUREUNIT) ||
+ (entity == AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC)) &&
+ (interface == AUDDLoopRecDriverDescriptors_CONTROL)) {
+ fastsource_get_feat_cur_val(entity,
+ AUDFeatureUnitRequest_GetChannel(request),
+ AUDFeatureUnitRequest_GetControl(request),
+ USBGenericRequest_GetLength(request));
+ } else {
+ TRACE_WARNING("Unsupported entity/interface combination 0x%04x\n\r",
+ USBGenericRequest_GetIndex(request));
+ USBD_Stall(0);
+ }
+ break;
+ default:
+ TRACE_WARNING("Unsupported request %u\n\r",
+ USBGenericRequest_GetIndex(request));
+ USBD_Stall(0);
+ break;
+ }
+}
+
+void fastsource_init(void)
+{
+ USBDDriver_Initialize(&fast_source_driver, &auddFastSourceDriverDescriptors,
+ driver_interfaces);
+
+ USBD_Init();
+}
+
+const uint8_t test_data[2048];
+
+static void wr_compl_cb(void *arg, unsigned char status, unsigned int transferred,
+ unsigned int remain)
+{
+ uint8_t epnr = (uint8_t) arg;
+
+ if (status == 0 && remain == 0) {
+ fastsource_start(epnr);
+ } else {
+ printf("Err: EP%u wr_compl, status 0x%02u, xfr %u, remain %u\r\n",
+ epnr, status, transferred, remain);
+ }
+}
+
+void fastsource_start(uint8_t epnr)
+{
+ USBD_Write(epnr, &test_data, sizeof(test_data), wr_compl_cb, (void *) epnr);
+}
+
+
personal git repositories of Harald Welte. Your mileage may vary