gpio.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("AutoChips Software") are
  4. * protected under relevant copyright laws. The information contained herein is
  5. * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
  6. * the prior written permission of AutoChips inc. and/or its licensors, any
  7. * reproduction, modification, use or disclosure of AutoChips Software, and
  8. * information contained herein, in whole or in part, shall be strictly
  9. * prohibited.
  10. *
  11. * AutoChips Inc. (C) 2018. All rights reserved.
  12. *
  13. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  14. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
  15. * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
  16. * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
  17. * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  19. * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
  20. * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
  21. * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
  22. * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
  23. * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
  24. * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
  25. * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
  26. * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  27. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
  28. * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
  29. * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
  30. * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
  31. * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
  32. */
  33. /*************<start>******************/
  34. /*************<include>****************/
  35. #include "gpio.h"
  36. /*************<macro>******************/
  37. /*************<enum>*******************/
  38. /*************<union>******************/
  39. /*************<struct>*****************/
  40. /*************<variable>***************/
  41. uint8_t g_svstatus = 0;
  42. /*************<prototype>**************/
  43. /**
  44. * @prototype GPIO_LedInit(void)
  45. *
  46. * @param[in] void
  47. * @return void
  48. *
  49. * @brief 初始化引脚.
  50. */
  51. void GPIO_PortInit(void)
  52. {
  53. /*
  54. GPIO_SetFunc(GPIO_CLOSE_KEY, GPIO_FUN0);
  55. GPIO_SetFunc(GPIO_OPEN_KEY, GPIO_FUN0);
  56. GPIO_SetFunc(GPIO_COVER_KEY, GPIO_FUN0);
  57. GPIO_SetDir(GPIO_CLOSE_KEY, GPIO_IN);
  58. GPIO_SetDir(GPIO_OPEN_KEY, GPIO_IN);
  59. GPIO_SetDir(GPIO_COVER_KEY, GPIO_IN);
  60. GPIO_SetPullup(GPIO_CLOSE_KEY, ENABLE);
  61. GPIO_SetPullup(GPIO_OPEN_KEY, ENABLE);
  62. GPIO_SetPullup(GPIO_COVER_KEY, ENABLE);
  63. */
  64. //set pin mux uart1
  65. GPIO_SetFunc(GPIOA, GPIO_PIN4, GPIO_FUN3);
  66. GPIO_SetFunc(GPIOA, GPIO_PIN5, GPIO_FUN3);
  67. /*初始化引脚功能,如果引脚上电后默认为GPIO,可省略掉初始化步骤.
  68. 有部分引脚上电默认为非GPIO,则必须选择其功能为GPIO才能作为GPIO使用.*/
  69. GPIO_SetFunc(RS485CTRL_PORT, RS485CTRL_PIN, GPIO_FUN0);
  70. GPIO_SetDir(RS485CTRL_PORT, RS485CTRL_PIN, GPIO_OUT);
  71. GPIO_SetFunc(RUNLED_PORT, RUNLED_PIN, GPIO_FUN0);
  72. GPIO_SetDir(RUNLED_PORT, RUNLED_PIN, GPIO_OUT);
  73. GPIO_SetFunc(SV1_PORT, SV1_PIN, GPIO_FUN0);
  74. GPIO_SetDir(SV1_PORT, SV1_PIN, GPIO_OUT);
  75. GPIO_SetFunc(SV2_PORT, SV2_PIN, GPIO_FUN0);
  76. GPIO_SetDir(SV2_PORT, SV2_PIN, GPIO_OUT);
  77. GPIO_SetFunc(SV3_PORT, SV3_PIN, GPIO_FUN0);
  78. GPIO_SetDir(SV3_PORT, SV3_PIN, GPIO_OUT);
  79. GPIO_SetFunc(SV4_PORT, SV4_PIN, GPIO_FUN0);
  80. GPIO_SetDir(SV4_PORT, SV4_PIN, GPIO_OUT);
  81. GPIO_SetPinLevel(SV1_PORT, SV1_PIN, SV_CLOSE);
  82. GPIO_SetPinLevel(SV2_PORT, SV2_PIN, SV_CLOSE);
  83. GPIO_SetPinLevel(SV3_PORT, SV3_PIN, SV_CLOSE);
  84. GPIO_SetPinLevel(SV4_PORT, SV4_PIN, SV_CLOSE);
  85. g_svstatus = 0x00;
  86. }
  87. void Sv_Control(uint8_t id, uint8_t action)
  88. {
  89. if(id >= SV_ALL){
  90. return ;
  91. }
  92. if(SV_OPEN == action){
  93. g_svstatus |= (1 << id);
  94. }else{
  95. g_svstatus &= ~(1 << id);
  96. }
  97. if(SV_01 == id){
  98. GPIO_SetPinLevel(SV1_PORT, SV1_PIN, action);
  99. }else if(SV_02 == id){
  100. GPIO_SetPinLevel(SV2_PORT, SV2_PIN, action);
  101. }else if(SV_03 == id){
  102. GPIO_SetPinLevel(SV3_PORT, SV3_PIN, action);
  103. }else if(SV_04 == id){
  104. GPIO_SetPinLevel(SV4_PORT, SV4_PIN, action);
  105. }
  106. }
  107. /*************<end>********************/