summaryrefslogtreecommitdiffstats
path: root/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser')
-rw-r--r--lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/Config/LUFAConfig.h93
-rw-r--r--lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.c189
-rw-r--r--lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.h67
-rw-r--r--lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/HIDReport.c90
-rw-r--r--lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/HIDReport.h67
-rw-r--r--lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c285
-rw-r--r--lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.h78
-rw-r--r--lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.txt71
-rw-r--r--lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/asf.xml52
-rw-r--r--lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/doxyfile2395
-rw-r--r--lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/makefile43
11 files changed, 0 insertions, 3430 deletions
diff --git a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/Config/LUFAConfig.h b/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/Config/LUFAConfig.h
deleted file mode 100644
index 197122fce1..0000000000
--- a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/Config/LUFAConfig.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- LUFA Library
- Copyright (C) Dean Camera, 2017.
-
- dean [at] fourwalledcubicle [dot] com
- www.lufa-lib.org
-*/
-
-/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
-
- Permission to use, copy, modify, distribute, and sell this
- software and its documentation for any purpose is hereby granted
- without fee, provided that the above copyright notice appear in
- all copies and that both that the copyright notice and this
- permission notice and warranty disclaimer appear in supporting
- documentation, and that the name of the author not be used in
- advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
-
- The author disclaims all warranties with regard to this
- software, including all implied warranties of merchantability
- and fitness. In no event shall the author be liable for any
- special, indirect or consequential damages or any damages
- whatsoever resulting from loss of use, data or profits, whether
- in an action of contract, negligence or other tortious action,
- arising out of or in connection with the use or performance of
- this software.
-*/
-
-/** \file
- * \brief LUFA Library Configuration Header File
- *
- * This header file is used to configure LUFA's compile time options,
- * as an alternative to the compile time constants supplied through
- * a makefile.
- *
- * For information on what each token does, refer to the LUFA
- * manual section "Summary of Compile Tokens".
- */
-
-#ifndef _LUFA_CONFIG_H_
-#define _LUFA_CONFIG_H_
-
- #if (ARCH == ARCH_AVR8)
-
- /* Non-USB Related Configuration Tokens: */
-// #define DISABLE_TERMINAL_CODES
-
- /* USB Class Driver Related Tokens: */
-// #define HID_HOST_BOOT_PROTOCOL_ONLY
-// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here}
-// #define HID_USAGE_STACK_DEPTH {Insert Value Here}
-// #define HID_MAX_COLLECTIONS {Insert Value Here}
-// #define HID_MAX_REPORTITEMS {Insert Value Here}
-// #define HID_MAX_REPORT_IDS {Insert Value Here}
-// #define NO_CLASS_DRIVER_AUTOFLUSH
-
- /* General USB Driver Related Tokens: */
-// #define ORDERED_EP_CONFIG
- #define USE_STATIC_OPTIONS (USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)
-// #define USB_DEVICE_ONLY
- #define USB_HOST_ONLY
-// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
-// #define NO_LIMITED_CONTROLLER_CONNECT
-// #define NO_SOF_EVENTS
-
- /* USB Device Mode Driver Related Tokens: */
-// #define USE_RAM_DESCRIPTORS
-// #define USE_FLASH_DESCRIPTORS
-// #define USE_EEPROM_DESCRIPTORS
-// #define NO_INTERNAL_SERIAL
-// #define FIXED_CONTROL_ENDPOINT_SIZE {Insert Value Here}
-// #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
-// #define FIXED_NUM_CONFIGURATIONS {Insert Value Here}
-// #define CONTROL_ONLY_DEVICE
-// #define INTERRUPT_CONTROL_ENDPOINT
-// #define NO_DEVICE_REMOTE_WAKEUP
-// #define NO_DEVICE_SELF_POWER
-
- /* USB Host Mode Driver Related Tokens: */
-// #define HOST_STATE_AS_GPIOR {Insert Value Here}
-// #define USB_HOST_TIMEOUT_MS {Insert Value Here}
-// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here}
-// #define NO_AUTO_VBUS_MANAGEMENT
-// #define INVERTED_VBUS_ENABLE_LINE
-
- #else
-
- #error Unsupported architecture for this LUFA configuration file.
-
- #endif
-#endif
diff --git a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.c b/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.c
deleted file mode 100644
index ab67915661..0000000000
--- a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- LUFA Library
- Copyright (C) Dean Camera, 2017.
-
- dean [at] fourwalledcubicle [dot] com
- www.lufa-lib.org
-*/
-
-/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
-
- Permission to use, copy, modify, distribute, and sell this
- software and its documentation for any purpose is hereby granted
- without fee, provided that the above copyright notice appear in
- all copies and that both that the copyright notice and this
- permission notice and warranty disclaimer appear in supporting
- documentation, and that the name of the author not be used in
- advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
-
- The author disclaims all warranties with regard to this
- software, including all implied warranties of merchantability
- and fitness. In no event shall the author be liable for any
- special, indirect or consequential damages or any damages
- whatsoever resulting from loss of use, data or profits, whether
- in an action of contract, negligence or other tortious action,
- arising out of or in connection with the use or performance of
- this software.
-*/
-
-/** \file
- *
- * USB Device Configuration Descriptor processing routines, to determine the correct pipe configurations
- * needed to communication with an attached USB device. Descriptors are special computer-readable structures
- * which the host requests upon device enumeration, to determine the device's capabilities and functions.
- */
-
-#include "ConfigDescriptor.h"
-
-/** Reads and processes an attached device's descriptors, to determine compatibility and pipe configurations. This
- * routine will read in the entire configuration descriptor, and configure the hosts pipes to correctly communicate
- * with compatible devices.
- *
- * This routine searches for a HID interface descriptor containing at least one Interrupt type IN endpoint and HID descriptor.
- *
- * \return An error code from the \ref KeyboardHostWithParser_GetConfigDescriptorDataCodes_t enum.
- */
-uint8_t ProcessConfigurationDescriptor(void)
-{
- uint8_t ConfigDescriptorData[512];
- void* CurrConfigLocation = ConfigDescriptorData;
- uint16_t CurrConfigBytesRem;
-
- USB_Descriptor_Interface_t* HIDInterface = NULL;
- USB_HID_Descriptor_HID_t* HIDDescriptor = NULL;
- USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
-
- /* Retrieve the entire configuration descriptor into the allocated buffer */
- switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
- {
- case HOST_GETCONFIG_Successful:
- break;
- case HOST_GETCONFIG_InvalidData:
- return InvalidConfigDataReturned;
- case HOST_GETCONFIG_BuffOverflow:
- return DescriptorTooLarge;
- default:
- return ControlError;
- }
-
- while (!(DataINEndpoint))
- {
- /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
- if (!(HIDInterface) ||
- USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
- DComp_NextKeyboardInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
- {
- /* Get the next HID interface from the configuration descriptor */
- if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
- DComp_NextKeyboardInterface) != DESCRIPTOR_SEARCH_COMP_Found)
- {
- /* Descriptor not found, error out */
- return NoCompatibleInterfaceFound;
- }
-
- /* Save the interface in case we need to refer back to it later */
- HIDInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t);
-
- /* Get the HID descriptor from the configuration descriptor */
- if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
- DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found)
- {
- /* Descriptor not found, error out */
- return NoCompatibleInterfaceFound;
- }
-
- /* Save the HID descriptor for later use */
- HIDDescriptor = DESCRIPTOR_PCAST(CurrConfigLocation, USB_HID_Descriptor_HID_t);
-
- /* Skip the remainder of the loop as we have not found an endpoint yet */
- continue;
- }
-
- /* Retrieve the endpoint address from the endpoint descriptor */
- USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t);
-
- /* If the endpoint is a IN type endpoint */
- if ((EndpointData->EndpointAddress & ENDPOINT_DIR_MASK) == ENDPOINT_DIR_IN)
- DataINEndpoint = EndpointData;
- }
-
- /* Configure the HID data IN pipe */
- Pipe_ConfigurePipe(KEYBOARD_DATA_IN_PIPE, EP_TYPE_INTERRUPT, DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, 1);
- Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS);
-
- /* Get the HID report size from the HID report descriptor */
- HIDReportSize = HIDDescriptor->HIDReportLength;
-
- /* Valid data found, return success */
- return SuccessfulConfigRead;
-}
-
-/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
- * configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
- * descriptor processing if an incompatible descriptor configuration is found.
- *
- * This comparator searches for the next Interface descriptor of the correct Keyboard HID Class and Protocol values.
- *
- * \return A value from the DSEARCH_Return_ErrorCodes_t enum
- */
-uint8_t DComp_NextKeyboardInterface(void* CurrentDescriptor)
-{
- USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
-
- if (Header->Type == DTYPE_Interface)
- {
- USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
-
- /* Check the HID descriptor class, break out if correct class interface found */
- if (Interface->Class == HID_CSCP_HIDClass)
- {
- return DESCRIPTOR_SEARCH_Found;
- }
- }
-
- return DESCRIPTOR_SEARCH_NotFound;
-}
-
-/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
- * configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
- * descriptor processing if an incompatible descriptor configuration is found.
- *
- * This comparator searches for the next Endpoint descriptor inside the current interface descriptor, aborting the
- * search if another interface descriptor is found before the required endpoint.
- *
- * \return A value from the DSEARCH_Return_ErrorCodes_t enum
- */
-uint8_t DComp_NextKeyboardInterfaceDataEndpoint(void* CurrentDescriptor)
-{
- USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
-
- if (Header->Type == DTYPE_Endpoint)
- return DESCRIPTOR_SEARCH_Found;
- else if (Header->Type == DTYPE_Interface)
- return DESCRIPTOR_SEARCH_Fail;
- else
- return DESCRIPTOR_SEARCH_NotFound;
-}
-
-/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
- * configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
- * descriptor processing if an incompatible descriptor configuration is found.
- *
- * This comparator searches for the next HID descriptor within the current HID interface descriptor.
- *
- * \return A value from the DSEARCH_Return_ErrorCodes_t enum
- */
-uint8_t DComp_NextHID(void* CurrentDescriptor)
-{
- USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
-
- if (Header->Type == HID_DTYPE_HID)
- return DESCRIPTOR_SEARCH_Found;
- else if (Header->Type == DTYPE_Interface)
- return DESCRIPTOR_SEARCH_Fail;
- else
- return DESCRIPTOR_SEARCH_NotFound;
-}
-
diff --git a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.h b/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.h
deleted file mode 100644
index 4cf111ba57..0000000000
--- a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- LUFA Library
- Copyright (C) Dean Camera, 2017.
-
- dean [at] fourwalledcubicle [dot] com
- www.lufa-lib.org
-*/
-
-/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
-
- Permission to use, copy, modify, distribute, and sell this
- software and its documentation for any purpose is hereby granted
- without fee, provided that the above copyright notice appear in
- all copies and that both that the copyright notice and this
- permission notice and warranty disclaimer appear in supporting
- documentation, and that the name of the author not be used in
- advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
-
- The author disclaims all warranties with regard to this
- software, including all implied warranties of merchantability
- and fitness. In no event shall the author be liable for any
- special, indirect or consequential damages or any damages
- whatsoever resulting from loss of use, data or profits, whether
- in an action of contract, negligence or other tortious action,
- arising out of or in connection with the use or performance of
- this software.
-*/
-
-/** \file
- *
- * Header file for ConfigDescriptor.c.
- */
-
-#ifndef _CONFIGDESCRIPTOR_H_
-#define _CONFIGDESCRIPTOR_H_
-
- /* Includes: */
- #include <LUFA/Drivers/USB/USB.h>
-
- #include "HIDReport.h"
-
- /* Macros: */
- /** Pipe address for the keyboard report data IN pipe. */
- #define KEYBOARD_DATA_IN_PIPE (PIPE_DIR_IN | 1)
-
- /* Enums: */
- /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */
- enum KeyboardHostWithParser_GetConfigDescriptorDataCodes_t
- {
- SuccessfulConfigRead = 0, /**< Configuration Descriptor was processed successfully */
- ControlError = 1, /**< A control request to the device failed to complete successfully */
- DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */
- InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */
- NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */
- };
-
- /* Function Prototypes: */
- uint8_t ProcessConfigurationDescriptor(void);
-
- uint8_t DComp_NextKeyboardInterface(void* CurrentDescriptor);
- uint8_t DComp_NextKeyboardInterfaceDataEndpoint(void* CurrentDescriptor);
- uint8_t DComp_NextHID(void* CurrentDescriptor);
-
-#endif
-
diff --git a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/HIDReport.c b/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/HIDReport.c
deleted file mode 100644
index 95ef8b476d..0000000000
--- a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/HIDReport.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- LUFA Library
- Copyright (C) Dean Camera, 2017.
-
- dean [at] fourwalledcubicle [dot] com
- www.lufa-lib.org
-*/
-
-/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
-
- Permission to use, copy, modify, distribute, and sell this
- software and its documentation for any purpose is hereby granted
- without fee, provided that the above copyright notice appear in
- all copies and that both that the copyright notice and this
- permission notice and warranty disclaimer appear in supporting
- documentation, and that the name of the author not be used in
- advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
-
- The author disclaims all warranties with regard to this
- software, including all implied warranties of merchantability
- and fitness. In no event shall the author be liable for any
- special, indirect or consequential damages or any damages
- whatsoever resulting from loss of use, data or profits, whether
- in an action of contract, negligence or other tortious action,
- arising out of or in connection with the use or performance of
- this software.
-*/
-
-#include "HIDReport.h"
-
-/** Size in bytes of the attached device's HID report descriptor */
-uint16_t HIDReportSize;
-
-/** Processed HID report descriptor items structure, containing information on each HID report element */
-HID_ReportInfo_t HIDReportInfo;
-
-
-/** Function to read in the HID report descriptor from the attached device, and process it into easy-to-read
- * structures via the HID parser routines in the LUFA library.
- *
- * \return A value from the \ref KeyboardHostWithParser_GetHIDReportDataCodes_t enum
- */
-uint8_t GetHIDReportData(void)
-{
- /* Create a buffer big enough to hold the entire returned HID report */
- uint8_t HIDReportData[HIDReportSize];
-
- USB_ControlRequest = (USB_Request_Header_t)
- {
- .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE),
- .bRequest = REQ_GetDescriptor,
- .wValue = (HID_DTYPE_Report << 8),
- .wIndex = 0,
- .wLength = HIDReportSize,
- };
-
- /* Select the control pipe for the request transfer */
- Pipe_SelectPipe(PIPE_CONTROLPIPE);
-
- /* Send control request to retrieve the HID report from the attached device */
- if (USB_Host_SendControlRequest(HIDReportData) != HOST_SENDCONTROL_Successful)
- return ParseControlError;
-
- /* Send the HID report to the parser for processing */
- if (USB_ProcessHIDReport(HIDReportData, HIDReportSize, &HIDReportInfo) != HID_PARSE_Successful)
- return ParseError;
-
- return ParseSuccessful;
-}
-
-/** Callback for the HID Report Parser. This function is called each time the HID report parser is about to store
- * an IN, OUT or FEATURE item into the HIDReportInfo structure. To save on RAM, we are able to filter out items
- * we aren't interested in (preventing us from being able to extract them later on, but saving on the RAM they would
- * have occupied).
- *
- * \param[in] CurrentItem Pointer to the item the HID report parser is currently working with
- *
- * \return Boolean \c true if the item should be stored into the HID report structure, \c false if it should be discarded
- */
-bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* const CurrentItem)
-{
- /* Check the attributes of the current item - see if we are interested in it or not;
- * only store KEYBOARD usage page items into the Processed HID Report structure to
- * save RAM and ignore the rest
- */
- return (CurrentItem->Attributes.Usage.Page == USAGE_PAGE_KEYBOARD);
-}
-
diff --git a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/HIDReport.h b/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/HIDReport.h
deleted file mode 100644
index 3ad3109c25..0000000000
--- a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/HIDReport.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- LUFA Library
- Copyright (C) Dean Camera, 2017.
-
- dean [at] fourwalledcubicle [dot] com
- www.lufa-lib.org
-*/
-
-/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
-
- Permission to use, copy, modify, distribute, and sell this
- software and its documentation for any purpose is hereby granted
- without fee, provided that the above copyright notice appear in
- all copies and that both that the copyright notice and this
- permission notice and warranty disclaimer appear in supporting
- documentation, and that the name of the author not be used in
- advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
-
- The author disclaims all warranties with regard to this
- software, including all implied warranties of merchantability
- and fitness. In no event shall the author be liable for any
- special, indirect or consequential damages or any damages
- whatsoever resulting from loss of use, data or profits, whether
- in an action of contract, negligence or other tortious action,
- arising out of or in connection with the use or performance of
- this software.
-*/
-
-/** \file
- *
- * Header file for HIDReport.c.
- */
-
-#ifndef _HID_REPORT_H_
-#define _HID_REPORT_H_
-
- /* Includes: */
- #include <LUFA/Drivers/USB/USB.h>
-
- #include "KeyboardHostWithParser.h"
-
- /* Macros: */
- /** HID Report Descriptor Usage Page value for a desktop keyboard. */
- #define USAGE_PAGE_KEYBOARD 0x07
-
- /* Enums: */
- /** Enum for the possible return codes of the \ref GetHIDReportData() function. */
- enum KeyboardHostWithParser_GetHIDReportDataCodes_t
- {
- ParseSuccessful = 0, /**< HID report descriptor parsed successfully */
- ParseError = 1, /**< Failed to fully process the HID report descriptor */
- ParseControlError = 2, /**< Control error occurred while trying to read the device HID descriptor */
- };
-
- /* External Variables: */
- extern uint16_t HIDReportSize;
- extern HID_ReportInfo_t HIDReportInfo;
-
- /* Function Prototypes: */
- uint8_t GetHIDReportData(void);
-
- bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* const CurrentItem);
-
-#endif
-
diff --git a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c b/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c
deleted file mode 100644
index e645cee037..0000000000
--- a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- LUFA Library
- Copyright (C) Dean Camera, 2017.
-
- dean [at] fourwalledcubicle [dot] com
- www.lufa-lib.org
-*/
-
-/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
-
- Permission to use, copy, modify, distribute, and sell this
- software and its documentation for any purpose is hereby granted
- without fee, provided that the above copyright notice appear in
- all copies and that both that the copyright notice and this
- permission notice and warranty disclaimer appear in supporting
- documentation, and that the name of the author not be used in
- advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
-
- The author disclaims all warranties with regard to this
- software, including all implied warranties of merchantability
- and fitness. In no event shall the author be liable for any
- special, indirect or consequential damages or any damages
- whatsoever resulting from loss of use, data or profits, whether
- in an action of contract, negligence or other tortious action,
- arising out of or in connection with the use or performance of
- this software.
-*/
-
-/** \file
- *
- * Main source file for the KeyboardHostWithParser demo. This file contains the main tasks of
- * the demo and is responsible for the initial application hardware configuration.
- */
-
-#include "KeyboardHostWithParser.h"
-
-/** Main program entry point. This routine configures the hardware required by the application, then
- * enters a loop to run the application tasks in sequence.
- */
-int main(void)
-{
- SetupHardware();
-
- puts_P(PSTR(ESC_FG_CYAN "Keyboard HID Parser Host Demo running.\r\n" ESC_FG_WHITE));
-
- LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
- GlobalInterruptEnable();
-
- for (;;)
- {
- KeyboardHost_Task();
-
- USB_USBTask();
- }
-}
-
-/** Configures the board hardware and chip peripherals for the demo's functionality. */
-void SetupHardware(void)
-{
-#if (ARCH == ARCH_AVR8)
- /* Disable watchdog if enabled by bootloader/fuses */
- MCUSR &= ~(1 << WDRF);
- wdt_disable();
-
- /* Disable clock division */
- clock_prescale_set(clock_div_1);
-#endif
-
- /* Hardware Initialization */
- Serial_Init(9600, false);
- LEDs_Init();
- USB_Init();
-
- /* Create a stdio stream for the serial port for stdin and stdout */
- Serial_CreateStream(NULL);
-}
-
-/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and
- * starts the library USB task to begin the enumeration and USB management process.
- */
-void EVENT_USB_Host_DeviceAttached(void)
-{
- puts_P(PSTR(ESC_FG_GREEN "Device Attached.\r\n" ESC_FG_WHITE));
- LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
-}
-
-/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and
- * stops the library USB task management process.
- */
-void EVENT_USB_Host_DeviceUnattached(void)
-{
- puts_P(PSTR(ESC_FG_GREEN "\r\nDevice Unattached.\r\n" ESC_FG_WHITE));
- LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
-}
-
-/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully
- * enumerated by the host and is now ready to be used by the application.
- */
-void EVENT_USB_Host_DeviceEnumerationComplete(void)
-{
- puts_P(PSTR("Getting Config Data.\r\n"));
-
- uint8_t ErrorCode;
-
- /* Get and process the configuration descriptor data */
- if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
- {
- if (ErrorCode == ControlError)
- puts_P(PSTR(ESC_FG_RED "Control Error (Get Configuration).\r\n"));
- else
- puts_P(PSTR(ESC_FG_RED "Invalid Device.\r\n"));
-
- printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
-
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
- return;
- }
-
- /* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
- if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
-
- {
- puts_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"));
- printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
-
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
- return;
- }
-
- printf_P(PSTR("Processing HID Report (Size %d Bytes).\r\n"), HIDReportSize);
-
- /* Get and process the device's first HID report descriptor */
- if ((ErrorCode = GetHIDReportData()) != ParseSuccessful)
- {
- puts_P(PSTR(ESC_FG_RED "Report Parse Error.\r\n"));
-
- if (!(HIDReportInfo.TotalReportItems))
- puts_P(PSTR("Not a valid Keyboard." ESC_FG_WHITE));
- else
- printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
-
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
- USB_Host_SetDeviceConfiguration(0);
- return;
- }
-
- puts_P(PSTR("Keyboard Enumerated.\r\n"));
- LEDs_SetAllLEDs(LEDMASK_USB_READY);
-}
-
-/** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */
-void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
-{
- USB_Disable();
-
- printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
- " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
-
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
- for(;;);
-}
-
-/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while
- * enumerating an attached USB device.
- */
-void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
- const uint8_t SubErrorCode)
-{
- printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
- " -- Error Code %d\r\n"
- " -- Sub Error Code %d\r\n"
- " -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
-
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
-}
-
-/** Task to read in and processes the next report from the attached device, displaying the report
- * contents on the board LEDs and via the serial port.
- */
-void KeyboardHost_Task(void)
-{
- if (USB_HostState != HOST_STATE_Configured)
- return;
-
- /* Select and unfreeze keyboard data pipe */
- Pipe_SelectPipe(KEYBOARD_DATA_IN_PIPE);
- Pipe_Unfreeze();
-
- /* Check to see if a packet has been received */
- if (Pipe_IsINReceived())
- {
- /* Check if data has been received from the attached keyboard */
- if (Pipe_IsReadWriteAllowed())
- {
- /* Create buffer big enough for the report */
- uint8_t KeyboardReport[Pipe_BytesInPipe()];
-
- /* Load in the keyboard report */
- Pipe_Read_Stream_LE(KeyboardReport, Pipe_BytesInPipe(), NULL);
-
- /* Process the read in keyboard report from the device */
- ProcessKeyboardReport(KeyboardReport);
- }
-
- /* Clear the IN endpoint, ready for next data packet */
- Pipe_ClearIN();
- }
-
- /* Freeze keyboard data pipe */
- Pipe_Freeze();
-}
-
-/** Processes a read HID report from an attached keyboard, extracting out elements via the HID parser results
- * as required and prints pressed characters to the serial port. Each time a key is typed, a board LED is toggled.
- *
- * \param[in] KeyboardReport Pointer to a HID report from an attached keyboard device
- */
-void ProcessKeyboardReport(uint8_t* KeyboardReport)
-{
- /* Check each HID report item in turn, looking for keyboard scan code reports */
- for (uint8_t ReportNumber = 0; ReportNumber < HIDReportInfo.TotalReportItems; ReportNumber++)
- {
- /* Create a temporary item pointer to the next report item */
- HID_ReportItem_t* ReportItem = &HIDReportInfo.ReportItems[ReportNumber];
-
- /* Check if the current report item is a keyboard scan-code */
- if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_KEYBOARD) &&
- (ReportItem->Attributes.BitSize == 8) &&
- (ReportItem->Attributes.Logical.Maximum > 1) &&
- (ReportItem->ItemType == HID_REPORT_ITEM_In))
- {
- /* Retrieve the keyboard scan-code from the report data retrieved from the device */
- bool FoundData = USB_GetHIDReportItemInfo(KeyboardReport, ReportItem);
-
- /* For multi-report devices - if the requested data was not in the issued report, continue */
- if (!(FoundData))
- continue;
-
- /* Key code is an unsigned char in length, cast to the appropriate type */
- uint8_t KeyCode = (uint8_t)ReportItem->Value;
-
- /* If scan-code is non-zero, a key is being pressed */
- if (KeyCode)
- {
- /* Toggle status LED to indicate keypress */
- LEDs_ToggleLEDs(LEDS_LED2);
-
- char PressedKey = 0;
-
- /* Retrieve pressed key character if alphanumeric */
- if ((KeyCode >= HID_KEYBOARD_SC_A) && (KeyCode <= HID_KEYBOARD_SC_Z))
- {
- PressedKey = (KeyCode - HID_KEYBOARD_SC_A) + 'A';
- }
- else if ((KeyCode >= HID_KEYBOARD_SC_1_AND_EXCLAMATION) &
- (KeyCode < HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS))
- {
- PressedKey = (KeyCode - HID_KEYBOARD_SC_1_AND_EXCLAMATION) + '1';
- }
- else if (KeyCode == HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS)
- {
- PressedKey = '0';
- }
- else if (KeyCode == HID_KEYBOARD_SC_SPACE)
- {
- PressedKey = ' ';
- }
- else if (KeyCode == HID_KEYBOARD_SC_ENTER)
- {
- PressedKey = '\n';
- }
-
- /* Print the pressed key character out through the serial port if valid */
- if (PressedKey)
- putchar(PressedKey);
- }
-
- /* Once a scan-code is found, stop scanning through the report items */
- break;
- }
- }
-}
-
diff --git a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.h b/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.h
deleted file mode 100644
index ce29a84918..0000000000
--- a/lib/lufa/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- LUFA Library
- Copyright (C) Dean Camera, 2017.
-
- dean [at] fourwalledcubicle [dot] com
- www.lufa-lib.org
-*/
-
-/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
-
- Permission to use, copy, modify, distribute, and sell this
- software and its documentation for any purpose is hereby granted
- without fee, provided that the above copyright notice appear in
- all copies and that both that the copyright notice and this
- permission notice and warranty disclaimer appear in supporting
- documentation, and that the name of the author not be used in
- advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
-
- The author disclaims all warranties with regard to this
- software, including all implied warranties of merchantability
- and fitness. In no event shall the author be liable for any
- special, indirect or consequential damages or any damages
- whatsoever resulting from loss of use, data or profits, whether
- in an action of contract, negligence or other tortious action,
- arising out of or in connection with the use or performance of
- this software.
-*/
-
-#ifndef _KEYBOARD_HOST_H_
-#define _KEYBOARD_HOST_H_
-
- /* Includes: */
- #include <avr/io.h>
- #include <avr/wdt.h>
- #include <avr/pgmspace.h>
- #include <avr/power.h>
- #include <avr/interrupt.h>
- #include <stdio.h>
-
- #include <LUFA/Drivers/Misc/TerminalCodes.h>
- #include <LUFA/Drivers/USB/USB.h>
- #include <LUFA/Drivers/Peripheral/Serial.h>
- #include <LUFA/Drivers/Board/LEDs.h>
- #include <LUFA/Platform/Platform.h>
-
- #include "ConfigDescriptor.h"
- #include "HIDReport.h"
-
- /* Macros: */
- /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
- #define LEDMASK_USB_NOTREADY LEDS_LED1
-
- /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
- #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
-
- /** LED mask for the library LED driver, to indicate that the USB interface is ready. */
- #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
-
- /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
- #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
-
- /* Function Prototypes: */
- void SetupHardware(void);
- void KeyboardHost_Task(void);
-
- void EVENT_USB_Host_HostError(const uint8_t ErrorCode);
- void EVENT_USB_Host_DeviceAttached(void);
- void EV