nim_gpio.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**
  2. * 配置gpio
  3. */
  4. /****************************************************************************/
  5. #include "hw_types.h"
  6. #include "soc_C6748.h"
  7. #include "hw_syscfg0_C6748.h"
  8. #include "nim_config.h"
  9. int flag = 0;
  10. /****************************************************************************/
  11. /* */
  12. /* 宏定义 */
  13. /* */
  14. /****************************************************************************/
  15. #define PINMUX0_GPIO0_11_ENABLE (SYSCFG_PINMUX0_PINMUX0_19_16_GPIO0_11 << \
  16. SYSCFG_PINMUX0_PINMUX0_19_16_SHIFT)
  17. #define PINMUX4_GPIO1_0_ENABLE (SYSCFG_PINMUX4_PINMUX4_31_28_GPIO1_0 << \
  18. SYSCFG_PINMUX4_PINMUX4_31_28_SHIFT)
  19. #define PINMUX4_GPIO1_1_ENABLE (SYSCFG_PINMUX4_PINMUX4_27_24_GPIO1_1 << \
  20. SYSCFG_PINMUX4_PINMUX4_27_24_SHIFT)
  21. #define PINMUX4_GPIO1_2_ENABLE (SYSCFG_PINMUX4_PINMUX4_23_20_GPIO1_2 << \
  22. SYSCFG_PINMUX4_PINMUX4_23_20_SHIFT)
  23. #define PINMUX4_GPIO1_3_ENABLE (SYSCFG_PINMUX4_PINMUX4_19_16_GPIO1_3 << \
  24. SYSCFG_PINMUX4_PINMUX4_19_16_SHIFT)
  25. #define PINMUX12_GPIO5_5_ENABLE (SYSCFG_PINMUX12_PINMUX12_11_8_GPIO5_5 << \
  26. SYSCFG_PINMUX12_PINMUX12_11_8_SHIFT)
  27. static void Bank0Handle(void);
  28. static void GPIOBank0InterruptInit();
  29. /****************************************************************************/
  30. /* */
  31. /* 管脚复用配置 */
  32. /* */
  33. /****************************************************************************/
  34. void GOIOBank0Pin11MuxMuxSetup(void)
  35. {
  36. unsigned int savePinmux = 0;
  37. savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(0)) &
  38. ~(SYSCFG_PINMUX0_PINMUX0_19_16));
  39. HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(0)) =
  40. (PINMUX0_GPIO0_11_ENABLE | savePinmux);
  41. }
  42. void GOIOBank1Pin0MuxMuxSetup(void)
  43. {
  44. unsigned int savePinmux = 0;
  45. savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(4)) &
  46. ~(SYSCFG_PINMUX4_PINMUX4_31_28));
  47. HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(4)) =
  48. (PINMUX4_GPIO1_0_ENABLE | savePinmux);
  49. }
  50. void GOIOBank1Pin1MuxMuxSetup(void)
  51. {
  52. unsigned int savePinmux = 0;
  53. savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(4)) &
  54. ~(SYSCFG_PINMUX4_PINMUX4_27_24));
  55. HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(4)) =
  56. (PINMUX4_GPIO1_1_ENABLE | savePinmux);
  57. }
  58. void GOIOBank1Pin2MuxMuxSetup(void)
  59. {
  60. unsigned int savePinmux = 0;
  61. savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(4)) &
  62. ~(SYSCFG_PINMUX4_PINMUX4_23_20));
  63. HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(4)) =
  64. (PINMUX4_GPIO1_2_ENABLE | savePinmux);
  65. }
  66. void GOIOBank1Pin3MuxMuxSetup(void)
  67. {
  68. unsigned int savePinmux = 0;
  69. savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(4)) &
  70. ~(SYSCFG_PINMUX4_PINMUX4_19_16));
  71. HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(4)) =
  72. (PINMUX4_GPIO1_3_ENABLE | savePinmux);
  73. }
  74. void GOIOBank5Pin5MuxMuxSetup(void)
  75. {
  76. unsigned int savePinmux = 0;
  77. savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(12)) &
  78. ~(SYSCFG_PINMUX12_PINMUX12_11_8));
  79. HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(12)) =
  80. (PINMUX12_GPIO5_5_ENABLE | savePinmux);
  81. }
  82. /**
  83. * GPIO0[11] 配置程输入模式,触控
  84. */
  85. void GPIOBank0Pin11Init()
  86. {
  87. GOIOBank0Pin11MuxMuxSetup();
  88. // 触控输入
  89. GPIODirModeSet(SOC_GPIO_0_REGS, 12, GPIO_DIR_INPUT); // GPIO0[11]
  90. GPIOBank0InterruptInit();
  91. }
  92. /**
  93. * GPIO5[5] 配置程输入模式,GUI电源
  94. */
  95. void GPIOBank5Pin5Init()
  96. {
  97. GOIOBank5Pin5MuxMuxSetup();
  98. // gui控制
  99. GPIODirModeSet(SOC_GPIO_0_REGS, 86, GPIO_DIR_OUTPUT); // GPIO5[5]
  100. GPIOPinWrite(SOC_GPIO_0_REGS, 86, GPIO_PIN_LOW);
  101. }
  102. static void GPIOBank0InterruptInit()
  103. {
  104. // 配置 触控 为上升沿及下降沿触发
  105. GPIOIntTypeSet(SOC_GPIO_0_REGS, 12, GPIO_INT_TYPE_BOTHEDGE);
  106. // 使能 GPIO BANK0 中断
  107. GPIOBankIntEnable(SOC_GPIO_0_REGS, 0);
  108. IntRegister(C674X_MASK_INT11, Bank0Handle);
  109. IntEventMap(C674X_MASK_INT11, SYS_INT_GPIO_B0INT);
  110. IntEnable(C674X_MASK_INT11);
  111. }
  112. static void Bank0Handle(void)
  113. {
  114. // 禁用 GPIO BANK 0 中断
  115. GPIOBankIntDisable(SOC_GPIO_0_REGS, 0);
  116. // 清除 GPIO BANK 0 中断事件
  117. IntEventClear(SYS_INT_GPIO_B0INT);
  118. if(GPIOPinIntStatus(SOC_GPIO_0_REGS, 12) == GPIO_INT_PEND)
  119. {
  120. // 清除中断状态
  121. GPIOPinIntClear(SOC_GPIO_0_REGS, 12);
  122. int value = GPIOPinRead(SOC_GPIO_0_REGS, 12);
  123. touch_switch(value);
  124. }
  125. // 使能 GPIO BANK 0 中断
  126. GPIOBankIntEnable(SOC_GPIO_0_REGS, 0);
  127. }