Commit Graph

68 Commits

Author SHA1 Message Date
Benjamin Tissoires
0068ef2b06 hidpp20: use a struct definition for onboard profiles
Removes the magic constants here and there, though the description
of the struct is not very nice and clean.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-11-06 18:57:26 +01:00
Benjamin Tissoires
2a2d9e0f67 hidpp20: add a generic write_page function
Looks like the crc needs to be passed anyway, so have a common helper to
set the crc and write the whole page.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-11-06 18:57:25 +01:00
Benjamin Tissoires
9714ba53f5 hidpp20: update the dictionary when writing the profiles
If the device has never been configured under Windows, the dictionary
of the profiles might be blank. When it is blank, any changes made to
the profiles are ignored by the mouse.
Update a new dictionary if the profile was previously not enabled.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-11-06 18:57:18 +01:00
Benjamin Tissoires
8782c5117f hidpp20: the profile also contains a name
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-11-06 18:50:51 +01:00
Benjamin Tissoires
72d74da27c hidpp20: read the profile in ROM if the profile in flash is not valid
This happens after unboxing the mouse or if there is a wrong crc in
the profiles.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-11-06 18:50:48 +01:00
Benjamin Tissoires
ee2bd0475f hidpp20: move the crc function up
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-11-06 18:48:50 +01:00
Benjamin Tissoires
071a507d44 hidpp20: replace manual BE feeding by the helpers
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-11-06 18:48:50 +01:00
Benjamin Tissoires
5c97492f44 hidpp20: fix LE/BE declarations, and move them to hidpp-generic.h
hidpp20_get_unaligned_be_u16 was LE, not BE.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-11-06 18:48:48 +01:00
Benjamin Tissoires
3753bd3216 hidpp20drv: implement write_button for devices with profiles
Still missing the consumer control HID keys, but the rest works (minus
the modifier keys).

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-22 15:14:03 -04:00
Benjamin Tissoires
ba26f6f35c hidpp20: implement the write functionality of the profiles
Not completely full features, but works to set the DPI, report rate and
buttons assignments (no macros yet).

The current code reads first the current values, changes that needs to be
changed and writes back the data. Long term, we want to build the data
directly from the profiles and just write them.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-22 15:14:03 -04:00
Benjamin Tissoires
2d020e840a hidpp20: fix the profile size
the profile contains 16 pages of 16 bytes, not only 15

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-22 15:14:03 -04:00
Benjamin Tissoires
88083511db hidpp20: remove unused parameter
profiles_list is not used anymore in hidpp20_onboard_profiles_get_current_profile
let's remove it.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-21 16:01:13 -04:00
Benjamin Tissoires
21d22bf74e hidpp20: change hidpp20_onboard_profiles_read_memory API
It looks like we can not use a section > 0xff and that the first
parameter corresponds to the type of the available memory (rom or flash).

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-20 17:32:56 -04:00
Benjamin Tissoires
d3abebf202 hidpp20: change hidpp20_onboard_profiles_read_memory API
It looks like we can not use a section > 0xff and that the first
parameter corresponds to the type of the available memory (rom or flash).

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-20 17:31:46 -04:00
Benjamin Tissoires
3294c5c048 hidpp20: parse the special keys in the profiles
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-20 17:28:47 -04:00
Benjamin Tissoires
26fdafb881 hidpp20: parse the buttons mapping in the profiles
Only export the actual buttons in ratbag_button for now.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-20 17:25:59 -04:00
Benjamin Tissoires
24f7319a6f hidpp20: read the button count from the mouse
When using onboard profiles, it looks like we have the button count.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-20 17:24:03 -04:00
Benjamin Tissoires
7c1718d316 hidpp20: first parsing of feature 0x8100 - onboard profiles
Obtained by rev-engineering the protocol.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-20 17:24:02 -04:00
Benjamin Tissoires
4991118bcd hidpp20: simplify internal hidpp20_feature_set_get API
We do not export it anymore and we plan to use it only in
hidpp20_device_new().

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-20 16:59:48 -04:00
Benjamin Tissoires
dcf0a0e89d hidpp20: use the internal list of features instead of asking the device
We already know the indexes in the table, so there is no point in making
a round trip to the device.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-20 16:49:17 -04:00
Benjamin Tissoires
2ff7bff6df hidpp20: remove uninitialized variable use
get_mousepointer_info does not take any parameters.
Remove the warning.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-20 16:49:17 -04:00
Benjamin Tissoires
6ac92f8479 hidpp20: retrieve and store the list of features once for all
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-20 16:49:13 -04:00
Benjamin Tissoires
8ffa2f9b96 hidpp20: retrieve the protocol version in hidpp20.c
We need hidpp20 to handle the list of available features. So we need to be
sure in hidpp20 that we are talking to a hidpp20 device.

