Note
This library is obsolete and should not be used in new designs. Instead, you should use GPIOTE driver.

The general purpose Input/Output is organized in the nRF51 Series chips as one port with up to 32 I/Os (dependent on package) enabling access and control of up to 32 pins through one port. In most applications, the state of a GPIO or a change in state of a GPIO may trigger an application to take action or transition to another state.

The GPIO Tasks and Events (GPIOTE) provides functionality for accessing GPIO pins using tasks and events. The GPIO Task & Events (GPIOTE) library referred to as the the 'app_gpiote' in the SDK, facilitates application(s) to register for notification of change in state of one or more pins.

Since an application can consist of multiple independent modules, GPIOTE library allows several components to share the GPIOTE interrupt,each user defining a set of pins able to generate events to the user. When a GPIOTE interrupt occurs, the GPIOTE interrupt handler will identify pin transition(S) and notify each client registered for the transition.

Note
Components that register with the library are henceforth referred to as clients or users.
This library uses GPIOTE driver, which must be enabled and properly configured in nrf_drv_config.h. You must specify GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS, which is the number of pins used for low power EVENTS_PORT including the pins used by this library.

Figure 1: Users are being notified of a pin transition event.

The GPIOTE users are responsible for configuring all their corresponding pins, except the SENSE field, which should be initialized to GPIO_PIN_CNF_SENSE_Disabled.

The module specifies on which pins events should be generated if the pin(s) goes from low->high or high->low or both directions.

Note
Even if the application is using the Scheduler, the GPIOTE event handlers will be called directly from the GPIOTE interrupt handler.
尽管应用使用了Scheduler,但是GPTOTE的事件句柄还是直接来自GPTOTE中断句柄。

Initializing GPIOTE module

The initialization procedure must be performed before using any of the other APIs of the module. It is recommended to use initialization macro APP_GPIOTE_INIT instead of the routine app_gpiote_init as the former takes care of reserving needed memory for the each user requested in the MAX_USERS parameter of the macro. This parameter indicates how may users are going to be registering with the library.

// Macro to initialize GPIOTE module and reserving necessary memory for each of user.
APP_GPIOTE_INIT(MAX_USERS); 
Note
Module initialization should be performed only once. Specifically when using the macro to avoid reserving memory for each module several times.

Registering with GPIOTE

Each user must register itself with the module to be notified of change in state of GPIO. During registry, the user must provide callback handler to notify of a transition event and pin transitions its is interested in. 32-bit bitmask is used to represent 32 GPIO pins as shown in Figure 2 below. User can register for transition from high to low and/or low to high.

Figure 2: GPIO Pin representation using 32-bit bitmask.

On successful registration, the user is assigned a user id and the user is expected to remember this identifier for all subsequent requests made to the module. This identifier is provided in the out parameter p_user_id. A sample registration is shown below.

// GPIOTE user identifier for the example module.
static app_gpiote_user_id_t m_example_user_id;
// GPIOTE event handler.
static void example_gpiote_event_handler(uint32_t event_pins_low_to_high, uint32_t event_pins_high_to_low);
.
.
.
uint32_t low_to_high_bitmask = 0x0000000F; // Bitmask to be notified of transition from low to high for GPIO 0-3
uint32_t high_to_low_bitmask = 0x0000000E; // Bitmask to be notified of transition from high to low for GPIO 0-2
uint32_t retval;
retval = app_gpiote_user_register(&m_example_user_id,
low_to_high_bitmask,
high_to_low_bitmask,
example_gpiote_event_handler);
if (retval != NRF_SUCCESS)
{
// Failed to register with user with GPIO module!
}

Note

It is possible for more than one user to register for same set/subset of GPIO pins; each of the concerned users will be notified of pin transition events.

By default, the GPIOTE is disabled on initialization. Therefore the GPIOTE has to be enabled by one of the users to start receiving GPIOTE state events. app_gpiote_user_enable is used to enable GPIOTE.

The following is a sample of registered user callback handling pin transition events.

// GPIOTE event handler.
void example_gpiote_event_handler (uint32_t event_pins_low_to_high, uint32_t event_pins_high_to_low)
{
    .
    .
    .
    if (event_pins_low_to_high & 0x00000001)
    {
         // GPIO pin 0 transitioned from low to high.
         // Take necessary action.
    }
    if (event_pins_high_to_low & 0x00000004)
    {
         // GPIO pin 2 transitioned from high to low.
         // Take necessary action.
    }
    .
    .
    .
}

Enable/Disable GPIOTE

The GPIOTE module can be enabled or disabled by a registered user at any point of time. No state transition events are received when the GPIOTE is disabled. On initialization, by default, the GPIOTE is disabled.

The following code snippet disables and enables the GPIOTE.

uint32_t retval;
// Enable notifications for example user module which is already registered.
retval = app_gpiote_user_disable(m_example_user_id);
if (retval != NRF_SUCCESS)
{
// Enabling notifications failed. Take corrective/needed action.
.
.
}
.
.
.
// Enable notifications for example user module which is already registered.
retval = app_gpiote_user_enable(m_example_user_id);
if (retval != NRF_SUCCESS)
{
// Enabling notifications failed. Take corrective/needed action.
.
.
}

Reading GPIOTE State

