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.
49 lines
1.3 KiB
49 lines
1.3 KiB
#include <stdint.h>
|
|
#include "usbdrv/usbdrv.h"
|
|
|
|
#include "main.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];
|
|
|
|
uint16_t send = (valH << 8) | valL;
|
|
uint16_t recv = spi_master_communicate(opcode, addr, send);
|
|
|
|
dataBuffer[0] = (recv >> 8) & 0xff;
|
|
dataBuffer[1] = recv & 0xff;
|
|
dataBuffer[2] = 0x0000;
|
|
dataBuffer[3] = 0x0000;
|
|
usbMsgPtr = dataBuffer;
|
|
return 4;
|
|
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|