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