mcp23018.h (1355B)
1 // Copyright 2022 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 * Port ID 11 */ 12 typedef enum { 13 mcp23018_PORTA, 14 mcp23018_PORTB, 15 } mcp23018_port_t; 16 17 /** 18 * Helpers for set_config 19 */ 20 enum { 21 ALL_OUTPUT = 0, 22 ALL_INPUT = 0xFF, 23 }; 24 25 /** 26 * Helpers for set_output 27 */ 28 enum { 29 ALL_LOW = 0, 30 ALL_HIGH = 0xFF, 31 }; 32 33 /** 34 * Init expander and any other dependent drivers 35 */ 36 void mcp23018_init(uint8_t slave_addr); 37 38 /** 39 * Configure input/output to a given port 40 */ 41 bool mcp23018_set_config(uint8_t slave_addr, mcp23018_port_t port, uint8_t conf); 42 43 /** 44 * Write high/low to a given port 45 */ 46 bool mcp23018_set_output(uint8_t slave_addr, mcp23018_port_t port, uint8_t conf); 47 48 /** 49 * Write high/low to both ports sequentially 50 * 51 * - slightly faster than multiple set_output 52 */ 53 bool mcp23018_set_output_all(uint8_t slave_addr, uint8_t confA, uint8_t confB); 54 55 /** 56 * Read state of a given port 57 */ 58 bool mcp23018_read_pins(uint8_t slave_addr, mcp23018_port_t port, uint8_t* ret); 59 60 /** 61 * Read state of both ports sequentially 62 * 63 * - slightly faster than multiple readPins 64 */ 65 bool mcp23018_read_pins_all(uint8_t slave_addr, uint16_t* ret); 66 67 // DEPRECATED - DO NOT USE 68 69 #define mcp23018_readPins mcp23018_read_pins 70 #define mcp23018_readPins_all mcp23018_read_pins_all