/***********************************************************************************************************************
 * This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file
 * will be overwritten if the respective MCUXpresso Config Tools is used to update this file.
 **********************************************************************************************************************/

/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
!!GlobalInfo
product: Peripherals v9.0
processor: MIMXRT1052xxxxB
package_id: MIMXRT1052DVL6B
mcu_data: ksdk2_0
processor_version: 9.0.0
board: IMXRT1050-EVKB
functionalGroups:
- name: BOARD_InitPeripherals
  UUID: c02f2a7b-0e89-43b6-9488-2b4f58340ab8
  called_from_default_init: true
  selectedCore: core0
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/

/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
component:
- type: 'system'
- type_id: 'system_54b53072540eeeb8f8e9343e71f28176'
- global_system_definitions:
  - user_definitions: ''
  - user_includes: ''
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */

/***********************************************************************************************************************
 * Included files
 **********************************************************************************************************************/
#include "peripherals.h"

/***********************************************************************************************************************
 * BOARD_InitPeripherals functional group
 **********************************************************************************************************************/
/***********************************************************************************************************************
 * LPUART1 initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'LPUART1'
- type: 'lpuart'
- mode: 'polling'
- custom_name_enabled: 'false'
- type_id: 'lpuart_54a65a580e3462acdbacefd5299e0cac'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'LPUART1'
- config_sets:
  - lpuartConfig_t:
    - lpuartConfig:
      - clockSource: 'LpuartClock'
      - lpuartSrcClkFreq: 'BOARD_BootClockRUN'
      - baudRate_Bps: '921600'
      - parityMode: 'kLPUART_ParityDisabled'
      - dataBitsCount: 'kLPUART_EightDataBits'
      - isMsb: 'false'
      - stopBitCount: 'kLPUART_OneStopBit'
      - txFifoWatermark: '0'
      - rxFifoWatermark: '1'
      - enableRxRTS: 'false'
      - enableTxCTS: 'false'
      - txCtsSource: 'kLPUART_CtsSourcePin'
      - txCtsConfig: 'kLPUART_CtsSampleAtStart'
      - rxIdleType: 'kLPUART_IdleTypeStartBit'
      - rxIdleConfig: 'kLPUART_IdleCharacter1'
      - enableTx: 'true'
      - enableRx: 'true'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
const lpuart_config_t LPUART1_config = {
  .baudRate_Bps = 921600UL,
  .parityMode = kLPUART_ParityDisabled,
  .dataBitsCount = kLPUART_EightDataBits,
  .isMsb = false,
  .stopBitCount = kLPUART_OneStopBit,
  .txFifoWatermark = 0U,
  .rxFifoWatermark = 1U,
  .enableRxRTS = false,
  .enableTxCTS = false,
  .txCtsSource = kLPUART_CtsSourcePin,
  .txCtsConfig = kLPUART_CtsSampleAtStart,
  .rxIdleType = kLPUART_IdleTypeStartBit,
  .rxIdleConfig = kLPUART_IdleCharacter1,
  .enableTx = true,
  .enableRx = true
};

static void LPUART1_init(void) {
  LPUART_Init(LPUART1_PERIPHERAL, &LPUART1_config, LPUART1_CLOCK_SOURCE);
}

/***********************************************************************************************************************
 * SEMC initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'SEMC'
- type: 'semc'
- mode: 'general'
- custom_name_enabled: 'false'
- type_id: 'semc_84a769c198c91c527e11dcec2f5b4b81'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'SEMC'
- config_sets:
  - fsl_semc:
    - enableDCD: 'false'
    - clockConfig:
      - clockSource: 'kSEMC_ClkSrcPeri'
      - clockSourceFreq: 'BOARD_BootClockRUN'
    - semc_config_t:
      - dqsMode: 'kSEMC_Loopbackdqspad'
      - cmdTimeoutCycles: '0'
      - busTimeoutCycles: '0'
      - queueWeight:
        - queueaEnable: 'false'
        - queueaWeight:
          - structORvalue: 'structure'
          - queueaConfig:
            - qos: '0'
            - aging: '0'
            - slaveHitSwith: '0'
            - slaveHitNoswitch: '0'
        - queuebEnable: 'false'
        - queuebWeight:
          - structORvalue: 'structure'
          - queuebConfig:
            - qos: '0'
            - aging: '0'
            - slaveHitSwith: '0'
            - weightPagehit: '0'
            - bankRotation: '0'
    - semc_sdram_config_t:
      - csxPinMux: 'kSEMC_MUXCSX0'
      - semcSdramCs: 'kSEMC_SDRAM_CS0'
      - address: '0x80000000'
      - memsize_input: '32MB'
      - portSize: 'kSEMC_PortSize16Bit'
      - burstLen: 'kSEMC_Sdram_BurstLen1'
      - columnAddrBitNum: 'kSEMC_SdramColunm_9bit'
      - casLatency: 'kSEMC_LatencyThree'
      - tPrecharge2Act_Ns: '18'
      - tAct2ReadWrite_Ns: '18'
      - tRefreshRecovery_Ns: '127'
      - tWriteRecovery_Ns: '12'
      - tCkeOff_Ns: '42'
      - tAct2Prechage_Ns: '42'
      - tSelfRefRecovery_Ns: '67'
      - tRefresh2Refresh_Ns: '60'
      - tAct2Act_Ns: '60'
      - tPrescalePeriod_Ns: '160'
      - tIdleTimeout_Ns: '0'
      - refreshPeriod_nsPerRow: '64'
      - refreshUrgThreshold: '64'
      - refreshBurstLen: '1'
    - sdramArray: []
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
semc_config_t SEMC_config = {
  .dqsMode = kSEMC_Loopbackdqspad,
  .cmdTimeoutCycles = 0U,
  .busTimeoutCycles = 0U,
  .queueWeight = {
    .queueaEnable = false,
    .queueaWeight = {
      .queueaConfig = {
        .qos = 0UL,
        .aging = 0UL,
        .slaveHitSwith = 0UL,
        .slaveHitNoswitch = 0UL
      },
    },
    .queuebEnable = false,
    .queuebWeight = {
      .queuebConfig = {
        .qos = 0UL,
        .aging = 0UL,
        .slaveHitSwith = 0UL,
        .weightPagehit = 0UL,
        .bankRotation = 0UL
      },
    }
  }
};
semc_sdram_config_t SEMC_sdram_struct = {
  .csxPinMux = kSEMC_MUXCSX0,
  .address = 0x80000000UL,
  .memsize_kbytes = 32768,
  .portSize = kSEMC_PortSize16Bit,
  .burstLen = kSEMC_Sdram_BurstLen1,
  .columnAddrBitNum = kSEMC_SdramColunm_9bit,
  .casLatency = kSEMC_LatencyThree,
  .tPrecharge2Act_Ns = 18U,
  .tAct2ReadWrite_Ns = 18U,
  .tRefreshRecovery_Ns = 127U,
  .tWriteRecovery_Ns = 12U,
  .tCkeOff_Ns = 42U,
  .tAct2Prechage_Ns = 42U,
  .tSelfRefRecovery_Ns = 67U,
  .tRefresh2Refresh_Ns = 60U,
  .tAct2Act_Ns = 60U,
  .tPrescalePeriod_Ns = 160UL,
  .tIdleTimeout_Ns = 0UL,
  .refreshPeriod_nsPerRow = 64UL,
  .refreshUrgThreshold = 64UL,
  .refreshBurstLen = 1U,
};

static void SEMC_init(void) {
  /* Initialize SEMC peripheral. */
  SEMC_Init(SEMC_PERIPHERAL, &SEMC_config);
  /* Initialize SEMC SDRAM. */
  SEMC_ConfigureSDRAM(SEMC_PERIPHERAL, kSEMC_SDRAM_CS0, &SEMC_sdram_struct, 150000000);
}

