本篇分享一个简单的点灯之旅。
首先,我们新建一个空白的(模板)项目:
在新建的工程,左下角可以看到:Device Configurator 4.0
没错,这就是英飞凌Modus Toolbox的图形化配置工具,类似意法半导体的CubeMX
在Device Configurator 界面,我们可以看到熟悉的画面。
外设设置
管脚设置
时钟设置
DMA设置
设置好后,对应的右侧就自动生成了可用的代码。
/* NOTE: This is a preview only. It combines elements of the
* cycfg_pins.c and cycfg_pins.h files located in the folder
* C:/Users/Administrator/InfineonWork/00/libs/TARGET_CY8CKIT-041S-MAX/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource.
*/
#include "cy_gpio.h"
#if defined (CY_USING_HAL)
#include "cyhal_hwmgr.h"
#endif //defined (CY_USING_HAL)
#define ioss_0_port_6_pin_4_PORT GPIO_PRT6
#define ioss_0_port_6_pin_4_PORT_NUM 6U
#define ioss_0_port_6_pin_4_PIN 4U
#define ioss_0_port_6_pin_4_NUM 4U
#define ioss_0_port_6_pin_4_DRIVEMODE CY_GPIO_DM_PULLDOWN_IN_OFF
#define ioss_0_port_6_pin_4_INIT_DRIVESTATE 1
#ifndef ioss_0_port_6_pin_4_HSIOM
#define ioss_0_port_6_pin_4_HSIOM HSIOM_SEL_GPIO
#endif
#define ioss_0_port_6_pin_4_IRQ ioss_interrupt_gpio_IRQn
#if defined (CY_USING_HAL)
#define ioss_0_port_6_pin_4_HAL_PORT_PIN P6_4
#define ioss_0_port_6_pin_4 P6_4
#define ioss_0_port_6_pin_4_HAL_IRQ CYHAL_GPIO_IRQ_NONE
#define ioss_0_port_6_pin_4_HAL_DIR CYHAL_GPIO_DIR_OUTPUT
#define ioss_0_port_6_pin_4_HAL_DRIVEMODE CYHAL_GPIO_DRIVE_PULLDOWN
#endif //defined (CY_USING_HAL)
const cy_stc_gpio_pin_config_t ioss_0_port_6_pin_4_config =
{
.outVal = 1,
.driveMode = CY_GPIO_DM_PULLDOWN_IN_OFF,
.hsiom = ioss_0_port_6_pin_4_HSIOM,
.intEdge = CY_GPIO_INTR_DISABLE,
.vtrip = CY_GPIO_VTRIP_CMOS,
.slewRate = CY_GPIO_SLEW_FAST,
.vregEn = 0UL,
.ibufMode = 0UL,
.vtripSel = 0UL,
.vrefSel = 0UL,
.vohSel = 0UL,
};
#if defined (CY_USING_HAL)
const cyhal_resource_inst_t ioss_0_port_6_pin_4_obj =
{
.type = CYHAL_RSC_GPIO,
.block_num = ioss_0_port_6_pin_4_PORT_NUM,
.channel_num = ioss_0_port_6_pin_4_PIN,
};
#endif //defined (CY_USING_HAL)
void init_cycfg_pins(void)
{
Cy_GPIO_Pin_Init(ioss_0_port_6_pin_4_PORT, ioss_0_port_6_pin_4_PIN, &ioss_0_port_6_pin_4_config);
}
void reserve_cycfg_pins(void)
{
#if defined (CY_USING_HAL)
cyhal_hwmgr_reserve(&ioss_0_port_6_pin_4_obj);
#endif //defined (CY_USING_HAL)
}
本例完成简单的点灯之旅,因功能极其简单,就直接用HAL函数了。
cy_gpio.h
#include "cy_pdl.h"
#include "cybsp.h"
#include "cy_gpio.h"
int main(void)
{
Cy_GPIO_Pin_FastInit(GPIO_PRT6,4u,CY_GPIO_DM_PULLDOWN,0,0); //P6.4下拉,功能为IO,初始值0
Cy_GPIO_Pin_FastInit(GPIO_PRT12,0u,CY_GPIO_DM_PULLDOWN,0,0); //P12.0下拉,功能为IO,初始值0
for (;;)
{
Cy_GPIO_Inv(GPIO_PRT6, 4u);
Cy_GPIO_Inv(GPIO_PRT12, 0u);
/* Wait for 0.5 seconds */
Cy_SysLib_Delay(500);
}
}
编译运行就可以看到LED2(P6.4),LED3(P12.0)闪烁了。
点灯