mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
185 lines
7.1 KiB
C
185 lines
7.1 KiB
C
/*********************************************************************************************************************
|
||
* COPYRIGHT NOTICE
|
||
* Copyright (c) 2020,<2C><><EFBFBD>ɿƼ<C9BF>
|
||
* All rights reserved.
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>QQȺ<51><C8BA><EFBFBD><EFBFBD>Ⱥ<EFBFBD><C8BA>824575535
|
||
*
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC><EFBFBD><EFBFBD>У<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5>;<EFBFBD><CDBE>
|
||
* <20><>ӭ<EFBFBD><D3AD>λʹ<CEBB>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>뱣<EFBFBD><EBB1A3><EFBFBD><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC>İ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
*
|
||
* @file gpio
|
||
* @company <09>ɶ<EFBFBD><C9B6><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC><EFBFBD><EFBFBD><EFBFBD>˾
|
||
* @author <09><><EFBFBD>ɿƼ<C9BF>(QQ3184284598)
|
||
* @version <09>鿴doc<6F><63>version<6F>ļ<EFBFBD> <20>汾˵<E6B1BE><CBB5>
|
||
* @Software ADS v1.2.2
|
||
* @Target core TC264D
|
||
* @Taobao https://seekfree.taobao.com/
|
||
* @date 2020-3-23
|
||
********************************************************************************************************************/
|
||
|
||
|
||
|
||
|
||
#include "zf_gpio.h"
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief <20><>ȡGPIO<49><4F><EFBFBD><EFBFBD>ַ
|
||
// @param pin ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7> common.h <20><>PIN_enumö<6D><C3B6>ֵȷ<D6B5><C8B7>)
|
||
// @return void
|
||
// Sample usage: <20>ļ<EFBFBD><C4BC>ڲ<EFBFBD>ʹ<EFBFBD>ã<EFBFBD><C3A3>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
volatile Ifx_P* get_port(PIN_enum pin)
|
||
{
|
||
volatile Ifx_P *port;
|
||
|
||
switch(pin&0xffe0)
|
||
{
|
||
case P00_0: port = &MODULE_P00; break;
|
||
case P02_0: port = &MODULE_P02; break;
|
||
case P10_0: port = &MODULE_P10; break;
|
||
case P11_0: port = &MODULE_P11; break;
|
||
case P13_0: port = &MODULE_P13; break;
|
||
case P14_0: port = &MODULE_P14; break;
|
||
case P15_0: port = &MODULE_P15; break;
|
||
case P20_0: port = &MODULE_P20; break;
|
||
case P21_0: port = &MODULE_P21; break;
|
||
case P22_0: port = &MODULE_P22; break;
|
||
case P23_0: port = &MODULE_P23; break;
|
||
case P32_0: port = &MODULE_P32; break;
|
||
case P33_0: port = &MODULE_P33; break;
|
||
default:break;
|
||
}
|
||
#pragma warning 507
|
||
return port;
|
||
#pragma warning default
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief GPIO<49><4F>ʼ<EFBFBD><CABC>
|
||
// @param pin ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7> common.h <20><>PIN_enumö<6D><C3B6>ֵȷ<D6B5><C8B7>)
|
||
// @param dir <20><><EFBFBD>ŵķ<C5B5><C4B7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPO <20><><EFBFBD>룺GPI
|
||
// @param dat <20><><EFBFBD>ų<EFBFBD>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1><EFBFBD>õĵ<C3B5>ƽ״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ч 0<><30><EFBFBD>͵<EFBFBD>ƽ 1<><31><EFBFBD>ߵ<EFBFBD>ƽ
|
||
// @param pinmode <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>zf_gpio.h<>ļ<EFBFBD><C4BC><EFBFBD>GPIOMODE_enumö<6D><C3B6>ֵȷ<D6B5><C8B7><EFBFBD><EFBFBD>
|
||
// @return void
|
||
// Sample usage: gpio_init(P00_0, GPO, 1, PUSHPULL);//P00_0<5F><30>ʼ<EFBFBD><CABC>ΪGPIO<49><4F><EFBFBD>ܡ<EFBFBD><DCA1><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
// @note <09><>Ҫ<EFBFBD>ر<EFBFBD>ע<EFBFBD><D7A2>P20_2<5F>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD>
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
void gpio_init(PIN_enum pin, GPIODIR_enum dir, uint8 dat, GPIOMODE_enum pinmode)
|
||
{
|
||
IfxPort_Mode port_mode;
|
||
|
||
if(dir == GPI)
|
||
{
|
||
switch(pinmode)
|
||
{
|
||
case NO_PULL: port_mode = IfxPort_Mode_inputNoPullDevice; break;
|
||
case PULLUP: port_mode = IfxPort_Mode_inputPullUp; break;
|
||
case PULLDOWN: port_mode = IfxPort_Mode_inputPullDown; break;
|
||
default: port_mode = IfxPort_Mode_inputPullUp; break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
switch(pinmode)
|
||
{
|
||
case OPENDRAIN: port_mode = IfxPort_Mode_outputOpenDrainGeneral; break;//<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||
default: port_mode = IfxPort_Mode_outputPushPullGeneral; break;//Ĭ<><C4AC>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
}
|
||
}
|
||
|
||
IfxPort_setPinMode(get_port(pin), pin&0x1f, port_mode);
|
||
|
||
IfxPort_setPinPadDriver(get_port(pin), pin&0x1f, IfxPort_PadDriver_cmosAutomotiveSpeed1);
|
||
|
||
if(dir == GPO)
|
||
{
|
||
if(dat) IfxPort_setPinHigh(get_port(pin), pin&0x1f);
|
||
else IfxPort_setPinLow(get_port(pin), pin&0x1f);
|
||
}
|
||
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief GPIO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
||
// @param pin ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7> common.h <20><>PIN_enumö<6D><C3B6>ֵȷ<D6B5><C8B7>)
|
||
// @param pin_driver <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
|
||
// @return void
|
||
// Sample usage: gpio_pin_driver(P00_0, IfxPort_PadDriver_cmosAutomotiveSpeed1)
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
void gpio_pin_driver(PIN_enum pin, IfxPort_PadDriver pin_driver)
|
||
{
|
||
IfxPort_setPinPadDriver(get_port(pin), pin&0x1f, pin_driver);
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief GPIO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
// @param pin ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7> common.h <20><>PIN_enumö<6D><C3B6>ֵȷ<D6B5><C8B7>)
|
||
// @param dat 0<><30><EFBFBD>͵<EFBFBD>ƽ 1<><31><EFBFBD>ߵ<EFBFBD>ƽ
|
||
// @return void
|
||
// Sample usage: gpio_set(P00_0, 1);//P00_0 <20><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽ
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
void gpio_set(PIN_enum pin, uint8 dat)
|
||
{
|
||
if(dat) IfxPort_setPinHigh(get_port(pin), pin&0x1f);
|
||
else IfxPort_setPinLow(get_port(pin), pin&0x1f);
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief GPIO״̬<D7B4><CCAC>ȡ
|
||
// @param pin ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7> common.h <20><>PIN_enumö<6D><C3B6>ֵȷ<D6B5><C8B7>)
|
||
// @return uint8 0<><30><EFBFBD>͵<EFBFBD>ƽ 1<><31><EFBFBD>ߵ<EFBFBD>ƽ
|
||
// Sample usage: uint8 status = gpio_get(P00_0);//<2F><>ȡP00_0<5F><30><EFBFBD>ŵ<EFBFBD>ƽ
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
uint8 gpio_get(PIN_enum pin)
|
||
{
|
||
return IfxPort_getPinState(get_port(pin), pin&0x1f);
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief GPIO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
// @param pin ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7> common.h <20><>PIN_enumö<6D><C3B6>ֵȷ<D6B5><C8B7>)
|
||
// @param dir <20><><EFBFBD>ŵķ<C5B5><C4B7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPO <20><><EFBFBD>룺GPI
|
||
// @param pinmode <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>zf_gpio.h<>ļ<EFBFBD><C4BC><EFBFBD>GPIOMODE_enumö<6D><C3B6>ֵȷ<D6B5><C8B7><EFBFBD><EFBFBD>
|
||
// @return void
|
||
// Sample usage: gpio_dir(P00_0, GPO, PUSHPULL);//<2F><><EFBFBD><EFBFBD>P00_0Ϊ<30><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
void gpio_dir(PIN_enum pin, GPIODIR_enum dir, GPIOMODE_enum pinmode)
|
||
{
|
||
IfxPort_Mode port_mode;
|
||
|
||
if(dir == GPI)
|
||
{
|
||
switch(pinmode)
|
||
{
|
||
case NO_PULL: port_mode = IfxPort_Mode_inputNoPullDevice; break;
|
||
case PULLUP: port_mode = IfxPort_Mode_inputPullUp; break;
|
||
case PULLDOWN: port_mode = IfxPort_Mode_inputPullDown; break;
|
||
default: port_mode = IfxPort_Mode_inputPullUp; break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
switch(pinmode)
|
||
{
|
||
case OPENDRAIN: port_mode = IfxPort_Mode_outputOpenDrainGeneral; break;//<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||
default: port_mode = IfxPort_Mode_outputPushPullGeneral; break;//Ĭ<><C4AC>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
}
|
||
}
|
||
|
||
IfxPort_setPinMode(get_port(pin), pin&0x1f, port_mode);
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief GPIO <20><>ת
|
||
// @param pin ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7> common.h <20><>PIN_enumö<6D><C3B6>ֵȷ<D6B5><C8B7>)
|
||
// @return void
|
||
// Sample usage: gpio_toggle(P00_0);//P00_0<5F><30><EFBFBD>ŵ<EFBFBD>ƽ<EFBFBD><C6BD>ת
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
void gpio_toggle(PIN_enum pin)
|
||
{
|
||
IfxPort_togglePin(get_port(pin), pin&0x1f);
|
||
}
|
||
|
||
|
||
|