【EFM32 Zero Gecko Starter Kit】-2-搭建开发环境
[复制链接]
本帖最后由 __lwl 于 2024-3-24 15:46 编辑
目前SiliconLabs芯片推荐的开发IDE是Simplicity Studio V5,下载安装过程比较漫长。
、
安装好之后板子通过USB-B - USB A连接至电脑后,可以看到IDE正确识别开发板。
接着新建一个空白工程:
Simplicity studio V5提供了“Software Component”的功能,这里面把常见的硬件外设包括片上的或者板级的外设进行了模块化。
比如通过搜索LED,然后右上角点击Install,即可进入LED配置界面,比如分配GPIO引脚等。
接下来熟悉一下按键输入触发中断,首先配置按键输入引脚,以及工作模式:
从原理图可以看出,按键0连接到PC8,按键1连接到PC9。接下来回到Simplicity Studio V5。
点击保存后,自动生成代码:
#include "sl_simple_button.h"
#include "sl_simple_button_btn0_config.h"
#include "sl_simple_button_btn1_config.h"
sl_simple_button_context_t simple_btn0_context = {
.state = 0,
.history = 0,
.port = SL_SIMPLE_BUTTON_BTN0_PORT,
.pin = SL_SIMPLE_BUTTON_BTN0_PIN,
.mode = SL_SIMPLE_BUTTON_BTN0_MODE,
};
const sl_button_t sl_button_btn0 = {
.context = &simple_btn0_context,
.init = sl_simple_button_init,
.get_state = sl_simple_button_get_state,
.poll = sl_simple_button_poll_step,
.enable = sl_simple_button_enable,
.disable = sl_simple_button_disable,
};
sl_simple_button_context_t simple_btn1_context = {
.state = 0,
.history = 0,
.port = SL_SIMPLE_BUTTON_BTN1_PORT,
.pin = SL_SIMPLE_BUTTON_BTN1_PIN,
.mode = SL_SIMPLE_BUTTON_BTN1_MODE,
};
const sl_button_t sl_button_btn1 = {
.context = &simple_btn1_context,
.init = sl_simple_button_init,
.get_state = sl_simple_button_get_state,
.poll = sl_simple_button_poll_step,
.enable = sl_simple_button_enable,
.disable = sl_simple_button_disable,
};
// the table of buttons and button count are generated as a
// convenience for the application
const sl_button_t *sl_simple_button_array[] = {
&sl_button_btn0,
&sl_button_btn1
};
const uint8_t simple_button_count = 2;
void sl_simple_button_init_instances(void)
{
sl_button_init(&sl_button_btn0);
sl_button_init(&sl_button_btn1);
}
void sl_simple_button_poll_instances(void)
{
sl_button_poll_step(&sl_button_btn0);
sl_button_poll_step(&sl_button_btn1);
}
对于按键中断处理与液晶显示:
/***************************************************************************//**
* Callback on button change.
*
* This function overrides a weak implementation defined in the simple_button
* module. It is triggered when the user activates one of the buttons.
*
******************************************************************************/
void sl_button_on_change(const sl_button_t *handle)
{
if (sl_button_get_state(handle) == SL_SIMPLE_BUTTON_PRESSED) {
if (&BUTTON_INSTANCE_0 == handle) {
currentLine = 0;
GLIB_clear(&glibContext);
} else if (&BUTTON_INSTANCE_1 == handle) {
GLIB_drawStringOnLine(&glibContext,
"BtnPressed!",
currentLine++,
GLIB_ALIGN_LEFT,
5,
5,
true);
}
DMD_updateDisplay();
}
}
实物测试:
待完善。
|