A registered user can read the current state of GPIOs by reading the state information. The following code snippets demonstrates a module reading the state information.
uint32_t retval;
uint32_t gpio_pin_state;
retval = app_gpiote_pins_state_get(m_example_user_id,&gpio_pin_state);
if (retval != NRF_SUCCESS)
{
// Failed to read state information. Take corrective action.
}
else
{
.
.
if (gpio_pins_state & 0x00000006) // Checks if pin one and two are set
{
// Take necessary action
}
.
.
}
												

NRF51822之GPIOTE介绍的更多相关文章

  1. NRF51822之GPIOTE使用

    ---恢复内容开始--- 在上篇介绍nrf51822的GPIOTE http://www.cnblogs.com/libra13179/p/5336580.html 我们现在开始下水游泳. /** @ ...

  2. nRF5芯片外设GPIO和GPIOTE介绍

    nRF51/nRF52同时包含GPIO和GPIOTE两种外设,经常有人将两者搞混,今天我们就来介绍一下这2种外设有什么不同,及使用注意事项. GPIO和GPIOTE都属于芯片外设,但两者功能完全不一样 ...

  3. NRF51822之pstorage介绍

    This information applies to the following SoftDevices: S110, S120, S130, S310 Introduction Persisten ...

  4. nRF51822外设应用[2]:GPIOTE的应用-按键检测

    版权声明:本文为博主原创文章,转载请注明作者和出处.    作者:强光手电[艾克姆科技-无线事业部] 1. nRF51822寄存器类型 nRF51822的寄存器和一般的单片机有所差别,nRF51822 ...

  5. [nRF51822] 5、 霸屏了——详解nRF51 SDK中的GPIOTE(从GPIO电平变化到产生中断事件的流程详解)

    :由于在大多数情况下GPIO的状态变化都会触发应用程序执行一些动作.为了方便nRF51官方把该流程封装成了GPIOTE,全称:The GPIO Tasks and Events (GPIOTE) . ...

  6. nrf51822裸机教程-GPIOTE

    GPIO通常都会具有中断功能,上一讲的GPIO中并没有涉及到中断的相关寄存器. 51822将GPIO的中断相关做成了一个单独的模块GPIOTE,这个模块不仅提供了GPIO的中断功能,同时提供了 通过t ...

  7. nrf51822微信开发2:[转]airkiss/airsync介绍

    "微信蓝牙"专题共分为8部分 1.airkiss/airsync介绍 2.eclipes的j2ee软件使用教程 3.微信公众号使用Dome(airkiss/airsync) 4.新 ...

  8. [编译] 4、在Linux下搭建nRF51822的开发烧写环境(makefile版)

    星期日, 09. 九月 2018 07:51下午 - beautifulzzzz 1.安装步骤 1) 从GNU Arm Embedded Toolchain官网下载最新的gcc-arm工具链,写文章时 ...

  9. [nRF51822] 14、浅谈蓝牙低功耗(BLE)的几种常见的应用场景及架构(科普类干货)

    蓝牙在短距离无线通信领域占据举足轻重的地位—— 从手机.平板.PC到车载设备, 到耳机.游戏手柄.音响.电视, 再到手环.电子秤.智能医疗器械(血糖仪.数字血压计.血气计.数字脉搏/心率监视器.数字体 ...

随机推荐

  1. Android UDP

    一.UDP协议全称是用户数据报协议 ,在网络中它与TCP协议一样用于处理数据包,是一种无连接的协议. 1.UDP是一个无连接协议,传输数据之前源端和终端不建立连接: 2.不维护连接状态,包括收发状态等 ...

  2. android上传文件到服务器

    package com.spring.sky.image.upload.network; import java.io.DataOutputStream; import java.io.File; i ...

  3. hive复杂类型与java类型的对应

    因为要往自定义的UDF传入复杂类型,所以需要对于这块的对应简单做一下总结 string java.lang.String, org.apache.hadoop.io.Text int int, jav ...

  4. volatile的理解

    用法解释 一旦一个共享变量(类的成员变量.类的静态成员变量)被volatile修饰之后,那么就具备了两层语义: 1)保证了不同线程对这个变量进行操作时的可见性,即一个线程修改了某个变量的值,这新值对其 ...

  5. Android RelativeLayout 实现左右中布局

    效果图如下: 代码如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns ...

  6. DFS HDOJ 2181 哈密顿绕行世界问题

    题目传送门 题意:中文题面 分析:直接排完序后DFS.这样的题以后不应该再写题解的. #include <bits/stdc++.h> using namespace std; vecto ...

  7. HDU4057 Rescue the Rabbit(AC自动机+状压DP)

    题目大概是给几个DNA片段以及它们各自的权值,如果一个DNA包含某个片段那么它的价值就加上这个片段的权值,同时包含多个相同DNA片段也只加一次,问长度l的DNA可能的最大价值. 与HDU2825大同小 ...

  8. 仿windows8 开始菜单 实现HubTileBase 以及仿鲜果联播实现 PulsingTile(脉冲磁贴)

    http://blog.csdn.net/wangrenzhu2011/article/details/8750820 (转) 本文章将以如何实现 开始菜单上的tile 为主. 该控件代码经过测试可直 ...

  9. COJ966 WZJ的数据结构(负三十四)

    WZJ的数据结构(负三十四) 难度级别:C: 运行时间限制:20000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 给一棵n个节点的树,请对于形如"u  ...

  10. 彻底卸载oracle数据库

    有时候因为各种各样的原因,我们不得不重装Oracle,但按照一般的操作,很多朋友用了oracle的删除,然后,你会发现重新安装时,点了下一步安装界面就消失了.事实证明,万能的重启也是解决不了问题的.往 ...