no-OS
adm1177.h
Go to the documentation of this file.
1 /**************************************************************************/
40 #ifndef __ADM1177_H__
41 #define __ADM1177_H__
42 
43 #include <stdint.h>
44 #include <stdio.h>
45 #include "no_os_i2c.h"
46 #include "no_os_util.h"
47 #include "no_os_units.h"
48 
49 /* ADM1177 Slave Address */
50 #define ADM1177_ADDRESS 0x5A
51 
52 /* ADM1177 Write Command Byte Bits */
53 #define ADM1177_CMD_V_CONT NO_OS_BIT(0)
54 #define ADM1177_CMD_V_ONCE NO_OS_BIT(1)
55 #define ADM1177_CMD_I_CONT NO_OS_BIT(2)
56 #define ADM1177_CMD_I_ONCE NO_OS_BIT(3)
57 #define ADM1177_CMD_VRANGE NO_OS_BIT(4)
58 #define ADM1177_CMD_STATUS_RD NO_OS_BIT(6)
59 
60 /* ADM11777 Write Extended Command Byte Register Addresses */
61 #define ADM1177_REG_ALERT_EN (NO_OS_BIT(7) | 0x1)
62 #define ADM1177_REG_ALERT_TH (NO_OS_BIT(7) | 0x2)
63 #define ADM1177_REG_CONTROL (NO_OS_BIT(7) | 0x3)
64 
65 /* ALERT_EN Register Operations */
66 #define ADM1177_EN_ADC_OC1_MASK NO_OS_BIT(0)
67 #define ADM1177_EN_ADC_OC4_MASK NO_OS_BIT(1)
68 #define ADM1177_EN_HS_ALERT_MASK NO_OS_BIT(2)
69 #define ADM1177_EN_OFF_ALERT_MASK NO_OS_BIT(3)
70 #define ADM1177_CLEAR_MASK NO_OS_BIT(4)
71 
72 /* CONTROL Register Operations */
73 #define ADM1177_SWOFF_MASK NO_OS_BIT(0)
74 
75 /* Status Byte Operations */
76 #define ADM1177_ADC_OC_MASK NO_OS_BIT(0)
77 #define ADM1177_ADC_ALERT_MASK NO_OS_BIT(1)
78 #define ADM1177_HS_OC_MASK NO_OS_BIT(2)
79 #define ADM1177_HS_ALERT_MASK NO_OS_BIT(3)
80 #define ADM1177_OFF_STATUS_MASK NO_OS_BIT(4)
81 #define ADM1177_OFF_ALERT_MASK NO_OS_BIT(5)
82 
83 /* Write Extended Command Mask */
84 #define ADM1177_EXT_CMD_MASK NO_OS_BIT(7)
85 
86 #define ADM1177_I_FULLSCALE 105840
87 #define ADM1177_RESOLUTION 4096
88 #define ADM1177_V_FULLSCALE_0 26350
89 #define ADM1177_V_FULLSCALE_1 6650
90 #define ADM1177_R_SENSE 25
91 
97 };
98 
102 };
103 
104 struct adm1177_dev {
108 };
109 
112 };
113 
114 /* Initializes the ADM1177 */
115 int adm1177_init(struct adm1177_dev **device,
117 
118 /* Removes the resources allocated by the ADM1177 */
119 int adm1177_remove(struct adm1177_dev *device);
120 
121 /* Write the command byte to the slave */
122 int adm1177_write(struct adm1177_dev *device,
123  uint8_t cmd,
124  uint8_t reg_address);
125 
126 /* Reads the status byte if requested */
127 int adm1177_read_status(struct adm1177_dev *device, uint8_t *status_byte);
128 
129 /* Sets vrange of the device */
130 int adm1177_set_vrange(struct adm1177_dev *device, uint8_t vrange);
131 
132 /* Gets conversion results for both Voltage and Current at the same time */
134  uint16_t* conv_voltage,
135  uint16_t* conv_current);
136 
137 /* Converts the raw sample of the voltage from the ADC in uV */
139  uint16_t raw_sample,
140  uint64_t *voltage_uv);
141 
142 /* Converts the raw sample of the current from the ADC in uA */
143 int adm1177_to_microampers(uint16_t raw_sample, uint64_t *current_ua);
144 
145 #endif /*__ADM1177_H__*/
adm1177_set_vrange
int adm1177_set_vrange(struct adm1177_dev *device, uint8_t vrange)
Sets the vrange off the ADM1177.
Definition: adm1177.c:107
ADM1177_V_FULLSCALE_0
#define ADM1177_V_FULLSCALE_0
Definition: adm1177.h:88
no_os_alloc.h
END_ATTRIBUTES_ARRAY
#define END_ATTRIBUTES_ARRAY
Definition: iio_types.h:121
iio_trigger.h
Header file for iio_trigger.
no_os_i2c_write
int32_t no_os_i2c_write(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Write data to slave device.
Definition: no_os_i2c.c:165
no_os_i2c_init
int32_t no_os_i2c_init(struct no_os_i2c_desc **desc, const struct no_os_i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: no_os_i2c.c:58
adm1177_remove
int adm1177_remove(struct adm1177_dev *device)
Free the resources allocated by adm1177_init().
Definition: adm1177.c:86
adm1177_vrange
adm1177_vrange
Definition: adm1177.h:99
adm1177_last_command
adm1177_last_command
Definition: adm1177.h:92
adm1177_remove
int adm1177_remove(struct adm1177_dev *device)
Free the resources allocated by adm1177_init().
Definition: adm1177.c:86
ADM1177_STATUS_EN
@ ADM1177_STATUS_EN
Definition: adm1177.h:96
no_os_i2c_remove
int32_t no_os_i2c_remove(struct no_os_i2c_desc *desc)
Free the resources allocated by no_os_i2c_init().
Definition: no_os_i2c.c:119
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.
Definition: adm1177.c:302
no_os_units.h
Header file of Units.
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.
Definition: adm1177.c:180
iio_trig_disable
int iio_trig_disable(void *trig)
Disable system interrupt which is linked to the given trigger.
Definition: iio_trigger.c:133
adm1177_init_param::i2c_init
struct no_os_i2c_init_param i2c_init
Definition: adm1177.h:111
ADM1177_VRANGE_HIGH
@ ADM1177_VRANGE_HIGH
Definition: adm1177.h:101
no_os_delay.h
Header file of Delay functions.
adm1177_dev::last_command
enum adm1177_last_command last_command
Definition: adm1177.h:106
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.
Definition: adm1177.c:180
device
Definition: ad9361_util.h:75
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.
Definition: adm1177.c:146
no_os_calloc
void * no_os_calloc(size_t nitems, size_t size)
Allocate memory and return a pointer to it, set memory to 0.
Definition: chibios_alloc.c:60
adm1177_dev::i2c_desc
struct no_os_i2c_desc * i2c_desc
Definition: adm1177.h:105
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 t...
Definition: adm1177.c:213
adc_iio_timer_trig_desc
struct iio_trigger adc_iio_timer_trig_desc
Definition: iio_adc_demo_trig.c:67
adm1177_to_microampers
int adm1177_to_microampers(uint16_t raw_sample, uint64_t *current_ua)
Converts the raw sample from the Readback into uA.
Definition: adm1177.c:331
iio_sw_trig_handler
int iio_sw_trig_handler(void *trig, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t priv)
Handles the write request for trigger_now attribute.
Definition: iio_trigger.c:214
adm1177_init
int adm1177_init(struct adm1177_dev **device, struct adm1177_init_param *init_param)
Initializes I2C.
Definition: adm1177.c:57
ADM1177_R_SENSE
#define ADM1177_R_SENSE
Definition: adm1177.h:90
adm1177.h
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.
Definition: adm1177.c:302
iio.h
Header file of iio.
no_os_error.h
Error codes definition.
iio_attribute::name
const char * name
Definition: iio_types.h:136
MILLIVOLT_PER_VOLT
#define MILLIVOLT_PER_VOLT
Definition: no_os_units.h:64
ADM1177_CMD_I_CONT
#define ADM1177_CMD_I_CONT
Definition: adm1177.h:55
iio_trig_enable
int iio_trig_enable(void *trig)
Enable system interrupt which is linked to the given trigger.
Definition: iio_trigger.c:116
adm1177_to_microampers
int adm1177_to_microampers(uint16_t raw_sample, uint64_t *current_ua)
Converts the raw sample from the Readback into uA.
Definition: adm1177.c:331
iio_attribute
Structure holding pointers to show and store functions.
Definition: iio_types.h:134
ADM1177_VRANGE_LOW
@ ADM1177_VRANGE_LOW
Definition: adm1177.h:100
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 t...
Definition: adm1177.c:213
adm1177_dev::vrange
enum adm1177_vrange vrange
Definition: adm1177.h:107
ADM1177_VOLTAGE_EN
@ ADM1177_VOLTAGE_EN
Definition: adm1177.h:93
ADM1177_V_FULLSCALE_1
#define ADM1177_V_FULLSCALE_1
Definition: adm1177.h:89
no_os_i2c_desc
Structure holding I2C address descriptor.
Definition: no_os_i2c.h:107
adm1177_dev
Definition: adm1177.h:104
ADM1177_CMD_V_CONT
#define ADM1177_CMD_V_CONT
Definition: adm1177.h:53
no_os_i2c_read
int32_t no_os_i2c_read(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Read data from slave device.
Definition: no_os_i2c.c:196
no_os_i2c.h
Header file of I2C Interface.
ADM1177_RESOLUTION
#define ADM1177_RESOLUTION
Definition: adm1177.h:87
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:75
ADM1177_CMD_V_ONCE
#define ADM1177_CMD_V_ONCE
Definition: adm1177.h:54
ADM1177_CMD_VRANGE
#define ADM1177_CMD_VRANGE
Definition: adm1177.h:57
no_os_udelay
void no_os_udelay(uint32_t usecs)
Wait until usecs microseconds passed.
Definition: aducm3029_delay.c:120
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:70
NULL
#define NULL
Definition: wrapper.h:64
iio_trigger
Definition: iio_types.h:236
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:119
ADM1177_CMD_I_ONCE
#define ADM1177_CMD_I_ONCE
Definition: adm1177.h:56
iio_adc_demo.h
Header file of ADC Demo iio.
ADM1177_VOLTAGE_AND_CURRENT_EN
@ ADM1177_VOLTAGE_AND_CURRENT_EN
Definition: adm1177.h:95
ADM1177_EXT_CMD_MASK
#define ADM1177_EXT_CMD_MASK
Definition: adm1177.h:84
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.
Definition: adm1177.c:146
ADM1177_CURRENT_EN
@ ADM1177_CURRENT_EN
Definition: adm1177.h:94
adc_iio_sw_trig_desc
struct iio_trigger adc_iio_sw_trig_desc
Definition: iio_adc_demo_trig.c:61
iio_trigger::is_synchronous
bool is_synchronous
Definition: iio_types.h:239
adm1177_set_vrange
int adm1177_set_vrange(struct adm1177_dev *device, uint8_t vrange)
Sets the vrange off the ADM1177.
Definition: adm1177.c:107
no_os_util.h
Header file of utility functions.
adm1177_init
int adm1177_init(struct adm1177_dev **device, struct adm1177_init_param *init_param)
Initializes I2C.
Definition: adm1177.c:57
ADM1177_I_FULLSCALE
#define ADM1177_I_FULLSCALE
Definition: adm1177.h:86
MICROVOLT_PER_VOLT
#define MICROVOLT_PER_VOLT
Definition: no_os_units.h:65
MILLIAMPER_PER_AMPER
#define MILLIAMPER_PER_AMPER
Definition: no_os_units.h:68
adm1177_init_param
Definition: adm1177.h:110