1 #ifndef DRIVER_IO_EXPANDER_PCAL9535A_H 2 #define DRIVER_IO_EXPANDER_PCAL9535A_H 96 #define IO_EXPANDER_INPUT 0x00 97 #define IO_EXPANDER_OUTPUT 0x02 98 #define IO_EXPANDER_INVERT 0x04 99 #define IO_EXPANDER_DIRECTION 0x06 100 #define IO_EXPANDER_DRIVE_PORT0 0x40 101 #define IO_EXPANDER_DRIVE_PORT1 0x42 102 #define IO_EXPANDER_INPUT_LATCH_ENABLE 0x44 103 #define IO_EXPANDER_PULL_ENABLE 0x46 104 #define IO_EXPANDER_PULL_SELECT 0x48 105 #define IO_EXPANDER_INT_MASK 0x4a 106 #define IO_EXPANDER_INT_STATUS 0x4c 107 #define IO_EXPANDER_OUTPUT_CONFIG 0x4f 123 extern uint16_t ReadPcal(
const struct gpio_ext_t* GpioExt, uint8_t Address);
124 extern void WritePcal(
const struct gpio_ext_t* GpioExt, uint8_t Address, uint16_t Data);
156 return ReadPcal(GpioExt, IO_EXPANDER_INPUT);
168 WritePcal(GpioExt, IO_EXPANDER_OUTPUT, Data);
181 WritePcal(GpioExt, IO_EXPANDER_DIRECTION, ~Direction);
193 WritePcal(GpioExt, IO_EXPANDER_PULL_SELECT, PullSelect);
205 WritePcal(GpioExt, IO_EXPANDER_PULL_ENABLE, PullEnable);
208 static inline void GpioExtSetInterruptsPcal(
const struct gpio_ext_t *GpioExt,
213 WritePcal(GpioExt, IO_EXPANDER_INT_MASK, ~Mask);
216 static inline void GpioExtSetLatchPcal(
const struct gpio_ext_t *GpioExt,
219 WritePcal(GpioExt, IO_EXPANDER_INPUT_LATCH_ENABLE, Mask);
222 extern void GpioExtSetDrivePcal(
const struct gpio_ext_t *GpioExt, uint8_t Values[]);
228 #endif //DRIVER_IO_EXPANDER_PCAL9535A_H
uint16_t InterruptMask
Internal interrupt bit mask (0 = disabled, 1 = enabled)
uint16_t Direction
Current direction state, copy of IO_EXPANDER_DIRECTION register.
uint16_t OutInit
Initialize value for output port pins (0 = low output, 1 = high output)
uint16_t PullSelect
Selects pullup or polldown resistors port pins (0 = 100k pulldown, 1 = 100k pullup) ...
static void GpioExtSetDirectionPcal(const struct gpio_ext_t *GpioExt, uint16_t Direction)
Set pins direction to GPIO port.
uint8_t SlaveAddress
I2C slave address 0x20 to 0x27.
static void GpioExtSetPullSelectPcal(const struct gpio_ext_t *GpioExt, uint16_t PullSelect)
Select pullup or pulldown for GPIO port.
const struct i2c_t * I2c
I2C port I2C0 or I2C1.
static void GpioExtOutPortPcal(const struct gpio_ext_t *GpioExt, uint16_t Data)
Name: GpioExtOutPortPcal Write 16-bits data to GPIO port.
static void GpioExtInitPcal(const struct gpio_ext_t *GpioExt)
Initialize I2C-based IO expander type NXP PCAL9535A.
Abstract IO extender driver.
uint16_t InputValues
Last read input values, copy of IO_EXPANDER_INPUT register.
uint16_t PullEnable
Enables pull resistors for port pins (0 = disable, 1 = enable)
static void GpioExtSetPullEnablePcal(const struct gpio_ext_t *GpioExt, uint16_t PullEnable)
Enable pullup/pulldown to GPIO port.
uint16_t Direction
Sets the direction of port pins (0 = output, 1 = input)
uint16_t InInvert
Invertion of inputs port pins (0 = no invert, 1 = invert)
uint16_t InterruptMask
Internal interrupt bit mask (0 = disabled, 1 = enabled), inverted copy of IO_EXPANDER_INT_MASK regist...
struct gpio_ext_state_t * State
Address to struct with RAM variables used by the driver.
uint16_t OutputValues
Last values set for output to IO_EXPANDER_OUTPUT register.
uint8_t Reserved
Reserved and not used.
struct gpio_ext_pcal_state_t * State
IO expander run-time state.
uint16_t InterruptStatus
Pending interrupt status.
const struct gpio_ext_api_t GpioPcalFunc
static void GpioExtDisablePcal(const struct gpio_ext_t *GpioExt)
De-initialize I2C-based IO expander type NXP PCAL9535A.
static uint16_t GpioExtInPortPcal(const struct gpio_ext_t *GpioExt)
Name: GpioExtInPortPcal Read 16-bits data from GPIO port.