#include "nvs.h"
#include "nvs_flash.h"

#include "H2201_dispatcher.h"
#include "H2201_i2c.h"
#include "H2201_i2s.h"
#include "H2201_bluetooth.h"
#include "H2201_buttons.h"

#define H2201_MAIN_TAG "H2201_MAIN"

void app_main(void)
{
    /* Initialize NVS — it is used to store PHY calibration data */
    esp_err_t err = nvs_flash_init();
    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
    {
        ESP_ERROR_CHECK(nvs_flash_erase());
        err = nvs_flash_init();
    }
    ESP_ERROR_CHECK(err);

    H2201_dispacther_init();

    h2201_i2s_init();

    h2201_bluetooth_init();    

    H2201_i2c_master_init();
    H2201_i2c_adau1761_init();

    H2201_shiftregister_init();
    H2201_buttons_init();
    H2201_encoder_init();
}