168 lines
6.7 KiB
C
168 lines
6.7 KiB
C
#include "usr_bsp_gpio.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 usr_bsp_gpio_init(uint32_t ui32Port, uint8_t ui8Pins, uint32_t ui32PinIO,
|
||
uint32_t ui32PinType)
|
||
{
|
||
if ((ui32Port == GPIO_PORTA_BASE) || (ui32Port == GPIO_PORTA_AHB_BASE)) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
|
||
} else if ((ui32Port == GPIO_PORTB_BASE) || (ui32Port == GPIO_PORTB_AHB_BASE)) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
|
||
} else if ((ui32Port == GPIO_PORTC_BASE) || (ui32Port == GPIO_PORTC_AHB_BASE)) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
|
||
} else if ((ui32Port == GPIO_PORTD_BASE) || (ui32Port == GPIO_PORTD_AHB_BASE)) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
|
||
} else if ((ui32Port == GPIO_PORTE_BASE) || (ui32Port == GPIO_PORTE_AHB_BASE)) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
|
||
} else if ((ui32Port == GPIO_PORTF_BASE) || (ui32Port == GPIO_PORTF_AHB_BASE)) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
|
||
} else if ((ui32Port == GPIO_PORTH_BASE) || (ui32Port == GPIO_PORTH_AHB_BASE)) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
|
||
} else if ((ui32Port == GPIO_PORTJ_BASE) || (ui32Port == GPIO_PORTJ_AHB_BASE)) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
|
||
} else if (ui32Port == GPIO_PORTK_BASE) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
|
||
} else if (ui32Port == GPIO_PORTL_BASE) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
|
||
} else if (ui32Port == GPIO_PORTM_BASE) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);
|
||
} else if (ui32Port == GPIO_PORTN_BASE) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
|
||
} else if (ui32Port == GPIO_PORTP_BASE) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);
|
||
} else if (ui32Port == GPIO_PORTQ_BASE) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ);
|
||
} else if (ui32Port == GPIO_PORTR_BASE) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOR);
|
||
} else if (ui32Port == GPIO_PORTS_BASE) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOS);
|
||
} else if (ui32Port == GPIO_PORTT_BASE) {
|
||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOT);
|
||
} else {
|
||
return -1;
|
||
}
|
||
if (ui32PinIO == GPIO_DIR_MODE_IN) {
|
||
GPIODirModeSet(ui32Port, ui8Pins, ui32PinIO);
|
||
} else if (ui32PinIO == GPIO_DIR_MODE_OUT) {
|
||
GPIODirModeSet(ui32Port, ui8Pins, ui32PinIO);
|
||
GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, ui32PinType);
|
||
} else if (ui32PinIO == GPIO_DIR_MODE_HW){
|
||
GPIODirModeSet(ui32Port, ui8Pins, ui32PinIO);
|
||
} else {
|
||
return -1;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
/* šŚÄÜ:ÉčÖĂ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
|
||
* out_mode USR_GPIO_OUT_HIGH, USR_GPIO_OUT_LOW
|
||
*/
|
||
int8_t usr_bsp_gpio_set_output(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;
|
||
}
|
||
|
||
/* šŚÄÜ:śÁČĄ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
|
||
*/
|
||
uint8_t usr_bsp_gpio_get_input(uint32_t ui32Port, uint8_t ui8Pins)
|
||
{
|
||
if (ui8Pins == GPIOPinRead(ui32Port, ui8Pins)) {
|
||
return 1;
|
||
}
|
||
return 0;
|
||
}
|