#ifndef MAD_CORE_BUS_I2C_H
#define MAD_CORE_BUS_I2C_H

#include "common/types.h"

// I2C multiplexer channels
#define AHT01 0x0  // Lower
#define AHT02 0x1  // Middle
#define AHT03 0x2  // Upper

// ADC channels
#define ADS01 0x0  // AIN0 GND
#define ADS02 0x1  // AIN1 GND
#define ADS03 0x2  // AIN2 GND
#define ADS04 0x3  // AIN3 GND

int   I2C_Init(void);
int   I2C_Start(byte addr, byte mode);
int   I2C_SetChannel(int channel);
int   I2C_Write(byte data);
byte  I2C_Read_ACK(void);
byte  I2C_Read_NACK(void);
int   I2C_Wait_ACK(void);
int   I2C_Stop(void);

// AHT20 temperature and humidity sensor
int  I2C_AHT20_Init(void);
int  I2C_AHT20_Read(float *temp, float *rhum);

// ADS1115 analog to digital converter
word   I2C_ADS1115_Read(int channel);
float  I2C_ADS1115_ReadThermistor(int channel);

#endif // MAD_CORE_BUS_I2C_H
