nRF51 SDK
|
HID Mouse Sample Application main file. More...
Functions | |
static void | on_hids_evt (ble_hids_t *p_hids, ble_hids_evt_t *p_evt) |
Function for handling HID events. More... | |
void | app_error_handler (uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name) |
Function for error handling, which is called when an error has occurred. More... | |
void | assert_nrf_callback (uint16_t line_num, const uint8_t *p_file_name) |
Callback function for asserts in the SoftDevice. More... | |
static void | service_error_handler (uint32_t nrf_error) |
Function for handling Service errors. More... | |
static void | battery_level_update (void) |
Function for performing a battery measurement, and update the Battery Level characteristic in the Battery Service. | |
static void | battery_level_meas_timeout_handler (void *p_context) |
Function for handling the Battery measurement timer timeout. More... | |
static void | leds_init (void) |
Function for the LEDs initialization. More... | |
static void | timers_init (void) |
Function for the Timer initialization. More... | |
static void | gap_params_init (void) |
Function for the GAP initialization. More... | |
static void | advertising_init (uint8_t adv_flags) |
Function for initializing the Advertising functionality. More... | |
static void | dis_init (void) |
Function for initializing Device Information Service. | |
static void | bas_init (void) |
Function for initializing Battery Service. | |
static void | hids_init (void) |
Function for initializing HID Service. | |
static void | services_init (void) |
Function for initializing services that will be used by the application. | |
static void | sensor_sim_init (void) |
Function for initializing the battery sensor simulator. | |
static void | sec_params_init (void) |
Function for initializing security parameters. | |
static void | conn_params_error_handler (uint32_t nrf_error) |
Function for handling a Connection Parameters error. More... | |
static void | conn_params_init (void) |
Function for initializing the Connection Parameters module. | |
static void | timers_start (void) |
Function for starting timers. | |
static void | advertising_start (void) |
Function for starting advertising. | |
static void | on_ble_evt (ble_evt_t *p_ble_evt) |
Function for handling the Application's BLE Stack events. More... | |
static void | ble_evt_dispatch (ble_evt_t *p_ble_evt) |
Function for dispatching a BLE stack event to all modules with a BLE stack event handler. More... | |
static void | ble_stack_init (void) |
Function for initializing the BLE stack. More... | |
static void | scheduler_init (void) |
Function for the Event Scheduler initialization. | |
static void | mouse_movement_send (int16_t x_delta, int16_t y_delta) |
Function for sending a Mouse Movement. More... | |
static void | button_event_handler (uint8_t pin_no) |
Function for handling button events. More... | |
static void | gpiote_init (void) |
Function for initializing the GPIOTE handler module. | |
static void | buttons_init (void) |
Function for initializing the button handler module. | |
static void | bond_manager_error_handler (uint32_t nrf_error) |
Function for handling a Bond Manager error. More... | |
static void | bond_evt_handler (ble_bondmngr_evt_t *p_evt) |
Function for handling the Bond Manager events. More... | |
static void | bond_manager_init (void) |
Function for the Bond Manager initialization. | |
static void | radio_notification_init (void) |
Function for initializing the Radio Notification event. | |
static void | power_manage (void) |
Function for the Power manager. | |
int | main (void) |
Function for application main entry. | |
Variables | |
static ble_hids_t | m_hids |
static ble_bas_t | m_bas |
static ble_gap_sec_params_t | m_sec_params |
static bool | m_in_boot_mode = false |
static ble_sensorsim_cfg_t | m_battery_sim_cfg |
static ble_sensorsim_state_t | m_battery_sim_state |
static app_timer_id_t | m_battery_timer_id |
static ble_advertising_mode_t | m_advertising_mode |
static int8_t | m_last_connected_master |
static uint8_t | m_direct_adv_cnt |
This file contains is the source code for a sample application using the HID, Battery and Device Information Service for implementing a simple mouse functionality. This application uses the Scheduler.
Also it would accept pairing requests from any peer device. This implementation of the application will not know whether a connected master is a known device or not.
#define LEFT_BUTTON_PIN_NO NRF6310_BUTTON_0 |
Button used for moving the mouse pointer to the left.
#define RIGHT_BUTTON_PIN_NO NRF6310_BUTTON_1 |
Button used for moving the mouse pointer to the right.
#define UP_BUTTON_PIN_NO NRF6310_BUTTON_2 |
Button used for moving the mouse pointer upwards.
#define DOWN_BUTTON_PIN_NO NRF6310_BUTTON_3 |
Button used for moving the mouse pointer downwards.
#define BONDMNGR_DELETE_BUTTON_PIN_NO RIGHT_BUTTON_PIN_NO |
Button used for deleting all bonded masters during startup.
#define ADV_DIRECTED_LED_PIN_NO NRF6310_LED_4 |
Is on when we are doing directed advertisement.
#define ADV_WHITELIST_LED_PIN_NO NRF6310_LED_5 |
Is on when we are doing advertising with whitelist.
#define ADV_INTERVAL_SLOW_LED_PIN_NO NRF6310_LED_6 |
Is on when we are doing slow advertising.
#define DEVICE_NAME "Nordic_Mouse" |
Name of device. Will be included in the advertising data.
#define MANUFACTURER_NAME "NordicSemiconductor" |
Manufacturer. Will be passed to Device Information Service.
#define APP_TIMER_PRESCALER 0 |
Value of the RTC1 PRESCALER register.
#define APP_TIMER_MAX_TIMERS 3 |
Maximum number of simultaneously created timers.
#define APP_TIMER_OP_QUEUE_SIZE 4 |
Size of timer operation queues.
#define BATTERY_LEVEL_MEAS_INTERVAL APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER) |
Battery level measurement interval (ticks).
#define MIN_BATTERY_LEVEL 81 |
Minimum simulated battery level.
#define MAX_BATTERY_LEVEL 100 |
Maximum simulated battery level.
#define BATTERY_LEVEL_INCREMENT 1 |
Increment between each simulated battery level measurement.
#define APP_ADV_INTERVAL_FAST 0x0028 |
Fast advertising interval (in units of 0.625 ms. This value corresponds to 25 ms.).
#define APP_ADV_INTERVAL_SLOW 0x0C80 |
Slow advertising interval (in units of 0.625 ms. This value corrsponds to 2 seconds).
#define APP_FAST_ADV_TIMEOUT 30 |
The duration of the fast advertising period (in seconds).
#define APP_SLOW_ADV_TIMEOUT 180 |
The duration of the slow advertising period (in seconds).
#define APP_DIRECTED_ADV_TIMEOUT 5 |
Number of direct advertisement (each lasting 1.28seconds).
#define PNP_ID_VENDOR_ID_SOURCE 0x02 |
Vendor ID Source.
#define PNP_ID_VENDOR_ID 0x1915 |
Vendor ID.
#define PNP_ID_PRODUCT_ID 0xEEEE |
Product ID.
#define PNP_ID_PRODUCT_VERSION 0x0001 |
Product Version.
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(7.5, UNIT_1_25_MS) |
Minimum connection interval (7.5 ms).
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(15, UNIT_1_25_MS) |
Maximum connection interval (15 ms).
#define SLAVE_LATENCY 25 |
Slave latency.
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(3000, UNIT_10_MS) |
Connection supervisory timeout (300 ms).
#define FIRST_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5000, APP_TIMER_PRESCALER) |
Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds).
#define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(30000, APP_TIMER_PRESCALER) |
Time between each call to sd_ble_gap_conn_param_update after the first (30 seconds).
#define MAX_CONN_PARAM_UPDATE_COUNT 3 |
Number of attempts before giving up the connection parameter negotiation.
#define APP_GPIOTE_MAX_USERS 1 |
Maximum number of users of the GPIOTE handler.
#define BUTTON_DETECTION_DELAY APP_TIMER_TICKS(50, APP_TIMER_PRESCALER) |
Delay from a GPIOTE event until a button is reported as pushed (in number of timer ticks).
#define SEC_PARAM_TIMEOUT 30 |
Timeout for Pairing Request or Security Request (in seconds).
#define SEC_PARAM_BOND 1 |
Perform bonding.
#define SEC_PARAM_MITM 0 |
Man In The Middle protection not required.
#define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_NONE |
No I/O capabilities.
#define SEC_PARAM_OOB 0 |
Out Of Band data not available.
#define SEC_PARAM_MIN_KEY_SIZE 7 |
Minimum encryption key size.
#define SEC_PARAM_MAX_KEY_SIZE 16 |
Maximum encryption key size.
#define MOVEMENT_SPEED 5 |
Number of pixels by which the cursor is moved each time a button is pushed.
#define INPUT_REPORT_COUNT 3 |
Number of input reports in this application.
#define INPUT_REP_BUTTONS_LEN 3 |
Length of Mouse Input Report containing button data.
#define INPUT_REP_MOVEMENT_LEN 3 |
Length of Mouse Input Report containing movement data.
#define INPUT_REP_MEDIA_PLAYER_LEN 1 |
Length of Mouse Input Report containing media player data.
#define INPUT_REP_BUTTONS_INDEX 0 |
Index of Mouse Input Report containing button data.
#define INPUT_REP_MOVEMENT_INDEX 1 |
Index of Mouse Input Report containing movement data.
#define INPUT_REP_MPLAYER_INDEX 2 |
Index of Mouse Input Report containing media player data.
#define INPUT_REP_REF_BUTTONS_ID 1 |
Id of reference to Mouse Input Report containing button data.
#define INPUT_REP_REF_MOVEMENT_ID 2 |
Id of reference to Mouse Input Report containing movement data.
#define INPUT_REP_REF_MPLAYER_ID 3 |
Id of reference to Mouse Input Report containing media player data.
#define FLASH_PAGE_SYS_ATTR (BLE_FLASH_PAGE_END - 3) |
Flash page used for bond manager system attribute information.
#define FLASH_PAGE_BOND (BLE_FLASH_PAGE_END - 1) |
Flash page used for bond manager bonding information.
#define BASE_USB_HID_SPEC_VERSION 0x0101 |
Version number of base USB HID Specification implemented by this application.
#define SCHED_MAX_EVENT_DATA_SIZE |
Maximum size of scheduler events.
#define SCHED_QUEUE_SIZE 10 |
Maximum number of events in the scheduler queue.
#define DEAD_BEEF 0xDEADBEEF |
Value used as error code on stack dump, can be used to identify stack location on stack unwind.
|
static |
This function will be called for all HID events which are passed to the application.
[in] | p_hids | HID service stucture. |
[in] | p_evt | Event received from the HID service. |
void app_error_handler | ( | uint32_t | error_code, |
uint32_t | line_num, | ||
const uint8_t * | p_file_name | ||
) |
[in] | error_code | Error code supplied to the handler. |
[in] | line_num | Line number where the handler is called. |
[in] | p_file_name | Pointer to the file name. |
void assert_nrf_callback | ( | uint16_t | line_num, |
const uint8_t * | p_file_name | ||
) |
This function will be called in case of an assert in the SoftDevice.
[in] | line_num | Line number of the failing ASSERT call. |
[in] | file_name | File name of the failing ASSERT call. |
|
static |
A pointer to this function will be passed to each service which may need to inform the application about an error.
[in] | nrf_error | Error code containing information about what went wrong. |
|
static |
This function will be called each time the battery level measurement timer expires.
[in] | p_context | Pointer used for passing some arbitrary information (context) from the app_start_timer() call to the timeout handler. |
|
static |
Initializes all LEDs used by the application.
|
static |
Initializes the timer module.
|
static |
This function shall be used to setup all the necessary GAP (Generic Access Profile) parameters of the device. It also sets the permissions and appearance.
|
static |
Encodes the required advertising data and passes it to the stack. Also builds a structure to be passed to the stack when starting advertising.
[in] | adv_flags | Indicates which type of advertisement to use, see GAP Discovery modes. |
|
static |
[in] | nrf_error | Error code containing information about what went wrong. |
|
static |
[in] | p_ble_evt | Bluetooth stack event. |
|
static |
This function is called from the scheduler in the main loop after a BLE stack event has been received.
[in] | p_ble_evt | Bluetooth stack event. |
|
static |
Initializes the SoftDevice and the BLE event interrupt.
|
static |
[in] | x_delta | Horizontal movement. |
[in] | y_delta | Vertical movement. |
|
static |
[in] | pin_no | The pin number of the button pressed. |
|
static |
[in] | nrf_error | Error code containing information about what went wrong. |
|
static |
[in] | p_evt | Data associated to the bond manager event. |
|
static |
Structure used to identify the HID service.
|
static |
Structure used to identify the battery service.
|
static |
Security requirements for this application.
|
static |
Current protocol mode.
|
static |
Battery Level sensor simulator configuration.
|
static |
Battery Level sensor simulator state.
|
static |
Battery timer.
|
static |
Variable to keep track of when we are advertising.
|
static |
BondManager reference handle to the last connected master.
|
static |
Counter of direct advertisements.