Move the version retrieval in hidpp20 where it makes sense.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-20 16:19:02 -04:00
Benjamin Tissoires
65888eedd4 hidpp20: add new struct hidpp20_device
This struct will be used to store the table features/index and probably
others. It also allows a single entry point to set the device index.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-20 16:18:56 -04:00
Benjamin Tissoires
3b3b9ce0a2 hidpp20: switch hidpp20 to use the non-libratbag dependencies too
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-16 16:43:46 -04:00
Peter Hutterer
5b8f3c4744 Add snprintf_safe() and sprintf_safe helpers
Blows up when sprintf encounters an error, the result string is empty or the
result string is truncated.

Note: sprintf_safe only works on static buffers, it uses ARRAY_LENGTH.

Fixes #14

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-10-13 07:01:09 +10:00
Benjamin Tissoires
d9645c0e4b hidpp20: document the names of the features in gaming mice
This patch adds nothing but some debug outputs and prepares the code
to support the recent gaming mice from Logitech.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-11 10:28:37 -04:00
Benjamin Tissoires
4abdb634cf hidpp20: add a define to document feature 0x0003
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-11 10:25:16 -04:00
Benjamin Tissoires
f4777e7b71 hidpp20: fix adjustable DPI for older mice
The G502 uses the version 0 of the adjustable DPI feature. This version
does not echo the given parameters which raised a -EIO in libratbag.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-11 10:24:45 -04:00
Benjamin Tissoires
0f1b11a874 debug: put the raw debug logs in hidraw, not in per-driver handlers
Might not be the best solution for hidpp10, because it just removes the
duplicates, but this way all of the other drivers can benefit from the
raw debug parameter.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-09-18 10:56:58 -04:00
Thomas Hindoe Paaboel Andersen
ab7b620dd4 hidpp10/20: fix a buffer overflow
We pass a negative length into log_buffer which expects a size_t.
This causes it to write past the allocated output_buf.
2015-09-15 20:24:56 +02:00
Thomas Hindoe Paaboel Andersen
6155d86923 hidpp10/20: retry on usb timeout
On the M705 I frequently get usb timeouts here if the device has
not been active for a while. Retrying after 10 ms seems to reliably
fix the timeout problem.

