ratazana/hidpp20.h
2025-11-10 04:53:37 -03:00

64 lines
1.7 KiB
C++

/**
* Copyright (c) 2025 favewa
* SPDX-License-Identifier: BSD-3-Clause
*/
#pragma once
#include "ratazana.h"
#include <stddef.h>
#include <stdint.h>
constexpr uint16_t HIDPP_VENDOR_LOGITECH = 0x046d;
constexpr uint8_t HIDPP_DEVICE_WIRED = 0xFF;
constexpr uint8_t HIDPP_DEVICE_WIRELESS_1 = 0x01;
constexpr uint8_t HIDPP_REPORT_SHORT = 0x10;
constexpr uint8_t HIDPP_REPORT_LONG = 0x11;
constexpr size_t HIDPP_SHORT_REPORT_SIZE = 7;
constexpr size_t HIDPP_LONG_REPORT_SIZE = 20;
constexpr uint8_t HIDPP_FUNCTION_PING = 0x00;
constexpr uint8_t HIDPP_FUNCTION_ERROR = 0x8F;
constexpr uint8_t HIDPP_SOFTWARE_ID = 0x10;
typedef struct __attribute__((packed)) {
uint8_t report_type;
uint8_t device_idx;
uint8_t feature_id;
uint8_t function_id;
uint8_t params[HIDPP_LONG_REPORT_SIZE - 4];
} hidpp_packet_t;
typedef union {
hidpp_packet_t packet;
uint8_t raw[HIDPP_LONG_REPORT_SIZE];
} hidpp_payload_t;
_Static_assert(sizeof(hidpp_packet_t) == HIDPP_LONG_REPORT_SIZE,
"hid++20 packet size mismatch");
typedef struct {
uint8_t major;
uint8_t minor;
} hidpp_version_t;
bool hidpp_match_logitech_mouse(ratazana_hid_device_t *info);
ratazana_result_t hidpp_detect_protocol(ratazana_device_t *restrict dev,
hidpp_version_t *restrict version);
ratazana_result_t hidpp_write(const ratazana_device_t *restrict dev,
const uint8_t *restrict data, size_t len);
ratazana_result_t hidpp_recv(const ratazana_device_t *restrict dev,
uint8_t *restrict data, size_t len,
int timeout_ms);
ratazana_result_t hidpp_communicate(ratazana_device_t *restrict dev,
const hidpp_payload_t *restrict request,
hidpp_payload_t *restrict response);