[LPC1347]: first implementation of USB device (not tested)

pull/17/head
samuel.mokrani@arm.com 2013-07-17 15:23:54 +03:00 committed by Bogdan Marinescu
parent 358e84edf3
commit 4bbd13b957
14 changed files with 82 additions and 74 deletions

View File

@ -400,8 +400,8 @@ uint8_t * USBAudio::configurationDesc() {
MSB(TERMINAL_USB_STREAMING), // wTerminalType
0x00, // bAssocTerminal
channel_nb_in, // bNrChannels
LSB(channel_config_in), // wChannelConfig
MSB(channel_config_in), // wChannelConfig
(uint8_t)(LSB(channel_config_in)), // wChannelConfig
(uint8_t)(MSB(channel_config_in)), // wChannelConfig
0x00, // iChannelNames
0x00, // iTerminal
@ -438,8 +438,8 @@ uint8_t * USBAudio::configurationDesc() {
MSB(TERMINAL_MICROPHONE), // wTerminalType
0x00, // bAssocTerminal
channel_nb_out, // bNrChannels
LSB(channel_config_out), // wChannelConfig
MSB(channel_config_out), // wChannelConfig
(uint8_t)(LSB(channel_config_out)), // wChannelConfig
(uint8_t)(MSB(channel_config_out)), // wChannelConfig
0x00, // iChannelNames
0x00, // iTerminal
@ -499,17 +499,17 @@ uint8_t * USBAudio::configurationDesc() {
0x02, // bSubFrameSize
16, // bBitResolution
0x01, // bSamFreqType
LSB(FREQ_IN), // tSamFreq
(FREQ_IN >> 8) & 0xff, // tSamFreq
(FREQ_IN >> 16) & 0xff, // tSamFreq
(uint8_t)(LSB(FREQ_IN)), // tSamFreq
(uint8_t)((FREQ_IN >> 8) & 0xff), // tSamFreq
(uint8_t)((FREQ_IN >> 16) & 0xff), // tSamFreq
// Endpoint - Standard Descriptor
ENDPOINT_DESCRIPTOR_LENGTH + 2, // bLength
ENDPOINT_DESCRIPTOR, // bDescriptorType
PHY_TO_DESC(EPISO_OUT), // bEndpointAddress
E_ISOCHRONOUS, // bmAttributes
LSB(PACKET_SIZE_ISO_IN), // wMaxPacketSize
MSB(PACKET_SIZE_ISO_IN), // wMaxPacketSize
(uint8_t)(LSB(PACKET_SIZE_ISO_IN)), // wMaxPacketSize
(uint8_t)(MSB(PACKET_SIZE_ISO_IN)), // wMaxPacketSize
0x01, // bInterval
0x00, // bRefresh
0x00, // bSynchAddress
@ -569,17 +569,17 @@ uint8_t * USBAudio::configurationDesc() {
0x02, // bSubFrameSize
0x10, // bBitResolution
0x01, // bSamFreqType
LSB(FREQ_OUT), // tSamFreq
(FREQ_OUT >> 8) & 0xff, // tSamFreq
(FREQ_OUT >> 16) & 0xff, // tSamFreq
(uint8_t)(LSB(FREQ_OUT)), // tSamFreq
(uint8_t)((FREQ_OUT >> 8) & 0xff), // tSamFreq
(uint8_t)((FREQ_OUT >> 16) & 0xff), // tSamFreq
// Endpoint - Standard Descriptor
ENDPOINT_DESCRIPTOR_LENGTH + 2, // bLength
ENDPOINT_DESCRIPTOR, // bDescriptorType
PHY_TO_DESC(EPISO_IN), // bEndpointAddress
E_ISOCHRONOUS, // bmAttributes
LSB(PACKET_SIZE_ISO_OUT), // wMaxPacketSize
MSB(PACKET_SIZE_ISO_OUT), // wMaxPacketSize
(uint8_t)(LSB(PACKET_SIZE_ISO_OUT)), // wMaxPacketSize
(uint8_t)(MSB(PACKET_SIZE_ISO_OUT)), // wMaxPacketSize
0x01, // bInterval
0x00, // bRefresh
0x00, // bSynchAddress

View File

@ -758,7 +758,7 @@ uint8_t * USBDevice::findDescriptor(uint8_t descriptorType)
if (wTotalLength <= (CONFIGURATION_DESCRIPTOR_LENGTH+2))
/* +2 is for bLength and bDescriptorType of next descriptor */
{
return false;
return NULL;
}
/* Start at first descriptor after the configuration descriptor */
@ -908,12 +908,12 @@ uint8_t * USBDevice::deviceDesc() {
0x00, /* bDeviceSubClass */
0x00, /* bDeviceprotocol */
MAX_PACKET_SIZE_EP0, /* bMaxPacketSize0 */
LSB(VENDOR_ID), /* idVendor (LSB) */
MSB(VENDOR_ID), /* idVendor (MSB) */
LSB(PRODUCT_ID), /* idProduct (LSB) */
MSB(PRODUCT_ID), /* idProduct (MSB) */
LSB(PRODUCT_RELEASE), /* bcdDevice (LSB) */
MSB(PRODUCT_RELEASE), /* bcdDevice (MSB) */
(uint8_t)(LSB(VENDOR_ID)), /* idVendor (LSB) */
(uint8_t)(MSB(VENDOR_ID)), /* idVendor (MSB) */
(uint8_t)(LSB(PRODUCT_ID)), /* idProduct (LSB) */
(uint8_t)(MSB(PRODUCT_ID)), /* idProduct (MSB) */
(uint8_t)(LSB(PRODUCT_RELEASE)), /* bcdDevice (LSB) */
(uint8_t)(MSB(PRODUCT_RELEASE)), /* bcdDevice (MSB) */
STRING_OFFSET_IMANUFACTURER, /* iManufacturer */
STRING_OFFSET_IPRODUCT, /* iProduct */
STRING_OFFSET_ISERIAL, /* iSerialNumber */

View File

@ -39,7 +39,7 @@ typedef enum {
/* Include configuration for specific target */
#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088)
#include "USBEndpoints_LPC17_LPC23.h"
#elif defined(TARGET_LPC11U24)
#elif defined(TARGET_LPC11U24) || defined(TARGET_LPC1347)
#include "USBEndpoints_LPC11U.h"
#elif defined(TARGET_KL25Z)
#include "USBEndpoints_KL25Z.h"

View File

@ -21,10 +21,11 @@
#include "mbed.h"
#include "USBEndpoints.h"
#include "toolchain.h"
#ifdef __GNUC__
#define __packed __attribute__ ((__packed__))
#endif
//#ifdef __GNUC__
//#define __packed __attribute__ ((__packed__))
//#endif
class USBHAL {
public:

View File

@ -16,7 +16,13 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef TARGET_LPC11U24
#if defined(TARGET_LPC11U24) || defined(TARGET_LPC1347)
#if defined(TARGET_LPC1347)
#define USB_IRQ USB_IRQ_IRQn
#elif defined(TARGET_LPC11U24)
#define USB_IRQ USB_IRQn
#endif
#include "USBHAL.h"
@ -81,22 +87,22 @@ static volatile int epComplete = 0;
// One entry for a double-buffered logical endpoint in the endpoint
// command/status list. Endpoint 0 is single buffered, out[1] is used
// for the SETUP packet and in[1] is not used
typedef __packed struct {
typedef struct {
uint32_t out[2];
uint32_t in[2];
} EP_COMMAND_STATUS;
} PACKED EP_COMMAND_STATUS;
typedef __packed struct {
typedef struct {
uint8_t out[MAX_PACKET_SIZE_EP0];
uint8_t in[MAX_PACKET_SIZE_EP0];
uint8_t setup[SETUP_PACKET_SIZE];
} CONTROL_TRANSFER;
} PACKED CONTROL_TRANSFER;
typedef __packed struct {
typedef struct {
uint32_t maxPacket;
uint32_t buffer[2];
uint32_t options;
} EP_STATE;
} PACKED EP_STATE;
static volatile EP_STATE endpointState[NUMBER_OF_PHYSICAL_ENDPOINTS];
@ -127,7 +133,7 @@ void USBMemCopy(uint8_t *dst, uint8_t *src, uint32_t size) {
USBHAL::USBHAL(void) {
NVIC_DisableIRQ(USB_IRQn);
NVIC_DisableIRQ(USB_IRQ);
// fill in callback array
epCallback[0] = &USBHAL::EP1_OUT_callback;
@ -184,24 +190,24 @@ USBHAL::USBHAL(void) {
instance = this;
//attach IRQ handler and enable interrupts
NVIC_SetVector(USB_IRQn, (uint32_t)&_usbisr);
NVIC_SetVector(USB_IRQ, (uint32_t)&_usbisr);
}
USBHAL::~USBHAL(void) {
// Ensure device disconnected (DCON not set)
LPC_USB->DEVCMDSTAT = 0;
// Disable USB interrupts
NVIC_DisableIRQ(USB_IRQn);
NVIC_DisableIRQ(USB_IRQ);
}
void USBHAL::connect(void) {
NVIC_EnableIRQ(USB_IRQn);
NVIC_EnableIRQ(USB_IRQ);
devCmdStat |= DCON;
LPC_USB->DEVCMDSTAT = devCmdStat;
}
void USBHAL::disconnect(void) {
NVIC_DisableIRQ(USB_IRQn);
NVIC_DisableIRQ(USB_IRQ);
devCmdStat &= ~DCON;
LPC_USB->DEVCMDSTAT = devCmdStat;
}

View File

@ -250,8 +250,8 @@ uint8_t * USBHID::configurationDesc() {
0x00, // bCountryCode
0x01, // bNumDescriptors
REPORT_DESCRIPTOR, // bDescriptorType
LSB(this->reportDescLength()), // wDescriptorLength (LSB)
MSB(this->reportDescLength()), // wDescriptorLength (MSB)
(uint8_t)(LSB(this->reportDescLength())), // wDescriptorLength (LSB)
(uint8_t)(MSB(this->reportDescLength())), // wDescriptorLength (MSB)
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
ENDPOINT_DESCRIPTOR, // bDescriptorType

View File

@ -530,8 +530,8 @@ uint8_t * USBKeyboard::configurationDesc() {
0x00, // bCountryCode
0x01, // bNumDescriptors
REPORT_DESCRIPTOR, // bDescriptorType
LSB(reportDescLength()), // wDescriptorLength (LSB)
MSB(reportDescLength()), // wDescriptorLength (MSB)
(uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB)
(uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB)
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
ENDPOINT_DESCRIPTOR, // bDescriptorType

View File

@ -222,8 +222,8 @@ uint8_t * USBMouse::configurationDesc() {
0x00, // bCountryCode
0x01, // bNumDescriptors
REPORT_DESCRIPTOR, // bDescriptorType
LSB(reportDescLength()), // wDescriptorLength (LSB)
MSB(reportDescLength()), // wDescriptorLength (MSB)
(uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB)
(uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB)
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
ENDPOINT_DESCRIPTOR, // bDescriptorType

View File

@ -45,7 +45,8 @@ public:
MIDIMessage() {}
MIDIMessage(uint8_t *buf) {
*((uint32_t *)data) = *((uint32_t *)buf);
for (int i = 0; i < 4; i++)
data[i] = buf[i];
}
// create messages
@ -245,6 +246,6 @@ public:
}
uint8_t data[4];
};
};
#endif

View File

@ -41,7 +41,7 @@ bool USBMIDI::EP2_OUT_callback() {
readEP(EPBULK_OUT, buf, &len, 64);
if (midi_evt != NULL) {
for (int i=0; i<len; i+=4) {
for (uint32_t i=0; i<len; i+=4) {
midi_evt(MIDIMessage(buf+i));
}
}

View File

@ -192,16 +192,16 @@ bool USBMSD::EP2_IN_callback() {
sendCSW();
break;
// an error has occured
case ERROR:
stallEndpoint(EPBULK_IN);
sendCSW();
break;
// the host has received the CSW -> we wait a CBW
// the host has received the CSW -> we wait a CBW
case WAIT_CSW:
stage = READ_CBW;
break;
// an error has occured
default:
stallEndpoint(EPBULK_IN);
sendCSW();
break;
}
return true;
}
@ -284,15 +284,15 @@ bool USBMSD::inquiryRequest (void) {
bool USBMSD::readFormatCapacity() {
uint8_t capacity[] = { 0x00, 0x00, 0x00, 0x08,
(BlockCount >> 24) & 0xff,
(BlockCount >> 16) & 0xff,
(BlockCount >> 8) & 0xff,
(BlockCount >> 0) & 0xff,
(uint8_t)((BlockCount >> 24) & 0xff),
(uint8_t)((BlockCount >> 16) & 0xff),
(uint8_t)((BlockCount >> 8) & 0xff),
(uint8_t)((BlockCount >> 0) & 0xff),
0x02,
(BlockSize >> 16) & 0xff,
(BlockSize >> 8) & 0xff,
(BlockSize >> 0) & 0xff,
(uint8_t)((BlockSize >> 16) & 0xff),
(uint8_t)((BlockSize >> 8) & 0xff),
(uint8_t)((BlockSize >> 0) & 0xff),
};
if (!write(capacity, sizeof(capacity))) {
return false;
@ -303,15 +303,15 @@ bool USBMSD::readFormatCapacity() {
bool USBMSD::readCapacity (void) {
uint8_t capacity[] = {
((BlockCount - 1) >> 24) & 0xff,
((BlockCount - 1) >> 16) & 0xff,
((BlockCount - 1) >> 8) & 0xff,
((BlockCount - 1) >> 0) & 0xff,
(uint8_t)(((BlockCount - 1) >> 24) & 0xff),
(uint8_t)(((BlockCount - 1) >> 16) & 0xff),
(uint8_t)(((BlockCount - 1) >> 8) & 0xff),
(uint8_t)(((BlockCount - 1) >> 0) & 0xff),
(BlockSize >> 24) & 0xff,
(BlockSize >> 16) & 0xff,
(BlockSize >> 8) & 0xff,
(BlockSize >> 0) & 0xff,
(uint8_t)((BlockSize >> 24) & 0xff),
(uint8_t)((BlockSize >> 16) & 0xff),
(uint8_t)((BlockSize >> 8) & 0xff),
(uint8_t)((BlockSize >> 0) & 0xff),
};
if (!write(capacity, sizeof(capacity))) {
return false;

View File

@ -184,7 +184,7 @@ private:
uint8_t LUN;
uint8_t CBLength;
uint8_t CB[16];
} __packed CBW;
} PACKED CBW;
// Bulk-only CSW
typedef struct {
@ -192,7 +192,7 @@ private:
uint32_t Tag;
uint32_t DataResidue;
uint8_t Status;
} __packed CSW;
} PACKED CSW;
//state of the bulk-only state machine
Stage stage;

View File

@ -116,8 +116,8 @@ uint8_t * USBCDC::deviceDesc() {
0, // bDeviceSubClass
0, // bDeviceProtocol
MAX_PACKET_SIZE_EP0, // bMaxPacketSize0
LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor
LSB(PRODUCT_ID), MSB(PRODUCT_ID),// idProduct
(uint8_t)(LSB(VENDOR_ID)), (uint8_t)(MSB(VENDOR_ID)), // idVendor
(uint8_t)(LSB(PRODUCT_ID)), (uint8_t)(MSB(PRODUCT_ID)),// idProduct
0x00, 0x01, // bcdDevice
1, // iManufacturer
2, // iProduct

View File

@ -27,7 +27,7 @@ int USBSerial::_putc(int c) {
}
int USBSerial::_getc() {
uint8_t c;
uint8_t c = 0;
while (buf.isEmpty());
buf.dequeue(&c);
return c;
@ -52,7 +52,7 @@ bool USBSerial::EP2_OUT_callback() {
//we read the packet received and put it on the circular buffer
readEP(c, &size);
for (int i = 0; i < size; i++) {
for (uint32_t i = 0; i < size; i++) {
buf.queue(c[i]);
}