Merge I2C command handler into main #18

Merged
sebgab merged 15 commits from output-fan-data-over-i2c into main 2024-04-30 08:37:29 +00:00
2 changed files with 10 additions and 7 deletions
Showing only changes of commit 6acdb2beb6 - Show all commits

View File

@ -8,7 +8,9 @@
// read request
volatile bool last_action_write = false;
volatile uint8_t i2c_recv[I2C_RECV_BUF_SIZE] = {0};
// Buffer to hold the received data
volatile uint8_t i2c_recv_buf[I2C_RECV_BUF_SIZE] = {0};
// Counter to know which datapoint we're on
volatile uint8_t i2c_recv_len = 0;
void init_i2c(void) {
@ -45,7 +47,7 @@ void init_i2c(void) {
void i2c_reset_recv() {
i2c_recv_len = 0;
for (int i = 0; i < I2C_RECV_BUF_SIZE; i++) {
i2c_recv[i] = 0;
i2c_recv_buf[i] = 0;
}
}
@ -56,7 +58,7 @@ void i2c_write_handler(uint8_t data) {
if (i2c_recv_len >= I2C_RECV_BUF_SIZE) { return; }
// Write the data to the receive buffer
i2c_recv[i2c_recv_len] = data;
i2c_recv_buf[i2c_recv_len] = data;
i2c_recv_len++;
}
@ -69,10 +71,10 @@ void i2c_read_handler() {
void i2c_stop_handler() {
if (last_action_write) {
// Parse the received command data
parse_command(i2c_recv, i2c_recv_len);
parse_command(i2c_recv_buf, 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_buf[0] == CLEAR_BULK_FAN_SPEED || i2c_recv_buf[0] == WRITE_CONFIG) {
route_command(0);
}
}

View File

@ -20,8 +20,9 @@ extern "C" {
#include <stdbool.h>
#include <util/twi.h>
// Received data info
#define I2C_RECV_BUF_SIZE 64
// Received data buffer size
// The size is larger than any expected command lenght
#define I2C_RECV_BUF_SIZE 16
// Reset recv to initial state
void i2c_reset_recv();