no-OS
Classes | Macros | Enumerations | Functions
adm1177.h File Reference
#include <stdint.h>
#include <stdio.h>
#include "no_os_i2c.h"
#include "no_os_util.h"
#include "no_os_units.h"
Include dependency graph for adm1177.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  adm1177_dev
 
struct  adm1177_init_param
 

Macros

#define ADM1177_ADDRESS   0x5A
 
#define ADM1177_CMD_V_CONT   NO_OS_BIT(0)
 
#define ADM1177_CMD_V_ONCE   NO_OS_BIT(1)
 
#define ADM1177_CMD_I_CONT   NO_OS_BIT(2)
 
#define ADM1177_CMD_I_ONCE   NO_OS_BIT(3)
 
#define ADM1177_CMD_VRANGE   NO_OS_BIT(4)
 
#define ADM1177_CMD_STATUS_RD   NO_OS_BIT(6)
 
#define ADM1177_REG_ALERT_EN   (NO_OS_BIT(7) | 0x1)
 
#define ADM1177_REG_ALERT_TH   (NO_OS_BIT(7) | 0x2)
 
#define ADM1177_REG_CONTROL   (NO_OS_BIT(7) | 0x3)
 
#define ADM1177_EN_ADC_OC1_MASK   NO_OS_BIT(0)
 
#define ADM1177_EN_ADC_OC4_MASK   NO_OS_BIT(1)
 
#define ADM1177_EN_HS_ALERT_MASK   NO_OS_BIT(2)
 
#define ADM1177_EN_OFF_ALERT_MASK   NO_OS_BIT(3)
 
#define ADM1177_CLEAR_MASK   NO_OS_BIT(4)
 
#define ADM1177_SWOFF_MASK   NO_OS_BIT(0)
 
#define ADM1177_ADC_OC_MASK   NO_OS_BIT(0)
 
#define ADM1177_ADC_ALERT_MASK   NO_OS_BIT(1)
 
#define ADM1177_HS_OC_MASK   NO_OS_BIT(2)
 
#define ADM1177_HS_ALERT_MASK   NO_OS_BIT(3)
 
#define ADM1177_OFF_STATUS_MASK   NO_OS_BIT(4)
 
#define ADM1177_OFF_ALERT_MASK   NO_OS_BIT(5)
 
#define ADM1177_EXT_CMD_MASK   NO_OS_BIT(7)
 
#define ADM1177_I_FULLSCALE   105840
 
#define ADM1177_RESOLUTION   4096
 
#define ADM1177_V_FULLSCALE_0   26350
 
#define ADM1177_V_FULLSCALE_1   6650
 
#define ADM1177_R_SENSE   25
 

Enumerations

enum  adm1177_last_command {
  ADM1177_VOLTAGE_EN,
  ADM1177_CURRENT_EN,
  ADM1177_VOLTAGE_AND_CURRENT_EN,
  ADM1177_STATUS_EN
}
 
enum  adm1177_vrange {
  ADM1177_VRANGE_LOW,
  ADM1177_VRANGE_HIGH
}
 

Functions

int adm1177_init (struct adm1177_dev **device, struct adm1177_init_param *init_param)
 Initializes I2C. More...
 
int adm1177_remove (struct adm1177_dev *device)
 Free the resources allocated by adm1177_init(). More...
 
int adm1177_write (struct adm1177_dev *device, uint8_t cmd, uint8_t reg_address)
 
  • In the write command byte operation, the master device sends a command byte to the slave device.
More...
 
int adm1177_read_status (struct adm1177_dev *device, uint8_t *status_byte)
 
  • Reads the status byte from the ADC if requested and transmits it through the status_byte pointer.
More...
 
int adm1177_set_vrange (struct adm1177_dev *device, uint8_t vrange)
 
  • Sets the vrange off the ADM1177.
More...
 
