no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ltc4306.h
Go to the documentation of this file.
1/***************************************************************************/
33#ifndef __LTC4306_H__
34#define __LTC4306_H__
35
36#include <stdint.h>
37#include <stdlib.h>
38#include "no_os_i2c.h"
39#include "no_os_util.h"
40
41/* Register address definitions */
42#define LTC4306_CTRL_REG0 0x00
43#define LTC4306_CTRL_REG1 0x01
44#define LTC4306_CTRL_REG2 0x02
45#define LTC4306_CTRL_REG3 0x03
46#define LTC4306_OUT_OF_BOUNDS 0x04
47
48/* Special Addresses */
49#define LTC4306_MASS_WRITE_ADDR 0xBA
50#define LTC4306_ALERT_RESPONSE_ADDR 0x19
51
52/* Masks (Bits and Fields) */
53/* REG0 */
54#define LTC4306_DOWNSTREAM_CONNECT NO_OS_BIT(7)
55#define LTC4306_ALERT_LOGIC(x) NO_OS_BIT(7 - (x))
56#define LTC4306_FAILED_CONN NO_OS_BIT(2)
57#define LTC4306_LATCHED_TOUT NO_OS_BIT(1)
58#define LTC4306_REALTIME_TOUT NO_OS_BIT(0)
59
60/* REG1 */
61#define LTC4306_UPSTREAM_EN NO_OS_BIT(7)
62#define LTC4306_DOWNSTREAM_EN NO_OS_BIT(6)
63#define LTC4306_OUT_DRV_STATE(x) NO_OS_BIT(6 - (x))
64#define LTC4306_GPIO_LOGIC(x) NO_OS_BIT(2 - (x))
65
66/* REG2 */
67#define LTC4306_GPIO_MODE_MASK NO_OS_GENMASK(7, 6)
68#define LTC4306_GPIO_MODE_CONFIG(x) NO_OS_BIT(8 - (x))
69#define LTC4306_CONN_REQ NO_OS_BIT(5)
70#define LTC4306_OUT_MODE_MASK NO_OS_GENMASK(4, 3)
71#define LTC4306_OUT_MODE_CONFIG(x) NO_OS_BIT(5 - (x))
72#define LTC4306_MASS_WRITE NO_OS_BIT(2)
73#define LTC4306_TOUT NO_OS_GENMASK(1, 0)
74
75/* REG3 */
76#define LTC4306_FET_STATE_MASK NO_OS_GENMASK(7, 4)
77#define LTC4306_FET_STATE(x) NO_OS_BIT(8 - (x))
78#define LTC4306_BUS_LOGIC_STATE_MASK NO_OS_GENMASK(3, 0)
79#define LTC4306_LOGIC_STATE(x) NO_OS_BIT(4 - (x))
80
81/* Other definitions */
82#define LTC4306_MIN_CHANNEL_INDEX 1
83#define LTC4306_CHANNEL_TWO 2
84#define LTC4306_CHANNEL_THREE 3
85#define LTC4306_MAX_CHANNEL_INDEX 4
86#define LTC4306_GPIO_MIN 1
87#define LTC4306_GPIO_MAX 2
88
94
101
104 /* GPIO status indicators (input or ouptut) */
106 /* GPIO out mode indicators (push pull or open drain */
108 /* FET status indicators (connected or not) */
110 /* Upstream accelerator indicator */
112 /* Downstream accelerator indicator */
114};
115
117 /* I2C */
119};
120
121/* Generate slave address depending on A0 and A1 logic levels */
123 enum ltc4306_addr_conn addr0, enum ltc4306_addr_conn addr1,
124 enum ltc4306_addr_conn addr2);
125
126/* Initialize device */
127int ltc4306_init(struct ltc4306_dev **device,
129
130/* Write byte/s to selected starting register */
131int ltc4306_write(struct ltc4306_dev *dev, uint8_t addr, uint8_t *write_data,
132 uint8_t bytes);
133
134/* Read byte/s from selected starting register */
135int ltc4306_read(struct ltc4306_dev *dev, uint8_t addr, uint8_t *read_data,
136 uint8_t bytes);
137
138/* Update selected register using mask and desired value */
139int ltc4306_reg_update(struct ltc4306_dev *dev, uint8_t addr, int update_mask,
140 int update_val);
141
142/* Deallocate resources for device */
143int ltc4306_remove(struct ltc4306_dev *dev);
144
145/* Checks if any downstream bus is connected to upstream bus */
146int ltc4306_downstream_check(struct ltc4306_dev *dev, bool *downstream_conn);
147
148/* Reads the status of selected ALERT pin */
150 uint8_t alert_pin_number, bool *is_high);
151
152/* Checks if any downstream connection attempt failed */
153int ltc4306_read_failed_conn(struct ltc4306_dev *dev, bool *is_high);
154
155/* Checks if any latched timeout occurs */
156int ltc4306_get_latched_timeout(struct ltc4306_dev *dev, bool *timed_out);
157
158/* Check status of stuck low timeout circuitry */
159int ltc4306_get_realtime_timeout(struct ltc4306_dev *dev, bool *timed_out);
160
161/* Sets status of upstream accelerator */
162int ltc4306_set_upstream_accel(struct ltc4306_dev *dev, bool upstream_en);
163
164/* Gets status of upstream accelerator */
165int ltc4306_get_upstream_accel(struct ltc4306_dev *dev, bool *upstream_en);
166
167/* Sets status of downstream accelerator */
168int ltc4306_set_downstream_accel(struct ltc4306_dev *dev, bool downstream_en);
169
170/* Gets status of downstream accelerator */
171int ltc4306_get_downstream_accel(struct ltc4306_dev *dev, bool *downstream_en);
172
173/* Sets GPIO Output Driver state */
174int ltc4306_set_gpio_output_state(struct ltc4306_dev *dev, int gpio,
175 bool is_high);
176
177/* Gets GPIO Output Driver state */
178int ltc4306_get_gpio_output_state(struct ltc4306_dev *dev, int gpio,
179 bool *is_high);
180
181/* Reads logic level of selected GPIO */
182int ltc4306_read_gpio_logic_state(struct ltc4306_dev *dev, int gpio,
183 bool *is_high);
184
185/* Sets the LTC4306's connection requirement bit field for downstream connect */
186int ltc4306_set_conn_req(struct ltc4306_dev *dev, bool connect_regardless);
187
188/* Gets the LTC4306's connection requirement bit field for downstream connect */
189int ltc4306_get_conn_req(struct ltc4306_dev *dev, bool *connect_regardless);
190
191/* Configure LTC4306's GPIO mode and output config (for output) */
192int ltc4306_gpio_configure(struct ltc4306_dev *dev, bool gpio1,
193 bool gpio2, bool gpio1_is_pushpull, bool gpio2_is_pushpull);
194
195/* Sets the mass write bit field */
196int ltc4306_set_mass_write(struct ltc4306_dev *dev, bool mass_write_en);
197
198/* Gets the mass write bit field */
199int ltc4306_get_mass_write(struct ltc4306_dev *dev, bool *mass_write_en);
200
201/* Sets the LTC4306's stuck low timeout mode */
203 enum ltc4306_timeout_mode tout);
204
205/* Gets the LTC4306's stuck low timeout mode */
207 enum ltc4306_timeout_mode *tout);
208
209/* Reads LTC4306's selected Bus Logic */
210int ltc4306_read_bus_logic_state(struct ltc4306_dev *dev, uint8_t bus_number,
211 bool *is_high);
212
213/* Sets the connection for selected LTC4306 downstream channel */
215 uint8_t bus_num, bool connect);
216
217/* Gets the connection for selected LTC4306 downstream channel */
219 uint8_t bus_num, bool *connect);
220
221#endif /* __LTC4306_H__ */
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
int ltc4306_read_gpio_logic_state(struct ltc4306_dev *dev, int gpio, bool *is_high)
Reads logic of selected GPIO.
Definition ltc4306.c:509
int ltc4306_get_gpio_output_state(struct ltc4306_dev *dev, int gpio, bool *is_high)
Gets GPIO Output Driver state.
Definition ltc4306.c:482
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 ...
Definition ltc4306.c:583
int ltc4306_set_upstream_accel(struct ltc4306_dev *dev, bool upstream_en)
En/Disables upstream accelerator.
Definition ltc4306.c:375
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,...
Definition ltc4306.c:228
int ltc4306_read(struct ltc4306_dev *dev, uint8_t addr, uint8_t *read_data, uint8_t bytes)
Reads the value of a register.
Definition ltc4306.c:171
int ltc4306_get_latched_timeout(struct ltc4306_dev *dev, bool *timed_out)
Reads Latched Timeout status.
Definition ltc4306.c:331
int ltc4306_set_timeout_mode(struct ltc4306_dev *dev, enum ltc4306_timeout_mode tout)
Sets LTC4306's Timeout Mode.
Definition ltc4306.c:672
int ltc4306_reg_update(struct ltc4306_dev *dev, uint8_t addr, int update_mask, int update_val)
Update selected I2C register contents.
Definition ltc4306.c:201
int ltc4306_get_conn_req(struct ltc4306_dev *dev, bool *connect_regardless)
Gets Connection Requirement bit field.
Definition ltc4306.c:553
int ltc4306_read_failed_conn(struct ltc4306_dev *dev, bool *is_high)
Reads Failed Connection Attempt bit.
Definition ltc4306.c:309
int ltc4306_get_timeout_mode(struct ltc4306_dev *dev, enum ltc4306_timeout_mode *tout)
Gets LTC4306's Timeout Mode.
Definition ltc4306.c:689
int ltc4306_remove(struct ltc4306_dev *dev)
Free the resources allocated by ltc4306_init().
Definition ltc4306.c:118
#define LTC4306_GPIO_MAX
Definition ltc4306.h:87
int ltc4306_set_mass_write(struct ltc4306_dev *dev, bool mass_write_en)
Enables Mass Write.
Definition ltc4306.c:633
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.
Definition ltc4306.c:282
int ltc4306_get_mass_write(struct ltc4306_dev *dev, bool *mass_write_en)
Gets Mass Write Bit Field status.
Definition ltc4306.c:650
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.
Definition ltc4306.c:87
int ltc4306_get_downstream_accel(struct ltc4306_dev *dev, bool *downstream_en)
Get status of downstream accelerator enable bit field.
Definition ltc4306.c:436
int ltc4306_write(struct ltc4306_dev *dev, uint8_t addr, uint8_t *write_data, uint8_t bytes)
Writes data into a register (I2C).
Definition ltc4306.c:139
int ltc4306_get_realtime_timeout(struct ltc4306_dev *dev, bool *timed_out)
Reads Realtime Timeout status.
Definition ltc4306.c:353
int ltc4306_set_conn_req(struct ltc4306_dev *dev, bool connect_regardless)
Sets Connection Requirement bit field.
Definition ltc4306.c:536
ltc4306_timeout_mode
Definition ltc4306.h:95
@ LTC4306_7P5MS
Definition ltc4306.h:99
@ LTC4306_15MS
Definition ltc4306.h:98
@ LTC4306_30MS
Definition ltc4306.h:97
@ LTC4306_DISABLED
Definition ltc4306.h:96
int ltc4306_set_downstream_accel(struct ltc4306_dev *dev, bool downstream_en)
En/Disables downstream accelerator.
Definition ltc4306.c:417
ltc4306_addr_conn
Definition ltc4306.h:89
@ LTC4306_NO_CONN
Definition ltc4306.h:92
@ LTC4306_HIGH
Definition ltc4306.h:91
@ LTC4306_LOW
Definition ltc4306.h:90
int ltc4306_read_bus_logic_state(struct ltc4306_dev *dev, uint8_t bus_number, bool *is_high)
Reads bus logic state.
Definition ltc4306.c:713
int ltc4306_get_downstream_channel(struct ltc4306_dev *dev, uint8_t bus_num, bool *connect)
Get the connection status of the selected FET.
Definition ltc4306.c:788
int ltc4306_get_upstream_accel(struct ltc4306_dev *dev, bool *upstream_en)
Get status of upstream accelerator enable bit field.
Definition ltc4306.c:394
int ltc4306_downstream_check(struct ltc4306_dev *dev, bool *downstream_conn)
Get downstream connect bit status to see if any downstream bus connected.
Definition ltc4306.c:259
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_...
Definition ltc4306.c:746
int ltc4306_set_gpio_output_state(struct ltc4306_dev *dev, int gpio, bool is_high)
Sets GPIO Output Driver state.
Definition ltc4306.c:459
#define LTC4306_MAX_CHANNEL_INDEX
Definition ltc4306.h:85
Header file of I2C Interface.
Header file of utility functions.
Definition ad9361_util.h:63
Definition ltc4306.h:102
bool downstream
Definition ltc4306.h:113
bool upstream
Definition ltc4306.h:111
bool is_input[LTC4306_GPIO_MAX]
Definition ltc4306.h:105
bool is_push_pull[LTC4306_GPIO_MAX]
Definition ltc4306.h:107
bool is_closed[LTC4306_MAX_CHANNEL_INDEX]
Definition ltc4306.h:109
struct no_os_i2c_desc * i2c_desc
Definition ltc4306.h:103
Definition ltc4306.h:116
struct no_os_i2c_init_param i2c_init
Definition ltc4306.h:118
Structure holding I2C address descriptor.
Definition no_os_i2c.h:89
Structure holding the parameters for I2C initialization.
Definition no_os_i2c.h:52