/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file    gpio.c
  * @brief   This file provides code for the configuration
  *          of all used GPIO pins.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2026 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "gpio.h"

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/*----------------------------------------------------------------------------*/
/* Configure GPIO                                                             */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/** Configure pins
     PA5   ------> PWR_WKUP6
     PA13 (JTMS/SWDIO)   ------> DEBUG_JTMS-SWDIO
     PA14 (JTCK/SWCLK)   ------> DEBUG_JTCK-SWCLK
*/
void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOE_CLK_ENABLE();
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(PowerMOdeControl_GPIO_Port, PowerMOdeControl_Pin, GPIO_PIN_SET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, ADC_TEMP_CS_Pin|ADC_RESET_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOE, VCC_LORA_ENABLE_Pin|LORA_RESET_Pin|LORA_RXEN_Pin|LORA_TXEN_Pin
                          |LORA_CS_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOD, ADC_CS_Pin|HIVE_SELECT_EN_Pin|HIVE_SELECT_A0_Pin|HIVE_SELECT_A1_Pin
                          |CELL_SELECT_EN_Pin|CELL_SELECT_A0_Pin|CELL_SELECT_A1_Pin|AVDD_ENABLE_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(WP_EN_GPIO_Port, WP_EN_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pins : DIP_ADRESS_0_Pin DIP_ADRESS_1_Pin DIP_ADRESS_2_Pin DIP_ADRESS_3_Pin
                           DIP_ADRESS_4_Pin LORA_BUSY_Pin */
  GPIO_InitStruct.Pin = DIP_ADRESS_0_Pin|DIP_ADRESS_1_Pin|DIP_ADRESS_2_Pin|DIP_ADRESS_3_Pin
                          |DIP_ADRESS_4_Pin|LORA_BUSY_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  /*Configure GPIO pins : DIP_ADRESS_5_Pin DIP_HIVE_SETTINGS_0_Pin DIP_HIVE_SETTINGS_1_Pin DIP_HIVE_SETTINGS_2_Pin
                           DIP_HIVE_SETTINGS_3_Pin DIP_HIVE_ENABLE_0_Pin */
  GPIO_InitStruct.Pin = DIP_ADRESS_5_Pin|DIP_HIVE_SETTINGS_0_Pin|DIP_HIVE_SETTINGS_1_Pin|DIP_HIVE_SETTINGS_2_Pin
                          |DIP_HIVE_SETTINGS_3_Pin|DIP_HIVE_ENABLE_0_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pin : ADC_Weight_DRDY_Pin */
  GPIO_InitStruct.Pin = ADC_Weight_DRDY_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(ADC_Weight_DRDY_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : LORA_DIO1_Pin LORA_DIO2_Pin SIG_CHARGING_Pin SIG_DONE_Pin
                           ADC_TEMP_DRDY_Pin */
  GPIO_InitStruct.Pin = LORA_DIO1_Pin|LORA_DIO2_Pin|SIG_CHARGING_Pin|SIG_DONE_Pin
                          |ADC_TEMP_DRDY_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PowerMOdeControl_Pin ADC_TEMP_CS_Pin ADC_RESET_Pin */
  GPIO_InitStruct.Pin = PowerMOdeControl_Pin|ADC_TEMP_CS_Pin|ADC_RESET_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pins : VCC_LORA_ENABLE_Pin LORA_RESET_Pin LORA_RXEN_Pin LORA_TXEN_Pin
                           LORA_CS_Pin */
  GPIO_InitStruct.Pin = VCC_LORA_ENABLE_Pin|LORA_RESET_Pin|LORA_RXEN_Pin|LORA_TXEN_Pin
                          |LORA_CS_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);

  /*Configure GPIO pins : ADC_CS_Pin HIVE_SELECT_EN_Pin HIVE_SELECT_A0_Pin HIVE_SELECT_A1_Pin
                           CELL_SELECT_EN_Pin CELL_SELECT_A0_Pin CELL_SELECT_A1_Pin AVDD_ENABLE_Pin */
  GPIO_InitStruct.Pin = ADC_CS_Pin|HIVE_SELECT_EN_Pin|HIVE_SELECT_A0_Pin|HIVE_SELECT_A1_Pin
                          |CELL_SELECT_EN_Pin|CELL_SELECT_A0_Pin|CELL_SELECT_A1_Pin|AVDD_ENABLE_Pin;
  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);

  /*Configure GPIO pins : DIP_HIVE_SETTINGS_4_Pin DIP_HIVE_SETTINGS_5_Pin ADC_VBUS_SENSE_Pin */
  GPIO_InitStruct.Pin = DIP_HIVE_SETTINGS_4_Pin|DIP_HIVE_SETTINGS_5_Pin|ADC_VBUS_SENSE_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : DIP_HIVE_ENABLE_1_Pin DIP_HIVE_ENABLE_2_Pin DIP_HIVE_ENABLE_3_Pin DIP_HIVE_ENABLE_4_Pin
                           DIP_HIVE_ENABLE_5_Pin */
  GPIO_InitStruct.Pin = DIP_HIVE_ENABLE_1_Pin|DIP_HIVE_ENABLE_2_Pin|DIP_HIVE_ENABLE_3_Pin|DIP_HIVE_ENABLE_4_Pin
                          |DIP_HIVE_ENABLE_5_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /*Configure GPIO pin : WP_EN_Pin */
  GPIO_InitStruct.Pin = WP_EN_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(WP_EN_GPIO_Port, &GPIO_InitStruct);

  /* EXTI interrupt init*/
  HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI0_IRQn);

  HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI1_IRQn);

  HAL_NVIC_SetPriority(EXTI2_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI2_IRQn);

  HAL_NVIC_SetPriority(EXTI3_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI3_IRQn);

  HAL_NVIC_SetPriority(EXTI4_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI4_IRQn);

  HAL_NVIC_SetPriority(EXTI6_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI6_IRQn);

}

/* USER CODE BEGIN 2 */

/* USER CODE END 2 */
