Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com)
Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com)
- Permission to use, copy, modify, distribute, and sell this
+ Permission to use, copy, modify, distribute, and sell 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
+ 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 disclaim all warranties with regard to this
software without specific, written prior permission.
The author disclaim all warranties with regard to this
* Main source file for the Keyboard demo. This file contains the main tasks of the demo and
* is responsible for the initial application hardware configuration.
*/
* Main source file for the Keyboard demo. This file contains the main tasks of the demo and
* is responsible for the initial application hardware configuration.
*/
#include "Keyboard.h"
/** Indicates what report mode the host has requested, true for normal HID reporting mode, false for special boot
#include "Keyboard.h"
/** Indicates what report mode the host has requested, true for normal HID reporting mode, false for special boot
uint16_t IdleCount = 500;
/** Current Idle period remaining. When the IdleCount value is set, this tracks the remaining number of idle
uint16_t IdleCount = 500;
/** Current Idle period remaining. When the IdleCount value is set, this tracks the remaining number of idle
* the current idle period via a Get Idle HID class request, thus its value must be preserved.
*/
uint16_t IdleMSRemaining = 0;
* the current idle period via a Get Idle HID class request, thus its value must be preserved.
*/
uint16_t IdleMSRemaining = 0;
* of the USB device after enumeration, and configures the keyboard device endpoints.
*/
void EVENT_USB_Device_ConfigurationChanged(void)
* of the USB device after enumeration, and configures the keyboard device endpoints.
*/
void EVENT_USB_Device_ConfigurationChanged(void)
/* Write the current protocol flag to the host */
Endpoint_Write_Byte(UsingReportProtocol);
Endpoint_ClearIN();
Endpoint_ClearStatusStage();
}
/* Write the current protocol flag to the host */
Endpoint_Write_Byte(UsingReportProtocol);
Endpoint_ClearIN();
Endpoint_ClearStatusStage();
}
/* Set or clear the flag depending on what the host indicates that the current Protocol should be */
UsingReportProtocol = (USB_ControlRequest.wValue != 0);
}
/* Set or clear the flag depending on what the host indicates that the current Protocol should be */
UsingReportProtocol = (USB_ControlRequest.wValue != 0);
}
Endpoint_ClearStatusStage();
/* Get idle period in MSB, IdleCount must be multiplied by 4 to get number of milliseconds */
IdleCount = ((USB_ControlRequest.wValue & 0xFF00) >> 6);
}
Endpoint_ClearStatusStage();
/* Get idle period in MSB, IdleCount must be multiplied by 4 to get number of milliseconds */
IdleCount = ((USB_ControlRequest.wValue & 0xFF00) >> 6);
}
/* Clear the report contents */
memset(ReportData, 0, sizeof(USB_KeyboardReport_Data_t));
/* Clear the report contents */
memset(ReportData, 0, sizeof(USB_KeyboardReport_Data_t));
/* Make sent key uppercase by indicating that the left shift key is pressed */
ReportData->Modifier = KEYBOARD_MODIFER_LEFTSHIFT;
/* Make sent key uppercase by indicating that the left shift key is pressed */
ReportData->Modifier = KEYBOARD_MODIFER_LEFTSHIFT;
if (JoyStatus_LCL & JOY_UP)
ReportData->KeyCode[UsedKeyCodes++] = 0x04; // A
else if (JoyStatus_LCL & JOY_DOWN)
if (JoyStatus_LCL & JOY_UP)
ReportData->KeyCode[UsedKeyCodes++] = 0x04; // A
else if (JoyStatus_LCL & JOY_DOWN)
static USB_KeyboardReport_Data_t PrevKeyboardReportData;
USB_KeyboardReport_Data_t KeyboardReportData;
bool SendReport = true;
static USB_KeyboardReport_Data_t PrevKeyboardReportData;
USB_KeyboardReport_Data_t KeyboardReportData;
bool SendReport = true;
/* Create the next keyboard report for transmission to the host */
CreateKeyboardReport(&KeyboardReportData);
/* Create the next keyboard report for transmission to the host */
CreateKeyboardReport(&KeyboardReportData);
/* Check to see if the report data has changed - if so a report MUST be sent */
SendReport = (memcmp(&PrevKeyboardReportData, &KeyboardReportData, sizeof(USB_KeyboardReport_Data_t)) != 0);
/* Check to see if the report data has changed - if so a report MUST be sent */
SendReport = (memcmp(&PrevKeyboardReportData, &KeyboardReportData, sizeof(USB_KeyboardReport_Data_t)) != 0);
/* Check if the idle period is set and has elapsed */
if ((IdleCount != HID_IDLE_CHANGESONLY) && (!(IdleMSRemaining)))
{
/* Reset the idle time remaining counter */
IdleMSRemaining = IdleCount;
/* Check if the idle period is set and has elapsed */
if ((IdleCount != HID_IDLE_CHANGESONLY) && (!(IdleMSRemaining)))
{
/* Reset the idle time remaining counter */
IdleMSRemaining = IdleCount;
{
/* Save the current report data for later comparison to check for changes */
PrevKeyboardReportData = KeyboardReportData;
{
/* Save the current report data for later comparison to check for changes */
PrevKeyboardReportData = KeyboardReportData;
/* Write Keyboard Report Data */
Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));
/* Write Keyboard Report Data */
Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));
/* Device must be connected and configured for the task to run */
if (USB_DeviceState != DEVICE_STATE_Configured)
return;
/* Device must be connected and configured for the task to run */
if (USB_DeviceState != DEVICE_STATE_Configured)
return;