no-OS
Loading...
Searching...
No Matches
ad7156.c File Reference

Implementation of AD7156 Driver. More...

#include <stdlib.h>
#include "ad7156.h"
#include "no_os_alloc.h"
Include dependency graph for ad7156.c:

Functions

void ad7156_get_register_value (struct ad7156_dev *dev, uint8_t *p_read_data, uint8_t register_address, uint8_t bytes_number)
 Performs a burst read of a specified number of registers.
 
void ad7156_set_register_value (struct ad7156_dev *dev, uint16_t register_value, uint8_t register_address, uint8_t bytes_number)
 Writes data into one or two registers.
 
int8_t ad7156_init (struct ad7156_dev **device, struct ad7156_init_param init_param)
 Initializes the communication peripheral and the initial Values for AD7156 Board.
 
int32_t ad7156_remove (struct ad7156_dev *dev)
 Free the resources allocated by ad7156_init().
 
void ad7156_reset (struct ad7156_dev *dev)
 Resets the device.
 
void ad7156_set_power_mode (struct ad7156_dev *dev, uint8_t pwr_mode)
 Sets the converter mode of operation.
 
void ad7156_channel_state (struct ad7156_dev *dev, uint8_t channel, uint8_t enable_conv)
 Enables or disables conversion on the selected channel.
 
void ad7156_set_range (struct ad7156_dev *dev, uint32_t channel, uint8_t range)
 Sets the input range of the specified channel.
 
float ad7156_get_range (struct ad7156_dev *dev, uint32_t channel)
 Reads the range bits from the device and returns the range in pF.
 
void ad7156_set_threshold_mode (struct ad7156_dev *dev, uint8_t thr_mode, uint8_t thr_fixed)
 Selects the threshold mode of operation.
 
void ad7156_set_threshold (struct ad7156_dev *dev, uint8_t channel, float p_fthr)
 Writes to the threshold register when threshold fixed mode is enabled.
 
void ad7156_set_sensitivity (struct ad7156_dev *dev, uint8_t channel, float p_fsensitivity)
 Writes a value(pF) to the sensitivity register. This functions should be used when adaptive threshold mode is selected.
 
uint16_t ad7156_read_channel_data (struct ad7156_dev *dev, uint8_t channel)
 Reads a 12-bit sample from the selected channel.
 
uint16_t ad7156_wait_read_channel_data (struct ad7156_dev *dev, uint8_t channel)
 Waits for a finished CDC conversion and reads a 12-bit sample from the selected channel.
 
float ad7156_read_channel_capacitance (struct ad7156_dev *dev, uint8_t channel)
 Reads a sample the selected channel and converts the data to picofarads(pF).
 
float ad7156_wait_read_channel_capacitance (struct ad7156_dev *dev, uint8_t channel)
 Waits for a finished CDC conversion the selected channel, reads a sample and converts the data to picofarads(pF).
 

Detailed Description

Implementation of AD7156 Driver.

Author
DNechita(Dan.N.nosp@m.echi.nosp@m.ta@an.nosp@m.alog.nosp@m..com)

