+/**
+ * In order to read bytes from the i2c we should make some tricks.
+ * This because the silicon manage automatically the NACK on last byte, so to read
+ * one, two or three byte we should manage separately these cases.
+ */
+bool i2c_recv(void *_buf, size_t count)
+{
+ uint8_t *buf = (uint8_t *)_buf;
+
+ while (count)
+ {
+ if (count == 1)
+ {
+ i2c->CR1 &= ~BV(CR1_POS);
+
+ if(!check_i2cStatus(I2C_EVENT_MASTER_BYTE_RECEIVED))
+ return false;
+
+ i2c->CR1 &= CR1_ACK_RESET;
+
+ *buf++ = i2c->DR;
+ count = 0;
+ }
+ else if (count == 2)
+ {
+ i2c->CR1 &= CR1_ACK_RESET;
+
+ WAIT_BTF(i2c);
+
+ i2c->CR1 |= CR1_STOP_SET;
+
+ *buf++ = i2c->DR;
+ *buf++ = i2c->DR;
+
+ count = 0;
+
+ i2c->CR1 &= ~BV(CR1_POS);
+
+ }
+ else if (count == 3)
+ {
+ i2c->CR1 &= ~BV(CR1_POS);
+
+ WAIT_BTF(i2c);
+
+ i2c->CR1 &= CR1_ACK_RESET;
+
+ *buf++ = i2c->DR;
+
+ i2c->CR1 |= CR1_STOP_SET;
+
+ *buf++ = i2c->DR;
+
+ WAIT_RXE(i2c);
+
+ *buf++ = i2c->DR;
+
+ count = 0;
+ }
+ else
+ {
+ i2c->CR1 &= ~BV(CR1_POS);
+
+ WAIT_BTF(i2c);
+
+ *buf++ = i2c->DR;
+
+ count--;
+ }
+ }
+
+ return true;
+}