Skip to content

Lab 4 Tasks

Work in labs/mouse/. The goal is not merely to read three bytes. The goal is to build a parser that can survive command responses, mid-stream starts, and invalid packets without poisoning the rest of the input stream.

Requested Functions

  • int mouse_enable_data_reporting(void)
  • int mouse_disable_data_reporting(void)
  • int mouse_process_byte(uint8_t byte)
  • int mouse_get_packet(mouse_packet_t *packet)

Guided Gaps

Decide how many retries command writes should attempt, validate ACK responses, store packet bytes until all three are available, drop bytes until the synchronization bit identifies byte 0, and convert signed movement into C integers. Keep those decisions visible in the code so that a later final project can use the library without rediscovering the packet format.

IMPORTANT

Do not assume the first byte you receive is packet byte 0. Robust code must resynchronize when a stream starts mid-packet.

Common Mistakes

Common mistakes include forgetting that X and Y have separate sign bits, treating overflow bits as movement, returning a packet before all three bytes arrived, and leaving data reporting enabled after a test. If the cursor in a demo jumps wildly, inspect synchronization and sign extension first.

Next: checks and references.

Course/docs licensed CC BY 4.0. Code licensed MIT.