mirror of
https://github.com/jam422470459/EPD-nRF52-hema213.git
synced 2025-12-19 23:03:21 +08:00
move components to SDK dir
This commit is contained in:
@@ -0,0 +1,402 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_config.h"
|
||||
#if APP_USBD_HID_KBD_ENABLED
|
||||
#include <string.h>
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "app_usbd_hid_kbd.h"
|
||||
#include "app_util_platform.h"
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_hid_kbd_internals USB HID keyboard internals
|
||||
* @{
|
||||
* @ingroup app_usbd_hid_kbd
|
||||
* @internals
|
||||
*/
|
||||
|
||||
STATIC_ASSERT(sizeof(app_usbd_hid_descriptor_t) == 6);
|
||||
|
||||
/**
|
||||
* @brief Auxiliary function to access HID keyboard context data
|
||||
*
|
||||
* @param[in] p_inst class instance data
|
||||
* @return HID keyboard instance data @ref app_usbd_hid_kbd_ctx_t
|
||||
*/
|
||||
static inline app_usbd_hid_kbd_ctx_t * hid_kbd_ctx_get(app_usbd_hid_kbd_t const * p_kbd)
|
||||
{
|
||||
ASSERT(p_kbd != NULL);
|
||||
ASSERT(p_kbd->specific.p_data != NULL);
|
||||
return &p_kbd->specific.p_data->ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Auxiliary function to access HID keyboard instance data
|
||||
*
|
||||
* @param[in] p_inst class instance data
|
||||
* @return HID keyboard instance data @ref app_usbd_hid_kbd_t
|
||||
*/
|
||||
static inline app_usbd_hid_kbd_t const * hid_kbd_get(app_usbd_class_inst_t const * p_inst)
|
||||
{
|
||||
ASSERT(p_inst != NULL);
|
||||
return (app_usbd_hid_kbd_t const *)p_inst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns keyboard report buffer handle
|
||||
*
|
||||
* @param[in] p_kbd HID keyboard instance
|
||||
* @return HID report buffer @ref app_usbd_hid_report_buffer_t
|
||||
* */
|
||||
static inline
|
||||
app_usbd_hid_report_buffer_t const * hid_kbd_rep_buffer_get(app_usbd_hid_kbd_t const * p_kbd)
|
||||
{
|
||||
ASSERT(p_kbd != NULL);
|
||||
app_usbd_hid_inst_t const * p_hinst = &p_kbd->specific.inst.hid_inst;
|
||||
app_usbd_hid_kbd_ctx_t * p_kbd_ctx = hid_kbd_ctx_get(p_kbd);
|
||||
app_usbd_hid_report_buffer_t * p_rep_buff = app_usbd_hid_rep_buff_in_get(p_hinst, 0);
|
||||
|
||||
p_rep_buff->p_buff = p_kbd_ctx->report_buff;
|
||||
p_rep_buff->size = sizeof(p_kbd_ctx->report_buff);
|
||||
|
||||
/*Keyboard has only one report input/output report buffer */
|
||||
return p_rep_buff;
|
||||
}
|
||||
|
||||
|
||||
/**@brief Auxiliary function to prepare report transfer buffer to next transfer
|
||||
*
|
||||
* @param[in] p_kbd HID keyboard instance
|
||||
*
|
||||
* @retval true if next transfer is required
|
||||
* @retval false if next transfer is not required
|
||||
*/
|
||||
static inline bool hid_kbd_transfer_next(app_usbd_hid_kbd_t const * p_kbd)
|
||||
{
|
||||
/*Send report only when state has changed*/
|
||||
app_usbd_hid_report_buffer_t const * p_rep_buffer = hid_kbd_rep_buffer_get(p_kbd);
|
||||
app_usbd_hid_kbd_ctx_t * p_kbd_ctx = hid_kbd_ctx_get(p_kbd);
|
||||
|
||||
if (memcmp(p_rep_buffer->p_buff, &p_kbd_ctx->rep, p_rep_buffer->size))
|
||||
{
|
||||
memcpy(p_rep_buffer->p_buff, &p_kbd_ctx->rep, p_rep_buffer->size);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Triggers IN endpoint transfer
|
||||
*
|
||||
* @param[in] p_kbd HID keyboard instance
|
||||
* @return standard error code
|
||||
*/
|
||||
static inline ret_code_t hid_kbd_transfer_set(app_usbd_hid_kbd_t const * p_kbd)
|
||||
{
|
||||
app_usbd_class_inst_t const * p_inst = (app_usbd_class_inst_t const *)p_kbd;
|
||||
app_usbd_hid_kbd_ctx_t * p_kbd_ctx = hid_kbd_ctx_get(p_kbd);
|
||||
|
||||
nrf_drv_usbd_ep_t ep_addr = app_usbd_hid_epin_addr_get(p_inst);
|
||||
|
||||
app_usbd_hid_state_flag_clr(&p_kbd_ctx->hid_ctx, APP_USBD_HID_STATE_FLAG_TRANS_IN_PROGRESS);
|
||||
|
||||
if (!hid_kbd_transfer_next(p_kbd))
|
||||
{
|
||||
/* Transfer buffer hasn't changed since last transfer. No need to setup
|
||||
* next transfer.
|
||||
* */
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
app_usbd_hid_report_buffer_t const * p_rep_buffer = hid_kbd_rep_buffer_get(p_kbd);
|
||||
NRF_DRV_USBD_TRANSFER_IN(transfer, p_rep_buffer->p_buff, p_rep_buffer->size);
|
||||
|
||||
ret_code_t ret;
|
||||
CRITICAL_REGION_ENTER();
|
||||
ret = app_usbd_core_ep_transfer(ep_addr, &transfer, NULL);
|
||||
if (ret == NRF_SUCCESS)
|
||||
{
|
||||
app_usbd_hid_state_flag_set(&p_kbd_ctx->hid_ctx, APP_USBD_HID_STATE_FLAG_TRANS_IN_PROGRESS);
|
||||
}
|
||||
CRITICAL_REGION_EXIT();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_code_t app_usbd_hid_kbd_modifier_state_set(app_usbd_hid_kbd_t const * p_kbd,
|
||||
app_usbd_hid_kbd_modifier_t modifier,
|
||||
bool state)
|
||||
{
|
||||
app_usbd_hid_kbd_ctx_t * p_kbd_ctx = hid_kbd_ctx_get(p_kbd);
|
||||
bool actual_state = (p_kbd_ctx->rep.modifier & modifier) != 0;
|
||||
|
||||
if (actual_state == state)
|
||||
{
|
||||
/*Modifier has already the same state*/
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
app_usbd_hid_access_lock(&p_kbd_ctx->hid_ctx);
|
||||
|
||||
if (state)
|
||||
{
|
||||
p_kbd_ctx->rep.modifier |= modifier;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_kbd_ctx->rep.modifier &= ~modifier;
|
||||
}
|
||||
app_usbd_hid_access_unlock(&p_kbd_ctx->hid_ctx);
|
||||
|
||||
if (app_usbd_hid_trans_required(&p_kbd_ctx->hid_ctx))
|
||||
{
|
||||
/*New transfer need to be triggered*/
|
||||
return hid_kbd_transfer_set(p_kbd);
|
||||
}
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t app_usbd_hid_kbd_key_control(app_usbd_hid_kbd_t const * p_kbd,
|
||||
app_usbd_hid_kbd_codes_t key,
|
||||
bool press)
|
||||
{
|
||||
app_usbd_hid_kbd_ctx_t * p_kbd_ctx = hid_kbd_ctx_get(p_kbd);
|
||||
uint8_t * destination = NULL;
|
||||
if (press)
|
||||
{
|
||||
for (size_t i = 0; i < ARRAY_SIZE(p_kbd_ctx->rep.key_table); ++i) {
|
||||
if (p_kbd_ctx->rep.key_table[i] == key)
|
||||
{
|
||||
/*Already pressed*/
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
if ((destination == NULL) && (p_kbd_ctx->rep.key_table[i] == 0))
|
||||
{
|
||||
destination = &p_kbd_ctx->rep.key_table[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (destination == NULL)
|
||||
{
|
||||
return NRF_ERROR_BUSY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*Find if key is pressed*/
|
||||
for (size_t i = 0; i < ARRAY_SIZE(p_kbd_ctx->rep.key_table); ++i) {
|
||||
if (p_kbd_ctx->rep.key_table[i] == key)
|
||||
{
|
||||
destination = &p_kbd_ctx->rep.key_table[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (destination == NULL)
|
||||
{
|
||||
/*Key hasn't been pressed*/
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/*Save destination*/
|
||||
app_usbd_hid_access_lock(&p_kbd_ctx->hid_ctx);
|
||||
*destination = press ? key : 0;
|
||||
app_usbd_hid_access_unlock(&p_kbd_ctx->hid_ctx);
|
||||
|
||||
if (app_usbd_hid_trans_required(&p_kbd_ctx->hid_ctx))
|
||||
{
|
||||
/*New transfer need to be triggered*/
|
||||
return hid_kbd_transfer_set(p_kbd);
|
||||
}
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
bool app_usbd_hid_kbd_led_state_get(app_usbd_hid_kbd_t const * p_kbd,
|
||||
app_usbd_hid_kbd_led_t led)
|
||||
{
|
||||
app_usbd_hid_kbd_ctx_t * p_kbd_ctx = hid_kbd_ctx_get(p_kbd);
|
||||
|
||||
return (p_kbd_ctx->leds_state & led) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief @ref app_usbd_hid_interface_t::on_get_report
|
||||
*/
|
||||
static ret_code_t hid_kbd_on_get_report(app_usbd_class_inst_t const * p_inst,
|
||||
app_usbd_setup_evt_t const * p_setup_ev)
|
||||
{
|
||||
app_usbd_hid_kbd_t const * p_kbd = hid_kbd_get(p_inst);
|
||||
app_usbd_hid_report_buffer_t const * p_rep_buffer = hid_kbd_rep_buffer_get(p_kbd);
|
||||
|
||||
return app_usbd_core_setup_rsp(&(p_setup_ev->setup), p_rep_buffer->p_buff, p_rep_buffer->size);
|
||||
}
|
||||
|
||||
|
||||
static ret_code_t hid_kbd_on_set_report_data_cb(nrf_drv_usbd_ep_status_t status, void * p_context)
|
||||
{
|
||||
if (status != NRF_USBD_EP_OK)
|
||||
{
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
app_usbd_hid_kbd_t const * p_kbd = p_context;
|
||||
app_usbd_hid_report_buffer_t const * p_rep_buff;
|
||||
p_rep_buff = app_usbd_hid_rep_buff_out_get(&p_kbd->specific.inst.hid_inst);
|
||||
|
||||
/*Update LEDs state*/
|
||||
app_usbd_hid_kbd_ctx_t * p_kbd_ctx = hid_kbd_ctx_get(p_kbd);
|
||||
p_kbd_ctx->leds_state = p_rep_buff->p_buff[1];
|
||||
|
||||
app_usbd_hid_user_ev_handler_t handler = p_kbd->specific.inst.hid_inst.user_event_handler;
|
||||
handler((app_usbd_class_inst_t const *)(p_kbd), APP_USBD_HID_USER_EVT_OUT_REPORT_READY);
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief @ref app_usbd_hid_interface_t::hid_kbd_on_set_report
|
||||
*/
|
||||
static ret_code_t hid_kbd_on_set_report(app_usbd_class_inst_t const * p_inst,
|
||||
app_usbd_setup_evt_t const * p_setup_ev)
|
||||
{
|
||||
app_usbd_hid_kbd_t const * p_kbd = hid_kbd_get(p_inst);
|
||||
|
||||
/*Request setup data*/
|
||||
app_usbd_hid_report_buffer_t const * p_rep_buff;
|
||||
p_rep_buff = app_usbd_hid_rep_buff_out_get(&p_kbd->specific.inst.hid_inst);
|
||||
|
||||
p_rep_buff->p_buff[0] = 0;
|
||||
NRF_DRV_USBD_TRANSFER_OUT(transfer, p_rep_buff->p_buff + 1, p_rep_buff->size - 1);
|
||||
|
||||
ret_code_t ret;
|
||||
CRITICAL_REGION_ENTER();
|
||||
ret = app_usbd_core_setup_data_transfer(NRF_DRV_USBD_EPOUT0, &transfer, NULL);
|
||||
if (ret == NRF_SUCCESS)
|
||||
{
|
||||
app_usbd_core_setup_data_handler_desc_t desc = {
|
||||
.handler = hid_kbd_on_set_report_data_cb,
|
||||
.p_context = (void*)p_kbd
|
||||
};
|
||||
|
||||
ret = app_usbd_core_setup_data_handler_set(NRF_DRV_USBD_EPOUT0, &desc);
|
||||
}
|
||||
CRITICAL_REGION_EXIT();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief @ref app_usbd_hid_interface_t::hid_kbd_ep_transfer_in
|
||||
*/
|
||||
static ret_code_t hid_kbd_ep_transfer_in(app_usbd_class_inst_t const * p_inst)
|
||||
{
|
||||
return hid_kbd_transfer_set((app_usbd_hid_kbd_t const *)p_inst);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief @ref app_usbd_class_interface_t::event_handler
|
||||
*/
|
||||
static ret_code_t hid_kbd_event_handler(app_usbd_class_inst_t const * p_inst,
|
||||
app_usbd_complex_evt_t const * p_event)
|
||||
{
|
||||
ASSERT(p_inst != NULL);
|
||||
ASSERT(p_event != NULL);
|
||||
|
||||
app_usbd_hid_kbd_t const * p_kbd = hid_kbd_get(p_inst);
|
||||
app_usbd_hid_inst_t const * p_hinst = &p_kbd->specific.inst.hid_inst;
|
||||
|
||||
app_usbd_hid_kbd_ctx_t * p_kbd_ctx = hid_kbd_ctx_get(p_kbd);
|
||||
app_usbd_hid_ctx_t * p_hid_ctx = &p_kbd_ctx->hid_ctx;
|
||||
|
||||
ret_code_t ret = NRF_SUCCESS;
|
||||
|
||||
switch (p_event->app_evt.type)
|
||||
{
|
||||
default:
|
||||
ret = NRF_ERROR_NOT_SUPPORTED;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret != NRF_ERROR_NOT_SUPPORTED)
|
||||
{
|
||||
/* Event was processed by specific handler */
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*Try handle event by generic HID event handler*/
|
||||
return app_usbd_hid_event_handler(p_inst, p_hinst, p_hid_ctx, p_event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief @ref app_usbd_class_interface_t::get_descriptors
|
||||
*/
|
||||
static const void * hid_kbd_get_descriptors(app_usbd_class_inst_t const * p_inst,
|
||||
size_t * p_size)
|
||||
{
|
||||
ASSERT(p_size != NULL);
|
||||
app_usbd_hid_kbd_t const * p_kbd = hid_kbd_get(p_inst);
|
||||
app_usbd_hid_inst_t const * p_hinst = &p_kbd->specific.inst.hid_inst;
|
||||
|
||||
*p_size = p_hinst->raw_desc_size;
|
||||
return p_hinst->p_raw_desc;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
const app_usbd_hid_methods_t app_usbd_hid_kbd_methods = {
|
||||
.on_get_report = hid_kbd_on_get_report,
|
||||
.on_set_report = hid_kbd_on_set_report,
|
||||
.ep_transfer_in = hid_kbd_ep_transfer_in,
|
||||
.ep_transfer_out = NULL,
|
||||
};
|
||||
|
||||
const app_usbd_class_methods_t app_usbd_hid_kbd_class_methods = {
|
||||
.event_handler = hid_kbd_event_handler,
|
||||
.get_descriptors = hid_kbd_get_descriptors,
|
||||
};
|
||||
|
||||
#endif // APP_USBD_HID_KBD_ENABLED
|
||||
@@ -0,0 +1,300 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_HID_KBD_H__
|
||||
#define APP_USBD_HID_KBD_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nrf_drv_usbd.h"
|
||||
#include "app_usbd_class_base.h"
|
||||
#include "app_usbd_hid_types.h"
|
||||
#include "app_usbd_hid.h"
|
||||
#include "app_usbd.h"
|
||||
#include "app_usbd_core.h"
|
||||
#include "app_usbd_descriptor.h"
|
||||
#include "app_usbd_hid_kbd_desc.h"
|
||||
#include "app_usbd_hid_kbd_internal.h"
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_hid_kbd USB HID keyboard
|
||||
* @ingroup app_usbd_hid
|
||||
*
|
||||
* @brief @tagAPI52840 Module with types, definitions, and API used by the HID keyboard class.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief HID keyboard codes
|
||||
* */
|
||||
typedef enum {
|
||||
APP_USBD_HID_KBD_A = 4, /**<KBD_A code*/
|
||||
APP_USBD_HID_KBD_B = 5, /**<KBD_B code*/
|
||||
APP_USBD_HID_KBD_C = 6, /**<KBD_C code*/
|
||||
APP_USBD_HID_KBD_D = 7, /**<KBD_D code*/
|
||||
APP_USBD_HID_KBD_E = 8, /**<KBD_E code*/
|
||||
APP_USBD_HID_KBD_F = 9, /**<KBD_F code*/
|
||||
APP_USBD_HID_KBD_G = 10, /**<KBD_G code*/
|
||||
APP_USBD_HID_KBD_H = 11, /**<KBD_H code*/
|
||||
APP_USBD_HID_KBD_I = 12, /**<KBD_I code*/
|
||||
APP_USBD_HID_KBD_J = 13, /**<KBD_J code*/
|
||||
APP_USBD_HID_KBD_K = 14, /**<KBD_K code*/
|
||||
APP_USBD_HID_KBD_L = 15, /**<KBD_L code*/
|
||||
APP_USBD_HID_KBD_M = 16, /**<KBD_M code*/
|
||||
APP_USBD_HID_KBD_N = 17, /**<KBD_N code*/
|
||||
APP_USBD_HID_KBD_O = 18, /**<KBD_O code*/
|
||||
APP_USBD_HID_KBD_P = 19, /**<KBD_P code*/
|
||||
APP_USBD_HID_KBD_Q = 20, /**<KBD_Q code*/
|
||||
APP_USBD_HID_KBD_R = 21, /**<KBD_R code*/
|
||||
APP_USBD_HID_KBD_S = 22, /**<KBD_S code*/
|
||||
APP_USBD_HID_KBD_T = 23, /**<KBD_T code*/
|
||||
APP_USBD_HID_KBD_U = 24, /**<KBD_U code*/
|
||||
APP_USBD_HID_KBD_V = 25, /**<KBD_V code*/
|
||||
APP_USBD_HID_KBD_W = 26, /**<KBD_W code*/
|
||||
APP_USBD_HID_KBD_X = 27, /**<KBD_X code*/
|
||||
APP_USBD_HID_KBD_Y = 28, /**<KBD_Y code*/
|
||||
APP_USBD_HID_KBD_Z = 29, /**<KBD_Z code*/
|
||||
APP_USBD_HID_KBD_1 = 30, /**<KBD_1 code*/
|
||||
APP_USBD_HID_KBD_2 = 31, /**<KBD_2 code*/
|
||||
APP_USBD_HID_KBD_3 = 32, /**<KBD_3 code*/
|
||||
APP_USBD_HID_KBD_4 = 33, /**<KBD_4 code*/
|
||||
APP_USBD_HID_KBD_5 = 34, /**<KBD_5 code*/
|
||||
APP_USBD_HID_KBD_6 = 35, /**<KBD_6 code*/
|
||||
APP_USBD_HID_KBD_7 = 36, /**<KBD_7 code*/
|
||||
APP_USBD_HID_KBD_8 = 37, /**<KBD_8 code*/
|
||||
APP_USBD_HID_KBD_9 = 38, /**<KBD_9 code*/
|
||||
APP_USBD_HID_KBD_0 = 39, /**<KBD_0 code*/
|
||||
APP_USBD_HID_KBD_ENTER = 40, /**<KBD_ENTER code*/
|
||||
APP_USBD_HID_KBD_ESCAPE = 41, /**<KBD_ESCAPE code*/
|
||||
APP_USBD_HID_KBD_BACKSPACE = 42, /**<KBD_BACKSPACE code*/
|
||||
APP_USBD_HID_KBD_TAB = 43, /**<KBD_TAB code*/
|
||||
APP_USBD_HID_KBD_SPACEBAR = 44, /**<KBD_SPACEBAR code*/
|
||||
APP_USBD_HID_KBD_UNDERSCORE = 45, /**<KBD_UNDERSCORE code*/
|
||||
APP_USBD_HID_KBD_PLUS = 46, /**<KBD_PLUS code*/
|
||||
APP_USBD_HID_KBD_OPEN_BRACKET = 47, /**<KBD_OPEN_BRACKET code*/
|
||||
APP_USBD_HID_KBD_CLOSE_BRACKET = 48, /**<KBD_CLOSE_BRACKET code*/
|
||||
APP_USBD_HID_KBD_BACKSLASH = 49, /**<KBD_BACKSLASH code*/
|
||||
APP_USBD_HID_KBD_ASH = 50, /**<KBD_ASH code*/
|
||||
APP_USBD_HID_KBD_COLON = 51, /**<KBD_COLON code*/
|
||||
APP_USBD_HID_KBD_QUOTE = 52, /**<KBD_QUOTE code*/
|
||||
APP_USBD_HID_KBD_TILDE = 53, /**<KBD_TILDE code*/
|
||||
APP_USBD_HID_KBD_COMMA = 54, /**<KBD_COMMA code*/
|
||||
APP_USBD_HID_KBD_DOT = 55, /**<KBD_DOT code*/
|
||||
APP_USBD_HID_KBD_SLASH = 56, /**<KBD_SLASH code*/
|
||||
APP_USBD_HID_KBD_CAPS_LOCK = 57, /**<KBD_CAPS_LOCK code*/
|
||||
APP_USBD_HID_KBD_F1 = 58, /**<KBD_F1 code*/
|
||||
APP_USBD_HID_KBD_F2 = 59, /**<KBD_F2 code*/
|
||||
APP_USBD_HID_KBD_F3 = 60, /**<KBD_F3 code*/
|
||||
APP_USBD_HID_KBD_F4 = 61, /**<KBD_F4 code*/
|
||||
APP_USBD_HID_KBD_F5 = 62, /**<KBD_F5 code*/
|
||||
APP_USBD_HID_KBD_F6 = 63, /**<KBD_F6 code*/
|
||||
APP_USBD_HID_KBD_F7 = 64, /**<KBD_F7 code*/
|
||||
APP_USBD_HID_KBD_F8 = 65, /**<KBD_F8 code*/
|
||||
APP_USBD_HID_KBD_F9 = 66, /**<KBD_F9 code*/
|
||||
APP_USBD_HID_KBD_F10 = 67, /**<KBD_F10 code*/
|
||||
APP_USBD_HID_KBD_F11 = 68, /**<KBD_F11 code*/
|
||||
APP_USBD_HID_KBD_F12 = 69, /**<KBD_F12 code*/
|
||||
APP_USBD_HID_KBD_PRINTSCREEN = 70, /**<KBD_PRINTSCREEN code*/
|
||||
APP_USBD_HID_KBD_SCROLL_LOCK = 71, /**<KBD_SCROLL_LOCK code*/
|
||||
APP_USBD_HID_KBD_PAUSE = 72, /**<KBD_PAUSE code*/
|
||||
APP_USBD_HID_KBD_INSERT = 73, /**<KBD_INSERT code*/
|
||||
APP_USBD_HID_KBD_HOME = 74, /**<KBD_HOME code*/
|
||||
APP_USBD_HID_KBD_PAGEUP = 75, /**<KBD_PAGEUP code*/
|
||||
APP_USBD_HID_KBD_DELETE = 76, /**<KBD_DELETE code*/
|
||||
APP_USBD_HID_KBD_END = 77, /**<KBD_END code*/
|
||||
APP_USBD_HID_KBD_PAGEDOWN = 78, /**<KBD_PAGEDOWN code*/
|
||||
APP_USBD_HID_KBD_RIGHT = 79, /**<KBD_RIGHT code*/
|
||||
APP_USBD_HID_KBD_LEFT = 80, /**<KBD_LEFT code*/
|
||||
APP_USBD_HID_KBD_DOWN = 81, /**<KBD_DOWN code*/
|
||||
APP_USBD_HID_KBD_UP = 82, /**<KBD_UP code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_NUM_LOCK = 83, /**<KBD_KEYPAD_NUM_LOCK code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_DIVIDE = 84, /**<KBD_KEYPAD_DIVIDE code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_AT = 85, /**<KBD_KEYPAD_AT code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_MULTIPLY = 85, /**<KBD_KEYPAD_MULTIPLY code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_MINUS = 86, /**<KBD_KEYPAD_MINUS code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_PLUS = 87, /**<KBD_KEYPAD_PLUS code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_ENTER = 88, /**<KBD_KEYPAD_ENTER code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_1 = 89, /**<KBD_KEYPAD_1 code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_2 = 90, /**<KBD_KEYPAD_2 code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_3 = 91, /**<KBD_KEYPAD_3 code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_4 = 92, /**<KBD_KEYPAD_4 code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_5 = 93, /**<KBD_KEYPAD_5 code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_6 = 94, /**<KBD_KEYPAD_6 code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_7 = 95, /**<KBD_KEYPAD_7 code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_8 = 96, /**<KBD_KEYPAD_8 code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_9 = 97, /**<KBD_KEYPAD_9 code*/
|
||||
APP_USBD_HID_KBD_KEYPAD_0 = 98, /**<KBD_KEYPAD_0 code*/
|
||||
} app_usbd_hid_kbd_codes_t;
|
||||
|
||||
/**
|
||||
* @brief HID keyboard modifier
|
||||
* */
|
||||
typedef enum {
|
||||
APP_USBD_HID_KBD_MODIFIER_NONE = 0x00, /**< MODIFIER_NONE bit*/
|
||||
APP_USBD_HID_KBD_MODIFIER_LEFT_CTRL = 0x01, /**< MODIFIER_LEFT_CTRL bit*/
|
||||
APP_USBD_HID_KBD_MODIFIER_LEFT_SHIFT = 0x02, /**< MODIFIER_LEFT_SHIFT bit*/
|
||||
APP_USBD_HID_KBD_MODIFIER_LEFT_ALT = 0x04, /**< MODIFIER_LEFT_ALT bit*/
|
||||
APP_USBD_HID_KBD_MODIFIER_LEFT_UI = 0x08, /**< MODIFIER_LEFT_UI bit*/
|
||||
APP_USBD_HID_KBD_MODIFIER_RIGHT_CTRL = 0x10, /**< MODIFIER_RIGHT_CTRL bit*/
|
||||
APP_USBD_HID_KBD_MODIFIER_RIGHT_SHIFT = 0x20, /**< MODIFIER_RIGHT_SHIFT bit*/
|
||||
APP_USBD_HID_KBD_MODIFIER_RIGHT_ALT = 0x40, /**< MODIFIER_RIGHT_ALT bit*/
|
||||
APP_USBD_HID_KBD_MODIFIER_RIGHT_UI = 0x80, /**< MODIFIER_RIGHT_UI bit*/
|
||||
} app_usbd_hid_kbd_modifier_t;
|
||||
|
||||
/**
|
||||
* @brief HID keyboard LEDs
|
||||
* */
|
||||
typedef enum {
|
||||
APP_USBD_HID_KBD_LED_NUM_LOCK = 0x01, /**< LED_NUM_LOCK id*/
|
||||
APP_USBD_HID_KBD_LED_CAPS_LOCK = 0x02, /**< LED_CAPS_LOCK id*/
|
||||
APP_USBD_HID_KBD_LED_SCROLL_LOCK = 0x04, /**< LED_SCROLL_LOCK id*/
|
||||
APP_USBD_HID_KBD_LED_COMPOSE = 0x08, /**< LED_COMPOSE id*/
|
||||
APP_USBD_HID_KBD_LED_KANA = 0x10, /**< LED_KANA id*/
|
||||
} app_usbd_hid_kbd_led_t;
|
||||
|
||||
|
||||
|
||||
#ifdef DOXYGEN
|
||||
/**
|
||||
* @brief HID keyboard class instance type
|
||||
*
|
||||
* @ref APP_USBD_CLASS_TYPEDEF
|
||||
*/
|
||||
typedef struct { } app_usbd_hid_kbd_t;
|
||||
#else
|
||||
/*lint -save -e10 -e26 -e123 -e505 */
|
||||
APP_USBD_CLASS_TYPEDEF(app_usbd_hid_kbd, \
|
||||
APP_USBD_HID_KBD_CONFIG(0, NRF_DRV_USBD_EPIN1), \
|
||||
APP_USBD_HID_KBD_INSTANCE_SPECIFIC_DEC, \
|
||||
APP_USBD_HID_KBD_DATA_SPECIFIC_DEC \
|
||||
);
|
||||
/*lint -restore*/
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Global definition of app_usbd_hid_kbd_t class
|
||||
*
|
||||
* @param instance_name Name of global instance
|
||||
* @param interface_number Unique interface index
|
||||
* @param endpoint Input endpoint (@ref nrf_drv_usbd_ep_t)
|
||||
* @param user_ev_handler User event handler (optional)
|
||||
*
|
||||
* Example class definition:
|
||||
* @code
|
||||
APP_USBD_HID_KBD_GLOBAL_DEF(my_awesome_kbd, 0, NRF_DRV_USBD_EPIN1, NULL)
|
||||
* @endcode
|
||||
*/
|
||||
#define APP_USBD_HID_KBD_GLOBAL_DEF(instance_name, interface_number, endpoint, user_ev_handler) \
|
||||
APP_USBD_HID_KBD_GLOBAL_DEF_INTERNAL(instance_name, \
|
||||
interface_number, \
|
||||
endpoint, \
|
||||
user_ev_handler)
|
||||
|
||||
/**
|
||||
* @brief Helper function to get class instance from HID keyboard internals
|
||||
*
|
||||
* @param[in] p_kbd Keyboard instance (declared by @ref APP_USBD_HID_KBD_GLOBAL_DEF)
|
||||
* @return Base class instance
|
||||
* */
|
||||
static inline app_usbd_class_inst_t const *
|
||||
app_usbd_hid_kbd_class_inst_get(app_usbd_hid_kbd_t const * p_kbd)
|
||||
{
|
||||
return &p_kbd->base;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Helper function to get HID keyboard from base class instance
|
||||
*
|
||||
* @param[in] p_inst Base class instance
|
||||
* @return HID keyboard class handle
|
||||
*/
|
||||
static inline app_usbd_hid_kbd_t const *
|
||||
app_usbd_hid_kbd_class_get(app_usbd_class_inst_t const * p_inst)
|
||||
{
|
||||
return (app_usbd_hid_kbd_t const *)p_inst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set HID keyboard modifier state
|
||||
*
|
||||
* @param[in] p_kbd Keyboard instance (declared by @ref APP_USBD_HID_KBD_GLOBAL_DEF)
|
||||
* @param[in] modifier Type of modifier
|
||||
* @param[in] state State, true active, false inactive
|
||||
* @return Standard error code
|
||||
* */
|
||||
ret_code_t app_usbd_hid_kbd_modifier_state_set(app_usbd_hid_kbd_t const * p_kbd,
|
||||
app_usbd_hid_kbd_modifier_t modifier,
|
||||
bool state);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Press/release HID keyboard key
|
||||
*
|
||||
* @param[in] p_kbd Keyboard instance (declared by @ref APP_USBD_HID_KBD_GLOBAL_DEF)
|
||||
* @param[in] key Keyboard key code
|
||||
* @param[in] press True -> key press, false -> release
|
||||
* @return Standard error code
|
||||
* */
|
||||
ret_code_t app_usbd_hid_kbd_key_control(app_usbd_hid_kbd_t const * p_kbd,
|
||||
app_usbd_hid_kbd_codes_t key,
|
||||
bool press);
|
||||
/**
|
||||
* @brief HID Keyboard LEDs state get
|
||||
*
|
||||
* @param[in] p_kbd Keyboard instance (declared by @ref APP_USBD_HID_KBD_GLOBAL_DEF)
|
||||
* @param[in] led LED code
|
||||
* @return true if LED is set, false otherwise
|
||||
* */
|
||||
bool app_usbd_hid_kbd_led_state_get(app_usbd_hid_kbd_t const * p_kbd,
|
||||
app_usbd_hid_kbd_led_t led);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_HID_KBD_H__ */
|
||||
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_HID_KBD_DESC_H__
|
||||
#define APP_USBD_HID_KBD_DESC_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_hid_kbd_desc USB HID keyboard descriptors
|
||||
* @ingroup app_usbd_hid_kbd
|
||||
*
|
||||
* @brief @tagAPI52840 Module with types, definitions, and API used by the HID keyboard class.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializer of interface descriptor for HID keyboard class
|
||||
*
|
||||
* @param interface_number Interface number
|
||||
* */
|
||||
#define APP_USBD_HID_KBD_INTERFACE_DSC(interface_number) \
|
||||
APP_USBD_HID_INTERFACE_DSC(interface_number, \
|
||||
1, \
|
||||
APP_USBD_HID_SUBCLASS_BOOT, \
|
||||
APP_USBD_HID_PROTO_KEYBOARD)
|
||||
|
||||
/**
|
||||
* @brief Initializer of HID descriptor for HID keyboard class
|
||||
*
|
||||
* @param ... Report descriptor item
|
||||
* */
|
||||
#define APP_USBD_HID_KBD_HID_DSC(...) \
|
||||
APP_USBD_HID_HID_DSC(__VA_ARGS__)
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptor for HID keyboard class
|
||||
*
|
||||
* @param endpoint Endpoint number
|
||||
* */
|
||||
#define APP_USBD_HID_KBD_EP_DSC(endpoint) \
|
||||
APP_USBD_HID_EP_DSC(endpoint, 8, 1)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Example of USB HID keyboard report descriptor
|
||||
*
|
||||
* */
|
||||
#define APP_USBD_HID_KBD_REPORT_DSC() { \
|
||||
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */\
|
||||
0x09, 0x06, /* USAGE (Keyboard) */\
|
||||
0xa1, 0x01, /* COLLECTION (Application) */\
|
||||
0x05, 0x07, /* USAGE_PAGE (Keyboard) */\
|
||||
0x19, 0xe0, /* USAGE_MINIMUM (Keyboard LeftControl) */\
|
||||
0x29, 0xe7, /* USAGE_MAXIMUM (Keyboard Right GUI) */\
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */\
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */\
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */\
|
||||
0x95, 0x08, /* REPORT_COUNT (8) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */\
|
||||
0x81, 0x03, /* INPUT (Cnst,Var,Abs) */\
|
||||
0x95, 0x05, /* REPORT_COUNT (5) */\
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */\
|
||||
0x05, 0x08, /* USAGE_PAGE (LEDs) */\
|
||||
0x19, 0x01, /* USAGE_MINIMUM (Num Lock) */\
|
||||
0x29, 0x05, /* USAGE_MAXIMUM (Kana) */\
|
||||
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0x75, 0x03, /* REPORT_SIZE (3) */\
|
||||
0x91, 0x03, /* OUTPUT (Cnst,Var,Abs) */\
|
||||
0x95, 0x06, /* REPORT_COUNT (6) */\
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */\
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */\
|
||||
0x25, 0x65, /* LOGICAL_MAXIMUM (101) */\
|
||||
0x05, 0x07, /* USAGE_PAGE (Keyboard) */\
|
||||
0x19, 0x00, /* USAGE_MINIMUM (Reserved (no event indicated))*/\
|
||||
0x29, 0x65, /* USAGE_MAXIMUM (Keyboard Application) */\
|
||||
0x81, 0x00, /* INPUT (Data,Ary,Abs) */\
|
||||
0xc0 /* END_COLLECTION */\
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_HID_KBD_DESC_H__ */
|
||||
@@ -0,0 +1,197 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_HID_KBD_INTERNAL_H__
|
||||
#define APP_USBD_HID_KBD_INTERNAL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_hid_kbd_internal USB HID keyboard internals
|
||||
* @ingroup app_usbd_hid_kbd
|
||||
*
|
||||
* @brief @tagAPI52840 Module with types, definitions, and API used by the HID keyboard class.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Forward declaration of HID keyboard class type
|
||||
*
|
||||
*/
|
||||
APP_USBD_CLASS_FORWARD(app_usbd_hid_kbd);
|
||||
|
||||
|
||||
/**
|
||||
* @brief HID keyboard part of class instance data
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
app_usbd_hid_inst_t hid_inst; //!< HID instance data
|
||||
} app_usbd_hid_kbd_inst_t;
|
||||
|
||||
/**
|
||||
* @brief HID keyboard context
|
||||
*
|
||||
* */
|
||||
typedef struct {
|
||||
app_usbd_hid_ctx_t hid_ctx; //!< HID class context
|
||||
|
||||
struct app_usbd_hid_kbd_ctx_internal_s {
|
||||
uint8_t modifier; //!< Keyboard modifier state @ref app_usbd_hid_kbd_modifier_t
|
||||
uint8_t reserved; //!< Reserved value
|
||||
uint8_t key_table[6]; //!< Keyboard keys table @ref app_usbd_hid_kbd_codes_t
|
||||
} rep;
|
||||
|
||||
uint8_t report_buff[8]; //!< Raw report buffer
|
||||
uint8_t leds_state; //!< Output report LEDs state
|
||||
uint8_t set_report; //!< Set report flag
|
||||
} app_usbd_hid_kbd_ctx_t;
|
||||
|
||||
/**
|
||||
* @brief HID keyboard configuration macro
|
||||
*
|
||||
* Used by @ref APP_USBD_HID_KBD_GLOBAL_DEF
|
||||
*
|
||||
*
|
||||
* */
|
||||
#define APP_USBD_HID_KBD_CONFIG(iface, ep) ((iface, ep))
|
||||
|
||||
|
||||
/**
|
||||
* @brief Specific class constant data for HID keyboard class
|
||||
* */
|
||||
#define APP_USBD_HID_KBD_INSTANCE_SPECIFIC_DEC app_usbd_hid_kbd_inst_t inst;
|
||||
|
||||
/**
|
||||
* @brief Specific class data for HID keyboard class
|
||||
* */
|
||||
#define APP_USBD_HID_KBD_DATA_SPECIFIC_DEC app_usbd_hid_kbd_ctx_t ctx;
|
||||
|
||||
|
||||
/**
|
||||
* @brief HID keyboard descriptors config macro
|
||||
*
|
||||
* @ref app_usbd_hid_kbd_inst_t
|
||||
*
|
||||
* @param interface_number Interface number
|
||||
* @param endpoint Endpoint number
|
||||
* @param rep_descriptor Keyboard report descriptor
|
||||
* */
|
||||
#define APP_USBD_HID_KBD_DSC_CONFIG(interface_number, endpoint, rep_descriptor) { \
|
||||
APP_USBD_HID_KBD_INTERFACE_DSC(interface_number) \
|
||||
APP_USBD_HID_KBD_HID_DSC(rep_descriptor) \
|
||||
APP_USBD_HID_KBD_EP_DSC(endpoint) \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure internal part of HID keyboard instance
|
||||
*
|
||||
* @param descriptors Raw descriptors buffer
|
||||
* @param report_desc Report descriptor
|
||||
* @param report_buff_in Input report buffers array
|
||||
* @param report_buff_out Output report buffer
|
||||
* @param user_ev_handler User event handler
|
||||
*/
|
||||
#define APP_USBD_HID_KBD_INST_CONFIG(descriptors, \
|
||||
report_desc, \
|
||||
report_buff_in, \
|
||||
report_buff_out, \
|
||||
user_ev_handler) \
|
||||
.inst = { \
|
||||
.hid_inst = APP_USBD_HID_INST_CONFIG(descriptors, \
|
||||
report_desc, \
|
||||
report_buff_in, \
|
||||
report_buff_out, \
|
||||
user_ev_handler, \
|
||||
&app_usbd_hid_kbd_methods), \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Public HID keyboard interface
|
||||
* */
|
||||
extern const app_usbd_hid_methods_t app_usbd_hid_kbd_methods;
|
||||
|
||||
/**
|
||||
* @brief Public HID keyboard class interface
|
||||
* */
|
||||
extern const app_usbd_class_methods_t app_usbd_hid_kbd_class_methods;
|
||||
|
||||
/**
|
||||
* @brief Global definition of @ref app_usbd_hid_kbd_t class
|
||||
*
|
||||
* @ref APP_USBD_HID_KBD_GLOBAL_DEF
|
||||
*/
|
||||
#define APP_USBD_HID_KBD_GLOBAL_DEF_INTERNAL(instance_name, \
|
||||
interface_number, \
|
||||
endpoint, \
|
||||
user_ev_handler) \
|
||||
static const uint8_t CONCAT_2(instance_name, _rep_dsc)[] = \
|
||||
APP_USBD_HID_KBD_REPORT_DSC(); \
|
||||
static const uint8_t CONCAT_2(instance_name, _dsc)[] = \
|
||||
APP_USBD_HID_KBD_DSC_CONFIG(interface_number, \
|
||||
endpoint, \
|
||||
CONCAT_2(instance_name, _rep_dsc)); \
|
||||
APP_USBD_HID_GENERIC_GLOBAL_OUT_REP_DEF(CONCAT_2(instance_name, _out), 1 + 1); \
|
||||
static app_usbd_hid_report_buffer_t CONCAT_2(instance_name, _in)[1]; \
|
||||
APP_USBD_CLASS_INST_GLOBAL_DEF( \
|
||||
instance_name, \
|
||||
app_usbd_hid_kbd, \
|
||||
&app_usbd_hid_kbd_class_methods, \
|
||||
APP_USBD_HID_KBD_CONFIG(interface_number, endpoint), \
|
||||
(APP_USBD_HID_KBD_INST_CONFIG(CONCAT_2(instance_name, _dsc), \
|
||||
CONCAT_2(instance_name, _rep_dsc), \
|
||||
CONCAT_2(instance_name, _in), \
|
||||
&CONCAT_2(instance_name, _out), \
|
||||
user_ev_handler)) \
|
||||
)
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_HID_KBD_INTERNAL_H__ */
|
||||
Reference in New Issue
Block a user