20240909-DXSPX-emb/Src/Usr/BSP/BspGPIO.c

162 lines
6.2 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "BspGPIO.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
/*
* 功能:用户GPIO初始化
* 参数:
* ui32Port GPIO_PORTA_BASE, GPIO_PORTA_AHB_BASE,
* GPIO_PORTB_BASE, GPIO_PORTB_AHB_BASE,
* GPIO_PORTC_BASE, GPIO_PORTC_AHB_BASE,
* GPIO_PORTD_BASE, GPIO_PORTD_AHB_BASE,
* GPIO_PORTE_BASE, GPIO_PORTE_AHB_BASE,
* GPIO_PORTF_BASE, GPIO_PORTF_AHB_BASE,
* GPIO_PORTG_BASE, GPIO_PORTG_AHB_BASE,
* GPIO_PORTH_BASE, GPIO_PORTH_AHB_BASE,
* GPIO_PORTJ_BASE, GPIO_PORTJ_AHB_BASE,
* GPIO_PORTK_BASE,
* GPIO_PORTL_BASE,
* GPIO_PORTM_BASE,
* GPIO_PORTN_BASE,
* GPIO_PORTP_BASE,
* GPIO_PORTQ_BASE,
* GPIO_PORTR_BASE,
* GPIO_PORTS_BASE,
* GPIO_PORTT_BASE,
*
* ui8Pins GPIO_PIN_0, GPIO_PIN_1
* GPIO_PIN_2, GPIO_PIN_3
* GPIO_PIN_4, GPIO_PIN_5
* GPIO_PIN_6, GPIO_PIN_7
*
* ui32PinIO GPIO_DIR_MODE_IN, GPIO_DIR_MODE_OUT, GPIO_DIR_MODE_HW
*
* ui32PinType GPIO_PIN_TYPE_STD, GPIO_PIN_TYPE_STD_WPU, GPIO_PIN_TYPE_STD_WPD
* GPIO_PIN_TYPE_OD, GPIO_PIN_TYPE_ANALOG
* GPIO_PIN_TYPE_WAKE_HIGH, GPIO_PIN_TYPE_WAKE_LOW
*/
int8_t BspGPIOInit(uint32_t ui32Port, uint8_t ui8Pins, uint32_t ui32PinIO,
uint32_t ui32PinType)
{
uint32_t ui32Peripheral = 0;
switch (ui32Port) {
case GPIO_PORTA_BASE:
case GPIO_PORTA_AHB_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOA; break;
case GPIO_PORTB_BASE:
case GPIO_PORTB_AHB_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOB; break;
case GPIO_PORTC_BASE:
case GPIO_PORTC_AHB_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOC; break;
case GPIO_PORTD_BASE:
case GPIO_PORTD_AHB_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOD; break;
case GPIO_PORTE_BASE:
case GPIO_PORTE_AHB_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOE; break;
case GPIO_PORTF_BASE:
case GPIO_PORTF_AHB_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOF; break;
case GPIO_PORTH_BASE:
case GPIO_PORTH_AHB_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOH; break;
case GPIO_PORTJ_BASE:
case GPIO_PORTJ_AHB_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOJ; break;
case GPIO_PORTK_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOK; break;
case GPIO_PORTL_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOL; break;
case GPIO_PORTM_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOM; break;
case GPIO_PORTN_BASE: ui32Peripheral = SYSCTL_PERIPH_GPION; break;
case GPIO_PORTP_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOP; break;
case GPIO_PORTQ_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOQ; break;
case GPIO_PORTR_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOR; break;
case GPIO_PORTS_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOS; break;
case GPIO_PORTT_BASE: ui32Peripheral = SYSCTL_PERIPH_GPIOT; break;
default: return -1;
}
SysCtlPeripheralEnable(ui32Peripheral);
GPIODirModeSet(ui32Port, ui8Pins, ui32PinIO);
if (ui32PinIO == GPIO_DIR_MODE_OUT) {
GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, ui32PinType);
} else if (ui32PinIO != GPIO_DIR_MODE_IN && ui32PinIO != GPIO_DIR_MODE_HW) {
return -1;
}
return 0;
}
/* <20><><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD>GPIO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ͵<DFB5>ƽ
* <20><><EFBFBD><EFBFBD>:
* ui32Port GPIO_PORTA_BASE, GPIO_PORTA_AHB_BASE,
* GPIO_PORTB_BASE, GPIO_PORTB_AHB_BASE,
* GPIO_PORTC_BASE, GPIO_PORTC_AHB_BASE,
* GPIO_PORTD_BASE, GPIO_PORTD_AHB_BASE,
* GPIO_PORTE_BASE, GPIO_PORTE_AHB_BASE,
* GPIO_PORTF_BASE, GPIO_PORTF_AHB_BASE,
* GPIO_PORTG_BASE, GPIO_PORTG_AHB_BASE,
* GPIO_PORTH_BASE, GPIO_PORTH_AHB_BASE,
* GPIO_PORTJ_BASE, GPIO_PORTJ_AHB_BASE,
* GPIO_PORTK_BASE,
* GPIO_PORTL_BASE,
* GPIO_PORTM_BASE,
* GPIO_PORTN_BASE,
* GPIO_PORTP_BASE,
* GPIO_PORTQ_BASE,
* GPIO_PORTR_BASE,
* GPIO_PORTS_BASE,
* GPIO_PORTT_BASE,
*
* ui8Pins GPIO_PIN_0, GPIO_PIN_1
* GPIO_PIN_2, GPIO_PIN_3
* GPIO_PIN_4, GPIO_PIN_5
* GPIO_PIN_6, GPIO_PIN_7
* out_mode USR_GPIO_OUT_HIGH, USR_GPIO_OUT_LOW
*/
int8_t BspGPIOSetOutput(uint32_t ui32Port, uint8_t ui8Pins, int out_mode)
{
if ((ui32Port > GPIO_PORTT_BASE) || (ui8Pins > GPIO_PIN_7)) {
return -1;
}
if (out_mode == USR_GPIO_OUT_HIGH) {
GPIOPinWrite(ui32Port, ui8Pins, ui8Pins);
} else {
GPIOPinWrite(ui32Port, ui8Pins, ~ui8Pins);
}
return 0;
}
/* <20><><EFBFBD><EFBFBD>:<3A><>ȡGPIO<49><4F><EFBFBD><EFBFBD>ֵ
* <20><><EFBFBD><EFBFBD>:
* ui32Port GPIO_PORTA_BASE, GPIO_PORTA_AHB_BASE,
* GPIO_PORTB_BASE, GPIO_PORTB_AHB_BASE,
* GPIO_PORTC_BASE, GPIO_PORTC_AHB_BASE,
* GPIO_PORTD_BASE, GPIO_PORTD_AHB_BASE,
* GPIO_PORTE_BASE, GPIO_PORTE_AHB_BASE,
* GPIO_PORTF_BASE, GPIO_PORTF_AHB_BASE,
* GPIO_PORTG_BASE, GPIO_PORTG_AHB_BASE,
* GPIO_PORTH_BASE, GPIO_PORTH_AHB_BASE,
* GPIO_PORTJ_BASE, GPIO_PORTJ_AHB_BASE,
* GPIO_PORTK_BASE,
* GPIO_PORTL_BASE,
* GPIO_PORTM_BASE,
* GPIO_PORTN_BASE,
* GPIO_PORTP_BASE,
* GPIO_PORTQ_BASE,
* GPIO_PORTR_BASE,
* GPIO_PORTS_BASE,
* GPIO_PORTT_BASE,
*
* ui8Pins GPIO_PIN_0, GPIO_PIN_1
* GPIO_PIN_2, GPIO_PIN_3
* GPIO_PIN_4, GPIO_PIN_5
* GPIO_PIN_6, GPIO_PIN_7
*/
uint8_t BspGPIOGetIutput(uint32_t ui32Port, uint8_t ui8Pins)
{
if (ui8Pins == GPIOPinRead(ui32Port, ui8Pins)) {
return 1;
}
return 0;
}