usb audio‏

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

usb audio‏

1,663 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LPCNX123 on Tue Aug 02 16:54:46 MST 2011
UsbDev   http://ics.nxp.com/support/documents/microcontrollers/?scope=LPC1768 http://ics.nxp.com/support/documents/microcontrollers/zip/lpc17xx.cmsis.driver.library.zip   the code I use has only speaker out and the adc side is just controlling the volume, I need examples of how to add a microphone to windows for the lpc1768, I see in the code their has been code left in to do this or at least half the code, or I could be way off in saying this, but how do you expect anybody to know how to do this with no examples, your almost asking somebody to do the impossible. Why is there nothing like this, this is just a basic standard thing.
0 Kudos
Reply
9 Replies

1,597 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LPCNX123 on Wed Aug 10 11:24:56 MST 2011
I am the reversing guy, I reverse....you write code ok, I have been biting my tongue for to long now.
0 Kudos
Reply

1,597 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wdawson61 on Wed Aug 10 10:23:50 MST 2011
My tongue hurts from being bitten...
0 Kudos
Reply

1,597 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LPCNX123 on Wed Aug 10 08:45:24 MST 2011
/*----------------------------------------------------------------------------
 *      U S B  -  K e r n e l
 *----------------------------------------------------------------------------
 *      Name:    ADCUSER.C
 *      Purpose: Audio Device Class Custom User Module
 *      Version: V1.10
 *----------------------------------------------------------------------------
 *      This software is supplied "AS IS" without any warranties, express,
 *      implied or statutory, including but not limited to the implied
 *      warranties of fitness for purpose, satisfactory quality and
 *      noninfringement. Keil extends you a royalty-free right to reproduce
 *      and distribute executable files created using this software for use
 *      on NXP Semiconductors LPC family microcontroller devices only. Nothing 
 *      else gives you the right to use this software.
 *
 * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
 *---------------------------------------------------------------------------*/

#include "type.h"

#include "usb.h"
#include "audio.h"
#include "usbcfg.h"
#include "usbcore.h"
#include "adcuser.h"

#include "usbaudio.h"

      uint16_t VolCur = 0x0100;     /* Volume Current Value */
const uint16_t VolMin = 0x0000;     /* Volume Minimum Value */
const uint16_t VolMax = 0x0100;     /* Volume Maximum Value */
const uint16_t VolRes = 0x0004;     /* Volume Resolution */

/*
 *  Audio Device Class Interface Get Request Callback
 *   Called automatically on ADC Interface Get Request
 *    Parameters:      None (global SetupPacket and EP0Buf)
 *    Return Value:    TRUE - Success, FALSE - Error
 */

uint32_t ADC_IF_GetRequest (void) {

/*
  Interface = SetupPacket.wIndex.WB.L;
  EntityID  = SetupPacket.wIndex.WB.H;
  Request   = SetupPacket.bRequest;
  Value     = SetupPacket.wValue.W;
  ...
*/

  if (SetupPacket.wIndex.W == 0x0200) {
    /* Feature Unit: Interface = 0, ID = 2 */
    if (SetupPacket.wValue.WB.L == 0) {
      /* Master Channel */
      switch (SetupPacket.wValue.WB.H) {
        case AUDIO_MUTE_CONTROL:
          switch (SetupPacket.bRequest) {
            case AUDIO_REQUEST_GET_CUR:
              EP0Buf[0] = Mute;
              return (TRUE);
          }
          break;
        case AUDIO_VOLUME_CONTROL:
          switch (SetupPacket.bRequest) {
            case AUDIO_REQUEST_GET_CUR:
              *((__packed uint16_t *)EP0Buf) = VolCur;
              return (TRUE);
            case AUDIO_REQUEST_GET_MIN:
              *((__packed uint16_t *)EP0Buf) = VolMin;
              return (TRUE);
            case AUDIO_REQUEST_GET_MAX:
              *((__packed uint16_t *)EP0Buf) = VolMax;
              return (TRUE);
            case AUDIO_REQUEST_GET_RES:
              *((__packed uint16_t *)EP0Buf) = VolRes;
              return (TRUE);
          }
          break;
      }
    }
  }
  return (FALSE);  /* Not Supported */
}


