Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:11

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief GPIO NXP PCA9535 Driver API
0007  *
0008  * @ingroup I2CGPIONXPPCA9535
0009  */
0010 
0011 /*
0012  * Copyright (c) 2014 embedded brains GmbH & Co. KG
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #ifndef _DEV_I2C_GPIO_NXP_PCA9539_H
0037 #define _DEV_I2C_GPIO_NXP_PCA9539_H
0038 
0039 #include <dev/i2c/i2c.h>
0040 
0041 #ifdef __cplusplus
0042 extern "C" {
0043 #endif /* __cplusplus */
0044 
0045 /**
0046  * @defgroup I2CGPIONXPPCA9535 GPIO NXP PCA9535 Driver
0047  *
0048  * @ingroup I2CDevice
0049  *
0050  * @brief Driver for NXP PCA9535 16-bit GPIO device.
0051  *
0052  * @{
0053  */
0054 
0055 int i2c_dev_register_gpio_nxp_pca9535(
0056   const char *bus_path,
0057   const char *dev_path,
0058   uint16_t address
0059 );
0060 
0061 #define GPIO_NXP_PCA9535_GET_INPUT (I2C_DEV_IO_CONTROL + 0)
0062 
0063 #define GPIO_NXP_PCA9535_GET_OUTPUT (I2C_DEV_IO_CONTROL + 1)
0064 
0065 #define GPIO_NXP_PCA9535_SET_OUTPUT (I2C_DEV_IO_CONTROL + 2)
0066 
0067 #define GPIO_NXP_PCA9535_CLEAR_AND_SET_OUTPUT (I2C_DEV_IO_CONTROL + 3)
0068 
0069 #define GPIO_NXP_PCA9535_GET_POL_INV (I2C_DEV_IO_CONTROL + 4)
0070 
0071 #define GPIO_NXP_PCA9535_SET_POL_INV (I2C_DEV_IO_CONTROL + 5)
0072 
0073 #define GPIO_NXP_PCA9535_GET_CONFIG (I2C_DEV_IO_CONTROL + 6)
0074 
0075 #define GPIO_NXP_PCA9535_SET_CONFIG (I2C_DEV_IO_CONTROL + 7)
0076 
0077 static inline int gpio_nxp_pca9535_get_input(int fd, uint16_t *val)
0078 {
0079   return ioctl(fd, GPIO_NXP_PCA9535_GET_INPUT, val);
0080 }
0081 
0082 static inline int gpio_nxp_pca9535_get_output(int fd, uint16_t *val)
0083 {
0084   return ioctl(fd, GPIO_NXP_PCA9535_GET_OUTPUT, val);
0085 }
0086 
0087 static inline int gpio_nxp_pca9535_set_output(int fd, uint16_t val)
0088 {
0089   return ioctl(fd, GPIO_NXP_PCA9535_SET_OUTPUT, (void *)(uintptr_t) val);
0090 }
0091 
0092 static inline int gpio_nxp_pca9535_clear_and_set_output(
0093   int fd,
0094   uint16_t clear,
0095   uint16_t set
0096 )
0097 {
0098   uint32_t clear_and_set = ((uint32_t) set << 16) | (uint32_t) clear;
0099 
0100   return ioctl(
0101     fd,
0102     GPIO_NXP_PCA9535_CLEAR_AND_SET_OUTPUT,
0103     (void *)(uintptr_t) clear_and_set
0104   );
0105 }
0106 
0107 static inline int gpio_nxp_pca9535_get_polarity_inversion(
0108   int fd,
0109   uint16_t *val
0110 )
0111 {
0112   return ioctl(fd, GPIO_NXP_PCA9535_GET_POL_INV, val);
0113 }
0114 
0115 static inline int gpio_nxp_pca9535_set_polarity_inversion(int fd, uint16_t val)
0116 {
0117   return ioctl(fd, GPIO_NXP_PCA9535_SET_POL_INV, (void *)(uintptr_t) val);
0118 }
0119 
0120 static inline int gpio_nxp_pca9535_get_config(int fd, uint16_t *val)
0121 {
0122   return ioctl(fd, GPIO_NXP_PCA9535_GET_CONFIG, val);
0123 }
0124 
0125 static inline int gpio_nxp_pca9535_set_config(int fd, uint16_t val)
0126 {
0127   return ioctl(fd, GPIO_NXP_PCA9535_SET_CONFIG, (void *)(uintptr_t) val);
0128 }
0129 
0130 /** @} */
0131 
0132 #ifdef __cplusplus
0133 }
0134 #endif /* __cplusplus */
0135 
0136 #endif /* _DEV_I2C_GPIO_NXP_PCA9539_H */