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. 微信SDK开发学习

    public class MainActivity extends Activity { // 应用程序的id,就是在网上开发平台创建应用的appid public static final Stri ...

  2. HTML-Audio/Video

    简介: 容器:不论是音频还是视频文件,实际上都是容器文件: 视频文件包含了音频轨道.视频轨道和其他一些元数据: 视频文件播放时,音频轨道和视频轨道是绑定在一起:元数据包含了该视频的封面.子标题.字幕等 ...

  3. intro.js 页面引导简单用法

    下载地址:http://pan.baidu.com/share/link?shareid=1894002026&uk=1829018343 <!DOCTYPE HTML PUBLIC & ...

  4. UIView 周围出现黑线的解决方法

    myView.clipsToBounds = YES;

  5. hiho 毁灭者问题

    描述 在 Warcraft III 之冰封王座中,毁灭者是不死族打三本后期时的一个魔法飞行单位. 毁灭者的核心技能之一,叫做魔法吸收(Absorb Mana): 现在让我们来考虑下面的问题: 假设你拥 ...

  6. libtiff 生成48位色tif图片

    BOOL CTifImage_48Bits::BitmapConvertTo48BitsTif(CString strImagePath, int nWidth, int nHeight, int n ...

  7. SecureCrt脚本(二)二级对象之Dialog

    Crt自动化 测试 SecureCrt脚本 JS脚本   1.引言 2.Dialog属性和方法 2.1.属性 2.2.方法 2.2.1.FileOpenDialog 2.2.2.MessageBox ...

  8. LeetCode-Repeated DNA Sequences (位图算法减少内存)

    Repeated DNA Sequences All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, ...

  9. 兼容ie[6-9]、火狐、Chrome、opera、maxthon3、360浏览器的js本地图片预览

    html代码: <div id="divPreview"> <img id="imgHeadPhoto" src="Images/H ...

  10. 释放用完的Excel COM组件

    How to Open; SaveAs; then Close an Excel 2013 (macro-enabled) workbook from PowerShell4   1. (http:/ ...