fpinctrl.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright : (C) 2022 Phytium Information Technology, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is OPEN SOURCE software: you can redistribute it and/or modify it
  6. * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
  7. * either version 1.0 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  10. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See the Phytium Public License for more details.
  12. *
  13. *
  14. * FilePath: fpinctrl.h
  15. * Date: 2022-03-28 14:16:09
  16. * LastEditTime: 2022-03-28 14:16:10
  17. * Description:  This files is for IO pin ctrl API definition
  18. *
  19. * Modify History:
  20. * Ver   Who        Date         Changes
  21. * ----- ------     --------    --------------------------------------
  22. * 1.0 zhugengyu 2022/3/28 init commit
  23. */
  24. #ifndef COMMON_FPINCTRL_H
  25. #define COMMON_FPINCTRL_H
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  30. /***************************** Include Files *********************************/
  31. #include "ftypes.h"
  32. #include "sdkconfig.h"
  33. #if defined(CONFIG_TARGET_F2000_4) || defined(CONFIG_TARGET_D2000)
  34. #ifndef FPIN_IO_CTRL
  35. #define FPIN_IO_CTRL
  36. #endif
  37. #endif
  38. #if defined(CONFIG_TARGET_E2000)
  39. #ifndef FPIN_IO_PAD
  40. #define FPIN_IO_PAD
  41. #endif
  42. #endif
  43. #if defined(FPIN_IO_CTRL)
  44. #include "fioctrl.h"
  45. #endif
  46. #if defined(FPIN_IO_PAD)
  47. #include "fiopad.h"
  48. #endif
  49. /**************************** Type Definitions *******************************/
  50. typedef enum
  51. {
  52. FPIN_FUNC0 = 0b000,
  53. FPIN_FUNC1,
  54. FPIN_FUNC2,
  55. FPIN_FUNC3 = 0b011,
  56. #if defined(FPIN_IO_PAD) /* E2000 support more pin func */
  57. FPIN_FUNC4,
  58. FPIN_FUNC5,
  59. FPIN_FUNC6,
  60. FPIN_FUNC7 = 0b111,
  61. #endif
  62. FPIN_NUM_OF_FUNC
  63. } FPinFunc; /* 引脚复用功能配置, func0为默认功能 */
  64. #if defined(FPIN_IO_PAD) /* Only support driver strength config in E2000 */
  65. typedef enum
  66. {
  67. FPIN_DRV0 = 0b0000,
  68. FPIN_DRV1,
  69. FPIN_DRV2,
  70. FPIN_DRV3,
  71. FPIN_DRV4,
  72. FPIN_DRV5,
  73. FPIN_DRV6,
  74. FPIN_DRV7,
  75. FPIN_DRV8,
  76. FPIN_DRV9,
  77. FPIN_DRV10,
  78. FPIN_DRV11,
  79. FPIN_DRV12,
  80. FPIN_DRV13,
  81. FPIN_DRV14,
  82. FPIN_DRV15 = 0b1111,
  83. FPIN_NUM_OF_DRIVE
  84. } FPinDrive; /* 引脚驱动能力配置 */
  85. #endif
  86. typedef enum
  87. {
  88. FPIN_PULL_NONE = 0b00,
  89. FPIN_PULL_DOWN = 0b01,
  90. FPIN_PULL_UP = 0b10,
  91. FPIN_NUM_OF_PULL
  92. } FPinPull; /* 引脚上下拉配置 */
  93. typedef enum
  94. {
  95. FPIN_OUTPUT_DELAY = 0, /* 延时设置方向为输出 */
  96. FPIN_INPUT_DELAY, /* 延时设置方向为输入 */
  97. FPIN_NUM_OF_DELAY_DIR
  98. } FPinDelayDir; /* 引脚延时配置方向 */
  99. typedef enum
  100. {
  101. FPIN_DELAY_COARSE_TUNING = 0, /* 延迟粗调档位 */
  102. FPIN_DELAY_FINE_TUNING, /* 延迟精调档位 */
  103. FPIN_NUM_OF_DELAY_TYPE
  104. } FPinDelayType; /* 引脚延时配置类型 */
  105. typedef enum
  106. {
  107. FPIN_DELAY_NONE = 0,
  108. FPIN_DELAY_1,
  109. FPIN_DELAY_2,
  110. FPIN_DELAY_3,
  111. FPIN_DELAY_4,
  112. FPIN_DELAY_5,
  113. FPIN_DELAY_6,
  114. FPIN_DELAY_7,
  115. FPIN_NUM_OF_DELAY
  116. } FPinDelay;
  117. typedef enum
  118. {
  119. FPIN_DELAY_IN_TYPE = 0, /* input delay */
  120. FPIN_DELAY_OUT_TYPE = 1, /* output delay */
  121. } FPinDelayIOType;
  122. typedef struct
  123. {
  124. u32 reg_off; /* 引脚配置寄存器偏移量 */
  125. u32 reg_bit; /* 引脚配置起始位 */
  126. } FPinIndex; /* 引脚索引 */
  127. /************************** Variable Definitions *****************************/
  128. /***************** Macros (Inline Functions) Definitions *********************/
  129. #define FPIN_NULL {0xffffffff, 0}
  130. /************************** Function Prototypes ******************************/
  131. /* 获取IO引脚当前的复用功能 */
  132. FPinFunc FPinGetFunc(const FPinIndex pin);
  133. /* 设置IO引脚复用功能 */
  134. void FPinSetFunc(const FPinIndex pin, FPinFunc func);
  135. /* 获取IO引脚当前的上下拉设置 */
  136. FPinPull FPinGetPull(const FPinIndex pin);
  137. /* 设置IO引脚的上下拉 */
  138. void FPinSetPull(const FPinIndex pin, FPinPull pull);
  139. #if defined(FPIN_IO_PAD)
  140. /* 获取IO引脚的驱动能力 */
  141. FPinDrive FPinGetDrive(const FPinIndex pin);
  142. /* 设置IO引脚的驱动能力 */
  143. void FPinSetDrive(const FPinIndex pin, FPinDrive drive);
  144. /* 获取IO引脚的复用、上下拉和驱动能力设置 */
  145. void FPinGetConfig(const FPinIndex pin, FPinFunc *func, FPinPull *pull, FPinDrive *drive);
  146. /* 设置IO引脚的复用、上下拉和驱动能力 */
  147. void FPinSetConfig(const FPinIndex pin, FPinFunc func, FPinPull pull, FPinDrive drive);
  148. #else
  149. /* 获取IO引脚的复用、上下拉和驱动能力设置 */
  150. void FPinGetConfig(const FPinIndex pin, FPinFunc *func, FPinPull *pull);
  151. /* 设置IO引脚的复用、上下拉和驱动能力 */
  152. void FPinSetConfig(const FPinIndex pin, FPinFunc func, FPinPull pull);
  153. #endif
  154. /* 获取IO引脚当前的单项延时设置 */
  155. FPinDelay FPinGetDelay(const FPinIndex pin, FPinDelayDir dir, FPinDelayType type);
  156. /* 检查IO引脚延时是否使能 */
  157. boolean FPinGetDelayEn(const FPinIndex pin, FPinDelayDir dir);
  158. /* 设置IO引脚单项延时 */
  159. void FPinSetDelay(const FPinIndex pin, FPinDelayDir dir, FPinDelayType type, FPinDelay delay);
  160. /* 使能或去使能IO引脚延时 */
  161. void FPinSetDelayEn(const FPinIndex pin, FPinDelayDir dir, boolean enable);
  162. /* Update and enable common IO pin delay config */
  163. void FPinSetDelayConfig(const FPinIndex pin, FPinDelayIOType in_out_type, FPinDelay roungh_delay, FPinDelay delicate_delay, boolean enable);
  164. /* Get current common IO pin delay config */
  165. void FPinGetDelayConfig(const FPinIndex pin, FPinDelay *in_roungh_delay, FPinDelay *in_delicate_delay,
  166. FPinDelay *out_roungh_delay, FPinDelay *out_delicate_delay);
  167. #ifdef __cplusplus
  168. }
  169. #endif
  170. #endif