int adm1177_read_conv (struct adm1177_dev *device, uint16_t *conv_voltage, uint16_t *conv_current)
 
  • Gets the voltage/current readback from the ADM1177s I2C ADC, if the device is initialized right and transmits the requested values.
More...
 
int adm1177_to_microvolts (struct adm1177_dev *device, uint16_t raw_sample, uint64_t *voltage_uv)
 
  • Converts the raw sample from the Readback into uV.
More...
 
int adm1177_to_microampers (uint16_t raw_sample, uint64_t *current_ua)
 
  • Converts the raw sample from the Readback into uA.
More...
 

Macro Definition Documentation

◆ ADM1177_ADC_ALERT_MASK

#define ADM1177_ADC_ALERT_MASK   NO_OS_BIT(1)

◆ ADM1177_ADC_OC_MASK

#define ADM1177_ADC_OC_MASK   NO_OS_BIT(0)

◆ ADM1177_ADDRESS

#define ADM1177_ADDRESS   0x5A

◆ ADM1177_CLEAR_MASK

#define ADM1177_CLEAR_MASK   NO_OS_BIT(4)

◆ ADM1177_CMD_I_CONT

#define ADM1177_CMD_I_CONT   NO_OS_BIT(2)

◆ ADM1177_CMD_I_ONCE

#define ADM1177_CMD_I_ONCE   NO_OS_BIT(3)

◆ ADM1177_CMD_STATUS_RD

#define ADM1177_CMD_STATUS_RD   NO_OS_BIT(6)

◆ ADM1177_CMD_V_CONT

#define ADM1177_CMD_V_CONT   NO_OS_BIT(0)

◆ ADM1177_CMD_V_ONCE

#define ADM1177_CMD_V_ONCE   NO_OS_BIT(1)

◆ ADM1177_CMD_VRANGE

#define ADM1177_CMD_VRANGE   NO_OS_BIT(4)

◆ ADM1177_EN_ADC_OC1_MASK

#define ADM1177_EN_ADC_OC1_MASK   NO_OS_BIT(0)

◆ ADM1177_EN_ADC_OC4_MASK

#define ADM1177_EN_ADC_OC4_MASK   NO_OS_BIT(1)

◆ ADM1177_EN_HS_ALERT_MASK

#define ADM1177_EN_HS_ALERT_MASK   NO_OS_BIT(2)

◆ ADM1177_EN_OFF_ALERT_MASK

#define ADM1177_EN_OFF_ALERT_MASK   NO_OS_BIT(3)

◆ ADM1177_EXT_CMD_MASK

#define ADM1177_EXT_CMD_MASK   NO_OS_BIT(7)

◆ ADM1177_HS_ALERT_MASK

#define ADM1177_HS_ALERT_MASK   NO_OS_BIT(3)

◆ ADM1177_HS_OC_MASK

#define ADM1177_HS_OC_MASK   NO_OS_BIT(2)

◆ ADM1177_I_FULLSCALE

#define ADM1177_I_FULLSCALE   105840

◆ ADM1177_OFF_ALERT_MASK

#define ADM1177_OFF_ALERT_MASK   NO_OS_BIT(5)

◆ ADM1177_OFF_STATUS_MASK

#define ADM1177_OFF_STATUS_MASK   NO_OS_BIT(4)

◆ ADM1177_R_SENSE

#define ADM1177_R_SENSE   25

◆ ADM1177_REG_ALERT_EN

#define ADM1177_REG_ALERT_EN   (NO_OS_BIT(7) | 0x1)

◆ ADM1177_REG_ALERT_TH

#define ADM1177_REG_ALERT_TH   (NO_OS_BIT(7) | 0x2)

◆ ADM1177_REG_CONTROL

#define ADM1177_REG_CONTROL   (NO_OS_BIT(7) | 0x3)

◆ ADM1177_RESOLUTION

#define ADM1177_RESOLUTION   4096

◆ ADM1177_SWOFF_MASK

#define ADM1177_SWOFF_MASK   NO_OS_BIT(0)

◆ ADM1177_V_FULLSCALE_0

#define ADM1177_V_FULLSCALE_0   26350

◆ ADM1177_V_FULLSCALE_1

#define ADM1177_V_FULLSCALE_1   6650

Enumeration Type Documentation

◆ adm1177_last_command

Enumerator
ADM1177_VOLTAGE_EN 
ADM1177_CURRENT_EN 
ADM1177_VOLTAGE_AND_CURRENT_EN 
ADM1177_STATUS_EN 

◆ adm1177_vrange

Enumerator
ADM1177_VRANGE_LOW 
ADM1177_VRANGE_HIGH 

Function Documentation

◆ adm1177_init()

int adm1177_init ( struct adm1177_dev **  device,
struct adm1177_init_param init_param 
)

Initializes I2C.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
status - Initialization status. Example: negative value - Initialization failed. 0 - Initialization succeeded.

◆ adm1177_read_conv()

int adm1177_read_conv ( struct adm1177_dev device,
uint16_t *  conv_voltage,
uint16_t *  conv_current 
)

  • Gets the voltage/current readback from the ADM1177s I2C ADC, if the device is initialized right and transmits the requested values.

Parameters
device- The device structure.
conv_voltage- The variable through which the voltage read from the ADC is received if requested. If it is 0, it means it was not requested.
conv_current- The variable through which the current read from the ADC is received if requested. If it is 0, it means it was not requested.
Returns
0 in case of success, negative error code otherwise.

◆ adm1177_read_status()

int adm1177_read_status ( struct adm1177_dev device,
uint8_t *  status_byte 
)

  • Reads the status byte from the ADC if requested and transmits it through the status_byte pointer.

Parameters
device- The device structure.
status_byte- The pointer through which the status byte is transmitted.
Returns
0 in case of success, negative error code otherwise.

◆ adm1177_remove()

int adm1177_remove ( struct adm1177_dev device)

Free the resources allocated by adm1177_init().

Parameters
device- The device structure.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adm1177_set_vrange()

int adm1177_set_vrange ( struct adm1177_dev device,
uint8_t  vrange 
)

  • Sets the vrange off the ADM1177.

Parameters
device- The device structure.
vrange- ADM1177_CMD_VRANGE for V Range of 6.65V, otherwise 26.65V will be used.
Returns
0 in case of success, negative error code otherwise.

◆ adm1177_to_microampers()

int adm1177_to_microampers ( uint16_t  raw_sample,
uint64_t *  current_ua 
)

  • Converts the raw sample from the Readback into uA.

Parameters
raw_sample- The raw sample of the Current Readback from the ADC.
current_ua- The pointer through which the converted microamper value is returned.
Returns
- 0, because there is no actual return.

◆ adm1177_to_microvolts()

int adm1177_to_microvolts ( struct adm1177_dev device,
uint16_t  raw_sample,
uint64_t *  voltage_uv 
)

  • Converts the raw sample from the Readback into uV.

Parameters
device- The device structure.
raw_sample- The raw sample of the Voltage Readback from the ADC.
voltage_uv- The pointer through which the converted microvolt value is returned.
Returns
- 0 in case of succes. negative error code if v_fullscale is set wrong.

◆ adm1177_write()

int adm1177_write ( struct adm1177_dev device,
uint8_t  cmd,
uint8_t  reg_address 
)

  • In the write command byte operation, the master device sends a command byte to the slave device.

Parameters
device- The device structure.
cmd- The command byte indicates which operation to be performed.
reg_address- In case of a write extended command byte operation one of the ADM1177_REG_ALERT_EN, ADM1177_REG_ALERT_TH or ADM1177_REG_CONTROL will be used. In case of a write command byte operation reg_address will be set to 0.
Returns
0 in case of success, negative error code otherwise.