2020-02-20 12:38:58 +08:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* File Name : gpio.c
|
|
|
|
* Description : This file provides code for the configuration
|
|
|
|
* of all used GPIO pins.
|
|
|
|
******************************************************************************
|
|
|
|
* @attention
|
|
|
|
*
|
|
|
|
* <h2><center>© Copyright (c) 2020 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"
|
|
|
|
/* USER CODE BEGIN 0 */
|
|
|
|
|
2020-04-17 15:55:14 +08:00
|
|
|
extern NaviKit_t NaviKit;
|
2020-02-20 12:38:58 +08:00
|
|
|
/* USER CODE END 0 */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* Configure GPIO */
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
|
|
|
|
/* USER CODE END 1 */
|
|
|
|
|
|
|
|
/** Configure pins as
|
|
|
|
* Analog
|
|
|
|
* Input
|
|
|
|
* Output
|
|
|
|
* EVENT_OUT
|
|
|
|
* EXTI
|
|
|
|
*/
|
|
|
|
void MX_GPIO_Init(void)
|
|
|
|
{
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
|
2020-02-20 12:38:58 +08:00
|
|
|
/* GPIO Ports Clock Enable */
|
2020-04-02 22:18:11 +08:00
|
|
|
__HAL_RCC_GPIOE_CLK_ENABLE();
|
2020-04-06 21:16:18 +08:00
|
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
2020-07-15 18:26:22 +08:00
|
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
2020-03-17 13:08:19 +08:00
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
2020-07-15 18:26:22 +08:00
|
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
2020-02-20 12:38:58 +08:00
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/*Configure GPIO pin Output Level */
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port, SYS_POWER_LED_CTL_Pin, GPIO_PIN_SET);
|
2020-04-02 22:18:11 +08:00
|
|
|
|
|
|
|
/*Configure GPIO pin Output Level */
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_WritePin(GPIOE, PMB_PS_ON_Pin|SYS_FAN_CTL_1_Pin|SYS_FAN_CTL_2_Pin|SYS_FAN_CTL_3_Pin, GPIO_PIN_RESET);
|
2020-04-02 22:18:11 +08:00
|
|
|
|
|
|
|
/*Configure GPIO pin Output Level */
|
2020-07-23 17:43:36 +08:00
|
|
|
HAL_GPIO_WritePin(GPIOC, PMB_CHRG_SHDN_Pin|SYS_BUZZ_CTL_Pin, GPIO_PIN_SET);
|
|
|
|
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
|
|
HAL_GPIO_WritePin(GPIOC, PMB_TEMP_SEN_EN_Pin|SYS_RUN_LED_CTL_Pin|SOC_U2_HUB_PWR_CTL_Pin, GPIO_PIN_RESET);
|
2020-04-02 22:18:11 +08:00
|
|
|
|
2020-04-06 21:16:18 +08:00
|
|
|
/*Configure GPIO pin Output Level */
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_WritePin(GPIOB, IIC2_SCL_Pin|IIC2_SDA_Pin|USB2_VBUS_CTL_1_Pin|USB2_VBUS_CTL_2_Pin
|
2020-07-23 17:43:36 +08:00
|
|
|
|USB2_VBUS_CTL_3_Pin|USB2_VBUS_CTL_4_Pin, GPIO_PIN_RESET);
|
2020-07-15 18:26:22 +08:00
|
|
|
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
|
|
HAL_GPIO_WritePin(GPIOD, USB2_VBUS_CTL_5_Pin|USB2_VBUS_CTL_6_Pin|USB3_VBUS_CTL_5_Pin|USB3_VBUS_CTL_6_Pin
|
|
|
|
|USB3_VBUS_CTL_1_Pin|USB3_VBUS_CTL_2_Pin|USB3_VBUS_CTL_3_Pin|USB3_VBUS_CTL_4_Pin
|
|
|
|
|SOC_U3_HUB_PWR_CTL_Pin|SOC_U3_HOST_PWR_CTL_Pin|SOC_U3_GEC_PWR_CTL_Pin|SOC_GE_SW_PWR_CTL_Pin
|
2020-07-23 17:43:36 +08:00
|
|
|
|SOM_POWER_EN_Pin, GPIO_PIN_RESET);
|
2020-07-15 18:26:22 +08:00
|
|
|
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
|
|
HAL_GPIO_WritePin(USB2_FS_ENUM_CTL_GPIO_Port, USB2_FS_ENUM_CTL_Pin, GPIO_PIN_RESET);
|
|
|
|
|
2020-07-23 17:43:36 +08:00
|
|
|
/*Configure GPIO pin Output Level */
|
|
|
|
HAL_GPIO_WritePin(GPIOD, SOM_SLEEP_WAKE_Pin|SOM_FORCE_RECOVERY_Pin, GPIO_PIN_SET);
|
|
|
|
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
|
|
HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port, SOM_SYS_RESET_Pin, GPIO_PIN_SET);
|
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
/*Configure GPIO pins : PEPin PEPin PEPin PEPin
|
|
|
|
PEPin */
|
|
|
|
GPIO_InitStruct.Pin = SYS_POWER_LED_CTL_Pin|PMB_PS_ON_Pin|SYS_FAN_CTL_1_Pin|SYS_FAN_CTL_2_Pin
|
|
|
|
|SYS_FAN_CTL_3_Pin;
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
|
|
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
2020-04-06 21:16:18 +08:00
|
|
|
|
2020-04-17 15:55:14 +08:00
|
|
|
/*Configure GPIO pin : PtPin */
|
2020-07-15 18:26:22 +08:00
|
|
|
GPIO_InitStruct.Pin = SYS_CUSTOM_BTN_Pin;
|
2020-04-17 15:55:14 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_Init(SYS_CUSTOM_BTN_GPIO_Port, &GPIO_InitStruct);
|
2020-04-02 22:18:11 +08:00
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
/*Configure GPIO pins : PEPin PEPin */
|
|
|
|
GPIO_InitStruct.Pin = PMB_CHRG_STAT2_Pin|PMG_CHRG_STAT1_Pin;
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
|
|
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
/*Configure GPIO pins : PCPin PCPin PCPin PCPin
|
|
|
|
PCPin */
|
|
|
|
GPIO_InitStruct.Pin = PMB_CHRG_SHDN_Pin|PMB_TEMP_SEN_EN_Pin|SYS_RUN_LED_CTL_Pin|SYS_BUZZ_CTL_Pin
|
|
|
|
|SOC_U2_HUB_PWR_CTL_Pin;
|
2020-04-02 22:18:11 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
/*Configure GPIO pins : PCPin PCPin */
|
|
|
|
GPIO_InitStruct.Pin = PMB_TEMP_SEN_ALT_Pin|PMB_CLOULOMB_ALCC_Pin;
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
2020-04-02 22:18:11 +08:00
|
|
|
|
|
|
|
/*Configure GPIO pin : PtPin */
|
2020-07-15 18:26:22 +08:00
|
|
|
GPIO_InitStruct.Pin = SYS_POWER_BTN_Pin;
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
|
|
|
HAL_GPIO_Init(SYS_POWER_BTN_GPIO_Port, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
/*Configure GPIO pins : PEPin PEPin PEPin */
|
|
|
|
GPIO_InitStruct.Pin = SYS_FAN_SNS_1_Pin|SYS_FAN_SNS_2_Pin|SYS_FAN_SNS_3_Pin;
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
/*Configure GPIO pins : PBPin PBPin PBPin PBPin
|
|
|
|
PBPin PBPin PBPin */
|
|
|
|
GPIO_InitStruct.Pin = IIC2_SCL_Pin|IIC2_SDA_Pin|USB2_VBUS_CTL_1_Pin|USB2_VBUS_CTL_2_Pin
|
|
|
|
|USB2_VBUS_CTL_3_Pin|USB2_VBUS_CTL_4_Pin|SOM_SYS_RESET_Pin;
|
2020-04-17 18:25:14 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
2020-04-02 22:18:11 +08:00
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
2020-04-02 22:18:11 +08:00
|
|
|
|
|
|
|
/*Configure GPIO pins : PDPin PDPin PDPin PDPin
|
2020-07-15 18:26:22 +08:00
|
|
|
PDPin PDPin PDPin PDPin
|
|
|
|
PDPin PDPin PDPin PDPin
|
|
|
|
PDPin PDPin PDPin */
|
|
|
|
GPIO_InitStruct.Pin = USB2_VBUS_CTL_5_Pin|USB2_VBUS_CTL_6_Pin|USB3_VBUS_CTL_5_Pin|USB3_VBUS_CTL_6_Pin
|
|
|
|
|USB3_VBUS_CTL_1_Pin|USB3_VBUS_CTL_2_Pin|USB3_VBUS_CTL_3_Pin|USB3_VBUS_CTL_4_Pin
|
|
|
|
|SOC_U3_HUB_PWR_CTL_Pin|SOC_U3_HOST_PWR_CTL_Pin|SOC_U3_GEC_PWR_CTL_Pin|SOC_GE_SW_PWR_CTL_Pin
|
|
|
|
|SOM_POWER_EN_Pin|SOM_SLEEP_WAKE_Pin|SOM_FORCE_RECOVERY_Pin;
|
2020-04-02 22:18:11 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
|
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
|
|
|
2020-04-06 21:16:18 +08:00
|
|
|
/*Configure GPIO pin : PtPin */
|
2020-07-15 18:26:22 +08:00
|
|
|
GPIO_InitStruct.Pin = USB2_FS_ENUM_CTL_Pin;
|
2020-04-06 21:16:18 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_Init(USB2_FS_ENUM_CTL_GPIO_Port, &GPIO_InitStruct);
|
2020-04-06 21:16:18 +08:00
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/*Configure GPIO pin : PtPin */
|
2020-07-15 18:26:22 +08:00
|
|
|
GPIO_InitStruct.Pin = SOM_SHUTDOWN_REQ_Pin;
|
2020-04-02 22:18:11 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_Init(SOM_SHUTDOWN_REQ_GPIO_Port, &GPIO_InitStruct);
|
2020-04-02 22:18:11 +08:00
|
|
|
|
2020-04-17 15:55:14 +08:00
|
|
|
/*Configure GPIO pin : PtPin */
|
2020-07-15 18:26:22 +08:00
|
|
|
GPIO_InitStruct.Pin = SOM_MOD_SLEEP_Pin;
|
2020-04-17 15:55:14 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_Init(SOM_MOD_SLEEP_GPIO_Port, &GPIO_InitStruct);
|
2020-04-17 15:55:14 +08:00
|
|
|
|
|
|
|
/* EXTI interrupt init*/
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0);
|
|
|
|
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
|
|
|
|
|
|
|
|
HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
|
|
|
|
HAL_NVIC_EnableIRQ(EXTI3_IRQn);
|
2020-04-17 15:55:14 +08:00
|
|
|
|
2020-02-20 12:38:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 2 */
|
2020-04-17 15:55:14 +08:00
|
|
|
|
|
|
|
void Beep(uint32_t time_ms)
|
2020-04-14 17:27:52 +08:00
|
|
|
{
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_WritePin(SYS_BUZZ_CTL_GPIO_Port,SYS_BUZZ_CTL_Pin, GPIO_PIN_RESET);
|
2020-04-17 15:55:14 +08:00
|
|
|
osDelay(time_ms);
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_WritePin(SYS_BUZZ_CTL_GPIO_Port,SYS_BUZZ_CTL_Pin, GPIO_PIN_SET);
|
2020-04-14 17:27:52 +08:00
|
|
|
}
|
2020-04-17 15:55:14 +08:00
|
|
|
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
2020-04-14 17:27:52 +08:00
|
|
|
{
|
2020-07-15 18:26:22 +08:00
|
|
|
if(GPIO_Pin==SYS_POWER_BTN_Pin)
|
|
|
|
{
|
|
|
|
if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET)
|
|
|
|
{//Rising edge trigger
|
|
|
|
NaviKit.sys.power_btn = true;
|
|
|
|
printf("pwr_btn pushed \n");
|
|
|
|
}
|
|
|
|
if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_RESET)
|
|
|
|
{//falling edge trigger
|
|
|
|
NaviKit.sys.power_btn = false;
|
2020-07-23 17:43:36 +08:00
|
|
|
printf("pwr_btn released \n");
|
2020-07-15 18:26:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(GPIO_Pin == SYS_CUSTOM_BTN_Pin)
|
2020-04-17 15:55:14 +08:00
|
|
|
{
|
2020-07-15 18:26:22 +08:00
|
|
|
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_SET)
|
2020-04-17 15:55:14 +08:00
|
|
|
{//Rising edge trigger
|
2020-07-15 18:26:22 +08:00
|
|
|
NaviKit.sys.custom_btn = false;
|
2020-07-23 17:43:36 +08:00
|
|
|
printf("cus_btn released \n");
|
2020-04-17 15:55:14 +08:00
|
|
|
}
|
2020-07-15 18:26:22 +08:00
|
|
|
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET)
|
2020-04-17 15:55:14 +08:00
|
|
|
{//falling edge trigger
|
2020-07-15 18:26:22 +08:00
|
|
|
NaviKit.sys.custom_btn = true;
|
|
|
|
printf("cus_btn pushed \n");
|
2020-04-17 15:55:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 17:27:52 +08:00
|
|
|
}
|
2020-02-20 12:38:58 +08:00
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|