rt-thread/bsp/hc32/ev_hc32f448_lqfp80/board/ports/tca9539.h

134 lines
4.0 KiB
C

/*
* Copyright (c) 2006-2022, RT-Thread Development Team
* Copyright (c) 2022-2024, Xiaohua Semiconductor Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2024-02-20 CDT first version
*/
#ifndef __TCA9539_H__
#define __TCA9539_H__
#include <rtdevice.h>
/**
* @defgroup TCA9539_REGISTER_Definition TCA9539 Register Definition
* @{
*/
#define TCA9539_REG_INPUT_PORT0 (0x00U)
#define TCA9539_REG_INPUT_PORT1 (0x01U)
#define TCA9539_REG_OUTPUT_PORT0 (0x02U)
#define TCA9539_REG_OUTPUT_PORT1 (0x03U)
#define TCA9539_REG_INVERT_PORT0 (0x04U)
#define TCA9539_REG_INVERT_PORT1 (0x05U)
#define TCA9539_REG_CONFIG_PORT0 (0x06U)
#define TCA9539_REG_CONFIG_PORT1 (0x07U)
/**
* @}
*/
/**
* @defgroup TCA9539_Port_Definition TCA9539 Port Definition
* @{
*/
#define TCA9539_IO_PORT0 (0x00U)
#define TCA9539_IO_PORT1 (0x01U)
/**
* @}
*/
/**
* @defgroup TCA9539_Pin_Definition TCA9539 Pin Definition
* @{
*/
#define TCA9539_IO_PIN0 (0x01U)
#define TCA9539_IO_PIN1 (0x02U)
#define TCA9539_IO_PIN2 (0x04U)
#define TCA9539_IO_PIN3 (0x08U)
#define TCA9539_IO_PIN4 (0x10U)
#define TCA9539_IO_PIN5 (0x20U)
#define TCA9539_IO_PIN6 (0x40U)
#define TCA9539_IO_PIN7 (0x80U)
#define TCA9539_IO_PIN_ALL (0xFFU)
/**
* @}
*/
/**
* @defgroup TCA9539_Direction_Definition TCA9539 Direction Definition
* @{
*/
#define TCA9539_DIR_OUT (0x00U)
#define TCA9539_DIR_IN (0x01U)
/**
* @}
*/
/**
* @defgroup TCA9539_Pin_State_Definition TCA9539 Pin State Definition
* @{
*/
#define TCA9539_PIN_RESET (0x00U)
#define TCA9539_PIN_SET (0x01U)
/**
* @}
*/
/**
* @defgroup HC32F448_EV_IO_Function_Sel Expand IO function definition
* @{
*/
#define EIO_SCI_CD (TCA9539_IO_PIN1) /* Smart card detect, input */
#define EIO_TOUCH_INT (TCA9539_IO_PIN2) /* Touch screen interrupt, input */
#define EIO_TOUCH_CTRST (TCA9539_IO_PIN5) /* 'Reset' for Cap touch panel, output */
#define EIO_LCD_RST (TCA9539_IO_PIN6) /* LCD panel reset, output */
#define EIO_LCD_BKL (TCA9539_IO_PIN7) /* LCD panel back light, output */
#define EIO_LIN_SLEEP (TCA9539_IO_PIN1) /* LIN PHY sleep, output */
#define EIO_CAN1_STB (TCA9539_IO_PIN2) /* CAN1 PHY standby, output */
#define EIO_CAN2_STB (TCA9539_IO_PIN3) /* CAN2 PHY standby, output */
#define EIO_LED_RED (TCA9539_IO_PIN5) /* Red LED, output */
#define EIO_LED_YELLOW (TCA9539_IO_PIN6) /* Yellow LED, output */
#define EIO_LED_BLUE (TCA9539_IO_PIN7) /* Blue LED, output */
/**
* @}
*/
/**
* @defgroup BSP_LED_PortPin_Sel BSP LED port/pin definition
* @{
*/
#define LED_PORT (TCA9539_IO_PORT1)
#define LED_RED_PORT (TCA9539_IO_PORT1)
#define LED_RED_PIN (EIO_LED_RED)
#define LED_YELLOW_PORT (TCA9539_IO_PORT1)
#define LED_YELLOW_PIN (EIO_LED_YELLOW)
#define LED_BLUE_PORT (TCA9539_IO_PORT1)
#define LED_BLUE_PIN (EIO_LED_BLUE)
/**
* @}
*/
/**
* @defgroup BSP CAN PHY STB port/pin definition
* @{
*/
#define CAN1_STB_PORT (TCA9539_IO_PORT1)
#define CAN1_STB_PIN (EIO_CAN1_STB)
#define CAN2_STB_PORT (TCA9539_IO_PORT1)
#define CAN2_STB_PIN (EIO_CAN2_STB)
/**
* @}
*/
int TCA9539_Init(void);
rt_err_t TCA9539_WritePin(uint8_t u8Port, uint8_t u8Pin, uint8_t u8PinState);
rt_err_t TCA9539_ReadPin(uint8_t u8Port, uint8_t u8Pin, uint8_t *pu8PinState);
rt_err_t TCA9539_TogglePin(uint8_t u8Port, uint8_t u8Pin);
rt_err_t TCA9539_ConfigPin(uint8_t u8Port, uint8_t u8Pin, uint8_t u8Dir);
#endif