no-OS
Functions | Variables
ltc4306.c File Reference

Implementation of ltc4306 driver. More...

#include <stdint.h>
#include <stdlib.h>
#include "no_os_i2c.h"
#include "no_os_util.h"
#include "no_os_error.h"
#include "no_os_alloc.h"
#include "ltc4306.h"
Include dependency graph for ltc4306.c:

Functions

int ltc4306_init (struct ltc4306_dev **device, struct ltc4306_init_param init_param)
 Initializes the communication peripheral and checks if the ltc4306 part is present. More...
 
int ltc4306_remove (struct ltc4306_dev *dev)
 Free the resources allocated by ltc4306_init(). More...
 
int ltc4306_write (struct ltc4306_dev *dev, uint8_t addr, uint8_t *write_data, uint8_t bytes)
 Writes data into a register (I2C). More...
 
int ltc4306_read (struct ltc4306_dev *dev, uint8_t addr, uint8_t *read_data, uint8_t bytes)
 Reads the value of a register. More...
 
int ltc4306_reg_update (struct ltc4306_dev *dev, uint8_t addr, int update_mask, int update_val)
 Update selected I2C register contents. More...
 
int ltc4306_addr_gen (struct ltc4306_init_param *init_param, enum ltc4306_addr_conn addr0, enum ltc4306_addr_conn addr1, enum ltc4306_addr_conn addr2)
 Gives the equivalent hex device address based on the input combination of addr0, addr1, and addr2. (27 possible device address) More...
 
int ltc4306_downstream_check (struct ltc4306_dev *dev, bool *downstream_conn)
 Get downstream connect bit status to see if any downstream bus connected. More...
 
int ltc4306_read_alert_logic_state (struct ltc4306_dev *dev, uint8_t alert_pin_number, bool *is_high)
 Reads Alert Logic State of selected ALERT pin. More...
 
int ltc4306_read_failed_conn (struct ltc4306_dev *dev, bool *is_high)
 Reads Failed Connection Attempt bit. More...
 
int ltc4306_get_latched_timeout (struct ltc4306_dev *dev, bool *timed_out)
 Reads Latched Timeout status. More...
 
int ltc4306_get_realtime_timeout (struct ltc4306_dev *dev, bool *timed_out)
 Reads Realtime Timeout status. More...
 
int ltc4306_set_upstream_accel (struct ltc4306_dev *dev, bool upstream_en)
 En/Disables upstream accelerator. More...
 
int ltc4306_get_upstream_accel (struct ltc4306_dev *dev, bool *upstream_en)
 Get status of upstream accelerator enable bit field. More...
 
int ltc4306_set_downstream_accel (struct ltc4306_dev *dev, bool downstream_en)
 En/Disables downstream accelerator. More...
 
int ltc4306_get_downstream_accel (struct ltc4306_dev *dev, bool *downstream_en)
 Get status of downstream accelerator enable bit field. More...
 
int ltc4306_set_gpio_output_state (struct ltc4306_dev *dev, int gpio, bool is_high)
 Sets GPIO Output Driver state. More...
 
int ltc4306_get_gpio_output_state (struct ltc4306_dev *dev, int gpio, bool *is_high)
 Gets GPIO Output Driver state. More...
 
int ltc4306_read_gpio_logic_state (struct ltc4306_dev *dev, int gpio, bool *is_high)
 Reads logic of selected GPIO. More...
 
int ltc4306_set_conn_req (struct ltc4306_dev *dev, bool connect_regardless)
 Sets Connection Requirement bit field. More...
 
int ltc4306_get_conn_req (struct ltc4306_dev *dev, bool *connect_regardless)
 Gets Connection Requirement bit field. More...
 
int ltc4306_gpio_configure (struct ltc4306_dev *dev, bool gpio1, bool gpio2, bool gpio1_is_pushpull, bool gpio2_is_pushpull)
 Configures GPIO1 and GPIO2 as input or output mode. If selected as output mode, can be configured as open-drain or push-pull. More...
 
int ltc4306_set_mass_write (struct ltc4306_dev *dev, bool mass_write_en)
 Enables Mass Write. More...
 
int ltc4306_get_mass_write (struct ltc4306_dev *dev, bool *mass_write_en)
 Gets Mass Write Bit Field status. More...
 
int ltc4306_set_timeout_mode (struct ltc4306_dev *dev, enum ltc4306_timeout_mode tout)
 Sets LTC4306's Timeout Mode. More...
 
int ltc4306_get_timeout_mode (struct ltc4306_dev *dev, enum ltc4306_timeout_mode *tout)
 Gets LTC4306's Timeout Mode. More...
 
int ltc4306_read_bus_logic_state (struct ltc4306_dev *dev, uint8_t bus_num, bool *is_high)
 Reads bus logic state. More...
 
int ltc4306_set_downstream_channel (struct ltc4306_dev *dev, uint8_t bus_num, bool connect)
 Dis/connects to a downstream bus. Bus logic state must be 1 for connection to occur EXCEPT when conn_req is 0. Controller will connect to downstream bus regardless of its logic state if conn_req is 1. More...
 
