From b28ff29f457aaf023846b9459cff1e72b9b77ad1 Mon Sep 17 00:00:00 2001 From: Jasper Date: Sun, 29 May 2022 00:28:23 +0200 Subject: [PATCH] Initialize LEDs --- Core/Inc/leds.h | 6 ++++++ Core/Src/leds.c | 27 +++++++++++++++++++++++++++ Core/Src/main.c | 2 ++ STM32Make.make | 1 + 4 files changed, 36 insertions(+) create mode 100644 Core/Inc/leds.h create mode 100644 Core/Src/leds.c diff --git a/Core/Inc/leds.h b/Core/Inc/leds.h new file mode 100644 index 0000000..7c3ad90 --- /dev/null +++ b/Core/Inc/leds.h @@ -0,0 +1,6 @@ +#ifndef __LEDS_H +#define __LEDS_H + +void leds_init(); + +#endif // __LEDS_H \ No newline at end of file diff --git a/Core/Src/leds.c b/Core/Src/leds.c new file mode 100644 index 0000000..aea30c5 --- /dev/null +++ b/Core/Src/leds.c @@ -0,0 +1,27 @@ +#include "leds.h" +#include "main.h" +#include "stm32g4xx_hal.h" +#include "stm32g4xx_hal_gpio.h" + +void leds_init() { + HAL_GPIO_WritePin(LED_NOE_GPIO_Port, LED_NOE_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(LED_NCLR_GPIO_Port, LED_NCLR_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(LED_OCLK_GPIO_Port, LED_OCLK_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(LED_ICLK_GPIO_Port, LED_ICLK_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(TOP_PWM_GPIO_Port, TOP_PWM_Pin, GPIO_PIN_SET); + HAL_Delay(10); + + for (int i = 0; i < 12; i++) { + GPIO_PinState state = (i % 2 == 0) ? GPIO_PIN_SET : GPIO_PIN_RESET; + HAL_GPIO_WritePin(LED_SER_GPIO_Port, LED_SER_Pin, state); + HAL_Delay(5); + HAL_GPIO_WritePin(LED_ICLK_GPIO_Port, LED_ICLK_Pin, GPIO_PIN_SET); + HAL_Delay(10); + HAL_GPIO_WritePin(LED_ICLK_GPIO_Port, LED_ICLK_Pin, GPIO_PIN_RESET); + HAL_Delay(10); + } + + HAL_GPIO_WritePin(LED_OCLK_GPIO_Port, LED_OCLK_Pin, GPIO_PIN_SET); + HAL_Delay(10); + HAL_GPIO_WritePin(LED_OCLK_GPIO_Port, LED_OCLK_Pin, GPIO_PIN_RESET); +} \ No newline at end of file diff --git a/Core/Src/main.c b/Core/Src/main.c index 64176dd..4d16741 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -22,6 +22,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "events.h" +#include "leds.h" #include "rpi.h" #include "state.h" #include "vehicle.h" @@ -105,6 +106,7 @@ int main(void) { MX_FDCAN1_Init(); MX_I2C2_Init(); /* USER CODE BEGIN 2 */ + leds_init(); state_init(); vehicle_init(&hfdcan1); rpi_init(&hi2c2); diff --git a/STM32Make.make b/STM32Make.make index c7f316e..3bef827 100644 --- a/STM32Make.make +++ b/STM32Make.make @@ -37,6 +37,7 @@ BUILD_DIR = build # C sources C_SOURCES = \ Core/Src/events.c \ +Core/Src/leds.c \ Core/Src/main.c \ Core/Src/rpi.c \ Core/Src/state.c \