Skip to content

Commit

Permalink
real initial release everything working and tested on Atmel U4 chips
Browse files Browse the repository at this point in the history
  • Loading branch information
Alabastard-64 committed Jan 21, 2023
1 parent a6d5417 commit af20361
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 32 deletions.
7 changes: 6 additions & 1 deletion quantum/pointing_device/pointing_device_modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void set_pointing_mode(pointing_mode_t pointing_mode) {
// skip if same
if (!memcmp(&pointing_mode_context.mode, &pointing_mode, sizeof(pointing_mode_t))) return;
memcpy(&pointing_mode_context.mode, &pointing_mode, sizeof(pointing_mode_t));
dprintf("PM status saved!");
dprintf("PM status saved!\n");
// Prevent zero divisor
if (!pointing_mode_context.mode.divisor) {
pointing_mode_context.mode.divisor = POINTING_DEFAULT_DIVISOR;
Expand Down Expand Up @@ -362,6 +362,11 @@ static report_mouse_t process_pointing_mode(pointing_mode_t pointing_mode, repor
switch (pointing_mode.id) {
// drag scroll mode (sets mouse axes to mouse_report h & v with divisor)
case PM_DRAG:
# ifdef MOUSE_WHEEL_HIRES_ENABLE
if (resolution_multiplier & 1 << 0) pointing_mode.y *= MAX(MOUSE_WHEEL_MULTIPLIER/pointing_mode.divisor, 1);
if (resolution_multiplier & 1 << 2) pointing_mode.x *= MAX(MOUSE_WHEEL_MULTIPLIER/pointing_mode.divisor, 1);
if (resolution_multiplier) pointing_mode.divisor = 1;
# endif
mouse_report.h = pointing_device_hv_clamp(pointing_mode.x / (int16_t)pointing_mode.divisor);
mouse_report.v = pointing_device_hv_clamp(pointing_mode.y / (int16_t)pointing_mode.divisor);
pointing_mode.x -= (int16_t)mouse_report.h * (int16_t)pointing_mode.divisor;
Expand Down
42 changes: 42 additions & 0 deletions tmk_core/protocol/chibios/usb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ extern keymap_config_t keymap_config;
uint8_t keyboard_idle __attribute__((aligned(2))) = 0;
uint8_t keyboard_protocol __attribute__((aligned(2))) = 1;
uint8_t keyboard_led_state = 0;
#ifdef MOUSE_WHEEL_HIRES_ENABLE
uint8_t resolution_multiplier = 0;
#endif
volatile uint16_t keyboard_idle_count = 0;
static virtual_timer_t keyboard_idle_timer;

Expand Down Expand Up @@ -606,6 +609,14 @@ static void set_led_transfer_cb(USBDriver *usbp) {
}
}

#ifdef MOUSE_WHEEL_HIRES_ENABLE
static void set_multiplier_cb(USBDriver *usbp) {
if (usbp->setup[6] == 2 && set_report_buf[0] == REPORT_ID_MULTIPLIER) {
resolution_multiplier = set_report_buf[1]
}
}
#endif

/* Callback for SETUP request on the endpoint 0 (control) */
static bool usb_request_hook_cb(USBDriver *usbp) {
const USBDescriptor *dp;
Expand All @@ -632,9 +643,21 @@ static bool usb_request_hook_cb(USBDriver *usbp) {
#endif
#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
case MOUSE_INTERFACE:
# ifndef MOUSE_WHEEL_HIRES_ENABLE
usbSetupTransfer(usbp, (uint8_t *)&mouse_report_sent, sizeof(mouse_report_sent), NULL);
return TRUE;
break;
# else
if (usbp->setup[2] == REPORT_ID_MULTIPLIER) {
usbSetupTransfer(usbp, (uint8_t *)&resolution_multiplier, sizeof(resolution_multiplier), NULL);
return TRUE;
break;
} else {
usbSetupTransfer(usbp, (uint8_t *)&mouse_report_sent, sizeof(mouse_report_sent), NULL);
return TRUE;
break;
}
# endif
#endif
#ifdef SHARED_EP_ENABLE
case SHARED_INTERFACE:
Expand All @@ -652,6 +675,13 @@ static bool usb_request_hook_cb(USBDriver *usbp) {
break;
}
# endif
# ifdef MOUSE_WHEEL_HIRES_ENABLE
if (usbp->setup[2] == REPORT_ID_MULTIPLIER) {
usbSetupTransfer(usbp, (uint8_t *)&resolution_multiplier, sizeof(resolution_multiplier), NULL);
return TRUE;
break;
}
# endif
#endif /* SHARED_EP_ENABLE */
default:
universal_report_blank.report_id = usbp->setup[2];
Expand Down Expand Up @@ -683,9 +713,21 @@ static bool usb_request_hook_cb(USBDriver *usbp) {
#if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
case SHARED_INTERFACE:
#endif
#ifndef MOUSE_WHEEL_HIRES_ENABLE
usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_led_transfer_cb);
return TRUE;
break;
#else
if (usbp->setup[2] == REPORT_ID_MULTIPLIER) {
usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_multiplier_cb);
return TRUE;
break;
} else {
usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_led_transfer_cb);
return TRUE;
break;
}
#endif
}
break;

Expand Down
18 changes: 10 additions & 8 deletions tmk_core/protocol/lufa/lufa.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ extern keymap_config_t keymap_config;

uint8_t keyboard_idle = 0;
/* 0: Boot Protocol, 1: Report Protocol(default) */
uint8_t keyboard_protocol = 1;
static uint8_t keyboard_led_state = 0;

static report_keyboard_t keyboard_report_sent;

uint8_t keyboard_protocol = 1;
static uint8_t keyboard_led_state = 0;
#ifdef MOUSE_WHEEL_HIRES_ENABLE
static uint8_t resolution_multiplier;
uint8_t resolution_multiplier = 0;
#endif

static report_keyboard_t keyboard_report_sent;

/* Host driver */
static uint8_t keyboard_leds(void);
static void send_keyboard(report_keyboard_t *report);
Expand Down Expand Up @@ -269,7 +268,10 @@ void EVENT_USB_Device_Connect(void) {
USB_Disable();
USB_Init();
USB_Device_EnableSOFEvents();
}
}
#ifdef MOUSE_WHEEL_HIRES_ENABLE
resolution_multiplier = 0;
#endif
}