We could have just added the 10 ms sleep directly but it does not
seem to be neccesary on wired devices so I chose not to. Setting the
ret value to a face positive number and looping would also work but
we risk an endless loop. In the end I just went for a single retry
as that fixed the problem for me.
2015-09-15 20:24:56 +02:00
Benjamin Tissoires
1cbbcae37c Add the G303 as a known device
The G303 is a wired device and we need to talk to it with 0xff (OK a
#define would be good). This was not a problem for all of the unifying
devices given that the kernel overwrites the device_id for us, but the
corded devices are a different kind, and this one rejects device id != ff.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-09-11 17:43:35 -04:00
Peter Hutterer
6c3a8aa90e Abort if zalloc fails
Let's not pretend we will handle out-of-memory errors correctly, and really,
it's not something we really need to be worried about.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-03 12:52:50 +10:00
Thomas Hindoe Paaboel Andersen
5f2d538e10 Avoid overflow when reading dpi list
LONG_MESSAGE_LENGTH is the length of the full message so we should
take the first parts of the union into account.
2015-09-02 21:59:06 +02:00
Peter Hutterer
5cb15524d4 hidpp: move the button lookup tables to the generic code
No functional changes

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-01 10:55:19 +10:00
Peter Hutterer
63e0ddc550 Add a LOG_LEVEL_RAW log level
Lower than debug, for spitting out all the protocol codes

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-08-28 15:08:51 +10:00
Benjamin Tissoires
6bc44f4d5f Factor out ratbag_button_action_match
This will be used often in drivers, so let's have a helper for it.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-08-26 16:55:29 -04:00
Benjamin Tissoires
08a568aed2 hidpp20: fix after button type revamp
the logical and physical bits were inverted:
- logical is the action of the button
- physical corresponds to the actual button on the mouse (so the 'type')
- there is a duplicate from driver-etekcity to match 2 actions, this should
  be factorized in a helper somewhere in a later commit

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-08-26 16:48:03 -04:00
Benjamin Tissoires
c28edd2411 Add the ratchet mode switch button type and action type
Found on the Logitech MX Master. Most of other Logitech device with
physical ratchet disable capability do not show this button to the host
however.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-08-26 11:01:25 -04:00
Peter Hutterer
7db22756b7 Revamp button action handling
One giant commit, but I didn't know how to split this up easier. The problem
is a misunderstanding in what the button type is and the code that built on
that misunderstanding, requiring a lot of interdependent parts to be updated
at once.

The button _type_ is the physical description of the button.
The button _action type_ is what will happen when you hit the buttons.

The type is read-only, since we're not dealing with mr potato head here.
The action is adjustible and we now support buttons, keys and special
in-hardware actions (e.g. dpi changes). A few FIXMEs still in place, e.g. we
don't handle modifiers with keys.

For buttons we just take numerical button numbers. i.e. we can map a button to
button 4, which will result in BTN_SIDE, and eventually logical button 8 in X.
For keys we take KEY_FOO, since eventually we want this to come out as that
(could do this for button as well I guess). Modifiers are currently ignored.
For special actions we have a enum of actions we support.

The button type enum is thus reduced a lot, and everything needs to be
switched.

This breaks ratbag-command change-button, will be fixed later since it's
misdesigned as it is anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-08-26 16:46:01 +10:00
Benjamin Tissoires
57cb37fa62 hidpp20: found 2 physical descriptions from the m325
These 2 buttons are on each side of the wheel. They send back/forward by
default.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-08-25 11:38:21 -04:00
Peter Hutterer
bbc4af6419 hidpp20: add support for 0x1b00 reprogrammable keys
As seen on the T650.

Reusing most of 0x1b04 here, except this one only gives us control id, task id
and flags.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-08-22 18:04:02 +10:00
Peter Hutterer
5e61dc4800 hidpp20: add control/task ID mappings from 0x1b00
Let's hope that the range is the same here and 0x1b04 doesn't redefine some of
them.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-08-22 17:42:29 +10:00
Benjamin Tissoires
88154c2438 hidpp20drv: implement button remapping
Problem: when a button is diverted, it stops sending its original button,
which is good, but then reports only on the HID++ long report collection.

That is a little bit embarrassing.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-08-21 15:50:01 -04:00
Benjamin Tissoires
bc05440477 hidpp20: do not shout one more time the recieved data
well, there is no fine grain while outputing the raw events, so that
means that we have always shown the actual answer just before.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-08-21 15:24:33 -04:00
Benjamin Tissoires
7fb5c2f81d hidpp20: handle new errors reporting
Looks like HID++2.0 devices report errors with 0xff also.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-08-21 15:24:33 -04:00
Benjamin Tissoires
8b0221554e hidpp20: invert logical/physical in function 1b04
I misread the documentation. The task_id corresponds to what the button
has been physically designed to, and the control_id is the logical
remapping.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-08-21 15:24:33 -04:00
Benjamin Tissoires
0eb6bd3948 hidpp: fill the ratbag_button info
We still need to differentiate logical from physical in button types.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-08-21 15:23:14 -04:00
Benjamin Tissoires
d6186c0c5a hidpp20: re-order the features by numeric order
no functional changes, just moving code.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-08-21 13:44:36 -04:00