#ifndef _I2C_H
#define _I2C_H


#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>  //printf

#include "sys.h"
#include "utilities.h"

#define SL2x23_DEV_ADDRESS  0x28

#define SL2x23_I2C_TIMING   0x00210507

#define RCC_I2C1CLK_HSI     ((uint32_t)0x00000000)
#define SL2x23_FLAG_TIMEOUT ((uint32_t)0x1000)
#define SL2x23_LONG_TIMEOUT ((uint32_t)(10 * SL2x23_FLAG_TIMEOUT))

/**
  * @brief  I2C EEPROM Interface pins
  */
#define SL2x23_I2C                  I2C1
#define SL2x23_I2C_CLK              RCC_APB1Periph_I2C1

#define SL2x23_I2C_SCL_PIN          GPIO_Pin_6                  /* PB.06 */
#define SL2x23_I2C_SCL_GPIO_PORT    GPIOB                       /* GPIOB */
#define SL2x23_I2C_SCL_GPIO_CLK     RCC_AHBPeriph_GPIOB
#define SL2x23_I2C_SCL_SOURCE       GPIO_PinSource6
#define SL2x23_I2C_SCL_AF           GPIO_AF_1

#define SL2x23_I2C_SDA_PIN          GPIO_Pin_7                  /* PB.07 */
#define SL2x23_I2C_SDA_GPIO_PORT    GPIOB                       /* GPIOB */
#define SL2x23_I2C_SDA_GPIO_CLK     RCC_AHBPeriph_GPIOB
#define SL2x23_I2C_SDA_SOURCE       GPIO_PinSource7
#define SL2x23_I2C_SDA_AF           GPIO_AF_1

void SL2x23_I2C_DeInit(void);
void SL2x23_I2C_Init(void);
void SL2x23_I2C_LowLevel_DeInit(void);
void SL2x23_I2C_LowLevel_Init(void);
uint32_t SL2x23_TIMEOUT_UserCallback(void);
uint32_t i2c_write_word(uint8_t i2c_dev_addr, uint8_t reg_addr, uint8_t reg_value);
uint8_t i2c_read_word(uint8_t i2c_dev_addr, uint8_t reg_addr, uint8_t *reg_value);

#ifdef __cplusplus
}
#endif
#endif
