Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PS/2 mouse performance #17111

Merged
merged 2 commits into from
May 31, 2022
Merged

Improve PS/2 mouse performance #17111

merged 2 commits into from
May 31, 2022

Conversation

and3rson
Copy link
Contributor

@and3rson and3rson commented May 16, 2022

Source PR: #5408

Credits to @tomykaira for doing the actual work!

Description

This PR improves performance of PS/2 mouse in both interrupt mode and USART mode. On my keyboard, it reduces matrix scan delay from 11ms to 1ms. This makes it possible to use encoder AND trackpoint at the same time without any lags!

Additional changes introduced are:

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Test case

Wiring & trackpoint images (source: https://github.com/joric/jorne/wiki/Trackpoint)

Wiring

R61 Trackpoint

Config (tested with both INT & USARG modes)

#define PS2_MOUSE_INIT_DELAY 200

#ifdef PS2_USE_USART
#define PS2_CLOCK_PIN   D5
#define PS2_DATA_PIN    D2

/* #define PS2_MOUSE_USE_REMOTE_MODE */

/* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */
/* set DDR of CLOCK as input to be slave */
#define PS2_USART_INIT() do {   \
    PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);   \
    PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);     \
    UCSR1C = ((1 << UMSEL10) |  \
              (3 << UPM10)   |  \
              (0 << USBS1)   |  \
              (3 << UCSZ10)  |  \
              (0 << UCPOL1));   \
    UCSR1A = 0;                 \
    UBRR1H = 0;                 \
    UBRR1L = 0;                 \
} while (0)
#define PS2_USART_RX_INT_ON() do {  \
    UCSR1B = ((1 << RXCIE1) |       \
              (1 << RXEN1));        \
} while (0)
#define PS2_USART_RX_POLL_ON() do { \
    UCSR1B = (1 << RXEN1);          \
} while (0)
#define PS2_USART_OFF() do {    \
    UCSR1C = 0;                 \
    UCSR1B &= ~((1 << RXEN1) |  \
                (1 << TXEN1));  \
} while (0)
#define PS2_USART_RX_READY      (UCSR1A & (1<<RXC1))
#define PS2_USART_RX_DATA       UDR1
#define PS2_USART_ERROR         (UCSR1A & ((1<<FE1) | (1<<DOR1) | (1<<UPE1)))
#define PS2_USART_RX_VECT       USART1_RX_vect
#endif

#ifdef PS2_USE_INT
// Note: pins are swapped, so re-soldering is needed to test both modes
#define PS2_CLOCK_PIN   D2
#define PS2_DATA_PIN    D5

/* #define PS2_MOUSE_USE_REMOTE_MODE */

#define PS2_INT_INIT()  do {    \
    EICRA |= ((1<<ISC21) |      \
              (0<<ISC20));      \
} while (0)
#define PS2_INT_ON()  do {      \
    EIMSK |= (1<<INT2);         \
} while (0)
#define PS2_INT_OFF() do {      \
    EIMSK &= ~(1<<INT2);        \
} while (0)
#define PS2_INT_VECT   INT2_vect
#endif
#endif

Demo of me using trackpoint & encoder simultaneously: https://imgur.com/a/cqL8j1x

@github-actions github-actions bot added the core label May 16, 2022
@zvecr zvecr changed the base branch from master to develop May 16, 2022 11:44
@drashna drashna requested a review from a team May 17, 2022 04:00
@zvecr zvecr changed the title Avoid READ command in stream mode (v2) Improve PS/2 mouse performance May 17, 2022
@drashna drashna merged commit ecce990 into qmk:develop May 31, 2022
0xcharly pushed a commit to Bastardkb/bastardkb-qmk that referenced this pull request Jul 4, 2022
@drashna drashna mentioned this pull request Aug 27, 2022
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants