// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//#include <stdio.h>
//#include <stdlib.h>
//#include <unistd.h>
//#include <string.h>
//#include "freertos/FreeRTOS.h"
//#include "freertos/task.h"
#include "nvs.h"
#include "nvs_flash.h"
//#include "esp_system.h"
//#include "esp_log.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_i2c_master_init();
    H2201_i2c_adau1761_init();

    h2201_i2s_init();

    h2201_bluetooth_init();

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