You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
216 lines
6.5 KiB
216 lines
6.5 KiB
/*
|
|
* Gpio.h
|
|
*
|
|
* Created on: 2024Äê4ÔÂ17ÈÕ
|
|
* Author: tang
|
|
*/
|
|
|
|
#ifndef UTILITIES_GPIO_H_
|
|
#define UTILITIES_GPIO_H_
|
|
|
|
|
|
|
|
#endif /* UTILITIES_GPIO_H_ */
|
|
#ifndef __HW_GPIO_H__
|
|
#define __HW_GPIO_H__
|
|
/*!
|
|
* \file hw-gpio.h
|
|
*
|
|
* \brief GPIO driver implementation
|
|
*
|
|
* \copyright Revised BSD License, see section \ref LICENSE.
|
|
*
|
|
* \code
|
|
* ______ _
|
|
* / _____) _ | |
|
|
* ( (____ _____ ____ _| |_ _____ ____| |__
|
|
* \____ \| ___ | (_ _) ___ |/ ___) _ \
|
|
* _____) ) ____| | | || |_| ____( (___| | | |
|
|
* (______/|_____)_|_|_| \__)_____)\____)_| |_|
|
|
* (C)2013-2017 Semtech
|
|
*
|
|
* \endcode
|
|
*
|
|
* \author Semtech
|
|
*/
|
|
|
|
/* Includes -----------------------------------------------------------------*/
|
|
//#include "hw.h"
|
|
#define GPIO_Pin_0 (0x00000001) /*!< Pin 0 selected */
|
|
#define GPIO_Pin_1 (0x00000002) /*!< Pin 1 selected */
|
|
#define GPIO_Pin_2 (0x00000004) /*!< Pin 2 selected */
|
|
#define GPIO_Pin_3 (0x00000008) /*!< Pin 3 selected */
|
|
#define GPIO_Pin_4 (0x00000010) /*!< Pin 4 selected */
|
|
#define GPIO_Pin_5 (0x00000020) /*!< Pin 5 selected */
|
|
#define GPIO_Pin_6 (0x00000040) /*!< Pin 6 selected */
|
|
#define GPIO_Pin_7 (0x00000080) /*!< Pin 7 selected */
|
|
#define GPIO_Pin_8 (0x00000100) /*!< Pin 8 selected */
|
|
#define GPIO_Pin_9 (0x00000200) /*!< Pin 9 selected */
|
|
#define GPIO_Pin_10 (0x00000400) /*!< Pin 10 selected */
|
|
#define GPIO_Pin_11 (0x00000800) /*!< Pin 11 selected */
|
|
#define GPIO_Pin_12 (0x00001000) /*!< Pin 12 selected */
|
|
#define GPIO_Pin_13 (0x00002000) /*!< Pin 13 selected */
|
|
#define GPIO_Pin_14 (0x00004000) /*!< Pin 14 selected */
|
|
#define GPIO_Pin_15 (0x00008000) /*!< Pin 15 selected */
|
|
#define GPIO_Pin_16 (0x00010000) /*!< Pin 16 selected */
|
|
#define GPIO_Pin_17 (0x00020000) /*!< Pin 17 selected */
|
|
#define GPIO_Pin_18 (0x00040000) /*!< Pin 18 selected */
|
|
#define GPIO_Pin_19 (0x00080000) /*!< Pin 19 selected */
|
|
#define GPIO_Pin_20 (0x00100000) /*!< Pin 20 selected */
|
|
#define GPIO_Pin_21 (0x00200000) /*!< Pin 21 selected */
|
|
#define GPIO_Pin_22 (0x00400000) /*!< Pin 22 selected */
|
|
#define GPIO_Pin_23 (0x00800000) /*!< Pin 23 selected */
|
|
#define GPIO_Pin_All (0xFFFFFFFF) /*!< All pins selected */
|
|
|
|
/*!
|
|
* Operation Mode for the GPIO
|
|
*/
|
|
/*ÔÚCH592ÀïÃæûÓÐ µ¥¶ÀµÄGPIOÊäÈëÊä³ö ½á¹¹Ìå
|
|
* */
|
|
//typedef enum
|
|
//{
|
|
// PIN_INPUT = 0,
|
|
// PIN_OUTPUT,
|
|
// PIN_ALTERNATE_FCT,
|
|
// PIN_ANALOGIC
|
|
//}PinModes;
|
|
|
|
/*!
|
|
* Add a pull-up, a pull-down or nothing on the GPIO line
|
|
*/
|
|
typedef enum
|
|
{
|
|
GPIO_ModeIN_Floating, //¸¡¿ÕÊäÈë
|
|
GPIO_ModeIN_PU, //ÉÏÀÊäÈë
|
|
GPIO_ModeIN_PD, //ÏÂÀÊäÈë
|
|
GPIO_ModeOut_PP_5mA, //ÍÆÍìÊä³ö×î´ó5mA
|
|
GPIO_ModeOut_PP_20mA, //ÍÆÍìÊä³ö×î´ó20mA
|
|
}PinTypes;
|
|
|
|
/*!
|
|
* Define the GPIO as Push-pull type or Open Drain
|
|
*/
|
|
|
|
/*ûÓж¨ÒåGPIO ÉÏÀ»¹ÊÇÏÂÀ*/
|
|
//typedef enum
|
|
//{
|
|
// PIN_PUSH_PULL = 0,
|
|
// PIN_OPEN_DRAIN
|
|
//}PinConfigs;
|
|
|
|
/*!
|
|
* Define the GPIO IRQ on a rising, falling or both edges
|
|
*/
|
|
typedef enum
|
|
{
|
|
GPIO_ITMode_LowLevel, //µÍµçƽ´¥·¢
|
|
GPIO_ITMode_HighLevel, //¸ßµçƽ´¥·¢
|
|
GPIO_ITMode_FallEdge, //ϽµÑØ´¥·¢
|
|
GPIO_ITMode_RiseEdge, //ÉÏÉýÑØ´¥·¢
|
|
}IrqModes;
|
|
|
|
/*!
|
|
* Structure for the GPIO
|
|
*/
|
|
//typedef struct
|
|
//{
|
|
// //PinNames pin;
|
|
// uint16_t pinIndex;
|
|
// void *port;
|
|
// uint16_t portIndex;
|
|
// PinTypes pull;
|
|
//}Gpio_t;
|
|
/****************************************************************************\
|
|
* Type definition
|
|
\****************************************************************************/
|
|
|
|
/****************************************************************************\
|
|
* Type definition
|
|
\****************************************************************************/
|
|
|
|
/*!
|
|
* Operation Mode for the GPIO
|
|
*/
|
|
|
|
|
|
|
|
|
|
typedef void( GpioIrqHandler )( void );
|
|
|
|
/***************************************************************************\
|
|
* External Functions
|
|
\***************************************************************************/
|
|
|
|
/**
|
|
* @brief Gets IRQ number as a finction of the GPIO_Pin.
|
|
* @param GPIO_Pin: Specifies the pins connected to the EXTI line.
|
|
* @retval IRQ number
|
|
*/
|
|
IRQn_Type MSP_GetIRQn( uint16_t gpioPin );
|
|
|
|
/*!
|
|
* \brief Initializes and configure the GPIO.
|
|
*/
|
|
void GpioInit( void );
|
|
|
|
/*!
|
|
* \brief DeInitializes the GPIO.
|
|
*/
|
|
void GpioDeInit( void );
|
|
|
|
/*!
|
|
* @brief Writes the given value to the GPIO output
|
|
*
|
|
* @param GPIOx: where x can be (A..E and H)
|
|
* @param GPIO_Pin: specifies the port bit to be written.
|
|
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
|
|
* All port bits are not necessarily available on all GPIOs.
|
|
* @param [IN] value New GPIO output value
|
|
* @retval none
|
|
*/
|
|
void GpioWrite( GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t value );
|
|
|
|
/*!
|
|
* @brief Reads the current GPIO input value
|
|
*
|
|
* @param GPIOx: where x can be (A..E and H)
|
|
* @param GPIO_Pin: specifies the port bit to be written.
|
|
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
|
|
* All port bits are not necessarily available on all GPIOs.
|
|
* @retval value Current GPIO input value
|
|
*/
|
|
uint32_t GpioRead( GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin );
|
|
|
|
/*!
|
|
* @brief Get the position of the bit set in the GPIO_Pin
|
|
* @param GPIO_Pin: specifies the port bit to be written.
|
|
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
|
|
* All port bits are not necessarily available on all GPIOs.
|
|
* @retval the position of the bit
|
|
*/
|
|
uint8_t GpioGetBitPos( uint16_t GPIO_Pin );
|
|
|
|
/*!
|
|
* @brief Records the interrupt handler for the GPIO object
|
|
*
|
|
* @param GPIOx: where x can be (A..E and H)
|
|
* @param GPIO_Pin: specifies the port bit to be written.
|
|
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
|
|
* All port bits are not necessarily available on all GPIOs.
|
|
* @param [IN] prio NVIC priority (0 is highest)
|
|
* @param [IN] irqHandler points to the function to execute
|
|
* @retval none
|
|
*/
|
|
void GpioSetIrq( GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t prio, GpioIrqHandler *irqHandler );
|
|
|
|
/*!
|
|
* @brief Execute the interrupt from the object
|
|
*
|
|
* @param GPIO_Pin: specifies the port bit to be written.
|
|
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
|
|
* All port bits are not necessarily available on all GPIOs.
|
|
* @retval none
|
|
*/
|
|
void GpioLaunchIrqHandler( uint16_t GPIO_Pin );
|
|
|
|
#endif // __HW_GPIO_H__
|
|
|