Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
mcp230xx.h
Go to the documentation of this file.
1/*
2 * This file is part of the Ultibo project, https://ultibo.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2026 Garry Wood <garry@softoz.com.au>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26#ifndef _ULTIBO_MCP230XX_H
27#define _ULTIBO_MCP230XX_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include "ultibo/gpio.h"
34#include "ultibo/i2c.h"
35
37#define MCP23008_GPIO_DESCRIPTION "Microchip MCP23008 8-bit I/O Expander"
38#define MCP23017_GPIO_DESCRIPTION "Microchip MCP23016 16-bit I/O Expander"
39
40#define MCP23008_GPIO_MIN_PIN GPIO_PIN_0
41#define MCP23008_GPIO_MAX_PIN GPIO_PIN_7
42#define MCP23008_GPIO_PIN_COUNT 8
43
44#define MCP23017_GPIO_MIN_PIN GPIO_PIN_0
45#define MCP23017_GPIO_MAX_PIN GPIO_PIN_15
46#define MCP23017_GPIO_PIN_COUNT 16
47
48#define MCP230XX_GPIO_MAX_LEVEL GPIO_LEVEL_HIGH
49
50#define MCP230XX_GPIO_MAX_PULL GPIO_PULL_UP
51
52#define MCP230XX_GPIO_MIN_FUNCTION GPIO_FUNCTION_IN
53#define MCP230XX_GPIO_MAX_FUNCTION GPIO_FUNCTION_OUT
54
56#define MCP230XX_CHIP_MCP23008 0
57#define MCP230XX_CHIP_MCP23017 1
58
60#define MCP230XX_I2C_RATE 400000
61
62#define MCP23008_I2C_SIZE 1
63#define MCP23017_I2C_SIZE 2
64
65#define MCP230XX_I2C_MAX_SIZE 2
66
67#define MCP23008_I2C_MAX_REG 0x0A
68#define MCP23017_I2C_MAX_REG 0x1A
69
73{
74 // GPIO Properties
76 // MCP230XX Properties
78 uint16_t address;
79 uint32_t chip;
80 uint32_t size;
81 uint8_t gpioreg;
82 uint8_t gppureg;
83 uint8_t iodirreg;
87};
88
90
98
106
113
114#ifdef __cplusplus
115}
116#endif
117
118#endif // _ULTIBO_MCP230XX_H
#define STDCALL
Definition globaltypes.h:45
struct _GPIO_DEVICE GPIO_DEVICE
Forward declared for GPIOPin.
Definition gpio.h:85
struct _I2C_DEVICE I2C_DEVICE
Definition i2c.h:81
GPIO_DEVICE *STDCALL mcp23017_gpio_create(I2C_DEVICE *i2c, uint16_t address)
Create, register and start a new MCP23017 GPIO device connected to the specified I2C device.
uint32_t STDCALL mcp230xx_gpio_destroy(GPIO_DEVICE *gpio)
Stop, deregister and destroy an MCP230XX GPIO device created by this driver.
GPIO_DEVICE *STDCALL mcp23008_gpio_create(I2C_DEVICE *i2c, uint16_t address)
Create, register and start a new MCP23008 GPIO device connected to the specified I2C device.
#define MCP230XX_I2C_MAX_SIZE
Maximum number of bytes to read/write all pin values for any register.
Definition mcp230xx.h:65
struct _MCP230XXGPIO MCP230XXGPIO
Definition mcp230xx.h:71
Definition mcp230xx.h:73
GPIO_DEVICE gpio
Definition mcp230xx.h:75
uint8_t gppuvalues[MCP230XX_I2C_MAX_SIZE]
Buffer for GPPU pull up values.
Definition mcp230xx.h:85
I2C_DEVICE * i2c
The I2C device this GPIO is connected to.
Definition mcp230xx.h:77
uint8_t gppureg
GPPU pull up resistor register for the device.
Definition mcp230xx.h:82
uint16_t address
The I2C address of the device.
Definition mcp230xx.h:78
uint8_t iodirvalues[MCP230XX_I2C_MAX_SIZE]
Buffer for IODIR I/O direction values.
Definition mcp230xx.h:86
uint8_t gpiovalues[MCP230XX_I2C_MAX_SIZE]
Buffer for GPIO port values (Output only).
Definition mcp230xx.h:84
uint32_t size
Size of an I2C read/write for the device.
Definition mcp230xx.h:80
uint8_t gpioreg
GPIO port register for the device.
Definition mcp230xx.h:81
uint32_t chip
The chip type (eg MCP230XX_CHIP_MCP23008).
Definition mcp230xx.h:79
uint8_t iodirreg
IODIR I/O direction register for the device.
Definition mcp230xx.h:83