aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lufa/Projects/HIDReportViewer/HIDReportViewer.h
blob: 22224fe1a421c4665de40623971d92058ab89b52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
             LUFA Library
     Copyright (C) Dean Camera, 2017.

  dean [at] fourwalledcubicle [dot] com
           www.lufa-lib.org
*/

/*
  Copyright 2017  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
 *
 *  Header file for HIDReportViewer.c.
 */

#ifndef _HID_REPORT_VIEWER_H_
#define _HID_REPORT_VIEWER_H_

	/* Includes: */
		#include <avr/io.h>
		#include <avr/wdt.h>
		#include <avr/pgmspace.h>
		#include <avr/power.h>
		#include <avr/interrupt.h>
		#include <stdio.h>
		#include <inttypes.h>

		#include <LUFA/Drivers/Misc/TerminalCodes.h>
		#include <LUFA/Drivers/Peripheral/Serial.h>
		#include <LUFA/Drivers/Board/LEDs.h>
		#include <LUFA/Drivers/USB/USB.h>
		#include <LUFA/Platform/Platform.h>

	/* Macros: */
		/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
		#define LEDMASK_USB_NOTREADY      LEDS_LED1

		/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
		#define LEDMASK_USB_ENUMERATING  (LEDS_LED2 | LEDS_LED3)

		/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
		#define LEDMASK_USB_READY        (LEDS_LED2 | LEDS_LED4)

		/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
		#define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)

		/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
		#define LEDMASK_USB_BUSY         (LEDS_LED1 | LEDS_LED3 | LEDS_LED4)

	/* Function Prototypes: */
		void SetupHardware(void);
		void RetrieveDeviceData(void);
		void OutputReportSizes(void);
		void OutputParsedReportItems(void);
		void OutputCollectionPath(const HID_CollectionPath_t* const CollectionPath);

		void EVENT_USB_Host_HostError(const uint8_t ErrorCode);
		void EVENT_USB_Host_DeviceAttached(void);
		void EVENT_USB_Host_DeviceUnattached(void);
		void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
		                                            const uint8_t SubErrorCode);
		void EVENT_USB_Host_DeviceEnumerationComplete(void);

		bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* const CurrentItem);

#endif
class="s">""; char newline[2] = "\n"; char arguments[6][20]; __attribute__ ((weak)) const char terminal_prompt[8] = "> "; #ifdef AUDIO_ENABLE #ifndef TERMINAL_SONG #define TERMINAL_SONG SONG(TERMINAL_SOUND) #endif float terminal_song[][2] = TERMINAL_SONG; #define TERMINAL_BELL() PLAY_SONG(terminal_song) #else #define TERMINAL_BELL() #endif __attribute__ ((weak)) const char keycode_to_ascii_lut[58] = { 0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0, 0, 0, '\t', ' ', '-', '=', '[', ']', '\\', 0, ';', '\'', '`', ',', '.', '/' }; __attribute__ ((weak)) const char shifted_keycode_to_ascii_lut[58] = { 0, 0, 0, 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', 0, 0, 0, '\t', ' ', '_', '+', '{', '}', '|', 0, ':', '\'', '~', '<', '>', '?' }; struct stringcase { char* string; void (*func)(void); } typedef stringcase; void enable_terminal(void) { terminal_enabled = true; strcpy(buffer, ""); for (int i = 0; i < 6; i++) strcpy(arguments[i], ""); // select all text to start over // SEND_STRING(SS_LCTRL("a")); send_string(terminal_prompt); } void disable_terminal(void) { terminal_enabled = false; } void terminal_about(void) { SEND_STRING("QMK Firmware\n"); SEND_STRING(" v"); SEND_STRING(QMK_VERSION); SEND_STRING("\n"SS_TAP(X_HOME)" Built: "); SEND_STRING(QMK_BUILDDATE); send_string(newline); #ifdef TERMINAL_HELP if (strlen(arguments[1]) != 0) { SEND_STRING("You entered: "); send_string(arguments[1]); send_string(newline); } #endif } void terminal_help(void); extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; void terminal_keycode(void) { if (strlen(arguments[1]) != 0 && strlen(arguments[2]) != 0 && strlen(arguments[3]) != 0) { char keycode_dec[5]; char keycode_hex[5]; uint16_t layer = strtol(arguments[1], (char **)NULL, 10); uint16_t row = strtol(arguments[2], (char **)NULL, 10); uint16_t col = strtol(arguments[3], (char **)NULL, 10); uint16_t keycode = pgm_read_word(&keymaps[layer][row][col]); itoa(keycode, keycode_dec, 10); itoa(keycode, keycode_hex, 16); SEND_STRING("0x"); send_string(keycode_hex); SEND_STRING(" ("); send_string(keycode_dec); SEND_STRING(")\n"); } else { #ifdef TERMINAL_HELP SEND_STRING("usage: keycode <layer> <row> <col>\n"); #endif } } void terminal_keymap(void) { if (strlen(arguments[1]) != 0) { uint16_t layer = strtol(arguments[1], (char **)NULL, 10); for (int r = 0; r < MATRIX_ROWS; r++) { for (int c = 0; c < MATRIX_COLS; c++) { uint16_t keycode = pgm_read_word(&keymaps[layer][r][c]); char keycode_s[8]; sprintf(keycode_s, "0x%04x, ", keycode); send_string(keycode_s); } send_string(newline); } } else { #ifdef TERMINAL_HELP SEND_STRING("usage: keymap <layer>\n"); #endif } } stringcase terminal_cases[] = { { "about", terminal_about }, { "help", terminal_help }, { "keycode", terminal_keycode }, { "keymap", terminal_keymap }, { "exit", disable_terminal } }; void terminal_help(void) { SEND_STRING("commands available:\n "); for( stringcase* case_p = terminal_cases; case_p != terminal_cases + sizeof( terminal_cases ) / sizeof( terminal_cases[0] ); case_p++ ) { send_string(case_p->string); SEND_STRING(" "); } send_string(newline); } void command_not_found(void) { SEND_STRING("command \""); send_string(buffer); SEND_STRING("\" not found\n"); } void process_terminal_command(void) { // we capture return bc of the order of events, so we need to manually send a newline send_string(newline); char * pch; uint8_t i = 0; pch = strtok(buffer, " "); while (pch != NULL) { strcpy(arguments[i], pch); pch = strtok(NULL, " "); i++; } bool command_found = false; for( stringcase* case_p = terminal_cases; case_p != terminal_cases + sizeof( terminal_cases ) / sizeof( terminal_cases[0] ); case_p++ ) { if( 0 == strcmp( case_p->string, buffer ) ) { command_found = true; (*case_p->func)(); break; } } if (!command_found) command_not_found(); if (terminal_enabled) { strcpy(buffer, ""); for (int i = 0; i < 6; i++) strcpy(arguments[i], ""); SEND_STRING(SS_TAP(X_HOME)); send_string(terminal_prompt); } } bool process_terminal(uint16_t keycode, keyrecord_t *record) { if (keycode == TERM_ON && record->event.pressed) { enable_terminal(); return false; } if (terminal_enabled && record->event.pressed) { if (keycode == TERM_OFF && record->event.pressed) { disable_terminal(); return false; } if (keycode < 256) { uint8_t str_len; char char_to_add; switch (keycode) { case KC_ENTER: process_terminal_command(); return false; break; case KC_ESC: SEND_STRING("\n"); enable_terminal(); return false; break; case KC_BSPC: str_len = strlen(buffer); if (str_len > 0) { buffer[str_len-1] = 0; return true; } else { TERMINAL_BELL(); return false; } break; case KC_LEFT: case KC_RIGHT: case KC_UP: case KC_DOWN: return false; break; default: if (keycode <= 58) { char_to_add = 0; if (get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) { char_to_add = shifted_keycode_to_ascii_lut[keycode]; } else if (get_mods() == 0) { char_to_add = keycode_to_ascii_lut[keycode]; } if (char_to_add != 0) { strncat(buffer, &char_to_add, 1); } } break; } } } return true; }