no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ade7758.c File Reference

Implementation of ADE7758 Driver. More...

#include "ade7758.h"
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "no_os_util.h"
#include "no_os_spi.h"
#include "no_os_gpio.h"
#include "no_os_irq.h"
#include "no_os_delay.h"
#include "no_os_units.h"
#include "no_os_alloc.h"
#include "no_os_crc16.h"
#include "no_os_print_log.h"
#include <stdlib.h>
#include <errno.h>
#include <math.h>
Include dependency graph for ade7758.c:

Functions

int ade7758_init (struct ade7758_dev **device, struct ade7758_init_param init_param)
 Initialize the device.
 
int ade7758_setup (struct ade7758_dev *dev)
 Setup the ADE7758 device.
 
int ade7758_read (struct ade7758_dev *dev, uint16_t reg_addr, int32_t *reg_data)
 Read device register.
 
int ade7758_write (struct ade7758_dev *dev, uint16_t reg_addr, uint32_t reg_data)
 Write device register.
 
int ade7758_update_bits (struct ade7758_dev *dev, uint16_t reg_addr, uint32_t mask, uint32_t reg_data)
 Update specific register bits.
 
int ade7758_remove (struct ade7758_dev *dev)
 Remove the device and release resources.
 
int ade7758_sw_reset (struct ade7758_dev *dev)
 Reset the device using SW reset.
 
int ade7758_version_product (struct ade7758_dev *dev, uint32_t *data_read)
 Version product.
 
int ade7758_read_ipk_val (struct ade7758_dev *dev, uint32_t *val)
 read Ipeak val
 
int ade7758_vpk_val (struct ade7758_dev *dev, uint32_t *val)
 read Vpeak val
 
int ade7758_get_int_status (struct ade7758_dev *dev, uint32_t msk, uint8_t *status)
 Get interrupt indicator from STATUS register.
 
int ade7758_clear_irq_status (struct ade7758_dev *dev, int32_t *reg_data)
 Clear irq status flags.
 
int ade7758_enable_irq (struct ade7758_dev *dev, uint32_t msk, uint8_t en)
 Enable/Disable interrupt.
 
int ade7758_wave_update_rate (struct ade7758_dev *dev, enum ade7758_data_rate sel)
 Select waveform register update rate.
 
int ade7758_wave_sample_data_source (struct ade7758_dev *dev, enum ade7758_wavesel sel)
 Select source of sampled data for wave register.
 
int ade7758_wave_phase_sel (struct ade7758_dev *dev, enum ade7758_phsel sel)
 Select the phase of sampled data for wave register.
 
int ade7758_consel (struct ade7758_dev *dev, enum ade7758_consel sel)
 Select the input to the energy accumulation registers.
 
int ade7758_freq_source (struct ade7758_dev *dev, enum ade7758_phsel sel)
 Select the source of the measurement of the voltage line frequency.
 
int ade7758_adcs_mode (struct ade7758_dev *dev, enum ade7758_dismod sel)
 Operation mode of the ADCs.
 
int ade7758_energy_vals_phase_a (struct ade7758_dev *dev, struct ade7758_energy_values *data)
 Read energy values phase A.
 
int ade7758_energy_vals_phase_b (struct ade7758_dev *dev, struct ade7758_energy_values *data)
 Read energy values phase B.
 
int ade7758_energy_vals_phase_c (struct ade7758_dev *dev, struct ade7758_energy_values *data)
 Read energy values phase C.
 
int ade7758_rms_vals_phase_a (struct ade7758_dev *dev, struct ade7758_rms_values *data)
 Read rms values phase A.
 
int ade7758_rms_vals_phase_b (struct ade7758_dev *dev, struct ade7758_rms_values *data)
 Read rms values phase B.
 
int ade7758_rms_vals_phase_c (struct ade7758_dev *dev, struct ade7758_rms_values *data)
 Read rms values phase C.
 
int ade7758_frequency_period_val (struct ade7758_dev *dev, struct ade7758_freq_per_value *data)
 Read frequency/period value.
 
int ade7758_temperature_val (struct ade7758_dev *dev, struct ade7758_temp_value *data)
 Read temperature value.
 

Detailed Description

Implementation of ADE7758 Driver.

Author
REtz (radu..nosp@m.etz@.nosp@m.analo.nosp@m.g.co.nosp@m.m)

Copyright 2025(c) Analog Devices, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ ade7758_adcs_mode()

int ade7758_adcs_mode ( struct ade7758_dev * dev,
enum ade7758_dismod sel )

Operation mode of the ADCs.

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

◆ ade7758_clear_irq_status()

int ade7758_clear_irq_status ( struct ade7758_dev * dev,
int32_t * reg_data )

Clear irq status flags.

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

◆ ade7758_consel()

int ade7758_consel ( struct ade7758_dev * dev,
enum ade7758_consel sel )

Select the input to the energy accumulation registers.

Parameters
dev- The device structure.
sel- consel value (see datasheet)
Returns
0 in case of success, negative error code otherwise.

◆ ade7758_enable_irq()

int ade7758_enable_irq ( struct ade7758_dev * dev,
uint32_t msk,
uint8_t en )

Enable/Disable interrupt.

