updates
This commit is contained in:
@@ -407,6 +407,18 @@ extern void PORTS_0_enter_DefaultMode_from_RESET(void) {
|
||||
extern void PORTS_1_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[P1 - Port 1 Pin Latch]
|
||||
/***********************************************************************
|
||||
- P1.0 is high. Set P1.0 to drive or float high
|
||||
- P1.1 is high. Set P1.1 to drive or float high
|
||||
- P1.2 is low. Set P1.2 to drive low
|
||||
- P1.3 is high. Set P1.3 to drive or float high
|
||||
- P1.4 is high. Set P1.4 to drive or float high
|
||||
- P1.5 is high. Set P1.5 to drive or float high
|
||||
- P1.6 is high. Set P1.6 to drive or float high
|
||||
- P1.7 is high. Set P1.7 to drive or float high
|
||||
***********************************************************************/
|
||||
P1 = P1_B0__HIGH | P1_B1__HIGH | P1_B2__LOW | P1_B3__HIGH | P1_B4__HIGH
|
||||
| P1_B5__HIGH | P1_B6__HIGH | P1_B7__HIGH;
|
||||
// [P1 - Port 1 Pin Latch]$
|
||||
|
||||
// $[P1MDOUT - Port 1 Output Mode]
|
||||
|
@@ -147,10 +147,14 @@ uint16_t USBD_XferCompleteCb(uint8_t epAddr, USB_Status_TypeDef status,
|
||||
UNUSED(xferred);
|
||||
UNUSED(remaining);
|
||||
|
||||
if (epAddr == EP1OUT)
|
||||
if (epAddr == EP2OUT)
|
||||
{
|
||||
usb_transfer_complete();
|
||||
}
|
||||
else if (epAddr == EP3IN)
|
||||
{
|
||||
usb_writeback_complete();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -104,19 +104,19 @@ SI_SEGMENT_VARIABLE(configDesc[],
|
||||
sizeof( ReportDescriptor0 ),// wDescriptorLength(LSB)
|
||||
sizeof( ReportDescriptor0 )>>8,// wDescriptorLength(MSB)
|
||||
|
||||
//Endpoint 1 IN Descriptor
|
||||
//Endpoint 2 IN Descriptor
|
||||
USB_ENDPOINT_DESCSIZE,// bLength
|
||||
USB_ENDPOINT_DESCRIPTOR,// bDescriptorType
|
||||
0x81,// bEndpointAddress
|
||||
0x83,// bEndpointAddress
|
||||
USB_EPTYPE_INTR,// bAttrib
|
||||
HID_PACKET_SIZE,// wMaxPacketSize (LSB)
|
||||
0x00,// wMaxPacketSize (MSB)
|
||||
5,// bInterval
|
||||
|
||||
//Endpoint 1 OUT Descriptor
|
||||
//Endpoint 3 OUT Descriptor
|
||||
USB_ENDPOINT_DESCSIZE,// bLength
|
||||
USB_ENDPOINT_DESCRIPTOR,// bDescriptorType
|
||||
0x01,// bEndpointAddress
|
||||
0x02,// bEndpointAddress
|
||||
USB_EPTYPE_INTR,// bAttrib
|
||||
HID_PACKET_SIZE,// wMaxPacketSize (LSB)
|
||||
0x00,// wMaxPacketSize (MSB)
|
||||
|
107
efm8/src/main.c
107
efm8/src/main.c
@@ -4,7 +4,10 @@
|
||||
#include "uart_1.h"
|
||||
#include "printing.h"
|
||||
|
||||
#define BUFFER_SIZE 13
|
||||
#define BUFFER_SIZE 12
|
||||
|
||||
#define SIGNAL_WRITE_BSY() P1 = P1 & (~(1<<2)) // Set P1 low
|
||||
#define SIGNAL_WRITE_RDY() P1 = P1 | (1<<2) // Set P1 high
|
||||
|
||||
data uint8_t write_ptr = 0;
|
||||
data uint8_t read_ptr = 0;
|
||||
@@ -12,20 +15,28 @@ data uint8_t i_ptr = 0;
|
||||
data uint8_t count = 0;
|
||||
data uint8_t writebackbuf_count = 0;
|
||||
|
||||
uint8_t hidmsgbuf[64][BUFFER_SIZE];
|
||||
uint8_t hidmsgbuf[64*BUFFER_SIZE];
|
||||
//uint8_t debugR[64];
|
||||
//uint8_t debugRi;
|
||||
//uint8_t debugW[64];
|
||||
//uint8_t debugW2[64];
|
||||
//uint8_t debugWi;
|
||||
data uint8_t writebackbuf[64];
|
||||
|
||||
void usb_transfer_complete()
|
||||
{
|
||||
count++;
|
||||
// memmove(debugR, hidmsgbuf + write_ptr*64, 64);
|
||||
// debugRi = write_ptr;
|
||||
write_ptr++;
|
||||
|
||||
if (write_ptr == BUFFER_SIZE)
|
||||
{
|
||||
write_ptr = 0;
|
||||
}
|
||||
if (count == 1 && i_ptr == 0)
|
||||
{
|
||||
SPI0DAT = hidmsgbuf[read_ptr][i_ptr++];
|
||||
SPI0DAT = (hidmsgbuf+read_ptr*64)[i_ptr++];
|
||||
}
|
||||
|
||||
|
||||
@@ -34,27 +45,48 @@ void usb_transfer_complete()
|
||||
|
||||
}
|
||||
|
||||
uint16_t USB_TX_COUNT = 0;
|
||||
|
||||
void usb_writeback_complete()
|
||||
{
|
||||
if (USB_TX_COUNT >= 511/2)
|
||||
{
|
||||
USB_TX_COUNT -= 64;
|
||||
if (USB_TX_COUNT < 511)
|
||||
{
|
||||
SIGNAL_WRITE_RDY();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USB_TX_COUNT -= 64;
|
||||
}
|
||||
}
|
||||
|
||||
void spi_transfer_complete()
|
||||
{
|
||||
count--;
|
||||
i_ptr = 0;
|
||||
SPI0FCN0 |= (1<<2); // Flush rx fifo buffer
|
||||
if (count)
|
||||
{
|
||||
SPI0DAT = hidmsgbuf[read_ptr][i_ptr++];
|
||||
}
|
||||
|
||||
// debugWi = read_ptr;
|
||||
|
||||
read_ptr++;
|
||||
|
||||
if (read_ptr == BUFFER_SIZE)
|
||||
{
|
||||
read_ptr = 0;
|
||||
}
|
||||
|
||||
if (count)
|
||||
{
|
||||
SPI0DAT = (hidmsgbuf+read_ptr*64)[i_ptr++];
|
||||
}
|
||||
// cprints("sent hid msg\r\n");
|
||||
}
|
||||
|
||||
data int overrun = 0;
|
||||
SI_INTERRUPT (SPI0_ISR, SPI0_IRQn)
|
||||
{
|
||||
data uint8_t byt;
|
||||
if (SPI0CN0_WCOL == 1)
|
||||
{
|
||||
// Write collision occurred
|
||||
@@ -65,14 +97,22 @@ SI_INTERRUPT (SPI0_ISR, SPI0_IRQn)
|
||||
{
|
||||
// Receive overrun occurred
|
||||
SPI0CN0_RXOVRN = 0;
|
||||
overrun = 1;
|
||||
// cprints("SPI0CN0_RXOVRN\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (EFM32_RW_PIN)
|
||||
{
|
||||
if (writebackbuf_count < 64) writebackbuf[writebackbuf_count++] = SPI0DAT;
|
||||
else cprints("overflow\r\n");
|
||||
if (writebackbuf_count < 64)
|
||||
{
|
||||
writebackbuf[writebackbuf_count++] = SPI0DAT;
|
||||
SIGNAL_WRITE_BSY();
|
||||
}
|
||||
else
|
||||
{
|
||||
cprints("overflow\r\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -80,8 +120,12 @@ SI_INTERRUPT (SPI0_ISR, SPI0_IRQn)
|
||||
{
|
||||
if (i_ptr < 64)
|
||||
{
|
||||
SPI0DAT = hidmsgbuf[read_ptr][i_ptr++];
|
||||
|
||||
// debugW[i_ptr] = (hidmsgbuf+read_ptr*64)[i_ptr];
|
||||
// debugW2[i_ptr] = read_ptr;
|
||||
// if (i_ptr == 63)
|
||||
// debugW2[i_ptr] = 0xaa;
|
||||
SPI0DAT = (hidmsgbuf+read_ptr*64)[i_ptr++];
|
||||
byt = SPI0DAT;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -97,7 +141,8 @@ SI_INTERRUPT (SPI0_ISR, SPI0_IRQn)
|
||||
void usb_write()
|
||||
{
|
||||
data uint8_t errors = 0;
|
||||
while (USB_STATUS_OK != (USBD_Write(EP1IN, writebackbuf, 64, false)))
|
||||
USB_TX_COUNT += 64;
|
||||
while (USB_STATUS_OK != (USBD_Write(EP3IN, writebackbuf, 64, true)))
|
||||
{
|
||||
delay(2);
|
||||
if (errors++ > 30)
|
||||
@@ -131,6 +176,8 @@ int main(void) {
|
||||
IE_EA = 1;
|
||||
IE_ESPI0 = 1;
|
||||
|
||||
SIGNAL_WRITE_RDY();
|
||||
|
||||
cprints("hello,world\r\n");
|
||||
|
||||
reset = RSTSRC;
|
||||
@@ -138,21 +185,30 @@ int main(void) {
|
||||
|
||||
while (1) {
|
||||
// delay(1500);
|
||||
if (overrun)
|
||||
{
|
||||
cprints("O\r\n");
|
||||
overrun = 0;
|
||||
}
|
||||
if (millis() - t1 > 1500)
|
||||
{
|
||||
P1_B5 = k++&1;
|
||||
// if (k&1)
|
||||
// SIGNAL_WRITE_RDY();
|
||||
// else
|
||||
// SIGNAL_WRITE_BSY();
|
||||
t1 = millis();
|
||||
}
|
||||
if (!USBD_EpIsBusy(EP1OUT) && !USBD_EpIsBusy(EP1IN))
|
||||
if (!USBD_EpIsBusy(EP2OUT) && !USBD_EpIsBusy(EP3IN) && lastcount==count)
|
||||
{
|
||||
// cprintd("sched read to ",1,reset);
|
||||
// cprintd("sched read to ",1,(int)(hidmsgbuf + write_ptr*64));
|
||||
if (count == BUFFER_SIZE)
|
||||
{
|
||||
cprints("Warning, USB buffer full\r\n");
|
||||
// cprints("Warning, USB buffer full\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_Read(EP1OUT, hidmsgbuf[write_ptr], 64, true);
|
||||
USBD_Read(EP2OUT, hidmsgbuf + write_ptr*64, 64, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,26 +216,31 @@ int main(void) {
|
||||
{
|
||||
// cprints("<< ");
|
||||
// dump_hex(writebackbuf,64);
|
||||
writebackbuf_count = 0;
|
||||
// while (USBD_EpIsBusy(EP1IN))
|
||||
// ;
|
||||
usb_write();
|
||||
writebackbuf_count = 0;
|
||||
if (USB_TX_COUNT < 511/2)
|
||||
{
|
||||
SIGNAL_WRITE_RDY();
|
||||
}
|
||||
}
|
||||
|
||||
if (lastcount != count)
|
||||
{
|
||||
if (count > lastcount)
|
||||
{
|
||||
// cprints(">> ");
|
||||
// dump_hex(writebackbuf,64);
|
||||
// cputd(debugRi); cprints(">> ");
|
||||
// dump_hex(debugR,64);
|
||||
|
||||
MSG_RDY_INT_PIN = 0;
|
||||
MSG_RDY_INT_PIN = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// cprints("efm32 read hid msg\r\n>> ");
|
||||
// dump_hex(debug,64);
|
||||
// cputd(debugWi); cprints(">>>> ");
|
||||
// dump_hex(debugW,64);
|
||||
// dump_hex(debugW2,64);
|
||||
}
|
||||
lastcount = count;
|
||||
}
|
||||
|
@@ -42,6 +42,7 @@ void dump_hex(uint8_t* hex, uint8_t len)
|
||||
putf(lut[b]);
|
||||
b = ((*hex) & 0x0f);
|
||||
putf(lut[b]);
|
||||
putf(' ');
|
||||
hex++;
|
||||
}
|
||||
cprints("\r\n");
|
||||
|
Reference in New Issue
Block a user