青风nrf52832跑zephyr——点亮LED
export ZEPHYR_GCC_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk
2、编译
cd samples/bluetooth/peripheral
cmake -DBOARD=nrf52_pca10040 -H. -Bbuild
cd build
make menuconfig
make
gpio_dev = device_get_binding(CONFIG_GPIO_NRF5_P0_DEV_NAME);
(void) gpio_pin_configure(gpio_dev,
,
(GPIO_DIR_OUT | GPIO_PUD_PULL_UP));
(void) gpio_pin_configure(gpio_dev,
,
(GPIO_DIR_OUT | GPIO_PUD_PULL_UP));
(void) gpio_pin_configure(gpio_dev,
,
(GPIO_DIR_OUT | GPIO_PUD_PULL_UP));
(void) gpio_pin_configure(gpio_dev,
,
(GPIO_DIR_OUT | GPIO_PUD_PULL_UP));
下面就可以操作gpio了,我们按pin来操作
gpio_pin_write(gpio_dev, + (gpio_delay_pin % ), gpio_delay % );
#include <zephyr/types.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <misc/printk.h>
#include <misc/byteorder.h>
#include <zephyr.h> #include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/conn.h>
#include <bluetooth/uuid.h>
#include <bluetooth/gatt.h> #include <gatt/hrs.h>
#include <gatt/dis.h>
#include <gatt/bas.h> #include <device.h>
#include <board.h>
#include <gpio.h> #define DEVICE_NAME CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) struct bt_conn *default_conn; static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0x0d, 0x18, 0x0f, 0x18, 0x05, 0x18),
}; static const struct bt_data sd[] = {
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
}; static void connected(struct bt_conn *conn, u8_t err)
{
if (err) {
printk("Connection failed (err %u)\n", err);
} else {
default_conn = bt_conn_ref(conn);
printk("Connected\n");
}
} static void disconnected(struct bt_conn *conn, u8_t reason)
{
printk("Disconnected (reason %u)\n", reason); if (default_conn) {
bt_conn_unref(default_conn);
default_conn = NULL;
}
} static struct bt_conn_cb conn_callbacks = {
.connected = connected,
.disconnected = disconnected,
}; static void bt_ready(int err)
{
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
return;
} printk("Bluetooth initialized\n"); hrs_init(0x01);
bas_init();
dis_init(CONFIG_SOC, "Manufacturer"); err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad),
sd, ARRAY_SIZE(sd));
if (err) {
printk("Advertising failed to start (err %d)\n", err);
return;
} printk("Advertising successfully started\n");
} static void auth_cancel(struct bt_conn *conn)
{
char addr[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); printk("Pairing cancelled: %s\n", addr);
} static struct bt_conn_auth_cb auth_cb_display = {
.cancel = auth_cancel,
}; void main(void)
{
int err;
int gpio_delay = ;
int gpio_delay_pin = ;
struct device *gpio_dev; err = bt_enable(bt_ready);
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
return;
} bt_conn_cb_register(&conn_callbacks);
bt_conn_auth_cb_register(&auth_cb_display); /*
* 添加个人测试代码,LED闪烁测试
*/ gpio_dev = device_get_binding(CONFIG_GPIO_NRF5_P0_DEV_NAME); (void) gpio_pin_configure(gpio_dev,
,
(GPIO_DIR_OUT | GPIO_PUD_PULL_UP));
(void) gpio_pin_configure(gpio_dev,
,
(GPIO_DIR_OUT | GPIO_PUD_PULL_UP));
(void) gpio_pin_configure(gpio_dev,
,
(GPIO_DIR_OUT | GPIO_PUD_PULL_UP));
(void) gpio_pin_configure(gpio_dev,
,
(GPIO_DIR_OUT | GPIO_PUD_PULL_UP)); /* Implement notification. At the moment there is no suitable way
* of starting delayed work so we do it here
*/
while () {
k_sleep(MSEC_PER_SEC); gpio_delay++;
gpio_delay = gpio_delay % ;
gpio_pin_write(gpio_dev, + (gpio_delay_pin % ), gpio_delay % );
if(gpio_delay == )
{
gpio_delay_pin++;
} /* Heartrate measurements simulation */
hrs_notify(); /* Battery level simulation */
bas_notify();
}
}


