master
Dario Ernst 15 years ago
parent a4cfcc0237
commit 0eccb96b39

@ -9,7 +9,7 @@ Software:
- irgendein Protokoll für SPI
- A/D-Wandler-Ansteuercode
- Check spi_proto include stuff?
- slave nicht aufhängen lassen wenn zu wenig gelesen
Später:
- PT1000

@ -68,7 +68,7 @@ int cnt, vid, pid;
int value = 0, index = 0;
/* int i=0; */
/* cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, 1, value, index, buffer, sizeof(buffer), 5000); */
/* 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()); */
/* } */
@ -77,7 +77,7 @@ int cnt, vid, pid;
/* 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, 2, value, index, buffer, sizeof(buffer), 5000); */
/* 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()); */
/* } */
@ -87,6 +87,8 @@ int cnt, vid, pid;
/* fprintf(stderr, "%3d.%02d*C \n", rxIndex/100, rxIndex%100); */
usb_close(handle);
return 0;
}

@ -0,0 +1 @@
../shared/spi_proto.c

@ -0,0 +1 @@
../shared/spi_proto.h

@ -1,17 +1,20 @@
#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 == 1) {
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 == 2) {
} else if(rq->bRequest == 101) {
dataBuffer[0] = (thermoData [2] & 0xff00)>>8;
dataBuffer[1] = thermoData [2] & 0x00ff;
dataBuffer[2] = (thermoData [3] & 0xff00)>>8;
@ -19,15 +22,15 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
usbMsgPtr = dataBuffer;
return 4;
} else {
uint8_t opcode = (rq->bRequest & 0xff00)>>8;
uint8_t addr = (rq->wValue & 0xff00)>>8;
uint8_t valH = rq->wIndex & 0x00ff;
uint8_t valL = (rq->wIndex & 0xff00)>>8;
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, data);
spi_mst_read(2, data)
spi_mst_write(4, send);
if(!spi_proto_needswrite(opcode)) spi_mst_read(2, recv);
dataBuffer[0] = recv[0];
dataBuffer[1] = recv[1];

@ -103,7 +103,10 @@ void spi_mst_read(uint8_t len, uint8_t *data){
}
}
void spi_sla_handle_packet(){
// TODO: make slave not hangup in case of partial read
uint8_t opcode, addr, do_write;
uint16_t data;
SPI_WAIT;

Loading…
Cancel
Save