#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/dma.h"
#include "hardware/timer.h"
#include "neopixel.h"
#include "oled.h"
// Definições de pinos e constantes
#define LED_PIN 25
#define NEOPIXEL_PIN 12
#define NEOPIXEL_LENGTH 8
// Variáveis globais
repeating_timer_t timer1;
bool task1_flag = false;
bool task2_flag = false;
bool task3_flag = false;
// Protótipos de funções
bool task1_callback(repeating_timer_t *rt);
bool task2_callback(repeating_timer_t *rt);
bool task3_callback(repeating_timer_t *rt);
void init_hardware();
void update_status_led();
void handle_neopixel();
void update_oled_display();
float read_internal_temp();
// Tarefa 1 - Principal (100ms)
bool task1_callback(repeating_timer_t *rt) {
task1_flag = true;
return true; // continua o timer
}
// Tarefa 2 - Secundária (200ms)
bool task2_callback(repeating_timer_t *rt) {
if(task1_flag) {
task2_flag = true;
task1_flag = false;
}
return true;
}
// Tarefa 3 - Secundária (500ms)
bool task3_callback(repeating_timer_t *rt) {
if(task1_flag) {
task3_flag = true;
task1_flag = false;
}
return true;
}
void main() {
stdio_init_all();
init_hardware();
// Configura timers repetitivos
add_repeating_timer_ms(100, task1_callback, NULL, &timer1); // Tarefa principal
add_repeating_timer_ms(200, task2_callback, NULL, NULL); // Tarefa 2
add_repeating_timer_ms(500, task3_callback, NULL, NULL); // Tarefa 3
while(true) {
if(task1_flag) {
update_status_led();
float temp = read_internal_temp();
// Processamento principal
task1_flag = false;
}
if(task2_flag) {
handle_neopixel();
task2_flag = false;
}
if(task3_flag) {
update_oled_display();
task3_flag = false;
}
tight_loop_contents();
}
}
void init_hardware() {
// Inicializa LED onboard
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
// Inicializa NeoPixel
neopixel_init(NEOPIXEL_PIN);
// Inicializa OLED
oled_init();
// Configura DMA para leitura de temperatura
// (implementação específica da placa)
}
float read_internal_temp() {
// Implementação da leitura de temperatura via DMA
// Retorna temperatura em Celsius
return 0.0f; // placeholder
}
void update_status_led() {
// Alterna LED para indicar atividade
static bool led_state = false;
led_state = !led_state;
gpio_put(LED_PIN, led_state);
}
void handle_neopixel() {
// Atualiza matriz NeoPixel
// (implementação específica)
}
void update_oled_display() {
// Atualiza display OLED com status e temperatura
// (implementação específica)
}