/*
 * i2c.h
 *
 *  Created on: Jun 8, 2021
 *      Author: user
 */

#ifndef INC_I2C_H_
#define INC_I2C_H_

#include "stdint.h"
#include "main.h"
/*#include "stm32l0xx_hal_i2c.h"*/
/*#include "stm32l0xx_ll_i2c.h"*/

/*
 * Defines & macros
 */

#define NULL 0

/*
 * Return values for I2C functions
 */

#define I2C_OK 0
#define I2C_ERROR -1 // generic error
#define I2C_ERROR_NACK -2 // NACK was received during transfer
#define I2C_ERROR_TX_INCOMPLETE -3 // number of TXed bytes != buffer length
#define I2C_ERROR_RX_INCOMPLETE -4 // number of RXed bytes != buffer length

/*
 * Type definitions
 */

/*
typedef struct {
	I2C_HandleTypeDef *i2c;
} i2c_context_t;
*/


/*
 * Function declarations
 */

int8_t i2c_init(I2C_HandleTypeDef *context, uint16_t i2c_timeout);
int8_t i2c_transmit(uint8_t address, uint8_t *buffer, uint16_t len);
int8_t i2c_receive(uint8_t address, uint8_t *buffer, uint16_t len);
int8_t i2c_transmit_receive(uint8_t address, uint16_t tx_buffer, uint16_t tx_len, uint8_t *rx_buffer, uint16_t rx_len);

#endif /* INC_I2C_H_ */