/*
 *  Audio Device Class Interface Set Request Callback
 *   Called automatically on ADC Interface Set Request
 *    Parameters:      None (global SetupPacket and EP0Buf)
 *    Return Value:    TRUE - Success, FALSE - Error
 */

uint32_t ADC_IF_SetRequest (void) {

/*
  Interface = SetupPacket.wIndex.WB.L;
  EntityID  = SetupPacket.wIndex.WB.H;
  Request   = SetupPacket.bRequest;
  Value     = SetupPacket.wValue.W;
  ...
*/

  if (SetupPacket.wIndex.W == 0x0200) {
    /* Feature Unit: Interface = 0, ID = 2 */
    if (SetupPacket.wValue.WB.L == 0) {
      /* Master Channel */
      switch (SetupPacket.wValue.WB.H) {
        case AUDIO_MUTE_CONTROL:
          switch (SetupPacket.bRequest) {
            case AUDIO_REQUEST_SET_CUR:
              Mute = EP0Buf[0];
              return (TRUE);
          }
          break;
        case AUDIO_VOLUME_CONTROL:
          switch (SetupPacket.bRequest) {
            case AUDIO_REQUEST_SET_CUR:
              VolCur = *((__packed uint16_t *)EP0Buf);
              return (TRUE);
          }
          break;
      }
    }
  }
  return (FALSE);  /* Not Supported */
}


/*
 *  Audio Device Class EndPoint Get Request Callback
 *   Called automatically on ADC EndPoint Get Request
 *    Parameters:      None (global SetupPacket and EP0Buf)
 *    Return Value:    TRUE - Success, FALSE - Error
 */

uint32_t ADC_EP_GetRequest (void) {

/*
  EndPoint = SetupPacket.wIndex.WB.L;
  Request  = SetupPacket.bRequest;
  Value    = SetupPacket.wValue.W;
  ...
*/
  return (FALSE);  /* Not Supported */
}


/*
 *  Audio Device Class EndPoint Set Request Callback
 *   Called automatically on ADC EndPoint Set Request
 *    Parameters:      None (global SetupPacket and EP0Buf)
 *    Return Value:    TRUE - Success, FALSE - Error
 */

uint32_t ADC_EP_SetRequest (void) {

/*
  EndPoint = SetupPacket.wIndex.WB.L;
  Request  = SetupPacket.bRequest;
  Value    = SetupPacket.wValue.W;
  ...
*/
  return (FALSE);  /* Not Supported */
}
0 Kudos
Reply

1,597 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LPCNX123 on Wed Aug 10 08:40:15 MST 2011
/*----------------------------------------------------------------------------
 *      U S B  -  K e r n e l
 *----------------------------------------------------------------------------
 * Name:    usbdesc.c
 * Purpose: USB Descriptors
 * Version: V1.20
 *----------------------------------------------------------------------------
 *      This software is supplied "AS IS" without any warranties, express,
 *      implied or statutory, including but not limited to the implied
 *      warranties of fitness for purpose, satisfactory quality and
 *      noninfringement. Keil extends you a royalty-free right to reproduce
 *      and distribute executable files created using this software for use
 *      on NXP Semiconductors LPC family microcontroller devices only. Nothing 
 *      else gives you the right to use this software.
 *
 * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
 *----------------------------------------------------------------------------
 * History:
 *          V1.20 Changed string descriptor handling
 *          V1.00 Initial Version
 *----------------------------------------------------------------------------*/
#include "type.h"

#include "usb.h"
#include "audio.h"
#include "usbcfg.h"
#include "usbdesc.h"


