no-OS
Functions
max22200.c File Reference

Source file of MAX22200 Driver. More...

#include <no_os_error.h>
#include <stdlib.h>
#include <string.h>
#include "max22200.h"
#include "no_os_util.h"
#include "no_os_alloc.h"
#include "no_os_delay.h"
Include dependency graph for max22200.c:

Functions

int max22200_reg_read (struct max22200_desc *desc, uint32_t reg, uint32_t *val)
 Read data from desired register for MAX22200. More...
 
int max22200_reg_write (struct max22200_desc *desc, uint32_t reg, uint32_t val)
 Write data to desired register for MAX22200. More...
 
int max22200_reg_update (struct max22200_desc *desc, uint32_t reg, uint32_t mask, uint32_t val)
 Update data in the desired register. More...
 
int max22200_set_trig_state (struct max22200_desc *desc, bool trig_state)
 Set external trigger's state of the MAX22200. More...
 
int max22200_set_ch_state (struct max22200_desc *desc, uint32_t ch, bool ch_state)
 Set channel state for specific channel. More...
 
int max22200_fault_mask_set (struct max22200_desc *desc, enum max22200_fault_mask fault_mask, bool enabled)
 Set fault mask bits in the status register. More...
 
int max22200_set_chop_freq (struct max22200_desc *desc, enum max22200_chopping_freq chopping_freq)
 Set chopping frequency value. More...
 
int max22200_set_ch_hit (struct max22200_desc *desc, uint32_t ch, uint8_t hit_current, uint8_t hit_time)
 Set channel HIT time and HIT current. More...
 
int max22200_set_ch_hold (struct max22200_desc *desc, uint32_t ch, uint8_t hold_current)
 Set channel hold current. More...
 
int max22200_set_ch_scale (struct max22200_desc *desc, uint32_t ch, enum max22200_scale scale)
 Set channel's scale to fullscale or half fullscale. More...
 
int max22200_set_ch_trig (struct max22200_desc *desc, uint32_t ch, enum max22200_trig trig)
 Set channel's trigger to be either SPI or external trigger. More...
 
int max22200_set_ch_mode (struct max22200_desc *desc, uint32_t ch, enum max22200_ch_drive ch_drive, enum max22200_ch_side ch_side, enum max22200_ch_op_mode ch_op_mode)
 Set chanmel operation mode, high-side/low-side and drive. More...
 
int max22200_set_ch_freq (struct max22200_desc *desc, uint32_t ch, enum max22200_ch_freq ch_freq)
 Set channel's frequency. More...
 
int max22200_set_ch_enable (struct max22200_desc *desc, uint32_t ch, enum max22200_ch_enable ch_enable, bool enabled)
 Set channel's enables for different checks, detection and functions. More...
 
int max22200_set_cfg_dpm (struct max22200_desc *desc, uint8_t dpm_istart_byte, uint8_t dpm_tdeb_ipth_byte)
 Set configuration DPM. More...
 
int max22200_fault_mask_get (struct max22200_desc *desc, enum max22200_fault_mask fault_mask, bool *enabled)
 Fault mask bit get function. More...
 
int max22200_get_ch_state (struct max22200_desc *desc, uint32_t ch, bool *ch_state)
 Read the state of a channel. More...
 
int max22200_get_chop_freq (struct max22200_desc *desc, enum max22200_chopping_freq *chopping_freq)
 Read chopping frequency. More...
 
int max22200_get_ch_hit (struct max22200_desc *desc, uint32_t ch, uint8_t *hit_current, uint8_t *hit_time)
 Read channel HIT configuration. More...
 
int max22200_get_ch_hold (struct max22200_desc *desc, uint32_t ch, uint8_t *hold_current)
 Read channel HOLD configuration. More...
 
int max22200_get_ch_scale (struct max22200_desc *desc, uint32_t ch, enum max22200_scale *scale)
 Read channel's scale. More...
 
int max22200_get_ch_trig (struct max22200_desc *desc, uint32_t ch, enum max22200_trig *trig)
 Read channel's selected trigger for specific channel. More...
 
