commit
25e646555c
@ -1 +0,0 @@
|
|||||||
../shared/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);
|
||||||
|
}
|
||||||
@ -1 +0,0 @@
|
|||||||
../shared/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
|
||||||
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
#ifndef __SPIPROTO_H
|
|
||||||
#define __SPIPROTO_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#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
|
|
||||||
@ -1 +0,0 @@
|
|||||||
../shared/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
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1 +0,0 @@
|
|||||||
../shared/spi_proto.h
|
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef __SPIPROTO_H
|
||||||
|
#define __SPIPROTO_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#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
|
||||||
Loading…
Reference in new issue