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
339typedef enum {
340#if IS_USED(MODULE_PCF8574) || DOXYGEN
342#endif
343#if IS_USED(MODULE_PCF8574A) || DOXYGEN
345#endif
346#if IS_USED(MODULE_PCF8575) || DOXYGEN
348#endif
349 PCF857X_EXP_MAX,
351
355typedef struct {
356
358 uint16_t addr;
362
363#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
364 gpio_t int_pin;
370#endif /* MODULE_PCF857X_IRQ */
372
373#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
389typedef struct {
391 void *dev;
393
394#endif /* MODULE_PCF857X_IRQ */
395
416
417#if IS_USED(MODULE_SAUL_GPIO) || DOXYGEN
428typedef struct {
429 unsigned int dev;
432#endif
433
450int pcf857x_init(pcf857x_t *dev, const pcf857x_params_t *params);
451
472int pcf857x_gpio_init(pcf857x_t *dev, uint8_t pin, gpio_mode_t mode);
473
474#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
510int pcf857x_gpio_init_int(pcf857x_t *dev, uint8_t pin,
511 gpio_mode_t mode,
512 gpio_flank_t flank,
513 gpio_cb_t isr,
514 void *arg);
515#endif /* MODULE_PCF857X_IRQ || DOXYGEN */
516
526int pcf857x_gpio_read(pcf857x_t *dev, uint8_t pin);
527
535void pcf857x_gpio_write(pcf857x_t *dev, uint8_t pin, int value);
536
543void pcf857x_gpio_clear(pcf857x_t *dev, uint8_t pin);
544
551void pcf857x_gpio_set(pcf857x_t *dev, uint8_t pin);
552
559void pcf857x_gpio_toggle(pcf857x_t *dev, uint8_t pin);
560
561#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
571void pcf857x_gpio_irq_enable(pcf857x_t *dev, uint8_t pin);
572
582void pcf857x_gpio_irq_disable(pcf857x_t *dev, uint8_t pin);
583#endif /* MODULE_PCF857X_IRQ || DOXYGEN */
584
585#ifdef __cplusplus
586}
587#endif
588
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:339
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.
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:341
@ PCF857X_EXP_PCF8575
PCF8575 16 bit I/O expander.
Definition pcf857x.h:347
@ PCF857X_EXP_PCF8574A
PCF8574A 8 bit I/O expander.
Definition pcf857x.h:344
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:135
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:389
event_t event
inherited event data structure
Definition pcf857x.h:390
void * dev
PCF857X device reference.
Definition pcf857x.h:391
PCF857X device initialization parameters.
Definition pcf857x.h:355
pcf857x_exp_t exp
PCF857X expander variant used by the device (default depends on used pseudomodules.
Definition pcf857x.h:360
gpio_t int_pin
MCU GPIO pin or GPIO_UNDEF if not used (default).
Definition pcf857x.h:364
i2c_t dev
I2C device (default I2C_DEV(0))
Definition pcf857x.h:357
uint16_t addr
I2C slave address offset to the PCF7857X base address (default 0)
Definition pcf857x.h:358
PCF857X configuration structure for mapping expander pins to SAUL.
Definition pcf857x.h:428
unsigned int dev
PCF857X device index.
Definition pcf857x.h:429
saul_gpio_params_t gpio
GPIO configuration for mapping to SAUL.
Definition pcf857x.h:430
PCF857X device data structure type.
Definition pcf857x.h:399
pcf857x_params_t params
device initialization parameters
Definition pcf857x.h:400
pcf857x_data_t modes
expander pin modes
Definition pcf857x.h:404
pcf857x_irq_event_t irq_event
IRQ event object used for the device.
Definition pcf857x.h:412
gpio_isr_ctx_t isr[PCF857X_GPIO_PIN_NUM]
ISR with arg for each expander pin.
Definition pcf857x.h:409
uint8_t pin_num
number of I/O pins, depends on used expander variant
Definition pcf857x.h:402
gpio_flank_t flank[PCF857X_GPIO_PIN_NUM]
interrupt flank for each expander pin
Definition pcf857x.h:410
pcf857x_data_t in
expander input pin values
Definition pcf857x.h:405
pcf857x_data_t out
expander output pin values
Definition pcf857x.h:406
bool enabled[PCF857X_GPIO_PIN_NUM]
enabled flag for each expander pin
Definition pcf857x.h:411
Direct mapped GPIO configuration values.
Definition periph.h:50