2015-04-09 18:32:04 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <avr/io.h>
|
|
|
|
#include <util/delay.h>
|
|
|
|
|
|
|
|
/* Check port settings for clock and data line */
|
2019-08-30 20:19:03 +02:00
|
|
|
#if !(defined(PS2_CLOCK_PORT) && defined(PS2_CLOCK_PIN) && defined(PS2_CLOCK_DDR) && defined(PS2_CLOCK_BIT))
|
|
|
|
# error "PS/2 clock port setting is required in config.h"
|
2015-04-09 18:32:04 +02:00
|
|
|
#endif
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
#if !(defined(PS2_DATA_PORT) && defined(PS2_DATA_PIN) && defined(PS2_DATA_DDR) && defined(PS2_DATA_BIT))
|
|
|
|
# error "PS/2 data port setting is required in config.h"
|
2015-04-09 18:32:04 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clock
|
|
|
|
*/
|
2019-08-30 20:19:03 +02:00
|
|
|
void clock_init(void) {}
|
2015-04-09 18:32:04 +02:00
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
void clock_lo(void) {
|
|
|
|
PS2_CLOCK_PORT &= ~(1 << PS2_CLOCK_BIT);
|
|
|
|
PS2_CLOCK_DDR |= (1 << PS2_CLOCK_BIT);
|
2015-04-09 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
void clock_hi(void) {
|
2015-04-09 18:32:04 +02:00
|
|
|
/* input with pull up */
|
2019-08-30 20:19:03 +02:00
|
|
|
PS2_CLOCK_DDR &= ~(1 << PS2_CLOCK_BIT);
|
|
|
|
PS2_CLOCK_PORT |= (1 << PS2_CLOCK_BIT);
|
2015-04-09 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
bool clock_in(void) {
|
|
|
|
PS2_CLOCK_DDR &= ~(1 << PS2_CLOCK_BIT);
|
|
|
|
PS2_CLOCK_PORT |= (1 << PS2_CLOCK_BIT);
|
2015-04-09 18:32:04 +02:00
|
|
|
_delay_us(1);
|
2019-08-30 20:19:03 +02:00
|
|
|
return PS2_CLOCK_PIN & (1 << PS2_CLOCK_BIT);
|
2015-04-09 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Data
|
|
|
|
*/
|
2019-08-30 20:19:03 +02:00
|
|
|
void data_init(void) {}
|
2015-04-09 18:32:04 +02:00
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
void data_lo(void) {
|
|
|
|
PS2_DATA_PORT &= ~(1 << PS2_DATA_BIT);
|
|
|
|
PS2_DATA_DDR |= (1 << PS2_DATA_BIT);
|
2015-04-09 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
void data_hi(void) {
|
2015-04-09 18:32:04 +02:00
|
|
|
/* input with pull up */
|
2019-08-30 20:19:03 +02:00
|
|
|
PS2_DATA_DDR &= ~(1 << PS2_DATA_BIT);
|
|
|
|
PS2_DATA_PORT |= (1 << PS2_DATA_BIT);
|
2015-04-09 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
bool data_in(void) {
|
|
|
|
PS2_DATA_DDR &= ~(1 << PS2_DATA_BIT);
|
|
|
|
PS2_DATA_PORT |= (1 << PS2_DATA_BIT);
|
2015-04-09 18:32:04 +02:00
|
|
|
_delay_us(1);
|
2019-08-30 20:19:03 +02:00
|
|
|
return PS2_DATA_PIN & (1 << PS2_DATA_BIT);
|
2015-04-09 18:32:04 +02:00
|
|
|
}
|