int max22200_get_ch_mode (struct max22200_desc *desc, uint32_t ch, enum max22200_ch_drive *ch_drive, enum max22200_ch_side *ch_side, enum max22200_ch_op_mode *ch_op_mode)
 Read channel's mode configuration. More...
 
int max22200_get_ch_freq (struct max22200_desc *desc, uint32_t ch, enum max22200_ch_freq *ch_freq)
 Read channel's frequency. More...
 
int max22200_get_ch_enable (struct max22200_desc *desc, uint32_t ch, enum max22200_ch_enable ch_enable, bool *enabled)
 Read channel's enable bits state. More...
 
int max22200_get_cfg_dpm (struct max22200_desc *desc, uint8_t *dpm_istart_byte, uint8_t *dpm_tdeb_ipth_byte)
 Read configuration for the detection of the plunger movement of the device. More...
 
int max22200_init (struct max22200_desc **desc, struct max22200_init_param *init_param)
 MAX22200 descriptor initialization function. More...
 
int max22200_remove (struct max22200_desc *desc)
 Deallocates all the resources used at initialization. More...
 

Detailed Description

Source file of MAX22200 Driver.

Author
Radu Sabau (radu..nosp@m.saba.nosp@m.u@ana.nosp@m.log..nosp@m.com)

Copyright 2023(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

◆ max22200_fault_mask_get()

int max22200_fault_mask_get ( struct max22200_desc desc,
enum max22200_fault_mask  fault_mask,
bool enabled 
)

Fault mask bit get function.

Parameters
desc- MAX22200 device descriptor.
fault_mask- Fault mask specific bit to read the state for.
enabled- State of the bit.
Returns
0 in case of succes, negative error code otherwise.

◆ max22200_fault_mask_set()

int max22200_fault_mask_set ( struct max22200_desc desc,
enum max22200_fault_mask  fault_mask,
bool  enabled 
)

Set fault mask bits in the status register.

Parameters
desc- MAX22200 device descriptor.
fault_mask- Desired fault mask bit to set.
enabled- enabled/disabled state of the mask.
Returns
0 in case of succes, negative error code otherwise.

◆ max22200_get_cfg_dpm()

int max22200_get_cfg_dpm ( struct max22200_desc desc,
uint8_t *  dpm_istart_byte,
uint8_t *  dpm_tdeb_ipth_byte 
)

Read configuration for the detection of the plunger movement of the device.

Parameters
desc- MAX22200 device descriptor.
dpm_istart_byte- Detection of plunger movement starting current value.
dpm_tdeb_ipth_byte- Detection of plunger movement debounce time value.
Returns
0 in case of succes, negative error code otherwise.

◆ max22200_get_ch_enable()

int max22200_get_ch_enable ( struct max22200_desc desc,
uint32_t  ch,
enum max22200_ch_enable  ch_enable,
bool enabled 
)

Read channel's enable bits state.

Parameters
desc- MAX22200 device descriptor.
ch- Channel's number (0 based).
ch_enable- Requested channel enable bit to read the state for.
enabled- Requested enabled bit state.
Returns
0 in case of succes, negative error code otherwise.

◆ max22200_get_ch_freq()

int max22200_get_ch_freq ( struct max22200_desc desc,
uint32_t  ch,
enum max22200_ch_freq ch_freq 
)

Read channel's frequency.

Parameters
desc- MAX22200 device descriptor.
ch- Channel's number (0 based).
ch_freq- Channel's frequency value read from the device.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_get_ch_hit()

int max22200_get_ch_hit ( struct max22200_desc desc,
uint32_t  ch,
uint8_t *  hit_current,
uint8_t *  hit_time 
)

Read channel HIT configuration.

Parameters
desc- MAX22200 device descriptor.
ch- Channel's number (0 based).
hit_current- HIT current value read from the device.
hit_time- HIT time value read from the device.
Returns
0 in case of succes, negative error code otherwise.

◆ max22200_get_ch_hold()

int max22200_get_ch_hold ( struct max22200_desc desc,
uint32_t  ch,
uint8_t *  hold_current 
)

Read channel HOLD configuration.

Parameters
desc- MAX22200 device descriptor.
ch- Channel's number (0 based).
hold_current- HOLD current value read from the device.
Returns
0 in case of succes, negative error code otherwise.

◆ max22200_get_ch_mode()

int max22200_get_ch_mode ( struct max22200_desc desc,
uint32_t  ch,
enum max22200_ch_drive ch_drive,
enum max22200_ch_side ch_side,
enum max22200_ch_op_mode ch_op_mode 
)

Read channel's mode configuration.

Parameters
desc- MAX22200 device descriptor.
ch- Channel's number (0 based).
ch_drive- Channel's drive read from the device.
ch_side- Channel's high-side/low-side configuraton read from the device.
ch_op_mode- Channel's operation mode read from the device.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_get_ch_scale()

int max22200_get_ch_scale ( struct max22200_desc desc,
uint32_t  ch,
enum max22200_scale scale 
)

Read channel's scale.

Parameters
desc- MAX22200 device descriptor.
ch- Channel's number (0 based).
scale- Scale read from device's channel.
Returns
0 in case of succes, negative error code otherwise.

◆ max22200_get_ch_state()

int max22200_get_ch_state ( struct max22200_desc desc,
uint32_t  ch,
bool ch_state 
)

Read the state of a channel.

Parameters
desc- MAX22200 device descriptor
ch- Channel number (0 based).
ch_state- State of the channel.
Returns
0 in case of succes, negative error code otherwise.

◆ max22200_get_ch_trig()

int max22200_get_ch_trig ( struct max22200_desc desc,
uint32_t  ch,
enum max22200_trig trig 
)

Read channel's selected trigger for specific channel.

Parameters
desc- MAX22200 device descriptor.
ch- Channel's number (0 based).
trig- Selected trigger for the channel requested read from the device.
Returns
0 in case of succes, negative error code otherwise.

◆ max22200_get_chop_freq()

int max22200_get_chop_freq ( struct max22200_desc desc,
enum max22200_chopping_freq chopping_freq 
)

Read chopping frequency.

Parameters
desc- MAX22200 device descriptor.
chopping_freq- Pointer of the variable holding the value of the chopping frequency.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_init()

int max22200_init ( struct max22200_desc **  desc,
struct max22200_init_param init_param 
)

MAX22200 descriptor initialization function.

Parameters
desc- MAX22200 device descriptor.
init_param- Initialization parameter containing data about the device descriptor to be initialized.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_reg_read()

int max22200_reg_read ( struct max22200_desc desc,
uint32_t  reg,
uint32_t *  val 
)

Read data from desired register for MAX22200.

Parameters
desc- MAX22200 device descriptor.
reg- Register address to read data from.
val- Value read from the register.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_reg_update()

int max22200_reg_update ( struct max22200_desc desc,
uint32_t  reg,
uint32_t  mask,
uint32_t  val 
)

Update data in the desired register.

Parameters
desc- MAX22200 device descriptor.
reg- Register address to update data to.
mask- Bit mask of the field to be updated.
val- Value to be updated in the desired register. Should be bit shifted by using no_os_field_prep(mask, val)
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_reg_write()

int max22200_reg_write ( struct max22200_desc desc,
uint32_t  reg,
uint32_t  val 
)

Write data to desired register for MAX22200.

Parameters
desc- MAXX22200 device descriptor.
reg- Register address to write data to.
val- Value to be written to the register.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_remove()

int max22200_remove ( struct max22200_desc desc)

Deallocates all the resources used at initialization.

Parameters
desc- MAX22200 device descriptor.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_set_cfg_dpm()

int max22200_set_cfg_dpm ( struct max22200_desc desc,
uint8_t  dpm_istart_byte,
uint8_t  dpm_tdeb_ipth_byte 
)

Set configuration DPM.

Parameters
desc- MAX22200 device descriptor.
dpm_istart_byte- Detection of plunger movement starting current
dpm_tdeb_ipth_byte- Detection of plunger movement debounce time.
Returns
0 in case of succes, negative error code otherwise.

◆ max22200_set_ch_enable()

int max22200_set_ch_enable ( struct max22200_desc desc,
uint32_t  ch,
enum max22200_ch_enable  ch_enable,
bool  enabled 
)

Set channel's enables for different checks, detection and functions.

Parameters
desc- MAX22200 device descriptor.
ch- Channel's number (0 based).
ch_enable- Channel enable to be set.
enabled- Disabled/Enabled state.
Returns
0 in case of succes, negative error code otherwise.

◆ max22200_set_ch_freq()

int max22200_set_ch_freq ( struct max22200_desc desc,
uint32_t  ch,
enum max22200_ch_freq  ch_freq 
)

Set channel's frequency.

Parameters
desc- MAX22200 device descriptor
ch- Channel's number (0 based).
ch_freq- 80KHz/100KHz frequency.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_set_ch_hit()

int max22200_set_ch_hit ( struct max22200_desc desc,
uint32_t  ch,
uint8_t  hit_current,
uint8_t  hit_time 
)

Set channel HIT time and HIT current.

Parameters
desc- MAX22200 device descriptor.
ch- Channel for which HIT time is to be set.(0 based)
hit_current- HIT current value, it shall not be greater than 127 since the value is stored only on 7 bits in the channel's configuration register.
hit_time- HIT time value to be set.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_set_ch_hold()

int max22200_set_ch_hold ( struct max22200_desc desc,
uint32_t  ch,
uint8_t  hold_current 
)

Set channel hold current.

Parameters
desc- MAX22200 device descriptor.
ch- Channel's number (0 based).
hold_current- Hold current value to be set. It shall not be greater than 127 since the value it's stored on 7 bits in the channel's configuration register.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_set_ch_mode()

int max22200_set_ch_mode ( struct max22200_desc desc,
uint32_t  ch,
enum max22200_ch_drive  ch_drive,
enum max22200_ch_side  ch_side,
enum max22200_ch_op_mode  ch_op_mode 
)

Set chanmel operation mode, high-side/low-side and drive.

Parameters
desc- MAX22200 device descriptor.
ch- Channel number (0 based).
ch_drive- Voltage/Current drive.
ch_side- High-Side/Low-Side.
ch_op_mode- Independent/Half-Bridge/Full-Bridge mode.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_set_ch_scale()

int max22200_set_ch_scale ( struct max22200_desc desc,
uint32_t  ch,
enum max22200_scale  scale 
)

Set channel's scale to fullscale or half fullscale.

Parameters
desc- MAX22200 device dscriptor.
ch- Channel's number (0 based).
scale- Scale value.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_set_ch_state()

int max22200_set_ch_state ( struct max22200_desc desc,
uint32_t  ch,
bool  ch_state 
)

Set channel state for specific channel.

Parameters
desc- MAX22200 device descriptor.
ch- Channel number.
ch_state- Channel's state to be changed into.
Returns
0 in case of succces, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_set_ch_trig()

int max22200_set_ch_trig ( struct max22200_desc desc,
uint32_t  ch,
enum max22200_trig  trig 
)

Set channel's trigger to be either SPI or external trigger.

Parameters
desc- MAX22200 device descriptor.
ch- Channel's number (0 based).
trig- Trigger to be set. If external trigger is requested but no external's trigger descriptor was initialized, will return negative error code.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_set_chop_freq()

int max22200_set_chop_freq ( struct max22200_desc desc,
enum max22200_chopping_freq  chopping_freq 
)

Set chopping frequency value.

Parameters
desc- MAX22200 device descriptor.
chopping_freq- Chopping frequency value.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ max22200_set_trig_state()

int max22200_set_trig_state ( struct max22200_desc desc,
bool  trig_state 
)

Set external trigger's state of the MAX22200.

Parameters
desc- MAX22200 device descriptor.
trig_state- State to change to.
Returns
0 in case of succes, negative error code otherwise.