/*
 * Copyright 2022 MindMotion Microelectronics Co., Ltd.
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */


#ifndef __BOARD_INIT_H__
#define __BOARD_INIT_H__

#include <stdio.h>
#include <stdint.h>

#include "hal_common.h"
#include "hal_rcc.h"
#include "hal_uart.h"
#include "hal_qspi.h"

#include "clock_init.h"
#include "pin_init.h"

/* DEBUG UART. */
#define BOARD_DEBUG_UART_PORT        UART1
#define BOARD_DEBUG_UART_BAUDRATE    9600u
#define BOARD_DEBUG_UART_FREQ        CLOCK_APB2_FREQ

/* QSPI. */
#define BOARD_QSPI_PORT                 QSPI
#define BOARD_QSPI_SCK_DIV              4u
#define BOARD_QSPI_RX_DELAY_CYCLES      1u
#define BOARD_QSPI_CS_HIGH_LEVEL_TIME   2u

/* cmd. */
#define BOARD_EXT_FLASH_CMD_BUS_WIDTH   QSPI_BusWidth_1b
#define BOARD_EXT_FLASH_CMD_VALUE       0x6B /* fast read quad. */
#define BOARD_EXT_FLASH_ADDR_BUS_WIDTH  QSPI_BusWidth_1b
#define BOARD_EXT_FLASH_ADDR_WORD_WIDTH QSPI_WordWidth_24b
#define BOARD_EXT_FLASH_DUMMY_CYCLES    8u
#define BOARD_EXT_FLASH_DATA_BUS_WIDTH  QSPI_BusWidth_4b

/* USB. */
#define BOARD_USB_PORT               USB
#define BOARD_USB_IRQn               USB_FS_IRQn
#define BOARD_USB_IRQHandler         USB_FS_IRQHandler
#define BOARD_USB_SOFTHRESHOLD       255u

#define BOARD_USB_VBUS_EN_GPIO_PORT  GPIOC
#define BOARD_USB_VBUS_EN_GPIO_PIN   GPIO_PIN_13

void BOARD_Init(void);
char board_getchar(void);

#endif /* __BOARD_INIT_H__ */
