Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gpio_ext_pca95xx.c
Go to the documentation of this file.
1/*
2 * Copyright (C) Tom van Dijk <tomvand@users.noreply.github.com>
3 *
4 * This file is part of paparazzi
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
27
29#include "generated/airframe.h"
30#include "peripherals/pca95xx.h"
31#include "mcu_periph/i2c.h"
32
33#include <stdbool.h>
34
35
36#ifdef GPIO_EXT_PCA95XX_I2C_PERIPH1
37#define GPIO_EXT_PCA95XX_I2C_PERIPH1_PTR &(GPIO_EXT_PCA95XX_I2C_PERIPH1)
38#else
39#define GPIO_EXT_PCA95XX_I2C_PERIPH1_PTR NULL
40#endif
41#ifdef GPIO_EXT_PCA95XX_I2C_PERIPH2
42#define GPIO_EXT_PCA95XX_I2C_PERIPH2_PTR &(GPIO_EXT_PCA95XX_I2C_PERIPH2)
43#else
44#define GPIO_EXT_PCA95XX_I2C_PERIPH2_PTR NULL
45#endif
46#ifdef GPIO_EXT_PCA95XX_I2C_PERIPH3
47#define GPIO_EXT_PCA95XX_I2C_PERIPH3_PTR &(GPIO_EXT_PCA95XX_I2C_PERIPH3)
48#else
49#define GPIO_EXT_PCA95XX_I2C_PERIPH3_PTR NULL
50#endif
51#ifdef GPIO_EXT_PCA95XX_I2C_PERIPH4
52#define GPIO_EXT_PCA95XX_I2C_PERIPH4_PTR &(GPIO_EXT_PCA95XX_I2C_PERIPH4)
53#else
54#define GPIO_EXT_PCA95XX_I2C_PERIPH4_PTR NULL
55#endif
62
63#ifndef GPIO_EXT_PCA95XX_I2C_ADDRESS1
64#define GPIO_EXT_PCA95XX_I2C_ADDRESS1 0x00
65#endif
66#ifndef GPIO_EXT_PCA95XX_I2C_ADDRESS2
67#define GPIO_EXT_PCA95XX_I2C_ADDRESS2 0x00
68#endif
69#ifndef GPIO_EXT_PCA95XX_I2C_ADDRESS3
70#define GPIO_EXT_PCA95XX_I2C_ADDRESS3 0x00
71#endif
72#ifndef GPIO_EXT_PCA95XX_I2C_ADDRESS4
73#define GPIO_EXT_PCA95XX_I2C_ADDRESS4 0x00
74#endif
81
82#ifndef GPIO_EXT_PCA95XX_BLOCKING1
83#define GPIO_EXT_PCA95XX_BLOCKING1 TRUE
84#endif
85#ifndef GPIO_EXT_PCA95XX_BLOCKING2
86#define GPIO_EXT_PCA95XX_BLOCKING2 TRUE
87#endif
88#ifndef GPIO_EXT_PCA95XX_BLOCKING3
89#define GPIO_EXT_PCA95XX_BLOCKING3 TRUE
90#endif
91#ifndef GPIO_EXT_PCA95XX_BLOCKING4
92#define GPIO_EXT_PCA95XX_BLOCKING4 TRUE
93#endif
100
101
108
109
118
119
126static struct gpio_ext_pca95xx_impl_t impl[GPIOEXT_NB]; // Initialized 0, so .initialized = false!
127
128
130 int i = port - GPIOEXT1;
131 if (impl[i].initialized) return;
132 /* Set up pca95xx implementation struct */
133 impl[i].output_reg = 0xFF;
134 impl[i].config_reg = 0xFF;
135 /* Set up pca95xx peripheral */
137 /* Configure pins as input (default) and wait for IC to wake up */
138 do {
139 pca95xx_configure(&impl[i].periph, 0xFF, true);
141 /* Mark initialization complete */
142 impl[i].initialized = true;
143}
144
145
152
159
161 int i = port - GPIOEXT1;
162 uint8_t result;
163 pca95xx_get_input(&impl[i].periph, gpios, &result);
164 return result;
165}
166
168 int i = port - GPIOEXT1;
169 impl[i].output_reg |= gpios;
171}
172
174 int i = port - GPIOEXT1;
175 impl[i].output_reg &= ~gpios;
177}
178
180 int i = port - GPIOEXT1;
181 impl[i].output_reg ^= gpios;
183}
184
185
186
187
188
static void gpio_ext_pca95xx_set(uint32_t port, uint32_t gpios)
#define GPIO_EXT_PCA95XX_I2C_ADDRESS1
#define GPIO_EXT_PCA95XX_I2C_PERIPH1_PTR
#define GPIO_EXT_PCA95XX_I2C_ADDRESS3
static const uint8_t i2c_addr[]
#define GPIO_EXT_PCA95XX_I2C_PERIPH2_PTR
#define GPIO_EXT_PCA95XX_I2C_ADDRESS2
static void gpio_ext_pca95xx_toggle(uint32_t port, uint32_t gpios)
#define GPIO_EXT_PCA95XX_I2C_ADDRESS4
#define GPIO_EXT_PCA95XX_I2C_PERIPH3_PTR
static void gpio_ext_pca95xx_setup_output(uint32_t port, uint32_t gpios)
static void gpio_ext_pca95xx_clear(uint32_t port, uint32_t gpios)
static void gpio_ext_pca95xx_setup_input(uint32_t port, uint32_t gpios)
#define GPIO_EXT_PCA95XX_BLOCKING1
struct gpio_ext_functions pca95xx_functions
static uint32_t gpio_ext_pca95xx_get(uint32_t port, uint32_t gpios)
static struct gpio_ext_pca95xx_impl_t impl[GPIOEXT_NB]
static const bool blocking[]
static void gpio_ext_pca95xx_lazy_init(uint32_t port)
#define GPIO_EXT_PCA95XX_I2C_PERIPH4_PTR
enum I2CTransactionStatus status
Transaction status.
Definition i2c.h:126
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition i2c.h:57
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
uint16_t foo
Definition main_demo5.c:58
void pca95xx_init(struct pca95xx *dev, struct i2c_periph *i2c_p, uint8_t addr)
Init PCA95XX.
Definition pca95xx.c:30
bool pca95xx_get_input(struct pca95xx *dev, uint8_t mask, uint8_t *result)
Get input value.
Definition pca95xx.c:78
bool pca95xx_configure(struct pca95xx *dev, uint8_t val, bool blocking)
Configure PCA95XX.
Definition pca95xx.c:42
bool pca95xx_set_output(struct pca95xx *dev, uint8_t mask, bool blocking)
Set output value.
Definition pca95xx.c:60
Driver for the 8-bit I/O expander based on i2c.
struct i2c_transaction i2c_trans
Definition pca95xx.h:55
PCA95XX structure.
Definition pca95xx.h:53
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.