Merge I2C command handler into main #18
@ -8,9 +8,7 @@
|
|||||||
// read request
|
// read request
|
||||||
volatile bool last_action_write = false;
|
volatile bool last_action_write = false;
|
||||||
|
|
||||||
volatile uint8_t i2c_recv[I2C_RECV_BUF_SIZE] = {
|
volatile uint8_t i2c_recv[I2C_RECV_BUF_SIZE] = {0};
|
||||||
0}; // Arbitrary length array to hold the received
|
|
||||||
// data, longer than max expected command
|
|
||||||
volatile uint8_t i2c_recv_len = 0;
|
volatile uint8_t i2c_recv_len = 0;
|
||||||
|
|
||||||
void init_i2c(void) {
|
void init_i2c(void) {
|
||||||
@ -73,22 +71,12 @@ void i2c_stop_handler() {
|
|||||||
// Parse the received command data
|
// Parse the received command data
|
||||||
parse_command(i2c_recv, i2c_recv_len);
|
parse_command(i2c_recv, i2c_recv_len);
|
||||||
|
|
||||||
|
// If the received command is a write only command we want to route it now.
|
||||||
if (i2c_recv[0] == CLEAR_BULK_FAN_SPEED || i2c_recv[0] == WRITE_CONFIG) {
|
if (i2c_recv[0] == CLEAR_BULK_FAN_SPEED || i2c_recv[0] == WRITE_CONFIG) {
|
||||||
route_command(0);
|
route_command(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write only commands need to be routed now
|
|
||||||
switch (i2c_recv[0]) {
|
|
||||||
WRITE_CONFIG:
|
|
||||||
CLEAR_BULK_FAN_SPEED:
|
|
||||||
route_command(0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Reset the buffer for future transmissions
|
// Reset the buffer for future transmissions
|
||||||
i2c_reset_recv();
|
i2c_reset_recv();
|
||||||
}
|
}
|
||||||
@ -103,16 +91,14 @@ ISR(TWI0_TWIS_vect) {
|
|||||||
uint8_t data = 0;
|
uint8_t data = 0;
|
||||||
|
|
||||||
if (((TWI0.SSTATUS & TWI_DIR_bm) >> TWI_DIR_bp) == 0) {
|
if (((TWI0.SSTATUS & TWI_DIR_bm) >> TWI_DIR_bp) == 0) {
|
||||||
// Data write Master -> Slave
|
// Data write Controller -> Target
|
||||||
data = TWI0.SDATA;
|
data = TWI0.SDATA;
|
||||||
|
|
||||||
// Send the data to the write handler
|
// Send the data to the write handler
|
||||||
i2c_write_handler(data);
|
i2c_write_handler(data);
|
||||||
} else {
|
} else {
|
||||||
// Data read Master <- Slave
|
// Data read Controller <- Target
|
||||||
i2c_read_handler();
|
i2c_read_handler();
|
||||||
// data = TWI0.SDATA;
|
|
||||||
// TWI0.SDATA = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Acknowledge having received
|
// Acknowledge having received
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user