Commit Graph

140 Commits

Author SHA1 Message Date
Thomas Hindoe Paaboel Andersen
e063aa3d2a hidpp10: Fix LED read/write
With this the LEDs can be read and written on the G9.

The G9 is as far as I know the only hid++1.0 mouse with RGB LED. The
other mice are monochrome.
2017-10-12 08:07:59 +10:00
Thomas Hindoe Paaboel Andersen
43f501907e hidpp10: fix setting resolution on G9
The G9 sends a short report and does not
have separate DPIs for x and y.
2017-10-05 17:20:49 +02:00
Peter Hutterer
7eadd20879 hidpp10: fix a coverity warning about OOB access
Make sure that the index we pass into long_clear_bit is never higher than the
number of bits in the single long we use as array here.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-08-31 09:48:52 +02:00
Peter Hutterer
8cb2d21ff5 Remove unnecessary NULL check before free()
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-08-31 13:03:07 +10:00
Peter Hutterer
340e5b7d86 Switch to a .ini-file based device database
The hwdb was a quick and easy way to add entries for new devices but we need
more and more info about the various types of devices. It's better to move
this to a proper database.

Side-effect: this also gives us an easy way to point to the list of devices
supported and makes checking for e.g. missing svgs easier.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-08-28 17:50:20 +02:00
Peter Hutterer
be624fe943 Move dpi range parsing to a helper function
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-08-28 17:50:20 +02:00
Clément Vuchener
468787601e hidpp: Distinguish 1.0 and 2.0 error codes 2017-08-18 04:26:50 +10:00
Benjamin Tissoires
ced958f135 hidpp10: implement enable/disable profiles
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2017-07-25 11:06:59 +10:00
Benjamin Tissoires
2c799eca30 hidpp10: correctly retrieve the profile directory and use it
We need to read the directory and the profiles only once.
Nothing tells us how many profiles are supported, so use the specifications
from Logitech website, and add a hwdb entry for those.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2017-07-25 11:06:59 +10:00
Peter Hutterer
04990e4ea2 hidpp10: error out if we deal with unsupported profiles
Just logging and error and continuing is not enough, we'll eventually
dereference garbage values.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-11 10:50:22 +02:00
Peter Hutterer
37c8dec45c Fix the various scan-build warnings for dead assignments
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-11 10:50:22 +02:00
Peter Hutterer
e311f89357 Provide a min/max dpi for the resolutions
For a GUI application like Piper, it's required that we know the range to
present to the user.

This patch includes the code for HID++ 1.0 and 2.0, other drivers need to
follow.

https://github.com/libratbag/libratbag/issues/180

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-06-29 09:07:18 +02:00
Benjamin Tissoires
8367569236 hidpp10: fix coverity issue
profile->dpi_modes[i].led[] is an array of boolean.
Given that the callers (hidpp10_fill_dpi_modes_*()) already are doing the
comparison against 0x02, I guess this is just copy/paste error.

Fixes #152

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2017-05-29 10:32:08 +10:00
Peter Hutterer
ad1fa22196 hidpp10: fix out-of-bounds access
sizeof() gives us twice as many elements as we have indices for on this 16-bit
array.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-02 09:52:59 +02:00
Clément Vuchener
67f1c00181 hidpp10: Fix and add some special action codes
I fixed resolution cycle up actually being resultion cycle down and added the missing cycle actions for resolutions and profiles.

Signed-off-by: Clément Vuchener <clement.vuchener@gmail.com>
2017-01-24 07:41:22 +10:00
Stephen Kitt
d1e42ac56c Copy all three bytes from parameters
In hidpp10_get_hidpp_notifications(), we want all three bytes from
parameters[], not parameters[0] twice. This matches
hidpp10_set_hidpp_notifications().

Signed-off-by: Stephen Kitt <skitt@redhat.com>
2017-01-04 07:29:13 +10:00
Peter Hutterer
01876023bb hidpp10: fix fetching of serial number
Was off by one, the message content only includes one byte of extra information
before the serial number. And add a BE 32-bit helper while we're at it.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-07-14 10:17:49 +10:00
Thomas Hindoe Paaboel Andersen
577a7c52fc hidpp10: Fix getting current resolution on G9
On the G9 the response to a 0x63 is a short report. The G9 does
not have individual resolutions for X and Y and thus only needs
to report a single value.

