Firmware SDK
twr_tca9534a.h
1 #ifndef _TWR_TCA9534A_H
2 #define _TWR_TCA9534A_H
3 
4 #include <twr_i2c.h>
5 #include <twr_tick.h>
6 
7 #define TWR_TCA9534A_PIN_STATE_LOW 0
8 #define TWR_TCA9534A_PIN_STATE_HIGH 1
9 
13 
15 
16 typedef enum
17 {
18  TWR_TCA9534A_PIN_P0 = 0,
19  TWR_TCA9534A_PIN_P1 = 1,
20  TWR_TCA9534A_PIN_P2 = 2,
21  TWR_TCA9534A_PIN_P3 = 3,
22  TWR_TCA9534A_PIN_P4 = 4,
23  TWR_TCA9534A_PIN_P5 = 5,
24  TWR_TCA9534A_PIN_P6 = 6,
25  TWR_TCA9534A_PIN_P7 = 7
26 
28 
30 
31 typedef enum
32 {
33  TWR_TCA9534A_PIN_DIRECTION_OUTPUT = 0,
34  TWR_TCA9534A_PIN_DIRECTION_INPUT = 1
35 
37 
39 
41 
42 typedef struct
43 {
44  twr_i2c_channel_t _i2c_channel;
45  uint8_t _i2c_address;
46  uint8_t _direction;
47  uint8_t _output_port;
48 
50 
55 
56 bool twr_tca9534a_init(twr_tca9534a_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address);
57 
63 
64 bool twr_tca9534a_read_port(twr_tca9534a_t *self, uint8_t *state);
65 
71 
72 bool twr_tca9534a_write_port(twr_tca9534a_t *self, uint8_t state);
73 
80 
81 bool twr_tca9534a_read_pin(twr_tca9534a_t *self, twr_tca9534a_pin_t pin, int *state);
82 
89 
90 bool twr_tca9534a_write_pin(twr_tca9534a_t *self, twr_tca9534a_pin_t pin, int state);
91 
97 
98 bool twr_tca9534a_get_port_direction(twr_tca9534a_t *self, uint8_t *direction);
99 
105 
106 bool twr_tca9534a_set_port_direction(twr_tca9534a_t *self, uint8_t direction);
107 
114 
116 
123 
125 
127 
128 #endif // _TWR_TCA9534A_H
twr_i2c_channel_t
I2C channels.
Definition: twr_i2c.h:16
bool twr_tca9534a_read_port(twr_tca9534a_t *self, uint8_t *state)
Read state of all pins.
Definition: twr_tca9534a.c:30
bool twr_tca9534a_get_port_direction(twr_tca9534a_t *self, uint8_t *direction)
Get direction of all pins.
Definition: twr_tca9534a.c:80
bool twr_tca9534a_write_port(twr_tca9534a_t *self, uint8_t state)
Write state to all pins.
Definition: twr_tca9534a.c:35
twr_tca9534a_pin_direction_t
Pin direction.
Definition: twr_tca9534a.h:32
bool twr_tca9534a_get_pin_direction(twr_tca9534a_t *self, twr_tca9534a_pin_t pin, twr_tca9534a_pin_direction_t *direction)
Get pin direction.
Definition: twr_tca9534a.c:99
bool twr_tca9534a_read_pin(twr_tca9534a_t *self, twr_tca9534a_pin_t pin, int *state)
Read pin state.
Definition: twr_tca9534a.c:47
bool twr_tca9534a_set_pin_direction(twr_tca9534a_t *self, twr_tca9534a_pin_t pin, twr_tca9534a_pin_direction_t direction)
Set pin direction.
Definition: twr_tca9534a.c:113
twr_tca9534a_pin_t
Individual pin names.
Definition: twr_tca9534a.h:17
bool twr_tca9534a_init(twr_tca9534a_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize TCA9534A.
Definition: twr_tca9534a.c:8
bool twr_tca9534a_set_port_direction(twr_tca9534a_t *self, uint8_t direction)
Set direction of all pins.
Definition: twr_tca9534a.c:87
bool twr_tca9534a_write_pin(twr_tca9534a_t *self, twr_tca9534a_pin_t pin, int state)
Write pin state.
Definition: twr_tca9534a.c:61
Pin state.
Definition: twr_tca9534a.h:43