Merge branch 'master' of gitorious.ghostdub.de:avr/thermocouple

master
Paul Goeser 15 years ago
commit 5e68bf9810

@ -24,7 +24,7 @@ respectively.
#include <usb.h> /* this is libusb */
#include "opendevice.h" /* common code moved to separate module */
#include "../firmware/usbdrv/usbconfig.h" /* device's VID/PID and names */
#include "../firmware/masterchip/usbdrv/usbconfig.h" /* device's VID/PID and names */
int main(int argc, char **argv)
{
@ -67,25 +67,41 @@ int cnt, vid, pid;
int rxValue, rxIndex;
int value = 0, index = 0;
/* int i=0; */
/* cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, 100, value, index, buffer, sizeof(buffer), 5000); */
/* if(cnt < 0){ */
/* fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror()); */
/* } */
/* rxValue = ((int)buffer[1] & 0xff) | (((int)buffer[0] & 0xff) << 8); */
/* rxIndex = ((int)buffer[3] & 0xff) | (((int)buffer[2] & 0xff) << 8); */
/* fprintf(stderr, "%3d.%02d*C ", rxValue/100, rxValue%100); */
/* fprintf(stderr, "%3d.%02d*C \n", rxIndex/100, rxIndex%100); */
/* cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, 101, value, index, buffer, sizeof(buffer), 5000); */
/* if(cnt < 0){ */
/* fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror()); */
/* } */
/* rxValue = ((int)buffer[1] & 0xff) | (((int)buffer[0] & 0xff) << 8); */
/* rxIndex = ((int)buffer[3] & 0xff) | (((int)buffer[2] & 0xff) << 8); */
/* fprintf(stderr, "%3d.%02d*C ", rxValue/100, rxValue%100); */
/* fprintf(stderr, "%3d.%02d*C \n", rxIndex/100, rxIndex%100); */
if(strcasecmp(argv[1], "temp") == 0) {
int i=0;
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, 100, value, index, buffer, sizeof(buffer), 5000);
if(cnt < 0){
fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror());
}
rxValue = ((int)buffer[1] & 0xff) | (((int)buffer[0] & 0xff) << 8);
rxIndex = ((int)buffer[3] & 0xff) | (((int)buffer[2] & 0xff) << 8);
fprintf(stderr, "%3d.%02d*C ", rxValue/100, rxValue%100);
fprintf(stderr, "%3d.%02d*C \n", rxIndex/100, rxIndex%100);
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, 101, value, index, buffer, sizeof(buffer), 5000);
if(cnt < 0){
fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror());
}
rxValue = ((int)buffer[1] & 0xff) | (((int)buffer[0] & 0xff) << 8);
rxIndex = ((int)buffer[3] & 0xff) | (((int)buffer[2] & 0xff) << 8);
fprintf(stderr, "%3d.%02d*C ", rxValue/100, rxValue%100);
fprintf(stderr, "%3d.%02d*C \n", rxIndex/100, rxIndex%100);
} else {
int opcode, addr, value;
int i=0;
sscanf(argv, "%i %i %i", &opcode, &addr, &value);
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, opcode, addr, value, buffer, sizeof(buffer), 5000);
if(cnt < 0){
fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror());
}
rxValue = ((int)buffer[1] & 0xff) | (((int)buffer[0] & 0xff) << 8);
rxIndex = ((int)buffer[3] & 0xff) | (((int)buffer[2] & 0xff) << 8);
fprintf(stderr, "request = 0x%04x", opcode);
fprintf(stderr, "rxValue = 0x%04x value = 0x%04x\n", rxValue, addr);
fprintf(stderr, "rxIndex = 0x%04x index = 0x%04x\n", rxIndex, value);
}

@ -3,7 +3,7 @@ include ../Makefile.inc
COMPILE = avr-gcc $(CFLAGS) $(DEFINES)
OBJECTS = usbdrv/usbdrvasm.o usbdrv/usbdrv.o main.o display.o lcd/lcd.o usb.o softtimer.o
OBJECTS = usbdrv/usbdrvasm.o usbdrv/usbdrv.o main.o display.o lcd/lcd.o usb.o softtimer.o spi.o spi_proto.o
# symbolic targets:
all: firmware.hex

@ -4,31 +4,55 @@
uint8_t read[2];
uint8_t write[4];
void talk_to_slave(uint8_t opcode, uint8_t addr, uint8_t wlen, uint8_t rlen)
void talk_to_slave(uint8_t opcode, uint8_t addr, uint8_t flags)
{
write[0] = opcode;
write[1] = addr;
spi_mst_start_packet();
spi_mst_write(wlen, write);
spi_mst_read(rlen, read);
spi_mst_write(wlen, flags & SPI_WRITE_DATA? 4 : 2);
spi_mst_read(rlen, flags & SPI_READ_DATA? 2 : 0);
spi_mst_end_packet();
}
uint16_t speak_raw(uint8_t opcode, uint8_t number, uint8_t flags, uint16_t value)
{
write[2] = value >> 8;
write[3] = value & 0xff;
talk_to_slave(opcode, number, flags);
return (read[0] << 8) | read[1];
}
uint8_t spi_proto_needs(uint8_t opcode)
{
uint8_t r = SPI_NONE;
switch(opcode)
{
case 1: case 2: case 3:
r = SPI_READ_DATA;
break;
case 4: case 5:
r = SPI_WRITE_DATA;
break;
}
return r;
}
uint16_t read_temperature(uint8_t number)
{
talk_to_slave(1, number, 2, 2);
talk_to_slave(1, number, SPI_READ_DATA);
return (read[0] << 8) | read[1];
}
uint8_t read_var8(uint8_t number)
{
talk_to_slave(2, number, 2, 2);
talk_to_slave(2, number, SPI_READ_DATA);
return read[1];
}
uint16_t read_var16(uint8_t number)
{
talk_to_slave(3, number, 2, 2);
talk_to_slave(3, number, SPI_READ_DATA);
return (read[0] << 8) | read[1];
}
@ -36,17 +60,17 @@ void write_var8(uint8_t number, uint8_t value)
{
write[2] = 0;
write[3] = number;
talk_to_slave(4, number, 4, 0);
talk_to_slave(4, number, SPI_WRITE_DATA);
}
void write_var16(uint8_t number, uint16_t value)
{
write[2] = value >> 8;
write[3] = value & 0xff;
talk_to_slave(5, number, 4, 0);
talk_to_slave(5, number, SPI_WRITE_DATA);
}
void call_func(uint8_t number)
{
talk_to_slave(6, number, 2, 0);
talk_to_slave(6, number, SPI_NONE);
}

@ -1,6 +1,14 @@
#ifndef SPI_PROTO_H
#define SPI_PROTO_H
#define SPI_WRITE_DATA 0x01
#define SPI_READ_DATA 0x10
#define SPI_NONE 0
uint16_t speak_raw(uint8_t opcode, uint8_t number, uint8_t flags, uint16_t data);
uint8_t spi_proto_needs(uint8_t opcode);
uint16_t read_temperature(uint8_t number);
uint8_t read_var8(uint8_t number);
uint16_t read_var16(uint8_t number);

@ -27,13 +27,11 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
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];
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;

Loading…
Cancel
Save