Re-init of read index in i2c structure in case i2c_read is called with only write...
authorNathael Pajani <nathael.pajani@ed3l.fr>
Wed, 13 Mar 2013 15:25:58 +0000 (16:25 +0100)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Tue, 8 Nov 2022 16:03:04 +0000 (17:03 +0100)
drivers/eeprom.c
drivers/i2c.c

index 94247fa..027d0d8 100644 (file)
@@ -159,7 +159,7 @@ int eeprom_write(uint32_t offset, const void *buf, size_t count)
        char full_buff[(EEPROM_ID_MAX_PAGE_SIZE + MAX_CMD_SIZE)];
        int eeprom_type = get_eeprom_type();
 
-        switch (eeprom_type) {
+       switch (eeprom_type) {
                case EEPROM_TYPE_SMALL:
                        cmd_size = CMD_SIZE_SMALL;
                        page_size = EEPROM_ID_SMALL_PAGE_SIZE;
index e629857..8f75684 100644 (file)
@@ -111,7 +111,9 @@ void I2C_0_Handler(void)
                        break;
                case 0x10:  /* A repeated START has been transmitted. */
                        /* Setting read_index to 0 is usefull only if next data byte is
-                        *    Slave Address + Read (SLA + R), but it's OK if we will write too. */
+                        *    Slave Address + Read (SLA + R), but it's OK if we perform a write too, and
+                        *    is necessary for read with a null data length used to probe for devices.
+                        */
                        i2c->read_index = 0;
                        /* Send Slave Address and Read/Write bit (SLA + R/W)
                         * Depending on R/W bit, Master Receive or master Transmit mode will be enterred. */
@@ -254,7 +256,6 @@ void I2C_0_Handler(void)
 
 
 
-
 /***************************************************************************** */
 /*                        I2C access                                           */
 /***************************************************************************** */
@@ -307,6 +308,7 @@ int i2c_read(const void *cmd_buf, size_t cmd_size, const void* ctrl_buf, void* i
        /* read buffer */
        mod_i2c.in_buff = inbuff;
        mod_i2c.read_length = count;
+       mod_i2c.read_index = 0;
 
        /* Start the process */
        mod_i2c.state = I2C_BUSY;