The set version of 0x63 should probably also be updated. However,
while my testing of such a change worked better than with long
reports there are still strange side effects of setting resolution,
like turning off all the LED's. LGS also seems to do a full profile
read/write instead of using 0x63 when changing the resolution.
2016-03-04 00:19:10 +01:00
Thomas Hindoe Paaboel Andersen
70d864af09 hidpp10: write profile for G9 2016-03-01 23:37:54 +01:00
Thomas Hindoe Paaboel Andersen
f0417a9535 hidpp10: Add definition for buttons on the G9 2016-03-01 21:20:18 +01:00
Thomas Hindoe Paaboel Andersen
9d9c42cc6a hidpp10: rename structs wrt _sym vs. _dual
Follow up for review in #56
2016-03-01 21:20:13 +01:00
Thomas Hindoe Paaboel Andersen
14ca639270 hidpp10: Parse G9 profile
This allows to read but not write profiles from the G9.

The dpi mode sturct is a little different as the mouse only supports
symetrical dpi for x/y. Given the current naming a suffix of _sym
was the best I could come up with.

The G9 profile has some additional unknown bytes compared to the
others. Unfortunately the content of them varies for the 4 first
profiles and the last. So adding a default value for the like with
the G700 is not possible. For this reason I dropped implementing
the write part for now.

Something else to address is that this mouse only has 10 buttons
compared to the usual 13 that we have in PROFILE_NUM_BUTTONS. For
now I just hardcoded it in the profile and hidpp10_get_profile.
2016-01-07 22:30:23 +01:00
Benjamin Tissoires
f05aafc786 hidpp10: do not overwrite macros when writing a profile
Previously, we would put a random address in the macro value, meaning we
lose the content of the macros.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-12-18 13:19:37 +01:00
Benjamin Tissoires
06d0c03ea1 hidpp10: parse macros
Macros are somewhat properly parsed in hidpp10.
The driver, however, supports only key press/release and delays.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-12-17 13:19:19 +01:00
Benjamin Tissoires
4673b62eb4 hidpp10: enable metadata parsing on G500(s) too
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-12-14 17:28:21 +01:00
Benjamin Tissoires
8f18357e47 hidpp10: properly parse metadata in profiles
unknown3 in G700 is the constant string "LGS02". This string is a marker
for LGS to specify that the rest of the data is the names of the profiles
and macros.

SetPoint doesn't set those, so they are considered as metadata.

In libratbag, we will parse those properly and always set them, no matter
if the user used SetPoint or not.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-12-14 17:26:07 +01:00
Benjamin Tissoires
b3834f48c8 hidpp10: do not reject profiles with invalid CRC
The mouse accept them, so they are not invalid.

Only the profile directory seems to be checking for the CRC.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-12-14 16:52:55 +01:00
Benjamin Tissoires
eb6e312bf3 hidpp10: implement full write of profiles
The complexity when writing the profile to ROM at first allows:
- to prevent the user to temper with a non full profile
- in case of a USB failure (disconnect or loss of power for the batteries)
  we don't use partially overwrite the profile.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-12-14 11:52:22 +01:00
Benjamin Tissoires
390a82bce9 hidpp10: fill in the profile and fake its writing
To not have a giant patch that writes profiles to the HID++1.0 mice,
this first patch only convert the user profile into the actual data
that needs to be sent to the mouse.
We use hidpp_error to output it but no end user will ever see that
because it will be removed in a later commit.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-12-14 11:52:22 +01:00
Benjamin Tissoires
fe8c850fe4 hidpp10: implement set current profile
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-12-14 11:52:22 +01:00
Benjamin Tissoires
bc1a940c82 hidpp10: store the names of the profiles and the names of the macros
Currently only in G700(s), as we don't know the mappings for the
other mice.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-12-11 17:06:20 +01:00
Benjamin Tissoires
76376b3b8f hidpp10: use uint16_t directly in _hidpp10_button_binding
much easier to deal with, especially when we need to write them back.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-12-11 16:07:15 +01:00
Benjamin Tissoires
c8c6fc6f1d hidpp10: fix valgrind complaint in get_profile
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-12-11 16:05:21 +01:00
Benjamin Tissoires
ab471f98f5 hidpp10: add missing line ending in log_error
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-12-11 16:05:21 +01:00
Benjamin Tissoires
3889d129fd hidpp10 add 2 more special usages
The G500 uses only one bit in the usage code (thus the holes in the table).
So for the G500, RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_CYCLE_UP is
the same as RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_DOWN for instance.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-11-27 22:37:49 +01:00
Benjamin Tissoires
cb4c34337a hidpp10: implement parsing of special keys
Create new RATBAG_BUTTON_ACTION_SPECIAL_BATTERY_LEVEL.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-11-26 17:57:00 +01:00
Benjamin Tissoires
fb2e543fb0 hidpp10: add support for Logitech G700
G700s should be the same

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-11-26 17:57:00 +01:00
Benjamin Tissoires
9db8d2875d hidpp10: read the profiles only once
Store them in a table in hidpp10_device.
When the dpi list is filled in, we need to invalidate
the profiles.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-11-26 17:56:31 +01:00
Benjamin Tissoires
0fa4d3d984 hidpp10: factor out hidpp10_fill_dpi_modes() and hidpp10_fill_buttons()
Preparation patch to add support for more than one profile type.

No functional changes

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-11-26 17:43:34 +01:00
Benjamin Tissoires
41d6bba4cd hidpp10: add mandatory udev prop RATBAG_HIDPP10_PROFILE
Allows to specify a type of profile and speed up the discovery of
hidpp10 devices when they are not actual gaming with a known profile.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-11-26 17:43:34 +01:00
Benjamin Tissoires
097add3df3 hidpp10: validate crc when reading profiles
if the crc is not valid, the device rejects the page and we should
not rely on it.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-11-26 17:43:34 +01:00
Benjamin Tissoires
6a9980b707 hidpp10: store the profile directory once for all
This is an expensive operation, so better store it in hidpp10_device

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-11-26 17:43:34 +01:00
Benjamin Tissoires
0ab1c5c234 hidpp10: check crc when reading a page
If the crc is wrong, the device will ignore the page.
This technically multiply by 6 the time to access the device, but this is
because we do not cache anything currently in hidpp10.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-11-26 17:43:34 +01:00
Peter Hutterer
ff44609bef hidpp10: use the directory profile count to get the device info
The G700 has 5 available profiles, bump HIDPP10_NUM_PROFILES.

On the other hand, hidpp10_get_device_info() doesn't fill anything...

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-11-26 17:43:34 +01:00
Benjamin Tissoires
8d65710846 hidpp10: implement profile directory
The command get_profile can either return an index in the directory (in
the page 0x01 of the memory) or an absolute address. If the address is
returned, it is unclear whether the directory is updated.

This commit also includes changes from Peter:
hidpp10: if the profile index exceeds the number of directory index, use 0
hidpp10: factor out directory fetching
hidpp10: use the profile directory only in hidpp10_get_profile

Fixes #26

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-11-26 17:42:26 +01:00
Benjamin Tissoires
3e8bf85c04 hidpp10: build a table of available dpi settings
Each hidpp10 device should have a udev property named either
RATBAG_HIDPP10_DPI or RATBAG_HIDPP10_DPI_LIST. These properties ensure
that we know the mapping between the raw value of the dpi reported by the
mouse and the actual value.

Older devices (using the scheme 1 or 2 of hidpp10_get_current_resolution)
have to use the DPI_LIST to be able to map 0x80+.
Newer devices (using scheme 3) use the DPI setting with min, max, step.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-11-25 11:21:51 +01:00
Benjamin Tissoires
c478b7a7d2 hidpp10: use generic BE/LE access
No functional changes.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-11-06 18:48:50 +01:00
Peter Hutterer
bdcc194e41 hidpp10: implement get_extended_pairing_info for the serial number
This request has more information, for now we just fetch the serial number

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-23 09:49:43 -04:00
Peter Hutterer
3eb331da50 hidpp10: fix truncated device name
The hidpp10 name length does not include the terminating zero.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-10-23 14:05:07 +10:00
Peter Hutterer
a5ee32eac8 hidpp10: add hidpp10_close_lock
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-10-23 14:04:59 +10:00