/***********************************************************************************************************************
 * LCDIF initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'LCDIF'
- type: 'elcdif'
- mode: 'rgbMode'
- custom_name_enabled: 'false'
- type_id: 'elcdif_1c39bcb43ed1a24bc8980672c7378576'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'LCDIF'
- config_sets:
  - fsl_elcdif:
    - config:
      - panelWidthInt: '800'
      - panelHeightInt: '480'
      - hsw: '20'
      - hfp: '210'
      - hbp: '46'
      - vsw: '10'
      - vfp: '22'
      - vbp: '23'
      - frameRate: '60 Hz'
      - polarityFlags_st:
        - vSyncActive: 'kELCDIF_VsyncActiveLow'
        - hSyncActive: 'kELCDIF_HsyncActiveLow'
        - dataEnableActive: 'kELCDIF_DataEnableActiveHigh'
        - driveDataClkEdge: 'kELCDIF_DriveDataOnRisingClkEdge'
      - bufferName: 'defaultBuffer'
      - bufferAlign: '64'
      - pixelFormat: 'kELCDIF_PixelFormatRGB565'
      - dataBus: 'kELCDIF_DataBus16Bit'
      - enablePxpHandShake: 'false'
      - start: 'true'
    - isInterruptEnabled: 'true'
    - elcdifInterruptSources: 'kELCDIF_CurFrameDoneInterruptEnable'
    - interrupt:
      - IRQn: 'LCDIF_IRQn'
      - enable_interrrupt: 'enabled'
      - enable_priority: 'true'
      - priority: '5'
      - enable_custom_name: 'false'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
/* RGB mode configuration */
const elcdif_rgb_mode_config_t LCDIF_rgbConfig = {
  .panelWidth = LCDIF_PANEL_WIDTH,
  .panelHeight = LCDIF_PANEL_HEIGHT,
  .hsw = 20U,
  .hfp = 210U,
  .hbp = 46U,
  .vsw = 10U,
  .vfp = 22U,
  .vbp = 23U,
  .polarityFlags = (kELCDIF_VsyncActiveLow | kELCDIF_HsyncActiveLow | kELCDIF_DataEnableActiveHigh | kELCDIF_DriveDataOnRisingClkEdge),
  .bufferAddr = (uint32_t) LCDIF_Buffer[0],
  .pixelFormat = kELCDIF_PixelFormatRGB565,
  .dataBus = kELCDIF_DataBus16Bit
};
/* RGB buffer */
AT_NONCACHEABLE_SECTION_ALIGN(uint16_t LCDIF_Buffer[2][LCDIF_PANEL_HEIGHT][LCDIF_PANEL_WIDTH], LCDIF_RGB_BUFFER_ALIGN);