/* USB Standard Device Descriptor */
const uint8_t USB_DeviceDescriptor[] = {
  USB_DEVICE_DESC_SIZE,              /* bLength */
  USB_DEVICE_DESCRIPTOR_TYPE,        /* bDescriptorType */
  WBVAL(0x0200), /* 2.00 */          /* bcdUSB */
  0x00,                              /* bDeviceClass */
  0x00,                              /* bDeviceSubClass */
  0x00,                              /* bDeviceProtocol */
  USB_MAX_PACKET0,                   /* bMaxPacketSize0 */
  WBVAL(0x1FC9),                     /* idVendor */
  WBVAL(0x4002),                     /* idProduct */
  WBVAL(0x0100), /* 1.00 */          /* bcdDevice */
  0x01,                              /* iManufacturer */
  0x02,                              /* iProduct */
  0x03,                              /* iSerialNumber */
  0x01                               /* bNumConfigurations: one possible configuration*/
};

/* USB Configuration Descriptor */
/*   All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
const uint8_t USB_ConfigDescriptor[] = {
/* Configuration 1 */
  USB_CONFIGUARTION_DESC_SIZE,          /* bLength */
  USB_CONFIGURATION_DESCRIPTOR_TYPE,    /* bDescriptorType */
  WBVAL(                                /* wTotalLength */
    USB_CONFIGUARTION_DESC_SIZE         +
    USB_INTERFACE_DESC_SIZE             +
    AUDIO_CONTROL_INTERFACE_DESC_SZ(1)  +
    AUDIO_INPUT_TERMINAL_DESC_SIZE      +
    AUDIO_FEATURE_UNIT_DESC_SZ(1,1)     +
    AUDIO_OUTPUT_TERMINAL_DESC_SIZE     +
    USB_INTERFACE_DESC_SIZE             +
    USB_INTERFACE_DESC_SIZE             +
    AUDIO_STREAMING_INTERFACE_DESC_SIZE +
    AUDIO_FORMAT_TYPE_I_DESC_SZ(1)      +
    AUDIO_STANDARD_ENDPOINT_DESC_SIZE   +
    AUDIO_STREAMING_ENDPOINT_DESC_SIZE
  ),
  0x02,                                 /* bNumInterfaces */
  0x01,                                 /* bConfigurationValue */
  0x00,                                 /* iConfiguration */
  USB_CONFIG_BUS_POWERED,               /* bmAttributes */
  USB_CONFIG_POWER_MA(100),             /* bMaxPower */
/* Interface 0, Alternate Setting 0, Audio Control */
  USB_INTERFACE_DESC_SIZE,              /* bLength */
  USB_INTERFACE_DESCRIPTOR_TYPE,        /* bDescriptorType */
  0x00,                                 /* bInterfaceNumber */
  0x00,                                 /* bAlternateSetting */
  0x00,                                 /* bNumEndpoints */
  USB_DEVICE_CLASS_AUDIO,               /* bInterfaceClass */
  AUDIO_SUBCLASS_AUDIOCONTROL,          /* bInterfaceSubClass */
  AUDIO_PROTOCOL_UNDEFINED,             /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
/* Audio Control Interface */
  AUDIO_CONTROL_INTERFACE_DESC_SZ(1),   /* bLength */
  AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
  AUDIO_CONTROL_HEADER,                 /* bDescriptorSubtype */
  WBVAL(0x0100), /* 1.00 */             /* bcdADC */
  WBVAL(                                /* wTotalLength */
    AUDIO_CONTROL_INTERFACE_DESC_SZ(1) +
    AUDIO_INPUT_TERMINAL_DESC_SIZE     +
    AUDIO_FEATURE_UNIT_DESC_SZ(1,1)    +
    AUDIO_OUTPUT_TERMINAL_DESC_SIZE
  ),
  0x01,                                 /* bInCollection */
  0x01,                                 /* baInterfaceNr */
/* Audio Input Terminal */
  AUDIO_INPUT_TERMINAL_DESC_SIZE,       /* bLength */
  AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
  AUDIO_CONTROL_INPUT_TERMINAL,         /* bDescriptorSubtype */
  0x01,                                 /* bTerminalID */
  WBVAL(AUDIO_TERMINAL_USB_STREAMING),  /* wTerminalType */
  0x00,                                 /* bAssocTerminal */
  0x01,                                 /* bNrChannels */
  WBVAL(AUDIO_CHANNEL_M),               /* wChannelConfig */
  0x00,                                 /* iChannelNames */
  0x00,                                 /* iTerminal */
