summaryrefslogtreecommitdiff
path: root/TERES-HID/KeyboardMouse.c
diff options
context:
space:
mode:
authorDiego Roversi <diegor@tiscali.it>2018-03-11 11:36:20 +0100
committerDiego Roversi <diegor@tiscali.it>2018-03-11 11:36:20 +0100
commitd7b39eed5194f0bfe7f5c8713abb6f99607f5081 (patch)
tree54084741c95217da8e984073eafa24b3d398cf7a /TERES-HID/KeyboardMouse.c
parent91bc0cd5909007bb3608cb37880af8447c7ac877 (diff)
add serial ACM handling
Diffstat (limited to 'TERES-HID/KeyboardMouse.c')
-rw-r--r--TERES-HID/KeyboardMouse.c171
1 files changed, 121 insertions, 50 deletions
diff --git a/TERES-HID/KeyboardMouse.c b/TERES-HID/KeyboardMouse.c
index 19d6aa9..673b194 100644
--- a/TERES-HID/KeyboardMouse.c
+++ b/TERES-HID/KeyboardMouse.c
@@ -49,11 +49,11 @@
uint16_t MagicBootKey ATTR_NO_INIT;
/** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */
-static uint8_t
+static uint8_t
PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];
/** Buffer to hold the previously generated Mouse HID report, for comparison purposes inside the HID class driver. */
-static uint8_t
+static uint8_t
PrevMouseHIDReportBuffer[sizeof(USB_WheelMouseReport_Data_t)];
int
@@ -70,6 +70,36 @@ limited(int value)
return value;
}
+/** LUFA CDC Class driver interface configuration and state information. This structure is
+ * passed to all CDC Class driver functions, so that multiple instances of the same class
+ * within a device can be differentiated from one another.
+ */
+USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = {
+ .Config = {
+ .ControlInterfaceNumber = INTERFACE_ID_CDC_CCI,
+ .DataINEndpoint = {
+ .Address = CDC_TX_EPADDR,
+ .Size = CDC_TXRX_EPSIZE,
+ .Banks = 1,
+ }
+ ,
+ .DataOUTEndpoint = {
+ .Address = CDC_RX_EPADDR,
+ .Size = CDC_TXRX_EPSIZE,
+ .Banks = 1,
+ }
+ ,
+ .NotificationEndpoint = {
+ .Address = CDC_NOTIFICATION_EPADDR,
+ .Size = CDC_NOTIFICATION_EPSIZE,
+ .Banks = 1,
+ }
+ ,
+ }
+ ,
+};
+
+
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another. This is for the keyboard HID
@@ -150,7 +180,16 @@ main(void)
PORTE = 0xff;
PORTB = 0xfd;
DDRB = 0xff;
+
HID_Device_USBTask(&Mouse_HID_Interface);
+
+ /*
+ * Must throw away unused bytes from the host, or it will lock up
+ * while waiting for the device
+ */
+ CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
+ CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
+
USB_USBTask();
if ((PINE & (1 << 2)) == 0) {
@@ -264,6 +303,9 @@ EVENT_USB_Device_ConfigurationChanged(void)
ConfigSuccess &=
HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface);
ConfigSuccess &= HID_Device_ConfigureEndpoints(&Mouse_HID_Interface);
+ ConfigSuccess &=
+ CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface);
+
USB_Device_EnableSOFEvents();
}
@@ -273,6 +315,7 @@ EVENT_USB_Device_ControlRequest(void)
{
HID_Device_ProcessControlRequest(&Keyboard_HID_Interface);
HID_Device_ProcessControlRequest(&Mouse_HID_Interface);
+ HID_Device_ProcessControlRequest(&Mouse_HID_Interface);
}
/** Event handler for the USB device Start Of Frame event. */
@@ -283,8 +326,30 @@ EVENT_USB_Device_StartOfFrame(void)
HID_Device_MillisecondElapsed(&Mouse_HID_Interface);
}
+/** CDC class driver callback function the processing of changes to the virtual
+ * control lines sent from the host..
+ *
+ * \param[in] CDCInterfaceInfo Pointer to the CDC class interface configuration structure being referenced
+ */
+void
+EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t *
+ const CDCInterfaceInfo)
+{
+ /*
+ * You can get changes to the virtual CDC lines in this callback; a
+ * common use-case is to use the Data Terminal Ready (DTR) flag to
+ * enable and disable CDC communications in your application when set
+ * to avoid the application blocking while waiting for a host to
+ * become ready and read in the pending data from the USB endpoints.
+ */
+ bool HostReady =
+ (CDCInterfaceInfo->State.ControlLineStates.
+ HostToDevice & CDC_CONTROL_LINE_OUT_DTR) != 0;
+}
+
+
void
-reset_key(USB_KeyboardReport_Data_t *report)
+reset_key(USB_KeyboardReport_Data_t * report)
{
keyc = 0;
report->Modifier = 0;
@@ -333,7 +398,7 @@ CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t *
uint8_t x = 0;
uint8_t fn = 0;
- reset_key( KeyboardReport );
+ reset_key(KeyboardReport);
if (itsDone) {
itsDone = false;
@@ -350,22 +415,23 @@ CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t *
DDRB = 0xff;
- for (colmn = 0; colmn < 8; colmn++) { // y ?
+ for (colmn = 0; colmn < 8; colmn++) { // y ?
uint8_t keynow = 0;
-
- // that's crazy... here we set d4=1 (x14-15) and then read from port B (y0..y7)
+
+ // that's crazy... here we set d4=1 (x14-15) and then read
+ // from port B (y0..y7)
// even if we are supposed to set Y0 and then read along X
if (colmn == 0) {
cli();
- DDRB = 0x00; // all input
- PORTB = 0x00; // pull up off
- DDRD = (1 << 4); // d4 output
- PORTD = (1 << 4); // d4 = 1 -> x14-15
+ DDRB = 0x00; // all input
+ PORTB = 0x00; // pull up off
+ DDRD = (1 << 4); // d4 output
+ PORTD = (1 << 4); // d4 = 1 -> x14-15
Delay_MS(2);
- if (PINB & 0x40) { //b6(y6) == 1 -> Fn Key
+ if (PINB & 0x40) { // b6(y6) == 1 -> Fn Key
fn = 112;
// tp_guarder();
if (PINB & 0x01) {
@@ -373,60 +439,65 @@ CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t *
}
if (PINB & 0x02) {
KeyboardReport->Modifier |=
- HID_KEYBOARD_MODIFIER_LEFTSHIFT;
- add_key(KeyboardReport,HID_KEYBOARD_SC_LEFT_SHIFT);
+ HID_KEYBOARD_MODIFIER_LEFTSHIFT;
+ add_key(KeyboardReport,
+ HID_KEYBOARD_SC_LEFT_SHIFT);
}
if (PINB & 0x20) {
- add_key(KeyboardReport,HID_KEYBOARD_SC_HOME);
+ add_key(KeyboardReport, HID_KEYBOARD_SC_HOME);
}
if (PINB & 0x80) {
KeyboardReport->Modifier |=
HID_KEYBOARD_MODIFIER_RIGHTSHIFT;
- add_key(KeyboardReport,HID_KEYBOARD_SC_RIGHT_SHIFT);
+ add_key(KeyboardReport,
+ HID_KEYBOARD_SC_RIGHT_SHIFT);
}
} else {
if (PINB & 0x01) {
- add_key(KeyboardReport,HID_KEYBOARD_SC_UP_ARROW);
+ add_key(KeyboardReport, HID_KEYBOARD_SC_UP_ARROW);
}
if (PINB & 0x02) {
KeyboardReport->Modifier |=
HID_KEYBOARD_MODIFIER_LEFTSHIFT;
- add_key(KeyboardReport,HID_KEYBOARD_SC_LEFT_SHIFT);
+ add_key(KeyboardReport,
+ HID_KEYBOARD_SC_LEFT_SHIFT);
}
if (PINB & 0x20) {
- add_key(KeyboardReport,HID_KEYBOARD_SC_LEFT_ARROW);
+ add_key(KeyboardReport,
+ HID_KEYBOARD_SC_LEFT_ARROW);
}
if (PINB & 0x80) {
KeyboardReport->Modifier |=
HID_KEYBOARD_MODIFIER_RIGHTSHIFT;
- add_key(KeyboardReport,HID_KEYBOARD_SC_RIGHT_SHIFT);
+ add_key(KeyboardReport,
+ HID_KEYBOARD_SC_RIGHT_SHIFT);
}
}
#if 0
// x0
- DDRD = (1 << 6); // d6 output (x0)
- PORTD = (1 << 6);// d6 =1
- DDRB = 0x00; // input
- PORTB = 0x00; // no pullup
+ DDRD = (1 << 6); // d6 output (x0)
+ PORTD = (1 << 6); // d6 =1
+ DDRB = 0x00; // input
+ PORTB = 0x00; // no pullup
Delay_MS(2);
if (PINB & 0x10) {
KeyboardReport->Modifier |=
HID_KEYBOARD_MODIFIER_RIGHTCTRL;
- add_key(KeyboardReport,HID_KEYBOARD_SC_RIGHT_CONTROL);
+ add_key(KeyboardReport, HID_KEYBOARD_SC_RIGHT_CONTROL);
}
if (PINB & 0x40) {
KeyboardReport->Modifier |=
HID_KEYBOARD_MODIFIER_LEFTCTRL;
- add_key(KeyboardReport,HID_KEYBOARD_SC_LEFT_CONTROL);
+ add_key(KeyboardReport, HID_KEYBOARD_SC_LEFT_CONTROL);
}
if (PINB & 0x08) {
if (fn == 112)
- add_key(KeyboardReport,HID_KEYBOARD_SC_VOLUME_UP);
+ add_key(KeyboardReport, HID_KEYBOARD_SC_VOLUME_UP);
else
- add_key(KeyboardReport,HID_KEYBOARD_SC_F5);
+ add_key(KeyboardReport, HID_KEYBOARD_SC_F5);
}
#endif
PORTB = rowY[colmn];
@@ -435,7 +506,7 @@ CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t *
PORTD = 0xfc;
Delay_MS(3);
sei();
- } // if colmn==0
+ } // if colmn==0
PORTB = rowY[colmn];
while (PINB != rowY[colmn]);
@@ -445,7 +516,7 @@ CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t *
// tp_guarder();
keynow = keys[colmn * 14 + x + fn];
KeyboardReport->Modifier |= keym[colmn * 14 + x];
- add_key(KeyboardReport,keynow);
+ add_key(KeyboardReport, keynow);
}
x = 1; // 1
@@ -453,14 +524,14 @@ CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t *
// tp_guarder();
keynow = keys[colmn * 14 + x + fn];
KeyboardReport->Modifier |= keym[colmn * 14 + x];
- add_key(KeyboardReport,keynow);
+ add_key(KeyboardReport, keynow);
}
x++; // 2
if ((PINC & (1 << 6)) == 0) {
// tp_guarder();
keynow = keys[colmn * 14 + x + fn];
KeyboardReport->Modifier |= keym[colmn * 14 + x];
- add_key(KeyboardReport,keynow);
+ add_key(KeyboardReport, keynow);
}
x++; // 3
if ((PIND & (1 << 7)) == 0) {
@@ -472,7 +543,7 @@ CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t *
TouchPadLocked = !TouchPadLocked;
while ((PIND & (1 << 7)) == 0);
}
- add_key(KeyboardReport,keynow);
+ add_key(KeyboardReport, keynow);
}
x++; // 4
// Delay_MS(5);
@@ -480,63 +551,63 @@ CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t *
// tp_guarder();
keynow = keys[colmn * 14 + x + fn];
KeyboardReport->Modifier |= keym[colmn * 14 + x];
- add_key(KeyboardReport,keynow);
+ add_key(KeyboardReport, keynow);
}
x++; // 5
if ((PINF & (1 << 1)) == 0) {
// tp_guarder();
keynow = keys[colmn * 14 + x + fn];
KeyboardReport->Modifier |= keym[colmn * 14 + x];
- add_key(KeyboardReport,keynow);
+ add_key(KeyboardReport, keynow);
}
x++; // 6
if ((PINF & (1 << 6)) == 0) {
// tp_guarder();
keynow = keys[colmn * 14 + x + fn];
KeyboardReport->Modifier |= keym[colmn * 14 + x];
- add_key(KeyboardReport,keynow);
+ add_key(KeyboardReport, keynow);
}
x++; // 7
if ((PINE & (1 << 6)) == 0) {
// tp_guarder();
keynow = keys[colmn * 14 + x + fn];
KeyboardReport->Modifier |= keym[colmn * 14 + x];
- add_key(KeyboardReport,keynow);
+ add_key(KeyboardReport, keynow);
}
x++; // 8
if ((PINF & (1 << 4)) == 0) {
// tp_guarder();
keynow = keys[colmn * 14 + x + fn];
KeyboardReport->Modifier |= keym[colmn * 14 + x];
- add_key(KeyboardReport,keynow);
+ add_key(KeyboardReport, keynow);
}
x++; // 9
if ((PIND & (1 << 5)) == 0) {
// tp_guarder();
keynow = keys[colmn * 14 + x + fn];
KeyboardReport->Modifier |= keym[colmn * 14 + x];
- add_key(KeyboardReport,keynow);
+ add_key(KeyboardReport, keynow);
}
x++; // 10
if ((PINF & (1 << 5)) == 0) {
// tp_guarder();
keynow = keys[colmn * 14 + x + fn];
KeyboardReport->Modifier |= keym[colmn * 14 + x];
- add_key(KeyboardReport,keynow);
+ add_key(KeyboardReport, keynow);
}
x++; // 11
if ((PINF & (1 << 7)) == 0) {
// tp_guarder();
keynow = keys[colmn * 14 + x + fn];
KeyboardReport->Modifier |= keym[colmn * 14 + x];
- add_key(KeyboardReport,keynow);
+ add_key(KeyboardReport, keynow);
}
x++; // 12
if ((PINE & (1 << 2)) == 0) {
// tp_guarder();
keynow = keys[colmn * 14 + x + fn];
KeyboardReport->Modifier |= keym[colmn * 14 + x];
- add_key(KeyboardReport,keynow);
+ add_key(KeyboardReport, keynow);
}
DDRD = 0;
PORTD = 0xfc;
@@ -548,7 +619,7 @@ CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t *
*ReportSize = sizeof(USB_KeyboardReport_Data_t);
return true; // return false;
}
-
+
if (HIDInterfaceInfo == &Mouse_HID_Interface) {
USB_WheelMouseReport_Data_t *MouseReport =
(USB_WheelMouseReport_Data_t *) ReportData;
@@ -607,21 +678,21 @@ CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t *
default:
break;
}
-
+
if (lastfingers != 1) {
time_one = 0;
startposX = posx1;
startposY = posy1;
lastfingers = 1;
}
-
+
lastposX = posx1;
lastposY = posy1;
if (speedlimit != 0x80)
speedlimit += 0x04;
break;
-
+
case 2:
if (lastfingers == 0)
touch_to = TOUCH_TO;
@@ -665,7 +736,7 @@ CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t *
*ReportSize = sizeof(USB_WheelMouseReport_Data_t);
return true;
}
-
+
return false;
}
@@ -697,7 +768,7 @@ ISR(ADC_vect)
{
ADCSRA |= (1 << ADIF);
button = ADCH;
-
+
if (button == oldbutton) {
if (button < 0xe8) {
if (button > 0xa0)
@@ -710,8 +781,8 @@ ISR(ADC_vect)
mouse = 0;
} else
oldbutton = button;
-
- mouse=0; // temporary fix: disable button
+
+ mouse = 0; // temporary fix: disable button
}