在线时间796 小时
UID3067179
注册时间2014-10-23
NXP金币1063
TA的每日心情 | 开心 2024-4-26 23:45 |
---|
签到天数: 1318 天 [LV.10]以坛为家III
版主
- 积分
- 7575
- 最后登录
- 2024-4-27
|
这篇来学习开发板硬件上的LED驱动程序。
一 、硬件部分
在zephyr的sample\basic\blinky例程是测试板卡上的LED指示灯的。
1.1、lpcxpresso55s36板卡对应的LED硬件端口配置
root@ubuntu:~/zephyrproject/zephyr/boards/arm/lpcxpresso55s36#
lpcxpresso55s36.dts文件内LED端口的定义
1.2、DIY板卡的LED硬件端口
将上面的文件修改成自己板卡的硬件端口
二、程序部分
测试程序修改sample\basic\blinky\src\main.c代码
mian.c
- /*
- * Copyright (c) 2016 Intel Corporation
- *
- * SPDX-License-Identifier: Apache-2.0
- */
- #include <zephyr/kernel.h>
- #include <zephyr/drivers/gpio.h>
- /* 1000 msec = 1 sec */
- #define SLEEP_TIME_MS 500
- /* The devicetree node identifier for the "led0" alias. */
- #define LED0_NODE DT_ALIAS(led0)
- #define LED1_NODE DT_ALIAS(led1)
- #define LED2_NODE DT_ALIAS(led2)
- #define LED3_NODE DT_ALIAS(led3)
- /*
- * A build error on this line means your board is unsupported.
- * See the sample documentation for information on how to fix this.
- */
- static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
- static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios);
- static const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(LED2_NODE, gpios);
- static const struct gpio_dt_spec led3 = GPIO_DT_SPEC_GET(LED3_NODE, gpios);
- void main(void)
- {
-
- gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE);
- gpio_pin_configure_dt(&led1, GPIO_OUTPUT_ACTIVE);
- gpio_pin_configure_dt(&led2, GPIO_OUTPUT_ACTIVE);
- gpio_pin_configure_dt(&led3, GPIO_OUTPUT_ACTIVE);
- gpio_pin_set_dt(&led0, 0);
- gpio_pin_set_dt(&led1, 1);
- gpio_pin_set_dt(&led2, 0);
- gpio_pin_set_dt(&led3, 1);
- while (1) {
-
- gpio_pin_toggle_dt(&led0);
- gpio_pin_toggle_dt(&led1);
- gpio_pin_toggle_dt(&led2);
- gpio_pin_toggle_dt(&led3);
- k_msleep(SLEEP_TIME_MS);
- }
- }
复制代码
三、编译和下载
执行命令:
root@ubuntu:~/zephyrproject/zephyr# west build -p auto -b lpcxpresso55s36 /opt/zephyrprj/blinky/
root@ubuntu:~/zephyrproject/zephyr# west flash
四、程序运行
LED指示灯交替点亮。
|
|