/* Audio Feature Unit */
  AUDIO_FEATURE_UNIT_DESC_SZ(1,1),      /* bLength */
  AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
  AUDIO_CONTROL_FEATURE_UNIT,           /* bDescriptorSubtype */
  0x02,                                 /* bUnitID */
  0x01,                                 /* bSourceID */
  0x01,                                 /* bControlSize */
  AUDIO_CONTROL_MUTE |
  AUDIO_CONTROL_VOLUME,                 /* bmaControls(0) */
  0x00,                                 /* bmaControls(1) */
  0x00,                                 /* iTerminal */
///* Audio Output Terminal */
  //AUDIO_OUTPUT_TERMINAL_DESC_SIZE,      /* bLength */
  //AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
  //AUDIO_CONTROL_OUTPUT_TERMINAL,        /* bDescriptorSubtype */
  //0x03,                                 /* bTerminalID */
  //WBVAL(AUDIO_TERMINAL_SPEAKER),        /* wTerminalType */
  //0x00,                                 /* bAssocTerminal */
  //0x02,                                 /* bSourceID */
  //0x00,                                 /* iTerminal */
/* Interface 1, Alternate Setting 0, Audio Streaming - Zero Bandwith */
  USB_INTERFACE_DESC_SIZE,              /* bLength */
  USB_INTERFACE_DESCRIPTOR_TYPE,        /* bDescriptorType */
  0x01,                                 /* bInterfaceNumber */
  0x00,                                 /* bAlternateSetting */
  0x00,                                 /* bNumEndpoints */
  USB_DEVICE_CLASS_AUDIO,               /* bInterfaceClass */
  AUDIO_SUBCLASS_AUDIOSTREAMING,        /* bInterfaceSubClass */
  AUDIO_PROTOCOL_UNDEFINED,             /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
/* Interface 1, Alternate Setting 1, Audio Streaming - Operational */
  USB_INTERFACE_DESC_SIZE,              /* bLength */
  USB_INTERFACE_DESCRIPTOR_TYPE,        /* bDescriptorType */
  0x01,                                 /* bInterfaceNumber */
  0x01,                                 /* bAlternateSetting */
  0x01,                                 /* bNumEndpoints */
  USB_DEVICE_CLASS_AUDIO,               /* bInterfaceClass */
  AUDIO_SUBCLASS_AUDIOSTREAMING,        /* bInterfaceSubClass */
  AUDIO_PROTOCOL_UNDEFINED,             /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
/* Audio Streaming Interface */
  AUDIO_STREAMING_INTERFACE_DESC_SIZE,  /* bLength */
  AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
  AUDIO_STREAMING_GENERAL,              /* bDescriptorSubtype */
  0x01,                                 /* bTerminalLink */
  0x01,                                 /* bDelay */
  WBVAL(AUDIO_FORMAT_PCM),              /* wFormatTag */
/* Audio Type I Format */
  AUDIO_FORMAT_TYPE_I_DESC_SZ(1),       /* bLength */
  AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
  AUDIO_STREAMING_FORMAT_TYPE,          /* bDescriptorSubtype */
  AUDIO_FORMAT_TYPE_I,                  /* bFormatType */
  0x01,                                 /* bNrChannels */
  0x02,                                 /* bSubFrameSize */
  16,                                   /* bBitResolution */
  0x01,                                 /* bSamFreqType */
  B3VAL(32000),                         /* tSamFreq */
/* Endpoint - Standard Descriptor */
  AUDIO_STANDARD_ENDPOINT_DESC_SIZE,    /* bLength */
  USB_ENDPOINT_DESCRIPTOR_TYPE,         /* bDescriptorType */
  USB_ENDPOINT_OUT(3),                  /* bEndpointAddress */
  USB_ENDPOINT_TYPE_ISOCHRONOUS,        /* bmAttributes */
  WBVAL(64),                            /* wMaxPacketSize */
  0x01,                                 /* bInterval */
  0x00,                                 /* bRefresh */
  0x00,                                 /* bSynchAddress */