Parameters
dev- The device structure.
msk- Interrupt mask.
en-Enable/Disable
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7758_energy_vals_phase_a()

int ade7758_energy_vals_phase_a ( struct ade7758_dev * dev,
struct ade7758_energy_values * data )

Read energy values phase A.

Parameters
dev- The device structure.
data- Structure to store energy values
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7758_energy_vals_phase_b()

int ade7758_energy_vals_phase_b ( struct ade7758_dev * dev,
struct ade7758_energy_values * data )

Read energy values phase B.

Parameters
dev- The device structure.
data- Structure to store energy values
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7758_energy_vals_phase_c()

int ade7758_energy_vals_phase_c ( struct ade7758_dev * dev,
struct ade7758_energy_values * data )

Read energy values phase C.

Parameters
dev- The device structure.
data- Structure to store energy values
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7758_freq_source()

int ade7758_freq_source ( struct ade7758_dev * dev,
enum ade7758_phsel sel )

Select the source of the measurement of the voltage line frequency.

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

◆ ade7758_frequency_period_val()

int ade7758_frequency_period_val ( struct ade7758_dev * dev,
struct ade7758_freq_per_value * data )

Read frequency/period value.

Parameters
dev- The device structure.
data- Structure to store the period val
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7758_get_int_status()

int ade7758_get_int_status ( struct ade7758_dev * dev,
uint32_t msk,
uint8_t * status )

Get interrupt indicator from STATUS register.

Parameters
dev- The device structure.
msk- Interrupt mask.
status- Status indicator.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7758_init()

int ade7758_init ( struct ade7758_dev ** device,
struct ade7758_init_param init_param )

Initialize the device.

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

◆ ade7758_read()

int ade7758_read ( struct ade7758_dev * dev,
uint16_t reg_addr,
int32_t * reg_data )

Read device register.

Parameters
dev- The device structure.
reg_addr- The register address.
reg_data- The data read from 32bit register.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7758_read_ipk_val()

int ade7758_read_ipk_val ( struct ade7758_dev * dev,
uint32_t * val )

read Ipeak val

Parameters
dev- The device structure.
val- Ipeak val
Returns
0 in case of success, negative error code otherwise.

◆ ade7758_remove()

int ade7758_remove ( struct ade7758_dev * dev)

Remove the device and release resources.

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.

◆ ade7758_rms_vals_phase_a()

int ade7758_rms_vals_phase_a ( struct ade7758_dev * dev,
struct ade7758_rms_values * data )

Read rms values phase A.

Parameters
dev- The device structure.
data- Structure to store rms values
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7758_rms_vals_phase_b()

int ade7758_rms_vals_phase_b ( struct ade7758_dev * dev,
struct ade7758_rms_values * data )

Read rms values phase B.

Parameters
dev- The device structure.
data- Structure to store rms values
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7758_rms_vals_phase_c()

int ade7758_rms_vals_phase_c ( struct ade7758_dev * dev,
struct ade7758_rms_values * data )

Read rms values phase C.

Parameters
dev- The device structure.
data- Structure to store rms values
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7758_setup()

int ade7758_setup ( struct ade7758_dev * dev)

Setup the ADE7758 device.

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

◆ ade7758_sw_reset()

int ade7758_sw_reset ( struct ade7758_dev * dev)

Reset the device using SW reset.

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

◆ ade7758_temperature_val()

int ade7758_temperature_val ( struct ade7758_dev * dev,
struct ade7758_temp_value * data )

Read temperature value.

Parameters
dev- The device structure.
data- Structure to store the temperature val
Returns
0 in case of success, negative error code otherwise.

◆ ade7758_update_bits()

int ade7758_update_bits ( struct ade7758_dev * dev,
uint16_t reg_addr,
uint32_t mask,
uint32_t reg_data )

Update specific register bits.

Parameters
dev- The device structure.
reg_addr- The register address.
mask- Specific bits mask.
reg_data- The data to be written.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7758_version_product()

int ade7758_version_product ( struct ade7758_dev * dev,
uint32_t * data_read )

Version product.

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

◆ ade7758_vpk_val()

int ade7758_vpk_val ( struct ade7758_dev * dev,
uint32_t * val )

read Vpeak val

Parameters
dev- The device structure.
val- Vpeak val
Returns
0 in case of success, negative error code otherwise.

◆ ade7758_wave_phase_sel()

int ade7758_wave_phase_sel ( struct ade7758_dev * dev,
enum ade7758_phsel sel )

Select the phase of sampled data for wave register.

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

◆ ade7758_wave_sample_data_source()

int ade7758_wave_sample_data_source ( struct ade7758_dev * dev,
enum ade7758_wavesel sel )

Select source of sampled data for wave register.

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

◆ ade7758_wave_update_rate()

int ade7758_wave_update_rate ( struct ade7758_dev * dev,
enum ade7758_data_rate sel )

Select waveform register update rate.

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

◆ ade7758_write()

int ade7758_write ( struct ade7758_dev * dev,
uint16_t reg_addr,
uint32_t reg_data )

Write device register.

Parameters
dev-The device structure.
reg_addr- The register address.
reg_data- The data to be written.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function: