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
9#pragma once
10
241
242#ifdef __cplusplus
243extern "C"
244{
245#endif
246
247#include <errno.h>
248#include <stdbool.h>
249#include <stdint.h>
250
251#include "kernel_defines.h"
252
253#include "periph/gpio.h"
254#include "periph/i2c.h"
255
256#if IS_USED(MODULE_SAUL_GPIO) || DOXYGEN
257#include "saul/periph.h"
258#endif /* MODULE_SAUL_GPIO */
259
260#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
261#include "event.h"
262#endif /* MODULE_PCF857X_IRQ */
263
272#ifndef PCF8575_BASE_ADDR
273#define PCF8575_BASE_ADDR (0x20)
276#endif
277#ifndef PCF8574_BASE_ADDR
278#define PCF8574_BASE_ADDR (0x20)
281#endif
282#ifndef PCF8574A_BASE_ADDR
283#define PCF8574A_BASE_ADDR (0x38)
286#endif
288
293#define PCF8575_GPIO_PIN_NUM (16)
294#define PCF8574_GPIO_PIN_NUM (8)
295#define PCF8574A_GPIO_PIN_NUM (8)
297
299#define PCF857X_GPIO_PIN(x,y) (y)
300
305#if IS_USED(MODULE_PCF8575) || DOXYGEN
306
313#define PCF857X_GPIO_PIN_NUM (16)
314
320typedef uint16_t pcf857x_data_t;
321
322#else /* MODULE_PCF8575 || DOXYGEN */
323
324#define PCF857X_GPIO_PIN_NUM (8)
325typedef uint8_t pcf857x_data_t;
326
327#endif /* MODULE_PCF8575 || DOXYGEN */
329
343
353typedef enum {
354#if IS_USED(MODULE_PCF8574) || DOXYGEN
356#endif
357#if IS_USED(MODULE_PCF8574A) || DOXYGEN
359#endif
360#if IS_USED(MODULE_PCF8575) || DOXYGEN
362#endif
363 PCF857X_EXP_MAX,
365
369typedef struct {
370
372 uint16_t addr;
376
377#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
378 gpio_t int_pin;
384#endif /* MODULE_PCF857X_IRQ */
386
387#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
403typedef struct {
405 void *dev;
407
408#endif /* MODULE_PCF857X_IRQ */
409
430
431#if IS_USED(MODULE_SAUL_GPIO) || DOXYGEN
442typedef struct {
443 unsigned int dev;
446#endif
447
464int pcf857x_init(pcf857x_t *dev, const pcf857x_params_t *params);
465
486int pcf857x_gpio_init(pcf857x_t *dev, uint8_t pin, gpio_mode_t mode);
487
488#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
524int pcf857x_gpio_init_int(pcf857x_t *dev, uint8_t pin,
525 gpio_mode_t mode,
526 gpio_flank_t flank,
527 gpio_cb_t isr,
528 void *arg);
529#endif /* MODULE_PCF857X_IRQ || DOXYGEN */
530
540int pcf857x_gpio_read(pcf857x_t *dev, uint8_t pin);
541
549void pcf857x_gpio_write(pcf857x_t *dev, uint8_t pin, int value);
550
557void pcf857x_gpio_clear(pcf857x_t *dev, uint8_t pin);
558
565void pcf857x_gpio_set(pcf857x_t *dev, uint8_t pin);
566
573void pcf857x_gpio_toggle(pcf857x_t *dev, uint8_t pin);
574
575#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
585void pcf857x_gpio_irq_enable(pcf857x_t *dev, uint8_t pin);
586
596void pcf857x_gpio_irq_disable(pcf857x_t *dev, uint8_t pin);
597#endif /* MODULE_PCF857X_IRQ || DOXYGEN */
598
599#ifdef __cplusplus
600}
601#endif
602
gpio_flank_t
Definition periph_cpu.h:176
Low-level GPIO peripheral driver interface definitions.
#define ENXIO
No such device or address.
Definition errno.h:131
#define EINVAL
Invalid argument.
Definition errno.h:96
#define ENOSYS
Function not supported.
Definition errno.h:123
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition errno.h:129
gpio_mode_t
Available pin modes.
Definition periph_cpu.h:91
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:353
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:320
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:313
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:335
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:355
@ PCF857X_EXP_PCF8575
PCF8575 16 bit I/O expander.
Definition pcf857x.h:361
@ PCF857X_EXP_PCF8574A
PCF8574A 8 bit I/O expander.
Definition pcf857x.h:358
@ PCF857X_ERROR_INT_PIN
interrupt pin initialization failed
Definition pcf857x.h:341
@ PCF857X_ERROR_INV_FLANK
invalid interrupt flank
Definition pcf857x.h:340
@ PCF857X_OK
success
Definition pcf857x.h:336
@ PCF857X_ERROR_INV_EXP
invalid expander variant
Definition pcf857x.h:338
@ PCF857X_ERROR_I2C
I2C communication error.
Definition pcf857x.h:337
@ PCF857X_ERROR_INV_MODE
invalid pin mode
Definition pcf857x.h:339
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:144
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:152
IRQ event type.
Definition pcf857x.h:403
event_t event
inherited event data structure
Definition pcf857x.h:404
void * dev
PCF857X device reference.
Definition pcf857x.h:405
PCF857X device initialization parameters.
Definition pcf857x.h:369
pcf857x_exp_t exp
PCF857X expander variant used by the device (default depends on used pseudomodules.
Definition pcf857x.h:374
gpio_t int_pin
MCU GPIO pin or GPIO_UNDEF if not used (default).
Definition pcf857x.h:378
i2c_t dev
I2C device (default I2C_DEV(0))
Definition pcf857x.h:371
uint16_t addr
I2C slave address offset to the PCF7857X base address (default 0)
Definition pcf857x.h:372
PCF857X configuration structure for mapping expander pins to SAUL.
Definition pcf857x.h:442
unsigned int dev
PCF857X device index.
Definition pcf857x.h:443
saul_gpio_params_t gpio
GPIO configuration for mapping to SAUL.
Definition pcf857x.h:444
PCF857X device data structure type.
Definition pcf857x.h:413
pcf857x_params_t params
device initialization parameters
Definition pcf857x.h:414
pcf857x_data_t modes
expander pin modes
Definition pcf857x.h:418
pcf857x_irq_event_t irq_event
IRQ event object used for the device.
Definition pcf857x.h:426
gpio_isr_ctx_t isr[PCF857X_GPIO_PIN_NUM]
ISR with arg for each expander pin.
Definition pcf857x.h:423
uint8_t pin_num
number of I/O pins, depends on used expander variant
Definition pcf857x.h:416
gpio_flank_t flank[PCF857X_GPIO_PIN_NUM]
interrupt flank for each expander pin
Definition pcf857x.h:424
pcf857x_data_t in
expander input pin values
Definition pcf857x.h:419
pcf857x_data_t out
expander output pin values
Definition pcf857x.h:420
bool enabled[PCF857X_GPIO_PIN_NUM]
enabled flag for each expander pin
Definition pcf857x.h:425
Direct mapped GPIO configuration values.
Definition periph.h:50