From 7e59368252120e9c8616342e0ad6b4adcae7872e Mon Sep 17 00:00:00 2001 From: "Sebastian H. Gabrielli" Date: Tue, 16 Apr 2024 15:35:43 +0200 Subject: [PATCH] Implement handling reading more than one byte --- prosjekt.X/command-handler.c | 2 +- prosjekt.X/command-handler.h | 3 ++- prosjekt.X/i2c.c | 6 ++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/prosjekt.X/command-handler.c b/prosjekt.X/command-handler.c index cb485ba..2772a4a 100644 --- a/prosjekt.X/command-handler.c +++ b/prosjekt.X/command-handler.c @@ -130,7 +130,7 @@ void parse_command(uint8_t command[], uint8_t command_len) { return; } -uint8_t route_command() { +uint8_t route_command(int pos) { switch (context.command) { WRITE_CONFIG: return WRITE_CONFIG; diff --git a/prosjekt.X/command-handler.h b/prosjekt.X/command-handler.h index dd87e15..696ee2b 100644 --- a/prosjekt.X/command-handler.h +++ b/prosjekt.X/command-handler.h @@ -63,7 +63,8 @@ typedef struct { void parse_command(uint8_t *command, uint8_t command_len); // Routes the provided command to the appropriate function to handle it -uint8_t route_command(); +// If the command is a read command it then returns the current byte +uint8_t route_command(int pos); #ifdef __cplusplus } diff --git a/prosjekt.X/i2c.c b/prosjekt.X/i2c.c index 278f689..c11fdcf 100644 --- a/prosjekt.X/i2c.c +++ b/prosjekt.X/i2c.c @@ -59,16 +59,14 @@ void i2c_write_handler(uint8_t data) { void i2c_read_handler() { last_action_write = false; - TWI0.SDATA = route_command(); + TWI0.SDATA = route_command(i2c_recv_len); + i2c_recv_len++; // Increment the counter of the current amount of requests } void i2c_stop_handler() { if (last_action_write) { // Parse the received command data parse_command(i2c_recv, i2c_recv_len); - } else { - // route_command(); - ; } // Reset the buffer for future transmissions i2c_reset_recv();