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.

217 lines
6.5 KiB

/*
* Gpio.h
*
* Created on: 2024417
* 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__