authorNathael Pajani <nathael.pajani@ed3l.fr>
Wed, 23 Sep 2015 05:29:47 +0000 (07:29 +0200)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Wed, 23 Sep 2015 05:29:47 +0000 (07:29 +0200)
drivers/i2c.c

index 8121882..31653cd 100644 (file)
@@ -35,9 +35,9 @@
 #include "core/lpc_core_cm3.h"
 #include "core/system.h"
 #include "lib/string.h"
+#include "lib/errno.h"
 #include "drivers/i2c.h"
 
-
 /*
  * I2C Bus structure
  *
@@ -259,7 +259,10 @@ void I2C_Handler(uint32_t bus_num)
                        break;
 
                case 0x50: /* Data byte has been received and ACK sent */
-                       i2c->in_buff[i2c->read_index++] = i2c->regs->data;
+                       if (i2c->in_buff != NULL) {
+                               i2c->in_buff[i2c->read_index] = i2c->regs->data;
+                       }
+                       i2c->read_index++;
                        if ((i2c->read_index + 1) < i2c->read_length) {
                                /* assert ACK after data is received, requesting next Data from slave */
                                i2c->regs->ctrl_set = I2C_ASSERT_ACK;
@@ -272,7 +275,10 @@ void I2C_Handler(uint32_t bus_num)
 
                case 0x58: /* Data byte has been received and NACK "sent" */
                        /* This tells the slave it was the last byte. We should be done. */
-                       i2c->in_buff[i2c->read_index++] = i2c->regs->data;
+                       if (i2c->in_buff != NULL) {
+                               i2c->in_buff[i2c->read_index] = i2c->regs->data;
+                       }
+                       i2c->read_index++;
                        /* FIXME : We have two other options : Repeated START or STOP + START,
                         *    but what for ? periodic reads ? */
                        i2c->regs->ctrl_set = I2C_STOP_FLAG;