📄 lh79524_gpio_driver.c
字号:
/***********************************************************************
* $Workfile: lh79524_gpio_driver.c $
* $Revision: 1.0 $
* $Author: ZhangJ $
* $Date: Oct 20 2004 09:48:54 $
*
* Project: LH79524 GPIO driver
*
* Description:
* This file contains driver support for the GPIO module on the
* LH79524
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh79524/source/lh79524_gpio_driver.c-arc $
*
* Rev 1.0 Oct 20 2004 09:48:54 ZhangJ
* Initial revision.
*
* Rev 1.0 Sep 14 2004 16:40:00 ZhangJ
* 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 "lh79524_iocon.h"
#include "lh79524_rcpc.h"
#include "lh79524_gpio_driver.h"
/***********************************************************************
*
* Function: gpio_set_data_dir
*
* Purpose: Set a GPIO data port's bits direction as inputs or outputs
*
* Processing:
* For the selected value of port, update the data direction
* register with the passed value of dir.
*
* Parameters:
* gpio_port Must be a GPIO port of type GPIO_REGS_T
* pins Selected pins for the 'dir' operation
* dir Direction to set. GPIO_INPUT or GPIO_OUTPUT
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void gpio_set_data_dir(GPIO_REGS_T * gpio_port,
UNS_8 pins,
GPIO_DIR_T dir)
{
if(
((INT_32)gpio_port == (INT_32)GPIOA) || ((INT_32)gpio_port == (INT_32)GPIOB)
|| ((INT_32)gpio_port == (INT_32)GPIOC) || ((INT_32)gpio_port == (INT_32)GPIOD)
|| ((INT_32)gpio_port == (INT_32)GPIOE) || ((INT_32)gpio_port == (INT_32)GPIOF)
|| ((INT_32)gpio_port == (INT_32)GPIOG) || ((INT_32)gpio_port == (INT_32)GPIOH)
|| ((INT_32)gpio_port == (INT_32)GPIOI) || ((INT_32)gpio_port == (INT_32)GPIOK)
|| ((INT_32)gpio_port == (INT_32)GPIOL) || ((INT_32)gpio_port == (INT_32)GPION)
)
{
if (dir == GPIO_INPUT)
gpio_port->ddr &= (~(UNS_32) pins);
else
gpio_port->ddr |= ((UNS_32) pins);
}
else if((INT_32)gpio_port == (INT_32)GPIOJ)
{
/* Input only port */
if (dir == GPIO_INPUT)
gpio_port->ddr &= (~(UNS_32) pins);
}
else if((INT_32)gpio_port == (INT_32)GPIOM)
{
/* Output only port */
if (dir == GPIO_OUTPUT)
gpio_port->ddr |= ((UNS_32) pins);
}
}
/***********************************************************************
*
* Function: gpio_get_data_dir
*
* Purpose: get a GPIO data port's direction setting
*
* Processing:
* For the selected value of port, update the data direction
* register with the passed value of dir.
*
* Parameters:
* gpio_port Must be an GPIO port of type GPIO_REGS_T
* pins Selected pins for the 'dir' operation
* dir Direction to set. GPIO_INPUT or GPIO_OUTPUT
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
UNS_8 gpio_get_data_dir(GPIO_REGS_T * gpio_port)
{
return (gpio_port->ddr);
}
/***********************************************************************
*
* Function: gpio_write_byte
*
* Purpose: Write one byte data to GPIO port
*
* Processing:
* For the selected value of port, update the data
* register with the passed value of data.
*
* Parameters:
* gpio_port Must be a GPIO port of type GPIO_REGS_T
* data Data for output
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void gpio_write_byte(GPIO_REGS_T * gpio_port, UNS_8 data)
{
if(
((INT_32)gpio_port == (INT_32)GPIOA) || ((INT_32)gpio_port == (INT_32)GPIOB)
|| ((INT_32)gpio_port == (INT_32)GPIOC) || ((INT_32)gpio_port == (INT_32)GPIOD)
|| ((INT_32)gpio_port == (INT_32)GPIOE) || ((INT_32)gpio_port == (INT_32)GPIOF)
|| ((INT_32)gpio_port == (INT_32)GPIOG) || ((INT_32)gpio_port == (INT_32)GPIOH)
|| ((INT_32)gpio_port == (INT_32)GPIOI) || ((INT_32)gpio_port == (INT_32)GPIOK)
|| ((INT_32)gpio_port == (INT_32)GPIOL) || ((INT_32)gpio_port == (INT_32)GPIOM)
|| ((INT_32)gpio_port == (INT_32)GPION)
)
{
gpio_port->dr = data;
}
}
/***********************************************************************
*
* Function: gpio_read_byte
*
* Purpose: Read one byte data from GPIO port
*
* Processing:
* For the selected port, read the data register.
*
* Parameters:
* gpio_port Must be a GPIO port of type GPIO_REGS_T
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
UNS_8 gpio_read_byte(GPIO_REGS_T * gpio_port)
{
if(
((INT_32)gpio_port == (INT_32)GPIOA) || ((INT_32)gpio_port == (INT_32)GPIOB)
|| ((INT_32)gpio_port == (INT_32)GPIOC) || ((INT_32)gpio_port == (INT_32)GPIOD)
|| ((INT_32)gpio_port == (INT_32)GPIOE) || ((INT_32)gpio_port == (INT_32)GPIOF)
|| ((INT_32)gpio_port == (INT_32)GPIOG) || ((INT_32)gpio_port == (INT_32)GPIOH)
|| ((INT_32)gpio_port == (INT_32)GPIOI) || ((INT_32)gpio_port == (INT_32)GPIOJ)
|| ((INT_32)gpio_port == (INT_32)GPIOK) || ((INT_32)gpio_port == (INT_32)GPIOL)
|| ((INT_32)gpio_port == (INT_32)GPION)
)
{
return (gpio_port->dr);
}
else
{
return 0;
}
}
/***********************************************************************
*
* Function: gpio_ext_int_init
*
* Purpose: external int pin init function
*
* Processing:
*
* Parameters:
* source: EXT_INT0 to EXT_INT7
* trigger: Level low = 0
* Level high = 1
* Falling edge = 2
* Rising edge = 3
*
* Outputs: None
*
* Returns: None
*
* Notes: None
*
**********************************************************************/
void gpio_ext_int_init(INT_32 source, INT_32 trigger)
{
switch (source)
{
case EXT_INT0:
RCPC->intconfig &= ~(_BIT(0) | _BIT(1));
RCPC->intconfig |= _SBF(0,trigger);
IOCON->mux_ctl_5 &= ~(_BIT(8) | _BIT(9));
IOCON->mux_ctl_5 |= IOCON_MUX5_INT0;
break;
case EXT_INT1:
RCPC->intconfig &= ~(_BIT(2) | _BIT(3));
RCPC->intconfig |= _SBF(2,trigger);
IOCON->mux_ctl_5 &= ~(_BIT(10) | _BIT(11));
IOCON->mux_ctl_5 |= IOCON_MUX5_INT1;
break;
case EXT_INT2:
RCPC->intconfig &= ~(_BIT(4) | _BIT(5));
RCPC->intconfig |= _SBF(4,trigger);
IOCON->mux_ctl_5 &= ~(_BIT(12) | _BIT(13));
IOCON->mux_ctl_5 |= IOCON_MUX5_INT2;
break;
case EXT_INT3:
RCPC->intconfig &= ~(_BIT(6) | _BIT(7));
RCPC->intconfig |= _SBF(6,trigger);
IOCON->mux_ctl_5 &= ~(_BIT(14) | _BIT(15));
IOCON->mux_ctl_5 |= IOCON_MUX5_INT3;
break;
case EXT_INT4:
RCPC->intconfig &= ~(_BIT(8) | _BIT(9));
RCPC->intconfig |= _SBF(8,trigger);
IOCON->mux_ctl_3 &= ~(_BIT(0) | _BIT(1));
IOCON->mux_ctl_3 |= IOCON_MUX3_INT4;
break;
case EXT_INT5:
RCPC->intconfig &= ~(_BIT(10) | _BIT(11));
RCPC->intconfig |= _SBF(10,trigger);
IOCON->mux_ctl_25 &= ~(_BIT(10) | _BIT(11));
IOCON->mux_ctl_25 |= IOCON_MUX25_INT5;
break;
case EXT_INT6:
RCPC->intconfig &= ~(_BIT(12) | _BIT(13));
RCPC->intconfig |= _SBF(12,trigger);
IOCON->mux_ctl_25 &= ~(_BIT(12) | _BIT(13));
IOCON->mux_ctl_25 |= IOCON_MUX25_INT6;
break;
case EXT_INT7:
RCPC->intconfig &= ~(_BIT(14) | _BIT(15));
RCPC->intconfig |= _SBF(14,trigger);
IOCON->mux_ctl_25 &= ~(_BIT(14) | _BIT(15));
IOCON->mux_ctl_25 |= IOCON_MUX25_INT7;
break;
default:
break;
}
}
/***********************************************************************
*
* Function: gpio_ext_int_clear
*
* Purpose: Clear int status bit caused by external int pin
*
* Processing:
*
* Parameters:
* source: EXT_INT0 to EXT_INT7
*
* Outputs: None
*
* Returns: None
*
* Notes: Clears edge-triggered interrupt status only.
*
**********************************************************************/
void gpio_ext_int_clear(INT_32 source)
{
switch (source)
{
case EXT_INT0:
RCPC->intclear |= _BIT(0);
break;
case EXT_INT1:
RCPC->intclear |= _BIT(1);
break;
case EXT_INT2:
RCPC->intclear |= _BIT(2);
break;
case EXT_INT3:
RCPC->intclear |= _BIT(3);
break;
case EXT_INT4:
RCPC->intclear |= _BIT(4);
break;
case EXT_INT5:
RCPC->intclear |= _BIT(5);
break;
case EXT_INT6:
RCPC->intclear |= _BIT(6);
break;
case EXT_INT7:
RCPC->intclear |= _BIT(7);
break;
default:
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -