/*
 * Copyright (c) 2021, Erich Styger
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "platform.h"
#include "esp_err.h"
#if PL_CONFIG_USE_BLINKY
  #include "led.h"
#endif
#if PL_CONFIG_USE_WIFI
  #include "wifi.h"
  #include "nvs_flash.h"
#endif
#if PL_CONFIG_USE_UDP_CLIENT
  #include "udp_client.h"
#endif
#if PL_CONFIG_USE_UDP_SERVER
  #include "udp_server.h"
#endif
#if PL_CONFIG_USE_SHELL
  #include "Shell.h"
#endif
#if PL_CONFIG_USE_I2C
  #include "i2c.h"
#endif
#if PL_CONFIG_USE_NVMC
  #include "nvmc.h"
#endif
#if PL_CONFIG_USE_PING
  #include "ping_shell.h"
#endif
#if PL_CONFIG_USE_SNTP_TIME
  #include "sntp_time.h"
#endif
#if PL_CONFIG_USE_TIME_DATE
  #include "McuTimeDate.h"
  #include "timer.h"
#endif
#if PL_CONFIG_USE_ROBO_REMOTE
  #include "robot.h"
#endif
#include "McuLib.h"
#include "McuGPIO.h"
#include "McuLED.h"
#include "McuUtility.h"
#include "McuWait.h"
#include "McuShell.h"
#include "McuRTOS.h"
#include "McuXFormat.h"
#include "McuLog.h"
#include "McuCriticalSection.h"
#include "esp32_mac.h"
#include "rs485.h"
#if PL_CONFIG_CHALLENGE_APP_ACTIVATED
	#include "challenge_app.h"
#endif

void PL_Init(void) {
  McuLib_Init();
  McuLog_Init();
  McuWait_Init();
  McuRTOS_Init();
  McuUtility_Init();
  McuGPIO_Init();
  McuLED_Init();
#if PL_CONFIG_USE_TIME_DATE
  McuTimeDate_Init();
  TMR_Init();
#endif

#if PL_CONFIG_USE_BLINKY
  LED_Init();
#endif
#if PL_CONFIG_USE_WIFI
  ESP_ERROR_CHECK(nvs_flash_init()); /* need to call this before using any WiFi functions */
  ESP32_MacInit();
  WiFi_Init();
#endif
#if PL_CONFIG_USE_UDP_SERVER
  UDP_Server_Init();
#endif
#if PL_CONFIG_USE_UDP_CLIENT
  UDP_Client_Init();
#endif
#if PL_CONFIG_USE_SHELL
  McuXFormat_Init();
  McuShell_Init();
  SHELL_Init();
#endif
#if PL_CONFIG_USE_I2C
  I2C_Init();
#endif
#if PL_CONFIG_USE_NVMC
  NVMC_Init();
#endif
#if PL_CONFIG_USE_RS485
  RS485_Init();
#endif
#if PL_CONFIG_USE_PING
  PING_Init();
#endif
#if PL_CONFIG_USE_SNTP_TIME
  SNTP_Init();
#endif
#if PL_CONFIG_USE_ROBO_REMOTE
  ROBOT_Init();
#endif
#if PL_CONFIG_CHALLENGE_APP_ACTIVATED
  Challenge_App_Init();
#endif
}
