Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
joh committed Dec 13, 2023
1 parent d918bb3 commit 30e6986
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions drivers/ps2/ps2_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "pointing_device.h"
#include "pointing_device_internal.h"

/* ============================= MACROS ============================ */
/* ============================= HELPERS ============================ */

static inline void ps2_mouse_convert_report_to_hid(ps2_mouse_report_t *ps2_report, report_mouse_t *mouse_report);
static inline void ps2_mouse_enable_scrolling(void);
Expand Down Expand Up @@ -149,6 +149,42 @@ void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate) {
PS2_MOUSE_SET_SAFE(PS2_MOUSE_SET_SAMPLE_RATE, sample_rate, "ps2 mouse set sample rate");
}

/* Note: PS/2 mouse uses counts/mm */
uint16_t ps2_mouse_get_cpi(void) {
uint8_t rcv, cpm;
rcv = ps2_host_send(PS2_MOUSE_STATUS_REQUEST);
if (rcv == PS2_ACK) {
rcv = ps2_host_recv_response();
cpm = ps2_host_recv_response();
rcv = ps2_host_recv_response();

return (1 << cpm);
}

return 0;
}

/* Note: PS/2 mouse uses counts/mm */
void ps2_mouse_set_cpi(uint16_t cpi) {
switch (cpi) {
case 1:
ps2_mouse_set_resolution(PS2_MOUSE_1_COUNT_MM);
break;
case 2:
ps2_mouse_set_resolution(PS2_MOUSE_2_COUNT_MM);
break;
case 4:
ps2_mouse_set_resolution(PS2_MOUSE_4_COUNT_MM);
break;
case 8:
ps2_mouse_set_resolution(PS2_MOUSE_8_COUNT_MM);
break;
default:
pd_dprintf("ps2_mouse: invalid cpi: %u\n", cpi);
break;
}
}

/* ============================= HELPERS ============================ */

#define min(a,b) ((a)<(b)?(a):(b))
Expand Down Expand Up @@ -178,6 +214,7 @@ static inline void ps2_mouse_convert_report_to_hid(ps2_mouse_report_t *ps2_repor
mouse_report->y = -mouse_report->y;

#ifdef PS2_MOUSE_ENABLE_SCROLLING
// Valid z values are in the range -8 to +7
mouse_report->v = -(ps2_report->z & PS2_MOUSE_SCROLL_MASK);
mouse_report->v *= PS2_MOUSE_V_MULTIPLIER;
#endif
Expand Down Expand Up @@ -210,38 +247,3 @@ static inline void ps2_mouse_enable_scrolling(void) {
wait_ms(20);
}

/* Note: PS/2 mouse uses counts/mm */
uint16_t ps2_mouse_get_cpi(void) {
uint8_t rcv, cpm;
rcv = ps2_host_send(PS2_MOUSE_STATUS_REQUEST);
if (rcv == PS2_ACK) {
rcv = ps2_host_recv_response();
cpm = ps2_host_recv_response();
rcv = ps2_host_recv_response();

return (1 << cpm);
}

return 0;
}

/* Note: PS/2 mouse uses counts/mm */
void ps2_mouse_set_cpi(uint16_t cpi) {
switch (cpi) {
case 1:
ps2_mouse_set_resolution(PS2_MOUSE_1_COUNT_MM);
break;
case 2:
ps2_mouse_set_resolution(PS2_MOUSE_2_COUNT_MM);
break;
case 4:
ps2_mouse_set_resolution(PS2_MOUSE_4_COUNT_MM);
break;
case 8:
ps2_mouse_set_resolution(PS2_MOUSE_8_COUNT_MM);
break;
default:
pd_dprintf("ps2_mouse: invalid cpi: %u\n", cpi);
break;
}
}

0 comments on commit 30e6986

Please sign in to comment.