/**
 *******************************************************************************
 * @file    dpm32m0xx_eval.c
 *
 * @brief   definitions for DPM32M08x_EVAL's leds, keys and COM ports hardware resources.
 *
 * @author  DPM
 *
 * @version V1.0.0, firmware update for DPM32M08x
 *
 * @date    2024-05-16
 *******************************************************************************/

/*
    Copyright (c) 2024, DP Microelectronics Inc.

    Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice, this
       list of conditions and the following disclaimer.
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
    3. Neither the name of the copyright holder nor the names of its contributors
       may be used to endorse or promote products derived from this software without
       specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/

#ifndef __DPM32M0XX_EVAL_H
#define __DPM32M0XX_EVAL_H

#ifdef __cplusplus
extern "C" {
#endif

#include "dpm32m0xx.h"
#include "dpm32m0xx_flash.h"
#include "dpm32m0xx_gpio.h"
#include "dpm32m0xx_rcc.h"
#include "dpm32m0xx_uart.h"

/* exported types */
typedef enum
{
  LED1 = 0,
  LED2 = 1,
  LED3 = 2,
  LED4 = 3
} EVAL_LedEnum;

typedef enum
{
  KEY_UP = 0,
  KEY1 = 1,
  KEY2 = 2,
  KEY3 = 3,
} EVAL_KeyEnum;

typedef enum
{
  KEY_MODE_GPIO = 0,
  KEY_MODE_IRQ  = 1
} EVAL_KeyModeEnum;

/* define for DPM32M08x eval board */
#if defined(DPM32M08x)

/* DPM32M08x eval low layer led */
#define LEDn                             4

#define LED1_PIN                         GPIO_PIN_10
#define LED1_GPIO_PORT                   GPIOC

#define LED2_PIN                         GPIO_PIN_11
#define LED2_GPIO_PORT                   GPIOC

#define LED3_PIN                         GPIO_PIN_12
#define LED3_GPIO_PORT                   GPIOC

#define LED4_PIN                         GPIO_PIN_13
#define LED4_GPIO_PORT                   GPIOC

/* DPM32M08x eval low layer button */
#define KEYn                             4

/* tamper push-button */
#define KEY_UP_PIN                       GPIO_PIN_2
#define KEY_UP_GPIO_PORT                 GPIOC
#define KEY_UP_PUPD                      GPIO_PUPD_DOWN
#define KEY_UP_GPIO_IRQn                 GPIOC_D_IRQn
#define KEY_UP_IRQ_TYPE                  GPIO_INT_RISING

#define KEY1_PIN                         GPIO_PIN_7
#define KEY1_GPIO_PORT                   GPIOC
#define KEY1_PUPD                        GPIO_PUPD_UP
#define KEY1_GPIO_IRQn                   GPIOC_D_IRQn
#define KEY1_IRQ_TYPE                    GPIO_INT_FALLING

#define KEY2_PIN                         GPIO_PIN_8
#define KEY2_GPIO_PORT                   GPIOC
#define KEY2_PUPD                        GPIO_PUPD_UP
#define KEY2_GPIO_IRQn                   GPIOC_D_IRQn
#define KEY2_IRQ_TYPE                    GPIO_INT_FALLING

#define KEY3_PIN                         GPIO_PIN_9
#define KEY3_GPIO_PORT                   GPIOC
#define KEY3_PUPD                        GPIO_PUPD_UP
#define KEY3_GPIO_IRQn                   GPIOC_D_IRQn
#define KEY3_IRQ_TYPE                    GPIO_INT_FALLING



/* DPM32M08x eval low layer COM */
#define COMn                             1

/* definition for COM 0, connected to UART0 */
#define EVAL_COM0                        UART0

#define EVAL_COM0_CLK                    RCC_APB_PERIPH_UART0

#define EVAL_COM0_TX_PIN                 GPIO_PIN_9
#define EVAL_COM0_RX_PIN                 GPIO_PIN_10

#define EVAL_COM_GPIO_PORT               GPIOA
#define EVAL_COM_AF                      GPIO_ALT_FUNC_1

#else
#error "Please define DPM32M08x"
#endif

/* function declarations */
void EVAL_LedInit(EVAL_LedEnum lednum);
void EVAL_LedOn(EVAL_LedEnum lednum);
void EVAL_LedOff(EVAL_LedEnum lednum);
void EVAL_LedToggle(EVAL_LedEnum lednum);

void EVAL_KeyInit(EVAL_KeyEnum keynum, EVAL_KeyModeEnum key_mode);
uint8_t EVAL_KeyStateGet(EVAL_KeyEnum keynum);

void EVAL_ComInit(void);

#ifdef __cplusplus
}

#endif

#endif /* DPM32M0XX_EVAL_H */
