/* Copyright Statement:
 *
 * This software/firmware and related documentation ("AutoChips Software") are
 * protected under relevant copyright laws. The information contained herein is
 * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
 * the prior written permission of AutoChips inc. and/or its licensors, any
 * reproduction, modification, use or disclosure of AutoChips Software, and
 * information contained herein, in whole or in part, shall be strictly
 * prohibited.
 *
 * AutoChips Inc. (C) 2024. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
 * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
 * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
 * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
 * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
 * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
 * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
 * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
 */
/******************************************************************************
 * @version: V3.1.0  AC7840x  Demo
 ******************************************************************************/

#ifndef _GPIO_H
#define _GPIO_H


#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* ===========================================  Includes  =========================================== */
#include <stdbool.h>
#include <stdint.h>
#include "ac7840x.h"
#include "gpio_drv.h"
#include "port_hw.h"


/* ============================  Define  ============================ */
#define LED3_PORT      (PORTC)
#define LED3_GPIO      (GPIOC)
#define LED3_PIN       (6)
#define LED4_PORT      (PORTC)
#define LED4_GPIO      (GPIOC)
#define LED4_PIN       (7)

#define RGBLED_R_PORT  (PORTD)
#define RGBLED_R_GPIO  (GPIOD)
#define RGBLED_R_PIN   (16)
#define RGBLED_G_PORT  (PORTD)
#define RGBLED_G_GPIO  (GPIOD)
#define RGBLED_G_PIN   (15)
#define RGBLED_B_PORT  (PORTE)
#define RGBLED_B_GPIO  (GPIOE)
#define RGBLED_B_PIN   (9)

#define KEY3_PORT      (PORTA)
#define KEY3_GPIO      (GPIOA)
#define KEY3_PIN       (6)
#define KEY4_PORT      (PORTE)
#define KEY4_GPIO      (GPIOE)
#define KEY4_PIN       (7)

#define LED3_ON        do{GPIO_DRV_WritePin(LED3_GPIO , LED3_PIN, 1);}while(0)
#define LED3_OFF       do{GPIO_DRV_WritePin(LED3_GPIO, LED3_PIN, 0);}while(0)
#define LED3_TOGGLE    do{GPIO_DRV_TogglePins(LED3_GPIO, (1<<LED3_PIN));}while(0)

#define LED4_ON        do{GPIO_DRV_WritePin(LED4_GPIO, LED4_PIN, 1);}while(0)
#define LED4_OFF       do{GPIO_DRV_WritePin(LED4_GPIO, LED4_PIN, 0);}while(0)
#define LED4_TOGGLE    do{GPIO_DRV_TogglePins(LED4_GPIO, (1<<LED4_PIN));}while(0)

#define RGBLED_R_ON           do{GPIO_DRV_WritePin(RGBLED_R_GPIO, RGBLED_R_PIN, 1);}while(0)
#define RGBLED_R_OFF          do{GPIO_DRV_WritePin(RGBLED_R_GPIO, RGBLED_R_PIN, 0);}while(0)
#define RGBLED_G_ON           do{GPIO_DRV_WritePin(RGBLED_G_GPIO, RGBLED_G_PIN, 1);}while(0)
#define RGBLED_G_OFF          do{GPIO_DRV_WritePin(RGBLED_G_GPIO, RGBLED_G_PIN, 0);}while(0)
#define RGBLED_B_ON           do{GPIO_DRV_WritePin(RGBLED_B_GPIO, RGBLED_B_PIN, 1);}while(0)
#define RGBLED_B_OFF          do{GPIO_DRV_WritePin(RGBLED_B_GPIO, RGBLED_B_PIN, 0);}while(0)

#define GET_K3_STS()   (GPIO_DRV_ReadPins(KEY3_GPIO)& (1<<KEY3_PIN))
#define GET_K4_STS()   (GPIO_DRV_ReadPins(KEY4_GPIO)& (1<<KEY4_PIN))



/* ===========================================  Typedef  ============================================ */

/* ==========================================  Variables  =========================================== */
extern void GPIO_LedInit(void);            /* LED 初始化 */
extern void GPIO_KeyInit(void);            /*按键初始化 */
extern uint8_t Get_Key4Value(void);        /* 获取K4按键状态 */
extern uint8_t Get_Key3Value(void);        /* 获取K3按键状态 */
extern void RGB_Toggle(void);              /* RGB闪烁 */
/* ====================================  Functions declaration  ===================================== */


/* ======================================  Functions define  ======================================== */


#ifdef __cplusplus
}
#endif

#endif /* _GPIO_H */

/* =============================================  EOF  ============================================== */
