📄 gpio.h
字号:
*
* int gpiopinClose(handle_t FileDesc);
*
* Semantics:
* Close GPIO pin device.
*
* Parameters:
* FileDesc - Pin file descriptor returned by "open" call.
*
* Example:
*
* // Close the GPIO driver on a specific pin
* gpioClose(PinA2);
*
* Return Value:
* Zero
*
*****************************************************************************/
/*****************************************************************************
*
* LOW LEVEL INLINE GPIO DRIVER INTERFACE
*
* General Description:
*
* The Low Level GPIO Driver is configured by the following:
*
* 1) The device is created and initialized by selecting it through defining the
* INCLUDE_GPIO and GPIO_INLINE variables in the appconfig.h file associated
* with the SDK Embedded Project created in CodeWarrior.
* String #include "gpiodrvinline.h" must be included into application source file.
*
* 2) A "gpioOpen" and "gpioClose" are not used.
*
* 3) The GPIO port is configured via "gpioIoctl" calls.
* See "gpioIoctl" call below.
*
*
* gpioIoctl for port configuration
*
* UWord16 gpioIoctl(Address, UWord16 Cmd, unsigned long params)
*
* Semantics:
* Modify GPIO port configuration or set a GPIO signal.
*
* Parameters:
* Address - The address of the port
*
* Cmd - command for driver ioctl command; these commands
* are listed in the description of the IO Layer ioctl
* interface
*
* Params - The Params is used to pass on a particular pin on a port in which to perform
* one of the above commands. The gpioPin macro defined below is used to obtain
* a mask for that particular pin and port.
*
*
* Return Value:
* Integer value returned by the gpioIoctl call.
*
* The only gpioIoctl command which currently returns a value (0 or 1)
* is GPIO_READ.
*
* Example:
*
* // disable peripheral as the master of bit 0 on port A
* gpioIoctl (&ArchIO.PortA, GPIO_SETAS_GPIO, gpioPin(0));
*
* // set bit 3 on port B as an output pin
* gpioIoctl (&ArchIO.PortB, GPIO_SETAS_OUTPUT, gpioPin(3));
*
* // read the state of port D pin 5
* state = gpioIoctl (&ArchIO.PortD, GPIO_READ, gpioPin(5));
*
*****************************************************************************/
/*****************************************************************************
*
* IO Layer Interface to the GPIO Driver
*
* General Description:
*
* A GPIO port is configured by the following:
*
* 1) The device is created and initialized by selecting it by defining
* both the INCLUDE_GPIO variable and the INCLUDE_IO variable in the
* appconfig.h file associated with the SDK Embedded Project created
* in CodeWarrior.
*
* 2) An "open" call is made to open communications with the GPIO Port
*
* 3) The GPIO port is configured via "ioctl" calls.
* See "IOCTL" call below.
*
* 4) After all GPIO operations are completed, the GPIO peripheral
* is closed via a "close" call.
*
*
* OPEN
*
* handle_t open(const char *pName, int OFlags, ...);
*
* Semantics:
* Opens a particular port for operations. Argument pName is the
* particular port name. A particular port needs to be opened before
* configuring the port with IOCTL calls.
*
* Parameters:
* pName - device name. See bsp.h for device names specific to this
* platform. Typically, the GPIO device name is
* BSP_DEVICE_NAME_GPIO_A
* BSP_DEVICE_NAME_GPIO_B
* BSP_DEVICE_NAME_GPIO_C
* BSP_DEVICE_NAME_GPIO_D
* BSP_DEVICE_NAME_GPIO_E
*
* BSP_DEVICE_NAME_GPIO_A_PIN0
* ...
* BSP_DEVICE_NAME_GPIO_A_PIN7
* BSP_DEVICE_NAME_GPIO_B_PIN0
* ...
* BSP_DEVICE_NAME_GPIO_B_PIN7
* BSP_DEVICE_NAME_GPIO_C_PIN0
* ...
* BSP_DEVICE_NAME_GPIO_C_PIN3
* BSP_DEVICE_NAME_GPIO_D_PIN0
* ...
* BSP_DEVICE_NAME_GPIO_D_PIN7
* BSP_DEVICE_NAME_GPIO_E_PIN0
* ...
* BSP_DEVICE_NAME_GPIO_E_PIN7
*
*
* OFlags - open mode flags. Ignored for port.
* for pins - O_SETAS_INPUT
* O_SETAS_OUTPUT
* O_DISABLE_PULLUP
* O_ENABLE_PULLUP
* O_SETAS_GPIO
* O_SETAS_PERIPHERAL
* O_INTERRUPT_ASSERT_DISABLE
* O_INTERRUPT_ASSERT_ENABLE
* O_INTERRUPT_DISABLE
* O_INTERRUPT_ENABLE
* O_INTERRUPT_DETECTION_ACTIVE_HIGH
* O_INTERRUPT_DETECTION_ACTIVE_LOW
*
* Return Value:
* Port file descriptor if open is successful.
* -1 value if open failed.
*
* Example:
*
* handle_t PortA;
*
* PortA = open(BSP_DEVICE_NAME_GPIO_A, NULL);
*
*
* IOCTL
*
* UWord16 ioctl(handle_t FileDesc, UWord16 Cmd, unsigned long params);
*
* Semantics:
* Modify port configuration. GPIO driver supports the following commands:
*
* GPIO_SETAS_GPIO When peripheral disabled DDR determines
* direction of data flow in PER register
*
* GPIO_SETAS_PERIPHERAL A peripheral masters the gpio pin, in PER
* register
*
* GPIO_SETAS_INPUT Sets a gpio pin as an input, in DDR register
*
* GPIO_SETAS_OUTPUT Sets a gpio pin as an output, in DDR register
*
* GPIO_INTERRUPT_DISABLE Disables edge detection for any incoming
* interrupt, in IENR register.
*
* GPIO_INTERRUPT_ENABLE Enables edge detection for any incoming
* interrupt, in IENR register.
*
* GPIO_DISABLE_PULLUP Disable pull-up, in PUR register
*
* GPIO_ENABLE_PULLUP Enable pull-up, in PUR register
*
* GPIO_INTERRUPT_ASSERT_DISABLE Disables an interrupt assert, in IAR register
*
* GPIO_INTERRUPT_ASSERT_ENABLE Enables an interrupt assert, used only
* in software testing, in IAR register
*
* GPIO_INTERRUPT_DETECTION_ACTIVE_HIGH The interrupt seen at the PAD is active high
*
* GPIO_INTERRUPT_DETECTION_ACTIVE_LOW The interrupt seen at the PAD is active low
*
* GPIO_CLEAR_INTERRUPT_PEND_REGISTER By writing zeros to this register the IPR is
* cleared
*
* GPIO_SET Sets a GPIO signal
*
* GPIO_CLEAR Clears a GPIO signal
*
* GPIO_TOGGLE Toggles a GPIO signal
*
* GPIO_READ Reads the value of an input pin;
* returns 0 or 1 for the value
*
* The pParams is used to pass on a particular pin on a port in which to perform
* one of the above commands. The gpioPin macro defined below is used to obtain
* a mask for that particular pin and port.
*
* Parameters:
* FileDesc - GPIO Device descriptor returned by "open" call.
* Cmd - command for driver
* pParam - pin on which to perform the command
*
* Return Value:
* Integer value returned by the ioctl call.
*
* The only ioctl command which currently returns a value (0 or 1)
* is GPIO_READ.
*
* Example:
*
* // disable peripheral as the master of bit 0 on port A
* ioctl(PortA, GPIO_SETAS_GPIO, gpioPin(0));
*
* // set bit 2 on port D as an output pin
* ioctl(PortD, GPIO_SETAS_OUTPUT, gpioPin(2));
*
* // read bit 7 on port B
* state = ioctl(PortB, GPIO_READ, gpioPin(7));
*
*
* CLOSE
*
* int close(handle_t FileDesc);
*
* Semantics:
* Close GPIO device.
*
* Parameters:
* FileDesc - Port file descriptor returned by "open" call.
*
* Example:
*
* // Close the GPIO driver on a specific port
* close(PortA);
*
* Return Value:
* Zero
*
*****************************************************************************/
/*****************************************************************************
*
* Macro used to define GPIO pins to be used by the ioctl functions.
*
* Example: gpioPin(0)
*
*****************************************************************************/
#if !defined(gpioPin)
#define gpioPin(Bit) ((unsigned short)(0x01 << Bit))
#endif /* !defined(gpioPin) */
#define GPIOALLPINS 0xFFFF
/* ioctl commands */
enum io_gpio
{
GPIO_SET = IO_OFFSET(io_sInterface, pIoctl[0] ),
GPIO_CLEAR = IO_OFFSET(io_sInterface, pIoctl[1] ),
GPIO_TOGGLE = IO_OFFSET(io_sInterface, pIoctl[2] ),
GPIO_DISABLE_PULLUP = IO_OFFSET(io_sInterface, pIoctl[3] ),
GPIO_ENABLE_PULLUP = IO_OFFSET(io_sInterface, pIoctl[4] ),
GPIO_SETAS_INPUT = IO_OFFSET(io_sInterface, pIoctl[5] ),
GPIO_SETAS_OUTPUT = IO_OFFSET(io_sInterface, pIoctl[6] ),
GPIO_SETAS_GPIO = IO_OFFSET(io_sInterface, pIoctl[7] ),
GPIO_SETAS_PERIPHERAL = IO_OFFSET(io_sInterface, pIoctl[8] ),
GPIO_INTERRUPT_ASSERT_DISABLE = IO_OFFSET(io_sInterface, pIoctl[9] ),
GPIO_INTERRUPT_ASSERT_ENABLE = IO_OFFSET(io_sInterface, pIoctl[10] ),
GPIO_INTERRUPT_DISABLE = IO_OFFSET(io_sInterface, pIoctl[11] ),
GPIO_INTERRUPT_ENABLE = IO_OFFSET(io_sInterface, pIoctl[12] ),
GPIO_INTERRUPT_DETECTION_ACTIVE_HIGH = IO_OFFSET(io_sInterface, pIoctl[13] ),
GPIO_INTERRUPT_DETECTION_ACTIVE_LOW = IO_OFFSET(io_sInterface, pIoctl[14] ),
GPIO_CLEAR_INTERRUPT_PEND_REGISTER = IO_OFFSET(io_sInterface, pIoctl[15] ),
GPIO_READ = IO_OFFSET(io_sInterface, pIoctl[16] )
};
#define O_DISABLE_PULLUP 0x0010
#define O_ENABLE_PULLUP 0x0020
#define O_SETAS_GPIO 0x0040
#define O_SETAS_PERIPHERAL 0x0080
#define O_INTERRUPT_ASSERT_DISABLE 0x0100
#define O_INTERRUPT_ASSERT_ENABLE 0x0200
#define O_INTERRUPT_DISABLE 0x0400
#define O_INTERRUPT_ENABLE 0x0800
#define O_INTERRUPT_DETECTION_ACTIVE_HIGH 0x1000
#define O_INTERRUPT_DETECTION_ACTIVE_LOW 0x2000
#ifdef __cplusplus
}
#endif
/*********************************************************************
* The driver file is included at the end of this public include
* file instead of the beginning to avoid circular dependency problems.
**********************************************************************/
#endif /* __GPIO_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -