1 /* 2 * Copyright 2021 NXP 3 * All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 #ifndef _FSL_PCA6416A_H_ 9 #define _FSL_PCA6416A_H_ 10 11 /******************************************************************************* 12 * Includes 13 ******************************************************************************/ 14 #include "fsl_common.h" 15 16 /* 17 * Change log: 18 * 19 * 1.0.0 20 * - Initial version 21 */ 22 23 /*! 24 * @addtogroup pca6416a 25 * @{ 26 */ 27 28 /******************************************************************************* 29 * Definitions 30 ******************************************************************************/ 31 32 /*! @brief Define the Register Memory Map of PCA6416A. */ 33 #define PCA6416A_INPUT_PORT_0 (0x00U) 34 #define PCA6416A_INPUT_PORT_1 (0x01U) 35 #define PCA6416A_OUTPUT_PORT_0 (0x02U) 36 #define PCA6416A_OUTPUT_PORT_1 (0x03U) 37 #define PCA6416A_POL_INV_PORT_0 (0x04U) 38 #define PCA6416A_POL_INV_PORT_1 (0x05U) 39 #define PCA6416A_CFG_PORT_0 (0x06U) 40 #define PCA6416A_CFG_PORT_1 (0x07U) 41 42 /*! @brief PCA6416A IO direction. */ 43 typedef enum _pca6416a_dir 44 { 45 kPCA6416A_Input = 0U, /*!< Set pin as input. */ 46 kPCA6416A_Output, /*!< Set pin as output. */ 47 } pca6416a_dir_t; 48 49 /*! @brief PCA6416A I2C receive function. */ 50 typedef status_t (*pca6416a_i2c_receive_func_t)(uint8_t deviceAddress, 51 uint32_t subAddress, 52 uint8_t subaddressSize, 53 uint8_t *rxBuff, 54 uint8_t rxBuffSize, 55 uint32_t flags); 56 57 /*! @brief PCA6416A I2C send function. */ 58 typedef status_t (*pca6416a_i2c_send_func_t)(uint8_t deviceAddress, 59 uint32_t subAddress, 60 uint8_t subaddressSize, 61 const uint8_t *txBuff, 62 uint8_t txBuffSize, 63 uint32_t flags); 64 65 /*! @brief PCA6416A configure structure.*/ 66 typedef struct _pca6416a_config 67 { 68 uint8_t i2cAddr; /*!< I2C address. */ 69 pca6416a_i2c_send_func_t I2C_SendFunc; /*!< Function to send I2C data. */ 70 pca6416a_i2c_receive_func_t I2C_ReceiveFunc; /*!< Function to receive I2C data. */ 71 } pca6416a_config_t; 72 73 /*! @brief PCA6416A driver handle. */ 74 typedef struct _pca6416a_handle 75 { 76 uint8_t i2cAddr; /*!< I2C address. */ 77 pca6416a_i2c_send_func_t I2C_SendFunc; /*!< Function to send I2C data. */ 78 pca6416a_i2c_receive_func_t I2C_ReceiveFunc; /*!< Function to receive I2C data. */ 79 } pca6416a_handle_t; 80 81 /******************************************************************************* 82 * API 83 ******************************************************************************/ 84 #if defined(__cplusplus) 85 extern "C" { 86 #endif 87 88 /*! 89 * @name Initialization and Control function 90 * @{ 91 */ 92 93 /*! 94 * @brief Initializes the PCA6416A driver handle. 95 * 96 * @param handle Pointer to the PCA6416A handle. 97 * @param config Pointer to the PCA6416A configuration structure. 98 */ 99 void PCA6416A_Init(pca6416a_handle_t *handle, const pca6416a_config_t *config); 100 101 /*! 102 * @brief Set PCA6416A pins direction. 103 * 104 * This function sets multiple pins direction, the pins to modify are passed in 105 * as a bit OR'ed value. 106 * 107 * For example, the following code set pin2 and pin3 to output: 108 * 109 * @code 110 PCA6416A_SetDirection(handle, (1<<2) | (1<<3), pkPCA6416A_Output); 111 @endcode 112 * 113 * @param handle Pointer to the PCA6416A handle. 114 * @param pins The pins to change, for example: (1<<2) | (1<<3) means pin 2 and pin 3. 115 * @param dir Pin direction. 116 * @return Return @ref kStatus_Success if successed, otherwise returns error code. 117 */ 118 status_t PCA6416A_SetDirection(pca6416a_handle_t *handle, uint16_t pins, pca6416a_dir_t dir); 119 120 /*! 121 * @brief Inverse PCA6416A pins polarity. 122 * 123 * This function changes multiple pins polarity, the pins to modify are passed in 124 * as a bit OR'ed value. 125 * 126 * For example, the following code set pin2 and pin3 to NOT inverse: 127 * 128 * @code 129 PCA6416A_InversePolarity(handle, (1<<2) | (1<<3), false); 130 @endcode 131 * 132 * @param handle Pointer to the PCA6416A handle. 133 * @param pins The pins to change, for example: (1<<2) | (1<<3) means pin 2 and pin 3. 134 * @param inverse Use true to inverse, false to not inverse. 135 * @return Return @ref kStatus_Success if successed, otherwise returns error code. 136 */ 137 status_t PCA6416A_InversePolarity(pca6416a_handle_t *handle, uint16_t pins, bool inverse); 138 139 /*! 140 * @brief Read PCA6416A pins value. 141 * 142 * @param handle Pointer to the PCA6416A handle. 143 * @param pinsValue Variable to save the read out pin values. 144 * @return Return @ref kStatus_Success if successed, otherwise returns error code. 145 */ 146 status_t PCA6416A_ReadPins(pca6416a_handle_t *handle, uint16_t *pinsValue); 147 148 /*! 149 * @brief Set PCA6416A pins output value to 1. 150 * 151 * This function changes multiple pins, the pins to modify are passed in as 152 * a bit OR'ed value. 153 * 154 * For example, the following code set pin2 and pin3 output value to 1. 155 * 156 * @code 157 PCA6416A_SetPins(handle, (1<<2) | (1<<3)); 158 @endcode 159 * 160 * @param handle Pointer to the PCA6416A handle. 161 * @param pins The pins to change, for example: (1<<2) | (1<<3) means pin 2 and pin 3. 162 * @return Return @ref kStatus_Success if successed, otherwise returns error code. 163 */ 164 status_t PCA6416A_SetPins(pca6416a_handle_t *handle, uint16_t pins); 165 166 /*! 167 * @brief Set PCA6416A pins output value to 0. 168 * 169 * This function changes multiple pins, the pins to modify are passed in as 170 * a bit OR'ed value. 171 * 172 * For example, the following code set pin2 and pin3 output value to 0. 173 * 174 * @code 175 PCA6416A_ClearPins(handle, (1<<2) | (1<<3)); 176 @endcode 177 * 178 * @param handle Pointer to the PCA6416A handle. 179 * @param pins The pins to change, for example: (1<<2) | (1<<3) means pin 2 and pin 3. 180 * @return Return @ref kStatus_Success if successed, otherwise returns error code. 181 */ 182 status_t PCA6416A_ClearPins(pca6416a_handle_t *handle, uint16_t pins); 183 184 /*! 185 * @brief Toggle PCA6416A pins output value. 186 * 187 * This function changes multiple pins, the pins to modify are passed in as 188 * a bit OR'ed value. 189 * 190 * For example, the following code toggle pin2 and pin3 output value. 191 * 192 * @code 193 PCA6416A_ClearPins(handle, (1<<2) | (1<<3)); 194 @endcode 195 * 196 * @param handle Pointer to the PCA6416A handle. 197 * @param pins The pins to change, for example: (1<<2) | (1<<3) means pin 2 and pin 3. 198 * @return Return @ref kStatus_Success if successed, otherwise returns error code. 199 */ 200 status_t PCA6416A_TogglePins(pca6416a_handle_t *handle, uint16_t pins); 201 202 /*! @} */ 203 204 #if defined(__cplusplus) 205 } 206 #endif 207 208 /*! @} */ 209 210 #endif /* _FSL_PCA6416A_H_ */ 211 212 /******************************************************************************* 213 * EOF 214 ******************************************************************************/ 215