Loading...
Searching...
No Matches
pcf857x.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Gunar Schorcht
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
238
239#ifdef __cplusplus
240extern "C"
241{
242#endif
243
244#include <errno.h>
245#include <stdbool.h>
246#include <stdint.h>
247
248#include "kernel_defines.h"
249
250#include "periph/gpio.h"
251#include "periph/i2c.h"
252
253#if IS_USED(MODULE_SAUL_GPIO) || DOXYGEN
254#include "saul/periph.h"
255#endif /* MODULE_SAUL_GPIO */
256
257#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
258#include "event.h"
259#endif /* MODULE_PCF857X_IRQ */
260
269#ifndef PCF8575_BASE_ADDR
270#define PCF8575_BASE_ADDR (0x20)
273#endif
274#ifndef PCF8574_BASE_ADDR
275#define PCF8574_BASE_ADDR (0x20)
278#endif
279#ifndef PCF8574A_BASE_ADDR
280#define PCF8574A_BASE_ADDR (0x38)
283#endif
285
290#define PCF8575_GPIO_PIN_NUM (16)
291#define PCF8574_GPIO_PIN_NUM (8)
292#define PCF8574A_GPIO_PIN_NUM (8)
294
296#define PCF857X_GPIO_PIN(x,y) (y)
297
302#if IS_USED(MODULE_PCF8575) || DOXYGEN
303
310#define PCF857X_GPIO_PIN_NUM (16)
311
317typedef uint16_t pcf857x_data_t;
318
319#else /* MODULE_PCF8575 || DOXYGEN */
320
321#define PCF857X_GPIO_PIN_NUM (8)
322typedef uint8_t pcf857x_data_t;
323
324#endif /* MODULE_PCF8575 || DOXYGEN */
326
336typedef enum {
337#if IS_USED(MODULE_PCF8574) || DOXYGEN
339#endif
340#if IS_USED(MODULE_PCF8574A) || DOXYGEN
342#endif
343#if IS_USED(MODULE_PCF8575) || DOXYGEN
345#endif
346 PCF857X_EXP_MAX,
348
352typedef struct {
353
355 uint16_t addr;
359
360#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
361 gpio_t int_pin;
367#endif /* MODULE_PCF857X_IRQ */
369
370#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
386typedef struct {
388 void *dev;
390
391#endif /* MODULE_PCF857X_IRQ */
392
413
414#if IS_USED(MODULE_SAUL_GPIO) || DOXYGEN
425typedef struct {
426 unsigned int dev;
429#endif
430
447int pcf857x_init(pcf857x_t *dev, const pcf857x_params_t *params);
448
469int pcf857x_gpio_init(pcf857x_t *dev, uint8_t pin, gpio_mode_t mode);
470
471#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
507int pcf857x_gpio_init_int(pcf857x_t *dev, uint8_t pin,
508 gpio_mode_t mode,
509 gpio_flank_t flank,
510 gpio_cb_t isr,
511 void *arg);
512#endif /* MODULE_PCF857X_IRQ || DOXYGEN */
513
523int pcf857x_gpio_read(pcf857x_t *dev, uint8_t pin);
524
532void pcf857x_gpio_write(pcf857x_t *dev, uint8_t pin, int value);
533
540void pcf857x_gpio_clear(pcf857x_t *dev, uint8_t pin);
541
548void pcf857x_gpio_set(pcf857x_t *dev, uint8_t pin);
549
556void pcf857x_gpio_toggle(pcf857x_t *dev, uint8_t pin);
557
558#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
568void pcf857x_gpio_irq_enable(pcf857x_t *dev, uint8_t pin);
569
579void pcf857x_gpio_irq_disable(pcf857x_t *dev, uint8_t pin);
580#endif /* MODULE_PCF857X_IRQ || DOXYGEN */
581
582#ifdef __cplusplus
583}
584#endif
585
gpio_flank_t
Definition periph_cpu.h:176
Low-level GPIO peripheral driver interface definitions.
gpio_mode_t
Available pin modes.
Definition periph_cpu.h:96
int pcf857x_init(pcf857x_t *dev, const pcf857x_params_t *params)
Initialize the PCF857X I/O expander.
pcf857x_exp_t
Definition of PCF857X expander variants.
Definition pcf857x.h:336
void pcf857x_gpio_irq_disable(pcf857x_t *dev, uint8_t pin)
Disable pin interrupt.
uint16_t pcf857x_data_t
Data type that can mask all expander pins.
Definition pcf857x.h:317
void pcf857x_gpio_write(pcf857x_t *dev, uint8_t pin, int value)
Write the value to PCF857X input pin.
#define PCF857X_GPIO_PIN_NUM
Maximum number of GPIO pins.
Definition pcf857x.h:310
int pcf857x_gpio_init(pcf857x_t *dev, uint8_t pin, gpio_mode_t mode)
Initialize a PCF857X pin.
void pcf857x_gpio_irq_enable(pcf857x_t *dev, uint8_t pin)
Enable pin interrupt.
void pcf857x_gpio_clear(pcf857x_t *dev, uint8_t pin)
Clear the PCF857X output pin.
int pcf857x_gpio_init_int(pcf857x_t *dev, uint8_t pin, gpio_mode_t mode, gpio_flank_t flank, gpio_cb_t isr, void *arg)
Initialize a PCF857X pin for external interrupt usage.
void pcf857x_gpio_set(pcf857x_t *dev, uint8_t pin)
Set the PCF857X output pin.
int pcf857x_gpio_read(pcf857x_t *dev, uint8_t pin)
Get the value from PCF857X input pin.
void pcf857x_gpio_toggle(pcf857x_t *dev, uint8_t pin)
Toggle the value of the PCF857X output pin.
@ PCF857X_EXP_PCF8574
PCF8574 8 bit I/O expander used.
Definition pcf857x.h:338
@ PCF857X_EXP_PCF8575
PCF8575 16 bit I/O expander.
Definition pcf857x.h:344
@ PCF857X_EXP_PCF8574A
PCF8574A 8 bit I/O expander.
Definition pcf857x.h:341
void(* gpio_cb_t)(void *arg)
Signature of event callback functions triggered from interrupts.
Definition gpio.h:143
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:155
struct event event_t
event structure forward declaration
Definition event.h:135
Low-level I2C peripheral driver interface definition.
Common macros and compiler attributes/pragmas configuration.
Parameter definitions for mapping peripherals directly to SAUL.
Default interrupt context for GPIO pins.
Definition gpio.h:149
IRQ event type.
Definition pcf857x.h:386
event_t event
inherited event data structure
Definition pcf857x.h:387
void * dev
PCF857X device reference.
Definition pcf857x.h:388
PCF857X device initialization parameters.
Definition pcf857x.h:352
pcf857x_exp_t exp
PCF857X expander variant used by the device (default depends on used pseudomodules.
Definition pcf857x.h:357
gpio_t int_pin
MCU GPIO pin or GPIO_UNDEF if not used (default).
Definition pcf857x.h:361
i2c_t dev
I2C device (default I2C_DEV(0))
Definition pcf857x.h:354
uint16_t addr
I2C slave address offset to the PCF7857X base address (default 0)
Definition pcf857x.h:355
PCF857X configuration structure for mapping expander pins to SAUL.
Definition pcf857x.h:425
unsigned int dev
PCF857X device index.
Definition pcf857x.h:426
saul_gpio_params_t gpio
GPIO configuration for mapping to SAUL.
Definition pcf857x.h:427
PCF857X device data structure type.
Definition pcf857x.h:396
pcf857x_params_t params
device initialization parameters
Definition pcf857x.h:397
pcf857x_data_t modes
expander pin modes
Definition pcf857x.h:401
pcf857x_irq_event_t irq_event
IRQ event object used for the device.
Definition pcf857x.h:409
gpio_isr_ctx_t isr[PCF857X_GPIO_PIN_NUM]
ISR with arg for each expander pin.
Definition pcf857x.h:406
uint8_t pin_num
number of I/O pins, depends on used expander variant
Definition pcf857x.h:399
gpio_flank_t flank[PCF857X_GPIO_PIN_NUM]
interrupt flank for each expander pin
Definition pcf857x.h:407
pcf857x_data_t in
expander input pin values
Definition pcf857x.h:402
pcf857x_data_t out
expander output pin values
Definition pcf857x.h:403
bool enabled[PCF857X_GPIO_PIN_NUM]
enabled flag for each expander pin
Definition pcf857x.h:408
Direct mapped GPIO configuration values.
Definition periph.h:47