2015-04-09 16:32:04 +00:00
|
|
|
#include <stdbool.h>
|
2021-10-20 19:07:40 +00:00
|
|
|
#include "ps2_io.h"
|
|
|
|
#include "gpio.h"
|
|
|
|
#include "wait.h"
|
2015-04-09 16:32:04 +00:00
|
|
|
|
|
|
|
/* Check port settings for clock and data line */
|
2021-10-20 19:07:40 +00:00
|
|
|
#if !(defined(PS2_CLOCK_PIN))
|
|
|
|
# error "PS/2 clock setting is required in config.h"
|
2015-04-09 16:32:04 +00:00
|
|
|
#endif
|
|
|
|
|
2021-10-20 19:07:40 +00:00
|
|
|
#if !(defined(PS2_DATA_PIN))
|
|
|
|
# error "PS/2 data setting is required in config.h"
|
2015-04-09 16:32:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clock
|
|
|
|
*/
|
2019-08-30 18:19:03 +00:00
|
|
|
void clock_init(void) {}
|
2015-04-09 16:32:04 +00:00
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
void clock_lo(void) {
|
2021-10-20 19:07:40 +00:00
|
|
|
// Transition from input with pull-up to output low via Hi-Z instead of output high
|
|
|
|
writePinLow(PS2_CLOCK_PIN);
|
|
|
|
setPinOutput(PS2_CLOCK_PIN);
|
2015-04-09 16:32:04 +00:00
|
|
|
}
|
|
|
|
|
2021-10-20 19:07:40 +00:00
|
|
|
void clock_hi(void) { setPinInputHigh(PS2_CLOCK_PIN); }
|
2015-04-09 16:32:04 +00:00
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
bool clock_in(void) {
|
2021-10-20 19:07:40 +00:00
|
|
|
setPinInputHigh(PS2_CLOCK_PIN);
|
|
|
|
wait_us(1);
|
|
|
|
return readPin(PS2_CLOCK_PIN);
|
2015-04-09 16:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Data
|
|
|
|
*/
|
2019-08-30 18:19:03 +00:00
|
|
|
void data_init(void) {}
|
2015-04-09 16:32:04 +00:00
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
void data_lo(void) {
|
2021-10-20 19:07:40 +00:00
|
|
|
// Transition from input with pull-up to output low via Hi-Z instead of output high
|
|
|
|
writePinLow(PS2_DATA_PIN);
|
|
|
|
setPinOutput(PS2_DATA_PIN);
|
2015-04-09 16:32:04 +00:00
|
|
|
}
|
|
|
|
|
2021-10-20 19:07:40 +00:00
|
|
|
void data_hi(void) { setPinInputHigh(PS2_DATA_PIN); }
|
2015-04-09 16:32:04 +00:00
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
bool data_in(void) {
|
2021-10-20 19:07:40 +00:00
|
|
|
setPinInputHigh(PS2_DATA_PIN);
|
|
|
|
wait_us(1);
|
|
|
|
return readPin(PS2_DATA_PIN);
|
2015-04-09 16:32:04 +00:00
|
|
|
}
|