本帖最后由 zhouminjie 于 2024-6-15 01:25 编辑
首次使用GeehyMCU,官网资料比较丰富,
开始点灯测试,官网下载SDK开发工具包,解压后在keil中安装F4系列Pack包,新建keil工程文件,添加SDK解压包中Libraries文件夹中.c.h等相关文件到工程中,
点灯部分代码如下:
#include "bsp_led.h"
GPIO_T *led_gpio_port[LED_NUM] =
{
LED_1_GPIO, LED_2_GPIO,
};
const uint16_t led_gpio_pin[LED_NUM] =
{
LED_1_PIN, LED_2_PIN,
};
const uint32_t led_gpio_crm_clk[LED_NUM] =
{
LED_1_GPIO_CRM_CLK, LED_2_GPIO_CRM_CLK,
};
// 不同芯片厂家修改
static void led_init(LED_TYPEDEF led)
{
GPIO_Config_T gpio_init_struct;
/* enable the led clock */
RCM_EnableAHB1PeriphClock(led_gpio_crm_clk[led]);
/* set default parameter */
GPIO_ConfigStructInit(&gpio_init_struct);
/* configure the led gpio */
gpio_init_struct.mode = GPIO_MODE_OUT;
gpio_init_struct.pin = led_gpio_pin[led];
gpio_init_struct.speed = GPIO_SPEED_50MHz;
GPIO_Config(led_gpio_port[led], &gpio_init_struct);
}
//
static void led_on(LED_TYPEDEF led)
{
if(led > (LED_NUM - 1))
return;
if(led_gpio_pin[led])
led_gpio_port[led]->BSCH = led_gpio_pin[led];
}
//
static void led_off(LED_TYPEDEF led)
{
if(led > (LED_NUM - 1))
return;
if(led_gpio_pin[led])
led_gpio_port[led]->BSCL = led_gpio_pin[led];
}
//
static void led_toggle(LED_TYPEDEF led)
{
if(led > (LED_NUM - 1))
return;
if(led_gpio_pin[led])
led_gpio_port[led]->ODATA ^= led_gpio_pin[led];
}
//
void bsp_led_on(LED_TYPEDEF led)
{
led_on(led);
}
//
void bsp_led_off(LED_TYPEDEF led)
{
led_off(led);
}
//
void bsp_led_toggle(LED_TYPEDEF led)
{
led_toggle(led);
}
//
void bsp_Init_GPIO_Led(void)
{
LED_TYPEDEF i;
for(i = LED_1; i < LED_NUM; i++)
{
led_init(i);
led_off(i);
}
}
#include "drv_led.h"
unsigned short Led_Dark[] = {0, 2, LED_EFFECT_END};
unsigned short Led_Light[] = {1, 2, LED_EFFECT_END};
unsigned short Led_Blink[] = {1, 1000 / LED_PROC_TICK, 0, 1000 / LED_PROC_TICK, LED_EFFECT_END};
//unsigned short Led_Blink2[] = {1,10,0,10,1,10,0,210,LED_EFFECT_AGN,4};
unsigned short Led_Blink3[] = {1, 1000 / LED_PROC_TICK, 0, 1000 / LED_PROC_TICK, LED_EFFECT_AGN, 2};
unsigned short LedTimer[LED_NUM]; //灯状态保持的时间
unsigned short *pLed[LED_NUM]; //灯状态
//
static void LedDrive(LED_TYPEDEF led, unsigned char state)
{
if(state)
{
bsp_led_on(led);
}
else
{
bsp_led_off(led);
}
}
//
void (*drv_LedDrive[])(LED_TYPEDEF, unsigned char) =
{
LedDrive, // LED1
LedDrive, // LED2
};
// LED特效控制
void drv_LedControl(LED_TYPEDEF LedIdx, LED_EFFECT_TEPEDEF State)
{
switch(State)
{
case LED_DARK:
pLed[LedIdx] = (unsigned short *)Led_Dark;
LedTimer[LedIdx] = *(pLed[LedIdx] + 1);
break;
case LED_LIGHT:
pLed[LedIdx] = (unsigned short *)Led_Light;
LedTimer[LedIdx] = *(pLed[LedIdx] + 1);
break;
case LED_BLINK:
pLed[LedIdx] = (unsigned short *)Led_Blink;
LedTimer[LedIdx] = *(pLed[LedIdx] + 1);
break;
case LED_BLINK3:
pLed[LedIdx] = (unsigned short *)Led_Blink3;
LedTimer[LedIdx] = *(pLed[LedIdx] + 1);
break;
default:
break;
}
}
//
void drv_Init_Led(void)
{
LED_TYPEDEF i;
bsp_Init_GPIO_Led();
for(i = LED_1; i < LED_NUM; i++)
{
drv_LedControl(i, LED_BLINK);
}
}
//
void drv_Led_All_Off(void)
{
LED_TYPEDEF i;
for(i = LED_1; i < LED_NUM; i++)
{
drv_LedControl(i, LED_DARK);
}
}
//
void drv_Led_All_On(void)
{
LED_TYPEDEF i;
for(i = LED_1; i < LED_NUM; i++)
{
drv_LedControl(i, LED_LIGHT);
}
}
//
void drv_Led_All_Blink(void)
{
LED_TYPEDEF i;
for(i = LED_1; i < LED_NUM; i++)
{
drv_LedControl(i, LED_BLINK3);
}
}
//
void drv_LedProc(void)
{
LED_TYPEDEF i;
for(i = LED_1; i < LED_NUM; i++)
{
if(LedTimer[i])
{
LedTimer[i]--;
}
else
{
//定时时间到
if(*(pLed[i] + 2) == LED_EFFECT_END)
{
//Led_Light[] = {1,10,LED_EFFECT_END};
}
else
{
pLed[i] += 2;
if(*pLed[i] == LED_EFFECT_AGN)
{
pLed[i] = pLed[i] - (*(pLed[i] + 1) * 2);
}
LedTimer[i] = *(pLed[i] + 1);
}
}
drv_LedDrive[i](i, *pLed[i]);
}
}
代码工程:
TEST_LED.rar
(7.78 MB)
|