diff --git a/main/drivers/char_lcd.cpp b/main/drivers/char_lcd.cpp index af0fa4b..7f3b0e3 100644 --- a/main/drivers/char_lcd.cpp +++ b/main/drivers/char_lcd.cpp @@ -1,10 +1,6 @@ #include "char_lcd.h" -#define CHAR_LCD_I2C_NUM I2C_NUM_0 - -#define LCD_ADDR 0x27 -#define LCD_COLS 20 -#define LCD_ROWS 4 +i2c_lcd_pcf8574_handle_t lcd; static const char *TAG = "char_lcd"; diff --git a/main/drivers/char_lcd.h b/main/drivers/char_lcd.h index d4003dc..dd7eeb0 100644 --- a/main/drivers/char_lcd.h +++ b/main/drivers/char_lcd.h @@ -2,6 +2,7 @@ #define CHAR_LCD_H #include "i2c_lcd_pcf8574.h" +#include #define CHAR_LCD_I2C_NUM I2C_NUM_0 @@ -9,9 +10,7 @@ #define LCD_COLS 20 #define LCD_ROWS 4 -i2c_lcd_pcf8574_handle_t lcd; - -static const char *CHAR_LCD_TAG = "char_lcd"; +extern i2c_lcd_pcf8574_handle_t lcd; void init_char_lcd(void); diff --git a/main/drivers/game_timer.cpp b/main/drivers/game_timer.cpp index 67b5590..027afb0 100644 --- a/main/drivers/game_timer.cpp +++ b/main/drivers/game_timer.cpp @@ -34,19 +34,19 @@ void stop_module_timer(void) { } void set_game_time(uint32_t new_time) { - time_left = new_time; + game_time_left = new_time; } uint32_t get_game_time() { - return time_left; + return game_time_left; } void set_module_time(uint32_t new_time) { - time_left = new_time; + module_time_left = new_time; } uint32_t get_module_time() { - return time_left; + return module_time_left; } static void game_timer_task(void *arg) diff --git a/main/drivers/game_timer.h b/main/drivers/game_timer.h index a5eb25d..5729772 100644 --- a/main/drivers/game_timer.h +++ b/main/drivers/game_timer.h @@ -2,7 +2,7 @@ #define GAME_TIMER_H #include "freertos/FreeRTOS.h" -#include "sseg.hpp" +#include "sseg.h" /// Initializes the game and module timers. void init_game_module_timer(void); diff --git a/main/drivers/leds.cpp b/main/drivers/leds.cpp index b0bc4cb..1709dc0 100644 --- a/main/drivers/leds.cpp +++ b/main/drivers/leds.cpp @@ -1,5 +1,7 @@ #include "leds.h" + + #define PIXEL_COUNT 21 #define NEOPIXEL_PIN GPIO_NUM_7 diff --git a/main/drivers/sd.cpp b/main/drivers/sd.cpp index 2e51882..806c885 100644 --- a/main/drivers/sd.cpp +++ b/main/drivers/sd.cpp @@ -1,5 +1,10 @@ #include "sd.h" +sdmmc_card_t *card; + +static const char* mount_point = MOUNT_POINT; +static const char* TAG = "sd"; + void init_sd() { esp_err_t ret; @@ -13,14 +18,14 @@ void init_sd() { .disk_status_check_enable = false, }; - ESP_LOGI(SD_TAG, "Initializing SD card"); + ESP_LOGI(TAG, "Initializing SD card"); // Use settings defined above to initialize SD card and mount FAT filesystem. // Note: esp_vfs_fat_sdmmc/sdspi_mount is all-in-one convenience functions. // Please check its source code and implement error recovery when developing // production applications. - ESP_LOGI(SD_TAG, "Using SDMMC peripheral"); + ESP_LOGI(TAG, "Using SDMMC peripheral"); sdmmc_host_t host = SDMMC_HOST_DEFAULT(); // This initializes the slot without card detect (CD) and write protect (WP) signals. @@ -44,20 +49,20 @@ void init_sd() { // connected on the bus. This is for debug / example purpose only. slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP; - ESP_LOGI(SD_TAG, "Mounting filesystem"); + ESP_LOGI(TAG, "Mounting filesystem"); ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, &mount_config, &card); if (ret != ESP_OK) { if (ret == ESP_FAIL) { - ESP_LOGE(SD_TAG, "Failed to mount filesystem. " + ESP_LOGE(TAG, "Failed to mount filesystem. " "If you want the card to be formatted, set the EXAMPLE_FORMAT_IF_MOUNT_FAILED menuconfig option."); } else { - ESP_LOGE(SD_TAG, "Failed to initialize the card (%s). " + ESP_LOGE(TAG, "Failed to initialize the card (%s). " "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret)); } return; } - ESP_LOGI(SD_TAG, "Filesystem mounted"); + ESP_LOGI(TAG, "Filesystem mounted"); // Card has been initialized, print its properties sdmmc_card_print_info(stdout, card); @@ -65,5 +70,5 @@ void init_sd() { void deinit_sd() { esp_vfs_fat_sdcard_unmount(mount_point, card); - ESP_LOGI(SD_TAG, "Card unmounted"); + ESP_LOGI(TAG, "Card unmounted"); } diff --git a/main/drivers/sd.h b/main/drivers/sd.h index 8ddb57d..35b38d5 100644 --- a/main/drivers/sd.h +++ b/main/drivers/sd.h @@ -10,9 +10,7 @@ #define MOUNT_POINT "/sdcard" -const char mount_point[] = MOUNT_POINT; - -sdmmc_card_t *card; +extern sdmmc_card_t *card; #define SD_PIN_CLK GPIO_NUM_48 #define SD_PIN_CMD GPIO_NUM_45 diff --git a/main/drivers/speaker.h b/main/drivers/speaker.h index 8c3b1c3..47decb1 100644 --- a/main/drivers/speaker.h +++ b/main/drivers/speaker.h @@ -9,7 +9,7 @@ #include "driver/gpio.h" #include "esp_check.h" #include "sdkconfig.h" -#include "sd.hpp" +#include "sd.h" #define SPEAKER_PIN_BCLK GPIO_NUM_46 #define SPEAKER_PIN_WS GPIO_NUM_9 @@ -17,12 +17,8 @@ #define SAMPLE_RATE 44100 #define AUDIO_BUFFER 2048 -static i2s_chan_handle_t tx_chan; - -static const char *SPEAKER_TAG = "speaker_driver"; - esp_err_t play_raw(const char *fp); -void init_speaker(void) +void init_speaker(void); void play_example(); #endif /* SPEAKER_H */ \ No newline at end of file diff --git a/main/drivers/sseg.cpp b/main/drivers/sseg.cpp index 3f11807..64fc154 100644 --- a/main/drivers/sseg.cpp +++ b/main/drivers/sseg.cpp @@ -1,5 +1,7 @@ #include "sseg.h" +TM1640* sseg = nullptr; + static const char *TAG = "sseg_driver"; void init_sseg() { diff --git a/main/drivers/sseg.h b/main/drivers/sseg.h index c4e9c39..53afd78 100644 --- a/main/drivers/sseg.h +++ b/main/drivers/sseg.h @@ -7,7 +7,7 @@ #define SSEG_PIN_DATA GPIO_NUM_10 #define SSEG_PIN_CLK GPIO_NUM_11 -TM1640* sseg = nullptr; +extern TM1640* sseg; /// Initializes the seven segment driver void init_sseg(); diff --git a/main/main.cpp b/main/main.cpp index 73d0aa4..9c7cc03 100755 --- a/main/main.cpp +++ b/main/main.cpp @@ -7,10 +7,10 @@ #include "drivers/tft.hpp" #include "drivers/wires.h" #include "drivers/bottom_half.h" -#include "drivers/sd.hpp" -#include "drivers/game_timer.hpp" -#include "drivers/speaker.hpp" -#include "drivers/char_lcd.hpp" +#include "drivers/sd.h" +#include "drivers/game_timer.h" +#include "drivers/speaker.h" +#include "drivers/char_lcd.h" #include "esp_rom_gpio.h" #include "steps/step0.hpp" @@ -25,7 +25,6 @@ #define WIRES_REG_WIRES static const char *TAG = "main"; -static void relay_task(void *arg); extern "C" void app_main(void) { printf("app_main\n"); @@ -34,7 +33,7 @@ extern "C" void app_main(void) { init_tft(); init_speaker(); init_sseg(); - init_game_timer(); + init_game_module_timer(); init_wires(); init_bottom_half(); @@ -42,7 +41,7 @@ extern "C" void app_main(void) { step0(); set_game_time(30000); - start_timer(); + start_game_timer(); step1(); step2(); step3(); @@ -50,7 +49,7 @@ extern "C" void app_main(void) { step5(); step6(); - stop_timer(); + stop_game_timer(); ESP_LOGI(TAG, "Bomb has been diffused. Counter-Terrorists win."); ESP_ERROR_CHECK_WITHOUT_ABORT(play_raw("/sdcard/diffused.pcm")); diff --git a/main/steps/setup_wires.hpp b/main/steps/setup_wires.hpp index e215431..7cb5a95 100644 --- a/main/steps/setup_wires.hpp +++ b/main/steps/setup_wires.hpp @@ -2,7 +2,7 @@ #define SETUP_WIRES_HPP #include "../drivers/bottom_half.h" -#include "../drivers/char_lcd.hpp" +#include "../drivers/char_lcd.h" #include "wires_puzzle.h" #include diff --git a/main/steps/step0.hpp b/main/steps/step0.hpp index 8ac1e9d..c64fee8 100644 --- a/main/steps/step0.hpp +++ b/main/steps/step0.hpp @@ -2,7 +2,7 @@ #define STEP_0_HPP #include "../drivers/bottom_half.h" -#include "../drivers/char_lcd.hpp" +#include "../drivers/char_lcd.h" #include "../drivers/wires.h" #include "setup_wires.hpp"