New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual device #41

merged 122 commits into from Oct 2, 2017
Jump to file or symbol
Failed to load files and symbols.
+17 −33
Diff settings


Just for now

Viewing a subset of changes. View all

virtualize: cleanup and refactor code

Virtdev example now capable of virtualizing various different hardware
devices by passing the vendor/device as strings as CLI args

Signed-off-by: Harry van Haaren <>
  • Loading branch information...
harryhaaren committed Sep 24, 2017
commit d79b5d1c405eba0114cd5cfadd980fe8792caff3
Copy path View file
@@ -18,7 +18,6 @@ void ctlra_impl_usb_shutdown(struct ctlra_t *ctlra);
* to be "dropped in" to the source, and then automatically register up
* without library code changes */
@@ -29,7 +28,6 @@ CTLRA_DEVICE_DECL(akai_apc);
@@ -46,7 +44,6 @@ static void ctlra_static_setup()
static const struct ctlra_dev_connect_func_t devices[] = {
{0, 0, 0},
{0x17cc, 0x1400, CTLRA_DEVICE_FUNC(ni_kontrol_d2)},
{0x17cc, 0x1210, CTLRA_DEVICE_FUNC(ni_kontrol_z1)},
{0x17cc, 0x1120, CTLRA_DEVICE_FUNC(ni_kontrol_f1)},
{0x17cc, 0x1320, CTLRA_DEVICE_FUNC(ni_kontrol_s2_mk2)},
{0x17cc, 0x1220, CTLRA_DEVICE_FUNC(ni_kontrol_x1_mk2)},
@@ -89,20 +86,6 @@ int ctlra_impl_dev_get_by_vid_pid(struct ctlra_t *ctlra, int32_t vid,
return -1;
/** Get the info struct for a controller by name. Note that the controller
* hardware itself does not have to be present to retrieve this info. The
* expected utilization of this function is to allow virtual controllers be
* created for testing and hardware-less development.
* @returns A valid pointer, or NULL if the device ID does not support info
static struct ctlra_dev_info_t *
ctlra_dev_get_info_by_name(const char *vendor, const char *device)
return 0;
struct ctlra_dev_t *ctlra_dev_connect(struct ctlra_t *ctlra,
ctlra_dev_connect_func connect,
ctlra_event_func event_func,
@@ -148,7 +131,7 @@ ctlra_dev_virtualize(struct ctlra_t *c, const char *vendor,
if(!info) {
CTLRA_WARN(c, "Couldn't find device '%s %s' in %d registered drivers\n",
CTLRA_WARN(c, "Couldn't find device '%s' '%s' in %d registered drivers\n",
vendor, device, i);
return -ENODEV;
@@ -295,7 +278,6 @@ ctlra_dev_match_usb_hid(struct ctlra_dev_id_t *id)
int device = id->usb_hid.device_id;
/* TODO: iter registered static info structs, return if match */
return &CTLRA_DEVICE_INFO_NAME(ni_kontrol_s2_mk2);
//return &CTLRA_DEVICE_INFO_NAME(ni_kontrol_z1);
//return &CTLRA_DEVICE_INFO_NAME(ni_maschine_mikro_mk2);
Copy path View file
@@ -278,13 +278,12 @@ int ctlra_probe(struct ctlra_t *ctlra, ctlra_accept_dev_func accept_func,
/** Add a virtualized device. This function adds a "virtual" device, which
* provides the controls of the physical device by displaying a user
* interface. In order for this function to operate, the device being
* virtualized must provide its info statically via the
* *ctlra_dev_get_info_by_id* API.
* virtualized must provide its info statically in the driver.
* The info provided about the device is used to emulate the device
* itself - the normal accept dev callback will be called in the
* application, with the device descriptor filled out as if it was the
* actual hardware plugged in. This allows total emulate of the hardware.
* actual hardware plugged in. This allows total emulation of the hardware.
int32_t ctlra_dev_virtualize(struct ctlra_t *ctlra, const char *vendor,
const char *device);
Copy path View file
@@ -37,8 +37,8 @@
#include "ni_kontrol_z1.h"
#include "impl.h"
#define NI_VENDOR (0x17cc)
#define NI_KONTROL_Z1 (0x1210)
#define CTLRA_DRIVER_VENDOR (0x17cc)
#define CTLRA_DRIVER_DEVICE (0x1210)
#define USB_HANDLE_IDX (0x0)
#define USB_INTERFACE_ID (0x03)
#define USB_ENDPOINT_READ (0x82)
@@ -380,7 +380,8 @@ ctlra_ni_kontrol_z1_connect(ctlra_event_func event_func,
int err = ctlra_dev_impl_usb_open(&dev->base,
if(err) {
return 0;
@@ -413,8 +414,8 @@ ctlra_ni_kontrol_z1_connect(ctlra_event_func event_func,
struct ctlra_dev_info_t ctlra_ni_kontrol_z1_info = {
.vendor = "Native Instruments",
.device = "Kontrol Z1",
.vendor_id = NI_VENDOR,
.device_id = NI_KONTROL_Z1,
.size_x = 120,
.size_y = 294,
@@ -429,6 +430,4 @@ struct ctlra_dev_info_t ctlra_ni_kontrol_z1_info = {
.get_name = ni_kontrol_z1_control_get_name,
Copy path View file
@@ -129,9 +129,13 @@ int accept_dev_func(const struct ctlra_dev_info_t *info,
int main(int argc, char **argv)
if(argc > 1) {
led = atoi(argv[1]);
led_set = 1;
/* default device to test.. */
char *vendor = "Native Instruments";
char *device = "Kontrol Z1";
if(argc > 2) {
vendor = argv[1];
device = argv[2];
signal(SIGINT, sighndlr);
@@ -141,7 +145,7 @@ int main(int argc, char **argv)
printf("connected devices %d\n", num_devs);
/* add a virtualized device */
ctlra_dev_virtualize(ctlra, "Native Instruments", "Kontrol Z1");
ctlra_dev_virtualize(ctlra, vendor, device);
int i = 0;
while(i < 4 && !done) {
ProTip! Use n and p to navigate between commits in a pull request.