#pragma once

#include <cstdint>
#include "I2C_Interface.hpp"

//! Write an 8-bit code to the LTC2946.
//! @return The function returns the state of the acknowledge bit after the I2C address write.
//! 0=acknowledge, 1=no acknowledge.
int8_t LTC2946_write(I2C& i2c, // I2C instance
					 uint8_t i2c_address, //!< Register address for the LTC2946
					 uint8_t adc_command, //!< The "command byte" for the LTC2946
					 uint8_t code //!< Value that will be written to the register.
);
//! Write a 16-bit code to the LTC2946.
//! @return The function returns the state of the acknowledge bit after the I2C address write.
//! 0=acknowledge, 1=no acknowledge.
int8_t LTC2946_write_16_bits(I2C& i2c, // I2C instance
							 uint8_t i2c_address, //!< Register address for the LTC2946
							 uint8_t adc_command, //!< The "command byte" for the LTC2946
							 uint16_t code //!< Value that will be written to the register.
);

//! Write a 24-bit code to the LTC2946.
//! @return The function returns the state of the acknowledge bit after the I2C address write.
//! 0=acknowledge, 1=no acknowledge.
int8_t LTC2946_write_24_bits(I2C& i2c, // I2C instance
							 uint8_t i2c_address, //!< Register address for the LTC2946
							 uint8_t adc_command, //!< The "command byte" for the LTC2946
							 uint32_t code //!< Value that will be written to the register.
);
//! Write a 32-bit code to the LTC2946.
//! @return The function returns the state of the acknowledge bit after the I2C address write.
//! 0=acknowledge, 1=no acknowledge.
int8_t LTC2946_write_32_bits(I2C& i2c, // I2C instance
							 uint8_t i2c_address, //!< Register address for the LTC2946
							 uint8_t adc_command, //!< The "command byte" for the LTC2946
							 uint32_t code //!< Value that will be written to the register.
);
//! Reads an 8-bit adc_code from LTC2946
//! @return The function returns the state of the acknowledge bit after the I2C address write.
//! 0=acknowledge, 1=no acknowledge.
int8_t LTC2946_read(I2C& i2c, // I2C instance
					uint8_t i2c_address, //!< Register address for the LTC2946
					uint8_t adc_command, //!< The "command byte" for the LTC2946
					uint8_t* adc_code //!< Value that will be read from the register.
);
//! Reads a 12-bit adc_code from LTC2946
//! @return The function returns the state of the acknowledge bit after the I2C address write.
//! 0=acknowledge, 1=no acknowledge.
int8_t LTC2946_read_12_bits(I2C& i2c, // I2C instance
							uint8_t i2c_address, //!< Register address for the LTC2946
							uint8_t adc_command, //!< The "command byte" for the LTC2946
							uint16_t* adc_code //!< Value that will be read from the register.
);
//! Reads a 16-bit adc_code from LTC2946
//! @return The function returns the state of the acknowledge bit after the I2C address write.
//! 0=acknowledge, 1=no acknowledge.
int8_t LTC2946_read_16_bits(I2C& i2c, // I2C instance
							uint8_t i2c_address, //!< Register address for the LTC2946
							uint8_t adc_command, //!< The "command byte" for the LTC2946
							uint16_t* adc_code //!< Value that will be read from the register.
);
//! Reads a 24-bit adc_code from LTC2946
//! @return The function returns the state of the acknowledge bit after the I2C address write.
//! 0=acknowledge, 1=no acknowledge.
int8_t LTC2946_read_24_bits(I2C& i2c, // I2C instance
							uint8_t i2c_address, //!< Register address for the LTC2946
							uint8_t adc_command, //!< The "command byte" for the LTC2946
							uint32_t* adc_code //!< Value that will be read from the register.
);
//! Reads a 32-bit adc_code from LTC2946
//! @return The function returns the state of the acknowledge bit after the I2C address write.
//! 0=acknowledge, 1=no acknowledge.
int8_t LTC2946_read_32_bits(I2C& i2c, // I2C instance
							uint8_t i2c_address, //!< Register address for the LTC2946
							uint8_t adc_command, //!< The "command byte" for the LTC2946
							uint32_t* adc_code //!< Value that will be read from the register.
);

//! Calculate the LTC2946 VIN voltage
//! @return Returns the VIN Voltage in Volts
float LTC2946_VIN_code_to_voltage(uint16_t adc_code, //!< The ADC value
								  float LTC2946_VIN_lsb //!< VIN lsb weight
);
//! Calculate the LTC2946 ADIN voltage
//! @return Returns the ADIN Voltage in Volts
float LTC2946_ADIN_code_to_voltage(uint16_t adc_code, //!< The ADC value
								   float LTC2946_ADIN_lsb //!< ADIN lsb weight
);
//! Calculate the LTC2946 current with a sense resistor
//! @return The LTC2946 current in Amps
float LTC2946_code_to_current(uint16_t adc_code, //!< The ADC value
							  float resistor, //!< The resistor value
							  float LTC2946_DELTA_SENSE_lsb //!< Delta sense lsb weight
);
//! Calculate the LTC2946 power
//! @return The LTC2946 power in Watts
float LTC2946_code_to_power(int32_t adc_code, //!< The ADC value
							float resistor, //!< The resistor value
							float LTC2946_Power_lsb); //!< Power lsb weight

//! Calculate the LTC2946 energy
//! @return The LTC2946 energy in Joules
float LTC2946_code_to_energy(int32_t adc_code, //!< The ADC value
							 float resistor, //!< The resistor value
							 float LTC2946_Power_lsb, //!< Power lsb weight
							 float LTC2946_TIME_lsb //!< Time lsb weight
);

//! Calculate the LTC2946 coulombs
//! @return The LTC2946 charge in coulombs
float LTC2946_code_to_coulombs(int32_t adc_code, //!< The ADC value
							   float resistor, //!< The resistor value
							   float LTC2946_DELTA_SENSE_lsb, //!< Delta sense lsb weight
							   float LTC2946_Time_lsb //!< Time lsb weight
);
//! Calculate the LTC2946 internal time base
//! @return The internal time base in seconds.
float LTC2946_code_to_time(float time_code, //!< Time adc code
						   float LTC2946_Time_lsb //!< Time lsb weight
);
