📄 lh7a400_gpio_driver.c
字号:
/**********************************************************************
* $Workfile: LH7A400_gpio_driver.c $
* $Revision: 1.3 $
* $Author: MaysR $
* $Date: Jun 12 2002 17:17:44 $
*
* Project: LH7A400
*
* Description:
* This file contains driver support for the LH7A400
* GPIO block. This module contains the following
* user functions:
* gpio_bit_is_output()--make a port bit an output with an initial value
* gpio_bit_is_input()--make a port bit an input
* gpio_bit_state()--return the state of the port bit; this is the output
* value for an ouput port and the input value for an
* input port
* gpio_pin_state()--return the state of the port pin no matter how the
* pin is configured (input, output, or muxed funxtion)
* gpio_port_f_bit_is_interrupt()--make a bit in port F an interrupt bit
* gpio_port_f_bit_is_gpio()--make a bit in port F a gpio bit
* gpio_interrupt_debounce_enable()--enable debounce for a port F
* interrupt bit
* gpio_interrupt_debounce_disable()--disable debounce for a port F
* interrupt bit
* gpio_interrupt_clear()--clear an edge-triggered GPIO interrupt
* gpio_interrupt_pending()--return 1 if there is a pending interrupt
* on the specified port F bit.
* gpio_raw_interrupt_pending()--return 1 if there is a pending raw
* interrupt on the specified port F bit.
* gpio_interrupt_edge_triggered()--set the port F interrupt bit to
* edge triggered
* gpio_interrupt_level_triggered()--set the port F interrupt bit to
* level triggered
* gpio_interrupt_active_high()--Make the port F interrupt bit
* active high
* gpio_interrupt_active_low()--Make the port F interrupt bit active low
*
* gpio_keyscan_set()--set the 4-bit keyscan value
* gpio_keyscan_get()--get the 4-bit keyscan value
*
* gpio_port_e_is_gpio()--configure the lower 4 bits of port E as gpio
* gpio_port_e_is_lcd()--configure the lower 4 bits of port E as
* lcd data[7:4]
*
* gpio_port_d_is_gpio()--configure all of port D as gpio
* gpio_port_d_is_lcd()--configure all of port D as LCD data[15:8]
*
* gpio_port_b_has_gpio()--configure port B[5:1] as gpio
* gpio_port_b_has_uart3()--configure port B[5:1] as UART3 pins
*
* NOTE: non-GPIO-related pinmux functions are implemented elsewhere
*
* General function usage:
* port letters are nominally upper case, but the drivers can deal
* with lower case.
*
* port bits are bit numbers (0,1,2,3,4,5,6,7 for 8-bit ports)
*
* port bit values are either 0 or 1. Keyscan values are 4-bits (0-15)
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/CHIPS/archives/LH7A400/GPIO/Drivers/LH7A400_gpio_driver.c-arc $
*
* Rev 1.3 Jun 12 2002 17:17:44 MaysR
* Cast return value for 'gpio_keyscan_get' to remove compiler
* warning.
*
* Rev 1.2 Nov 20 2001 11:12:16 KovitzP
* Added function block comments.
*
* Rev 1.1 Nov 19 2001 10:28:52 KovitzP
* Added GPIO-related PINMUX functions
*
* Rev 1.0 Nov 16 2001 10:43:20 KovitzP
* Initial revision.
*
*
* COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
* CAMAS, WA
*********************************************************************/
#include "LH7A400_gpio_driver.h"
#define UPPER_CASE(c) (((c)>='a' || (c)<='z') ? (c)-'a'+'A' : (c))
/**********************************************************************
*
* Function: gpio_bit_is_output
*
* Purpose:
* make a port bit an output with an initial value
*
* Processing:
* Convert the port letter to upper case. Switch on the port letter
* to choose the appropriate GPIO data direction register. Set the
* appropriate bit in the data register for the selected port to
* the specified initial value so that when the port is enabled as
* output, it will output the correct value. Set or
* clear the appropriate bit in the data direction register (as
* required by the specific port) to make the port bit an output.
*
* Parameters:
* port_letter: A single character, either upper or lower case,
* signifying the GPIO port. For example, PORTC is 'C'
* port_bit: The bit number of GPIO port. For example PORTC1 is 1.
* init_value: The initial bit state when output are enabled (0 or 1)
*
* Outputs: None
*
* Returns: Nothing
*
* Notes:
*
**********************************************************************/
void gpio_bit_is_output(UNS_8 port_letter,
UNS_8 port_bit,
UNS_8 init_value)
{
switch (UPPER_CASE(port_letter) )
{
case 'A':
if (init_value)
GPIO->padr |= _BIT(port_bit);
else
GPIO->padr &= ~_BIT(port_bit);
GPIO->paddr |= _BIT(port_bit);
break;
case 'B':
if (init_value)
GPIO->pbdr |= _BIT(port_bit);
else
GPIO->pbdr &= ~_BIT(port_bit);
GPIO->pbddr |= _BIT(port_bit);
break;
case 'C':
if (init_value)
GPIO->pcdr |= _BIT(port_bit);
else
GPIO->pcdr &= ~_BIT(port_bit);
GPIO->pcddr &= ~_BIT(port_bit);
break;
case 'D':
if (init_value)
GPIO->pddr |= _BIT(port_bit);
else
GPIO->pddr &= ~_BIT(port_bit);
GPIO->pdddr &= ~_BIT(port_bit);
break;
case 'E':
if (init_value)
GPIO->pedr |= _BIT(port_bit);
else
GPIO->pedr |= _BIT(port_bit);
GPIO->peddr |= _BIT(port_bit);
break;
case 'F':
if (init_value)
GPIO->pfdr |= _BIT(port_bit);
else
GPIO->pfdr |= _BIT(port_bit);
GPIO->pfddr |= _BIT(port_bit);
break;
case 'G':
if (init_value)
GPIO->pgdr |= _BIT(port_bit);
else
GPIO->pgdr &= ~_BIT(port_bit);
GPIO->pgddr &= ~_BIT(port_bit);
break;
case 'H':
if (init_value)
GPIO->phdr |= _BIT(port_bit);
else
GPIO->phdr |= _BIT(port_bit);
GPIO->phddr |= _BIT(port_bit);
break;
}
}
/**********************************************************************
*
* Function: gpio_bit_is_input
*
* Purpose:
* make a port bit an input
*
* Processing:
* Convert the port letter to upper case. Switch on the port letter
* to choose the appropriate GPIO data direction register. Set or
* clear the appropriate bit in the data direction register (as
* required by the specific port) to make the port bit an input.
*
* Parameters:
* port_letter: A single character, either upper or lower case,
* signifying the GPIO port. For example, PORTC is 'C'
* port_bit: The bit number of GPIO port. For example PORTC1 is 1.
*
* Outputs: None
*
* Returns: Nothing
*
* Notes:
*
**********************************************************************/
void gpio_bit_is_input(UNS_8 port_letter, UNS_8 port_bit)
{
switch (UPPER_CASE(port_letter) )
{
case 'A':
GPIO->paddr &= ~_BIT(port_bit);
break;
case 'B':
GPIO->pbddr &= ~_BIT(port_bit);
break;
case 'C':
GPIO->pcddr |= _BIT(port_bit);
break;
case 'D':
GPIO->pdddr |= _BIT(port_bit);
break;
case 'E':
GPIO->peddr &= ~_BIT(port_bit);
break;
case 'F':
GPIO->pfddr &= ~_BIT(port_bit);
break;
case 'G':
GPIO->pgddr |= _BIT(port_bit);
break;
case 'H':
GPIO->phddr &= ~_BIT(port_bit);
break;
}
}
/**********************************************************************
*
* Function: gpio_bit_state
*
* Purpose:
* return the state of the port bit; this is the output value for an
* ouput port and the input value for an input port
*
* Processing:
* Convert the port letter to upper case. Switch on the port letter
* to choose the appropriate GPIO data register. AND the data register
* with 1 << port_bit and return the result.
*
* Parameters:
* port_letter: A single character, either upper or lower case,
* signifying the GPIO port. For example, PORTC is 'C'
* port_bit: The bit number of GPIO port. For example PORTC1 is 1.
*
* Outputs: None
*
* Returns:
* 0 if the port bit is clear or the port or bit is invalid.
* non-zero if the port bit is set in the data register (output)
* or on the pin (input)
*
* Notes:
*
**********************************************************************/
INT_32 gpio_bit_state(UNS_8 port_letter, UNS_8 port_bit)
{
switch (UPPER_CASE(port_letter) )
{
case 'A':
return GPIO->padr & _BIT(port_bit);
break;
case 'B':
return GPIO->pbdr & _BIT(port_bit);
break;
case 'C':
return GPIO->pcdr & _BIT(port_bit);
break;
case 'D':
return GPIO->pddr & _BIT(port_bit);
break;
case 'E':
return GPIO->pedr & _BIT(port_bit);
break;
case 'F':
return GPIO->pfdr & _BIT(port_bit);
break;
case 'G':
return GPIO->pgdr & _BIT(port_bit);
break;
case 'H':
return GPIO->phdr & _BIT(port_bit);
break;
}
return 0;
}
/**********************************************************************
*
* Function: gpio_pin_state
*
* Purpose:
* return the state of the port pin no matter how the pin is
* configured (input, output, or muxed funxtion)
*
* Processing:
*
* Parameters:
* port_letter: A single character, either upper or lower case,
* signifying the GPIO port. For example, PORTC is 'C'
* port_bit: The bit number of GPIO port. For example PORTC1 is 1.
*
* Outputs: None
*
* Returns:
* 0 if the pin state is low
* non-0 if the pin state is high.
*
* Notes:
* This function always returns the state of the pin, not the
* data register.
*
**********************************************************************/
INT_32 gpio_pin_state(UNS_8 port_letter, UNS_8 port_bit)
{
switch (UPPER_CASE(port_letter) )
{
case 'A':
return GPIO->papindr & _BIT(port_bit);
break;
case 'B':
return GPIO->pbpindr & _BIT(port_bit);
break;
case 'C':
return GPIO->pcpindr & _BIT(port_bit);
break;
case 'D':
return GPIO->pdpindr & _BIT(port_bit);
break;
case 'E':
return GPIO->pepindr & _BIT(port_bit);
break;
case 'F':
return GPIO->pfpindr & _BIT(port_bit);
break;
case 'G':
return GPIO->pgpindr & _BIT(port_bit);
break;
case 'H':
return GPIO->phpindr & _BIT(port_bit);
break;
}
return 0;
}
/**********************************************************************
*
* Function: gpio_port_f_bit_is_interrupt
*
* Purpose:
* make a bit in port F an interrupt bit
*
* Processing:
* Set the appropriate bit in the gpiointen register
*
* Parameters:
* port_f_bit: The bit number of the port F bit. For example, for
* PORTF2, use port_f_bit == 2.
*
* Outputs: None
*
* Returns: Nothing
*
* Notes:
*
**********************************************************************/
void gpio_port_f_bit_is_interrupt(UNS_8 port_f_bit)
{
GPIO->gpiointen |= _BIT(port_f_bit);
}
/**********************************************************************
*
* Function: gpio_port_f_bit_is_gpio
*
* Purpose:
* make a bit in port F a gpio bit
*
* Processing:
* Clear the appropriate bit in the gpiointen register
*
* Parameters:
* port_f_bit: The bit number of the port F bit. For example, for
* PORTF2, use port_f_bit == 2.
*
* Outputs: None
*
* Returns: Nothing
*
* Notes:
*
**********************************************************************/
void gpio_port_f_bit_is_gpio(UNS_8 port_f_bit)
{
GPIO->gpiointen &= ~_BIT(port_f_bit);
}
/**********************************************************************
*
* Function: gpio_interrupt_debounce_enable
*
* Purpose:
* enable debounce for a port F interrupt bit
*
* Processing:
* set the appropriate bit in the gpiodb register
*
* Parameters:
* port_f_bit: The bit number of the port F bit. For example, for
* PORTF2, use port_f_bit == 2.
*
* Outputs: None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -