small tweaks to drivers, starting speaker refactor
This commit is contained in:
parent
ab7148be42
commit
42aa5fa315
@ -1,5 +1,6 @@
|
||||
#include "all.h"
|
||||
|
||||
static const char *TAG = "driver_all";
|
||||
static void init_i2c();
|
||||
|
||||
void init_drivers() {
|
||||
@ -9,6 +10,8 @@ void init_drivers() {
|
||||
// init the bottom half so that we can get user input.
|
||||
init_bottom_half();
|
||||
init_sd();
|
||||
init_speaker();
|
||||
|
||||
}
|
||||
|
||||
/// @brief Initializes I2C_NUM_0.
|
||||
@ -21,6 +24,8 @@ void init_drivers() {
|
||||
/// - The PERH port
|
||||
/// - The Capacitive Touch Panel
|
||||
static void init_i2c() {
|
||||
ESP_LOGI(TAG, "Initializing i2c...");
|
||||
|
||||
i2c_config_t conf = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = GPIO_NUM_5,
|
||||
@ -37,4 +42,6 @@ static void init_i2c() {
|
||||
|
||||
ESP_ERROR_CHECK(i2c_param_config(I2C_NUM_0, &conf));
|
||||
ESP_ERROR_CHECK(i2c_driver_install(I2C_NUM_0, conf.mode, 0, 0, 0));
|
||||
|
||||
ESP_LOGI(TAG, "i2c initialized!");
|
||||
}
|
||||
@ -36,6 +36,8 @@ static void receive_touch();
|
||||
// }
|
||||
|
||||
void init_bottom_half() {
|
||||
ESP_LOGI(TAG, "Initializing bottom half...");
|
||||
|
||||
ESP_ERROR_CHECK(gpio_set_direction(BOTTOM_PIN_INTERUPT, GPIO_MODE_INPUT));
|
||||
ESP_ERROR_CHECK(gpio_set_pull_mode(BOTTOM_PIN_INTERUPT, GPIO_PULLUP_ONLY));
|
||||
|
||||
@ -52,6 +54,8 @@ void init_bottom_half() {
|
||||
receive_touch();
|
||||
|
||||
xTaskCreate(poll_bottom_task, "poll_bottom", 4096, NULL, 10, NULL);
|
||||
|
||||
ESP_LOGI(TAG, "Bottom half initialized!");
|
||||
}
|
||||
|
||||
static uint8_t receive_delta(void) {
|
||||
|
||||
@ -8,7 +8,7 @@ i2c_lcd_pcf8574_handle_t lcd;
|
||||
static const char *TAG = "char_lcd";
|
||||
|
||||
void init_lcd() {
|
||||
ESP_LOGI(TAG, "Initializing LCD");
|
||||
ESP_LOGI(TAG, "Initializing LCD...");
|
||||
|
||||
lcd_init(&lcd, LCD_ADDR, CHAR_LCD_I2C_NUM);
|
||||
lcd_begin(&lcd, LCD_COLS, LCD_ROWS);
|
||||
|
||||
@ -8,7 +8,7 @@ static const char* mount_point = MOUNT_POINT;
|
||||
static const char* TAG = "sd";
|
||||
|
||||
bool init_sd() {
|
||||
ESP_LOGI(TAG, "Initializing SD card");
|
||||
ESP_LOGI(TAG, "Initializing SD card...");
|
||||
|
||||
esp_err_t ret;
|
||||
|
||||
@ -40,6 +40,8 @@ bool init_sd() {
|
||||
.flags = 0
|
||||
// .flags = SDMMC_SLOT_FLAG_INTERNAL_PULLUP
|
||||
};
|
||||
|
||||
try_mount:
|
||||
ESP_LOGI(TAG, "Mounting filesystem");
|
||||
ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, &mount_config, &card);
|
||||
|
||||
@ -48,16 +50,28 @@ bool init_sd() {
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to mount sd card: %s.", esp_err_to_name(ret));
|
||||
|
||||
lcd_print(0, 0, "SD Mount Failed!");
|
||||
lcd_print(0, 1, esp_err_to_name(ret));
|
||||
lcd_print(0, 2, "Press Green to retry");
|
||||
lcd_print(0, 0, "SD: ");
|
||||
lcd_print(4, 0, esp_err_to_name(ret));
|
||||
lcd_print(0, 1, "Press Green to retry");
|
||||
lcd_print(0, 2, "Press Yellow to skip");
|
||||
lcd_print(0, 3, "Press Red to format");
|
||||
|
||||
ButtonKey button;
|
||||
while (!( ))
|
||||
while (!( get_button_pressed(&button) && (button == ButtonKey::button_green || button == ButtonKey::button_red || button == ButtonKey::button_yellow) )) vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
lcd_clear();
|
||||
|
||||
if (button == ButtonKey::button_green) {
|
||||
goto try_mount;
|
||||
}
|
||||
if (button == ButtonKey::button_yellow) {
|
||||
return false;
|
||||
}
|
||||
if (button == ButtonKey::button_red) {
|
||||
mount_config.format_if_mount_failed = true;
|
||||
goto try_mount;
|
||||
}
|
||||
}
|
||||
|
||||
// Card has been initialized, print its properties
|
||||
sdmmc_card_print_info(stdout, card);
|
||||
|
||||
@ -2,12 +2,11 @@
|
||||
|
||||
i2s_chan_handle_t tx_chan;
|
||||
|
||||
static const char *TAG = "speaker_driver";
|
||||
static const char *TAG = "speaker";
|
||||
|
||||
esp_err_t play_raw_stop_queue(const char *fp, QueueHandle_t stop_handle) {
|
||||
FILE *fh = fopen(fp, "rb");
|
||||
if (fh == NULL)
|
||||
{
|
||||
if (fh == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to open file");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
@ -61,7 +60,6 @@ esp_err_t play_raw_stop_queue(const char *fp, QueueHandle_t stop_handle) {
|
||||
esp_err_t play_raw(const char *fp) {
|
||||
FILE *fh = fopen(fp, "rb");
|
||||
if (fh == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to open file");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
@ -109,6 +107,8 @@ esp_err_t play_raw(const char *fp) {
|
||||
}
|
||||
|
||||
void init_speaker(void) {
|
||||
ESP_LOGI(TAG, "Initializing speaker...");
|
||||
|
||||
i2s_chan_config_t tx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);
|
||||
ESP_ERROR_CHECK(i2s_new_channel(&tx_chan_cfg, &tx_chan, NULL));
|
||||
|
||||
@ -129,6 +129,8 @@ void init_speaker(void) {
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_chan, &tx_std_cfg));
|
||||
|
||||
ESP_LOGI(TAG, "Speaker initialized!");
|
||||
}
|
||||
|
||||
void play_example() {
|
||||
|
||||
@ -25,13 +25,10 @@ extern "C" void app_main(void) {
|
||||
|
||||
init_drivers();
|
||||
init_tft();
|
||||
init_speaker();
|
||||
init_sseg();
|
||||
init_game_module_timer();
|
||||
init_leds();
|
||||
init_wires();
|
||||
init_bottom_half();
|
||||
|
||||
init_power_board();
|
||||
|
||||
clean_bomb();
|
||||
|
||||
@ -42,7 +42,7 @@ void setup_wires(void) {
|
||||
ButtonKey button;
|
||||
|
||||
while (1) {
|
||||
while (get_pressed_keypad(&key)) {
|
||||
while (get_keypad_pressed(&key)) {
|
||||
if (key == KeypadKey::k1) {
|
||||
generate_new_wires(wires);
|
||||
save_wires_to_sd_card(wires);
|
||||
@ -53,7 +53,7 @@ void setup_wires(void) {
|
||||
}
|
||||
}
|
||||
|
||||
while (get_pressed_button(&button)) {
|
||||
while (get_button_pressed(&button)) {
|
||||
if (button == ButtonKey::b1) {
|
||||
// left
|
||||
editing_idx = editing_idx - 1;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user