2015-04-09 18:32:04 +02:00
|
|
|
#include <stdbool.h>
|
2021-10-20 21:07:40 +02:00
|
|
|
#include "ps2_io.h"
|
|
|
|
#include "gpio.h"
|
|
|
|
#include "wait.h"
|
2015-04-09 18:32:04 +02:00
|
|
|
|
|
|
|
/* Check port settings for clock and data line */
|
2021-10-20 21:07:40 +02:00
|
|
|
#if !(defined(PS2_CLOCK_PIN))
|
|
|
|
# error "PS/2 clock setting is required in config.h"
|
2015-04-09 18:32:04 +02:00
|
|
|
#endif
|
|
|
|
|
2021-10-20 21:07:40 +02:00
|
|
|
#if !(defined(PS2_DATA_PIN))
|
|
|
|
# error "PS/2 data 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) {
|
2021-10-20 21:07:40 +02: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 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2022-02-12 19:29:31 +01:00
|
|
|
void clock_hi(void) {
|
|
|
|
setPinInputHigh(PS2_CLOCK_PIN);
|
|
|
|
}
|
2015-04-09 18:32:04 +02:00
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
bool clock_in(void) {
|
2021-10-20 21:07:40 +02:00
|
|
|
setPinInputHigh(PS2_CLOCK_PIN);
|
|
|
|
wait_us(1);
|
|
|
|
return readPin(PS2_CLOCK_PIN);
|
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) {
|
2021-10-20 21:07:40 +02: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 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2022-02-12 19:29:31 +01:00
|
|
|
void data_hi(void) {
|
|
|
|
setPinInputHigh(PS2_DATA_PIN);
|
|
|
|
}
|
2015-04-09 18:32:04 +02:00
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
bool data_in(void) {
|
2021-10-20 21:07:40 +02:00
|
|
|
setPinInputHigh(PS2_DATA_PIN);
|
|
|
|
wait_us(1);
|
|
|
|
return readPin(PS2_DATA_PIN);
|
2015-04-09 18:32:04 +02:00
|
|
|
}
|