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

/* header file is included with -include compiler option */

#define SIM_UIDH       /* FIX: SDK does not define this one, but should be! See https://mcuoneclipse.com/2020/11/30/getting-a-96bit-unique-id-for-each-kinetis-device-using-mcuxpresso-sdk/ */

/* ---------------------------------------------------------------------------------------*/
/* SDK */
#define McuLib_CONFIG_CPU_IS_KINETIS                (1)
#define McuLib_CONFIG_CPU_VARIANT                   McuLib_CONFIG_CPU_VARIANT_NXP_K22FX
#define McuLib_CONFIG_SDK_VERSION_USED              McuLib_CONFIG_SDK_MCUXPRESSO_2_0
/* ---------------------------------------------------------------------------------------*/
/* FreeRTOS */
#define McuLib_CONFIG_SDK_USE_FREERTOS              (1)
#define configUSE_SEGGER_SYSTEM_VIEWER_HOOKS        (1)
#define configUSE_HEAP_SCHEME                       5 /* either 1 (only alloc), 2 (alloc/free), 3 (malloc), 4 (coalesc blocks), 5 (multiple blocks), 6 (newlib) */
#define configTOTAL_HEAP_SIZE                       (54*1024)
#define configUSE_HEAP_SECTION_NAME                 (1)
#define configHEAP_SECTION_NAME_STRING              ".bss.$SRAM_LOWER.FreeRTOS"
/* ---------------------------------------------------------------------------------------*/
/* Shell */
#define McuShell_CONFIG_PROJECT_NAME_STRING         "MK22FX512 SumoV2"
#define McuShell_CONFIG_DEFAULT_SHELL_BUFFER_SIZE   (128)  /* buffer size for parsing, must be able to include multiple commands */
#define McuRTT_CONFIG_RTT_BUFFER_SIZE_UP            (4096)
#define McuShellUart_CONFIG_UART 					          McuShellUart_CONFIG_UART_K22FX512_UART0_A1_A2
#define McuShell_CONFIG_MULTI_CMD_ENABLED           (1)
#define McuShell_CONFIG_MULTI_CMD_SIZE              (96) /* maximum size of a single command in a multi-command string */
#define McuShell_CONFIG_PROMPT_STRING               "ROBO> "
#define McuShell_CONFIG_ECHO_ENABLED                (1)
/* ---------------------------------------------------------------------------------------*/
/* I2C and OLED */
//#define CONFIG_I2C_USE_PORT_B     (1) /* tinyK22: PTB0, PTB1 */
#define CONFIG_I2C_USE_PORT_B     (1) /* Robot: PTB2, PTB3 */
#define CONFIG_I2C_USE_PORT_E     (0) /* PTE0, PTE1 */
#if CONFIG_I2C_USE_PORT_B /* robot */
  #define SCL1_CONFIG_GPIO_NAME     GPIOB
  #define SCL1_CONFIG_PORT_NAME     PORTB
  #define SCL1_CONFIG_PIN_NUMBER    2u

  #define SDA1_CONFIG_GPIO_NAME     GPIOB
  #define SDA1_CONFIG_PORT_NAME     PORTB
  #define SDA1_CONFIG_PIN_NUMBER    3u
#elif 0 /* tinyK22 */
  #define SCL1_CONFIG_GPIO_NAME     GPIOB
  #define SCL1_CONFIG_PORT_NAME     PORTB
  #define SCL1_CONFIG_PIN_NUMBER    0u

  #define SDA1_CONFIG_GPIO_NAME     GPIOB
  #define SDA1_CONFIG_PORT_NAME     PORTB
  #define SDA1_CONFIG_PIN_NUMBER    1u
#elif CONFIG_I2C_USE_PORT_E
  #define SCL1_CONFIG_GPIO_NAME     GPIOE
  #define SCL1_CONFIG_PORT_NAME     PORTE
  #define SCL1_CONFIG_PIN_NUMBER    1u

  #define SDA1_CONFIG_GPIO_NAME     GPIOE
  #define SDA1_CONFIG_PORT_NAME     PORTE
  #define SDA1_CONFIG_PIN_NUMBER    0u
#endif
#define CONFIG_USE_HW_I2C                       (0)
/* ------------------- I2C ---------------------------*/
#define McuGenericI2C_CONFIG_USE_ON_ERROR_EVENT (0)
#define McuGenericI2C_CONFIG_USE_MUTEX          (1 && McuLib_CONFIG_SDK_USE_FREERTOS)

#define McuGenericSWI2C_CONFIG_DO_YIELD (0 && McuLib_CONFIG_SDK_USE_FREERTOS) /* because of Yield in GenericSWI2C */
#define McuGenericSWI2C_CONFIG_DELAY_NS (1250)
/* I2C Pin Muxing */
#define SDA1_CONFIG_DO_PIN_MUXING (1)
#define SCL1_CONFIG_DO_PIN_MUXING (1)

#if USE_HW_I2C
  #define McuGenericI2C_CONFIG_INTERFACE_HEADER_FILE "i2clib.h"
  #define McuGenericI2C_CONFIG_RECV_BLOCK                        I2CLIB_RecvBlock
  #define McuGenericI2C_CONFIG_SEND_BLOCK                        I2CLIB_SendBlock
  #if McuGenericI2C_CONFIG_SUPPORT_STOP_NO_START
  #define McuGenericI2C_CONFIG_SEND_BLOCK_CONTINUE               I2CLIB_SendBlockContinue
  #endif
  #define McuGenericI2C_CONFIG_SEND_STOP                         I2CLIB_SendStop
  #define McuGenericI2C_CONFIG_SELECT_SLAVE                      I2CLIB_SelectSlave
  #define McuGenericI2C_CONFIG_RECV_BLOCK_CUSTOM_AVAILABLE       (0)
  #define McuGenericI2C_CONFIG_RECV_BLOCK_CUSTOM                 I2CLIB_RecvBlockCustom
#endif
/* ---------------------------------------------------------------------------------------*/
/* OLED and GUI */
#if 1 /* type of OLED */
  #define McuSSD1306_CONFIG_SSD1306_DRIVER_TYPE  (1106)
#else
  #define McuSSD1306_CONFIG_SSD1306_DRIVER_TYPE  (1306)
#endif
//#define McuSSD1306_CONFIG_SSD1306_START_COLUMN_OFFSET (0) /* needed for 1.3" Banggood display */
#define McuSSD1306_CONFIG_SSD1306_I2C_DELAY_US   (0)
/* ---------------------------------------------------------------------------------------*/
/* LittlevGL */
#define LV_CONFIG_DISPLAY_WIDTH        (128)
#define LV_CONFIG_DISPLAY_HEIGHT       (64)
#define LV_CONFIG_COLOR_DEPTH          (1)
#define LV_CONFIG_DPI                  (25)
#define LV_USE_THEME_MONO              (1)
/* ---------------------------------------------------------------------------------------*/
/* ESP32 */
#define McuESP32_CONFIG_SHELL_UART                McuShellUart_CONFIG_UART_K22FX512_UART1_E1_E0
#define McuESP32_CONFIG_USE_USB_CDC               (1)
#define McuESP32_CONFIG_VERBOSE_CONTROL_SIGNALS   (1)

/*
 * RF_EN pin: us echo PTA12
 * RF_IO0 pin: us trig PTA5
 */
#define McuESP32_CONFIG_USE_CTRL_PINS   (1)
#define McuESP32_CONFIG_EN_GPIO         GPIOA
#define McuESP32_CONFIG_EN_PORT         PORTA
#define McuESP32_CONFIG_EN_PIN          12
#define McuESP32_CONFIG_RST_GPIO        GPIOA
#define McuESP32_CONFIG_RST_PORT        PORTA
#define McuESP32_CONFIG_RST_PIN         5
/* ---------------------------------------------------------------------------------------*/
/* FXOS8700 accelerometer */
#define McuFXOS8700_CONFIG_I2C_DEVICE_ADDRESS  (0x1D)
/* ---------------------------------------------------------------------------------------*/

