青风nrf52832跑zephyr——点亮LED
1 export ZEPHYR_GCC_VARIANT=zephyr 2 export ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk
2、编译
1 cd samples/bluetooth/peripheral 2 cmake -DBOARD=nrf52_pca10040 -H. -Bbuild 3 cd build 4 make menuconfig 5 make
1 gpio_dev = device_get_binding(CONFIG_GPIO_NRF5_P0_DEV_NAME);
1 (void) gpio_pin_configure(gpio_dev, 2 17, 3 (GPIO_DIR_OUT | GPIO_PUD_PULL_UP)); 4 (void) gpio_pin_configure(gpio_dev, 5 18, 6 (GPIO_DIR_OUT | GPIO_PUD_PULL_UP)); 7 (void) gpio_pin_configure(gpio_dev, 8 19, 9 (GPIO_DIR_OUT | GPIO_PUD_PULL_UP)); 10 (void) gpio_pin_configure(gpio_dev, 11 20, 12 (GPIO_DIR_OUT | GPIO_PUD_PULL_UP));
下面就可以操作gpio了,我们按pin来操作
1 gpio_pin_write(gpio_dev, 17 + (gpio_delay_pin % 4), gpio_delay % 2);
1 #include <zephyr/types.h> 2 #include <stddef.h> 3 #include <string.h> 4 #include <errno.h> 5 #include <misc/printk.h> 6 #include <misc/byteorder.h> 7 #include <zephyr.h> 8 9 #include <bluetooth/bluetooth.h> 10 #include <bluetooth/hci.h> 11 #include <bluetooth/conn.h> 12 #include <bluetooth/uuid.h> 13 #include <bluetooth/gatt.h> 14 15 #include <gatt/hrs.h> 16 #include <gatt/dis.h> 17 #include <gatt/bas.h> 18 19 #include <device.h> 20 #include <board.h> 21 #include <gpio.h> 22 23 24 25 26 #define DEVICE_NAME CONFIG_BT_DEVICE_NAME 27 #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) 28 29 struct bt_conn *default_conn; 30 31 static const struct bt_data ad[] = { 32 BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), 33 BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0x0d, 0x18, 0x0f, 0x18, 0x05, 0x18), 34 }; 35 36 static const struct bt_data sd[] = { 37 BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN), 38 }; 39 40 static void connected(struct bt_conn *conn, u8_t err) 41 { 42 if (err) { 43 printk("Connection failed (err %u)\n", err); 44 } else { 45 default_conn = bt_conn_ref(conn); 46 printk("Connected\n"); 47 } 48 } 49 50 static void disconnected(struct bt_conn *conn, u8_t reason) 51 { 52 printk("Disconnected (reason %u)\n", reason); 53 54 if (default_conn) { 55 bt_conn_unref(default_conn); 56 default_conn = NULL; 57 } 58 } 59 60 static struct bt_conn_cb conn_callbacks = { 61 .connected = connected, 62 .disconnected = disconnected, 63 }; 64 65 static void bt_ready(int err) 66 { 67 if (err) { 68 printk("Bluetooth init failed (err %d)\n", err); 69 return; 70 } 71 72 printk("Bluetooth initialized\n"); 73 74 hrs_init(0x01); 75 bas_init(); 76 dis_init(CONFIG_SOC, "Manufacturer"); 77 78 err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), 79 sd, ARRAY_SIZE(sd)); 80 if (err) { 81 printk("Advertising failed to start (err %d)\n", err); 82 return; 83 } 84 85 printk("Advertising successfully started\n"); 86 } 87 88 static void auth_cancel(struct bt_conn *conn) 89 { 90 char addr[BT_ADDR_LE_STR_LEN]; 91 92 bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); 93 94 printk("Pairing cancelled: %s\n", addr); 95 } 96 97 static struct bt_conn_auth_cb auth_cb_display = { 98 .cancel = auth_cancel, 99 }; 100 101 void main(void) 102 { 103 int err; 104 int gpio_delay = 0; 105 int gpio_delay_pin = 0; 106 struct device *gpio_dev; 107 108 err = bt_enable(bt_ready); 109 if (err) { 110 printk("Bluetooth init failed (err %d)\n", err); 111 return; 112 } 113 114 bt_conn_cb_register(&conn_callbacks); 115 bt_conn_auth_cb_register(&auth_cb_display); 116 117 /* 118 * 添加个人测试代码,LED闪烁测试 119 */ 120 121 gpio_dev = device_get_binding(CONFIG_GPIO_NRF5_P0_DEV_NAME); 122 123 (void) gpio_pin_configure(gpio_dev, 124 17, 125 (GPIO_DIR_OUT | GPIO_PUD_PULL_UP)); 126 (void) gpio_pin_configure(gpio_dev, 127 18, 128 (GPIO_DIR_OUT | GPIO_PUD_PULL_UP)); 129 (void) gpio_pin_configure(gpio_dev, 130 19, 131 (GPIO_DIR_OUT | GPIO_PUD_PULL_UP)); 132 (void) gpio_pin_configure(gpio_dev, 133 20, 134 (GPIO_DIR_OUT | GPIO_PUD_PULL_UP)); 135 136 137 /* Implement notification. At the moment there is no suitable way 138 * of starting delayed work so we do it here 139 */ 140 while (1) { 141 k_sleep(MSEC_PER_SEC); 142 143 gpio_delay++; 144 gpio_delay = gpio_delay % 2; 145 gpio_pin_write(gpio_dev, 17 + (gpio_delay_pin % 4), gpio_delay % 2); 146 if(gpio_delay == 0) 147 { 148 gpio_delay_pin++; 149 } 150 151 /* Heartrate measurements simulation */ 152 hrs_notify(); 153 154 /* Battery level simulation */ 155 bas_notify(); 156 } 157 }
转载于:https://www.cnblogs.com/skawu/p/8110540.html
青风nrf52832跑zephyr——点亮LED相关推荐
- cortex-A8的第一个裸跑程序——点亮LED灯
@****************************************************************************** @ File:led_on.S @ 功能 ...
- STM8S自学笔记-003 GPIO输出:点亮LED灯 and 跑马灯特效
STM8S自学笔记-003 GPIO输出:点亮LED灯 and 跑马灯特效 点亮LED GPIO初始化函数:GPIO_Init() GPIO电平操作库函数:GPIO_WriteHigh().GPIO_ ...
- STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)
系列文章目录 STM32F103ZE学习记录:主要参考正点原子教程 文章目录 系列文章目录 前言 一.环境的搭建 1.新建编程文件操作步骤 2.ST_LINK烧录搭建 3.STlink下载出现st-l ...
- 【嵌入式08】STM32F103C8T6寄存器方式借助面包板点亮LED流水灯详解
文章目录 一.题目简述 二.简述:初始化GPIO,点亮LED灯 三.工程文件模板的建立 四.使用寄存器点亮LED灯--代码部分 1.硬件连接设计 2.打开之前建立的工程模板 3.代码编写 4.硬件连接 ...
- STM32F103寄存器方式点亮LED流水灯
实验要求:以 STM32最小系统核心板(STM32F103C8T6)+面板板+3只红绿蓝LED 搭建电路,使用GPIOB.GPIOC.GPIOD这3个端口控制LED灯,轮流闪烁,间隔时长1秒.1)写出 ...
- S5PV210-NoOS-一步一步点亮LED
LED特性 电流从LED正流向LED负,LED就发光,没有电流就不亮. 原理图 最下面一颗是电源指示灯,上面三个普通IO口.LED4为PWM调节,可以用来调亮度. 如何点亮LED? 把GPJ0_3写成 ...
- 一步步点亮LED3_从零开始手写汇编点亮LED
1.GPxCON.GPxDAT寄存器分析 GPJ0端口一共有8个引脚,分别记作:GPJ0_0 ~ GPJ0_7,相关重要寄存器就是GPJ0CON和GPJ0DAT GPJ0CON寄存器中设置8个引脚的工 ...
- 【小月电子】安路国产FPGA开发板系统学习教程-LESSON1点亮LED灯
点亮LED灯例程讲解 若要观看该博客配套的视频教程,可点击此链接 根据多年工作经验,总结出的FPGA的设计流程,概括起来总共有以上12步,其中根据项目难易度可省去其中一些步骤.比如非常简单的项目,我们 ...
- 青风nrf51822开发板学习记录
青风开发板上LED引脚/LED端口定义 #define LED_START 18 #define LED_0 18 #define LED_1 19 #d ...
最新文章
- 低调!中国北斗核心卫星部署完成,开启“全球时代”!超越GPS指日可待
- JVM - 应用JVM核心参数推荐设置
- C# 扩展集合ObservableCollection使集合在添加、删除、值变更后触发事件
- 新增操作 失败后重试_可重试的操作
- 【POJ - 3352】Road Construction(Tarjan,边双连通分量)
- 毕设ssm商城系统_ssm商城系统(爱淘淘购物)项目源码
- python使用hash256加密验证字符串
- ConcurrentModificationException的情况
- 拆分SharePoint 2013 中CreatedModifiedInfo 的时间
- 一个简单的文本编译器
- AJAX在IE下的调试
- lenovo L480 进入bios_利用微星主板自带的 M-Flash BIOS工具升级BIOS
- js设置cookie值 判断登陆
- JDY-31蓝牙模块测试
- php存省市,PHP格式化全国省市区列表
- ng : 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\ng.ps1,因为在此系统上禁止运行脚本
- 主引导扇区程序代码优化-2
- POI - Excel 打印配置
- R语言并行计算实战教程
- PHP unlink的使用
热门文章
- 2,2‘-联噻吩-5,5’-二甲醛|cas32364-72-0 中间体材料
- 约瑟夫环问题逢七过小游戏
- 台湾清华大学彭明辉教授的研究生手册
- 自己公司的gitlab和官网gitlab都是以下的操作步骤!(我是自己公司的gitlab已成功)
- Python 官方中文教程(简)
- 迁移数据库报错解决方案
- 微博视频发布软件有哪些
- 在家打LOL的ping很高老是掉线怎么办?(亲测有一定效果)PC打游戏延迟很高怎么办?(有通用性)
- 下一代GIS的思考-周成虎院士报告
- 题目:在BlossimView系统中实时显示全国各省会的天气