int ltc4306_get_downstream_channel (struct ltc4306_dev *dev, uint8_t bus_num, bool *connect)
 Get the connection status of the selected FET. More...
 

Variables

const uint8_t ltc4306_addresses []
 

Detailed Description

Implementation of ltc4306 driver.

Author
Jose Ramon San Buenaventura (jose..nosp@m.sanb.nosp@m.uenav.nosp@m.entu.nosp@m.ra@an.nosp@m.alog.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

◆ ltc4306_addr_gen()

int ltc4306_addr_gen ( struct ltc4306_init_param init_param,
enum ltc4306_addr_conn  addr0,
enum ltc4306_addr_conn  addr1,
enum ltc4306_addr_conn  addr2 
)

Gives the equivalent hex device address based on the input combination of addr0, addr1, and addr2. (27 possible device address)

Parameters
init_param- init param structure.
addr0- addr0 logic level
addr1- addr1 logic level
addr2- addr2 logic level
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ltc4306_downstream_check()

int ltc4306_downstream_check ( struct ltc4306_dev dev,
bool downstream_conn 
)

Get downstream connect bit status to see if any downstream bus connected.

Parameters
dev- The device structure.
downstream_conn- Stores status of downstream connect bit.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_get_conn_req()

int ltc4306_get_conn_req ( struct ltc4306_dev dev,
bool connect_regardless 
)

Gets Connection Requirement bit field.

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

◆ ltc4306_get_downstream_accel()

int ltc4306_get_downstream_accel ( struct ltc4306_dev dev,
bool downstream_en 
)

Get status of downstream accelerator enable bit field.

Parameters
dev- The device structure.
downstream_en- Stores status of Downstream Connected bit.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_get_downstream_channel()

int ltc4306_get_downstream_channel ( struct ltc4306_dev dev,
uint8_t  bus_num,
bool connect 
)

Get the connection status of the selected FET.

Parameters
dev- The device structure.
bus_num- Bus number that the user wants to connect to. (can be any value from 1 to 4)
connect- Stores the status of the bus FET state.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_get_gpio_output_state()

int ltc4306_get_gpio_output_state ( struct ltc4306_dev dev,
int  gpio,
bool is_high 
)

Gets GPIO Output Driver state.

Parameters
dev- The device structure.
gpio- GPIO to set / reset.
is_high- Stores status of selected GPIO.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_get_latched_timeout()

int ltc4306_get_latched_timeout ( struct ltc4306_dev dev,
bool timed_out 
)

Reads Latched Timeout status.

Parameters
dev- The device structure.
timed_out- Stores status of Latched Timeout bit.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_get_mass_write()

int ltc4306_get_mass_write ( struct ltc4306_dev dev,
bool mass_write_en 
)

Gets Mass Write Bit Field status.

Parameters
dev- The device structure.
mass_write_en- Stores the status of the mass write bit field.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_get_realtime_timeout()

int ltc4306_get_realtime_timeout ( struct ltc4306_dev dev,
bool timed_out 
)

Reads Realtime Timeout status.

Parameters
dev- The device structure.
timed_out- Stores status of Realtime Timeout bit.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_get_timeout_mode()

int ltc4306_get_timeout_mode ( struct ltc4306_dev dev,
enum ltc4306_timeout_mode tout 
)

Gets LTC4306's Timeout Mode.

Parameters
dev- The device structure.
tout- Stores the timeout read.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_get_upstream_accel()

int ltc4306_get_upstream_accel ( struct ltc4306_dev dev,
bool upstream_en 
)

Get status of upstream accelerator enable bit field.

Parameters
dev- The device structure.
upstream_en- Stores status of Upstream Connected bit.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_gpio_configure()

int ltc4306_gpio_configure ( struct ltc4306_dev dev,
bool  gpio1,
bool  gpio2,
bool  gpio1_is_pushpull,
bool  gpio2_is_pushpull 
)

Configures GPIO1 and GPIO2 as input or output mode. If selected as output mode, can be configured as open-drain or push-pull.

Parameters
dev- The device structure.
gpio1- Set true to configure GPIO1 to input mode; false for output mode.
gpio2- Set true to configure GPIO2 to input mode; false for output mode.
gpio1_is_pushpull- Set true to configure GPIO1 output mode to push-pull; false for open-drain.
gpio2_is_pushpull- Set true to configure GPIO2 output mode to push-pull; false for open-drain.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_init()

int ltc4306_init ( struct ltc4306_dev **  device,
struct ltc4306_init_param  init_param 
)

Initializes the communication peripheral and checks if the ltc4306 part is present.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
status - Result of the initialization procedure. Example: -1 - I2C peripheral was not initialized or ltc4306 part is not present. 0 - I2C peripheral is initialized and ltc4306 part is present.
Here is the caller graph for this function:

◆ ltc4306_read()

int ltc4306_read ( struct ltc4306_dev dev,
uint8_t  addr,
uint8_t *  read_data,
uint8_t  bytes 
)

Reads the value of a register.

Parameters
dev- The device structure.
addr- Address of the register.
read_data- Read data bufer
bytes- Number of bytes to read from starting register address
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ltc4306_read_alert_logic_state()

int ltc4306_read_alert_logic_state ( struct ltc4306_dev dev,
uint8_t  alert_pin_number,
bool is_high 
)

Reads Alert Logic State of selected ALERT pin.

Parameters
dev- The device structure.
alert_pin_number- ALERT pin to be read (1 to 4).
is_high- Stores status of selected ALERT pin.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_read_bus_logic_state()

int ltc4306_read_bus_logic_state ( struct ltc4306_dev dev,
uint8_t  bus_num,
bool is_high 
)

Reads bus logic state.

Parameters
dev- The device structure.
bus_num- Selects what bus to read (any number from 1 to 4)
is_high- Stores logic status of selected bus.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ltc4306_read_failed_conn()

int ltc4306_read_failed_conn ( struct ltc4306_dev dev,
bool is_high 
)

Reads Failed Connection Attempt bit.

Parameters
dev- The device structure.
is_high- Stores status of Failed Connection Attempt bit
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_read_gpio_logic_state()

int ltc4306_read_gpio_logic_state ( struct ltc4306_dev dev,
int  gpio,
bool is_high 
)

Reads logic of selected GPIO.

Parameters
dev- The device structure.
gpio- GPIO number (only 1 or 2)
is_high- Stores logic state value of selected GPIO.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_reg_update()

int ltc4306_reg_update ( struct ltc4306_dev dev,
uint8_t  addr,
int  update_mask,
int  update_val 
)

Update selected I2C register contents.

Parameters
dev- The device structure.
addr- Starting / selected register address.
update_mask- Mask to update to selected register bit/s
update_val- Value used to update on selected register
Returns
- 0 if I2C write is successful, error otherwise.
Here is the caller graph for this function:

◆ ltc4306_remove()

int ltc4306_remove ( struct ltc4306_dev dev)

Free the resources allocated by ltc4306_init().

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

◆ ltc4306_set_conn_req()

int ltc4306_set_conn_req ( struct ltc4306_dev dev,
bool  connect_regardless 
)

Sets Connection Requirement bit field.

Parameters
dev- The device structure.
connect_regardless- Set true to configure controller to connect to downstream bus regardless of bus logic state; otherwise, set false.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_set_downstream_accel()

int ltc4306_set_downstream_accel ( struct ltc4306_dev dev,
bool  downstream_en 
)

En/Disables downstream accelerator.

Parameters
dev- The device structure.
downstream_en- Set true to enable downstream rise time accelerator; false to disable
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_set_downstream_channel()

int ltc4306_set_downstream_channel ( struct ltc4306_dev dev,
uint8_t  bus_num,
bool  connect 
)

Dis/connects to a downstream bus. Bus logic state must be 1 for connection to occur EXCEPT when conn_req is 0. Controller will connect to downstream bus regardless of its logic state if conn_req is 1.

Parameters
dev- The device structure.
bus_num- Bus number to dis/connect (1 to 4).
connect- Set true to connect selecetd downstream to upstream, false otherwise.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ltc4306_set_gpio_output_state()

int ltc4306_set_gpio_output_state ( struct ltc4306_dev dev,
int  gpio,
bool  is_high 
)

Sets GPIO Output Driver state.

Parameters
dev- The device structure.
gpio- GPIO to set / reset.
is_high- GPIO logic level.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ltc4306_set_mass_write()

int ltc4306_set_mass_write ( struct ltc4306_dev dev,
bool  mass_write_en 
)

Enables Mass Write.

Parameters
dev- The device structure.
mass_write_en- Set true to enable mass write address; false to disable.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_set_timeout_mode()

int ltc4306_set_timeout_mode ( struct ltc4306_dev dev,
enum ltc4306_timeout_mode  tout 
)

Sets LTC4306's Timeout Mode.

Parameters
dev- The device structure.
tout- Timeout mode to configure.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_set_upstream_accel()

int ltc4306_set_upstream_accel ( struct ltc4306_dev dev,
bool  upstream_en 
)

En/Disables upstream accelerator.

Parameters
dev- The device structure.
upstream_en- Set true to enable upstream rise time accelerator, false otherwise.
Returns
0 in case of success, negative error code otherwise.

◆ ltc4306_write()

int ltc4306_write ( struct ltc4306_dev dev,
uint8_t  addr,
uint8_t *  write_data,
uint8_t  bytes 
)

Writes data into a register (I2C).

Parameters
dev- The device structure.
addr- Starting / selected register address.
write_data- Write data buffer
bytes- number of bytes to write
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

Variable Documentation

◆ ltc4306_addresses

const uint8_t ltc4306_addresses[]
Initial value:
= {
0x88,
0x8E,
0x8C,
0xB2,
0x8A,
0x82,
0x80,
0x86,
0x84,
0xA8,
0xAE,
0xAC,
0xB0,
0xAA,
0xA2,
0xA0,
0xA6,
0xA4,
0x98,
0x9E,
0x9C,
0xB4,
0x9A,
0x92,
0x90,
0x96,
0x94,
}