/***********************************************************************************************************************
 * 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 v6.0
processor: K32L2B31xxxA
package_id: K32L2B31VLH0A
mcu_data: ksdk2_0
processor_version: 0.0.0
board: FRDM-K32L2B
functionalGroups:
- name: BOARD_InitPeripherals
  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: []
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/

/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
component:
- type: 'msg'
- type_id: 'msg_6e2baaf3b97dbeef01c0043275f9a0e7'
- global_messages: []
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */

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

/***********************************************************************************************************************
 * BOARD_InitPeripherals functional group
 **********************************************************************************************************************/
/***********************************************************************************************************************
 * ACCEL initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'ACCEL'
- type: 'i2c'
- mode: 'I2C_Polling'
- type_id: 'i2c_2566d7363e7e9aaedabb432110e372d7'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'I2C0'
- config_sets:
  - fsl_i2c:
    - i2c_mode: 'kI2C_Master'
    - clockSource: 'BusInterfaceClock'
    - clockSourceFreq: 'GetFreq'
    - i2c_master_config:
      - enableMaster: 'true'
      - enableStopHold: 'false'
      - baudRate_Bps: '100000'
      - glitchFilterWidth: '0'
    - quick_selection: 'QS_I2C_1'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
const i2c_master_config_t ACCEL_config = {
    .enableMaster = true, .enableStopHold = false, .baudRate_Bps = 100000, .glitchFilterWidth = 0};

void ACCEL_init(void)
{
    /* Initialization function */
    I2C_MasterInit(ACCEL_PERIPHERAL, &ACCEL_config, ACCEL_CLK_FREQ);
}

/***********************************************************************************************************************
 * DEBUG_UART initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'DEBUG_UART'
- type: 'lpuart'
- mode: 'polling'
- type_id: 'lpuart_bebe3e12b6ec22bbd14199038f2bf459'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'LPUART0'
- config_sets:
  - lpuartConfig_t:
    - lpuartConfig:
      - clockSource: 'LpuartClock'
      - lpuartSrcClkFreq: 'BOARD_BootClockRUN'
      - baudRate_Bps: '115200'
      - parityMode: 'kLPUART_ParityDisabled'
      - dataBitsCount: 'kLPUART_EightDataBits'
      - isMsb: 'false'
      - stopBitCount: 'kLPUART_OneStopBit'
      - rxIdleType: 'kLPUART_IdleTypeStartBit'
      - rxIdleConfig: 'kLPUART_IdleCharacter1'
      - enableTx: 'true'
      - enableRx: 'true'
    - quick_selection: 'QuickSelection1'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
const lpuart_config_t DEBUG_UART_config = {.baudRate_Bps  = 115200,
                                           .parityMode    = kLPUART_ParityDisabled,
                                           .dataBitsCount = kLPUART_EightDataBits,
                                           .isMsb         = false,
                                           .stopBitCount  = kLPUART_OneStopBit,
                                           .rxIdleType    = kLPUART_IdleTypeStartBit,
                                           .rxIdleConfig  = kLPUART_IdleCharacter1,
                                           .enableTx      = true,
                                           .enableRx      = true};

void DEBUG_UART_init(void)
{
    LPUART_Init(DEBUG_UART_PERIPHERAL, &DEBUG_UART_config, DEBUG_UART_CLOCK_SOURCE);
}

/***********************************************************************************************************************
 * FLASH initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'FLASH'
- type: 'spi'
- mode: 'SPI_Polling'
- type_id: 'spi_672b694426b0a10a1d774659ee8f8435'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'SPI0'
- config_sets:
  - fsl_spi:
    - spi_mode: 'kSPI_Master'
    - clockSource: 'BusInterfaceClock'
    - clockSourceFreq: 'GetFreq'
    - spi_master_config:
      - enableMaster: 'true'
      - enableStopInWaitMode: 'false'
      - polarity: 'kSPI_ClockPolarityActiveHigh'
      - phase: 'kSPI_ClockPhaseFirstEdge'
      - direction: 'kSPI_MsbFirst'
      - dataMode: 'kSPI_8BitMode'
      - outputMode: 'kSPI_SlaveSelectAutomaticOutput'
      - pinMode: 'kSPI_PinModeNormal'
      - baudRate_Bps: '500000'
    - quick_selection: 'QS_SPI_1'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
const spi_master_config_t FLASH_config = {.enableMaster         = true,
                                          .enableStopInWaitMode = false,
                                          .polarity             = kSPI_ClockPolarityActiveHigh,
                                          .phase                = kSPI_ClockPhaseFirstEdge,
                                          .direction            = kSPI_MsbFirst,
                                          .dataMode             = kSPI_8BitMode,
                                          .outputMode           = kSPI_SlaveSelectAutomaticOutput,
                                          .pinMode              = kSPI_PinModeNormal,
                                          .baudRate_Bps         = 500000};

void FLASH_init(void)
{
    /* Initialization function */
    SPI_MasterInit(FLASH_PERIPHERAL, &FLASH_config, FLASH_CLK_FREQ);
}

/***********************************************************************************************************************
 * Initialization functions
 **********************************************************************************************************************/
void BOARD_InitPeripherals(void)
{
    /* Initialize components */
    ACCEL_init();
    DEBUG_UART_init();
    FLASH_init();
}

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