Skip to content

Instantly share code, notes, and snippets.

@giulioz
Created September 4, 2024 15:40
Show Gist options
  • Save giulioz/7c0d43d97477194a3e18bed37e4e992f to your computer and use it in GitHub Desktop.
Save giulioz/7c0d43d97477194a3e18bed37e4e992f to your computer and use it in GitHub Desktop.
Control a Native Instrument Komplete Kontrol A-Series keyboard via raw USB HID commands. Can read the buttons and write to the LCD screen and LEDs.
#include <hidapi.h>
#include <stdio.h>
int main() {
hid_init();
hid_device *handle = hid_open(0x17cc, 0x1750, NULL);
// Disable local controls
unsigned char buf1[3] = {0xa0, 0x03, 0x04};
hid_write(handle, buf1, 3);
// Each byte is a column of 8 pixels (0 = black, 1 = white)
unsigned char screen_content[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff};
for (size_t i = 0; i < 256; i++) {
screen_content[i] = 0xff - i;
}
// Screen high
unsigned char buf2[256 + 9] = {
0xe0, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x02, 0x00,
};
for (size_t i = 0; i < 256; i++)
buf2[i + 9] = screen_content[i];
hid_write(handle, buf2, sizeof(buf2));
// Screen low
unsigned char buf3[256 + 9] = {
0xe0, 0x00, 0x00, 0x02, 0x00, 0x80, 0x00, 0x02, 0x00,
};
for (size_t i = 0; i < 256; i++)
buf3[i + 9] = screen_content[i];
hid_write(handle, buf3, sizeof(buf3));
// LEDs
unsigned char buf4[] = {0x80, 0x7c, 0x7c, 0x7c, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x7c, 0x7e, 0x0, 0x7c, 0x7c};
hid_write(handle, buf4, sizeof(buf4));
// Buttons
while (true) {
unsigned char buf[32];
hid_read(handle, buf, 32);
for (int i = 0; i < 32; i++)
printf("%02x ", buf[i]);
printf("\n");
}
hid_close(handle);
hid_exit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment