Corrections to Keyboard and Mouse combined demos so that all modes (normal, interrupt, fully interrupt) work correctly.

pull/1469/head
Dean Camera 16 years ago
parent 3ab07f0d93
commit 7184153e5d

@ -163,7 +163,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
EndpointAddress: (ENDPOINT_DESCRIPTOR_DIR_IN | KEYBOARD_EPNUM),
Attributes: EP_TYPE_INTERRUPT,
EndpointSize: KEYBOARD_EPSIZE,
PollingIntervalMS: 0x02
PollingIntervalMS: 0x04
},
KeyboardLEDsEndpoint:
@ -173,7 +173,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
EndpointAddress: (ENDPOINT_DESCRIPTOR_DIR_OUT | KEYBOARD_LEDS_EPNUM),
Attributes: EP_TYPE_INTERRUPT,
EndpointSize: KEYBOARD_EPSIZE,
PollingIntervalMS: 0x02
PollingIntervalMS: 0x04
}
};

@ -113,6 +113,11 @@ int main(void)
*/
EVENT_HANDLER(USB_Connect)
{
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
#endif
/* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating);
@ -334,14 +339,10 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
/** Fills the given HID report data structure with the next HID report to send to the host.
*
* \param ReportData Pointer to a HID report data structure to be filled
*
* \return Boolean true if the new report differs from the last report, false otherwise
*/
bool CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData)
void CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData)
{
static uint8_t PrevJoyStatus = 0;
uint8_t JoyStatus_LCL = Joystick_GetStatus();
bool InputChanged = false;
uint8_t JoyStatus_LCL = Joystick_GetStatus();
/* Clear the report contents */
memset(ReportData, 0, sizeof(USB_KeyboardReport_Data_t));
@ -358,15 +359,6 @@ bool CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData)
if (JoyStatus_LCL & JOY_PRESS)
ReportData->KeyCode[0] = 0x08; // E
/* Check if the new report is different to the previous report */
InputChanged = (uint8_t)(PrevJoyStatus ^ JoyStatus_LCL);
/* Save the current joystick status for later comparison */
PrevJoyStatus = JoyStatus_LCL;
/* Return whether the new report is different to the previous report or not */
return InputChanged;
}
/** Processes a received LED report, and updates the board LEDs states to match.
@ -394,19 +386,25 @@ void ProcessLEDReport(uint8_t LEDReport)
static inline void SendNextReport(void)
{
USB_KeyboardReport_Data_t KeyboardReportData;
bool SendReport;
bool SendReport = true;
/* Create the next keyboard report for transmission to the host */
SendReport = CreateKeyboardReport(&KeyboardReportData);
CreateKeyboardReport(&KeyboardReportData);
/* Check if the idle period is set and has elapsed */
if (IdleCount && !(IdleMSRemaining))
/* Check if the idle period is set */
if (IdleCount)
{
/* Idle period elapsed, indicate that a report must be sent */
SendReport = true;
/* Reset the idle time remaining counter, must multiply by 4 to get the duration in milliseconds */
IdleMSRemaining = (IdleCount << 2);
/* Check if idle period has elapsed */
if (!(IdleMSRemaining))
{
/* Reset the idle time remaining counter, must multiply by 4 to get the duration in milliseconds */
IdleMSRemaining = (IdleCount << 2);
}
else
{
/* Idle period not elapsed, indicate that a report must not be sent */
SendReport = false;
}
}
/* Select the Keyboard Report Endpoint */

@ -113,7 +113,7 @@
HANDLES_EVENT(USB_UnhandledControlPacket);
/* Function Prototypes: */
bool CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData);
void CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData);
void ProcessLEDReport(uint8_t LEDReport);
static inline void SendNextReport(void);
static inline void ReceiveNextReport(void);

@ -113,9 +113,11 @@ int main(void)
*/
EVENT_HANDLER(USB_Connect)
{
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
#endif
/* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating);
@ -307,15 +309,10 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
/** Fills the given HID report data structure with the next HID report to send to the host.
*
* \param ReportData Pointer to a HID report data structure to be filled
*
* \return Boolean true if the new report differs from the last report, false otherwise
*/
bool CreateMouseReport(USB_MouseReport_Data_t* ReportData)
void CreateMouseReport(USB_MouseReport_Data_t* ReportData)
{
static uint8_t PrevJoyStatus = 0;
static bool PrevHWBStatus = false;
uint8_t JoyStatus_LCL = Joystick_GetStatus();
bool InputChanged = false;
uint8_t JoyStatus_LCL = Joystick_GetStatus();
/* Clear the report contents */
memset(ReportData, 0, sizeof(USB_MouseReport_Data_t));
@ -335,16 +332,6 @@ bool CreateMouseReport(USB_MouseReport_Data_t* ReportData)
if (HWB_GetStatus())
ReportData->Button |= (1 << 1);
/* Check if the new report is different to the previous report */
InputChanged = ((uint8_t)(PrevJoyStatus ^ JoyStatus_LCL) | (uint8_t)(HWB_GetStatus() ^ PrevHWBStatus));
/* Save the current joystick and HWB status for later comparison */
PrevJoyStatus = JoyStatus_LCL;
PrevHWBStatus = HWB_GetStatus();
/* Return whether the new report is different to the previous report or not */
return InputChanged;
}
/** Sends the next HID report to the host, via the keyboard data endpoint. */

@ -113,7 +113,7 @@
HANDLES_EVENT(USB_UnhandledControlPacket);
/* Function Prototypes: */
bool CreateMouseReport(USB_MouseReport_Data_t* ReportData);
void CreateMouseReport(USB_MouseReport_Data_t* ReportData);
void UpdateStatus(uint8_t CurrentStatus);
#endif

Loading…
Cancel
Save