Gpiote Handling Library
-
Note
This library was obsolete and should not being
-
used in new designs. Instead, you should use Gpiote driver.
The general purpose Input/output are organized in the nRF51 Series chips as one port with up to + I/Os (dependent on Packa GE) enabling access and control of up to pins through one port. In very applications, the state of a gpio or a change in state of a GPIO trigger a application to take action or Tran Sition 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 "App_gpiote" in the SDK, facilitates application (s) to Register for notification The 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 GP IOTE Interrupt,each User defining a set of pins able to generate events to the user. When a gpiote interrupt occurs, the Gpiote interrupt handler would identify pin transition (S) and notify each client Regist Ered for the transition.
-
Note
The
-
. Register with the library is henceforth referred to as clients or users.
This
-
library uses Gpiote driver, which must is enabled and properly configured in Nrf_drv_config.h. You must specify gpiote_config_num_of_low_power_events, which are the number of pins used for low POWER events_port Includi ng the pins used by this library.
Figure 1:users is being notified of a pin transition event.
The Gpiote users is responsible for configuring all their corresponding pins, except the sense field, which should is INI Tialized to gpio_pin_cnf_sense_disabled.
The module specifies on which pins events should is 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 would be called directly from the gpiote I Nterrupt handler.
Initializing gpiote Module
The initialization procedure must is 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 C is of reserving needed memory for the all user requested in the Max_users parameter of the macro. This parameter indicates how may users is going to being registering with the library.
//Macro to initialize Gpiote module and reserving necessary memory for each of the user.App_gpiote_init (max_users);
-
Note
-
Module initialization should is 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 being notified of change in state of GPIO. During registry, the user must provide callback handler to notify of a transition event and pin transitions it is interes Ted in. 32-bit bitmask are used to represent, GPIO pins as shown in Figure 2 below. User can register for transition-from-low-and/or low-to-high.
Figure 2:gpio Pin representation using 32-bit bitmask.
On successful registration, the user was assigned a user ID and the user is expected to remember this identifier for all SU Bsequent requests made to the module. This identifier was provided in the out parameter p_user_id. A sample registration is shown below.
//Gpiote User identifier for the example module.Staticapp_gpiote_user_id_t m_example_user_id;//Gpiote event handler.Static voidExample_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 is notified of transition from low to high for GPIO 0-3uint32_t High_to_low_bitmask =0x0000000e;//Bitmask to is notified of transition from high to low for GPIO 0-2uint32_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 the 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 wil L be notified of pin transition events.
By default, the Gpiote are disabled on initialization. Therefore the Gpiote have to is 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.voidExample_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) { //The GPIO pin 2 transitioned from high to low. //Take necessary action. } . . .}
Enable/disable Gpiote
The Gpiote module can is enabled or disabled by a registered user at any point of time. No state transition Events was received when the gpiote was 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 the 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 the 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;re Tval= App_gpiote_pins_state_get (m_example_user_id,&gpio_pin_state);if(RetVal! =nrf_success) {//Failed to read the state information. Take corrective action.}Else{..if(Gpio_pins_state &0x00000006)//Checks if pin One and both are set{//Take necessary action}..}
Analysis on the gpiote of NRF51822