nrf51822 GPIOTE
来源:互联网 发布:黑猫警长知乎 编辑:程序博客网 时间:2024/06/05 19:33
The GPIO Tasks and Events (GPIOTE) module provides functionality for accessing GPIO pins using tasks and events.
GPIO的任务TASK和事件EVENT模块提供了使用任务和事件来使用GPIO的功能
A task can be used for performing the following write operations to a pin:
TASK任务:可执行以下三种对引脚的输出操作
• Set 置位(1)
• Clear 清零(0)
• Toggle 反转(!)
An event can be generated from any of the following input pins using the GPIO DETECT signal:
EVENT事件:利用输入引脚的检测信号(DETECT signal)可以产生以下event:
• Rising edge 上升沿
• Falling edge 下降沿
• Any change 变化
PIN:
OUT[n] tasks and theIN[n] events 输入事件导致输出任务
The tasks can be used forwriting to individual pins,
the events can begenerated from changes occurring at the inputs of individual pins.
Every pair of OUT[n] tasks and IN[n] events has one CONFIG[n] registerassociated with it.
When an OUT[n] task or anIN[n] event has been configured to operate on a pin, the pin can only bewritten from the GPIOTE module. Attempting to write a pin as a normal GPIO pinwill have no effect.当IO配置为GPIOTE后,GPIO操作将无效,直到GPIOTE释放此脚
通过CONFIG[n] registers 对task和event进行配置:
nrf_gpiote_task_config(uint32_t channel_number, uint32_t pin_number, nrf_gpiote_polarity_t polarity,gpiote_outinit_t initial_value)说明:GPIOTE有4个通道Channel channel_number [0: 3] 31个IO pin可作为通道 pin_number [0:30] 即每个IO引脚都有GPIOTE通道方式:NRF_GPIOTE_POLARITY_LOTOHI = GPIOTE_CONFIG_POLARITY_LoToHi, ///< Low to highNRF_GPIOTE_POLARITY_HITOLO = GPIOTE_CONFIG_POLARITY_HiToLo, ///< High to lowNRF_GPIOTE_POLARITY_TOGGLE = GPIOTE_CONFIG_POLARITY_Toggle ///< Toggle} nrf_gpiote_polarity_t;通道配置后的初始值:NRF_GPIOTE_INITIAL_VALUE_LOW = GPIOTE_CONFIG_OUTINIT_Low, ///< Low to high NRF_GPIOTE_INITIAL_VALUE_HIGH = GPIOTE_CONFIG_OUTINIT_High ///< High to low
示例分析():typedef enum{ NRF_GPIOTE_POLARITY_LOTOHI = GPIOTE_CONFIG_POLARITY_LoToHi, ///< Low to high NRF_GPIOTE_POLARITY_HITOLO = GPIOTE_CONFIG_POLARITY_HiToLo, ///< High to low NRF_GPIOTE_POLARITY_TOGGLE = GPIOTE_CONFIG_POLARITY_Toggle ///< Toggle} nrf_gpiote_polarity_t;typedef enum{ NRF_GPIOTE_INITIAL_VALUE_LOW = GPIOTE_CONFIG_OUTINIT_Low, ///< Low to high NRF_GPIOTE_INITIAL_VALUE_HIGH = GPIOTE_CONFIG_OUTINIT_High ///< High to low} nrf_gpiote_outinit_t;
* @brief Function for configuring GPIOTE channel as output, setting the properly desired output level. * * * @param channel_number specifies the GPIOTE channel [0:3] to configure as an output channel. * @param pin_number specifies the pin number [0:30] to use in the GPIOTE channel. * @param polarity specifies the desired polarity in the output GPIOTE channel. * @param initial_value specifies the initial value of the GPIOTE channel input after the channel configuration. */static __INLINE void nrf_gpiote_task_config(uint32_t channel_number, uint32_t pin_number, nrf_gpiote_polarity_t polarity, nrf_gpiote_outinit_t initial_value){ /* Check if the output desired is high or low */ if (initial_value == NRF_GPIOTE_INITIAL_VALUE_LOW) { /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the correct state in GPIOTE but not in the OUT register. */ NRF_GPIO->OUTCLR = (1 << pin_number); /* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */ NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | (31UL << GPIOTE_CONFIG_PSEL_Pos) | (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos); } else { /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the correct state in GPIOTE but not in the OUT register. */ NRF_GPIO->OUTSET = (1 << pin_number); /* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */ NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | (31UL << GPIOTE_CONFIG_PSEL_Pos) | (GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos); } /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */ __NOP(); __NOP(); __NOP(); /* Launch the task to take the GPIOTE channel output to the desired level */ NRF_GPIOTE->TASKS_OUT[channel_number] = 1; /* Finally configure the channel as the caller expects. If OUTINIT works, the channel is configured properly. If it does not, the channel output inheritance sets the proper level. */ NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | ((uint32_t)pin_number << GPIOTE_CONFIG_PSEL_Pos) | ((uint32_t)polarity << GPIOTE_CONFIG_POLARITY_Pos) | ((uint32_t)initial_value << GPIOTE_CONFIG_OUTINIT_Pos); /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */ __NOP(); __NOP(); __NOP(); }/** * @brief Function for configuring GPIOTE channel as input, automatically clearing an event that appears in some cases under configuration. * * Note that when configuring the channel as input an event might be triggered. Care of disabling interrupts * for that channel is left to the user. * * @param channel_number specifies the GPIOTE channel [0:3] to configure as an input channel. * @param pin_number specifies the pin number [0:30] to use in the GPIOTE channel. * @param polarity specifies the desired polarity in the output GPIOTE channel. */static __INLINE void nrf_gpiote_event_config(uint32_t channel_number, uint32_t pin_number, nrf_gpiote_polarity_t polarity){ /* Configure the channel as the caller expects */ NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos) | ((uint32_t)pin_number << GPIOTE_CONFIG_PSEL_Pos) | ((uint32_t)polarity << GPIOTE_CONFIG_POLARITY_Pos); /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */ __NOP(); __NOP(); __NOP(); /* Clear the event that appears in some cases */ NRF_GPIOTE->EVENTS_IN[channel_number] = 0; }/** * @brief Function for unconfiguring GPIOTE channel. * * * Note that when unconfiguring the channel, the pin is configured as GPIO PIN_CNF configuration. * * @param channel_number specifies the GPIOTE channel [0:3] to unconfigure. */static __INLINE void nrf_gpiote_unconfig(uint32_t channel_number){ /* Unonfigure the channel as the caller expects */ NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Disabled << GPIOTE_CONFIG_MODE_Pos) | (31UL << GPIOTE_CONFIG_PSEL_Pos) | (GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos);}
- nrf51822 GPIOTE
- NRF51822 GPIOTE
- nrf51822裸机教程-GPIOTE
- nRF51822外设应用[2]:GPIOTE的应用-按键检测
- nRF51822 的GPIOTE的中断处理函数中不能直接调用softdevice的功能,需要用app_scheduler
- nRF52832 GPIOTE
- NRF51822
- nRF51822
- nRF52832 GPIOTE EVENT中断使用
- nrf51822 app_timer
- NRF51822 GPIO
- nrf51822资料
- NRF51822 Timer
- Nordic NRF51822
- NRF51822 学习
- NRF51822 GPIO
- nordic nrf51822
- nrf51822、Android
- linux/内核/gcc/make版本和系统位数 查询命令
- 智能便携设备粘贴胶供应商
- Java 过滤掉所有的HTML标签
- sonar下载地址&使用
- 如何选择机器学习算法
- nrf51822 GPIOTE
- 用一个低仿界面来说说自定义viewgroup和事件分发的一些知识
- Android按键事件发布流程
- ThumbnailUtils.extractThumbnail Android图片缩略图显示总结及比较
- C++11中auto、decltype等关键字不能在codeblacks的GNU编译器识别通过的问题的解决
- 初学unity,关于解决有向匀速运动的问题
- 单例模式
- ios8.0下CLLocationManager定位服务需要授权了
- TextLable,TextView首行缩进问题