tca9539.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (C) 2022-2024, Xiaohua Semiconductor Co., Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-04-28 CDT first version
  9. */
  10. #ifndef __TCA9539_H__
  11. #define __TCA9539_H__
  12. #include <rtdevice.h>
  13. /**
  14. * @defgroup TCA9539_REGISTER_Definition TCA9539 Register Definition
  15. * @{
  16. */
  17. #define TCA9539_REG_INPUT_PORT0 (0x00U)
  18. #define TCA9539_REG_INPUT_PORT1 (0x01U)
  19. #define TCA9539_REG_OUTPUT_PORT0 (0x02U)
  20. #define TCA9539_REG_OUTPUT_PORT1 (0x03U)
  21. #define TCA9539_REG_INVERT_PORT0 (0x04U)
  22. #define TCA9539_REG_INVERT_PORT1 (0x05U)
  23. #define TCA9539_REG_CONFIG_PORT0 (0x06U)
  24. #define TCA9539_REG_CONFIG_PORT1 (0x07U)
  25. /**
  26. * @}
  27. */
  28. /**
  29. * @defgroup TCA9539_Port_Definition TCA9539 Port Definition
  30. * @{
  31. */
  32. #define TCA9539_IO_PORT0 (0x00U)
  33. #define TCA9539_IO_PORT1 (0x01U)
  34. /**
  35. * @}
  36. */
  37. /**
  38. * @defgroup TCA9539_Pin_Definition TCA9539 Pin Definition
  39. * @{
  40. */
  41. #define TCA9539_IO_PIN0 (0x01U)
  42. #define TCA9539_IO_PIN1 (0x02U)
  43. #define TCA9539_IO_PIN2 (0x04U)
  44. #define TCA9539_IO_PIN3 (0x08U)
  45. #define TCA9539_IO_PIN4 (0x10U)
  46. #define TCA9539_IO_PIN5 (0x20U)
  47. #define TCA9539_IO_PIN6 (0x40U)
  48. #define TCA9539_IO_PIN7 (0x80U)
  49. #define TCA9539_IO_PIN_ALL (0xFFU)
  50. /**
  51. * @}
  52. */
  53. /**
  54. * @defgroup TCA9539_Direction_Definition TCA9539 Direction Definition
  55. * @{
  56. */
  57. #define TCA9539_DIR_OUT (0x00U)
  58. #define TCA9539_DIR_IN (0x01U)
  59. /**
  60. * @}
  61. */
  62. /**
  63. * @defgroup TCA9539_Pin_State_Definition TCA9539 Pin State Definition
  64. * @{
  65. */
  66. #define TCA9539_PIN_RESET (0x00U)
  67. #define TCA9539_PIN_SET (0x01U)
  68. /**
  69. * @}
  70. */
  71. /**
  72. * @defgroup HC32F4A0_EV_IO_Function_Sel Expand IO function definition
  73. * @{
  74. */
  75. #define EIO_USBFS_OC (TCA9539_IO_PIN0) /* USBFS over-current, input */
  76. #define EIO_USBHS_OC (TCA9539_IO_PIN1) /* USBHS over-current, input */
  77. #define EIO_SDIC1_CD (TCA9539_IO_PIN2) /* SDIC1 card detect, input */
  78. #define EIO_SCI_CD (TCA9539_IO_PIN3) /* Smart card detect, input */
  79. #define EIO_TOUCH_INT (TCA9539_IO_PIN4) /* Touch screen interrupt, input */
  80. #define EIO_LIN_SLEEP (TCA9539_IO_PIN5) /* LIN PHY sleep, output */
  81. #define EIO_RTCS_CTRST (TCA9539_IO_PIN6) /* 'CS' for Resistor touch panel or 'Reset' for Cap touch panel, output */
  82. #define EIO_LCD_RST (TCA9539_IO_PIN7) /* LCD panel reset, output */
  83. #define EIO_CAM_RST (TCA9539_IO_PIN0) /* Camera module reset, output */
  84. #define EIO_CAM_STB (TCA9539_IO_PIN1) /* Camera module standby, output */
  85. #define EIO_USB3300_RST (TCA9539_IO_PIN2) /* USBHS PHY USB3300 reset, output */
  86. #define EIO_ETH_RST (TCA9539_IO_PIN3) /* ETH PHY reset, output */
  87. #define EIO_CAN_STB (TCA9539_IO_PIN4) /* CAN PHY standby, output */
  88. #define EIO_LED_RED (TCA9539_IO_PIN5) /* Red LED, output */
  89. #define EIO_LED_YELLOW (TCA9539_IO_PIN6) /* Yellow LED, output */
  90. #define EIO_LED_BLUE (TCA9539_IO_PIN7) /* Blue LED, output */
  91. /**
  92. * @}
  93. */
  94. /**
  95. * @defgroup BSP_LED_PortPin_Sel BSP LED port/pin definition
  96. * @{
  97. */
  98. #define LED_PORT (TCA9539_IO_PORT1)
  99. #define LED_RED_PORT (TCA9539_IO_PORT1)
  100. #define LED_RED_PIN (EIO_LED_RED)
  101. #define LED_YELLOW_PORT (TCA9539_IO_PORT1)
  102. #define LED_YELLOW_PIN (EIO_LED_YELLOW)
  103. #define LED_BLUE_PORT (TCA9539_IO_PORT1)
  104. #define LED_BLUE_PIN (EIO_LED_BLUE)
  105. /**
  106. * @}
  107. */
  108. /**
  109. * @defgroup BSP CAN PHY STB port/pin definition
  110. * @{
  111. */
  112. #define CAN_STB_PORT (TCA9539_IO_PORT1)
  113. #define CAN_STB_PIN (EIO_CAN_STB)
  114. /**
  115. * @}
  116. */
  117. int TCA9539_Init(void);
  118. rt_err_t TCA9539_WritePin(uint8_t u8Port, uint8_t u8Pin, uint8_t u8PinState);
  119. rt_err_t TCA9539_ReadPin(uint8_t u8Port, uint8_t u8Pin, uint8_t *pu8PinState);
  120. rt_err_t TCA9539_TogglePin(uint8_t u8Port, uint8_t u8Pin);
  121. rt_err_t TCA9539_ConfigPin(uint8_t u8Port, uint8_t u8Pin, uint8_t u8Dir);
  122. #endif