|
|
@ -18,8 +18,8 @@
|
|
|
|
// value.
|
|
|
|
// value.
|
|
|
|
#define SERIAL_DELAY 24
|
|
|
|
#define SERIAL_DELAY 24
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
|
|
|
|
matrix_row_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
|
|
|
|
uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
|
|
|
|
matrix_row_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
|
|
|
|
|
|
|
|
|
|
|
|
#define SLAVE_DATA_CORRUPT (1<<0)
|
|
|
|
#define SLAVE_DATA_CORRUPT (1<<0)
|
|
|
|
volatile uint8_t status = 0;
|
|
|
|
volatile uint8_t status = 0;
|
|
|
@ -42,7 +42,7 @@ void serial_input(void) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline static
|
|
|
|
inline static
|
|
|
|
uint8_t serial_read_pin(void) {
|
|
|
|
matrix_row_t serial_read_pin(void) {
|
|
|
|
return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK);
|
|
|
|
return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -93,10 +93,10 @@ void sync_send(void) {
|
|
|
|
|
|
|
|
|
|
|
|
// Reads a byte from the serial line
|
|
|
|
// Reads a byte from the serial line
|
|
|
|
static
|
|
|
|
static
|
|
|
|
uint8_t serial_read_byte(void) {
|
|
|
|
matrix_row_t serial_read_byte(void) {
|
|
|
|
uint8_t byte = 0;
|
|
|
|
matrix_row_t byte = 0;
|
|
|
|
serial_input();
|
|
|
|
serial_input();
|
|
|
|
for ( uint8_t i = 0; i < 8; ++i) {
|
|
|
|
for ( uint8_t i = 0; i < sizeof(matrix_row_t)*8; ++i) {
|
|
|
|
byte = (byte << 1) | serial_read_pin();
|
|
|
|
byte = (byte << 1) | serial_read_pin();
|
|
|
|
serial_delay();
|
|
|
|
serial_delay();
|
|
|
|
_delay_us(1);
|
|
|
|
_delay_us(1);
|
|
|
@ -107,8 +107,8 @@ uint8_t serial_read_byte(void) {
|
|
|
|
|
|
|
|
|
|
|
|
// Sends a byte with MSB ordering
|
|
|
|
// Sends a byte with MSB ordering
|
|
|
|
static
|
|
|
|
static
|
|
|
|
void serial_write_byte(uint8_t data) {
|
|
|
|
void serial_write_byte(matrix_row_t data) {
|
|
|
|
uint8_t b = 8;
|
|
|
|
matrix_row_t b = sizeof(matrix_row_t)*8;
|
|
|
|
serial_output();
|
|
|
|
serial_output();
|
|
|
|
while( b-- ) {
|
|
|
|
while( b-- ) {
|
|
|
|
if(data & (1 << b)) {
|
|
|
|
if(data & (1 << b)) {
|
|
|
@ -145,7 +145,7 @@ ISR(SERIAL_PIN_INTERRUPT) {
|
|
|
|
sync_send();
|
|
|
|
sync_send();
|
|
|
|
checksum_computed += serial_master_buffer[i];
|
|
|
|
checksum_computed += serial_master_buffer[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint8_t checksum_received = serial_read_byte();
|
|
|
|
matrix_row_t checksum_received = serial_read_byte();
|
|
|
|
sync_send();
|
|
|
|
sync_send();
|
|
|
|
|
|
|
|
|
|
|
|
serial_input(); // end transaction
|
|
|
|
serial_input(); // end transaction
|
|
|
|