Skip to content

Commit

Permalink
added USB 2.0 Descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
cozycactus committed Sep 5, 2020
1 parent ce9c72b commit 1f07eb4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
8 changes: 8 additions & 0 deletions bsp/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ void Fx3UsbUnstallEp0(void)
Fx3SetReg32(FX3_PROT_CS, FX3_PROT_CS_SETUP_CLR_BUSY);
}

void Fx3UsbHSUnstallEp0(void)
{
Fx3ClearReg32(FX3_DEV_EPI_CS+0,FX3_DEV_EPI_CS_STALL);
Fx3ClearReg32(FX3_DEV_EPO_CS+0,FX3_DEV_EPO_CS_STALL);
Fx3UtilDelayUs(1);
Fx3SetReg32(FX3_DEV_CS, FX3_DEV_CS_SETUP_CLR_BUSY);
}

void Fx3UsbDmaDataOut(uint8_t ep, volatile void *buffer, uint16_t length)
{
uint16_t d = Fx3DmaAllocateDescriptor();
Expand Down
1 change: 1 addition & 0 deletions bsp/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ extern void Fx3UsbInit(const struct Fx3UsbCallbacks *callbacks);
extern void Fx3UsbConnect(void);
extern void Fx3UsbStallEp0(void);
extern void Fx3UsbUnstallEp0(void);
void Fx3UsbHSUnstallEp0(void);
extern void Fx3UsbDmaDataOut(uint8_t ep, volatile void *buffer,
uint16_t length);
extern void Fx3UsbDmaDataIn(uint8_t ep, const volatile void *buffer,
Expand Down
35 changes: 32 additions & 3 deletions descriptors.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
#include <stdint.h>
#include <stddef.h>

#include <bsp/uart.h>
#include <bsp/usb.h>

#include "descriptors.h"

static const struct __attribute__((packed)) {
uint8_t length, descriptor_type;
uint16_t usb_version;
uint8_t device_class, sub_class, protocol, max_packet_size;
uint16_t vendor, product, dev_version;
uint8_t manuf_index, product_index, serial_index, num_configurations;
} highspeed_device_descriptor = {
.length = sizeof(highspeed_device_descriptor),
.descriptor_type = FX3_USB_DESCRIPTOR_DEVICE,
.usb_version = 0x0200,
.device_class = 0xff,
.sub_class = 0xff,
.protocol = 0xff,
.max_packet_size = 64 /* 2^9 */,
.vendor = 0x04b4,
.product = 0x00f3,
.dev_version = 0x0001,
.manuf_index = 1,
.product_index = 2,
.serial_index = 3,
.num_configurations = 1
};

static const struct __attribute__((packed)) {
uint8_t length, descriptor_type;
uint16_t usb_version;
Expand Down Expand Up @@ -168,7 +191,13 @@ const void *GetDescriptor(uint8_t descriptor_type, uint8_t descriptor_no)

const void *GetDescriptorHS(uint8_t descriptor_type, uint8_t descriptor_no)
{
(void)(descriptor_type);
(void)(descriptor_no);
switch(descriptor_type) {
case FX3_USB_DESCRIPTOR_DEVICE:
if (descriptor_no == 0)
//Fx3UartTxString("\nim here!\n");
return &highspeed_device_descriptor;
break;
}
//(void)(descriptor_no);
return NULL;
}
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static void SetupDataHS(uint8_t request_type, uint8_t request, uint16_t value,
*(const uint16_t *)(descr+2) : *descr);
if (len < length)
length = len;
Fx3UsbUnstallEp0();
Fx3UsbHSUnstallEp0();
Fx3UsbDmaDataIn(0, descr, length);
return;

Expand Down

0 comments on commit 1f07eb4

Please sign in to comment.