From aa38e5c1f48e31213ee349aa5cd6f06c85bda70d Mon Sep 17 00:00:00 2001
From: android <android@lingyun.com>
Date: Tue, 25 Jun 2024 21:49:39 +0800
Subject: [PATCH] Add GD32F103RCT6 ADC converter board SDK source code

---
 mcu_sdk/gd32f103/rk_eFire/System/Src/gpio.c |  218 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 218 insertions(+), 0 deletions(-)

diff --git a/mcu_sdk/gd32f103/rk_eFire/System/Src/gpio.c b/mcu_sdk/gd32f103/rk_eFire/System/Src/gpio.c
new file mode 100644
index 0000000..4f905fc
--- /dev/null
+++ b/mcu_sdk/gd32f103/rk_eFire/System/Src/gpio.c
@@ -0,0 +1,218 @@
+/**
+  ******************************************************************************
+  * File Name          : gpio.c
+  * Description        : This file provides code for the configuration
+  *                      of all used GPIO pins.
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
+  * All rights reserved.</center></h2>
+  *
+  * This software component is licensed by ST under Ultimate Liberty license
+  * SLA0044, the "License"; You may not use this file except in compliance with
+  * the License. You may obtain a copy of the License at:
+  *                             www.st.com/SLA0044
+  *
+  ******************************************************************************
+  */
+
+/* Includes ------------------------------------------------------------------*/
+#include "gpio.h"
+#include "board_common.h"
+/* USER CODE END 0 */
+
+/*----------------------------------------------------------------------------*/
+/* Configure GPIO                                                             */
+/*----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
+/* Configure GPIO                                                             */
+/*----------------------------------------------------------------------------*/
+extern IRQn_Type MSP_GetIRQn( uint16_t GPIO_Pin);
+
+/** Configure pins as 
+        * Analog 
+        * Input 
+        * Output
+        * EVENT_OUT
+        * EXTI
+*/
+void Board_GPIOInit(void)
+{
+
+  /* GPIO Ports Clock Enable */
+  __HAL_RCC_GPIOC_CLK_ENABLE();
+  __HAL_RCC_GPIOD_CLK_ENABLE();
+  __HAL_RCC_GPIOA_CLK_ENABLE();
+  __HAL_RCC_GPIOB_CLK_ENABLE();
+}
+
+static GpioIrqHandler *GpioIrq[16] = { NULL };
+
+/* Private function prototypes -----------------------------------------------*/
+
+static uint8_t HW_GPIO_GetBitPos(uint16_t GPIO_Pin);
+
+/* Exported functions ---------------------------------------------------------*/
+/*!
+ * @brief Initializes the given GPIO object
+ *
+ * @param  GPIOx: where x can be (A..E and H)
+ * @param  GPIO_Pin: specifies the port bit to be written.
+ *                   This parameter can be one of GPIO_PIN_x where x can be (0..15).
+ *                   All port bits are not necessarily available on all GPIOs.
+ * @param [IN] initStruct  GPIO_InitTypeDef intit structure
+ * @retval none
+ */
+void HW_GPIO_Init( GPIO_TypeDef* port, uint16_t GPIO_Pin, GPIO_InitTypeDef* initStruct)
+{
+
+  RCC_GPIO_CLK_ENABLE(  (uint32_t) port);
+
+  initStruct->Pin = GPIO_Pin ;
+
+  HAL_GPIO_Init( port, initStruct );
+}
+
+void HW_GPIO_DeInit( GPIO_TypeDef* port, uint16_t GPIO_Pin)
+{
+    HAL_GPIO_DeInit(port, GPIO_Pin);
+}
+
+
+
+/*!
+ * @brief Records the interrupt handler for the GPIO  object
+ *
+ * @param  GPIOx: where x can be (A..E and H) 
+ * @param  GPIO_Pin: specifies the port bit to be written.
+ *                   This parameter can be one of GPIO_PIN_x where x can be (0..15).
+ *                   All port bits are not necessarily available on all GPIOs.
+ * @param [IN] prio       NVIC priority (0 is highest)
+ * @param [IN] irqHandler  points to the  function to execute
+ * @retval none
+ */
+void HW_GPIO_SetIrq( GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t prio,  GpioIrqHandler *irqHandler )
+{
+  IRQn_Type IRQnb;
+  
+  uint32_t BitPos = HW_GPIO_GetBitPos( GPIO_Pin ) ;
+  
+  if ( irqHandler != NULL)
+  {
+    GpioIrq[ BitPos ] = irqHandler;
+
+    IRQnb = MSP_GetIRQn( GPIO_Pin );
+
+    HAL_NVIC_SetPriority( IRQnb , prio, 0);
+    
+    HAL_NVIC_EnableIRQ( IRQnb );
+  }
+  else
+  {
+    GpioIrq[ BitPos ] = NULL;
+  }
+}
+
+/*!
+ * @brief Execute the interrupt from the object
+ *
+ * @param  GPIO_Pin: specifies the port bit to be written.
+ *                   This parameter can be one of GPIO_PIN_x where x can be (0..15).
+ *                   All port bits are not necessarily available on all GPIOs.
+ * @retval none
+ */
+void HW_GPIO_IrqHandler( uint16_t GPIO_Pin )
+{
+  uint32_t BitPos = HW_GPIO_GetBitPos( GPIO_Pin );
+  
+  if ( GpioIrq[ BitPos ]  != NULL)
+  {
+    GpioIrq[ BitPos ] ( );
+  }
+}
+
+/*!
+ * @brief Writes the given value to the GPIO output
+ *
+ * @param  GPIO_Pin: specifies the port bit to be written.
+ *                   This parameter can be one of GPIO_PIN_x where x can be (0..15).
+ *                   All port bits are not necessarily available on all GPIOs.
+ * @param [IN] value New GPIO output value
+ * @retval none
+ */
+void HW_GPIO_Write( GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin,  uint32_t value )
+{
+  HAL_GPIO_WritePin( GPIOx, GPIO_Pin , (GPIO_PinState) value );
+}
+
+/*!
+ * @brief Reads the current GPIO input value
+ *
+ * @param  GPIOx: where x can be (A..E and H) 
+ * @param  GPIO_Pin: specifies the port bit to be written.
+ *                   This parameter can be one of GPIO_PIN_x where x can be (0..15).
+ *                   All port bits are not necessarily available on all GPIOs.
+ * @retval value   Current GPIO input value
+ */
+uint32_t HW_GPIO_Read( GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin )
+{
+  return HAL_GPIO_ReadPin( GPIOx, GPIO_Pin);
+}
+
+/* Private functions ---------------------------------------------------------*/
+
+/*!
+ * @brief Get the position of the bit set in the GPIO_Pin
+ * @param  GPIO_Pin: specifies the port bit to be written.
+ *                   This parameter can be one of GPIO_PIN_x where x can be (0..15).
+ *                   All port bits are not necessarily available on all GPIOs.
+ * @retval the position of the bit
+ */
+static uint8_t HW_GPIO_GetBitPos(uint16_t GPIO_Pin)
+{
+  uint8_t PinPos=0;
+  
+  if ( ( GPIO_Pin & 0xFF00 ) != 0) { PinPos |= 0x8; }
+  if ( ( GPIO_Pin & 0xF0F0 ) != 0) { PinPos |= 0x4; }
+  if ( ( GPIO_Pin & 0xCCCC ) != 0) { PinPos |= 0x2; }
+  if ( ( GPIO_Pin & 0xAAAA ) != 0) { PinPos |= 0x1; }
+  
+  return PinPos;
+}
+
+void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
+{
+  HW_GPIO_IrqHandler( GPIO_Pin );
+}
+
+/**
+  * @brief  Gets IRQ number as a function of the GPIO_Pin.
+  * @param  GPIO_Pin: Specifies the pins connected to the EXTI line.
+  * @retval IRQ number
+  */
+IRQn_Type MSP_GetIRQn( uint16_t GPIO_Pin)
+{
+  switch( GPIO_Pin )
+  {
+    case GPIO_PIN_0:    return EXTI0_IRQn;
+    case GPIO_PIN_1:    return EXTI1_IRQn;
+    case GPIO_PIN_2:    return EXTI2_IRQn;
+    case GPIO_PIN_3:    return EXTI3_IRQn;
+    case GPIO_PIN_4:    return EXTI4_IRQn;
+    case GPIO_PIN_5:
+    case GPIO_PIN_6:
+    case GPIO_PIN_7:
+    case GPIO_PIN_8:
+    case GPIO_PIN_9:    return EXTI9_5_IRQn;
+    case GPIO_PIN_10:
+    case GPIO_PIN_11:
+    case GPIO_PIN_12:
+    case GPIO_PIN_13:
+    case GPIO_PIN_14:
+    case GPIO_PIN_15:
+    default: return EXTI15_10_IRQn;
+  }
+}
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

--
Gitblit v1.9.1