#include "stm32c0xx_hal.h"
#include "FreeRTOS.h"
#include "task.h"
void tled_scroll(void* p);
void MX_GPIO_Init(void);
void SystemClock_Config(void);
int main(void)
{
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
// Création de la tâche de gestion du défilement
xTaskHandle HScroll;
uint16_t leds[] = {GPIO_PIN_11, GPIO_PIN_4, GPIO_PIN_0, GPIO_PIN_1, GPIO_PIN_9, GPIO_PIN_8, GPIO_PIN_7, GPIO_PIN_10};
xTaskCreate(tled_scroll, "tled_scroll", 128, (void*)leds, 1, &HScroll);
void tled_scroll(void* p)
{
uint16_t* leds = (uint16_t*)p;
uint8_t num_leds = 8;
uint8_t current_led = 0;
int8_t direction = 1; // Direction initiale : 1 pour avancer, -1 pour reculer
while (1)
{
// Allume les deux LEDs actuelles
HAL_GPIO_WritePin(GPIOA, leds[current_led], GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, leds[(current_led + 1) % num_leds], GPIO_PIN_SET);
vTaskDelay(500);
// Éteint les deux LEDs actuelles
HAL_GPIO_WritePin(GPIOA, leds[current_led], GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, leds[(current_led + 1) % num_leds], GPIO_PIN_RESET);
// Passe aux LEDs suivantes dans la direction spécifiée
current_led += direction;
if (current_led >= num_leds)
{
current_led = num_leds - 2; // Recule d'une LED pour éviter de dépasser
direction = -1; // Inverse la direction
}
else if (current_led < 0)
{
current_led = 1; // Avance d'une LED pour éviter de dépasser
direction = 1; // Inverse la direction
}
// Pause entre chaque paire de LEDs
vTaskDelay(500);
}
}
void MX_GPIO_Init(void)
{
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct = {0};
/*Configure GPIO pins : PA0, PA1, PA4, PA7, PA8, PA9, PA11, PA10 */
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_11 | GPIO_PIN_7 | GPIO_PIN_9 | GPIO_PIN_8 | GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
// Gérer l'erreur de manière appropriée
}
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
// Gérer l'erreur de manière appropriée
}
}
// Fonction de ralentissement de FreeRTOS
void vApplicationIdleHook(void)
{
// Fonction de ralentissement de FreeRTOS
}