青风nrf52832跑zephyr——点亮LED的更多相关文章
- 第7章 使用寄存器点亮LED灯
第7章 使用寄存器点亮LED灯 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fir ...
- 第7章 使用寄存器点亮LED灯—零死角玩转STM32-F429系列
第7章 使用寄存器点亮LED灯 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fir ...
- Arduino 极速入门系列–1 点亮 LED
本篇内容为,使用 Arduino 点亮 LED 的做法示范.很简单的一个入门示范.我们让 LED 闪. 本篇使用到的工具和材料 Arduino Mini Pro 1 PCS Mini USB 数据线 ...
- STM32学习笔记——点亮LED
STM32学习笔记——点亮LED 本人学习STM32是直接通过操作stm32的寄存器,使用的开发板是野火ISO-V2版本: 先简单的介绍一下stm32的GPIO: stm32的GPIO有多种模式: 1 ...
- STM32F407第一步之点亮LED
STM32F407第一步之点亮LED. 要点亮LED,首先了解一下F4的GPIO模块.首先看一下STM32F4数据手册,GPIO模块的内部结构图 看上去有点复杂,不要怕,慢慢理解就可以了.对外引脚那里 ...
- ARM学习篇一 点亮LED
要点亮LED,先决条件是什么,当然得有相应的硬件设施.板子的整个电路图比较大,我就直接取相关部分. 给发光二级管加上3.3v电压后,通过1k电阻,直接与S3C2440连接.至于为什么要加电阻,大家应该 ...
- zigbee学习之路(二)点亮LED
一.前言 今天,我来教大家如何点亮led,这也是学习开发板最基础的步骤了. 二.原理分析 cc2530芯片跟虽然是51的内核,但是它跟51单片机还是有区别的,51单片机不需要对IO口进行配置,而cc2 ...
- MSP430F5438点亮led
今天只是想点亮一个led灯,因为没有视频,搞得很多的东西都是自己摸,下午本来讲和咨询店家,TMD说好给一点技术支持,结果一点也不给,我真想草泥马了,其实代码早就写出来了,只是哥哥不知道这款开发板还有接 ...
- JZ2440开发笔记(5)——通过按键点亮LED
在JZ2440中,点亮LED就是给LED的控制位设置为输出,数据位设置为低电平,而通过按键点亮LED,就需要将按键对应的控制位设置为输出. 下面是JZ2440的3个LED电路图: 下面是JZ2440的 ...
随机推荐
- linux卸载Python3
一.卸载Python3 1.卸载python3 rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps 卸载pyhton3 2.whereis ...
- [笔记] Ubuntu机器添加新硬盘安装流程
SSD虽然快,但是容量不够用,买了块希捷4TB的机械硬盘,准备给台机扩容. 安装环境 OS: Ubuntu 18.04 安装新硬盘 问了客服,原来这款机箱已经带了硬盘滑槽,不需要固定螺钉了. 买了SA ...
- @ComponentScan 注解
在配置类上添加 @ComponentScan 注解.该注解默认会扫描该类所在的包下所有的配置类,相当于xml的 <context:component-scan>. @ComponentSc ...
- logistics二分类
binaryclassification #DATASET: https://archive.ics.uci.edu/ml/datasets/Glass+Identificationimport nu ...
- django中Queryset的删除问题、分页问题
在开发选课界面时需要过滤掉已经选择过的课程,之前一直以为QuerySet是列表的结构,所以打算在判断之后使用list.remove()方法将已选的课程除掉,但在实际操作时,发现这么做并不行,原来Que ...
- 第五周课程总结&试验报告三
第五周课程总结 一.第五周课程总结 1.this关键字 this可用于任何实例方法内指向当前对象,也可指向对其调用当前方法的对象,或者在需要当前类型对象引用时使用.当一个类的属性(成员变量)名与访问该 ...
- C关于字符串操作的库函数实现总结
常用C关于字符串操作的库函数实现: //获取字符串长度 int Strlen(const char* s) { assert(s != NULL); ; while (*s++ != '\0') { ...
- 编写java 程序与Linux进行远程连接并运行linux下的脚本
我这里是通过连接到centos6.5的大数据集群的主节点,并通过运行hadoop的启动脚本来启动hadoop 本人采用的是SSH的方式连接 通过创建maven项目来编写代码,在编写代码之前需要先导入架 ...
- Spring 中的几个常用的钩子接口
1.Aware接口 Awear 这个单词的意思是知道的,所以可以猜想以Awear 结尾的接口意思可以把他知道的东西告诉我们.常用的Awear接口有 ApplicationContextAware和 B ...
- mysql大数据量插入参考
Mysql 千万数据10秒批量插入只需三步第一步:配置my.ini文件文件中配置bulk_insert_buffer_size=120M 或者更大将insert语句的长度设为最大.Max_allowe ...