/* Endpoint - Audio Streaming */
  AUDIO_STREAMING_ENDPOINT_DESC_SIZE,   /* bLength */
  AUDIO_ENDPOINT_DESCRIPTOR_TYPE,       /* bDescriptorType */
  AUDIO_ENDPOINT_GENERAL,               /* bDescriptor */
  0x00,                                 /* bmAttributes */
  0x00,                                 /* bLockDelayUnits */
  WBVAL(0x0000),                        /* wLockDelay */
/* Terminator */
  0                                     /* bLength */
};

0 Kudos
Reply

1,597 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LPCNX123 on Wed Aug 10 08:38:39 MST 2011

Quote: Rob65
The whole idea of the examples is to give you a head start on writing your own programs. So there is a timer example to show you how to use the timer module, a uart example to show the uart etc.
For almost every peripheral an example program exists.
The USB block has a lot of nice examples: a virtual serial port, a mass storage example, and at least 2 HID examples (joystick and mouse).



Not enough examples, and from having a quick look nothing new in years now:)



Quote: Rob65


Let me just quote you from another thread you opened:


You won't make too many friends this way...
So I think I'm done trying to answer this for now :mad:


Rob



Guess that would depend on what you know, such as aliens took over the planet and then low and behold it was never them that was in charge but the shadows:)

This is so basic, and I think your just lazy, but I think I am getting more of a idea now.

I need to make changes to the usbdesc.c file adding in AUDIO_TERMINAL_MICROPHONE, not sure if it should just go in place of AUDIO_TERMINAL_USB_STREAMING.

And then I need to edit the ADCUSER.C and try and hack in
AUDIO_TERMINAL_MICROPHONE

Will I ever do it, I don't know and I don't care, it took so long to even figure this out, that I am starting to lose interest.
0 Kudos
Reply

1,597 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Fri Aug 05 06:19:33 MST 2011

Quote: LPCNX123
This is so basic and simple for you, I really can't understand why this has not been done.



The whole idea of the examples is to give you a head start on writing your own programs. So there is a timer example to show you how to use the timer module, a uart example to show the uart etc.
For almost every peripheral an example program exists.
The USB block has a lot of nice examples: a virtual serial port, a mass storage example, and at least 2 HID examples (joystick and mouse).

Let me just quote you from another thread you opened:


Quote: LPCNX123

..It's just a pointless discussion to have with any of you.


You won't make too many friends this way...
So I think I'm done trying to answer this for now :mad:


Rob
0 Kudos
Reply

1,597 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LPCNX123 on Fri Aug 05 02:33:53 MST 2011
Let's face facts, you have done this on purpose, so that I have to do this myself. This is so basic and simple for you, I really can't understand why this has not been done. Which pretty much sum's it up how I started these verses.   But yes the same code bundled for how many years now. ooohhh goodday.:)
0 Kudos
Reply

1,597 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Thu Aug 04 10:46:16 MST 2011

Quote: NXP_Europe
Since we're all also just humans as you are, it is not that impossible as you impose :rolleyes:
Kind regards,



Having an example to create your examples from would make you monkeys.
Good to read you are also (just) human :D


Quote: LPCNX123
I could be way off in saying  this, but how do you expect anybody to know how to do this with no  examples, your almost asking somebody to do the impossible.



It indeed is not inpossible at all. If you want to create your own USB device then start reading the USB specs, the user manual and use your own programming skills to fill in the rest.
If you then still have specific questions about some USB issues or questions about a lpc1xxx peripheral (or interaction between peripherals like NVIC or DMA with a peripheral), try to isolate the problem and see if other users on this forum are able to help you.

I know this works: I created a custom USB device with the help of the USB specs, the USB examples and some help from forum members.

Regards,

Rob
0 Kudos
Reply

1,597 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Thu Aug 04 06:13:18 MST 2011
Hi,
No unfortunately we don't have and example on USB audio MIC in. We unfortunately don't have the time to create examples for each and every possible function of our broad range of MCUs. :)

And at the end we also don't have any examples as well for creating examples for you, so we have to develop them from scratch. Since we're all also just humans as you are, it is not that impossible as you impose :rolleyes:
Kind regards,
0 Kudos
Reply