Rename receive buffer for better clarity & add comment
This commit is contained in:
parent
ba54ff20ef
commit
6acdb2beb6
@ -8,7 +8,9 @@
|
|||||||
// 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] = {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;
|
volatile uint8_t i2c_recv_len = 0;
|
||||||
|
|
||||||
void init_i2c(void) {
|
void init_i2c(void) {
|
||||||
@ -45,7 +47,7 @@ void init_i2c(void) {
|
|||||||
void i2c_reset_recv() {
|
void i2c_reset_recv() {
|
||||||
i2c_recv_len = 0;
|
i2c_recv_len = 0;
|
||||||
for (int i = 0; i < I2C_RECV_BUF_SIZE; i++) {
|
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; }
|
if (i2c_recv_len >= I2C_RECV_BUF_SIZE) { return; }
|
||||||
|
|
||||||
// Write the data to the receive buffer
|
// Write the data to the receive buffer
|
||||||
i2c_recv[i2c_recv_len] = data;
|
i2c_recv_buf[i2c_recv_len] = data;
|
||||||
i2c_recv_len++;
|
i2c_recv_len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,10 +71,10 @@ void i2c_read_handler() {
|
|||||||
void i2c_stop_handler() {
|
void i2c_stop_handler() {
|
||||||
if (last_action_write) {
|
if (last_action_write) {
|
||||||
// Parse the received command data
|
// 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 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);
|
route_command(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,8 +20,9 @@ extern "C" {
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <util/twi.h>
|
#include <util/twi.h>
|
||||||
|
|
||||||
// Received data info
|
// Received data buffer size
|
||||||
#define I2C_RECV_BUF_SIZE 64
|
// The size is larger than any expected command lenght
|
||||||
|
#define I2C_RECV_BUF_SIZE 16
|
||||||
|
|
||||||
// Reset recv to initial state
|
// Reset recv to initial state
|
||||||
void i2c_reset_recv();
|
void i2c_reset_recv();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user