📄 lh7a404_gpio_driver.c
字号:
/***********************************************************************
* $Workfile: lh7a404_gpio_driver.c $
* $Revision: 1.2 $
* $Author: WellsK $
* $Date: Jan 05 2004 11:05:48 $
*
* Project: LH7A404 GPIO driver
*
* Description:
* This file contains driver support for the GPIO module on the
* LH7A404
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh7a404/source/lh7a404_gpio_driver.c-arc $
*
* Rev 1.2 Jan 05 2004 11:05:48 WellsK
* Modified keyboard scan function and enumerations to be more
* inline with how they actually work.
*
* Rev 1.1 Dec 04 2003 17:41:50 WellsK
* Corrected logic of gpio_clear_int() function
*
* Rev 1.0 Jun 30 2003 16:51:22 WellsK
* Initial revision.
*
*
***********************************************************************
* SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
* OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
* AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES,
* SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
*
* SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY
* FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A
* SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
* FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
*
* COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
* CAMAS, WA
**********************************************************************/
#include "lh7a404_gpio_driver.h"
/***********************************************************************
* GPIO driver public functions
**********************************************************************/
/***********************************************************************
*
* Function: gpio_set_data_dir
*
* Purpose: Set a GPIO data port's bits as inputs or outputs
*
* Processing:
* For the selected value of port, update the data direction
* register with the passed value of dir.
*
* Parameters:
* port : Must be an enueration of type GPIO_PORT_T
* pins : Selected pins for the 'dir' operation
* dir : Direction to set the selected 'pins'
*
* Outputs: None
*
* Returns: Nothing
*
* Notes:
* Ports C, D, and G use '0' to indicate an output. All other use
* '1'.
*
**********************************************************************/
void gpio_set_data_dir(GPIO_PORT_T port,
UNS_8 pins,
GPIO_DIR_T dir)
{
if (dir == GPIO_INPUT)
{
/* GPIO inputs have the corresponding data direction bit set
to 0 */
switch (port)
{
case GPIO_PORT_A:
GPIO->paddr &= (~(UNS_32) pins);
break;
case GPIO_PORT_B:
GPIO->pbddr &= (~(UNS_32) pins);
break;
case GPIO_PORT_C:
GPIO->pcddr &= (UNS_32) pins;
break;
case GPIO_PORT_D:
GPIO->pdddr &= (UNS_32) pins;
break;
case GPIO_PORT_E:
GPIO->peddr &= (~(UNS_32) pins);
break;
case GPIO_PORT_F:
GPIO->pfddr &= (~(UNS_32) pins);
break;
case GPIO_PORT_G:
GPIO->pgddr &= (UNS_32) pins;
break;
case GPIO_PORT_H:
GPIO->phddr &= (~(UNS_32) pins);
break;
default:
break;
}
}
else
{
/* GPIO outputs have the corresponding data direction bit set
to 1 */
switch (port)
{
case GPIO_PORT_A:
GPIO->paddr |= (UNS_32) pins;
break;
case GPIO_PORT_B:
GPIO->pbddr |= (UNS_32) pins;
break;
case GPIO_PORT_C:
GPIO->pcddr &= (~(UNS_32) pins);
break;
case GPIO_PORT_D:
GPIO->pdddr &= (~(UNS_32) pins);
break;
case GPIO_PORT_E:
GPIO->peddr |= (UNS_32) pins;
break;
case GPIO_PORT_F:
GPIO->pfddr |= (UNS_32) pins;
break;
case GPIO_PORT_G:
GPIO->pgddr &= (~(UNS_32) pins);
break;
case GPIO_PORT_H:
GPIO->phddr |= (UNS_32) pins;
break;
default:
break;
}
}
}
/***********************************************************************
*
* Function: gpio_get_data_dir
*
* Purpose: Get a GPIO data port's data direction status
*
* Processing:
* For the selected value of port, read the data direction
* register and return the value to the caller.
*
* Parameters:
* port : Must be an enueration of type GPIO_PORT_T
*
* Outputs: None
*
* Returns: The value of the data direction register for port
*
* Notes: None
*
**********************************************************************/
UNS_8 gpio_get_data_dir(GPIO_PORT_T port)
{
UNS_32 dir;
switch (port)
{
case GPIO_PORT_A:
dir = GPIO->paddr;
break;
case GPIO_PORT_B:
dir = GPIO->pbddr;
break;
case GPIO_PORT_C:
dir = GPIO->pcddr;
break;
case GPIO_PORT_D:
dir = GPIO->pdddr;
break;
case GPIO_PORT_E:
dir = GPIO->peddr;
break;
case GPIO_PORT_F:
dir = GPIO->pfddr;
break;
case GPIO_PORT_G:
dir = GPIO->pgddr;
break;
case GPIO_PORT_H:
dir = GPIO->phddr;
break;
default:
break;
}
return (UNS_32) dir;
}
/***********************************************************************
*
* Function: gpio_data_write
*
* Purpose: Write to a GPIO data register (output)
*
* Processing:
* For the selected value of port, update the data register with
* the passed value of data.
*
* Parameters:
* port : Must be an enueration of type GPIO_PORT_T
* data : Value to write to the data register (1 = high)
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void gpio_data_write(GPIO_PORT_T port,
UNS_8 data)
{
switch (port)
{
case GPIO_PORT_A:
GPIO->padr = (UNS_32) data;
break;
case GPIO_PORT_B:
GPIO->pbdr = (UNS_32) data;
break;
case GPIO_PORT_C:
GPIO->pcdr = (UNS_32) data;
break;
case GPIO_PORT_D:
GPIO->pddr = (UNS_32) data;
break;
case GPIO_PORT_E:
GPIO->pedr = (UNS_32) data;
break;
case GPIO_PORT_F:
GPIO->pfdr = (UNS_32) data;
break;
case GPIO_PORT_G:
GPIO->pgdr = (UNS_32) data;
break;
case GPIO_PORT_H:
GPIO->phdr = (UNS_32) data;
break;
default:
break;
}
}
/***********************************************************************
*
* Function: gpio_data_read
*
* Purpose: Read a GPIO data register (input)
*
* Processing:
* For the selected value of port, read the data register and
* return the value to the caller.
*
* Parameters:
* port : Must be an enueration of type GPIO_PORT_T
*
* Outputs: None
*
* Returns: The data value for the data register 'port'
*
* Notes:
* The states of the GPIO inputs are read from the feedback input
* signals. In some conditions, the programmed state of an output
* may not match a read performed with this function.
*
**********************************************************************/
UNS_8 gpio_data_read(GPIO_PORT_T port)
{
UNS_32 data;
switch (port)
{
case GPIO_PORT_A:
data = GPIO->papindr;
break;
case GPIO_PORT_B:
data = GPIO->pbpindr;
break;
case GPIO_PORT_C:
data = GPIO->pcpindr;
break;
case GPIO_PORT_D:
data = GPIO->pdpindr;
break;
case GPIO_PORT_E:
data = GPIO->pepindr;
break;
case GPIO_PORT_F:
data = GPIO->pfpindr;
break;
case GPIO_PORT_G:
data = GPIO->pgpindr;
break;
case GPIO_PORT_H:
data = GPIO->phpindr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -