commit cad3fafcbd0b92676b3adcaeeeb05954ad7f57d7
parent 1f115125b28f198adec2da3dfc89591f4d8d8247
Author: Lukas F. Hartmann <lukas@mnt.mn>
Date: Sun, 26 Aug 2018 23:35:02 +0200
untabify, header
Diffstat:
1 file changed, 180 insertions(+), 175 deletions(-)
diff --git a/reform-keyboard-fw/Keyboard.c b/reform-keyboard-fw/Keyboard.c
@@ -1,4 +1,9 @@
/*
+ MNT Reform Keyboard Firmware
+ Copyright 2018 Lukas F. Hartmann / MNT Media and Technology UG, Berlin
+ lukas@mntmn.com
+*/
+/*
LUFA Library
Copyright (C) Dean Camera, 2018.
@@ -39,20 +44,20 @@ static uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];
* within a device can be differentiated from one another.
*/
USB_ClassInfo_HID_Device_t Keyboard_HID_Interface =
- {
- .Config =
- {
- .InterfaceNumber = INTERFACE_ID_Keyboard,
- .ReportINEndpoint =
- {
- .Address = KEYBOARD_EPADDR,
- .Size = KEYBOARD_EPSIZE,
- .Banks = 1,
- },
- .PrevReportINBuffer = PrevKeyboardHIDReportBuffer,
- .PrevReportINBufferSize = sizeof(PrevKeyboardHIDReportBuffer),
- },
- };
+ {
+ .Config =
+ {
+ .InterfaceNumber = INTERFACE_ID_Keyboard,
+ .ReportINEndpoint =
+ {
+ .Address = KEYBOARD_EPADDR,
+ .Size = KEYBOARD_EPSIZE,
+ .Banks = 1,
+ },
+ .PrevReportINBuffer = PrevKeyboardHIDReportBuffer,
+ .PrevReportINBufferSize = sizeof(PrevKeyboardHIDReportBuffer),
+ },
+ };
#define output_low(port,pin) port &= ~(1<<pin)
@@ -66,26 +71,26 @@ int kdb_modifier = 0;
int main(void)
{
- SetupHardware();
- GlobalInterruptEnable();
-
- for (;;)
- {
- HID_Device_USBTask(&Keyboard_HID_Interface);
- USB_USBTask();
- }
+ SetupHardware();
+ GlobalInterruptEnable();
+
+ for (;;)
+ {
+ HID_Device_USBTask(&Keyboard_HID_Interface);
+ USB_USBTask();
+ }
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware()
{
- /* Disable watchdog if enabled by bootloader/fuses */
- MCUSR &= ~(1 << WDRF);
- wdt_disable();
+ /* Disable watchdog if enabled by bootloader/fuses */
+ MCUSR &= ~(1 << WDRF);
+ wdt_disable();
- /* Disable clock division */
- clock_prescale_set(clock_div_1);
- /* Hardware Initialization */
- USB_Init();
+ /* Disable clock division */
+ clock_prescale_set(clock_div_1);
+ /* Hardware Initialization */
+ USB_Init();
DDRB = 0b00111111;
DDRD = 0b00000000;
@@ -117,141 +122,141 @@ void EVENT_USB_Device_Disconnect(void)
/** Event handler for the library USB Configuration Changed event. */
void EVENT_USB_Device_ConfigurationChanged(void)
{
- bool ConfigSuccess = true;
+ bool ConfigSuccess = true;
- ConfigSuccess &= HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface);
+ ConfigSuccess &= HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface);
- USB_Device_EnableSOFEvents();
+ USB_Device_EnableSOFEvents();
}
/** Event handler for the library USB Control Request reception event. */
void EVENT_USB_Device_ControlRequest(void)
{
- HID_Device_ProcessControlRequest(&Keyboard_HID_Interface);
+ HID_Device_ProcessControlRequest(&Keyboard_HID_Interface);
}
/** Event handler for the USB device Start Of Frame event. */
void EVENT_USB_Device_StartOfFrame(void)
{
- HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);
+ HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);
}
-#define KEY_A 0x04
-#define KEY_B 0x05
-#define KEY_C 0x06
-#define KEY_D 0x07
-#define KEY_E 0x08
-#define KEY_F 0x09
-#define KEY_G 0x0A
-#define KEY_H 0x0B
-#define KEY_I 0x0C
-#define KEY_J 0x0D
-#define KEY_K 0x0E
-#define KEY_L 0x0F
-#define KEY_M 0x10
-#define KEY_N 0x11
-#define KEY_O 0x12
-#define KEY_P 0x13
-#define KEY_Q 0x14
-#define KEY_R 0x15
-#define KEY_S 0x16
-#define KEY_T 0x17
-#define KEY_U 0x18
-#define KEY_V 0x19
-#define KEY_W 0x1A
-#define KEY_X 0x1B
-#define KEY_Y 0x1C
-#define KEY_Z 0x1D
-#define KEY_1 0x1E
-#define KEY_2 0x1F
-#define KEY_3 0x20
-#define KEY_4 0x21
-#define KEY_5 0x22
-#define KEY_6 0x23
-#define KEY_7 0x24
-#define KEY_8 0x25
-#define KEY_9 0x26
-#define KEY_0 0x27
-#define KEY_ENTER 0x28
-#define KEY_ESCAPE 0x29
-#define KEY_BACKSPACE 0x2A
-#define KEY_TAB 0x2B
-#define KEY_SPACE 0x2C
-#define KEY_MINUS_AND_UNDERSCORE 0x2D
-#define KEY_EQUAL_AND_PLUS 0x2E
-#define KEY_OPENING_BRACKET_AND_OPENING_BRACE 0x2F
-#define KEY_CLOSING_BRACKET_AND_CLOSING_BRACE 0x30
-#define KEY_BACKSLASH_AND_PIPE 0x31
-#define KEY_NON_US_HASHMARK_AND_TILDE 0x32
-#define KEY_SEMICOLON_AND_COLON 0x33
-#define KEY_APOSTROPHE_AND_QUOTE 0x34
-#define KEY_GRAVE_ACCENT_AND_TILDE 0x35
-#define KEY_COMMA_AND_LESS_THAN_SIGN 0x36
-#define KEY_DOT_AND_GREATER_THAN_SIGN 0x37
-#define KEY_SLASH_AND_QUESTION_MARK 0x38
-#define KEY_CAPS_LOCK 0x39
-#define KEY_F1 0x3A
-#define KEY_F2 0x3B
-#define KEY_F3 0x3C
-#define KEY_F4 0x3D
-#define KEY_F5 0x3E
-#define KEY_F6 0x3F
-#define KEY_F7 0x40
-#define KEY_F8 0x41
-#define KEY_F9 0x42
-#define KEY_F10 0x43
-#define KEY_F11 0x44
-#define KEY_F12 0x45
-#define KEY_PRINT_SCREEN 0x46
-#define KEY_SCROLL_LOCK 0x47
-#define KEY_PAUSE 0x48
-#define KEY_INSERT 0x49
-#define KEY_HOME 0x4A
-#define KEY_PAGE_UP 0x4B
-#define KEY_DELETE 0x4C
-#define KEY_END 0x4D
-#define KEY_PAGE_DOWN 0x4E
-#define KEY_RIGHT_ARROW 0x4F
-#define KEY_LEFT_ARROW 0x50
-#define KEY_DOWN_ARROW 0x51
-#define KEY_UP_ARROW 0x52
-#define KEY_NUM_LOCK 0x53
-#define KEY_KEYPAD_SLASH 0x54
-#define KEY_KEYPAD_ASTERISK 0x55
-#define KEY_KEYPAD_MINUS 0x56
-#define KEY_KEYPAD_PLUS 0x57
-#define KEY_KEYPAD_ENTER 0x58
-#define KEY_KEYPAD_1_AND_END 0x59
-#define KEY_KEYPAD_2_AND_DOWN_ARROW 0x5A
-#define KEY_KEYPAD_3_AND_PAGE_DOWN 0x5B
-#define KEY_KEYPAD_4_AND_LEFT_ARROW 0x5C
-#define KEY_KEYPAD_5 0x5D
-#define KEY_KEYPAD_6_AND_RIGHT_ARROW 0x5E
-#define KEY_KEYPAD_7_AND_HOME 0x5F
-#define KEY_KEYPAD_8_AND_UP_ARROW 0x60
-#define KEY_KEYPAD_9_AND_PAGE_UP 0x61
-#define KEY_KEYPAD_0_AND_INSERT 0x62
-#define KEY_KEYPAD_DOT_AND_DELETE 0x63
-#define KEY_NON_US_BACKSLASH_AND_PIPE 0x64
-#define KEY_APPLICATION 0x65
-#define KEY_POWER 0x66
-#define KEY_KEYPAD_EQUAL_SIGN 0x67
-#define KEY_F13 0x68
-#define KEY_F14 0x69
-#define KEY_F15 0x6A
-#define KEY_F16 0x6B
-#define KEY_F17 0x6C
-#define KEY_F18 0x6D
-#define KEY_F19 0x6E
-#define KEY_F20 0x6F
-#define KEY_F21 0x70
-#define KEY_F22 0x71
-#define KEY_F23 0x72
-#define KEY_F24 0x73
-
-#define KEY_MUTE 0x7F
-#define KEY_VOLUME_UP 0x80
-#define KEY_VOLUME_DOWN 0x81
+#define KEY_A 0x04
+#define KEY_B 0x05
+#define KEY_C 0x06
+#define KEY_D 0x07
+#define KEY_E 0x08
+#define KEY_F 0x09
+#define KEY_G 0x0A
+#define KEY_H 0x0B
+#define KEY_I 0x0C
+#define KEY_J 0x0D
+#define KEY_K 0x0E
+#define KEY_L 0x0F
+#define KEY_M 0x10
+#define KEY_N 0x11
+#define KEY_O 0x12
+#define KEY_P 0x13
+#define KEY_Q 0x14
+#define KEY_R 0x15
+#define KEY_S 0x16
+#define KEY_T 0x17
+#define KEY_U 0x18
+#define KEY_V 0x19
+#define KEY_W 0x1A
+#define KEY_X 0x1B
+#define KEY_Y 0x1C
+#define KEY_Z 0x1D
+#define KEY_1 0x1E
+#define KEY_2 0x1F
+#define KEY_3 0x20
+#define KEY_4 0x21
+#define KEY_5 0x22
+#define KEY_6 0x23
+#define KEY_7 0x24
+#define KEY_8 0x25
+#define KEY_9 0x26
+#define KEY_0 0x27
+#define KEY_ENTER 0x28
+#define KEY_ESCAPE 0x29
+#define KEY_BACKSPACE 0x2A
+#define KEY_TAB 0x2B
+#define KEY_SPACE 0x2C
+#define KEY_MINUS_AND_UNDERSCORE 0x2D
+#define KEY_EQUAL_AND_PLUS 0x2E
+#define KEY_OPENING_BRACKET_AND_OPENING_BRACE 0x2F
+#define KEY_CLOSING_BRACKET_AND_CLOSING_BRACE 0x30
+#define KEY_BACKSLASH_AND_PIPE 0x31
+#define KEY_NON_US_HASHMARK_AND_TILDE 0x32
+#define KEY_SEMICOLON_AND_COLON 0x33
+#define KEY_APOSTROPHE_AND_QUOTE 0x34
+#define KEY_GRAVE_ACCENT_AND_TILDE 0x35
+#define KEY_COMMA_AND_LESS_THAN_SIGN 0x36
+#define KEY_DOT_AND_GREATER_THAN_SIGN 0x37
+#define KEY_SLASH_AND_QUESTION_MARK 0x38
+#define KEY_CAPS_LOCK 0x39
+#define KEY_F1 0x3A
+#define KEY_F2 0x3B
+#define KEY_F3 0x3C
+#define KEY_F4 0x3D
+#define KEY_F5 0x3E
+#define KEY_F6 0x3F
+#define KEY_F7 0x40
+#define KEY_F8 0x41
+#define KEY_F9 0x42
+#define KEY_F10 0x43
+#define KEY_F11 0x44
+#define KEY_F12 0x45
+#define KEY_PRINT_SCREEN 0x46
+#define KEY_SCROLL_LOCK 0x47
+#define KEY_PAUSE 0x48
+#define KEY_INSERT 0x49
+#define KEY_HOME 0x4A
+#define KEY_PAGE_UP 0x4B
+#define KEY_DELETE 0x4C
+#define KEY_END 0x4D
+#define KEY_PAGE_DOWN 0x4E
+#define KEY_RIGHT_ARROW 0x4F
+#define KEY_LEFT_ARROW 0x50
+#define KEY_DOWN_ARROW 0x51
+#define KEY_UP_ARROW 0x52
+#define KEY_NUM_LOCK 0x53
+#define KEY_KEYPAD_SLASH 0x54
+#define KEY_KEYPAD_ASTERISK 0x55
+#define KEY_KEYPAD_MINUS 0x56
+#define KEY_KEYPAD_PLUS 0x57
+#define KEY_KEYPAD_ENTER 0x58
+#define KEY_KEYPAD_1_AND_END 0x59
+#define KEY_KEYPAD_2_AND_DOWN_ARROW 0x5A
+#define KEY_KEYPAD_3_AND_PAGE_DOWN 0x5B
+#define KEY_KEYPAD_4_AND_LEFT_ARROW 0x5C
+#define KEY_KEYPAD_5 0x5D
+#define KEY_KEYPAD_6_AND_RIGHT_ARROW 0x5E
+#define KEY_KEYPAD_7_AND_HOME 0x5F
+#define KEY_KEYPAD_8_AND_UP_ARROW 0x60
+#define KEY_KEYPAD_9_AND_PAGE_UP 0x61
+#define KEY_KEYPAD_0_AND_INSERT 0x62
+#define KEY_KEYPAD_DOT_AND_DELETE 0x63
+#define KEY_NON_US_BACKSLASH_AND_PIPE 0x64
+#define KEY_APPLICATION 0x65
+#define KEY_POWER 0x66
+#define KEY_KEYPAD_EQUAL_SIGN 0x67
+#define KEY_F13 0x68
+#define KEY_F14 0x69
+#define KEY_F15 0x6A
+#define KEY_F16 0x6B
+#define KEY_F17 0x6C
+#define KEY_F18 0x6D
+#define KEY_F19 0x6E
+#define KEY_F20 0x6F
+#define KEY_F21 0x70
+#define KEY_F22 0x71
+#define KEY_F23 0x72
+#define KEY_F24 0x73
+
+#define KEY_MUTE 0x7F
+#define KEY_VOLUME_UP 0x80
+#define KEY_VOLUME_DOWN 0x81
const uint8_t matrix[15*6] = {
KEY_ESCAPE, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, KEY_DELETE, KEY_F13,
@@ -294,9 +299,9 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
void* ReportData,
uint16_t* const ReportSize)
{
- USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData;
+ USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData;
- uint8_t UsedKeyCodes = 0;
+ uint8_t UsedKeyCodes = 0;
output_low(PORTE, LED);
@@ -342,27 +347,27 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
metaPressed = metaPressedNow;
- /*if (JoyStatus_LCL & JOY_UP)
- KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_A;
- else if (JoyStatus_LCL & JOY_DOWN)
- KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_B;
+ /*if (JoyStatus_LCL & JOY_UP)
+ KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_A;
+ else if (JoyStatus_LCL & JOY_DOWN)
+ KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_B;
- if (JoyStatus_LCL & JOY_LEFT)
- KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_C;
- else if (JoyStatus_LCL & JOY_RIGHT)
- KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_D;
+ if (JoyStatus_LCL & JOY_LEFT)
+ KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_C;
+ else if (JoyStatus_LCL & JOY_RIGHT)
+ KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_D;
- if (JoyStatus_LCL & JOY_PRESS)
- KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_E;
+ if (JoyStatus_LCL & JOY_PRESS)
+ KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_E;
- if (ButtonStatus_LCL & BUTTONS_BUTTON1)
- KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_F;
+ if (ButtonStatus_LCL & BUTTONS_BUTTON1)
+ KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_F;
- if (UsedKeyCodes)
+ if (UsedKeyCodes)
KeyboardReport->Modifier = HID_KEYBOARD_MODIFIER_LEFTSHIFT;*/
- *ReportSize = sizeof(USB_KeyboardReport_Data_t);
- return false;
+ *ReportSize = sizeof(USB_KeyboardReport_Data_t);
+ return false;
}
/** HID class driver callback function for the processing of HID reports from the host.
@@ -379,18 +384,18 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI
const void* ReportData,
const uint16_t ReportSize)
{
- //uint8_t LEDMask = LEDS_NO_LEDS;
- //uint8_t* LEDReport = (uint8_t*)ReportData;
+ //uint8_t LEDMask = LEDS_NO_LEDS;
+ //uint8_t* LEDReport = (uint8_t*)ReportData;
- /*if (*LEDReport & HID_KEYBOARD_LED_NUMLOCK)
- LEDMask |= LEDS_LED1;
+ /*if (*LEDReport & HID_KEYBOARD_LED_NUMLOCK)
+ LEDMask |= LEDS_LED1;
- if (*LEDReport & HID_KEYBOARD_LED_CAPSLOCK)
- LEDMask |= LEDS_LED3;
+ if (*LEDReport & HID_KEYBOARD_LED_CAPSLOCK)
+ LEDMask |= LEDS_LED3;
- if (*LEDReport & HID_KEYBOARD_LED_SCROLLLOCK)
+ if (*LEDReport & HID_KEYBOARD_LED_SCROLLLOCK)
LEDMask |= LEDS_LED4;*/
- //LEDs_SetAllLEDs(LEDMask);
+ //LEDs_SetAllLEDs(LEDMask);
}