move other drivers

This commit is contained in:
Mitchell Marino 2025-03-26 08:21:30 -05:00 committed by Mitchell M
parent 83915efc33
commit 6530ed56c6
7 changed files with 77 additions and 39 deletions

View File

@ -13,7 +13,9 @@ void init_drivers() {
init_speaker(); init_speaker();
init_sseg(); init_sseg();
init_game_timers(); init_game_timers();
init_tft();
init_leds();
init_power_board();
} }
/// @brief Initializes I2C_NUM_0. /// @brief Initializes I2C_NUM_0.

View File

@ -1,8 +1,12 @@
#include "leds.h" #include "leds.h"
led_strip_handle_t leds; static const char* TAG = "leds";
static led_strip_handle_t leds;
void init_leds() {
ESP_LOGI(TAG, "Initializing LEDs...");
void init_leds(void) {
led_strip_config_t strip_config = { led_strip_config_t strip_config = {
.strip_gpio_num = NEOPIXEL_PIN, .strip_gpio_num = NEOPIXEL_PIN,
.max_leds = LED_COUNT, .max_leds = LED_COUNT,
@ -17,9 +21,24 @@ void init_leds(void) {
rmt_config.flags.with_dma = false; rmt_config.flags.with_dma = false;
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &leds)); ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &leds));
ESP_LOGI(TAG, "LEDs initialized!");
} }
void example_leds(void) { void leds_set(IndicatorLED led, uint8_t r, uint8_t g, uint8_t b) {
led_strip_set_pixel(leds, i, i, LED_COUNT-i, 0)
}
void leds_flush() {
led_strip_refresh(leds);
}
void leds_clear()
{
led_strip_clear(leds);
}
void example_leds() {
for (int i = 0; i < LED_COUNT; i++) { for (int i = 0; i < LED_COUNT; i++) {
ESP_ERROR_CHECK(led_strip_set_pixel(leds, i, i, LED_COUNT-i, 0)); ESP_ERROR_CHECK(led_strip_set_pixel(leds, i, i, LED_COUNT-i, 0));
} }

View File

@ -8,33 +8,42 @@
// 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution) // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
#define LED_STRIP_RMT_RES_HZ (10 * 1000 * 1000) #define LED_STRIP_RMT_RES_HZ (10 * 1000 * 1000)
extern led_strip_handle_t leds;
typedef enum { typedef enum {
shape1 = 0, led_shape1 = 0,
shape2 = 1, led_shape2 = 1,
shape3 = 2, led_shape3 = 2,
shape4 = 3, led_shape4 = 3,
module_sseg = 4, led_module_sseg = 4,
game_sseg = 5, led_game_sseg = 5,
tft = 6, led_tft = 6,
mic = 7, led_mic = 7,
ir_led = 8, led_ir_led = 8,
speaker = 9, led_speaker = 9,
rfid = 10, led_rfid = 10,
keypad = 11, led_keypad = 11,
char_lcd = 12, led_char_lcd = 12,
switch4 = 13, led_switch4 = 13,
switch3 = 14, led_switch3 = 14,
switch2 = 15, led_switch2 = 15,
switch1 = 16, led_switch1 = 16,
button4 = 17, led_button4 = 17,
button3 = 18, led_button3 = 18,
button2 = 19, led_button2 = 19,
button1 = 20, led_button1 = 20,
} Led; } IndicatorLED;
void init_leds(void); /// @brief Initializes the indicator LEDs
void example_leds(void); void init_leds();
/// Sets the color of an LED.
///
/// Call `flush_leds()` to send the data to the LEDs.
void leds_set(IndicatorLED led, uint8_t r, uint8_t g, uint8_t b);
/// Outputs the data to the leds.
void leds_flush();
/// Clears the LEDs
void leds_clear();
#endif /* LEDS_H */ #endif /* LEDS_H */

View File

@ -1,7 +1,8 @@
#include "power.h" #include "power.h"
#include "char_lcd.h" #include "char_lcd.h"
#include <esp_log.h>
static const char* TAG = "POWER"; static const char* TAG = "power";
void bat_monitor_task(void* arg) { void bat_monitor_task(void* arg) {
while (1) { while (1) {
@ -36,12 +37,17 @@ void bat_monitor_task(void* arg) {
} }
void init_power_board() { void init_power_board() {
ESP_LOGI(TAG, "Initializing power board...")
if (!lipo.begin()) { if (!lipo.begin()) {
ESP_LOGE(TAG, "Failed to init communication with the battery gas guage"); ESP_LOGE(TAG, "Failed to init communication with the battery gas guage");
return;
} }
auto voltage = lipo.voltage(); auto voltage = lipo.voltage();
ESP_LOGI(TAG, "Battery Voltage: %d", voltage); ESP_LOGI(TAG, "Battery Voltage: %d", voltage);
ESP_LOGI(TAG, "Power board initialized!");
} }

View File

@ -2,12 +2,14 @@
#define POWER_H #define POWER_H
#include "SparkFunBQ27441/SparkFunBQ27441.h" #include "SparkFunBQ27441/SparkFunBQ27441.h"
#include <esp_log.h>
void bat_monitor_task(void* arg); void bat_monitor_task(void* arg);
/// Initializes the battery gas guage for getting battery stats. /// Initializes the battery gas guage for getting battery stats.
void init_power_board(); void init_power_board();
/// @brief Gets the battery voltage
/// @return battery voltage in mV.
uint16_t get_bat_voltage(); uint16_t get_bat_voltage();
#endif /* POWER_H */ #endif /* POWER_H */

View File

@ -178,11 +178,13 @@ static void tick_timer_task(void* arg) {
} }
void init_tft() { void init_tft() {
ESP_LOGI(TAG, "Initializing TFT...");
initialize_spi(); initialize_spi();
initialize_display(); initialize_display();
xTaskCreatePinnedToCore(guiTask, "gui", 4096*2, NULL, 5, NULL, 1); xTaskCreatePinnedToCore(guiTask, "gui", 4096*2, NULL, 5, NULL, 1);
// xTaskCreatePinnedToCore(tick_timer_task, "tick_lvgl", 4096, NULL, 5, NULL, 1); // xTaskCreatePinnedToCore(tick_timer_task, "tick_lvgl", 4096, NULL, 5, NULL, 1);
ESP_LOGI(TAG, "TFT initialization Successful"); ESP_LOGI(TAG, "TFT initialized!");
} }

View File

@ -24,12 +24,10 @@ extern "C" void app_main(void) {
printf("app_main\n"); printf("app_main\n");
init_drivers(); init_drivers();
init_tft();
init_leds();
init_wires();
init_power_board();
step4(); // TODO: get wires out of the drivers
// TODO: generify the strike system out of wires
init_wires();
clean_bomb(); clean_bomb();
step0(); step0();