Copyright 2013(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ ad7156_channel_state()

void ad7156_channel_state ( struct ad7156_dev * dev,
uint8_t channel,
uint8_t enable_conv )

Enables or disables conversion on the selected channel.

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
enable_conv- The state of channel activity. Example: 0 - disable conversion on selected channel. 1 - enable conversion on selected channel.

◆ ad7156_get_range()

float ad7156_get_range ( struct ad7156_dev * dev,
uint32_t channel )

Reads the range bits from the device and returns the range in pF.

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
Returns
The capacitive input range(pF).

◆ ad7156_get_register_value()

void ad7156_get_register_value ( struct ad7156_dev * dev,
uint8_t * p_read_data,
uint8_t register_address,
uint8_t bytes_number )

Performs a burst read of a specified number of registers.

Parameters
dev- The device structure.
p_read_data- The read values are stored in this buffer.
register_address- The start address of the burst read.
bytes_number- Number of bytes to read.

◆ ad7156_init()

int8_t ad7156_init ( struct ad7156_dev ** device,
struct ad7156_init_param init_param )

Initializes the communication peripheral and the initial Values for AD7156 Board.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
ret - The result of the initialization procedure. Example: -1 - I2C peripheral was not initialized or the device is not present. 0 - I2C peripheral was initialized and the device is present.

◆ ad7156_read_channel_capacitance()

float ad7156_read_channel_capacitance ( struct ad7156_dev * dev,
uint8_t channel )

Reads a sample the selected channel and converts the data to picofarads(pF).

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
Returns
Conversion result form the selected channel as picofarads(pF).

◆ ad7156_read_channel_data()

uint16_t ad7156_read_channel_data ( struct ad7156_dev * dev,
uint8_t channel )

Reads a 12-bit sample from the selected channel.

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
Returns
Conversion result form the selected channel.

◆ ad7156_remove()

int32_t ad7156_remove ( struct ad7156_dev * dev)

Free the resources allocated by ad7156_init().

Parameters
dev- The device structure.
Returns
ret - The result of the remove procedure.

◆ ad7156_reset()

void ad7156_reset ( struct ad7156_dev * dev)

Resets the device.

Parameters
dev- The device structure.

◆ ad7156_set_power_mode()

void ad7156_set_power_mode ( struct ad7156_dev * dev,
uint8_t pwr_mode )

Sets the converter mode of operation.

Parameters
dev- The device structure.
pwr_mode- Mode of operation option. Example: AD7156_CONV_MODE_IDLE - Idle AD7156_CONV_MODE_CONT_CONV - Continuous conversion AD7156_CONV_MODE_SINGLE_CONV - Single conversion AD7156_CONV_MODE_PWR_DWN - Power-down

◆ ad7156_set_range()

void ad7156_set_range ( struct ad7156_dev * dev,
uint32_t channel,
uint8_t range )

Sets the input range of the specified channel.

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
range- Input range option. Example: AD7156_CDC_RANGE_2_PF - 2pF input range. AD7156_CDC_RANGE_0_5_PF - 0.5pF input range. AD7156_CDC_RANGE_1_PF - 1pF input range. AD7156_CDC_RANGE_4_PF - 4pF input range.

◆ ad7156_set_register_value()

void ad7156_set_register_value ( struct ad7156_dev * dev,
uint16_t register_value,
uint8_t register_address,
uint8_t bytes_number )

Writes data into one or two registers.

Parameters
dev- The device structure.
register_value- Data value to write.
register_address- Address of the register.
bytes_number- Number of bytes. Accepted values: 0 - 1.

◆ ad7156_set_sensitivity()

void ad7156_set_sensitivity ( struct ad7156_dev * dev,
uint8_t channel,
float p_fsensitivity )

Writes a value(pF) to the sensitivity register. This functions should be used when adaptive threshold mode is selected.

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
p_fsensitivity- The sensitivity value in picofarads(pF).

◆ ad7156_set_threshold()

void ad7156_set_threshold ( struct ad7156_dev * dev,
uint8_t channel,
float p_fthr )

Writes to the threshold register when threshold fixed mode is enabled.

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
p_fthr- The threshold value in picofarads(pF). The value must not be out of the selected input range.

◆ ad7156_set_threshold_mode()

void ad7156_set_threshold_mode ( struct ad7156_dev * dev,
uint8_t thr_mode,
uint8_t thr_fixed )

Selects the threshold mode of operation.

Parameters
dev- The device structure.
thr_mode- Output comparator mode. Example: AD7156_THR_MODE_NEGATIVE AD7156_THR_MODE_POSITIVE AD7156_THR_MODE_IN_WINDOW AD7156_THR_MODE_OU_WINDOW
thr_fixed- Selects the threshold mode. Example: AD7156_ADAPTIVE_THRESHOLD AD7156_FIXED_THRESHOLD

◆ ad7156_wait_read_channel_capacitance()

float ad7156_wait_read_channel_capacitance ( struct ad7156_dev * dev,
uint8_t channel )

Waits for a finished CDC conversion the selected channel, reads a sample and converts the data to picofarads(pF).

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
Returns
Conversion result form the selected channel as picofarads(pF).

◆ ad7156_wait_read_channel_data()

uint16_t ad7156_wait_read_channel_data ( struct ad7156_dev * dev,
uint8_t channel )

Waits for a finished CDC conversion and reads a 12-bit sample from the selected channel.

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
Returns
Conversion result form the selected channel.