no-OS
Functions
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. More...
 
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. More...
 
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. More...
 
int32_t ad7156_remove (struct ad7156_dev *dev)
 Free the resources allocated by ad7156_init(). More...
 
void ad7156_reset (struct ad7156_dev *dev)
 Resets the device. More...
 
void ad7156_set_power_mode (struct ad7156_dev *dev, uint8_t pwr_mode)
 Sets the converter mode of operation. More...
 
void ad7156_channel_state (struct ad7156_dev *dev, uint8_t channel, uint8_t enable_conv)
 Enables or disables conversion on the selected channel. More...
 
void ad7156_set_range (struct ad7156_dev *dev, uint32_t channel, uint8_t range)
 Sets the input range of the specified channel. More...
 
float ad7156_get_range (struct ad7156_dev *dev, uint32_t channel)
 Reads the range bits from the device and returns the range in pF. More...
 
void ad7156_set_threshold_mode (struct ad7156_dev *dev, uint8_t thr_mode, uint8_t thr_fixed)
 Selects the threshold mode of operation. More...
 
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. More...
 
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. More...
 
uint16_t ad7156_read_channel_data (struct ad7156_dev *dev, uint8_t channel)
 Reads a 12-bit sample from the selected channel. More...
 
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. More...
 
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). More...
 
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). More...
 

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.

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

◆ 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.
Returns
None.

◆ 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).
Here is the caller graph for this function:

◆ 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.
Returns
None.
Here is the caller graph for this function:

◆ 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.
Here is the caller graph for this function:

◆ 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.
Returns
None.

◆ 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
Returns
None.

◆ 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.
Returns
None.

◆ 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.
Returns
None.
Here is the caller graph for this function:

◆ 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).
Returns
None.

◆ 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.
Returns
None.

◆ 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
Returns
None.

◆ 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.
Here is the caller graph for this function: