/***********************************************************************************************************************
 * 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.1
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);
}

/***********************************************************************************************************************
 * NVIC initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'NVIC'
- type: 'nvic'
- mode: 'general'
- custom_name_enabled: 'false'
- type_id: 'nvic_57b5eef3774cc60acaede6f5b8bddc67'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'NVIC'
- config_sets:
  - nvic:
    - interrupt_table:
      - 0: []
      - 1: []
      - 2: []
    - interrupts: []
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */

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

/***********************************************************************************************************************
 * GPIO1 initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'GPIO1'
- type: 'igpio'
- mode: 'GPIO'
- custom_name_enabled: 'false'
- type_id: 'igpio_b1c1fa279aa7069dca167502b8589cb7'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'GPIO1'
- config_sets:
  - fsl_gpio:
    - enable_irq_comb_0_15: 'true'
    - gpio_interrupt_comb_0_15:
      - IRQn: 'GPIO1_Combined_0_15_IRQn'
      - enable_interrrupt: 'enabled'
      - enable_priority: 'true'
      - priority: '6'
      - enable_custom_name: 'false'
    - enable_irq_comb_16_31: 'true'
    - gpio_interrupt_comb_16_31:
      - IRQn: 'GPIO1_Combined_16_31_IRQn'
      - enable_interrrupt: 'noInit'
      - enable_priority: 'false'
      - priority: '0'
      - enable_custom_name: 'false'
    - enable_irq_int0: 'false'
    - gpio_interrupt_int0:
      - IRQn: 'GPIO1_INT0_IRQn'
      - enable_interrrupt: 'enabled'
      - enable_priority: 'false'
      - priority: '0'
      - enable_custom_name: 'false'
    - enable_irq_int1: 'false'
    - gpio_interrupt_int1:
      - IRQn: 'GPIO1_INT1_IRQn'
      - enable_interrrupt: 'enabled'
      - enable_priority: 'false'
      - priority: '0'
      - enable_custom_name: 'false'
    - enable_irq_int2: 'false'
    - gpio_interrupt_int2:
      - IRQn: 'GPIO1_INT2_IRQn'
      - enable_interrrupt: 'enabled'
      - enable_priority: 'false'
      - priority: '0'
      - enable_custom_name: 'false'
    - enable_irq_int3: 'false'
    - gpio_interrupt_int3:
      - IRQn: 'GPIO1_INT3_IRQn'
      - enable_interrrupt: 'enabled'
      - enable_priority: 'false'
      - priority: '0'
      - enable_custom_name: 'false'
    - enable_irq_int4: 'false'
    - gpio_interrupt_int4:
      - IRQn: 'GPIO1_INT4_IRQn'
      - enable_interrrupt: 'enabled'
      - enable_priority: 'false'
      - priority: '0'
      - enable_custom_name: 'false'
    - enable_irq_int5: 'false'
    - gpio_interrupt_int5:
      - IRQn: 'GPIO1_INT5_IRQn'
      - enable_interrrupt: 'enabled'
      - enable_priority: 'false'
      - priority: '0'
      - enable_custom_name: 'false'
    - enable_irq_int6: 'false'
    - gpio_interrupt_int6:
      - IRQn: 'GPIO1_INT6_IRQn'
      - enable_interrrupt: 'enabled'
      - enable_priority: 'false'
      - priority: '0'
      - enable_custom_name: 'false'
    - enable_irq_int7: 'false'
    - gpio_interrupt_int7:
      - IRQn: 'GPIO1_INT7_IRQn'
      - enable_interrrupt: 'enabled'
      - enable_priority: 'false'
      - priority: '0'
      - enable_custom_name: 'false'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */

static void GPIO1_init(void) {
  /* Make sure, the clock gate for GPIO1 is enabled (e. g. in pin_mux.c) */
  /* Interrupt vector GPIO1_Combined_0_15_IRQn priority settings in the NVIC. */
  NVIC_SetPriority(GPIO1_GPIO_COMB_0_15_IRQN, GPIO1_GPIO_COMB_0_15_IRQ_PRIORITY);
  /* Enable interrupt GPIO1_Combined_0_15_IRQn request in the NVIC. */
  EnableIRQ(GPIO1_GPIO_COMB_0_15_IRQN);
  /* Interrupt GPIO1_Combined_16_31_IRQn request in the NVIC is not initialized (disabled by default). */
  /* It can be enabled later by EnableIRQ(GPIO1_GPIO_COMB_16_31_IRQN);  function call. */
}

/***********************************************************************************************************************
 * 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: 'UTF8'
      - FF_STRF_ENCODE: 'UTF8'
      - FF_CODE_PAGE: 'cpUS'
      - FF_FS_RPATH: 'enableRP2'
    - driveConfig:
      - FF_VOLUMES: '1'
      - FF_STR_VOLUME_ID: 'numericId'
      - volumes:
        - 0:
          - volumeStr: 'SD'
      - 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: 'true'
      - FF_NORTC_MON: '1'
      - FF_NORTC_MDAY: '1'
      - FF_NORTC_YEAR: '2021'
      - 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();
  GPIO1_init();
}

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