1 #include <twr_chester_a.h>
4 #define RELAY_1_MASK (1 << TWR_TCA9534A_PIN_P0)
5 #define RELAY_2_MASK (1 << TWR_TCA9534A_PIN_P1)
9 if (self->is_tca9534a_initialized)
24 self->is_tca9534a_initialized =
true;
31 self->is_tca9534a_initialized =
false;
35 return init_tca9534a(
self);
40 if (!init_tca9534a(
self))
45 uint8_t port =
self->tca9534a._output_port;
49 case TWR_CHESTER_A_RELAY_1:
54 port &= ~RELAY_1_MASK;
58 case TWR_CHESTER_A_RELAY_2:
63 port &= ~RELAY_2_MASK;
67 case TWR_CHESTER_A_RELAY_BOTH:
70 port |= RELAY_1_MASK | RELAY_2_MASK;
72 port &= ~(RELAY_1_MASK | RELAY_2_MASK);
84 self->is_tca9534a_initialized =
false;
94 if (!init_tca9534a(
self))
99 uint8_t port =
self->tca9534a._output_port;
103 case TWR_CHESTER_A_RELAY_1:
105 *state = (port & RELAY_1_MASK) != 0;
108 case TWR_CHESTER_A_RELAY_2:
110 *state = (port & RELAY_2_MASK) != 0;
113 case TWR_CHESTER_A_RELAY_BOTH:
127 return twr_chester_a_relay_get_state(
self, relay, &state) &&
128 twr_chester_a_relay_set_state(
self, relay, !state);
twr_chester_a_relay_t
Relay enum.
struct twr_chester_a_t twr_chester_a_t
HARDWARIO CHESTER A instance.
twr_i2c_channel_t
I2C channels.
void void void void void twr_log_error(const char *format,...) __attribute__((format(printf
Log ERROR message (annotated in log as <E>)
bool twr_tca9534a_write_port(twr_tca9534a_t *self, uint8_t state)
Write state to all pins.
bool twr_tca9534a_init(twr_tca9534a_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize TCA9534A.
bool twr_tca9534a_set_port_direction(twr_tca9534a_t *self, uint8_t direction)
Set direction of all pins.