pca9505.h (1210B)
1 // Copyright 2022 nirim000 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 * Port ID 11 */ 12 typedef enum { 13 PCA9505_PORT0, 14 PCA9505_PORT1, 15 PCA9505_PORT2, 16 PCA9505_PORT3, 17 PCA9505_PORT4, 18 } pca9505_port_t; 19 20 /** 21 * Helpers for set_config 22 */ 23 enum { 24 ALL_NORMAL = 0, 25 ALL_INVERTED = 0xFF, 26 }; 27 28 /** 29 * Helpers for set_config 30 */ 31 enum { 32 ALL_OUTPUT = 0, 33 ALL_INPUT = 0xFF, 34 }; 35 36 /** 37 * Helpers for set_output 38 */ 39 enum { 40 ALL_LOW = 0, 41 ALL_HIGH = 0xFF, 42 }; 43 44 /** 45 * Init expander and any other dependent drivers 46 */ 47 void pca9505_init(uint8_t slave_addr); 48 49 /** 50 * Configure input/output to a given port 51 */ 52 bool pca9505_set_config(uint8_t slave_addr, pca9505_port_t port, uint8_t conf); 53 54 /** 55 * Configure polarity to a given port 56 */ 57 bool pca9505_set_polarity(uint8_t slave_addr, pca9505_port_t port, uint8_t conf); 58 59 /** 60 * Write high/low to a given port 61 */ 62 bool pca9505_set_output(uint8_t slave_addr, pca9505_port_t port, uint8_t conf); 63 64 /** 65 * Read state of a given port 66 */ 67 bool pca9505_read_pins(uint8_t slave_addr, pca9505_port_t port, uint8_t* ret); 68 69 // DEPRECATED - DO NOT USE 70 71 #define pca9505_readPins pca9505_read_pins