Parent directory

pca9555.h

1880 bytes
 1// Copyright 2020 zvecr<git@zvecr.com>
 2// SPDX-License-Identifier: GPL-2.0-or-later
 3
 4#pragma once
 5
 6#include <stdint.h>
 7#include <stdbool.h>
 8
 9/*
10            PCA9555
11         ,----------.
12   SDA --| SDA  P00 |-- P00
13   SCL --| SCL  P01 |-- P01
14   INT --| INT  P02 |-- P02
15         |      P03 |-- P03
16   A0  --| A0   P04 |-- P04
17   A1  --| A1   P05 |-- P05
18   A2  --| A2   P06 |-- P06
19         |      P07 |-- P07
20         |          |
21         |      P10 |-- P10
22         |      P11 |-- P11
23         |      P12 |-- P12
24         |      P13 |-- P13
25         |      P14 |-- P14
26         |      P15 |-- P15
27         |      P16 |-- P16
28         |      P17 |-- P17
29         `----------'
30*/
31
32/**
33 * Port ID
34 */
35typedef enum {
36    PCA9555_PORT0,
37    PCA9555_PORT1,
38} pca9555_port_t;
39
40/**
41 * Helpers for set_config
42 */
43enum {
44    ALL_OUTPUT = 0,
45    ALL_INPUT  = 0xFF,
46};
47
48/**
49 * Helpers for set_output
50 */
51enum {
52    ALL_LOW  = 0,
53    ALL_HIGH = 0xFF,
54};
55
56/**
57 * Init expander and any other dependent drivers
58 */
59void pca9555_init(uint8_t slave_addr);
60
61/**
62 * Configure input/output to a given port
63 */
64bool pca9555_set_config(uint8_t slave_addr, pca9555_port_t port, uint8_t conf);
65
66/**
67 * Write high/low to a given port
68 */
69bool pca9555_set_output(uint8_t slave_addr, pca9555_port_t port, uint8_t conf);
70
71/**
72 * Write high/low to both ports sequentially
73 *
74 *  - slightly faster than multiple set_output
75 */
76bool pca9555_set_output_all(uint8_t slave_addr, uint8_t confA, uint8_t confB);
77
78/**
79 * Read state of a given port
80 */
81bool pca9555_read_pins(uint8_t slave_addr, pca9555_port_t port, uint8_t* ret);
82
83/**
84 * Read state of both ports sequentially
85 *
86 *  - slightly faster than multiple readPins
87 */
88bool pca9555_read_pins_all(uint8_t slave_addr, uint16_t* ret);
89
90// DEPRECATED - DO NOT USE
91
92#define pca9555_readPins pca9555_read_pins
93#define pca9555_readPins_all pca9555_read_pins_all