summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Roversi <diegor@tiscali.it>2017-11-17 21:28:06 +0100
committerDiego Roversi <diegor@tiscali.it>2017-11-17 21:28:49 +0100
commit2f9acf73f09e5dc0bbb271f5269a2b58334e0e1e (patch)
tree90a37c251a4e46e1ef4856406dcbc48901204fb8
parent6b7929bf0a3a017e9e4e485a693fc8ec43880457 (diff)
Code indented with 'indent -nut -orig' plus some cosmetic changes
-rw-r--r--TERES-HID/Descriptors.c471
-rw-r--r--TERES-HID/KeyboardMouse.c1569
2 files changed, 976 insertions, 1064 deletions
diff --git a/TERES-HID/Descriptors.c b/TERES-HID/Descriptors.c
index 89266b6..c91e2e0 100644
--- a/TERES-HID/Descriptors.c
+++ b/TERES-HID/Descriptors.c
@@ -1,43 +1,39 @@
/*
- This software is based on the LUFA library. Modifications of the
- software are released under GPL but LUFA library itself is copyrigthed
- by its creator Dean Camera. Refer to the license below on the usage of
- LUFA library.
-
- Chris Boudacoff @ Olimex Ltd
- chris <at> protonic <dot> co <dot> uk
-*/
+ * This software is based on the LUFA library. Modifications of the
+ * software are released under GPL but LUFA library itself is copyrigthed
+ * by its creator Dean Camera. Refer to the license below on the usage of
+ * LUFA library.
+ *
+ * Chris Boudacoff @ Olimex Ltd chris <at> protonic <dot> co <dot> uk
+ */
/*
- LUFA Library
- Copyright (C) Dean Camera, 2015.
-
- dean [at] fourwalledcubicle [dot] com
- www.lufa-lib.org
-*/
+ * LUFA Library Copyright (C) Dean Camera, 2015.
+ *
+ * dean [at] fourwalledcubicle [dot] com www.lufa-lib.org
+ */
/*
- Copyright 2015 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.
-*/
+ * Copyright 2015 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
*
@@ -57,26 +53,24 @@
*
* This descriptor describes the mouse HID interface's report structure.
*/
-const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] =
-{
- /* Use the HID class driver's standard Mouse report.
- * Min X/Y Axis values: -1
- * Max X/Y Axis values: 1
- * Min physical X/Y Axis values (used to determine resolution): -1
- * Max physical X/Y Axis values (used to determine resolution): 1
- * Buttons: 3
- * Absolute screen coordinates: false
- */
- HID_DESCRIPTOR_WHEEL_MOUSE(-100, 100, -100,100, 3, false)
+const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = {
+ /*
+ * Use the HID class driver's standard Mouse report. Min X/Y Axis
+ * values: -1 Max X/Y Axis values: 1 Min physical X/Y Axis values
+ * (used to determine resolution): -1 Max physical X/Y Axis values
+ * (used to determine resolution): 1 Buttons: 3 Absolute screen
+ * coordinates: false
+ */
+ HID_DESCRIPTOR_WHEEL_MOUSE(-100, 100, -100, 100, 3, false)
};
/** Same as the MouseReport structure, but defines the keyboard HID interface's report structure. */
-const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] =
-{
- /* Use the HID class driver's standard Keyboard report.
- * Max simultaneous keys: 6
- */
- HID_DESCRIPTOR_KEYBOARD(6)
+const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = {
+ /*
+ * Use the HID class driver's standard Keyboard report. Max
+ * simultaneous keys: 6
+ */
+ HID_DESCRIPTOR_KEYBOARD(6)
};
/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
@@ -84,26 +78,26 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] =
* number of device configurations. The descriptor is read out by the USB host when the enumeration
* process begins.
*/
-const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
-{
- .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
+const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {
+ .Header = {.Size = sizeof(USB_Descriptor_Device_t),.Type = DTYPE_Device}
+ ,
- .USBSpecification = VERSION_BCD(1,1,0),
- .Class = USB_CSCP_NoDeviceClass,
- .SubClass = USB_CSCP_NoDeviceSubclass,
- .Protocol = USB_CSCP_NoDeviceProtocol,
+ .USBSpecification = VERSION_BCD(1, 1, 0),
+ .Class = USB_CSCP_NoDeviceClass,
+ .SubClass = USB_CSCP_NoDeviceSubclass,
+ .Protocol = USB_CSCP_NoDeviceProtocol,
- .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
+ .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
- .VendorID = 0x15ba, //Vendor: Olimex Ltd.
- .ProductID = 0x003c,
- .ReleaseNumber = VERSION_BCD(0, 0, 1),
+ .VendorID = 0x15ba, // Vendor: Olimex Ltd.
+ .ProductID = 0x003c,
+ .ReleaseNumber = VERSION_BCD(0, 0, 1),
- .ManufacturerStrIndex = STRING_ID_Manufacturer,
- .ProductStrIndex = STRING_ID_Product,
- .SerialNumStrIndex = USE_INTERNAL_SERIAL,
+ .ManufacturerStrIndex = STRING_ID_Manufacturer,
+ .ProductStrIndex = STRING_ID_Product,
+ .SerialNumStrIndex = USE_INTERNAL_SERIAL,
- .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
+ .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
};
/** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
@@ -111,115 +105,140 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
* and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
* a configuration so that the host may correctly communicate with the USB device.
*/
-const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
-{
- .Config =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
-
- .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
- .TotalInterfaces = 2,
- .ConfigurationNumber = 1,
- .ConfigurationStrIndex = NO_DESCRIPTOR,
-
- .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED),
-
- .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
- },
- .HID1_KeyboardInterface =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
-
- .InterfaceNumber = INTERFACE_ID_Keyboard,
- .AlternateSetting = 0x00,
-
- .TotalEndpoints = 1,
-
- .Class = HID_CSCP_HIDClass,
- .SubClass = HID_CSCP_BootSubclass,
- .Protocol = HID_CSCP_KeyboardBootProtocol,
-
- .InterfaceStrIndex = NO_DESCRIPTOR
- },
-
- .HID1_KeyboardHID =
- {
- .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
-
- .HIDSpec = VERSION_BCD(1,1,1),
- .CountryCode = 0x00,
- .TotalReportDescriptors = 1,
- .HIDReportType = HID_DTYPE_Report,
- .HIDReportLength = sizeof(KeyboardReport)
- },
-
- .HID1_ReportINEndpoint =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
-
- .EndpointAddress = KEYBOARD_IN_EPADDR,
- .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
- .EndpointSize = HID_EPSIZE,
- .PollingIntervalMS = 0x05
- },
-
- .HID2_MouseInterface =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
-
- .InterfaceNumber = INTERFACE_ID_Mouse,
- .AlternateSetting = 0x00,
-
- .TotalEndpoints = 1,
-
- .Class = HID_CSCP_HIDClass,
- .SubClass = HID_CSCP_BootSubclass,
- .Protocol = HID_CSCP_MouseBootProtocol,
-
- .InterfaceStrIndex = NO_DESCRIPTOR
- },
-
- .HID2_MouseHID =
- {
- .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
-
- .HIDSpec = VERSION_BCD(1,1,1),
- .CountryCode = 0x00,
- .TotalReportDescriptors = 1,
- .HIDReportType = HID_DTYPE_Report,
- .HIDReportLength = sizeof(MouseReport)
- },
-
- .HID2_ReportINEndpoint =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
-
- .EndpointAddress = MOUSE_IN_EPADDR,
- .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
- .EndpointSize = HID_EPSIZE,
- .PollingIntervalMS = 0x05
- }
+const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
+ .Config = {
+ .Header = {.Size =
+ sizeof(USB_Descriptor_Configuration_Header_t),.
+ Type = DTYPE_Configuration}
+ ,
+
+ .TotalConfigurationSize =
+ sizeof(USB_Descriptor_Configuration_t),
+ .TotalInterfaces = 2,
+ .ConfigurationNumber = 1,
+ .ConfigurationStrIndex = NO_DESCRIPTOR,
+
+ .ConfigAttributes =
+ (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED),
+
+ .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
+ }
+ ,
+ .HID1_KeyboardInterface = {
+ .Header = {.Size =
+ sizeof
+ (USB_Descriptor_Interface_t),.
+ Type = DTYPE_Interface}
+ ,
+
+ .InterfaceNumber = INTERFACE_ID_Keyboard,
+ .AlternateSetting = 0x00,
+
+ .TotalEndpoints = 1,
+
+ .Class = HID_CSCP_HIDClass,
+ .SubClass = HID_CSCP_BootSubclass,
+ .Protocol = HID_CSCP_KeyboardBootProtocol,
+
+ .InterfaceStrIndex = NO_DESCRIPTOR}
+ ,
+
+ .HID1_KeyboardHID = {
+ .Header = {.Size =
+ sizeof(USB_HID_Descriptor_HID_t),.
+ Type = HID_DTYPE_HID}
+ ,
+
+ .HIDSpec = VERSION_BCD(1, 1, 1),
+ .CountryCode = 0x00,
+ .TotalReportDescriptors = 1,
+ .HIDReportType = HID_DTYPE_Report,
+ .HIDReportLength = sizeof(KeyboardReport)
+ }
+ ,
+
+ .HID1_ReportINEndpoint = {
+ .Header = {.Size =
+ sizeof
+ (USB_Descriptor_Endpoint_t),.
+ Type = DTYPE_Endpoint}
+ ,
+
+ .EndpointAddress = KEYBOARD_IN_EPADDR,
+ .Attributes =
+ (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC |
+ ENDPOINT_USAGE_DATA),
+ .EndpointSize = HID_EPSIZE,
+ .PollingIntervalMS = 0x05}
+ ,
+
+ .HID2_MouseInterface = {
+ .Header = {.Size =
+ sizeof(USB_Descriptor_Interface_t),.
+ Type = DTYPE_Interface}
+ ,
+
+ .InterfaceNumber = INTERFACE_ID_Mouse,
+ .AlternateSetting = 0x00,
+
+ .TotalEndpoints = 1,
+
+ .Class = HID_CSCP_HIDClass,
+ .SubClass = HID_CSCP_BootSubclass,
+ .Protocol = HID_CSCP_MouseBootProtocol,
+
+ .InterfaceStrIndex = NO_DESCRIPTOR}
+ ,
+
+ .HID2_MouseHID = {
+ .Header = {.Size =
+ sizeof(USB_HID_Descriptor_HID_t),.Type =
+ HID_DTYPE_HID}
+ ,
+
+ .HIDSpec = VERSION_BCD(1, 1, 1),
+ .CountryCode = 0x00,
+ .TotalReportDescriptors = 1,
+ .HIDReportType = HID_DTYPE_Report,
+ .HIDReportLength = sizeof(MouseReport)
+ }
+ ,
+
+ .HID2_ReportINEndpoint = {
+ .Header = {.Size =
+ sizeof
+ (USB_Descriptor_Endpoint_t),.
+ Type = DTYPE_Endpoint}
+ ,
+
+ .EndpointAddress = MOUSE_IN_EPADDR,
+ .Attributes =
+ (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC |
+ ENDPOINT_USAGE_DATA),
+ .EndpointSize = HID_EPSIZE,
+ .PollingIntervalMS = 0x05}
};
/** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
* the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
* via the language ID table available at USB.org what languages the device supports for its string descriptors.
*/
-const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG);
+const USB_Descriptor_String_t PROGMEM LanguageString =
+USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG);
/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
* form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
* Descriptor.
*/
const USB_Descriptor_String_t PROGMEM ManufacturerString =
- USB_STRING_DESCRIPTOR(L"Olimex Ltd.");
+USB_STRING_DESCRIPTOR(L"Olimex Ltd.");
/** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
* and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
* Descriptor.
*/
-const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(
- L"TERES Keyboard+Touchpad");
+const USB_Descriptor_String_t PROGMEM ProductString =
+USB_STRING_DESCRIPTOR(L"TERES Keyboard+Touchpad");
/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
* documentation) by the application code so that the address and size of a requested descriptor can be given
@@ -227,75 +246,71 @@ const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(
* is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
* USB host.
*/
-uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
- const uint16_t wIndex,
- const void** const DescriptorAddress)
+uint16_t
+CALLBACK_USB_GetDescriptor(const uint16_t wValue,
+ const uint16_t wIndex,
+ const void **const DescriptorAddress)
{
- const uint8_t DescriptorType = (wValue >> 8);
- const uint8_t DescriptorNumber = (wValue & 0xFF);
-
- const void* Address = NULL;
- uint16_t Size = NO_DESCRIPTOR;
-
- switch (DescriptorType)
- {
- case DTYPE_Device:
- Address = &DeviceDescriptor;
- Size = sizeof(USB_Descriptor_Device_t);
- break;
- case DTYPE_Configuration:
- Address = &ConfigurationDescriptor;
- Size = sizeof(USB_Descriptor_Configuration_t);
- break;
- case DTYPE_String:
- switch (DescriptorNumber)
- {
- case STRING_ID_Language:
- Address = &LanguageString;
- Size = pgm_read_byte(&LanguageString.Header.Size);
- break;
- case STRING_ID_Manufacturer:
- Address = &ManufacturerString;
- Size = pgm_read_byte(&ManufacturerString.Header.Size);
- break;
- case STRING_ID_Product:
- Address = &ProductString;
- Size = pgm_read_byte(&ProductString.Header.Size);
- break;
- }
-
- break;
- case HID_DTYPE_HID:
- switch (wIndex)
- {
- case INTERFACE_ID_Keyboard:
- Address = &ConfigurationDescriptor.HID1_KeyboardHID;
- Size = sizeof(USB_HID_Descriptor_HID_t);
- break;
- case INTERFACE_ID_Mouse:
- Address = &ConfigurationDescriptor.HID2_MouseHID;
- Size = sizeof(USB_HID_Descriptor_HID_t);
- break;
- }
-
- break;
- case HID_DTYPE_Report:
- switch (wIndex)
- {
- case INTERFACE_ID_Keyboard:
- Address = &KeyboardReport;
- Size = sizeof(KeyboardReport);
- break;
- case INTERFACE_ID_Mouse:
- Address = &MouseReport;
- Size = sizeof(MouseReport);
- break;
- }
-
- break;
- }
-
- *DescriptorAddress = Address;
- return Size;
+ const uint8_t DescriptorType = (wValue >> 8);
+ const uint8_t DescriptorNumber = (wValue & 0xFF);
+
+ const void *Address = NULL;
+ uint16_t Size = NO_DESCRIPTOR;
+
+ switch (DescriptorType) {
+ case DTYPE_Device:
+ Address = &DeviceDescriptor;
+ Size = sizeof(USB_Descriptor_Device_t);
+ break;
+ case DTYPE_Configuration:
+ Address = &ConfigurationDescriptor;
+ Size = sizeof(USB_Descriptor_Configuration_t);
+ break;
+ case DTYPE_String:
+ switch (DescriptorNumber) {
+ case STRING_ID_Language:
+ Address = &LanguageString;
+ Size = pgm_read_byte(&LanguageString.Header.Size);
+ break;
+ case STRING_ID_Manufacturer:
+ Address = &ManufacturerString;
+ Size = pgm_read_byte(&ManufacturerString.Header.Size);
+ break;
+ case STRING_ID_Product:
+ Address = &ProductString;
+ Size = pgm_read_byte(&ProductString.Header.Size);
+ break;
+ }
+
+ break;
+ case HID_DTYPE_HID:
+ switch (wIndex) {
+ case INTERFACE_ID_Keyboard:
+ Address = &ConfigurationDescriptor.HID1_KeyboardHID;
+ Size = sizeof(USB_HID_Descriptor_HID_t);
+ break;
+ case INTERFACE_ID_Mouse:
+ Address = &ConfigurationDescriptor.HID2_MouseHID;
+ Size = sizeof(USB_HID_Descriptor_HID_t);
+ break;
+ }
+
+ break;
+ case HID_DTYPE_Report:
+ switch (wIndex) {
+ case INTERFACE_ID_Keyboard:
+ Address = &KeyboardReport;
+ Size = sizeof(KeyboardReport);
+ break;
+ case INTERFACE_ID_Mouse:
+ Address = &MouseReport;
+ Size = sizeof(MouseReport);
+ break;
+ }
+
+ break;
+ }
+
+ *DescriptorAddress = Address;
+ return Size;
}
-
diff --git a/TERES-HID/KeyboardMouse.c b/TERES-HID/KeyboardMouse.c
index d089fa9..f0ed997 100644
--- a/TERES-HID/KeyboardMouse.c
+++ b/TERES-HID/KeyboardMouse.c
@@ -1,42 +1,38 @@
/*
- This software is based on the LUFA library. Modifications of the
- software are released under GPL but LUFA library itself is copyrigthed
- by its creator Dean Camera. Refer to the license below on the usage of
- LUFA library.
-
- Chris Boudacoff @ Olimex Ltd
- chris <at> protonic <dot> co <dot> uk
-*/
+ * This software is based on the LUFA library. Modifications of the
+ * software are released under GPL but LUFA library itself is copyrigthed
+ * by its creator Dean Camera. Refer to the license below on the usage of
+ * LUFA library.
+ *
+ * Chris Boudacoff @ Olimex Ltd chris <at> protonic <dot> co <dot> uk
+ */
/*
- LUFA Library
- Copyright (C) Dean Camera, 2015.
-
- dean [at] fourwalledcubicle [dot] com
- www.lufa-lib.org
-*/
+ * LUFA Library Copyright (C) Dean Camera, 2015.
+ *
+ * dean [at] fourwalledcubicle [dot] com www.lufa-lib.org
+ */
/*
- Copyright 2015 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.
-*/
+ * Copyright 2015 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
*
@@ -53,236 +49,238 @@
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 PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_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 PrevMouseHIDReportBuffer[sizeof(USB_WheelMouseReport_Data_t)];
-
+static uint8_t
+ PrevMouseHIDReportBuffer[sizeof(USB_WheelMouseReport_Data_t)];
-
-int limited(int value)
-{
-if (value < 0)
+int
+limited(int value)
{
- if (abs(value) > speedlimit)
- return -speedlimit;
+ if (value < 0) {
+ if (abs(value) > speedlimit)
+ return -speedlimit;
+ } else {
+ if (value > speedlimit)
+ return speedlimit;
+ }
+ return value;
}
-else
-{
- if (value > speedlimit)
- return speedlimit;
-
-
-}
-
-return value;
-
-
-}
/** 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
* interface within the device.
*/
-USB_ClassInfo_HID_Device_t Keyboard_HID_Interface =
- {
- .Config =
- {
- .InterfaceNumber = INTERFACE_ID_Keyboard,
- .ReportINEndpoint =
- {
- .Address = KEYBOARD_IN_EPADDR,
- .Size = HID_EPSIZE,
- .Banks = 1,
- },
- .PrevReportINBuffer = PrevKeyboardHIDReportBuffer,
- .PrevReportINBufferSize = sizeof(PrevKeyboardHIDReportBuffer),
- },
- };
+USB_ClassInfo_HID_Device_t Keyboard_HID_Interface = {
+ .Config = {
+ .InterfaceNumber = INTERFACE_ID_Keyboard,
+ .ReportINEndpoint = {
+ .Address = KEYBOARD_IN_EPADDR,
+ .Size = HID_EPSIZE,
+ .Banks = 1,
+ }
+ ,
+ .PrevReportINBuffer = PrevKeyboardHIDReportBuffer,
+ .PrevReportINBufferSize =
+ sizeof(PrevKeyboardHIDReportBuffer),
+ }
+ ,
+};
/** 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 mouse HID
* interface within the device.
*/
-USB_ClassInfo_HID_Device_t Mouse_HID_Interface =
- {
- .Config =
- {
- .InterfaceNumber = INTERFACE_ID_Mouse,
- .ReportINEndpoint =
- {
- .Address = MOUSE_IN_EPADDR,
- .Size = HID_EPSIZE,
- .Banks = 1,
- },
- .PrevReportINBuffer = PrevMouseHIDReportBuffer,
- .PrevReportINBufferSize = sizeof(PrevMouseHIDReportBuffer),
- },
- };
-
-
- void Jump_To_Bootloader(void)
- {
- // If USB is used, detach from the bus and reset it
- USB_Disable();
-
- // Disable all interrupts
- cli();
-
- // Wait one seconds for the USB detachment to register on the host
- Delay_MS(1000);
-
- // Set the bootloader key to the magic value and force a reset
- wdt_enable(WDTO_250MS);
- for (;;);
- }
-
-void tp_guarder(void)
+USB_ClassInfo_HID_Device_t Mouse_HID_Interface = {
+ .Config = {
+ .InterfaceNumber = INTERFACE_ID_Mouse,
+ .ReportINEndpoint = {
+ .Address = MOUSE_IN_EPADDR,
+ .Size = HID_EPSIZE,
+ .Banks = 1,
+ }
+ ,
+ .PrevReportINBuffer = PrevMouseHIDReportBuffer,
+ .PrevReportINBufferSize = sizeof(PrevMouseHIDReportBuffer),
+ }
+ ,
+};
+
+
+void
+Jump_To_Bootloader(void)
+{
+ // If USB is used, detach from the bus and reset it
+ USB_Disable();
+
+ // Disable all interrupts
+ cli();
+
+ // Wait one seconds for the USB detachment to register on the host
+ Delay_MS(1000);
+
+ // Set the bootloader key to the magic value and force a reset
+ wdt_enable(WDTO_250MS);
+ for (;;);
+}
+
+void
+tp_guarder(void)
{
- tp_guard=true;
- tpguard=TP_LOCK;
+ tp_guard = true;
+ tpguard = TP_LOCK;
}
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
-int main(void)
-{
-
-
- SetupHardware();
- GlobalInterruptEnable();
-
- for (;;)
- {
-
-
- HID_Device_USBTask(&Keyboard_HID_Interface);
- DDRE=0x00;
- PORTE=0xff;
- PORTB=0xfd;
- DDRB=0xff;
- HID_Device_USBTask(&Mouse_HID_Interface);
- USB_USBTask();
-
- if ((PINE & (1<<2)) == 0)
- {
- DDRB=0xff;
- PORTB=0xfe;
- Delay_MS(10);
- if ((PINC & (1<<7)) == 0)
- {
-
-
- PORTB=0xbf;
- Delay_MS(10);
- if ((PIND & (1<<4)) == 0)
- Jump_To_Bootloader();
- }
- }
- }
+int
+main(void)
+{
+ SetupHardware();
+ GlobalInterruptEnable();
+
+ for (;;) {
+ HID_Device_USBTask(&Keyboard_HID_Interface);
+ DDRE = 0x00;
+ PORTE = 0xff;
+ PORTB = 0xfd;
+ DDRB = 0xff;
+ HID_Device_USBTask(&Mouse_HID_Interface);
+ USB_USBTask();
+
+ if ((PINE & (1 << 2)) == 0) {
+ DDRB = 0xff;
+ PORTB = 0xfe;
+ Delay_MS(10);
+ if ((PINC & (1 << 7)) == 0) {
+ PORTB = 0xbf;
+ Delay_MS(10);
+ if ((PIND & (1 << 4)) == 0)
+ Jump_To_Bootloader();
+ }
+ }
+ }
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
-void SetupHardware()
+void
+SetupHardware()
{
#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);
+ /*
+ * Disable watchdog if enabled by bootloader/fuses
+ */
+ MCUSR &= ~(1 << WDRF);
+ wdt_disable();
+
+ /*
+ * Disable clock division
+ */
+ clock_prescale_set(clock_div_1);
#elif (ARCH == ARCH_XMEGA)
- /* Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it */
- XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU);
- XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL);
-
- /* Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference */
- XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ);
- XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB);
-
- PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
+ /*
+ * Start the PLL to multiply the 2MHz RC oscillator to 32MHz and
+ * switch the CPU core to run from it
+ */
+ XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU);
+ XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL);
+
+ /*
+ * Start the 32MHz internal RC oscillator and start the DFLL to
+ * increase it to 48MHz using the USB SOF as a reference
+ */
+ XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ);
+ XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB);
+
+ PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
#endif
- /* Hardware Initialization */
+ /*
+ * Hardware Initialization
+ */
- //Keyboard init
- DDRB = 0xff;
- PORTB = 0xff;
+ // Keyboard init
+ DDRB = 0xff;
+ PORTB = 0xff;
- DDRD = 0;
- PORTD = 0xfc;
+ DDRD = 0;
+ PORTD = 0xfc;
- DDRC = 0;
- PORTC = 0xc0;
+ DDRC = 0;
+ PORTC = 0xc0;
- DDRE = 0;
+ DDRE = 0;
PORTE = 0x44;
DDRF = 0;
PORTF = 0xf2;
+ TWI_Init(TWI_BIT_PRESCALE_4,
+ TWI_BITLENGTH_FROM_FREQ(TWI_BIT_PRESCALE_4, 100000));
+ ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128);
+ ADCSRA |= 1 << ADIE;
+ MCUCR = 0;
+ EIMSK |= 1 << INT2;
+ ADC_SetupChannel(0);
+ ADC_StartReading(ADC_REFERENCE_AVCC | ADC_LEFT_ADJUSTED |
+ ADC_CHANNEL0);
- TWI_Init(TWI_BIT_PRESCALE_4 , TWI_BITLENGTH_FROM_FREQ(TWI_BIT_PRESCALE_4 , 100000));
- ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128);
- ADCSRA |= 1 << ADIE;
- MCUCR = 0;
- EIMSK |= 1 << INT2;
+ // set timer0 counter initial value to 0
+ TCNT0 = 0x00;
+ // start timer0 with /1024 prescaler
+ TCCR0B = (1 << CS02) | (1 << CS00);
+ TIMSK0 = 1 << TOIE0;
- ADC_SetupChannel(0);
- ADC_StartReading(ADC_REFERENCE_AVCC | ADC_LEFT_ADJUSTED | ADC_CHANNEL0);
-
- // set timer0 counter initial value to 0
- TCNT0=0x00;
- // start timer0 with /1024 prescaler
- TCCR0B = (1<<CS02) | (1<<CS00);
- TIMSK0=1<<TOIE0;
-
- USB_Init();
- button = 0xff;
+ USB_Init();
+ button = 0xff;
}
/** Event handler for the library USB Connection event. */
-void EVENT_USB_Device_Connect(void)
+void
+EVENT_USB_Device_Connect(void)
{
}
/** Event handler for the library USB Disconnection event. */
-void EVENT_USB_Device_Disconnect(void)
+void
+EVENT_USB_Device_Disconnect(void)
{
}
/** Event handler for the library USB Configuration Changed event. */
-void EVENT_USB_Device_ConfigurationChanged(void)
+void
+EVENT_USB_Device_ConfigurationChanged(void)
{
- bool ConfigSuccess = true;
-
- ConfigSuccess &= HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface);
- ConfigSuccess &= HID_Device_ConfigureEndpoints(&Mouse_HID_Interface);
- USB_Device_EnableSOFEvents();
+ bool ConfigSuccess = true;
+ ConfigSuccess &=
+ HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface);
+ ConfigSuccess &= HID_Device_ConfigureEndpoints(&Mouse_HID_Interface);
+ USB_Device_EnableSOFEvents();
}
/** Event handler for the library USB Control Request reception event. */
-void EVENT_USB_Device_ControlRequest(void)
+void
+EVENT_USB_Device_ControlRequest(void)
{
- HID_Device_ProcessControlRequest(&Keyboard_HID_Interface);
- HID_Device_ProcessControlRequest(&Mouse_HID_Interface);
-
-
+ HID_Device_ProcessControlRequest(&Keyboard_HID_Interface);
+ HID_Device_ProcessControlRequest(&Mouse_HID_Interface);
}
/** Event handler for the USB device Start Of Frame event. */
-void EVENT_USB_Device_StartOfFrame(void)
+void
+EVENT_USB_Device_StartOfFrame(void)
{
- HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);
- HID_Device_MillisecondElapsed(&Mouse_HID_Interface);
+ HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);
+ HID_Device_MillisecondElapsed(&Mouse_HID_Interface);
}
/** HID class driver callback function for the creation of HID reports to the host.
@@ -295,516 +293,436 @@ void EVENT_USB_Device_StartOfFrame(void)
*
* \return Boolean \c true to force the sending of the report, \c false to let the library determine if it needs to be sent
*/
-bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
- uint8_t* const ReportID,
- const uint8_t ReportType,
- void* ReportData,
- uint16_t* const ReportSize)
-{
-
-
- /* Determine which interface must have its report generated */
- if (HIDInterfaceInfo == &Keyboard_HID_Interface)
- {
- USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData;
-
-uint8_t x=0;
-uint8_t fn = 0;
-
-keyc = 0; //reset keys
-KeyboardReport->Modifier = 0;
-
-for (x=0;x<6;x++)
-KeyboardReport->KeyCode[x]=0;
-
-
-if (itsDone)
-{
-//
-
-itsDone = false;
-#if 0
-
-switch (tpdata[2])
-{
-case 0:
-KeyboardReport->KeyCode[0]=HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS;
-break;
-case 1:
-KeyboardReport->KeyCode[0]=HID_KEYBOARD_SC_1_AND_EXCLAMATION;
-break;
-case 2:
-KeyboardReport->KeyCode[0]=HID_KEYBOARD_SC_2_AND_AT;
-break;
-default:
-KeyboardReport->KeyCode[0]=HID_KEYBOARD_SC_DOT_AND_GREATER_THAN_SIGN;
-break;
-}
-
-keyc = 1;
-
-#endif
-}
-DDRE=0;
-DDRF=0;
-DDRC=0;
- DDRD = 0;
- PORTD = 0xfc;
-PORTE=0xFF;
-PORTF=0xFF;
-PORTC=0xFF;
-
-
-DDRB = 0xff;
-
-for (colmn = 0; colmn<8; colmn++)
-{
-
-uint8_t keynow=0;
-
-if (colmn == 0)
-{
-cli();
-DDRB=0x00;
-PORTB=0x00;
-DDRD = (1<<4);
-PORTD = (1<<4);
-
-Delay_MS(2);
-
-if (PINB & 0x40)
-{
- fn = 112;
- //tp_guarder();
- if (PINB & 0x01)
- {
- KeyboardReport->KeyCode[keyc]=HID_KEYBOARD_SC_PAGE_UP;
- if (keyc<5) keyc++;
- }
- if (PINB & 0x02)
- {
- KeyboardReport->Modifier |= HID_KEYBOARD_MODIFIER_LEFTSHIFT;
- KeyboardReport->KeyCode[keyc]=HID_KEYBOARD_SC_LEFT_SHIFT;
- if (keyc<5) keyc++;
-
- }
- if (PINB & 0x20)
- {
- KeyboardReport->KeyCode[keyc]=HID_KEYBOARD_SC_HOME;
- if (keyc<5) keyc++;
- }
-
- if (PINB & 0x80)
- {
- KeyboardReport->Modifier |= HID_KEYBOARD_MODIFIER_RIGHTSHIFT;
- KeyboardReport->KeyCode[keyc]=HID_KEYBOARD_SC_RIGHT_SHIFT;
- if (keyc<5) keyc++;
- }
-
-
-
-}
-else
-{
-
- if (PINB & 0x01)
- {
- KeyboardReport->KeyCode[keyc]=HID_KEYBOARD_SC_UP_ARROW;
- if (keyc<5) keyc++;
- //tp_guarder();
- }
- if (PINB & 0x02)
- {
- KeyboardReport->Modifier |= HID_KEYBOARD_MODIFIER_LEFTSHIFT;
- KeyboardReport->KeyCode[keyc]=HID_KEYBOARD_SC_LEFT_SHIFT;
- if (keyc<5) keyc++;
- }
- if (PINB & 0x20)
- {
- KeyboardReport->KeyCode[keyc]=HID_KEYBOARD_SC_LEFT_ARROW;
- if (keyc<5) keyc++;
- //tp_guarder();
- }
-
- if (PINB & 0x80)
- {
- KeyboardReport->Modifier |= HID_KEYBOARD_MODIFIER_RIGHTSHIFT;
- KeyboardReport->KeyCode[keyc]=HID_KEYBOARD_SC_RIGHT_SHIFT;
- if (keyc<5) keyc++;
- }
-
-
-
-}
-
-//////x0
-DDRD = (1<<6);
-PORTD = (1<<6);
-DDRB=0x00;
-PORTB=0x00;
-Delay_MS(2);
-
-if (PINB & 0x10)
-{
- KeyboardReport->Modifier |= HID_KEYBOARD_MODIFIER_RIGHTCTRL;
- KeyboardReport->KeyCode[keyc]=HID_KEYBOARD_SC_RIGHT_CONTROL;
- if (keyc<5) keyc++;
-
-}
-if (PINB & 0x40)
-{
- KeyboardReport->Modifier |= HID_KEYBOARD_MODIFIER_LEFTCTRL;
- KeyboardReport->KeyCode[keyc]=HID_KEYBOARD_SC_LEFT_CONTROL;
- if (keyc<5) keyc++;
-
-}
-if (PINB & 0x08)
-{
- if (fn==112)
- KeyboardReport->KeyCode[keyc]=HID_KEYBOARD_SC_VOLUME_UP;
- else
- KeyboardReport->KeyCode[keyc]=HID_KEYBOARD_SC_F5;
- if (keyc<5) keyc++;
-
-}
-
-
-PORTB = rowY[colmn];
-DDRB = 0xff;
- DDRD = 0;
- PORTD = 0xfc;
-Delay_MS(3);
-sei();
-}
-
-PORTB = rowY[colmn];
-while (PINB != rowY[colmn]);
-
-x=1;
-
-if ((PINC & (1<<7)) == 0)
-{
- //tp_guarder();
-keynow= keys[colmn*14+x+fn];
-KeyboardReport->Modifier |= keym[colmn*14+x];
-if (keynow!=0)
-{
-KeyboardReport->KeyCode[keyc]=keys[colmn*14+x+fn];
-if (keyc<5) keyc++;
-}
-}
-x++;//2
-if ((PINC & (1<<6)) == 0)
-{
-// tp_guarder();
-keynow= keys[colmn*14+x+fn];
-KeyboardReport->Modifier |= keym[colmn*14+x];
-if (keynow!=0)
-{
-KeyboardReport->KeyCode[keyc]=keynow;
-if (keyc<5) keyc++;
-}
-}
-x++;//3
-//Delay_MS(5);
-if ((PIND & (1<<7))== 0)
-{
-// tp_guarder();
-keynow= keys[colmn*14+x+fn];
-KeyboardReport->Modifier |= keym[colmn*14+x];
-
-
-if (keynow == HID_KEY_LOCK_TOUCHPAD)
- {
- TouchPadLocked=!TouchPadLocked;
- while ((PIND & (1<<7))== 0);
- }
-if (keynow!=0)
-{
-KeyboardReport->KeyCode[keyc]=keynow;
-if (keyc<5) keyc++;
-}
-}
-x++;//4
-//Delay_MS(5);
-if ((PIND & (1<<3)) == 0)
-{
-// tp_guarder();
-keynow= keys[colmn*14+x+fn];
-KeyboardReport->Modifier |= keym[colmn*14+x];
-if (keynow!=0)
-{
-KeyboardReport->KeyCode[keyc]=keynow;
-if (keyc<5) keyc++;
-}
-}
-x++;//5
-if ((PINF & (1<<1)) == 0)
-{
-// tp_guarder();
-keynow= keys[colmn*14+x+fn];
-KeyboardReport->Modifier |= keym[colmn*14+x];
-if (keynow!=0)
-{
-KeyboardReport->KeyCode[keyc]=keynow;
-if (keyc<5) keyc++;
-}
-}
-x++;//6
-if ((PINF & (1<<6)) == 0)
-{
-// tp_guarder();
-keynow= keys[colmn*14+x+fn];
-KeyboardReport->Modifier |= keym[colmn*14+x];
-if (keynow!=0)
-{
-KeyboardReport->KeyCode[keyc]=keynow;
-if (keyc<5) keyc++;
-}
-}
-x++;//7
-if ((PINE & (1<<6)) == 0)
-{
-// tp_guarder();
-keynow= keys[colmn*14+x+fn];
-KeyboardReport->Modifier |= keym[colmn*14+x];
-if (keynow!=0)
-{
-KeyboardReport->KeyCode[keyc]=keynow;
-if (keyc<5) keyc++;
-}
-}
-x++;//8
-if ((PINF & (1<<4)) == 0)
-{
-// tp_guarder();
-keynow= keys[colmn*14+x+fn];
-KeyboardReport->Modifier |= keym[colmn*14+x];
-if (keynow!=0)
-{
-KeyboardReport->KeyCode[keyc]=keynow;
-if (keyc<5) keyc++;
-}
-}
-x++;//9
-if ((PIND & (1<<5)) == 0)
-{
-// tp_guarder();
-keynow= keys[colmn*14+x+fn];
-KeyboardReport->Modifier |= keym[colmn*14+x];
-if (keynow!=0)
-{
-KeyboardReport->KeyCode[keyc]=keynow;
-if (keyc<5) keyc++;
-}
-}
-x++;//10
-if ((PINF & (1<<5)) == 0)
-{
-// tp_guarder();
-keynow= keys[colmn*14+x+fn];
-KeyboardReport->Modifier |= keym[colmn*14+x];
-if (keynow!=0)
-{
-KeyboardReport->KeyCode[keyc]=keynow;
-if (keyc<5) keyc++;
-}
-}
-
-
-x++;//11
-if ((PINF & (1<<7)) == 0)
-{
-// tp_guarder();
-keynow= keys[colmn*14+x+fn];
-KeyboardReport->Modifier |= keym[colmn*14+x];
-if (keynow!=0)
-{
-KeyboardReport->KeyCode[keyc]=keynow;
-if (keyc<5) keyc++;
-}
-}
-
-
-x++;//12
-if ((PINE & (1<<2)) == 0)
-{
-// tp_guarder();
-keynow= keys[colmn*14+x+fn];
-KeyboardReport->Modifier |= keym[colmn*14+x];
-if (keynow!=0)
-{
-KeyboardReport->KeyCode[keyc]=keynow;
-if (keyc<5) keyc++;
-
-}
-}
- DDRD = 0;
- PORTD = 0xfc;
-
-
-}
-
-if ((KeyboardReport->Modifier == 0) && (keyc!=0)) tp_guarder();
-
-
- *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;
-
-
- MR_Y = 0;
- MR_X = 0;
- MR_W = 0;
- MR_B |= mouse;// (1 << 0);
-
-//cli();
-if (ActionSend)
-{
-uint16_t posx1 = tpdata[3]<<8 | tpdata[4];
-uint16_t posy1 = tpdata[5]<<8 | tpdata[6];
-switch (tpdata[2])
-{
-case 0:
- if (lastfingers != 0)
- {
- if (time_zero>PRETAP)
- {
-
- if (time_pressed<CLICK_MS)
- {
-
- if (abs(startposX+startposY-posx1-posy1)<10)
- {
- if (time_two != 0)
- MR_B_REQ = MOUSE_RIGTH;
- else
- MR_B_REQ = MOUSE_LEFT;
- }
- }
-
-
-
- }
-
- time_zero = 0;
- }
- speedlimit=0;
- lastposX = 0;
- lastposY = 0;
-
-break;
-
-case 1:
-
-
-
- touch_to=TOUCH_TO;
-
- switch (lastfingers)
- {
- case 0:
-
- presstime=CLICK_MS;
- speedlimit=0;
- break;
- case 1:
-
- if (lastposX != 0)
- {
- MR_X = limited(posx1 - lastposX);
- MR_Y = limited(posy1 - lastposY);
-
-
- }
- break;
-
- case 2:
-
-
- speedlimit=0;
- break;
- 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;
-
- if (lastfingers == 2)
- {
- if (lastposY > posy1 + DRAG_HYST)
- MR_W = WHEEL;
- else if (lastposY + DRAG_HYST < posy1)
- MR_W = -WHEEL;
-
- if (MR_W !=0) time_zero = 0;
- presstime=0;
- }
- else
- {
-
- time_two = 0;
- startposX=posx1;
- startposY=posy1;
- lastfingers = 2;
-
- }
- lastposX = posx1;
- lastposY = posy1;
-
- break;
-
-
-default:
- lastposX = 0;
- lastposY = 0;
-
- break;
-
-
-}
-lastfingers = tpdata[2];
-ActionSend = false;
-itsDone = true;
-}
- MouseReport->Y = MR_Y;
- MouseReport->X = MR_X;
- MouseReport->Button = MR_B;
- MouseReport->Wheel = MR_W;
-
- MR_B=0;
-
- *ReportSize = sizeof(USB_WheelMouseReport_Data_t);
- return true;
- }
-
+bool
+CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t *
+ const HIDInterfaceInfo,
+ uint8_t * const ReportID,
+ const uint8_t ReportType,
+ void *ReportData,
+ uint16_t * const ReportSize)
+{
+ /*
+ * Determine which interface must have its report generated
+ */
+ if (HIDInterfaceInfo == &Keyboard_HID_Interface) {
+
+ USB_KeyboardReport_Data_t *KeyboardReport =
+ (USB_KeyboardReport_Data_t *) ReportData;
+
+ uint8_t x = 0;
+ uint8_t fn = 0;
+
+ keyc = 0; // reset keys
+ KeyboardReport->Modifier = 0;
+
+ for (x = 0; x < 6; x++)
+ KeyboardReport->KeyCode[x] = 0;
+
+
+ if (itsDone) {
+ itsDone = false;
+ }
+
+ DDRE = 0;
+ DDRF = 0;
+ DDRC = 0;
+ DDRD = 0;
+ PORTD = 0xfc;
+ PORTE = 0xFF;
+ PORTF = 0xFF;
+ PORTC = 0xFF;
+
+ DDRB = 0xff;
+
+ for (colmn = 0; colmn < 8; colmn++) {
+
+ uint8_t keynow = 0;
+
+ if (colmn == 0) {
+ cli();
+ DDRB = 0x00;
+ PORTB = 0x00;
+ DDRD = (1 << 4);
+ PORTD = (1 << 4);
+
+ Delay_MS(2);
+
+ if (PINB & 0x40) {
+ fn = 112;
+ // tp_guarder();
+ if (PINB & 0x01) {
+ KeyboardReport->KeyCode[keyc] =
+ HID_KEYBOARD_SC_PAGE_UP;
+ if (keyc < 5)
+ keyc++;
+ }
+ if (PINB & 0x02) {
+ KeyboardReport->Modifier |=
+ HID_KEYBOARD_MODIFIER_LEFTSHIFT;
+ KeyboardReport->KeyCode[keyc] =
+ HID_KEYBOARD_SC_LEFT_SHIFT;
+ if (keyc < 5)
+ keyc++;
+ }
+ if (PINB & 0x20) {
+ KeyboardReport->KeyCode[keyc] =
+ HID_KEYBOARD_SC_HOME;
+ if (keyc < 5)
+ keyc++;
+ }
+ if (PINB & 0x80) {
+ KeyboardReport->Modifier |=
+ HID_KEYBOARD_MODIFIER_RIGHTSHIFT;
+ KeyboardReport->KeyCode[keyc] =
+ HID_KEYBOARD_SC_RIGHT_SHIFT;
+ if (keyc < 5)
+ keyc++;
+ }
+
+ } else {
+ if (PINB & 0x01) {
+ KeyboardReport->KeyCode[keyc] =
+ HID_KEYBOARD_SC_UP_ARROW;
+ if (keyc < 5)
+ keyc++;
+ // tp_guarder();
+ }
+ if (PINB & 0x02) {
+ KeyboardReport->Modifier |=
+ HID_KEYBOARD_MODIFIER_LEFTSHIFT;
+ KeyboardReport->KeyCode[keyc] =
+ HID_KEYBOARD_SC_LEFT_SHIFT;
+ if (keyc < 5)
+ keyc++;
+ }
+ if (PINB & 0x20) {
+ KeyboardReport->KeyCode[keyc] =
+ HID_KEYBOARD_SC_LEFT_ARROW;
+ if (keyc < 5)
+ keyc++;
+ // tp_guarder();
+ }
+ if (PINB & 0x80) {
+ KeyboardReport->Modifier |=
+ HID_KEYBOARD_MODIFIER_RIGHTSHIFT;
+ KeyboardReport->KeyCode[keyc] =
+ HID_KEYBOARD_SC_RIGHT_SHIFT;
+ if (keyc < 5)
+ keyc++;
+ }
+ }
+
+ // x0
+ DDRD = (1 << 6);
+ PORTD = (1 << 6);
+ DDRB = 0x00;
+ PORTB = 0x00;
+ Delay_MS(2);
+
+ if (PINB & 0x10) {
+ KeyboardReport->Modifier |=
+ HID_KEYBOARD_MODIFIER_RIGHTCTRL;
+ KeyboardReport->KeyCode[keyc] =
+ HID_KEYBOARD_SC_RIGHT_CONTROL;
+ if (keyc < 5)
+ keyc++;
+ }
+ if (PINB & 0x40) {
+ KeyboardReport->Modifier |=
+ HID_KEYBOARD_MODIFIER_LEFTCTRL;
+ KeyboardReport->KeyCode[keyc] =
+ HID_KEYBOARD_SC_LEFT_CONTROL;
+ if (keyc < 5)
+ keyc++;
+ }
+ if (PINB & 0x08) {
+ if (fn == 112)
+ KeyboardReport->KeyCode[keyc] =
+ HID_KEYBOARD_SC_VOLUME_UP;
+ else
+ KeyboardReport->KeyCode[keyc] = HID_KEYBOARD_SC_F5;
+ if (keyc < 5)
+ keyc++;
+ }
+
+ PORTB = rowY[colmn];
+ DDRB = 0xff;
+ DDRD = 0;
+ PORTD = 0xfc;
+ Delay_MS(3);
+ sei();
+ }
+
+ PORTB = rowY[colmn];
+ while (PINB != rowY[colmn]);
+
+ x = 1;
+
+ if ((PINC & (1 << 7)) == 0) {
+ // tp_guarder();
+ keynow = keys[colmn * 14 + x + fn];
+ KeyboardReport->Modifier |= keym[colmn * 14 + x];
+ if (keynow != 0) {
+ KeyboardReport->KeyCode[keyc] =
+ keys[colmn * 14 + x + fn];
+ if (keyc < 5)
+ keyc++;
+ }
+ }
+ x++; // 2
+ if ((PINC & (1 << 6)) == 0) {
+ // tp_guarder();
+ keynow = keys[colmn * 14 + x + fn];
+ KeyboardReport->Modifier |= keym[colmn * 14 + x];
+ if (keynow != 0) {
+ KeyboardReport->KeyCode[keyc] = keynow;
+ if (keyc < 5)
+ keyc++;
+ }
+ }
+ x++; // 3
+ // Delay_MS(5);
+ if ((PIND & (1 << 7)) == 0) {
+ // tp_guarder();
+ keynow = keys[colmn * 14 + x + fn];
+ KeyboardReport->Modifier |= keym[colmn * 14 + x];
+
+ if (keynow == HID_KEY_LOCK_TOUCHPAD) {
+ TouchPadLocked = !TouchPadLocked;
+ while ((PIND & (1 << 7)) == 0);
+ }
+ if (keynow != 0) {
+ KeyboardReport->KeyCode[keyc] = keynow;
+ if (keyc < 5)
+ keyc++;
+ }
+ }
+ x++; // 4
+ // Delay_MS(5);
+ if ((PIND & (1 << 3)) == 0) {
+ // tp_guarder();
+ keynow = keys[colmn * 14 + x + fn];
+ KeyboardReport->Modifier |= keym[colmn * 14 + x];
+ if (keynow != 0) {
+ KeyboardReport->KeyCode[keyc] = keynow;
+ if (keyc < 5)
+ keyc++;
+ }
+ }
+ x++; // 5
+ if ((PINF & (1 << 1)) == 0) {
+ // tp_guarder();
+ keynow = keys[colmn * 14 + x + fn];
+ KeyboardReport->Modifier |= keym[colmn * 14 + x];
+ if (keynow != 0) {
+ KeyboardReport->KeyCode[keyc] = keynow;
+ if (keyc < 5)
+ keyc++;
+ }
+ }
+ x++; // 6
+ if ((PINF & (1 << 6)) == 0) {
+ // tp_guarder();
+ keynow = keys[colmn * 14 + x + fn];
+ KeyboardReport->Modifier |= keym[colmn * 14 + x];
+ if (keynow != 0) {
+ KeyboardReport->KeyCode[keyc] = keynow;
+ if (keyc < 5)
+ keyc++;
+ }
+ }
+ x++; // 7
+ if ((PINE & (1 << 6)) == 0) {
+ // tp_guarder();
+ keynow = keys[colmn * 14 + x + fn];
+ KeyboardReport->Modifier |= keym[colmn * 14 + x];
+ if (keynow != 0) {
+ KeyboardReport->KeyCode[keyc] = keynow;
+ if (keyc < 5)
+ keyc++;
+ }
+ }
+ x++; // 8
+ if ((PINF & (1 << 4)) == 0) {
+ // tp_guarder();
+ keynow = keys[colmn * 14 + x + fn];
+ KeyboardReport->Modifier |= keym[colmn * 14 + x];
+ if (keynow != 0) {
+ KeyboardReport->KeyCode[keyc] = keynow;
+ if (keyc < 5)
+ keyc++;
+ }
+ }
+ x++; // 9
+ if ((PIND & (1 << 5)) == 0) {
+ // tp_guarder();
+ keynow = keys[colmn * 14 + x + fn];
+ KeyboardReport->Modifier |= keym[colmn * 14 + x];
+ if (keynow != 0) {
+ KeyboardReport->KeyCode[keyc] = keynow;
+ if (keyc < 5)
+ keyc++;
+ }
+ }
+ x++; // 10
+ if ((PINF & (1 << 5)) == 0) {
+ // tp_guarder();
+ keynow = keys[colmn * 14 + x + fn];
+ KeyboardReport->Modifier |= keym[colmn * 14 + x];
+ if (keynow != 0) {
+ KeyboardReport->KeyCode[keyc] = keynow;
+ if (keyc < 5)
+ keyc++;
+ }
+ }
+ x++; // 11
+ if ((PINF & (1 << 7)) == 0) {
+ // tp_guarder();
+ keynow = keys[colmn * 14 + x + fn];
+ KeyboardReport->Modifier |= keym[colmn * 14 + x];
+ if (keynow != 0) {
+ KeyboardReport->KeyCode[keyc] = keynow;
+ if (keyc < 5)
+ keyc++;
+ }
+ }
+ x++; // 12
+ if ((PINE & (1 << 2)) == 0) {
+ // tp_guarder();
+ keynow = keys[colmn * 14 + x + fn];
+ KeyboardReport->Modifier |= keym[colmn * 14 + x];
+ if (keynow != 0) {
+ KeyboardReport->KeyCode[keyc] = keynow;
+ if (keyc < 5)
+ keyc++;
+ }
+ }
+ DDRD = 0;
+ PORTD = 0xfc;
+ }
+
+ if ((KeyboardReport->Modifier == 0) && (keyc != 0))
+ tp_guarder();
+
+ *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;
+
+ MR_Y = 0;
+ MR_X = 0;
+ MR_W = 0;
+ MR_B |= mouse; // (1 << 0);
+
+ // cli();
+ if (ActionSend) {
+ uint16_t posx1 = tpdata[3] << 8 | tpdata[4];
+ uint16_t posy1 = tpdata[5] << 8 | tpdata[6];
+ switch (tpdata[2]) {
+ case 0:
+ if (lastfingers != 0) {
+ if (time_zero > PRETAP) {
+
+ if (time_pressed < CLICK_MS) {
+
+ if (abs(startposX + startposY - posx1 - posy1)
+ < 10) {
+ if (time_two != 0)
+ MR_B_REQ = MOUSE_RIGTH;
+ else
+ MR_B_REQ = MOUSE_LEFT;
+ }
+ }
+ }
+
+ time_zero = 0;
+ }
+ speedlimit = 0;
+ lastposX = 0;
+ lastposY = 0;
+
+ break;
+
+ case 1:
+ touch_to = TOUCH_TO;
+
+ switch (lastfingers) {
+ case 0:
+ presstime = CLICK_MS;
+ speedlimit = 0;
+ break;
+ case 1:
+ if (lastposX != 0) {
+ MR_X = limited(posx1 - lastposX);
+ MR_Y = limited(posy1 - lastposY);
+ }
+ break;
+ case 2:
+ speedlimit = 0;
+ break;
+ 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;
+
+ if (lastfingers == 2) {
+ if (lastposY > posy1 + DRAG_HYST)
+ MR_W = WHEEL;
+ else if (lastposY + DRAG_HYST < posy1)
+ MR_W = -WHEEL;
+
+ if (MR_W != 0)
+ time_zero = 0;
+ presstime = 0;
+ } else {
+ time_two = 0;
+ startposX = posx1;
+ startposY = posy1;
+ lastfingers = 2;
+ }
+ lastposX = posx1;
+ lastposY = posy1;
+
+ break;
+ default:
+ lastposX = 0;
+ lastposY = 0;
+
+ break;
+ }
+ lastfingers = tpdata[2];
+ ActionSend = false;
+ itsDone = true;
+ }
+ MouseReport->Y = MR_Y;
+ MouseReport->X = MR_X;
+ MouseReport->Button = MR_B;
+ MouseReport->Wheel = MR_W;
+
+ MR_B = 0;
+
+ *ReportSize = sizeof(USB_WheelMouseReport_Data_t);
+ return true;
+ }
}
@@ -818,148 +736,127 @@ itsDone = true;
* \param[in] ReportData Pointer to a buffer where the received report has been stored
* \param[in] ReportSize Size in bytes of the received HID report
*/
-void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
- const uint8_t ReportID,
- const uint8_t ReportType,
- const void* ReportData,
- const uint16_t ReportSize)
+void
+CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t *
+ const HIDInterfaceInfo,
+ const uint8_t ReportID,
+ const uint8_t ReportType,
+ const void *ReportData,
+ const uint16_t ReportSize)
{
- if (HIDInterfaceInfo == &Keyboard_HID_Interface)
- {
+ if (HIDInterfaceInfo == &Keyboard_HID_Interface) {
- }
+ }
}
ISR(ADC_vect)
{
-
- ADCSRA |= (1 << ADIF);
- button= ADCH;
-
-
- if (button == oldbutton)
- {
- if (button < 0xe8)
- {
-
- if (button>0xa0) mouse = MOUSE_RIGTH;
-
- else if (button>0x80) mouse = MOUSE_LEFT;
-
- else mouse = MOUSE_MIDDLE;
-
- }
- else mouse = 0;
- }
- else oldbutton = button;
-
+ ADCSRA |= (1 << ADIF);
+ button = ADCH;
+
+ if (button == oldbutton) {
+ if (button < 0xe8) {
+ if (button > 0xa0)
+ mouse = MOUSE_RIGTH;
+ else if (button > 0x80)
+ mouse = MOUSE_LEFT;
+ else
+ mouse = MOUSE_MIDDLE;
+ } else
+ mouse = 0;
+ } else
+ oldbutton = button;
}
-
-
-
-
ISR(INT2_vect)
{
- #if 1
- if (TWI_StartTransmission(0x48 | TWI_ADDRESS_WRITE, 10) == TWI_ERROR_NoError)
- {
- TWI_SendByte(0x00);
- TWI_StopTransmission();
-
- if (TWI_StartTransmission(0x48 | TWI_ADDRESS_READ, 10) == TWI_ERROR_NoError)
- {
-
-
- // Read some bytes, acknowledge after the last byte is received????
- for (int s=0;s<0x06;s++)
- TWI_ReceiveByte(&tpdata[s], false);
-
-
- TWI_ReceiveByte(&tpdata[0x06], true);
-
- }
- }
- // Must stop transmission afterwards to release the bus
- TWI_StopTransmission();
-
-if ((!TouchPadLocked) && (!tp_guard))
- ActionSend = true;
+#if 1
+ if (TWI_StartTransmission(0x48 | TWI_ADDRESS_WRITE, 10) ==
+ TWI_ERROR_NoError) {
+ TWI_SendByte(0x00);
+ TWI_StopTransmission();
+
+ if (TWI_StartTransmission(0x48 | TWI_ADDRESS_READ, 10) ==
+ TWI_ERROR_NoError) {
+ // Read some bytes, acknowledge after the last byte is
+ // received????
+ for (int s = 0; s < 0x06; s++)
+ TWI_ReceiveByte(&tpdata[s], false);
+ TWI_ReceiveByte(&tpdata[0x06], true);
+ }
+ }
+ // Must stop transmission afterwards to release the bus
+ TWI_StopTransmission();
+
+ if ((!TouchPadLocked) && (!tp_guard))
+ ActionSend = true;
#endif
}
// timer0 overflow ~60hz
-ISR(TIMER0_OVF_vect) {
-
-#if 1
-
-
- if (TWI_StartTransmission(0x48 | TWI_ADDRESS_WRITE, 10) == TWI_ERROR_NoError)
- {
- TWI_SendByte(0x00);
- TWI_StopTransmission();
-
- if (TWI_StartTransmission(0x48 | TWI_ADDRESS_READ, 10) == TWI_ERROR_NoError)
- {
-
-
- // Read some bytes, acknowledge after the last byte is received????
- for (int s=0;s<0x06;s++)
- TWI_ReceiveByte(&tpdata[s], false);
-
-
- TWI_ReceiveByte(&tpdata[0x06], true);
-
- }
- }
- // Must stop transmission afterwards to release the bus
- TWI_StopTransmission();
- if ((!TouchPadLocked) && (!tp_guard) && (tpdata[0]!=0))
- ActionSend = true;
-
-
-
-
-
-#endif
-
-
- if ((time_zero != 0xff) && (tpdata[2]==0)) time_zero++;
-
- if (time_zero==TOUCH_TO)
- {
-#if TAP_ENABLED
- MR_B=MR_B_REQ;
- MR_B_REQ=0;
+ISR(TIMER0_OVF_vect)
+{
+#if 1
+ if (TWI_StartTransmission(0x48 | TWI_ADDRESS_WRITE, 10) ==
+ TWI_ERROR_NoError) {
+ TWI_SendByte(0x00);
+ TWI_StopTransmission();
+
+ if (TWI_StartTransmission(0x48 | TWI_ADDRESS_READ, 10) ==
+ TWI_ERROR_NoError) {
+ // Read some bytes, acknowledge after the last byte is
+ // received????
+ for (int s = 0; s < 0x06; s++)
+ TWI_ReceiveByte(&tpdata[s], false);
+
+ TWI_ReceiveByte(&tpdata[0x06], true);
+ }
+ }
+ // Must stop transmission afterwards to release the bus
+ TWI_StopTransmission();
+ if ((!TouchPadLocked) && (!tp_guard) && (tpdata[0] != 0))
+ ActionSend = true;
+#endif
+
+ if ((time_zero != 0xff) && (tpdata[2] == 0))
+ time_zero++;
+
+ if (time_zero == TOUCH_TO) {
+#if TAP_ENABLED
+ MR_B = MR_B_REQ;
+ MR_B_REQ = 0;
#endif
- time_one=0;
- time_two=0;
- time_pressed=0;
- }
- if ((time_one != 0xff) && (tpdata[2]==1)) time_one++;
- if ((time_two != 0xff) && (tpdata[2]==2)) time_two++;
-
-
- if (ticks!=0) ticks--;
- if (dragtime!=0) dragtime--;
- if (presstime != 0) presstime--;
- if (tpguard !=0) tpguard--;
- if (tpguard==1) tp_guard = false;
-
-
-
- if (touch_to!=0) touch_to--;
- if (touch_to==1)
- {
- tap_enabled=true;
- lastposX=0;
- lastposY=0;
- drag=false;
- if (presstime!=0)
- ActionSend = true;
- else
- lastfingers=0;
-
- }
+ time_one = 0;
+ time_two = 0;
+ time_pressed = 0;
+ }
+ if ((time_one != 0xff) && (tpdata[2] == 1))
+ time_one++;
+ if ((time_two != 0xff) && (tpdata[2] == 2))
+ time_two++;
+
+ if (ticks != 0)
+ ticks--;
+ if (dragtime != 0)
+ dragtime--;
+ if (presstime != 0)
+ presstime--;
+ if (tpguard != 0)
+ tpguard--;
+ if (tpguard == 1)
+ tp_guard = false;
+
+ if (touch_to != 0)
+ touch_to--;
+ if (touch_to == 1) {
+ tap_enabled = true;
+ lastposX = 0;
+ lastposY = 0;
+ drag = false;
+ if (presstime != 0)
+ ActionSend = true;
+ else
+ lastfingers = 0;
+ }
}