fix couple issues with usb firmware
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <stdio.h>
|
||||
#include "printing.h"
|
||||
#include "descriptors.h"
|
||||
#include "app.h"
|
||||
|
||||
#define UNUSED(expr) do { (void)(expr); } while (0)
|
||||
|
||||
@@ -63,22 +64,19 @@ USB_Status_TypeDef USBD_SetupCmdCb(
|
||||
SI_VARIABLE_SEGMENT_POINTER(setup, USB_Setup_TypeDef, MEM_MODEL_SEG)) {
|
||||
|
||||
USB_Status_TypeDef retVal = USB_STATUS_REQ_UNHANDLED;
|
||||
// USB_Status_TypeDef retVal = USB_STATUS_OK;
|
||||
// cprints("USBD_SetupCmdCb\r\n");
|
||||
|
||||
|
||||
if ((setup->bmRequestType.Type == USB_SETUP_TYPE_STANDARD)
|
||||
&& (setup->bmRequestType.Direction == USB_SETUP_DIR_IN)
|
||||
&& (setup->bmRequestType.Recipient == USB_SETUP_RECIPIENT_INTERFACE)) {
|
||||
// A HID device must extend the standard GET_DESCRIPTOR command
|
||||
// with support for HID descriptors.
|
||||
// cprints("USB_SETUP_TYPE_STANDARD\r\n");
|
||||
|
||||
switch (setup->bRequest) {
|
||||
case GET_DESCRIPTOR:
|
||||
// cprints("GET_DESCRIPTOR\r\n");
|
||||
if (setup->wIndex == 0)
|
||||
{
|
||||
if ((setup->wValue >> 8) == USB_HID_REPORT_DESCRIPTOR) {
|
||||
// cprints("1\r\n");
|
||||
|
||||
USBD_Write(EP0, ReportDescriptor0,
|
||||
EFM8_MIN(sizeof(ReportDescriptor0), setup->wLength),
|
||||
@@ -86,7 +84,7 @@ USB_Status_TypeDef USBD_SetupCmdCb(
|
||||
retVal = USB_STATUS_OK;
|
||||
|
||||
} else if ((setup->wValue >> 8) == USB_HID_DESCRIPTOR) {
|
||||
// cprints("2\r\n");
|
||||
|
||||
USBD_Write(EP0, (&configDesc[18]),
|
||||
EFM8_MIN(USB_HID_DESCSIZE, setup->wLength), false);
|
||||
retVal = USB_STATUS_OK;
|
||||
@@ -100,12 +98,10 @@ USB_Status_TypeDef USBD_SetupCmdCb(
|
||||
&& (setup->bmRequestType.Recipient == USB_SETUP_RECIPIENT_INTERFACE)
|
||||
&& (setup->wIndex == HID_INTERFACE_INDEX))
|
||||
{
|
||||
// cprints("USB_SETUP_TYPE_CLASS\r\n");
|
||||
// Implement the necessary HID class specific commands.
|
||||
switch (setup->bRequest)
|
||||
{
|
||||
case USB_HID_SET_IDLE:
|
||||
// cprints("USB_HID_SET_IDLE\r\n");
|
||||
if (((setup->wValue & 0xFF) == 0) // Report ID
|
||||
&& (setup->wLength == 0)
|
||||
&& (setup->bmRequestType.Direction != USB_SETUP_DIR_IN))
|
||||
@@ -115,7 +111,6 @@ USB_Status_TypeDef USBD_SetupCmdCb(
|
||||
break;
|
||||
|
||||
case USB_HID_GET_IDLE:
|
||||
// cprints("USB_HID_GET_IDLE\r\n");
|
||||
if ((setup->wValue == 0) // Report ID
|
||||
&& (setup->wLength == 1)
|
||||
&& (setup->bmRequestType.Direction == USB_SETUP_DIR_IN))
|
||||
@@ -129,10 +124,6 @@ USB_Status_TypeDef USBD_SetupCmdCb(
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// cprints("nothing\r\n");
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
@@ -147,11 +138,11 @@ uint16_t USBD_XferCompleteCb(uint8_t epAddr, USB_Status_TypeDef status,
|
||||
UNUSED(xferred);
|
||||
UNUSED(remaining);
|
||||
|
||||
if (epAddr == EP2OUT)
|
||||
if (epAddr == INPUT_ENDPOINT)
|
||||
{
|
||||
usb_transfer_complete();
|
||||
}
|
||||
else if (epAddr == EP3IN)
|
||||
else if (epAddr == OUTPUT_ENDPOINT)
|
||||
{
|
||||
usb_writeback_complete();
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include <string.h>
|
||||
#include <efm8_usb.h>
|
||||
#include "descriptors.h"
|
||||
#include "app.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -107,7 +108,7 @@ SI_SEGMENT_VARIABLE(configDesc[],
|
||||
//Endpoint 2 IN Descriptor
|
||||
USB_ENDPOINT_DESCSIZE,// bLength
|
||||
USB_ENDPOINT_DESCRIPTOR,// bDescriptorType
|
||||
0x83,// bEndpointAddress
|
||||
OUTPUT_ENDPOINT_NUM,// bEndpointAddress
|
||||
USB_EPTYPE_INTR,// bAttrib
|
||||
HID_PACKET_SIZE,// wMaxPacketSize (LSB)
|
||||
0x00,// wMaxPacketSize (MSB)
|
||||
@@ -116,7 +117,7 @@ SI_SEGMENT_VARIABLE(configDesc[],
|
||||
//Endpoint 3 OUT Descriptor
|
||||
USB_ENDPOINT_DESCSIZE,// bLength
|
||||
USB_ENDPOINT_DESCRIPTOR,// bDescriptorType
|
||||
0x02,// bEndpointAddress
|
||||
INPUT_ENDPOINT_NUM,// bEndpointAddress
|
||||
USB_EPTYPE_INTR,// bAttrib
|
||||
HID_PACKET_SIZE,// wMaxPacketSize (LSB)
|
||||
0x00,// wMaxPacketSize (MSB)
|
||||
@@ -139,7 +140,7 @@ LANGID_STATIC_CONST_STRING_DESC( langDesc[], LANG_STRING );
|
||||
UTF16LE_PACKED_STATIC_CONST_STRING_DESC( mfrDesc[], MFR_STRING, MFR_SIZE);
|
||||
UTF16LE_PACKED_STATIC_CONST_STRING_DESC( prodDesc[], PROD_STRING, PROD_SIZE);
|
||||
UTF16LE_PACKED_STATIC_CONST_STRING_DESC( serDesc[], SER_STRING, SER_SIZE);
|
||||
UTF16LE_PACKED_STATIC_CONST_STRING_DESC( cfgDesc[], CFG_STRING, CFG_SIZE);
|
||||
//UTF16LE_PACKED_STATIC_CONST_STRING_DESC( cfgDesc[], CFG_STRING, CFG_SIZE);
|
||||
UTF16LE_PACKED_STATIC_CONST_STRING_DESC( int0Desc[], INT0_STRING, INT0_SIZE);
|
||||
|
||||
|
||||
@@ -165,7 +166,7 @@ SI_SEGMENT_VARIABLE(initstruct,
|
||||
deviceDesc, // deviceDescriptor
|
||||
configDesc,// configDescriptor
|
||||
myUsbStringTable_USEnglish,// stringDescriptors
|
||||
sizeof(myUsbStringTable_USEnglish) / sizeof(void *)// numberOfStrings
|
||||
5// numberOfStrings
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -79,7 +79,7 @@ void usb_write()
|
||||
{
|
||||
data uint8_t errors = 0;
|
||||
USB_TX_COUNT += 64;
|
||||
while (USB_STATUS_OK != (USBD_Write(EP3IN, writebackbuf, 64, true)))
|
||||
while (USB_STATUS_OK != (USBD_Write(OUTPUT_ENDPOINT, writebackbuf, 64, true)))
|
||||
{
|
||||
delay(2);
|
||||
if (errors++ > 30)
|
||||
@@ -89,7 +89,7 @@ void usb_write()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern USBD_Device_TypeDef myUsbDevice;
|
||||
|
||||
int main(void) {
|
||||
data uint8_t k;
|
||||
@@ -102,8 +102,10 @@ int main(void) {
|
||||
|
||||
enter_DefaultMode_from_RESET();
|
||||
|
||||
|
||||
eeprom_init();
|
||||
|
||||
|
||||
SCON0_TI = 1;
|
||||
P2_B0 = 1;
|
||||
|
||||
@@ -121,6 +123,7 @@ int main(void) {
|
||||
|
||||
cprints("hello,world\r\n");
|
||||
|
||||
|
||||
reset = RSTSRC;
|
||||
cprintx("reset source: ", 1, reset);
|
||||
if (reset != 0x10)
|
||||
@@ -128,12 +131,6 @@ int main(void) {
|
||||
RSTSRC = (1<<4);
|
||||
}
|
||||
|
||||
// last_efm32_pin = SPI0FCN0;
|
||||
// cprintx("spi fifo0 cntrl: ", 1, last_efm32_pin);
|
||||
//
|
||||
// last_efm32_pin = SPI0FCN1;
|
||||
// cprintx("spi fifo1 cntrl: ", 1, last_efm32_pin);
|
||||
|
||||
MSG_RDY_INT_PIN = 1;
|
||||
SIGNAL_WRITE_BSY();
|
||||
|
||||
@@ -211,7 +208,7 @@ int main(void) {
|
||||
t1 = millis();
|
||||
}
|
||||
// if (!USBD_EpIsBusy(EP2OUT) && !USBD_EpIsBusy(EP3IN) && lastcount==count)
|
||||
if (!USBD_EpIsBusy(EP2OUT) && lastcount==count)
|
||||
if (!USBD_EpIsBusy(INPUT_ENDPOINT) && lastcount==count)
|
||||
{
|
||||
// cprintd("sched read to ",1,(int)(hidmsgbuf + write_ptr*64));
|
||||
if (count == BUFFER_SIZE)
|
||||
@@ -220,7 +217,7 @@ int main(void) {
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_Read(EP2OUT, hidmsgbuf + write_ptr*64, 64, true);
|
||||
USBD_Read(INPUT_ENDPOINT, hidmsgbuf + write_ptr*64, 64, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -63,6 +63,7 @@ static void int2str_reduce_n(char ** snum, uint32_t copy, uint8_t n)
|
||||
do
|
||||
{
|
||||
copy /= n;
|
||||
++*snum;
|
||||
}while(copy);
|
||||
}
|
||||
|
||||
@@ -72,8 +73,10 @@ static char xdata __int2str_buf[9];
|
||||
|
||||
static void int2str_map_n(char ** snum, uint32_t i, uint8_t n)
|
||||
{
|
||||
int c = 0;
|
||||
do
|
||||
{
|
||||
if (*snum <__int2str_buf) break;
|
||||
*--*snum = __digits[i % n];
|
||||
i /= n;
|
||||
}while(i);
|
||||
|
Reference in New Issue
Block a user