You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
#include "main.h"
|
|
#include "spi.h"
|
|
#include "spi_proto.h"
|
|
#include "usb.h"
|
|
|
|
usbMsgLen_t usbFunctionSetup(uchar data[8]) {
|
|
usbRequest_t *rq = (void *)data;
|
|
static uchar dataBuffer[4];
|
|
|
|
if(rq->bRequest == 100) {
|
|
dataBuffer[0] = (thermoData [0] & 0xff00)>>8;
|
|
dataBuffer[1] = thermoData [0] & 0x00ff;
|
|
dataBuffer[2] = (thermoData [1] & 0xff00)>>8;
|
|
dataBuffer[3] = thermoData [1] & 0x00ff;
|
|
usbMsgPtr = dataBuffer;
|
|
return 4;
|
|
} else if(rq->bRequest == 101) {
|
|
dataBuffer[0] = (thermoData [2] & 0xff00)>>8;
|
|
dataBuffer[1] = thermoData [2] & 0x00ff;
|
|
dataBuffer[2] = (thermoData [3] & 0xff00)>>8;
|
|
dataBuffer[3] = thermoData [3] & 0x00ff;
|
|
usbMsgPtr = dataBuffer;
|
|
return 4;
|
|
} else {
|
|
uint8_t opcode = (uint8_t) ((rq->bRequest & 0xff00)>>8);
|
|
uint8_t addr = (uint8_t) rq->wValue.bytes[0];
|
|
uint8_t valH = (uint8_t) rq->wIndex.bytes[0];
|
|
uint8_t valL = (uint8_t) rq->wIndex.bytes[1];
|
|
|
|
uint8_t send[] = {opcode, addr, valH, valL};
|
|
uint8_t recv[2];
|
|
spi_mst_write(4, send);
|
|
if(!spi_proto_needswrite(opcode)) spi_mst_read(2, recv);
|
|
|
|
dataBuffer[0] = recv[0];
|
|
dataBuffer[1] = recv[1];
|
|
dataBuffer[2] = 0x0000;
|
|
dataBuffer[3] = 0x0000;
|
|
usbMsgPtr = dataBuffer;
|
|
return 4;
|
|
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|