1 #ifndef DRIVER_GPIO_EXT_H 2 #define DRIVER_GPIO_EXT_H 43 #include <lib/assert.h> 46 #include <app_util_platform.h> 58 #define GPIO_EXT_MAXPINS 16 60 #ifndef DRIVER_PORT_EXT_INIT_TABLE 61 #error DRIVER_PORT_EXT_INIT_TABLE must point to a header file with pin init values 63 #define PINDEF(name, pin, mode, value, drive) name = pin, 65 #include DRIVER_PORT_EXT_INIT_TABLE 183 #define GPIO_EXT_VCALL(GpioExt, Fn) (GpioExt)->Func->Fn 185 extern void GpioExtPortWriteImpl(
const struct gpio_ext_t* GpioExt,
186 uint16_t* StoredValue, uint16_t DesiredValue,
189 extern uint16_t GpioExtPortReadImpl(
const struct gpio_ext_t* GpioExt,
190 bool TriggerInterrupt);
214 uint16_t Value, uint16_t Mask)
216 uint16_t DesiredValue = Value & Mask;
265 uint16_t Mask = (1 << Pin);
266 Value = Value ? Mask : 0;
279 uint16_t Mask = (1 << Pin);
292 uint16_t Mask = (1 << Pin);
305 uint16_t Mask = (1 << Pin);
319 return GpioExtPortReadImpl(GpioExt,
true);
332 return (Port & (1 << Pin)) ? 1 : 0;
349 static inline uint16_t GpioExtInterruptsClear(
const struct gpio_ext_t* GpioExt, uint16_t Mask)
352 GpioExtPortReadImpl(GpioExt,
false);
357 return (InterruptStatus);
360 static inline uint16_t GpioExtInterruptsRead(
const struct gpio_ext_t* GpioExt)
364 return (InterruptStatus);
367 static inline void GpioExtInterruptsEnable(
const struct gpio_ext_t* GpioExt, uint16_t Mask)
377 static inline void GpioExtInterruptsDisable(
const struct gpio_ext_t* GpioExt, uint16_t Mask)
403 uint8_t ret = GpioExt->
State->Status;
412 #endif //DRIVER_GPIO_EXT_H static void GpioExtPortWrite(const struct gpio_ext_t *GpioExt, uint16_t Value, uint16_t Mask)
Write 16-bits data to the GPIO port.
gpio_ext_outport_t GpioExtOutPort
Function to write to GPIO expander port.
Operation completed successfully.
static void GpioExtPortToggle(const struct gpio_ext_t *GpioExt, uint16_t Mask)
Invert bits by mask in the GPIO port.
uint16_t InterruptMask
Internal interrupt bit mask (0 = disabled, 1 = enabled)
uint16_t InterruptStatus
Pending interrupt status.
Do not touch pin pullup / pulldown setting (leave as is)
gpio_ext_outport_t GpioExtSetPullSelect
Function to set GPIO expander pullup/pulldown.
gpio_ext_inport_t GpioExtInPort
Function to read from GPIO expander port.
Driver for port initialisazion and IO functions for nRF52 uC.
gpio_ext_outport_t GpioExtSetInterrupts
Function to enable/disable GPIO expander interrupts.
Do not touch pin direction setting (leave as is)
static uint8_t GpioExtCheckStatus(const struct gpio_ext_t *GpioExt)
Check status of GpioExt operations and reset status to GPIO_EXT_STATUS_OK.
uint8_t Drive
Pin drive force in %%.
void(* gpio_ext_init_t)(const struct gpio_ext_t *GpioExt)
Virtual function initializes pins of an gpio expander to default values based on DRIVER_PORT_EXT_INIT...
const struct gpio_ext_api_t * Func
Virtual functions table.
gpio_ext_setdrive_t GpioExtSetDrive
Function to set GPIO expander drive force.
uint16_t PullSelect
Current pullup/pulldown state (0 = pulldown, 1 = pullup)
static void GpioExtPinWrite(const struct gpio_ext_t *GpioExt, uint16_t Pin, uint16_t Value)
Set/clear 1 pin in the GPIO port.
static void GpioExtPortClear(const struct gpio_ext_t *GpioExt, uint16_t Mask)
Clear bits by mask in the GPIO port.
void IrqTriggerExternal(void)
uint16_t(* gpio_ext_inport_t)(const struct gpio_ext_t *GpioExt)
Virtual function reads from gpio expander port.
uint16_t InputValues
Last read input values.
gpio_ext_outport_t GpioExtSetPullEnable
Function to enable/disable GPIO expander pullup/pulldowen.
uint16_t Direction
Current direction state (0 = in, 1 = out)
uint8_t Value
Initial pin value.
uint16_t PortMask
Bitmask of all the pins on the port (f.ex. 0xFF for 8-bit port, 0xFFFF for 16-bit) ...
uint8_t PinsNum
Total number of pins on the port.
uint16_t atomic_xor16(volatile uint16_t *p, uint16_t value)
static void GpioExtPinSet(const struct gpio_ext_t *GpioExt, uint16_t Pin)
Set 1 pin in the GPIO port.
Header file for the EVE atomic primitives set.
const void * Impl
Device specific configuration data.
static void GpioExtPortSet(const struct gpio_ext_t *GpioExt, uint16_t Mask)
Set bits by mask in the GPIO port.
uint16_t OutputValues
Last values set for output.
static void GpioExtPinClear(const struct gpio_ext_t *GpioExt, uint16_t Pin)
Clear 1 pin in the GPIO port.
static uint16_t GpioExtPortRead(const struct gpio_ext_t *GpioExt)
Read all the pins from the GPIO port.
static void GpioExtPinToggle(const struct gpio_ext_t *GpioExt, uint16_t Pin)
Invert 1 pin in the GPIO port.
gpio_ext_outport_t GpioExtSetDirection
Function to set GPIO expander pins direction.
struct gpio_ext_state_t * State
Address to struct with RAM variables used by the driver.
gpio_ext_init_t GpioExtInit
Function to initialize GPIO expander chip.
void GpioExtInit(const struct gpio_ext_t *GpioExt)
Initialize IO expander driver and chip.
void(* gpio_ext_outport_t)(const struct gpio_ext_t *GpioExt, uint16_t Value)
Virtual function writes to gpio expander port / pin direction register / pull select register / pull ...
Disconnect pin pullup / pulldown.
gpio_ext_outport_t GpioExtSetLatch
Function to enable/disable GPIO expander interrupt latch.
External IRQ abstraction.
void(* gpio_ext_setdrive_t)(const struct gpio_ext_t *GpioExt, uint8_t Values[])
Virtual function sets drive force to gpio expander pins.
void GpioExtPortSetup(const struct gpio_ext_t *GpioExt, uint16_t Direction, uint16_t PullSelect, uint16_t PullEnable, uint16_t Mask)
Set IO expander ports to input or output.
gpio_ext_init_t GpioExtDisable
Function to deinitialize GPIO expander chip.
static uint8_t GpioExtPinRead(const struct gpio_ext_t *GpioExt, uint16_t Pin)
Read a pin value from the GPIO port.
uint16_t PullEnable
Current pull resistor enabled state (0 = off, 1 = on)