diff --git a/firmware/masterchip/spi_proto.c b/firmware/masterchip/spi_proto.c deleted file mode 120000 index a86d415..0000000 --- a/firmware/masterchip/spi_proto.c +++ /dev/null @@ -1 +0,0 @@ -../shared/spi_proto.c \ No newline at end of file diff --git a/firmware/masterchip/spi_proto.c b/firmware/masterchip/spi_proto.c new file mode 100644 index 0000000..c12e128 --- /dev/null +++ b/firmware/masterchip/spi_proto.c @@ -0,0 +1,52 @@ +#include "spi_proto.h" +#include "spi.h" + +uint8_t read[2]; +uint8_t write[4]; + +void talk_to_slave(uint8_t opcode, uint8_t addr, uint8_t wlen, uint8_t rlen) +{ + write[0] = opcode; + write[1] = addr; + spi_mst_start_packet(); + spi_mst_write(wlen, write); + spi_mst_read(rlen, read); + spi_mst_end_packet(); +} + +uint16_t read_temperature(uint8_t number) +{ + talk_to_slave(1, number, 2, 2); + return (read[0] << 8) | read[1]; +} + +uint8_t read_var8(uint8_t number) +{ + talk_to_slave(2, number, 2, 2); + return read[1]; +} + +uint16_t read_var16(uint8_t number) +{ + talk_to_slave(3, number, 2, 2); + return (read[0] << 8) | read[1]; +} + +void write_var8(uint8_t number, uint8_t value) +{ + write[2] = 0; + write[3] = number; + talk_to_slave(4, number, 4, 0); +} + +void write_var16(uint8_t number, uint16_t value) +{ + write[2] = value >> 8; + write[3] = value & 0xff; + talk_to_slave(5, number, 4, 0); +} + +void call_func(uint8_t number) +{ + talk_to_slave(6, number, 2, 0); +} diff --git a/firmware/masterchip/spi_proto.h b/firmware/masterchip/spi_proto.h deleted file mode 120000 index 8d40308..0000000 --- a/firmware/masterchip/spi_proto.h +++ /dev/null @@ -1 +0,0 @@ -../shared/spi_proto.h \ No newline at end of file diff --git a/firmware/masterchip/spi_proto.h b/firmware/masterchip/spi_proto.h new file mode 100644 index 0000000..c7861fc --- /dev/null +++ b/firmware/masterchip/spi_proto.h @@ -0,0 +1,11 @@ +#ifndef SPI_PROTO_H +#define SPI_PROTO_H + +uint16_t read_temperature(uint8_t number); +uint8_t read_var8(uint8_t number); +uint16_t read_var16(uint8_t number); +void write_var8(uint8_t number, uint8_t value); +void write_var16(uint8_t number, uint16_t value); +void call_func(uint8_t number); + +#endif diff --git a/firmware/shared/spi_proto.c b/firmware/shared/spi_proto.c deleted file mode 100644 index bcf9928..0000000 --- a/firmware/shared/spi_proto.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "spi_proto.h" - -uint8_t spi_proto_needswrite(uint8_t opcode) { - if(opcode == 4 || opcode == 5) return 1; - return 0; -} - -uint16_t spi_proto_handlewrite(uint8_t opcode, uint8_t addr) { - if(opcode == 4) { - return (uint16_t) (*spi_proto_globals8[addr]); - } else if(opcode == 5) { - return (*spi_proto_globals16[addr]); - } else { - return 0xFFFF; - } - -} - -void spi_proto_handleread(uint8_t opcode, uint8_t addr, uint16_t data) { - if(opcode == 2) { - *spi_proto_globals8[addr] = (uint8_t) data; - } else if(opcode == 3) { - *spi_proto_globals16[addr] = data; - } else if (opcode == 6) { - funptr_t func = spi_proto_funcs[addr]; - (*func)(); - } else { - // boom - } -} diff --git a/firmware/shared/spi_proto.h b/firmware/shared/spi_proto.h deleted file mode 100644 index e57f691..0000000 --- a/firmware/shared/spi_proto.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __SPIPROTO_H -#define __SPIPROTO_H - -#include -#include "main.h" - -typedef void(*funptr_t)(); - - -extern uint16_t *spi_proto_globals8[]; -extern uint8_t *spi_proto_globals16[]; -extern funptr_t spi_proto_funcs[]; - -uint8_t spi_proto_needswrite(uint8_t opcode); -uint16_t spi_proto_handlewrite(uint8_t opcode, uint8_t addr); -void spi_proto_handleread(uint8_t opcode, uint8_t addr, uint16_t data); - -#endif diff --git a/firmware/slavechip/spi_proto.c b/firmware/slavechip/spi_proto.c deleted file mode 120000 index a86d415..0000000 --- a/firmware/slavechip/spi_proto.c +++ /dev/null @@ -1 +0,0 @@ -../shared/spi_proto.c \ No newline at end of file diff --git a/firmware/slavechip/spi_proto.c b/firmware/slavechip/spi_proto.c new file mode 100644 index 0000000..bcf9928 --- /dev/null +++ b/firmware/slavechip/spi_proto.c @@ -0,0 +1,30 @@ +#include "spi_proto.h" + +uint8_t spi_proto_needswrite(uint8_t opcode) { + if(opcode == 4 || opcode == 5) return 1; + return 0; +} + +uint16_t spi_proto_handlewrite(uint8_t opcode, uint8_t addr) { + if(opcode == 4) { + return (uint16_t) (*spi_proto_globals8[addr]); + } else if(opcode == 5) { + return (*spi_proto_globals16[addr]); + } else { + return 0xFFFF; + } + +} + +void spi_proto_handleread(uint8_t opcode, uint8_t addr, uint16_t data) { + if(opcode == 2) { + *spi_proto_globals8[addr] = (uint8_t) data; + } else if(opcode == 3) { + *spi_proto_globals16[addr] = data; + } else if (opcode == 6) { + funptr_t func = spi_proto_funcs[addr]; + (*func)(); + } else { + // boom + } +} diff --git a/firmware/slavechip/spi_proto.h b/firmware/slavechip/spi_proto.h deleted file mode 120000 index 8d40308..0000000 --- a/firmware/slavechip/spi_proto.h +++ /dev/null @@ -1 +0,0 @@ -../shared/spi_proto.h \ No newline at end of file diff --git a/firmware/slavechip/spi_proto.h b/firmware/slavechip/spi_proto.h new file mode 100644 index 0000000..e57f691 --- /dev/null +++ b/firmware/slavechip/spi_proto.h @@ -0,0 +1,18 @@ +#ifndef __SPIPROTO_H +#define __SPIPROTO_H + +#include +#include "main.h" + +typedef void(*funptr_t)(); + + +extern uint16_t *spi_proto_globals8[]; +extern uint8_t *spi_proto_globals16[]; +extern funptr_t spi_proto_funcs[]; + +uint8_t spi_proto_needswrite(uint8_t opcode); +uint16_t spi_proto_handlewrite(uint8_t opcode, uint8_t addr); +void spi_proto_handleread(uint8_t opcode, uint8_t addr, uint16_t data); + +#endif