no-OS
Loading...
Searching...
No Matches
ltc4306.h File Reference

Header file of ltc4306 driver. More...

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

Classes

struct  ltc4306_dev
 
struct  ltc4306_init_param
 

Macros

#define LTC4306_CTRL_REG0   0x00
 
#define LTC4306_CTRL_REG1   0x01
 
#define LTC4306_CTRL_REG2   0x02
 
#define LTC4306_CTRL_REG3   0x03
 
#define LTC4306_OUT_OF_BOUNDS   0x04
 
#define LTC4306_MASS_WRITE_ADDR   0xBA
 
#define LTC4306_ALERT_RESPONSE_ADDR   0x19
 
#define LTC4306_DOWNSTREAM_CONNECT   NO_OS_BIT(7)
 
#define LTC4306_ALERT_LOGIC(x)
 
#define LTC4306_FAILED_CONN   NO_OS_BIT(2)
 
#define LTC4306_LATCHED_TOUT   NO_OS_BIT(1)
 
#define LTC4306_REALTIME_TOUT   NO_OS_BIT(0)
 
#define LTC4306_UPSTREAM_EN   NO_OS_BIT(7)
 
#define LTC4306_DOWNSTREAM_EN   NO_OS_BIT(6)
 
#define LTC4306_OUT_DRV_STATE(x)
 
#define LTC4306_GPIO_LOGIC(x)
 
#define LTC4306_GPIO_MODE_MASK   NO_OS_GENMASK(7, 6)
 
#define LTC4306_GPIO_MODE_CONFIG(x)
 
#define LTC4306_CONN_REQ   NO_OS_BIT(5)
 
#define LTC4306_OUT_MODE_MASK   NO_OS_GENMASK(4, 3)
 
#define LTC4306_OUT_MODE_CONFIG(x)
 
#define LTC4306_MASS_WRITE   NO_OS_BIT(2)
 
#define LTC4306_TOUT   NO_OS_GENMASK(1, 0)
 
#define LTC4306_FET_STATE_MASK   NO_OS_GENMASK(7, 4)
 
#define LTC4306_FET_STATE(x)
 
#define LTC4306_BUS_LOGIC_STATE_MASK   NO_OS_GENMASK(3, 0)
 
#define LTC4306_LOGIC_STATE(x)
 
#define LTC4306_MIN_CHANNEL_INDEX   1
 
#define LTC4306_CHANNEL_TWO   2
 
#define LTC4306_CHANNEL_THREE   3
 
#define LTC4306_MAX_CHANNEL_INDEX   4
 
#define LTC4306_GPIO_MIN   1
 
#define LTC4306_GPIO_MAX   2
 

Enumerations

enum  ltc4306_addr_conn {
  LTC4306_LOW ,
  LTC4306_HIGH ,
  LTC4306_NO_CONN
}
 
enum  ltc4306_timeout_mode {
  LTC4306_DISABLED ,
  LTC4306_30MS ,
  LTC4306_15MS ,
  LTC4306_7P5MS
}
 

Functions

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)
 
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.
 
int ltc4306_write (struct ltc4306_dev *dev, uint8_t addr, uint8_t *write_data, uint8_t bytes)
 Writes data into a register (I2C).
 
int ltc4306_read (struct ltc4306_dev *dev, uint8_t addr, uint8_t *read_data, uint8_t bytes)
 Reads the value of a register.
 
int ltc4306_reg_update (struct ltc4306_dev *dev, uint8_t addr, int update_mask, int update_val)
 Update selected I2C register contents.
 
int ltc4306_remove (struct ltc4306_dev *dev)
 Free the resources allocated by ltc4306_init().
 
int ltc4306_downstream_check (struct ltc4306_dev *dev, bool *downstream_conn)
 Get downstream connect bit status to see if any downstream bus connected.
 
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.
 
int ltc4306_read_failed_conn (struct ltc4306_dev *dev, bool *is_high)
 Reads Failed Connection Attempt bit.
 
int ltc4306_get_latched_timeout (struct ltc4306_dev *dev, bool *timed_out)
 Reads Latched Timeout status.
 
int ltc4306_get_realtime_timeout (struct ltc4306_dev *dev, bool *timed_out)
 Reads Realtime Timeout status.
 
int ltc4306_set_upstream_accel (struct ltc4306_dev *dev, bool upstream_en)
 En/Disables upstream accelerator.
 
int ltc4306_get_upstream_accel (struct ltc4306_dev *dev, bool *upstream_en)
 Get status of upstream accelerator enable bit field.
 
int ltc4306_set_downstream_accel (struct ltc4306_dev *dev, bool downstream_en)
 En/Disables downstream accelerator.
 
int ltc4306_get_downstream_accel (struct ltc4306_dev *dev, bool *downstream_en)
 Get status of downstream accelerator enable bit field.
 
int ltc4306_set_gpio_output_state (struct ltc4306_dev *dev, int gpio, bool is_high)
 Sets GPIO Output Driver state.
 
int ltc4306_get_gpio_output_state (struct ltc4306_dev *dev, int gpio, bool *is_high)
 Gets GPIO Output Driver state.
 
int ltc4306_read_gpio_logic_state (struct ltc4306_dev *dev, int gpio, bool *is_high)
 Reads logic of selected GPIO.
 
int ltc4306_set_conn_req (struct ltc4306_dev *dev, bool connect_regardless)
 Sets Connection Requirement bit field.
 
int ltc4306_get_conn_req (struct ltc4306_dev *dev, bool *connect_regardless)
 Gets Connection Requirement bit field.
 
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.
 
int ltc4306_set_mass_write (struct ltc4306_dev *dev, bool mass_write_en)
 Enables Mass Write.
 
int ltc4306_get_mass_write (struct ltc4306_dev *dev, bool *mass_write_en)
 Gets Mass Write Bit Field status.
 
int ltc4306_set_timeout_mode (struct ltc4306_dev *dev, enum ltc4306_timeout_mode tout)
 Sets LTC4306's Timeout Mode.
 
int ltc4306_get_timeout_mode (struct ltc4306_dev *dev, enum ltc4306_timeout_mode *tout)
 Gets LTC4306's Timeout Mode.
 
int ltc4306_read_bus_logic_state (struct ltc4306_dev *dev, uint8_t bus_number, bool *is_high)
 Reads bus logic state.
 
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.
 
int ltc4306_get_downstream_channel (struct ltc4306_dev *dev, uint8_t bus_num, bool *connect)
 Get the connection status of the selected FET.
 

Detailed Description

Header file 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.

SPDX-License-Identifier: BSD-3-Clause

Macro Definition Documentation

◆ LTC4306_ALERT_LOGIC

#define LTC4306_ALERT_LOGIC ( x)
Value:
NO_OS_BIT(7 - (x))
#define NO_OS_BIT(x)
Definition no_os_util.h:23

◆ LTC4306_ALERT_RESPONSE_ADDR

#define LTC4306_ALERT_RESPONSE_ADDR   0x19

◆ LTC4306_BUS_LOGIC_STATE_MASK

#define LTC4306_BUS_LOGIC_STATE_MASK   NO_OS_GENMASK(3, 0)

◆ LTC4306_CHANNEL_THREE

#define LTC4306_CHANNEL_THREE   3

◆ LTC4306_CHANNEL_TWO

#define LTC4306_CHANNEL_TWO   2

◆ LTC4306_CONN_REQ

#define LTC4306_CONN_REQ   NO_OS_BIT(5)

◆ LTC4306_CTRL_REG0

#define LTC4306_CTRL_REG0   0x00

◆ LTC4306_CTRL_REG1

#define LTC4306_CTRL_REG1   0x01

◆ LTC4306_CTRL_REG2

#define LTC4306_CTRL_REG2   0x02

◆ LTC4306_CTRL_REG3

#define LTC4306_CTRL_REG3   0x03

◆ LTC4306_DOWNSTREAM_CONNECT

#define LTC4306_DOWNSTREAM_CONNECT   NO_OS_BIT(7)

◆ LTC4306_DOWNSTREAM_EN

#define LTC4306_DOWNSTREAM_EN   NO_OS_BIT(6)

◆ LTC4306_FAILED_CONN

#define LTC4306_FAILED_CONN   NO_OS_BIT(2)

◆ LTC4306_FET_STATE

#define LTC4306_FET_STATE ( x)
Value:
NO_OS_BIT(8 - (x))

◆ LTC4306_FET_STATE_MASK

#define LTC4306_FET_STATE_MASK   NO_OS_GENMASK(7, 4)

◆ LTC4306_GPIO_LOGIC

#define LTC4306_GPIO_LOGIC ( x)
Value:
NO_OS_BIT(2 - (x))

◆ LTC4306_GPIO_MAX

#define LTC4306_GPIO_MAX   2

◆ LTC4306_GPIO_MIN

#define LTC4306_GPIO_MIN   1

◆ LTC4306_GPIO_MODE_CONFIG

#define LTC4306_GPIO_MODE_CONFIG ( x)
Value:
NO_OS_BIT(8 - (x))

◆ LTC4306_GPIO_MODE_MASK

#define LTC4306_GPIO_MODE_MASK   NO_OS_GENMASK(7, 6)

◆ LTC4306_LATCHED_TOUT

#define LTC4306_LATCHED_TOUT   NO_OS_BIT(1)

◆ LTC4306_LOGIC_STATE

#define LTC4306_LOGIC_STATE ( x)
Value:
NO_OS_BIT(4 - (x))

◆ LTC4306_MASS_WRITE

#define LTC4306_MASS_WRITE   NO_OS_BIT(2)

◆ LTC4306_MASS_WRITE_ADDR

#define LTC4306_MASS_WRITE_ADDR   0xBA

◆ LTC4306_MAX_CHANNEL_INDEX

#define LTC4306_MAX_CHANNEL_INDEX   4

◆ LTC4306_MIN_CHANNEL_INDEX

#define LTC4306_MIN_CHANNEL_INDEX   1

◆ LTC4306_OUT_DRV_STATE

#define LTC4306_OUT_DRV_STATE ( x)
Value:
NO_OS_BIT(6 - (x))

◆ LTC4306_OUT_MODE_CONFIG

#define LTC4306_OUT_MODE_CONFIG ( x)
Value:
NO_OS_BIT(5 - (x))

◆ LTC4306_OUT_MODE_MASK

#define LTC4306_OUT_MODE_MASK   NO_OS_GENMASK(4, 3)

◆ LTC4306_OUT_OF_BOUNDS

#define LTC4306_OUT_OF_BOUNDS   0x04

◆ LTC4306_REALTIME_TOUT

#define LTC4306_REALTIME_TOUT   NO_OS_BIT(0)

◆ LTC4306_TOUT

#define LTC4306_TOUT   NO_OS_GENMASK(1, 0)

◆ LTC4306_UPSTREAM_EN

#define LTC4306_UPSTREAM_EN   NO_OS_BIT(7)

Enumeration Type Documentation

◆ ltc4306_addr_conn

Enumerator
LTC4306_LOW 
LTC4306_HIGH 
LTC4306_NO_CONN 

◆ ltc4306_timeout_mode

Enumerator
LTC4306_DISABLED 
LTC4306_30MS 
LTC4306_15MS 
LTC4306_7P5MS 

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.

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

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

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

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

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

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

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

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

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