mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-18 22:38:32 +03:00
Renamed main folder to firmware
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
@@ -0,0 +1,374 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \addtogroup usbd_hid_key
|
||||
*@{
|
||||
* Implement HID Keyboard Function For USB Device.
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Headers
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
#include <HIDDKeyboard.h>
|
||||
#include <HIDDFunction.h>
|
||||
|
||||
#include <USBLib_Trace.h>
|
||||
|
||||
#include <USBRequests.h>
|
||||
#include <HIDDescriptors.h>
|
||||
#include <HIDRequests.h>
|
||||
#include <HIDReports.h>
|
||||
#include <HIDUsages.h>
|
||||
|
||||
#include <USBD.h>
|
||||
#include <USBD_HAL.h>
|
||||
#include <USBDDriver.h>
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Internal types
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Extended struct for an HID Keyboard Input report, for transfer driver to
|
||||
* send reports.
|
||||
*/
|
||||
typedef struct _KBDInputReport {
|
||||
/** Callback when report done */
|
||||
HIDDReportEventCallback fCallback;
|
||||
/** Callback arguments */
|
||||
void* pArg;
|
||||
|
||||
/** Report size (ID + DATA) */
|
||||
uint16_t wMaxSize;
|
||||
/** Transfered size */
|
||||
uint16_t wTransferred;
|
||||
/** Report idle rate */
|
||||
uint8_t bIdleRate;
|
||||
/** Delay count for Idle */
|
||||
uint8_t bDelay;
|
||||
/** Report ID */
|
||||
uint8_t bID;
|
||||
/** Input Report Data Block */
|
||||
HIDDKeyboardInputReport sReport;
|
||||
} KBDInputReport;
|
||||
|
||||
/**
|
||||
* Extended struct for an HID Keyboard Output report, for transfer driver to
|
||||
* polling reports.
|
||||
*/
|
||||
typedef struct _KBDOutputReport {
|
||||
/** Callback when report done */
|
||||
HIDDReportEventCallback fCallback;
|
||||
/** Callback arguments */
|
||||
void* pArg;
|
||||
|
||||
/** Report size (ID + DATA) */
|
||||
uint16_t wMaxSize;
|
||||
/** Transfered size */
|
||||
uint16_t wTransferred;
|
||||
/** Report idle rate */
|
||||
uint8_t bIdleRate;
|
||||
/** Delay count for Idle */
|
||||
uint8_t bDelay;
|
||||
/** Report ID */
|
||||
uint8_t bID;
|
||||
/** Output Report Data Block */
|
||||
HIDDKeyboardOutputReport sReport;
|
||||
} KBDOutputReport;
|
||||
|
||||
/**
|
||||
* Driver structure for an HID device implementing keyboard functionalities.
|
||||
*/
|
||||
typedef struct _HIDDKeyboard {
|
||||
|
||||
/** USB HID Functionn */
|
||||
HIDDFunction hidDrv;
|
||||
/** Input report list */
|
||||
HIDDReport *inputReports[1];
|
||||
/** Output report list */
|
||||
HIDDReport *outputReports[1];
|
||||
} HIDDKeyboard;
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Internal variables
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/** HIDD Keyboard Input Report Instance */
|
||||
static KBDInputReport inputReport;
|
||||
|
||||
/** HIDD Keyboard Output Report Instance */
|
||||
static KBDOutputReport outputReport;
|
||||
|
||||
/** Static instance of the HIDD keyboard device driver. */
|
||||
static HIDDKeyboard hiddKeyboard;
|
||||
|
||||
/** Report descriptor used by the driver. */
|
||||
const uint8_t hiddKeyboardReportDescriptor[] = {
|
||||
|
||||
HIDReport_GLOBAL_USAGEPAGE + 1, HIDGenericDesktop_PAGEID,
|
||||
HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_KEYBOARD,
|
||||
HIDReport_COLLECTION + 1, HIDReport_COLLECTION_APPLICATION,
|
||||
|
||||
/* Input report: modifier keys */
|
||||
HIDReport_GLOBAL_REPORTSIZE + 1, 1,
|
||||
HIDReport_GLOBAL_REPORTCOUNT + 1, 8,
|
||||
HIDReport_GLOBAL_USAGEPAGE + 1, HIDKeypad_PAGEID,
|
||||
HIDReport_LOCAL_USAGEMINIMUM + 1,
|
||||
HIDDKeyboardDescriptors_FIRSTMODIFIERKEY,
|
||||
HIDReport_LOCAL_USAGEMAXIMUM + 1,
|
||||
HIDDKeyboardDescriptors_LASTMODIFIERKEY,
|
||||
HIDReport_GLOBAL_LOGICALMINIMUM + 1, 0,
|
||||
HIDReport_GLOBAL_LOGICALMAXIMUM + 1, 1,
|
||||
HIDReport_INPUT + 1, HIDReport_VARIABLE,
|
||||
|
||||
/* Input report: standard keys */
|
||||
HIDReport_GLOBAL_REPORTCOUNT + 1, 3,
|
||||
HIDReport_GLOBAL_REPORTSIZE + 1, 8,
|
||||
HIDReport_GLOBAL_LOGICALMINIMUM + 1,
|
||||
HIDDKeyboardDescriptors_FIRSTSTANDARDKEY,
|
||||
HIDReport_GLOBAL_LOGICALMAXIMUM + 1,
|
||||
HIDDKeyboardDescriptors_LASTSTANDARDKEY,
|
||||
HIDReport_GLOBAL_USAGEPAGE + 1, HIDKeypad_PAGEID,
|
||||
HIDReport_LOCAL_USAGEMINIMUM + 1,
|
||||
HIDDKeyboardDescriptors_FIRSTSTANDARDKEY,
|
||||
HIDReport_LOCAL_USAGEMAXIMUM + 1,
|
||||
HIDDKeyboardDescriptors_LASTSTANDARDKEY,
|
||||
HIDReport_INPUT + 1, 0 /* Data array */,
|
||||
|
||||
/* Output report: LEDs */
|
||||
HIDReport_GLOBAL_REPORTCOUNT + 1, 3,
|
||||
HIDReport_GLOBAL_REPORTSIZE + 1, 1,
|
||||
HIDReport_GLOBAL_USAGEPAGE + 1, HIDLeds_PAGEID,
|
||||
HIDReport_GLOBAL_LOGICALMINIMUM + 1, 0,
|
||||
HIDReport_GLOBAL_LOGICALMAXIMUM + 1, 1,
|
||||
HIDReport_LOCAL_USAGEMINIMUM + 1, HIDLeds_NUMLOCK,
|
||||
HIDReport_LOCAL_USAGEMAXIMUM + 1, HIDLeds_SCROLLLOCK,
|
||||
HIDReport_OUTPUT + 1, HIDReport_VARIABLE,
|
||||
|
||||
/* Output report: padding */
|
||||
HIDReport_GLOBAL_REPORTCOUNT + 1, 1,
|
||||
HIDReport_GLOBAL_REPORTSIZE + 1, 5,
|
||||
HIDReport_OUTPUT + 1, HIDReport_CONSTANT,
|
||||
|
||||
HIDReport_ENDCOLLECTION
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Internal functions
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Callback invoked when an output report has been received from the host.
|
||||
* Forward the new status of the LEDs to the user program via the
|
||||
* HIDDKeyboardCallbacks_LedsChanged callback.
|
||||
*/
|
||||
static void HIDDKeyboard_ReportReceived(void)
|
||||
{
|
||||
HIDDKeyboardOutputReport *pOut = &outputReport.sReport;
|
||||
|
||||
/* Trigger callback */
|
||||
if (HIDDKeyboardCallbacks_LedsChanged) {
|
||||
HIDDKeyboardCallbacks_LedsChanged(
|
||||
pOut->numLockStatus,
|
||||
pOut->capsLockStatus,
|
||||
pOut->scrollLockStatus);
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Exported functions
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Initializes the HID keyboard device driver SW.
|
||||
* (Init USBDDriver .., Init function driver .., Init USBD ...)
|
||||
* \param pUsbd Pointer to USBDDriver instance.
|
||||
* \param bInterfaceNb Interface number for the function.
|
||||
*/
|
||||
void HIDDKeyboard_Initialize(USBDDriver* pUsbd, uint8_t bInterfaceNb)
|
||||
{
|
||||
HIDDKeyboard *pKbd = &hiddKeyboard;
|
||||
HIDDFunction *pHidd = &pKbd->hidDrv;
|
||||
|
||||
/* One input report */
|
||||
pKbd->inputReports[0] = (HIDDReport*)&inputReport;
|
||||
HIDDFunction_InitializeReport(pKbd->inputReports[0],
|
||||
sizeof(HIDDKeyboardInputReport),
|
||||
0,
|
||||
0, 0);
|
||||
/* One output report */
|
||||
pKbd->outputReports[0] = (HIDDReport*)&outputReport;
|
||||
HIDDFunction_InitializeReport(
|
||||
pKbd->outputReports[0],
|
||||
sizeof(HIDDKeyboardOutputReport),
|
||||
0,
|
||||
(HIDDReportEventCallback)HIDDKeyboard_ReportReceived, 0);
|
||||
|
||||
/* Function initialize */
|
||||
HIDDFunction_Initialize(pHidd,
|
||||
pUsbd, bInterfaceNb,
|
||||
hiddKeyboardReportDescriptor,
|
||||
pKbd->inputReports, 1,
|
||||
pKbd->outputReports, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure function with expected descriptors and start functionality.
|
||||
* Usually invoked when device is configured.
|
||||
* \pDescriptors Pointer to the descriptors for function configure.
|
||||
* \wLength Length of descriptors in number of bytes.
|
||||
*/
|
||||
void HIDDKeyboard_ConfigureFunction(USBGenericDescriptor *pDescriptors,
|
||||
uint16_t wLength)
|
||||
{
|
||||
HIDDKeyboard *pKbd = &hiddKeyboard;
|
||||
HIDDFunction *pHidd = &pKbd->hidDrv;
|
||||
USBGenericDescriptor * pDesc = pDescriptors;
|
||||
|
||||
pDesc = HIDDFunction_ParseInterface(pHidd,
|
||||
pDescriptors,
|
||||
wLength);
|
||||
|
||||
/* Start receiving output reports */
|
||||
HIDDFunction_StartPollingOutputs(pHidd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles HID-specific SETUP request sent by the host.
|
||||
* \param request Pointer to a USBGenericRequest instance.
|
||||
* \return USBRC_SUCCESS if request is handled.
|
||||
*/
|
||||
uint32_t HIDDKeyboard_RequestHandler(const USBGenericRequest *request)
|
||||
{
|
||||
HIDDKeyboard *pKbd = &hiddKeyboard;
|
||||
HIDDFunction *pHidd = &pKbd->hidDrv;
|
||||
|
||||
TRACE_INFO_WP("Kbd ");
|
||||
|
||||
/* Process HID requests */
|
||||
return HIDDFunction_RequestHandler(pHidd, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a change in which keys are currently pressed or release to the
|
||||
* host.
|
||||
*
|
||||
* \param pressedKeys Pointer to an array of key codes indicating keys that have
|
||||
* been pressed since the last call to
|
||||
* HIDDKeyboardDriver_ChangeKeys().
|
||||
* \param pressedKeysSize Number of key codes in the pressedKeys array.
|
||||
* \param releasedKeys Pointer to an array of key codes indicates keys that have
|
||||
* been released since the last call to
|
||||
* HIDDKeyboardDriver_ChangeKeys().
|
||||
* \param releasedKeysSize Number of key codes in the releasedKeys array.
|
||||
* \return USBD_STATUS_SUCCESS if the report has been sent to the host;
|
||||
* otherwise an error code.
|
||||
*/
|
||||
uint32_t HIDDKeyboard_ChangeKeys(uint8_t *pressedKeys,
|
||||
uint8_t pressedKeysSize,
|
||||
uint8_t *releasedKeys,
|
||||
uint8_t releasedKeysSize)
|
||||
{
|
||||
HIDDKeyboard *pKbd = &hiddKeyboard;
|
||||
HIDDFunction *pHidd = &pKbd->hidDrv;
|
||||
HIDDKeyboardInputReport *pReport =
|
||||
(HIDDKeyboardInputReport *)pKbd->inputReports[0]->bData;
|
||||
|
||||
/* Press keys */
|
||||
while (pressedKeysSize > 0) {
|
||||
|
||||
/* Check if this is a standard or modifier key */
|
||||
if (HIDKeypad_IsModifierKey(*pressedKeys)) {
|
||||
|
||||
/* Set the corresponding bit in the input report */
|
||||
HIDDKeyboardInputReport_PressModifierKey(
|
||||
pReport,
|
||||
*pressedKeys);
|
||||
}
|
||||
else {
|
||||
|
||||
HIDDKeyboardInputReport_PressStandardKey(
|
||||
pReport,
|
||||
*pressedKeys);
|
||||
}
|
||||
|
||||
pressedKeysSize--;
|
||||
pressedKeys++;
|
||||
}
|
||||
|
||||
/* Release keys */
|
||||
while (releasedKeysSize > 0) {
|
||||
|
||||
/* Check if this is a standard or modifier key */
|
||||
if (HIDKeypad_IsModifierKey(*releasedKeys)) {
|
||||
|
||||
/* Set the corresponding bit in the input report */
|
||||
HIDDKeyboardInputReport_ReleaseModifierKey(
|
||||
pReport,
|
||||
*releasedKeys);
|
||||
}
|
||||
else {
|
||||
|
||||
HIDDKeyboardInputReport_ReleaseStandardKey(
|
||||
pReport,
|
||||
*releasedKeys);
|
||||
}
|
||||
|
||||
releasedKeysSize--;
|
||||
releasedKeys++;
|
||||
}
|
||||
|
||||
/* Send input report through the interrupt IN endpoint */
|
||||
return USBD_Write(pHidd->bPipeIN,
|
||||
pReport,
|
||||
sizeof(HIDDKeyboardInputReport),
|
||||
0,
|
||||
0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a remote wake-up sequence if the host has explicitely enabled it
|
||||
* by sending the appropriate SET_FEATURE request.
|
||||
*/
|
||||
void HIDDKeyboard_RemoteWakeUp(void)
|
||||
{
|
||||
HIDDKeyboard *pKbd = &hiddKeyboard;
|
||||
HIDDFunction *pHidd = &pKbd->hidDrv;
|
||||
USBDDriver *pUsbd = pHidd->pUsbd;
|
||||
|
||||
/* Remote wake-up has been enabled */
|
||||
if (USBDDriver_IsRemoteWakeUpEnabled(pUsbd)) {
|
||||
|
||||
USBD_RemoteWakeUp();
|
||||
}
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
@@ -0,0 +1,66 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \addtogroup usbd_hid_key
|
||||
*@{
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Headers
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
#include "HIDDKeyboardDriver.h"
|
||||
#include <USBLib_Trace.h>
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Exported functions
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* For HID Keyboard Function.
|
||||
* Indicates that the status of one or more LEDs has been changed by the
|
||||
* host.
|
||||
* \param numLockStatus Indicates the current status of the num. lock key.
|
||||
* \param capsLockStatus Indicates the current status of the caps lock key.
|
||||
* \param scrollLockStatus Indicates the current status of the scroll lock key.
|
||||
*/
|
||||
WEAK void HIDDKeyboardCallbacks_LedsChanged(
|
||||
uint8_t numLockStatus,
|
||||
uint8_t capsLockStatus,
|
||||
uint8_t scrollLockStatus)
|
||||
{
|
||||
TRACE_INFO(
|
||||
"LEDs status: %d, %d, %d\n\r",
|
||||
numLockStatus,
|
||||
capsLockStatus,
|
||||
scrollLockStatus);
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
@@ -0,0 +1,123 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \addtogroup usbd_hid_key
|
||||
*@{
|
||||
* Implement a USB device that only have HID Keyboard Function.
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Headers
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
#include <HIDDKeyboardDriver.h>
|
||||
#include <HIDDFunction.h>
|
||||
|
||||
#include <USBLib_Trace.h>
|
||||
|
||||
#include <USBRequests.h>
|
||||
#include <HIDDescriptors.h>
|
||||
#include <HIDRequests.h>
|
||||
#include <HIDReports.h>
|
||||
#include <HIDUsages.h>
|
||||
|
||||
#include <USBD.h>
|
||||
#include <USBD_HAL.h>
|
||||
#include <USBDDriver.h>
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Internal types
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Internal variables
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Internal functions
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Exported functions
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Initializes the HID keyboard device driver.
|
||||
*/
|
||||
void HIDDKeyboardDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
|
||||
{
|
||||
USBDDriver *pUsbd = USBD_GetDriver();
|
||||
USBDDriver_Initialize(pUsbd, pDescriptors, 0);
|
||||
HIDDKeyboard_Initialize(pUsbd, 0);
|
||||
USBD_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles configureation changed event.
|
||||
* \param cfgnum New configuration number
|
||||
*/
|
||||
void HIDDKeyboardDriver_ConfigurationChangedHandler(uint8_t cfgnum)
|
||||
{
|
||||
USBDDriver *pUsbd = USBD_GetDriver();
|
||||
const USBDDriverDescriptors * pDescriptors = pUsbd->pDescriptors;
|
||||
USBConfigurationDescriptor *pDesc;
|
||||
|
||||
if (cfgnum > 0) {
|
||||
if (USBD_HAL_IsHighSpeed() && pDescriptors->pHsConfiguration)
|
||||
pDesc = (USBConfigurationDescriptor*)pDescriptors->pHsConfiguration;
|
||||
else
|
||||
pDesc = (USBConfigurationDescriptor*)pDescriptors->pFsConfiguration[0];
|
||||
HIDDKeyboard_ConfigureFunction((USBGenericDescriptor*)pDesc,
|
||||
pDesc->wTotalLength);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles HID-specific SETUP request sent by the host.
|
||||
* \param request Pointer to a USBGenericRequest instance.
|
||||
*/
|
||||
void HIDDKeyboardDriver_RequestHandler(const USBGenericRequest *request)
|
||||
{
|
||||
USBDDriver *pUsbd = USBD_GetDriver();
|
||||
|
||||
TRACE_INFO_WP("NewReq ");
|
||||
|
||||
/* Process HID requests */
|
||||
if (USBRC_SUCCESS == HIDDKeyboard_RequestHandler(request)) {
|
||||
return;
|
||||
}
|
||||
/* Process STD requests */
|
||||
else {
|
||||
USBDDriver_RequestHandler(pUsbd, request);
|
||||
}
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* Implementation of the HIDDKeyboardInputReport class.
|
||||
*/
|
||||
|
||||
/** \addtogroup usbd_hid_key
|
||||
*@{
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Headers
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
#include <HIDDKeyboard.h>
|
||||
#include <USBLib_Trace.h>
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Exported functions
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Initializes a keyboard input report instance.
|
||||
* \param report Pointer to a HIDDKeyboardInputReport instance.
|
||||
*/
|
||||
void HIDDKeyboardInputReport_Initialize(HIDDKeyboardInputReport *report)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
report->bmModifierKeys = 0;
|
||||
for (i = 0; i < HIDDKeyboardInputReport_MAXKEYPRESSES; i++) {
|
||||
|
||||
report->pressedKeys[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a standard key as being pressed.
|
||||
* \param report Pointer to a HIDDKeyboardInputReport instance.
|
||||
* \param key Key code of the standard key.
|
||||
*/
|
||||
void HIDDKeyboardInputReport_PressStandardKey(HIDDKeyboardInputReport *report,
|
||||
uint8_t key)
|
||||
{
|
||||
/* Find first available slot */
|
||||
uint32_t i = 0;
|
||||
uint8_t found = 0;
|
||||
while ((i < HIDDKeyboardInputReport_MAXKEYPRESSES) && !found) {
|
||||
|
||||
/* Free slot: no key referenced (code = 0) or ErrorRollOver */
|
||||
if ((report->pressedKeys[i] == 0)
|
||||
|| (report->pressedKeys[i] == HIDKeypad_ERRORROLLOVER)) {
|
||||
|
||||
found = 1;
|
||||
report->pressedKeys[i] = key;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Report ErrorRollOver in all fields if too many keys are pressed */
|
||||
if (!found) {
|
||||
|
||||
for (i=0; i < HIDDKeyboardInputReport_MAXKEYPRESSES; i++) {
|
||||
|
||||
report->pressedKeys[i] = HIDKeypad_ERRORROLLOVER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a standard key as not being pressed anymore.
|
||||
* \param report Pointer to a HIDDKeyboardInputReport instance.
|
||||
* \param key Key code of the standard key
|
||||
*/
|
||||
void HIDDKeyboardInputReport_ReleaseStandardKey(HIDDKeyboardInputReport *report,
|
||||
uint8_t key)
|
||||
{
|
||||
/* Look for key in array */
|
||||
uint32_t i = 0;
|
||||
uint8_t found = 0;
|
||||
while ((i < HIDDKeyboardInputReport_MAXKEYPRESSES) && !found) {
|
||||
|
||||
if (report->pressedKeys[i] == key) {
|
||||
|
||||
found = 1;
|
||||
report->pressedKeys[i] = 0;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a modifier key as being currently pressed.
|
||||
* \param report Pointer to a HIDDKeyboardInputReport instance.
|
||||
* \param key Key code of the modifier key.
|
||||
*/
|
||||
void HIDDKeyboardInputReport_PressModifierKey(HIDDKeyboardInputReport *report,
|
||||
uint8_t key)
|
||||
{
|
||||
/* Set corresponding bit */
|
||||
uint8_t bit = key - HIDDKeyboardDescriptors_FIRSTMODIFIERKEY;
|
||||
report->bmModifierKeys |= 1 << bit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a modifier key as not being pressed anymore.
|
||||
* \param report Pointer to a HIDDKeyboardInputReport instance.
|
||||
* \param key Key code of the modifier key.
|
||||
*/
|
||||
void HIDDKeyboardInputReport_ReleaseModifierKey(HIDDKeyboardInputReport *report,
|
||||
uint8_t key)
|
||||
{
|
||||
/* Clear corresponding bit */
|
||||
uint8_t bit = key - HIDDKeyboardDescriptors_FIRSTMODIFIERKEY;
|
||||
report->bmModifierKeys &= ~(1 << bit);
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
@@ -0,0 +1,96 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* Implementation of the HIDDKeyboardOutputReport class.
|
||||
*/
|
||||
|
||||
/** \addtogroup usbd_hid_key
|
||||
*@{
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Headers
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
#include <HIDDKeyboard.h>
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Exported functions
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Initializes a keyboard output report.
|
||||
* \param report Pointer to a HIDDKeyboardOutputReport instance.
|
||||
*/
|
||||
void HIDDKeyboardOutputReport_Initialize(HIDDKeyboardOutputReport *report)
|
||||
{
|
||||
report->numLockStatus = 0;
|
||||
report->capsLockStatus = 0;
|
||||
report->scrollLockStatus = 0;
|
||||
report->padding = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the current status of the num. lock LED according to the
|
||||
* given report.
|
||||
* \param report Pointer to a HIDDKeyboardOutputReport instance.
|
||||
* \return 1 if the num. lock LED is light on; otherwise 0.
|
||||
*/
|
||||
unsigned char HIDDKeyboardOutputReport_GetNumLockStatus(
|
||||
const HIDDKeyboardOutputReport *report)
|
||||
{
|
||||
return report->numLockStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the current status of the caps lock LED according to the
|
||||
* given report.
|
||||
* \param report Pointer to a HIDDKeyboardOutputReport instance.
|
||||
* \return 1 if the caps lock LED is light on; otherwise 0.
|
||||
*/
|
||||
unsigned char HIDDKeyboardOutputReport_GetCapsLockStatus(
|
||||
const HIDDKeyboardOutputReport *report)
|
||||
{
|
||||
return report->capsLockStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the current status of the scroll lock LED according to the
|
||||
* given report.
|
||||
* \param report Pointer to a HIDDKeyboardOutputReport instance.
|
||||
* \return 1 if the scroll lock LED is light on; otherwise 0.
|
||||
*/
|
||||
unsigned char HIDDKeyboardOutputReport_GetScrollLockStatus(
|
||||
const HIDDKeyboardOutputReport *report)
|
||||
{
|
||||
return report->scrollLockStatus;
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
Reference in New Issue
Block a user