1.设备树引入:
zephyr不同于常用的RTOS,pin脚定义部分需要配合dts,config,yaml等文件结合实现但是有着超强的可移植性。
pin脚定义如下
test0: testpin {
compatible = "gpio-outputs";
testpin: testpin0 {
gpios = <&gpio_prt3 GPIO_ACTIVE_HIGH>;
label = "my label";
};
};
2.yaml的引入:
我的理解是yaml相当于dts和c文件沟通的桥梁,每新建一个模块的dts需要实施更新对应的yaml
description: |
This allows you to control a gpio pin
compatible: "gpio-outputs"
child-binding:
description: |
GPIO output child node
properties:
gpios:
type: phandle-array
required: true
description: |
pin function
label:
required: false
type: string
description: |
gpio function.
3.main.c
#define MYPIN DT_NODELABEL(testpin)
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(gpiopin,gpiotest);
gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
while(1)
{
//灯闪烁
gpio_pin_toggle_dt(&led);
}