Loading...
Searching...
No Matches
pcf857x.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018 Gunar Schorcht
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
240#ifndef PCF857X_H
241#define PCF857X_H
242
243#ifdef __cplusplus
244extern "C"
245{
246#endif
247
248#include <errno.h>
249#include <stdbool.h>
250#include <stdint.h>
251
252#include "kernel_defines.h"
253
254#include "periph/gpio.h"
255#include "periph/i2c.h"
256
257#if IS_USED(MODULE_SAUL_GPIO) || DOXYGEN
258#include "saul/periph.h"
259#endif /* MODULE_SAUL_GPIO */
260
261#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
262#include "event.h"
263#endif /* MODULE_PCF857X_IRQ */
264
273#ifndef PCF8575_BASE_ADDR
274#define PCF8575_BASE_ADDR (0x20)
277#endif
278#ifndef PCF8574_BASE_ADDR
279#define PCF8574_BASE_ADDR (0x20)
282#endif
283#ifndef PCF8574A_BASE_ADDR
284#define PCF8574A_BASE_ADDR (0x38)
287#endif
294#define PCF8575_GPIO_PIN_NUM (16)
295#define PCF8574_GPIO_PIN_NUM (8)
296#define PCF8574A_GPIO_PIN_NUM (8)
300#define PCF857X_GPIO_PIN(x,y) (y)
301
306#if IS_USED(MODULE_PCF8575) || DOXYGEN
307
314#define PCF857X_GPIO_PIN_NUM (16)
315
321typedef uint16_t pcf857x_data_t;
322
323#else /* MODULE_PCF8575 || DOXYGEN */
324
325#define PCF857X_GPIO_PIN_NUM (8)
326typedef uint8_t pcf857x_data_t;
328#endif /* MODULE_PCF8575 || DOXYGEN */
344
354typedef enum {
355#if IS_USED(MODULE_PCF8574) || DOXYGEN
357#endif
358#if IS_USED(MODULE_PCF8574A) || DOXYGEN
360#endif
361#if IS_USED(MODULE_PCF8575) || DOXYGEN
363#endif
364 PCF857X_EXP_MAX,
366
370typedef struct {
371
373 uint16_t addr;
378#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
379 gpio_t int_pin;
385#endif /* MODULE_PCF857X_IRQ */
387
388#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
404typedef struct {
406 void *dev;
408
409#endif /* MODULE_PCF857X_IRQ */
410
414typedef struct {
417 uint8_t pin_num;
423#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
426 bool enabled[PCF857X_GPIO_PIN_NUM];
428#endif /* MODULE_PCF857X_IRQ */
429
430} pcf857x_t;
431
432#if IS_USED(MODULE_SAUL_GPIO) || DOXYGEN
443typedef struct {
444 unsigned int dev;
447#endif
448
465int pcf857x_init(pcf857x_t *dev, const pcf857x_params_t *params);
466
487int pcf857x_gpio_init(pcf857x_t *dev, uint8_t pin, gpio_mode_t mode);
488
489#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
525int pcf857x_gpio_init_int(pcf857x_t *dev, uint8_t pin,
526 gpio_mode_t mode,
527 gpio_flank_t flank,
528 gpio_cb_t isr,
529 void *arg);
530#endif /* MODULE_PCF857X_IRQ || DOXYGEN */
531
541int pcf857x_gpio_read(pcf857x_t *dev, uint8_t pin);
542
550void pcf857x_gpio_write(pcf857x_t *dev, uint8_t pin, int value);
551
558void pcf857x_gpio_clear(pcf857x_t *dev, uint8_t pin);
559
566void pcf857x_gpio_set(pcf857x_t *dev, uint8_t pin);
567
574void pcf857x_gpio_toggle(pcf857x_t *dev, uint8_t pin);
575
576#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
586void pcf857x_gpio_irq_enable(pcf857x_t *dev, uint8_t pin);
587
597void pcf857x_gpio_irq_disable(pcf857x_t *dev, uint8_t pin);
598#endif /* MODULE_PCF857X_IRQ || DOXYGEN */
599
600#ifdef __cplusplus
601}
602#endif
603
604#endif /* PCF857X_H */
gpio_flank_t
Definition periph_cpu.h:180
Low-level GPIO peripheral driver interface definitions.
#define ENXIO
No such device or address.
Definition errno.h:132
#define EINVAL
Invalid argument.
Definition errno.h:97
#define ENOSYS
Function not supported.
Definition errno.h:124
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition errno.h:130
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:354
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:321
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:314
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.
pcf857x_error_codes_t
Definition of PCF857X driver error codes.
Definition pcf857x.h:336
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:356
@ PCF857X_EXP_PCF8575
PCF8575 16 bit I/O expander.
Definition pcf857x.h:362
@ PCF857X_EXP_PCF8574A
PCF8574A 8 bit I/O expander.
Definition pcf857x.h:359
@ PCF857X_ERROR_INT_PIN
interrupt pin initialization failed
Definition pcf857x.h:342
@ PCF857X_ERROR_INV_FLANK
invalid interrupt flank
Definition pcf857x.h:341
@ PCF857X_OK
success
Definition pcf857x.h:337
@ PCF857X_ERROR_INV_EXP
invalid expander variant
Definition pcf857x.h:339
@ PCF857X_ERROR_I2C
I2C communication error.
Definition pcf857x.h:338
@ PCF857X_ERROR_INV_MODE
invalid pin mode
Definition pcf857x.h:340
void(* gpio_cb_t)(void *arg)
Signature of event callback functions triggered from interrupts.
Definition gpio.h:146
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:151
Low-level I2C peripheral driver interface definition.
Common macros and compiler attributes/pragmas configuration.
gpio_mode_t
Available pin modes.
Definition periph_cpu.h:82
Parameter definitions for mapping peripherals directly to SAUL.
event structure
Definition event.h:148
Default interrupt context for GPIO pins.
Definition gpio.h:152
IRQ event type.
Definition pcf857x.h:404
event_t event
inherited event data structure
Definition pcf857x.h:405
void * dev
PCF857X device reference.
Definition pcf857x.h:406
PCF857X device initialization parameters.
Definition pcf857x.h:370
pcf857x_exp_t exp
PCF857X expander variant used by the device (default depends on used pseudomodules.
Definition pcf857x.h:375
gpio_t int_pin
MCU GPIO pin or GPIO_UNDEF if not used (default).
Definition pcf857x.h:379
i2c_t dev
I2C device (default I2C_DEV(0))
Definition pcf857x.h:372
uint16_t addr
I2C slave address offset to the PCF7857X base address (default 0)
Definition pcf857x.h:373
PCF857X configuration structure for mapping expander pins to SAUL.
Definition pcf857x.h:443
unsigned int dev
PCF857X device index.
Definition pcf857x.h:444
saul_gpio_params_t gpio
GPIO configuration for mapping to SAUL.
Definition pcf857x.h:445
PCF857X device data structure type.
Definition pcf857x.h:414
pcf857x_params_t params
device initialization parameters
Definition pcf857x.h:415
pcf857x_data_t modes
expander pin modes
Definition pcf857x.h:419
pcf857x_irq_event_t irq_event
IRQ event object used for the device.
Definition pcf857x.h:427
uint8_t pin_num
number of I/O pins, depends on used expander variant
Definition pcf857x.h:417
pcf857x_data_t in
expander input pin values
Definition pcf857x.h:420
pcf857x_data_t out
expander output pin values
Definition pcf857x.h:421
Direct mapped GPIO configuration values.
Definition periph.h:51