From 51001d6bc4ebd6bc5fdfb50f8add7d3ef6e9d3d2 Mon Sep 17 00:00:00 2001 From: Mitchell Marino Date: Wed, 26 Mar 2025 08:21:30 -0500 Subject: [PATCH] move other drivers --- main/drivers/all.cpp | 4 ++- main/drivers/leds.cpp | 25 ++++++++++++++--- main/drivers/leds.h | 61 ++++++++++++++++++++++++------------------ main/drivers/power.cpp | 8 +++++- main/drivers/power.h | 6 +++-- main/drivers/tft.cpp | 4 ++- main/main.cpp | 8 +++--- 7 files changed, 77 insertions(+), 39 deletions(-) diff --git a/main/drivers/all.cpp b/main/drivers/all.cpp index 1298839..2d8e03c 100644 --- a/main/drivers/all.cpp +++ b/main/drivers/all.cpp @@ -13,7 +13,9 @@ void init_drivers() { init_speaker(); init_sseg(); init_game_timers(); - + init_tft(); + init_leds(); + init_power_board(); } /// @brief Initializes I2C_NUM_0. diff --git a/main/drivers/leds.cpp b/main/drivers/leds.cpp index 4b19535..9be368e 100644 --- a/main/drivers/leds.cpp +++ b/main/drivers/leds.cpp @@ -1,8 +1,12 @@ #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 = { .strip_gpio_num = NEOPIXEL_PIN, .max_leds = LED_COUNT, @@ -17,9 +21,24 @@ void init_leds(void) { rmt_config.flags.with_dma = false; 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++) { ESP_ERROR_CHECK(led_strip_set_pixel(leds, i, i, LED_COUNT-i, 0)); } diff --git a/main/drivers/leds.h b/main/drivers/leds.h index 1dc0366..09f9ea3 100644 --- a/main/drivers/leds.h +++ b/main/drivers/leds.h @@ -8,33 +8,42 @@ // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution) #define LED_STRIP_RMT_RES_HZ (10 * 1000 * 1000) -extern led_strip_handle_t leds; - typedef enum { - shape1 = 0, - shape2 = 1, - shape3 = 2, - shape4 = 3, - module_sseg = 4, - game_sseg = 5, - tft = 6, - mic = 7, - ir_led = 8, - speaker = 9, - rfid = 10, - keypad = 11, - char_lcd = 12, - switch4 = 13, - switch3 = 14, - switch2 = 15, - switch1 = 16, - button4 = 17, - button3 = 18, - button2 = 19, - button1 = 20, -} Led; + led_shape1 = 0, + led_shape2 = 1, + led_shape3 = 2, + led_shape4 = 3, + led_module_sseg = 4, + led_game_sseg = 5, + led_tft = 6, + led_mic = 7, + led_ir_led = 8, + led_speaker = 9, + led_rfid = 10, + led_keypad = 11, + led_char_lcd = 12, + led_switch4 = 13, + led_switch3 = 14, + led_switch2 = 15, + led_switch1 = 16, + led_button4 = 17, + led_button3 = 18, + led_button2 = 19, + led_button1 = 20, +} IndicatorLED; -void init_leds(void); -void example_leds(void); +/// @brief Initializes the indicator LEDs +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 */ \ No newline at end of file diff --git a/main/drivers/power.cpp b/main/drivers/power.cpp index 37aefb0..41f401e 100644 --- a/main/drivers/power.cpp +++ b/main/drivers/power.cpp @@ -1,7 +1,8 @@ #include "power.h" #include "char_lcd.h" +#include -static const char* TAG = "POWER"; +static const char* TAG = "power"; void bat_monitor_task(void* arg) { while (1) { @@ -36,12 +37,17 @@ void bat_monitor_task(void* arg) { } void init_power_board() { + ESP_LOGI(TAG, "Initializing power board...") + if (!lipo.begin()) { ESP_LOGE(TAG, "Failed to init communication with the battery gas guage"); + return; } auto voltage = lipo.voltage(); ESP_LOGI(TAG, "Battery Voltage: %d", voltage); + + ESP_LOGI(TAG, "Power board initialized!"); } diff --git a/main/drivers/power.h b/main/drivers/power.h index f84bafc..463b0ec 100644 --- a/main/drivers/power.h +++ b/main/drivers/power.h @@ -2,12 +2,14 @@ #define POWER_H #include "SparkFunBQ27441/SparkFunBQ27441.h" -#include void bat_monitor_task(void* arg); /// Initializes the battery gas guage for getting battery stats. void init_power_board(); + +/// @brief Gets the battery voltage +/// @return battery voltage in mV. uint16_t get_bat_voltage(); -#endif /* POWER_H */ \ No newline at end of file +#endif /* POWER_H */ diff --git a/main/drivers/tft.cpp b/main/drivers/tft.cpp index 3c4839e..1bbd6d6 100644 --- a/main/drivers/tft.cpp +++ b/main/drivers/tft.cpp @@ -178,11 +178,13 @@ static void tick_timer_task(void* arg) { } void init_tft() { + ESP_LOGI(TAG, "Initializing TFT..."); + initialize_spi(); initialize_display(); xTaskCreatePinnedToCore(guiTask, "gui", 4096*2, 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!"); } diff --git a/main/main.cpp b/main/main.cpp index 8c16234..26d762e 100755 --- a/main/main.cpp +++ b/main/main.cpp @@ -24,12 +24,10 @@ extern "C" void app_main(void) { printf("app_main\n"); 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(); step0();