|
|
|
|
@ -16,10 +16,11 @@ uint16_t spi_master_transceive(uint8_t opcode, uint8_t addr, uint16_t value)
|
|
|
|
|
spi_mst_start_packet();
|
|
|
|
|
spi_mst_write_read(5,mst_buf);
|
|
|
|
|
spi_mst_end_packet();
|
|
|
|
|
} while(mst_buf[1] == 0); // wait for echoed opcode
|
|
|
|
|
} while(mst_buf[1] =! opcode || mst_buf[2] != addr); // wait for echoed opcode
|
|
|
|
|
//TODO: validate opcode and addr
|
|
|
|
|
|
|
|
|
|
// bytes from slave are received shifted right by one
|
|
|
|
|
return (mst_buf[3] << 8) | mst_buf[4];
|
|
|
|
|
return ((mst_buf[3] << 8) | mst_buf[4]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -58,12 +59,8 @@ void call_func(uint8_t number)
|
|
|
|
|
uint16_t spi_proto_slaveaction(uint8_t opcode, uint8_t addr, uint16_t data) {
|
|
|
|
|
uint16_t retval = 0;
|
|
|
|
|
switch(opcode){
|
|
|
|
|
case 0:
|
|
|
|
|
retval = data;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
//TODO
|
|
|
|
|
retval = 0;
|
|
|
|
|
retval = data;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
retval = (*spi_proto_globals8[addr]);
|
|
|
|
|
@ -79,6 +76,13 @@ uint16_t spi_proto_slaveaction(uint8_t opcode, uint8_t addr, uint16_t data) {
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
(*spi_proto_funcs[addr])();
|
|
|
|
|
//TODO: prevent a function from being run several times because the message gets repeated.
|
|
|
|
|
break;
|
|
|
|
|
case 7:
|
|
|
|
|
//TODO
|
|
|
|
|
retval = 0;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return retval;
|
|
|
|
|
|