From 6acdb2beb6b82449b37077a18015561ca7ff3827 Mon Sep 17 00:00:00 2001 From: "Sebastian H. Gabrielli" Date: Sun, 28 Apr 2024 20:14:27 +0200 Subject: [PATCH] Rename receive buffer for better clarity & add comment --- prosjekt.X/i2c.c | 12 +++++++----- prosjekt.X/i2c.h | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/prosjekt.X/i2c.c b/prosjekt.X/i2c.c index 716618b..c0d6f45 100644 --- a/prosjekt.X/i2c.c +++ b/prosjekt.X/i2c.c @@ -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); } } diff --git a/prosjekt.X/i2c.h b/prosjekt.X/i2c.h index 342f459..cd7c646 100644 --- a/prosjekt.X/i2c.h +++ b/prosjekt.X/i2c.h @@ -20,8 +20,9 @@ extern "C" { #include #include -// 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();