#include <inttypes.h>
Go to the source code of this file.
Functions | |
void | ps2_init () |
Init PS/2 related I/O and interrupts. | |
uint8_t | ps2_avail () |
Check if the input buffer contains at least one byte. | |
uint8_t | ps2_getbyte () |
Get one byte from input buffer. ps_avail() must be checked before doing so. | |
void | ps2_sendbyte (uint8_t) |
Transmit one byte and wait for completion. | |
uint8_t | ps2_busy () |
Check if PS/2 statemachine is in IDLE state. | |
void | ps2_enable_recv (uint8_t) |
Suspend or enable PS/2 device by pulling clock line low. |
uint8_t ps2_avail | ( | ) |
uint8_t ps2_busy | ( | ) |
void ps2_enable_recv | ( | uint8_t | ) |
Suspend or enable PS/2 device by pulling clock line low.
1 | = enable |
00088 { 00089 if (enable) { 00090 state = IDLE; 00091 ps2_dir(1,1); 00092 // enable INT0 interruptt 00093 GIFR |= _BV(INTF0); 00094 GICR |= _BV(INT0); 00095 } else { 00096 // disable INT0, then everything else 00097 GICR &= ~_BV(INT0); 00098 ps2_clk(0); 00099 ps2_dir(1,0); 00100 } 00101 }
uint8_t ps2_getbyte | ( | ) |
Get one byte from input buffer. ps_avail() must be checked before doing so.
00120 { 00121 uint8_t result = rx_buf[rx_tail]; 00122 rx_tail = (rx_tail + 1) % PS2_RXBUF_LEN; 00123 00124 return result; 00125 }
void ps2_init | ( | ) |
Init PS/2 related I/O and interrupts.
00067 { 00068 state = IDLE; 00069 rx_head = 0; 00070 rx_tail = 0; 00071 ps2_enable_recv(0); 00072 00073 MCUCR |= _BV(ISC01); // falling edge for INT00 00074 TIMSK &= ~_BV(TOIE0); 00075 }
void ps2_sendbyte | ( | uint8_t | ) |
Transmit one byte and wait for completion.
00127 { 00128 while (state != IDLE); 00129 00130 // 1. pull clk low for 100us 00131 ps2_enable_recv(0); 00132 00133 tx_byte = byte; 00134 state = TX_REQ0; 00135 00136 // 128us 00137 TCNT0 = 255-4; 00138 TIMSK |= _BV(TOIE0); 00139 TCCR0 = 4; 00140 00141 while (state != IDLE); 00142 }