static void LCDIF_init(void) {
  /* RGB mode initialization */
  ELCDIF_RgbModeInit(LCDIF_PERIPHERAL, &LCDIF_rgbConfig);
  /* Enable interrupts */
  ELCDIF_EnableInterrupts(LCDIF_PERIPHERAL, (kELCDIF_CurFrameDoneInterruptEnable));
  /* Interrupt vector LCDIF_IRQn priority settings in the NVIC. */
  NVIC_SetPriority(LCDIF_LCDIF_IRQN, LCDIF_LCDIF_IRQ_PRIORITY);
  /* Enable interrupt LCDIF_IRQn request in the NVIC. */
  EnableIRQ(LCDIF_LCDIF_IRQN);
  /* RGB mode start */
  ELCDIF_RgbModeStart(LCDIF_PERIPHERAL);
}

/***********************************************************************************************************************
 * FATFS initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'FATFS'
- type: 'fatfs'
- mode: 'general'
- custom_name_enabled: 'false'
- type_id: 'fatfs_2f85acf758668258920f70258052a088'
- functional_group: 'BOARD_InitPeripherals'
- config_sets:
  - init_config:
    - initConfig:
      - initPartitionsStr: 'false'
      - multiplePartitions:
        - 0:
          - Volume: '0'
          - Partition: 'autoDetect'
        - 1:
          - Volume: '0'
          - Partition: 'autoDetect'
      - enablePhysicalLayerInit: 'false'
      - diskConfig:
        - initFunctionID: 'FATFS_DiskInit'
      - initResultObject: 'false'
      - resultName: 'FATFS_Result'
      - fatfsObjects:
        - 0:
          - objID: 'FATFS_System_0'
          - diskMount: 'false'
          - mountPath: '0:'
          - mountInitOpt: 'false'
      - filObjects: []
      - filInfoObjects: []
      - dirObjects: []
  - ff_config:
    - revisionID: 'rev14_1'
    - MSDKadaptation: 'SD_DISK_ENABLE'
    - functionConfig:
      - FF_FS_READONLY: 'false'
      - FF_FS_MINIMIZE: 'level1'
      - FF_USE_STRFUNC: 'enableWithoutConversion'
      - FF_USE_FIND: 'disableDirRead'
      - FF_USE_MKFS: 'true'
      - FF_USE_FASTSEEK: 'false'
      - FF_USE_EXPAND: 'false'
      - FF_USE_CHMOD: 'false'
      - FF_USE_LABEL: 'false'
      - FF_USE_FORWARD: 'false'
    - namespaceConfig:
      - FF_USE_LFN: 'enableLfnStack'
      - FF_MAX_LFN: '255'
      - FF_LFN_BUF: 'LFNID'
      - FF_SFN_BUF: 'SFNID'
      - FF_LFN_UNICODE: 'ansiOEM'
      - FF_STRF_ENCODE: 'ansiOEM'
      - FF_CODE_PAGE: 'cpJapanese'
      - FF_FS_RPATH: 'enableRP2'
    - driveConfig:
      - FF_VOLUMES: '6'
      - FF_STR_VOLUME_ID: 'numericId'
      - volumes:
        - 0:
          - volumeStr: 'RAM'
        - 1:
          - volumeStr: 'NAND'
        - 2:
          - volumeStr: 'CF'
        - 3:
          - volumeStr: 'SD'
        - 4:
          - volumeStr: 'SD2'
        - 5:
          - volumeStr: 'USB'
      - FF_MULTI_PARTITION: 'false'
      - FF_MIN_SS: 'value512'
      - FF_MAX_SS: 'value512'
      - FF_LBA64: 'false'
      - FF_MIN_GPT: '0x100000000'
      - FF_USE_TRIM: 'false'
    - systemConfig:
      - FF_FS_TINY: 'false'
      - FF_FS_EXFAT: 'false'
      - FF_FS_NORTC: 'false'
      - FF_NORTC_MON: '1'
      - FF_NORTC_MDAY: '1'
      - FF_NORTC_YEAR: '2020'
      - FF_FS_NOFSINFO: ''
      - FF_FS_LOCK: '0'
      - FF_FS_REENTRANT: 'false'
      - FF_FS_TIMEOUT: '1000'
      - FF_SYNC_t: 'HANDLE'
      - includeOS: 'false'
      - headerFileName: 'somertos.h'
    - fatfs_codegenerator: []
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
/* FATFS System object */
FATFS FATFS_System_0;

/* Empty initialization function (commented out)
static void FATFS_init(void) {
} */

/***********************************************************************************************************************
 * Initialization functions
 **********************************************************************************************************************/
void BOARD_InitPeripherals(void)
{
  /* Initialize components */
  LPUART1_init();
  SEMC_init();
  LCDIF_init();
}

/***********************************************************************************************************************
 * BOARD_InitBootPeripherals function
 **********************************************************************************************************************/
void BOARD_InitBootPeripherals(void)
{
  BOARD_InitPeripherals();
}
