![]() |
no-OS
|
Source file of AD74416H Driver. More...
#include "ad74416h.h"#include "no_os_crc8.h"#include "no_os_delay.h"#include "no_os_error.h"#include "no_os_util.h"#include "no_os_alloc.h"Macros | |
| #define | AD74416H_CRC_POLYNOMIAL 0x7 |
| #define | AD74416H_DIN_DEBOUNCE_LEN NO_OS_BIT(5) |
| #define | AD77416H_DEV_ADDRESS_MSK NO_OS_GENMASK(5, 4) |
Functions | |
| NO_OS_DECLARE_CRC8_TABLE (_crc_table) | |
| int | ad74416h_dac_voltage_to_code (struct ad74416h_desc *desc, int32_t mvolts, uint16_t *code, uint32_t ch) |
| Converts a millivolt value in the corresponding DAC 16 bit code. | |
| int | ad74416h_dac_current_to_code (struct ad74416h_desc *desc, uint32_t uamps, uint16_t *code) |
| Convers a microamp value in the corresponding DAC 16 bit code. | |
| int | ad74416h_reg_read_raw (struct ad74416h_desc *desc, uint32_t addr, uint8_t *val) |
| Read a raw communication frame. | |
| int | ad74416h_reg_write (struct ad74416h_desc *desc, uint32_t addr, uint16_t val) |
| Write a register's value. | |
| int | ad74416h_reg_read (struct ad74416h_desc *desc, uint32_t addr, uint16_t *val) |
| Read a register's value. | |
| int | ad74416h_reg_update (struct ad74416h_desc *desc, uint32_t addr, uint16_t mask, uint16_t val) |
| Update a register's field. | |
| int | ad74416h_nb_active_channels (struct ad74416h_desc *desc, uint8_t *nb_channels) |
| Get the number of active channels. | |
| int | ad74416h_get_raw_adc_result (struct ad74416h_desc *desc, uint32_t ch, uint32_t *val) |
| Read the raw ADC raw conversion value. | |
| int | ad74416h_set_adc_channel_enable (struct ad74416h_desc *desc, uint32_t ch, bool status) |
| Enable/disable a specific ADC channel. | |
| int | ad74416h_set_diag_channel_enable (struct ad74416h_desc *desc, uint32_t ch, bool status) |
| Enable conversions on a diagnostic register. | |
| int | ad74416h_get_adc_range (struct ad74416h_desc *desc, uint32_t ch, uint16_t *val) |
| Get the ADC measurement range for a specific channel. | |
| int | ad74416h_set_adc_range (struct ad74416h_desc *desc, uint32_t ch, enum ad74416h_adc_range val) |
| Set the ADC measurement range for a specific channel. | |
| int | ad74416h_get_adc_rate (struct ad74416h_desc *desc, uint32_t ch, enum ad74416h_adc_rate *val) |
| Get the ADC Conversion Rate for a specific channel. | |
| int | ad74416h_set_adc_rate (struct ad74416h_desc *desc, uint32_t ch, enum ad74416h_adc_rate val) |
| Set the ADC Conversion Rate for a specific channel. | |
| int | ad74416h_get_adc_conv_mux (struct ad74416h_desc *desc, uint32_t ch, enum ad74416h_adc_conv_mux *val) |
| Get the ADC Input Node for conversion. | |
| int | ad74416h_set_adc_conv_mux (struct ad74416h_desc *desc, uint32_t ch, enum ad74416h_adc_conv_mux val) |
| Set the ADC Input Node for conversion. | |
| int | ad74416h_set_adc_conv_seq (struct ad74416h_desc *desc, enum ad74416h_conv_seq status) |
| Start or stop ADC conversions. | |
| int | ad74416h_get_adc_single (struct ad74416h_desc *desc, uint32_t ch, uint32_t *val) |
| Get a single ADC raw value for a specific channel, then power down the ADC. | |
| int | ad74416h_get_temp (struct ad74416h_desc *desc, uint32_t ch, uint16_t *temp) |
| Read the die's temperature from the diagnostic register. | |
| int | ad74416h_set_channel_function (struct ad74416h_desc *desc, uint32_t ch, enum ad74416h_op_mode ch_func) |
| Set the operation mode for a specific channel. | |
| int | ad74416h_set_channel_vout_range (struct ad74416h_desc *desc, uint32_t ch, enum ad74416h_vout_range vout_range) |
| Set the voltage range for a specific channel. | |
| int | ad74416h_set_channel_i_limit (struct ad74416h_desc *desc, uint32_t ch, enum ad74416h_i_limit i_limit) |
| Set the current limit for a specific DAC channel in vout mode. | |
| int | ad74416h_set_channel_dac_code (struct ad74416h_desc *desc, uint32_t ch, uint16_t dac_code) |
| Set and load a code for the DAC on a specific channel. | |
| int | ad74416h_set_diag (struct ad74416h_desc *desc, uint32_t ch, enum ad74416h_diag_mode diag_code) |
| Set which diagnostic value to be loaded in the DIAG_RESULT register. | |
| int | ad74416h_get_diag (struct ad74416h_desc *desc, uint32_t ch, uint16_t *diag_code) |
| Get the diagnostic value for a specific channel. | |
| int | ad74416h_set_debounce_mode (struct ad74416h_desc *desc, uint32_t ch, enum ad74416h_debounce_mode mode) |
| Set the debounce mode for the IOx inputs when the ADC is running in digital input mode. | |
| int | ad74416h_set_debounce_time (struct ad74416h_desc *desc, uint32_t ch, uint32_t time) |
| Set the debounce settle time for the IOx inputs when the ADC is running in digital input mode. | |
| int | ad74416h_gpio_get (struct ad74416h_desc *desc, uint32_t ch, uint8_t *val) |
| Get the GPO value for a specific channel. | |
| int | ad74416h_set_gpio_config (struct ad74416h_desc *desc, uint32_t ch, enum ad74416h_gpio_select config) |
| Set the GPIO operation mode. | |
| int | ad74416h_set_threshold (struct ad74416h_desc *desc, uint32_t ch, uint32_t threshold) |
| Set the threshold, for which a signal would be considered high, when the ADC is running in digital input mode. | |
| int | ad74416h_do_set (struct ad74416h_desc *desc, uint32_t ch, uint8_t val) |
| Set the DO value of a channel. | |
| int | ad74416h_gpio_set (struct ad74416h_desc *desc, uint32_t ch, uint8_t val) |
| Set the logic value of a GPO pin. | |
| int | ad74416h_get_live (struct ad74416h_desc *desc, union ad74416h_live_status *status) |
| Read the live status bits. | |
| int | ad74416h_dac_slew_enable (struct ad74416h_desc *desc, uint32_t ch, enum ad74416h_slew_lin_step step, enum ad74416h_lin_rate rate) |
| Configure and enable slew rate control for a DAC on a specific channel. | |
| int | ad74416h_dac_slew_disable (struct ad74416h_desc *desc, uint32_t ch) |
| Disable the slew rate control. | |
| int | ad74416h_set_therm_rst (struct ad74416h_desc *desc, bool enable) |
| Enable or disable the higher thermal reset. | |
| int | ad74416h_reset (struct ad74416h_desc *desc) |
| Perform software or hardware reset and wait for device reset time. | |
| int | ad74416h_init (struct ad74416h_desc **desc, struct ad74416h_init_param *init_param) |
| Initialize the device structure. | |
| int | ad74416h_remove (struct ad74416h_desc *desc) |
| Free the device descriptor. | |
Source file of AD74416H Driver.
Copyright 2023(c) Analog Devices, Inc.
SPDX-License-Identifier: BSD-3-Clause
| #define AD74416H_CRC_POLYNOMIAL 0x7 |
| #define AD74416H_DIN_DEBOUNCE_LEN NO_OS_BIT(5) |
| #define AD77416H_DEV_ADDRESS_MSK NO_OS_GENMASK(5, 4) |
| int ad74416h_dac_current_to_code | ( | struct ad74416h_desc * | desc, |
| uint32_t | uamps, | ||
| uint16_t * | code ) |
Convers a microamp value in the corresponding DAC 16 bit code.
| desc | - The device structure. |
| uamps | - The microamps value |
| code | - The resulting DAC code |
| int ad74416h_dac_slew_disable | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch ) |
Disable the slew rate control.
| desc | - The device structure. |
| ch | - The channel index. |
| int ad74416h_dac_slew_enable | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| enum ad74416h_slew_lin_step | step, | ||
| enum ad74416h_lin_rate | rate ) |
Configure and enable slew rate control for a DAC on a specific channel.
| desc | - The device structure. |
| ch | - The channel index. |
| step | - Number of codes per increment. |
| rate | - Number of increments per second. |
| int ad74416h_dac_voltage_to_code | ( | struct ad74416h_desc * | desc, |
| int32_t | mvolts, | ||
| uint16_t * | code, | ||
| uint32_t | ch ) |
Converts a millivolt value in the corresponding DAC 16 bit code.
| desc | - The device structure. |
| mvolts | - The millivolts value. |
| code | - The resulting DAC code. |
| ch | - The channel index. |
| int ad74416h_do_set | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| uint8_t | val ) |
Set the DO value of a channel.
| desc | - The device structure |
| ch | - The channel index |
| val | - the output logic state. 0-low 1-high |
| int ad74416h_get_adc_conv_mux | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| enum ad74416h_adc_conv_mux * | val ) |
Get the ADC Input Node for conversion.
| desc | - The device structure. |
| ch | - The channel index. |
| val | - The ADC input node setting. |
| int ad74416h_get_adc_range | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| uint16_t * | val ) |
Get the ADC measurement range for a specific channel.
| desc | - The device structure. |
| ch | - The channel index. |
| val | - The ADC range value. |
| int ad74416h_get_adc_rate | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| enum ad74416h_adc_rate * | val ) |
Get the ADC Conversion Rate for a specific channel.
| desc | - The device structure. |
| ch | - The channel index. |
| val | - The ADC rejection setting. |
| int ad74416h_get_adc_single | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| uint32_t * | val ) |
Get a single ADC raw value for a specific channel, then power down the ADC.
| desc | - The device structure. |
| ch | - The channel index. |
| val | - The ADC raw result. |
| int ad74416h_get_diag | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| uint16_t * | diag_code ) |
Get the diagnostic value for a specific channel.
| desc | - The device structure. |
| ch | - The channel index. |
| diag_code | - The diagnostic setting. |
| int ad74416h_get_live | ( | struct ad74416h_desc * | desc, |
| union ad74416h_live_status * | status ) |
Read the live status bits.
| desc | - The device structure. |
| status | - The register's value. |
| int ad74416h_get_raw_adc_result | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| uint32_t * | val ) |
Read the raw ADC raw conversion value.
| desc | - The device structure. |
| ch | - The channel index. |
| val | - The ADC raw conversion value. |
| int ad74416h_get_temp | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| uint16_t * | temp ) |
Read the die's temperature from the diagnostic register.
| desc | - The device structure. |
| ch | - The diagnostic channel on which the temperature reading is assigned and enabled. |
| temp | - The measured temperature (in degrees Celsius). |
| int ad74416h_gpio_get | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| uint8_t * | val ) |
Get the GPO value for a specific channel.
| desc | - The device structure. |
| ch | - The channel index. |
| val | - The debounce time. |
| int ad74416h_gpio_set | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| uint8_t | val ) |
Set the logic value of a GPO pin.
| desc | - The device structure. |
| ch | - The channel index. |
| val | - The output logic state. |
| int ad74416h_init | ( | struct ad74416h_desc ** | desc, |
| struct ad74416h_init_param * | init_param ) |
Initialize the device structure.
| desc | - The device structure to be initialized. |
| init_param | - Initialization parameter for the device descriptor. |
| int ad74416h_nb_active_channels | ( | struct ad74416h_desc * | desc, |
| uint8_t * | nb_channels ) |
Get the number of active channels.
| desc | - The device structure. |
| nb_channels | - The number of active channels |
| int ad74416h_reg_read | ( | struct ad74416h_desc * | desc, |
| uint32_t | addr, | ||
| uint16_t * | val ) |
Read a register's value.
| desc | - The device structure. |
| addr | - The register's address. |
| val | - The register's read value. |
| int ad74416h_reg_read_raw | ( | struct ad74416h_desc * | desc, |
| uint32_t | addr, | ||
| uint8_t * | val ) |
Read a raw communication frame.
| desc | - The device structure. |
| addr | - The register's address. |
| val | - A raw comm frame. |
Reading a register on AD74416H requires writing the address to the READ_SELECT register first and then doing another spi read, which will contain the requested register value.
| int ad74416h_reg_update | ( | struct ad74416h_desc * | desc, |
| uint32_t | addr, | ||
| uint16_t | mask, | ||
| uint16_t | val ) |
Update a register's field.
| desc | - The device structure. |
| addr | - The register's address. |
| val | - The register's value. |
| mask | - The mask for a specific register field. |
| int ad74416h_reg_write | ( | struct ad74416h_desc * | desc, |
| uint32_t | addr, | ||
| uint16_t | val ) |
Write a register's value.
| desc | - The device structure. |
| addr | - The register's address. |
| val | - The register's value. |
| int ad74416h_remove | ( | struct ad74416h_desc * | desc | ) |
Free the device descriptor.
| desc | - The device structure. |
| int ad74416h_reset | ( | struct ad74416h_desc * | desc | ) |
Perform software or hardware reset and wait for device reset time.
| desc | - The device structure. |
| int ad74416h_set_adc_channel_enable | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| bool | status ) |
Enable/disable a specific ADC channel.
| desc | - The device structure. |
| ch | - The channel index. |
| status | - Enabled or disabled status. |
| int ad74416h_set_adc_conv_mux | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| enum ad74416h_adc_conv_mux | val ) |
Set the ADC Input Node for conversion.
| desc | - The device structure |
| ch | - The channel index. |
| val | - The ADC input node setting. |
| int ad74416h_set_adc_conv_seq | ( | struct ad74416h_desc * | desc, |
| enum ad74416h_conv_seq | status ) |
Start or stop ADC conversions.
| desc | - The device structure. |
| status | - The ADC conversion sequence. |
If the ADC was powered down, wait for 100us before the ADC starts doing conversions.
| int ad74416h_set_adc_range | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| enum ad74416h_adc_range | val ) |
Set the ADC measurement range for a specific channel.
| desc | - The device structure. |
| ch | - The channel index. |
| val | - The ADC range value. |
| int ad74416h_set_adc_rate | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| enum ad74416h_adc_rate | val ) |
Set the ADC Conversion Rate for a specific channel.
| desc | - The device structure. |
| ch | - The channel index. |
| val | - The ADC rejection setting. |
| int ad74416h_set_channel_dac_code | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| uint16_t | dac_code ) |
Set and load a code for the DAC on a specific channel.
| desc | - The device structure. |
| ch | - The channel index. |
| dac_code | - The code for the DAC. |
| int ad74416h_set_channel_function | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| enum ad74416h_op_mode | ch_func ) |
Set the operation mode for a specific channel.
| desc | - The device structure. |
| ch | - The channel index. |
| ch_func | - The operation mode. |
| int ad74416h_set_channel_i_limit | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| enum ad74416h_i_limit | i_limit ) |
Set the current limit for a specific DAC channel in vout mode.
| desc | - The devices structure |
| ch | - The channel index |
| i_limit | - The current limit |
| int ad74416h_set_channel_vout_range | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| enum ad74416h_vout_range | vout_range ) |
Set the voltage range for a specific channel.
| desc | - The device structure. |
| ch | - The channel index. |
| vout_range | - The voltage range. |
| int ad74416h_set_debounce_mode | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| enum ad74416h_debounce_mode | mode ) |
Set the debounce mode for the IOx inputs when the ADC is running in digital input mode.
| desc | - The device structure. |
| ch | - The channel index. |
| mode | - The debounce mode. |
| int ad74416h_set_debounce_time | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| uint32_t | time ) |
Set the debounce settle time for the IOx inputs when the ADC is running in digital input mode.
| desc | - The device structure. |
| ch | - The channel index. |
| time | - The debounce time. |
| int ad74416h_set_diag | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| enum ad74416h_diag_mode | diag_code ) |
Set which diagnostic value to be loaded in the DIAG_RESULT register.
| desc | - The device structure. |
| ch | - The channel index. |
| diag_code | - The diagnostic setting. |
| int ad74416h_set_diag_channel_enable | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| bool | status ) |
Enable conversions on a diagnostic register.
| desc | - The device structure. |
| ch | - Diagnostic channel index. |
| status | - Enabled or disabled status. |
| int ad74416h_set_gpio_config | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| enum ad74416h_gpio_select | config ) |
Set the GPIO operation mode.
| desc | - The device structure. |
| ch | - The channel index. |
| config | - The configuration setting. |
| int ad74416h_set_therm_rst | ( | struct ad74416h_desc * | desc, |
| bool | enable ) |
Enable or disable the higher thermal reset.
| desc | - The device structure. |
| enable | - The thermal reset status. false: reset at 110 deg. Celsius. true: reset at 140 deg. Celsius. |
| int ad74416h_set_threshold | ( | struct ad74416h_desc * | desc, |
| uint32_t | ch, | ||
| uint32_t | threshold ) |
Set the threshold, for which a signal would be considered high, when the ADC is running in digital input mode.
| desc | - The device structure. |
| ch | - The channel index. |
| threshold | - The threshold value (in millivolts). |
Set a fixed range (0 - 16 V) for the threshold, so it would not depend on Vadd.
| NO_OS_DECLARE_CRC8_TABLE | ( | _crc_table | ) |