From f8a7257b54bca17496140e457cec2eb454067e70 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Fri, 4 Dec 2015 18:27:21 -0800 Subject: [PATCH] Export vendor command interface The vendor command interface allows the user to write a vendor request packet using the known vendor interface. However, it is not intended for regular use, since the existing API is better suited to abstract it away from the user. Rather, the prime goal is for a test harness interface that can be used to debug problems seen during regular library accesses. --- libx52/Makefile.am | 2 +- libx52/configure.ac | 2 +- libx52/src/libx52.h | 14 ++++++++++++++ libx52/src/x52_cli.c | 21 ++++++++++++++++++++- libx52/src/x52_control.c | 2 +- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/libx52/Makefile.am b/libx52/Makefile.am index 1dcb614..7ced535 100644 --- a/libx52/Makefile.am +++ b/libx52/Makefile.am @@ -4,7 +4,7 @@ lib_LTLIBRARIES = libx52.la libx52_la_SOURCES = src/x52_common.h src/x52_commands.h src/libx52.h \ src/x52_control.c src/x52_core.c \ src/x52_date_time.c src/x52_mfd_led.c -libx52_la_LDFLAGS = -version-info 1:0:0 -lusb-1.0 +libx52_la_LDFLAGS = -version-info 2:0:1 -lusb-1.0 pkginclude_HEADERS = src/libx52.h bin_PROGRAMS = x52cli x52test diff --git a/libx52/configure.ac b/libx52/configure.ac index cab3d8d..0cdb7ab 100644 --- a/libx52/configure.ac +++ b/libx52/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([libx52], [1.0.0], [nirenjan@gmail.com]) +AC_INIT([libx52], [1.1.0], [nirenjan@gmail.com]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_PROG_CC diff --git a/libx52/src/libx52.h b/libx52/src/libx52.h index 7a4d149..a5378be 100644 --- a/libx52/src/libx52.h +++ b/libx52/src/libx52.h @@ -295,4 +295,18 @@ int libx52_set_blink(libx52_device *x52, uint8_t state); */ int libx52_update(libx52_device *x52); +/** + * @brief Write a raw vendor control packet + * + * This can be used to debug issues seen on the hardware, however, it is not + * recommended for use by end users, as it can potentially damage the hardware. + * + * @param[in] x52 Pointer to the device + * @param[in] index wIndex in the USB packet + * @param[in] value wValue in the USB packet + * + * @returns 0 on success, -errno on failure + */ +int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value); + #endif /* !defined LIBX52_H */ diff --git a/libx52/src/x52_cli.c b/libx52/src/x52_cli.c index 268bef0..63a06e9 100644 --- a/libx52/src/x52_cli.c +++ b/libx52/src/x52_cli.c @@ -24,6 +24,7 @@ typedef enum { X52_CTL_CMD_SHIFT, X52_CTL_CMD_CLOCK, X52_CTL_CMD_OFFSET, + X52_CTL_CMD_RAW, X52_CTL_CMD_MAX } x52_ctl_command; @@ -160,6 +161,7 @@ DEFINE_MAP(command) = { { "shift", X52_CTL_CMD_SHIFT }, { "clock", X52_CTL_CMD_CLOCK }, { "offset", X52_CTL_CMD_OFFSET }, + { "raw", X52_CTL_CMD_RAW }, { NULL, -1 } }; @@ -231,6 +233,14 @@ static int update_offset(libx52_device *x52, void *args[]) return rc; } +static int write_raw(libx52_device *x52, void *args[]) +{ + uint16_t wIndex = (uint16_t)strtoul(args[0], NULL, 0); + uint16_t wValue = (uint16_t)strtoul(args[1], NULL, 0); + + return libx52_vendor_command(x52, wIndex, wValue); +} + const struct command_handler handlers[X52_CTL_CMD_MAX] = { [X52_CTL_CMD_LED_STATE] = { update_led, @@ -291,6 +301,15 @@ const struct command_handler handlers[X52_CTL_CMD_MAX] = { }, "offset {2 | 3} {12hr | 24hr}" }, + [X52_CTL_CMD_RAW] = { + write_raw, + 2, + { + NULL, + NULL, + }, + "raw " + } }; static int do_help(const struct command_handler *cmd) @@ -304,7 +323,7 @@ static int do_help(const struct command_handler *cmd) printf("\t%s\n", handlers[i].help); } - printf("\n"); + printf("\nWARNING: raw command may damage your device\n\n"); } } diff --git a/libx52/src/x52_control.c b/libx52/src/x52_control.c index 94f4004..d6f0773 100644 --- a/libx52/src/x52_control.c +++ b/libx52/src/x52_control.c @@ -19,7 +19,7 @@ #include "x52_commands.h" #include "x52_common.h" -static int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value) +int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value) { int j; int rc;