parent
aa90daa614
commit
b199352e54
@ -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
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
@ -0,0 +1 @@
|
||||
../shared/spi_proto.c
|
||||
@ -0,0 +1 @@
|
||||
../shared/spi_proto.h
|
||||
Loading…
Reference in new issue