/** \brief Event USB Device Connect
Expand Down Expand Up @@ -462,7 +464,7 @@ void EVENT_USB_Device_ControlRequest(void) {
#endif
# ifdef MOUSE_WHEEL_HIRES_ENABLE
if (USB_ControlRequest.wValue == (0x0300 | REPORT_ID_MULTIPLIER)) {
ReportData = (uint8_t *)&resolution_multiplier;
ReportData = &resolution_multiplier;
ReportSize = sizeof(resolution_multiplier);
}
# endif
Expand Down
3 changes: 2 additions & 1 deletion tmk_core/protocol/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,11 @@ typedef int8_t mouse_hv_report_t;
# ifndef MOUSE_WHEEL_MULTIPLIER
# define MOUSE_WHEEL_MULTIPLIER 120
# endif
extern uint8_t resolution_multiplier;
#endif

typedef struct {
#ifdef MOUSE_SHARED_EP
#if (defined(MOUSE_SHARED_EP) || defined(MOUSE_WHEEL_HIRES_ENABLE))
uint8_t report_id;
#endif
uint8_t buttons;
Expand Down
25 changes: 12 additions & 13 deletions tmk_core/protocol/usb_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = {
HID_RI_REPORT_COUNT(8, 0x01),
HID_RI_REPORT_SIZE(8, 0x03),
HID_RI_OUTPUT(8, HID_IOF_CONSTANT),
HID_RI_END_COLLECTION(0),
HID_RI_END_COLLECTION(0), // Application
#ifndef KEYBOARD_SHARED_EP
};
#endif
Expand All @@ -115,7 +115,7 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
HID_RI_USAGE(8, 0x02), // Mouse
HID_RI_COLLECTION(8, 0x01), // Application
# ifdef MOUSE_SHARED_EP
# if (defined(MOUSE_SHARED_EP) || defined(MOUSE_WHEEL_HIRES_ENABLE))
HID_RI_REPORT_ID(8, REPORT_ID_MOUSE),
# endif
HID_RI_USAGE(8, 0x01), // Pointer
Expand Down Expand Up @@ -166,14 +166,14 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
HID_RI_PHYSICAL_MINIMUM(8, 0x01), // Min 1
HID_RI_PHYSICAL_MAXIMUM(8, MOUSE_WHEEL_MULTIPLIER), // Max 120
HID_RI_FEATURE(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
# ifdef MOUSE_SHARED_EP
HID_RI_REPORT_ID(8, REPORT_ID_MOUSE),
# else
HID_RI_REPORT_ID(8, 0x00), // reset report ID
# endif
# endif // MOUSE_WHEEL_HIRES_ENABLE
// Vertical wheel (1-2 bytes)
HID_RI_USAGE(8, 0x38), // Wheel (V)
# ifdef MOUSE_WHEEL_HIRES_ENABLE
HID_RI_PHYSICAL_MINIMUM(8, 0x00), // Reset Global Value
HID_RI_PHYSICAL_MAXIMUM(8, 0x00),
# endif
# ifdef MOUSE_WHEEL_EXTENDED_REPORT
HID_RI_LOGICAL_MINIMUM(16, -32767),
HID_RI_LOGICAL_MAXIMUM(16, 32767),
Expand All @@ -189,7 +189,6 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
# ifdef MOUSE_WHEEL_HIRES_ENABLE
HID_RI_END_COLLECTION(0), // Logical
# endif

// Horizontal Wheel (1 or 2 bytes)
# ifdef MOUSE_WHEEL_HIRES_ENABLE
HID_RI_COLLECTION(8, 0x02), // Logical collection
Expand All @@ -206,14 +205,14 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
// Padding 4 bits
HID_RI_REPORT_SIZE(8, 0x04),
HID_RI_FEATURE(8, HID_IOF_CONSTANT | HID_IOF_VARIABLE),
# ifdef MOUSE_SHARED_EP
HID_RI_REPORT_ID(8, REPORT_ID_MOUSE),
# else
HID_RI_REPORT_ID(8, 0x00), // reset report ID
# endif
# endif // MOUSE_WHEEL_HIRES_ENABLE
HID_RI_USAGE_PAGE(8, 0x0C), // Consumer
HID_RI_USAGE(16, 0x0238), // AC Pan (Horizontal Wheel)
# ifdef MOUSE_WHEEL_HIRES_ENABLE
HID_RI_PHYSICAL_MINIMUM(8, 0x00), // Reset Global Value
HID_RI_PHYSICAL_MAXIMUM(8, 0x00),
# endif
# ifdef MOUSE_WHEEL_EXTENDED_REPORT
HID_RI_LOGICAL_MINIMUM(16, -32767),
HID_RI_LOGICAL_MAXIMUM(16, 32767),
Expand All @@ -229,8 +228,8 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
# ifdef MOUSE_WHEEL_HIRES_ENABLE
HID_RI_END_COLLECTION(0), // Logical
# endif
HID_RI_END_COLLECTION(0), // Physical
HID_RI_END_COLLECTION(0), // Application
HID_RI_END_COLLECTION(0), // Physical
HID_RI_END_COLLECTION(0), // Application
# ifndef MOUSE_SHARED_EP
};
# endif
Expand Down
18 changes: 9 additions & 9 deletions tmk_core/protocol/vusb/vusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ enum usb_interfaces {

static uint8_t keyboard_led_state = 0;
static uint8_t vusb_idle_rate = 0;

#ifdef MOUSE_WHEEL_HIRES_ENABLE
static uint8_t resolution_multiplier;
uint8_t resolution_multiplier = 0;
#endif

/* Keyboard report send buffer */
Expand All @@ -104,13 +103,6 @@ static uint8_t kbuf_tail = 0;

