Implement handling reading more than one byte

This commit is contained in:
Sebastian H. Gabrielli 2024-04-16 15:35:43 +02:00
parent 9fd877aab5
commit 7e59368252
3 changed files with 5 additions and 6 deletions

View File

@ -130,7 +130,7 @@ void parse_command(uint8_t command[], uint8_t command_len) {
return; return;
} }
uint8_t route_command() { uint8_t route_command(int pos) {
switch (context.command) { switch (context.command) {
WRITE_CONFIG: WRITE_CONFIG:
return WRITE_CONFIG; return WRITE_CONFIG;

View File

@ -63,7 +63,8 @@ typedef struct {
void parse_command(uint8_t *command, uint8_t command_len); void parse_command(uint8_t *command, uint8_t command_len);
// Routes the provided command to the appropriate function to handle it // 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 #ifdef __cplusplus
} }

View File

@ -59,16 +59,14 @@ void i2c_write_handler(uint8_t data) {
void i2c_read_handler() { void i2c_read_handler() {
last_action_write = false; 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() { 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, i2c_recv_len);
} else {
// route_command();
;
} }
// Reset the buffer for future transmissions // Reset the buffer for future transmissions
i2c_reset_recv(); i2c_reset_recv();