1 #ifndef DRIVER_IO_EXPANDER_PCAL9535A_H 2 #define DRIVER_IO_EXPANDER_PCAL9535A_H 79 const struct i2c_t *I2c;
93 #define IO_EXPANDER_INPUT 0x00 94 #define IO_EXPANDER_OUTPUT 0x02 95 #define IO_EXPANDER_INVERT 0x04 96 #define IO_EXPANDER_DIRECTION 0x06 97 #define IO_EXPANDER_DRIVE_PORT0 0x40 98 #define IO_EXPANDER_DRIVE_PORT1 0x42 99 #define IO_EXPANDER_INPUT_LATCH_ENABLE 0x44 100 #define IO_EXPANDER_PULL_ENABLE 0x46 101 #define IO_EXPANDER_PULL_SELECT 0x48 102 #define IO_EXPANDER_INT_MASK 0x4a 103 #define IO_EXPANDER_INT_STATUS 0x4c 104 #define IO_EXPANDER_OUTPUT_CONFIG 0x4f 114 extern bool IoExpanderRead(
const struct io_expander_t *IoExpander,
const uint8_t Address, uint16_t *Data);
115 extern bool IoExpanderWrite(
const struct io_expander_t *IoExpander,
const uint8_t Address,
const uint16_t Data);
233 return IoExpanderWrite(IoExpander, IO_EXPANDER_DIRECTION, Direction);
248 if (IoExpanderWrite(IoExpander, IO_EXPANDER_DRIVE_PORT0, (uint16_t)Drive) &&
249 IoExpanderWrite(IoExpander, IO_EXPANDER_DRIVE_PORT1, (uint16_t)(Drive >> 16)))
269 if (IoExpanderWrite(IoExpander, IO_EXPANDER_PULL_SELECT, PullSelect) &&
270 IoExpanderWrite(IoExpander, IO_EXPANDER_PULL_ENABLE, PullEnable))
277 #endif //DRIVER_IO_EXPANDER_PCAL9535A_H bool IoExpPortWrite(const struct io_expander_t *IoExpander, const uint8_t Port0, const uint8_t Port1)
Name: IoExpPortWrite Write to IO expander PORT0 and PORT1.
bool IoExpPortInterruptsDisable(const struct io_expander_t *IoExpander, uint16_t Mask)
Name: IoExpPortInterruptsDisable Disable (mask) interrupts for the selected set of pins...
uint16_t IoExpPortInterruptsRead(const struct io_expander_t *IoExpander)
Name: IoExpPortInterruptsRead Read and clear interrupt status from the IO expander.
uint16_t PullSelect
Selects pullup or polldown resistors port pins (0 = 100k pulldown, 1 = 100k pullup) ...
void IoExpPortInterruptsClear(const struct io_expander_t *IoExpander, uint16_t Mask)
Name: IoExpPortInterruptsDisable Clear (remove pending status) interrupts for the selected set of pin...
uint16_t InInvert
Invertion of inputs port pins (0 = no invert, 1 = invert)
uint16_t OutputValues
Last values set for output to IO_EXPANDER_OUTPUT register.
static bool IoExpPortPullResistorSet(const struct io_expander_t *IoExpander, const uint16_t PullEnable, const uint16_t PullSelect)
Name: IoExpPortPullResistorSet Disables/enables pullup/pulldown resistors for IO expander port pins...
struct io_expander_state_t * State
IO expander run-time state.
uint8_t Reserved
Reserved and not used.
bool IoExpPortRead(const struct io_expander_t *IoExpander, uint16_t *In)
Name: IoExpPortRead Read 16-bits data from IO expander ports.
uint16_t InterruptStatus
Pending interrupt status.
uint16_t Direction
Sets the direction of port pins (0 = output, 1 = input)
bool IoExpPortInit(const struct io_expander_t *IoExpander)
Name: IoExpPortInit Initializes I2C-based IO expander type NXP PCAL9535A.
static bool IoExpPortSet(const struct io_expander_t *IoExpander, const uint16_t SetBits)
Name: IoExpPortSet Sets IO expander port bits.
uint16_t InputValues
Last read input values, copy of IO_EXPANDER_INPUT register.
bool IoExpPortInterruptsEnable(const struct io_expander_t *IoExpander, uint16_t Mask)
Name: IoExpPortInterruptsEnable Enable (unmask) interrupts for the selected set of pins...
uint16_t Direction
Current direction state, copy of IO_EXPANDER_DIRECTION register.
static bool IoExpPortDirection(const struct io_expander_t *IoExpander, const uint16_t Direction)
Name: IoExpPortDirection Set IO expander ports to input and output.
uint16_t InterruptMask
Internal interrupt bit mask (0 = disabled, 1 = enabled), inverted copy of IO_EXPANDER_INT_MASK regist...
static bool IoExpPortClear(const struct io_expander_t *IoExpander, const uint16_t ClearBits)
Name: IoExpPortClear Clears IO expander port bits.
uint16_t PullEnable
Enables pull resistors for port pins (0 = disable, 1 = enable)
static bool IoExpPortDriveSet(const struct io_expander_t *IoExpander, const uint32_t Drive)
Name: IoExpPortDriveSet Set output drive strength for IO expander ports.
uint16_t OutInit
Initialize value for output port pins (0 = low output, 1 = high output)