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.

45 lines
1.2 KiB

15 years ago
#include "main.h"
15 years ago
#include "spi.h"
#include "spi_proto.h"
#include "usb.h"
15 years ago
usbMsgLen_t usbFunctionSetup(uchar data[8]) {
usbRequest_t *rq = (void *)data;
static uchar dataBuffer[4];
15 years ago
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;
15 years ago
} 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 {
15 years ago
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 = speak_raw(opcode, addr, spi_proto_needs(opcode), send);
dataBuffer[0] = (recv >> 8) & 0xff;
dataBuffer[1] = recv & 0xff;
dataBuffer[2] = 0x0000;
dataBuffer[3] = 0x0000;
usbMsgPtr = dataBuffer;
return 4;
}
return 0;
}