Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
df0d2af961 | ||
|
426ace718b | ||
|
f8d340a9dd | ||
|
13ff230615 |
26
docs/feature_console_in.md
Normal file
26
docs/feature_console_in.md
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Console In
|
||||||
|
|
||||||
|
The "Console" in QMK refers to PJRC's vendor page of `0xFF31` and usage page of `0x74` - this is mainly used for sending debug statements to the computer that can be read via the QMK Toolbox (recommended), or HID listen.
|
||||||
|
|
||||||
|
When `#define CONSOLE_IN_ENABLE` is placed in the `config.h` file, the keyboard will also listen to messages sent to the keyboard, will be able to respond in a custom way, defined at the `quantum`, `kb`, or `user` level. A keymap's example might look like this:
|
||||||
|
|
||||||
|
```c
|
||||||
|
void process_console_data_user(uint8_t * data, uint8_t length) {
|
||||||
|
switch (data[0]) {
|
||||||
|
case 0x05:
|
||||||
|
print("Sending back a message to the computer\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Which will execute when a report is sent to the keyboard when the first byte is `0x05`.
|
||||||
|
|
||||||
|
## Default actions (defined at the `quantum` level)
|
||||||
|
|
||||||
|
When the first byte is:
|
||||||
|
|
||||||
|
* `0x01`: Print "Saying hello\n" via the console, and play the audio on song
|
||||||
|
* `0xFE`: Enter the bootloader - only works when `CONSOLE_IN_BOOTLOADER` is defined in the `config.h`
|
||||||
|
|
||||||
|
This needs to be fleshed out a bit more with some sort of versioning.
|
@ -44,6 +44,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define AUDIO_VOICES
|
#define AUDIO_VOICES
|
||||||
#define C6_AUDIO
|
#define C6_AUDIO
|
||||||
|
|
||||||
|
#define CONSOLE_IN_ENABLE
|
||||||
|
|
||||||
#define BACKLIGHT_PIN B7
|
#define BACKLIGHT_PIN B7
|
||||||
|
|
||||||
/* COL2ROW or ROW2COL */
|
/* COL2ROW or ROW2COL */
|
||||||
|
@ -65,7 +65,7 @@ CONSOLE_ENABLE = yes # Console for debug(+400)
|
|||||||
COMMAND_ENABLE = no # Commands for debug and configuration
|
COMMAND_ENABLE = no # Commands for debug and configuration
|
||||||
NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
|
NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
|
||||||
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
|
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
|
||||||
MIDI_ENABLE = yes # MIDI controls
|
MIDI_ENABLE = no # MIDI controls
|
||||||
AUDIO_ENABLE = yes # Audio output on port C6
|
AUDIO_ENABLE = yes # Audio output on port C6
|
||||||
UNICODE_ENABLE = no # Unicode
|
UNICODE_ENABLE = no # Unicode
|
||||||
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
|
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
|
||||||
|
@ -1296,3 +1296,42 @@ __attribute__ ((weak))
|
|||||||
void shutdown_user() {}
|
void shutdown_user() {}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifdef CONSOLE_IN_ENABLE
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void process_console_data_user(uint8_t * data, uint8_t length) {
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void process_console_data_kb(uint8_t * data, uint8_t length) {
|
||||||
|
process_console_data_user(data, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
void process_console_data_quantum(uint8_t * data, uint8_t length) {
|
||||||
|
// This can be used for testing - it echos back the information received
|
||||||
|
// print("Received message:\n ");
|
||||||
|
// while (*data) {
|
||||||
|
// sendchar(*data);
|
||||||
|
// data++;
|
||||||
|
// }
|
||||||
|
switch (data[0]) {
|
||||||
|
case 0x01:
|
||||||
|
print("Saying hello\n");
|
||||||
|
#ifdef AUDIO_ENABLE
|
||||||
|
audio_on();
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case 0xFE:
|
||||||
|
#ifdef CONSOLE_IN_BOOTLOADER
|
||||||
|
print("Entering bootloader\n");
|
||||||
|
reset_keyboard();
|
||||||
|
#else
|
||||||
|
print("Unable to enter bootloader\n");
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
process_console_data_kb(data, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -193,4 +193,10 @@ void led_set_kb(uint8_t usb_led);
|
|||||||
|
|
||||||
void api_send_unicode(uint32_t unicode);
|
void api_send_unicode(uint32_t unicode);
|
||||||
|
|
||||||
|
#ifdef CONSOLE_IN_ENABLE
|
||||||
|
void process_console_data_user(uint8_t * data, uint8_t length);
|
||||||
|
void process_console_data_kb(uint8_t * data, uint8_t length);
|
||||||
|
void process_console_data_quantum(uint8_t * data, uint8_t length);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -208,8 +208,11 @@ typedef struct
|
|||||||
|
|
||||||
#ifdef CONSOLE_ENABLE
|
#ifdef CONSOLE_ENABLE
|
||||||
# define CONSOLE_IN_EPNUM (RAW_OUT_EPNUM + 1)
|
# define CONSOLE_IN_EPNUM (RAW_OUT_EPNUM + 1)
|
||||||
//# define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 2)
|
# ifdef CONSOLE_IN_ENABLE
|
||||||
# define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 1)
|
# define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 2)
|
||||||
|
# else
|
||||||
|
# define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 1)
|
||||||
|
# endif
|
||||||
#else
|
#else
|
||||||
# define CONSOLE_OUT_EPNUM RAW_OUT_EPNUM
|
# define CONSOLE_OUT_EPNUM RAW_OUT_EPNUM
|
||||||
#endif
|
#endif
|
||||||
|
@ -264,6 +264,14 @@ static void raw_hid_task(void)
|
|||||||
* Console
|
* Console
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
#ifdef CONSOLE_ENABLE
|
#ifdef CONSOLE_ENABLE
|
||||||
|
|
||||||
|
static bool console_flush = false;
|
||||||
|
#define CONSOLE_FLUSH_SET(b) do { \
|
||||||
|
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {\
|
||||||
|
console_flush = b; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
static void Console_Task(void)
|
static void Console_Task(void)
|
||||||
{
|
{
|
||||||
/* Device must be connected and configured for the task to run */
|
/* Device must be connected and configured for the task to run */
|
||||||
@ -272,49 +280,62 @@ static void Console_Task(void)
|
|||||||
|
|
||||||
uint8_t ep = Endpoint_GetCurrentEndpoint();
|
uint8_t ep = Endpoint_GetCurrentEndpoint();
|
||||||
|
|
||||||
#if 0
|
#ifdef CONSOLE_IN_ENABLE
|
||||||
// TODO: impl receivechar()/recvchar()
|
/* Create a temporary buffer to hold the read in report from the host */
|
||||||
Endpoint_SelectEndpoint(CONSOLE_OUT_EPNUM);
|
uint8_t ConsoleData[CONSOLE_EPSIZE];
|
||||||
|
bool data_read = false;
|
||||||
|
|
||||||
/* Check to see if a packet has been sent from the host */
|
// TODO: impl receivechar()/recvchar()
|
||||||
if (Endpoint_IsOUTReceived())
|
Endpoint_SelectEndpoint(CONSOLE_OUT_EPNUM);
|
||||||
{
|
|
||||||
/* Check to see if the packet contains data */
|
|
||||||
if (Endpoint_IsReadWriteAllowed())
|
|
||||||
{
|
|
||||||
/* Create a temporary buffer to hold the read in report from the host */
|
|
||||||
uint8_t ConsoleData[CONSOLE_EPSIZE];
|
|
||||||
|
|
||||||
/* Read Console Report Data */
|
/* Check to see if a packet has been sent from the host */
|
||||||
Endpoint_Read_Stream_LE(&ConsoleData, sizeof(ConsoleData), NULL);
|
if (Endpoint_IsOUTReceived())
|
||||||
|
{
|
||||||
|
/* Check to see if the packet contains data */
|
||||||
|
if (Endpoint_IsReadWriteAllowed())
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Read Console Report Data */
|
||||||
|
Endpoint_Read_Stream_LE(&ConsoleData, sizeof(ConsoleData), NULL);
|
||||||
|
data_read = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Finalize the stream transfer to send the last packet */
|
||||||
|
Endpoint_ClearOUT();
|
||||||
|
|
||||||
|
if (data_read) {
|
||||||
/* Process Console Report Data */
|
/* Process Console Report Data */
|
||||||
//ProcessConsoleHIDReport(ConsoleData);
|
process_console_data_quantum(ConsoleData, sizeof(ConsoleData));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Finalize the stream transfer to send the last packet */
|
}
|
||||||
Endpoint_ClearOUT();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* IN packet */
|
#endif
|
||||||
Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM);
|
|
||||||
if (!Endpoint_IsEnabled() || !Endpoint_IsConfigured()) {
|
|
||||||
Endpoint_SelectEndpoint(ep);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// fill empty bank
|
if (console_flush) {
|
||||||
while (Endpoint_IsReadWriteAllowed())
|
/* IN packet */
|
||||||
Endpoint_Write_8(0);
|
Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM);
|
||||||
|
if (!Endpoint_IsEnabled() || !Endpoint_IsConfigured()) {
|
||||||
|
Endpoint_SelectEndpoint(ep);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// flash senchar packet
|
// fill empty bank
|
||||||
if (Endpoint_IsINReady()) {
|
while (Endpoint_IsReadWriteAllowed())
|
||||||
Endpoint_ClearIN();
|
Endpoint_Write_8(0);
|
||||||
|
|
||||||
|
// flash senchar packet
|
||||||
|
if (Endpoint_IsINReady()) {
|
||||||
|
Endpoint_ClearIN();
|
||||||
|
}
|
||||||
|
// CONSOLE_FLUSH_SET(false);
|
||||||
|
console_flush = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Endpoint_SelectEndpoint(ep);
|
Endpoint_SelectEndpoint(ep);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -380,13 +401,8 @@ void EVENT_USB_Device_WakeUp()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef CONSOLE_ENABLE
|
// #ifdef CONSOLE_ENABLE
|
||||||
static bool console_flush = false;
|
#if 0
|
||||||
#define CONSOLE_FLUSH_SET(b) do { \
|
|
||||||
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {\
|
|
||||||
console_flush = b; \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
// called every 1ms
|
// called every 1ms
|
||||||
void EVENT_USB_Device_StartOfFrame(void)
|
void EVENT_USB_Device_StartOfFrame(void)
|
||||||
@ -395,9 +411,9 @@ void EVENT_USB_Device_StartOfFrame(void)
|
|||||||
if (++count % 50) return;
|
if (++count % 50) return;
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
if (!console_flush) return;
|
//if (!console_flush) return;
|
||||||
Console_Task();
|
Console_Task();
|
||||||
console_flush = false;
|
//console_flush = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -440,10 +456,10 @@ void EVENT_USB_Device_ConfigurationChanged(void)
|
|||||||
/* Setup Console HID Report Endpoints */
|
/* Setup Console HID Report Endpoints */
|
||||||
ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
|
ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
|
||||||
CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
|
CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
|
||||||
#if 0
|
#ifdef CONSOLE_IN_ENABLE
|
||||||
ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
|
ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
|
||||||
CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
|
CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NKRO_ENABLE
|
#ifdef NKRO_ENABLE
|
||||||
@ -1101,7 +1117,7 @@ static void setup_usb(void)
|
|||||||
USB_Init();
|
USB_Init();
|
||||||
|
|
||||||
// for Console_Task
|
// for Console_Task
|
||||||
USB_Device_EnableSOFEvents();
|
//USB_Device_EnableSOFEvents();
|
||||||
print_set_sendchar(sendchar);
|
print_set_sendchar(sendchar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1216,6 +1232,10 @@ int main(void)
|
|||||||
raw_hid_task();
|
raw_hid_task();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONSOLE_ENABLE
|
||||||
|
Console_Task();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
|
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
|
||||||
USB_USBTask();
|
USB_USBTask();
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user