935
+ − 1 /**
+ − 2 ******************************************************************************
+ − 3 * @file gpio.c
+ − 4 * @author heinrichs weikamp gmbh
+ − 5 * @version V0.0.1
+ − 6 * @date 08-Dec-2024
+ − 7 * @brief Definitions for GPIO operations (GPIO_V2)
+ − 8 *
+ − 9 @verbatim
+ − 10 ==============================================================================
+ − 11 ##### How to use #####
+ − 12 ==============================================================================
+ − 13 @endverbatim
+ − 14 ******************************************************************************
+ − 15 * @attention
+ − 16 *
+ − 17 * <h2><center>© COPYRIGHT(c) 2024 heinrichs weikamp</center></h2>
+ − 18 *
+ − 19 ******************************************************************************
+ − 20 */
+ − 21
+ − 22 /* Includes ------------------------------------------------------------------*/
+ − 23
+ − 24 #include "stm32f4xx_hal.h"
+ − 25 #include "gpio.h"
951
+ − 26 #include "data_exchange.h"
+ − 27 #include "scheduler.h"
935
+ − 28
+ − 29 /* Exported variables --------------------------------------------------------*/
+ − 30 /* Private variables ---------------------------------------------------------*/
+ − 31
+ − 32 /* Private types -------------------------------------------------------------*/
+ − 33
+ − 34 /* Private function prototypes -----------------------------------------------*/
+ − 35
+ − 36 /* Exported functions --------------------------------------------------------*/
+ − 37 void GPIO_LEDs_VIBRATION_Init(void) {
+ − 38 GPIO_InitTypeDef GPIO_InitStructure;
+ − 39
+ − 40 __GPIOA_CLK_ENABLE();
+ − 41 GPIO_InitStructure.Pin = LED_CONTROL_PIN_RED;
+ − 42 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
+ − 43 GPIO_InitStructure.Pull = GPIO_PULLUP;
+ − 44 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
+ − 45 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure);
+ − 46 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_SET);
+ − 47
+ − 48 GPIO_InitStructure.Pin = LED_CONTROL_PIN_GREEN;
+ − 49 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
+ − 50 GPIO_InitStructure.Pull = GPIO_PULLUP;
+ − 51 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
+ − 52 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure);
+ − 53 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_SET);
+ − 54
+ − 55 GPIO_InitStructure.Pin = VIBRATION_CONTROL_PIN;
+ − 56 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
+ − 57 GPIO_InitStructure.Pull = GPIO_PULLDOWN;
+ − 58 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
+ − 59 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure);
+ − 60 HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_RESET);
938
+ − 61 }
+ − 62
+ − 63 void GPIO_GNSS_Init()
+ − 64 {
+ − 65 GPIO_InitTypeDef GPIO_InitStructure;
935
+ − 66
+ − 67 __GPIOB_CLK_ENABLE();
+ − 68 GPIO_InitStructure.Pin = GPS_POWER_CONTROL_PIN;
+ − 69 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
+ − 70 GPIO_InitStructure.Pull = GPIO_PULLUP;
+ − 71 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
+ − 72 HAL_GPIO_Init( GPIOB, &GPIO_InitStructure);
+ − 73 HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_SET);
+ − 74
+ − 75 GPIO_InitStructure.Pin = GPS_BCKP_CONTROL_PIN;
+ − 76 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
+ − 77 GPIO_InitStructure.Pull = GPIO_PULLDOWN;
+ − 78 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
+ − 79 HAL_GPIO_Init( GPIOB, &GPIO_InitStructure);
947
+ − 80 HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_SET);
935
+ − 81 }
+ − 82
+ − 83 void GPIO_Power_MainCPU_Init(void) {
+ − 84 GPIO_InitTypeDef GPIO_InitStructure;
+ − 85 __GPIOC_CLK_ENABLE();
+ − 86 GPIO_InitStructure.Pin = MAINCPU_CONTROL_PIN;
+ − 87 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
+ − 88 GPIO_InitStructure.Pull = GPIO_PULLUP;
+ − 89 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
+ − 90 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure);
+ − 91 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_RESET);
+ − 92 }
+ − 93
951
+ − 94 #ifdef ENABLE_GPIO_V2
+ − 95 void GPIO_HandleBuzzer()
+ − 96 {
+ − 97 static uint32_t buzzerOnTick = 0;
+ − 98 static uint8_t buzzerWasOn = 0;
+ − 99
+ − 100 if(((global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_BUZZER_ON) != 0))
+ − 101 {
+ − 102 if(!buzzerWasOn)
+ − 103 {
+ − 104 buzzerOnTick = HAL_GetTick();
+ − 105 GPIO_VIBRATION_ON();
+ − 106 /* GPIO_LED_RED_ON(); */
+ − 107
+ − 108 if(time_elapsed_ms(buzzerOnTick,HAL_GetTick()) > EXT_INTERFACE_BUZZER_ON_TIME_MS)
+ − 109 {
+ − 110 GPIO_VIBRATION_OFF();
+ − 111 /* GPIO_LED_RED_OFF(); */
+ − 112 }
+ − 113 }
+ − 114 buzzerWasOn = 1;
+ − 115 }
+ − 116 else
+ − 117 {
+ − 118 if(buzzerWasOn)
+ − 119 {
+ − 120 buzzerOnTick = 0;
+ − 121 GPIO_VIBRATION_OFF();
+ − 122 /* GPIO_LED_RED_OFF(); */
+ − 123 }
+ − 124 buzzerWasOn = 0;
+ − 125 }
+ − 126 }
+ − 127 #endif
935
+ − 128 void GPIO_Power_MainCPU_ON(void) {
+ − 129 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_RESET);
+ − 130 }
+ − 131
+ − 132 void GPIO_Power_MainCPU_OFF(void) {
+ − 133 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_SET);
+ − 134 }
+ − 135
+ − 136 #ifdef ENABLE_GPIO_V2
+ − 137 void GPIO_LED_GREEN_ON(void) {
+ − 138 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_RESET);
+ − 139 }
+ − 140
+ − 141 void GPIO_LED_GREEN_OFF(void) {
+ − 142 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_SET);
+ − 143 }
+ − 144
+ − 145 void GPIO_LED_RED_ON(void) {
+ − 146 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_RESET);
+ − 147 }
+ − 148
+ − 149 void GPIO_LED_RED_OFF(void) {
+ − 150 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_SET);
+ − 151 }
+ − 152
+ − 153 void GPIO_VIBRATION_ON(void) {
+ − 154 HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_SET);
+ − 155 }
+ − 156
+ − 157 void GPIO_VIBRATION_OFF(void) {
+ − 158 HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_RESET);
+ − 159 }
+ − 160
+ − 161 void GPIO_GPS_ON(void) {
+ − 162 HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_RESET);
+ − 163 }
+ − 164
+ − 165 void GPIO_GPS_OFF(void) {
+ − 166 HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_SET);
+ − 167 }
+ − 168
+ − 169 void GPIO_GPS_BCKP_ON(void) {
+ − 170 HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_SET);
+ − 171 }
+ − 172
+ − 173 void GPIO_GPS_BCKP_OFF(void) {
+ − 174 HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_RESET);
+ − 175 }
+ − 176 #endif
+ − 177
+ − 178 /* Private functions ---------------------------------------------------------*/
+ − 179
+ − 180
+ − 181 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/