Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions tmk_core/protocol/ps2_busywait.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ uint8_t ps2_host_send(uint8_t data)
bool parity = true;
ps2_error = PS2_ERR_NONE;

// see http://www.burtonsys.com/ps2_chapweske.htm but note that
// sending host->device samples on the rising not falling CLK edge

/* terminate a transmission if we have */
inhibit();
wait_us(100); // 100us [4]p.13, [5]p.50
Expand All @@ -84,25 +87,23 @@ uint8_t ps2_host_send(uint8_t data)

/* Data bit */
for (uint8_t i = 0; i < 8; i++) {
wait_us(15);
if (data&(1<<i)) {
parity = !parity;
data_hi();
} else {
data_lo();
}
WAIT(clock_hi, 50, 2);
// keyboard sampled the data, just before here, just as the clock goes high
WAIT(clock_lo, 50, 3);
}

/* Parity bit */
wait_us(15);
if (parity) { data_hi(); } else { data_lo(); }
WAIT(clock_hi, 50, 4);
WAIT(clock_lo, 50, 5);

/* Stop bit */
wait_us(15);
data_hi();

/* Ack */
Expand Down
7 changes: 4 additions & 3 deletions tmk_core/protocol/ps2_interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ uint8_t ps2_host_send(uint8_t data)
bool parity = true;
ps2_error = PS2_ERR_NONE;

// see http://www.burtonsys.com/ps2_chapweske.htm but note that
// sending host->device samples on the rising not falling CLK edge

PS2_INT_OFF();

/* terminate a transmission if we have */
Expand All @@ -85,25 +88,23 @@ uint8_t ps2_host_send(uint8_t data)

/* Data bit[2-9] */
for (uint8_t i = 0; i < 8; i++) {
_delay_us(15);
if (data&(1<<i)) {
parity = !parity;
data_hi();
} else {
data_lo();
}
WAIT(clock_hi, 50, 2);
// keyboard sampled the data, just before here, just as the clock goes high
WAIT(clock_lo, 50, 3);
}

/* Parity bit */
_delay_us(15);
if (parity) { data_hi(); } else { data_lo(); }
WAIT(clock_hi, 50, 4);
WAIT(clock_lo, 50, 5);

/* Stop bit */
_delay_us(15);
data_hi();

/* Ack */
Expand Down
7 changes: 4 additions & 3 deletions tmk_core/protocol/ps2_usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ uint8_t ps2_host_send(uint8_t data)
bool parity = true;
ps2_error = PS2_ERR_NONE;

// see http://www.burtonsys.com/ps2_chapweske.htm but note that
// sending host->device samples on the rising not falling CLK edge

PS2_USART_OFF();

/* terminate a transmission if we have */
Expand All @@ -91,25 +94,23 @@ uint8_t ps2_host_send(uint8_t data)

/* Data bit[2-9] */
for (uint8_t i = 0; i < 8; i++) {
_delay_us(15);
if (data&(1<<i)) {
parity = !parity;
data_hi();
} else {
data_lo();
}
WAIT(clock_hi, 50, 2);
// keyboard sampled the data, just before here, just as the clock goes high
WAIT(clock_lo, 50, 3);
}

/* Parity bit */
_delay_us(15);
if (parity) { data_hi(); } else { data_lo(); }
WAIT(clock_hi, 50, 4);
WAIT(clock_lo, 50, 5);

/* Stop bit */
_delay_us(15);
data_hi();

/* Ack */
Expand Down