Mercurial > public > ostc4
changeset 935:f2494a708f52 Evo_2_23
Added unit files for GPIO:
The new gpios need to be accessed from severall units. That's why the current, static implementation in the baseCPU did not fit. To enable global usage of the function they have been moved into new source / header file
author | Ideenmodellierer |
---|---|
date | Sun, 08 Dec 2024 21:59:22 +0100 |
parents | 406d498786e7 |
children | 3029f0332f4f |
files | Small_CPU/Inc/gpio.h Small_CPU/Src/gpio.c |
diffstat | 2 files changed, 199 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Small_CPU/Inc/gpio.h Sun Dec 08 21:59:22 2024 +0100 @@ -0,0 +1,59 @@ +/** + ****************************************************************************** + * @file gpio.h + * @author heinrichs weikamp gmbh + * @version V0.0.1 + * @date 08-Dec-2024 + * @brief new GPIO definitions (GPIO_V2) + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2024 heinrichs weikamp</center></h2> + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef GPIO_H +#define GPIO_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ + +#include "configuration.h" + +#define VIBRATION_CONTROL_PIN GPIO_PIN_3 /* PortA */ +#define LED_CONTROL_PIN_RED GPIO_PIN_2 /* PortA */ +#define LED_CONTROL_PIN_GREEN GPIO_PIN_1 /* PortA */ +#define MAINCPU_CONTROL_PIN GPIO_PIN_0 /* PortC */ +#define GPS_POWER_CONTROL_PIN GPIO_PIN_15 /* PortB */ +#define GPS_BCKP_CONTROL_PIN GPIO_PIN_14 /* PortB */ + +void GPIO_LEDs_VIBRATION_Init(void); +void GPIO_Power_MainCPU_Init(void); +void GPIO_Power_MainCPU_ON(void); +void GPIO_Power_MainCPU_OFF(void); + +#ifdef ENABLE_GPIO_V2 +void GPIO_LED_RED_OFF(void); +void GPIO_LED_RED_ON(void); +void GPIO_LED_GREEN_OFF(void); +void GPIO_LED_GREEN_ON(void); +void GPIO_VIBRATION_OFF(void); +void GPIO_VIBRATION_ON(void); +void GPIO_GPS_OFF(void); +void GPIO_GPS_ON(void); +void GPIO_GPS_BCKP_OFF(void); +void GPIO_GPS_BCKP_ON(void); +#endif +#ifdef __cplusplus +} +#endif +#endif /* GPIO_H */ + + + +/************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Small_CPU/Src/gpio.c Sun Dec 08 21:59:22 2024 +0100 @@ -0,0 +1,140 @@ +/** + ****************************************************************************** + * @file gpio.c + * @author heinrichs weikamp gmbh + * @version V0.0.1 + * @date 08-Dec-2024 + * @brief Definitions for GPIO operations (GPIO_V2) + * + @verbatim + ============================================================================== + ##### How to use ##### + ============================================================================== + @endverbatim + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2024 heinrichs weikamp</center></h2> + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ + +#include "stm32f4xx_hal.h" +#include "gpio.h" + +/* Exported variables --------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private types -------------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Exported functions --------------------------------------------------------*/ +void GPIO_LEDs_VIBRATION_Init(void) { + GPIO_InitTypeDef GPIO_InitStructure; + + __GPIOA_CLK_ENABLE(); + GPIO_InitStructure.Pin = LED_CONTROL_PIN_RED; + GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.Pull = GPIO_PULLUP; + GPIO_InitStructure.Speed = GPIO_SPEED_LOW; + HAL_GPIO_Init( GPIOA, &GPIO_InitStructure); + HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_SET); + + GPIO_InitStructure.Pin = LED_CONTROL_PIN_GREEN; + GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.Pull = GPIO_PULLUP; + GPIO_InitStructure.Speed = GPIO_SPEED_LOW; + HAL_GPIO_Init( GPIOA, &GPIO_InitStructure); + HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_SET); + + GPIO_InitStructure.Pin = VIBRATION_CONTROL_PIN; + GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.Pull = GPIO_PULLDOWN; + GPIO_InitStructure.Speed = GPIO_SPEED_LOW; + HAL_GPIO_Init( GPIOA, &GPIO_InitStructure); + HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_RESET); + + __GPIOB_CLK_ENABLE(); + GPIO_InitStructure.Pin = GPS_POWER_CONTROL_PIN; + GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.Pull = GPIO_PULLUP; + GPIO_InitStructure.Speed = GPIO_SPEED_LOW; + HAL_GPIO_Init( GPIOB, &GPIO_InitStructure); + HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_SET); + + GPIO_InitStructure.Pin = GPS_BCKP_CONTROL_PIN; + GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.Pull = GPIO_PULLDOWN; + GPIO_InitStructure.Speed = GPIO_SPEED_LOW; + HAL_GPIO_Init( GPIOB, &GPIO_InitStructure); + HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_RESET); +} + +void GPIO_Power_MainCPU_Init(void) { + GPIO_InitTypeDef GPIO_InitStructure; + __GPIOC_CLK_ENABLE(); + GPIO_InitStructure.Pin = MAINCPU_CONTROL_PIN; + GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.Pull = GPIO_PULLUP; + GPIO_InitStructure.Speed = GPIO_SPEED_LOW; + HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); + HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_RESET); +} + +void GPIO_Power_MainCPU_ON(void) { + HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_RESET); +} + +void GPIO_Power_MainCPU_OFF(void) { + HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_SET); +} + +#ifdef ENABLE_GPIO_V2 +void GPIO_LED_GREEN_ON(void) { + HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_RESET); +} + +void GPIO_LED_GREEN_OFF(void) { + HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_SET); +} + +void GPIO_LED_RED_ON(void) { + HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_RESET); +} + +void GPIO_LED_RED_OFF(void) { + HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_SET); +} + +void GPIO_VIBRATION_ON(void) { + HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_SET); +} + +void GPIO_VIBRATION_OFF(void) { + HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_RESET); +} + +void GPIO_GPS_ON(void) { + HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_RESET); +} + +void GPIO_GPS_OFF(void) { + HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_SET); +} + +void GPIO_GPS_BCKP_ON(void) { + HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_SET); +} + +void GPIO_GPS_BCKP_OFF(void) { + HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_RESET); +} +#endif + +/* Private functions ---------------------------------------------------------*/ + + +/************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/