static report_keyboard_t keyboard_report_sent;

#ifdef MOUSE_WHEEL_HIRES_ENABLE
static report_resolution_multiplier_t resolution_multiplier_report = {
REPORT_ID_MULTIPLIER,
0x00,
};
#endif

#define VUSB_TRANSFER_KEYBOARD_MAX_TRIES 10

/* transfer keyboard report from buffer */
Expand Down Expand Up @@ -546,6 +538,10 @@ const PROGMEM uchar shared_hid_report[] = {
# endif
// Wheel (1-2 bytes)
0x09, 0x38, // Usage (Wheel)
# ifdef MOUSE_WHEEL_HIRES_ENABLE
0x35, 0x00, // Physical Minimum (0)
0x45, 0x00, // Physical Maximum (0) Reset Global Value
# endif
# ifdef MOUSE_WHEEL_EXTENDED_REPORT
0x16, 0x01, 0x80, // Logical Minimum (-32767)
0x26, 0xFF, 0x7F, // Logical Maximum (32767)
Expand Down Expand Up @@ -582,6 +578,10 @@ const PROGMEM uchar shared_hid_report[] = {
# endif
0x05, 0x0C, // Usage Page (Consumer)
0x0A, 0x38, 0x02, // Usage (AC Pan)
# ifdef MOUSE_WHEEL_HIRES_ENABLE
0x35, 0x00, // Physical Minimum (0)
0x45, 0x00, // Physical Maximum (0) Reset Global Value
# endif
# ifdef MOUSE_WHEEL_EXTENDED_REPORT
0x16, 0x01, 0x80, // Logical Minimum (-32767)
0x26, 0xFF, 0x7F, // Logical Maximum (32767)
Expand Down

0 comments on commit af20361

Please sign in to comment.