2021-08-05 14:51:24 -07:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include "ps2_io.h"
|
|
|
|
|
|
|
|
// chibiOS headers
|
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
2023-04-12 21:43:27 -07:00
|
|
|
#include "gpio.h"
|
2021-08-05 14:51:24 -07:00
|
|
|
|
|
|
|
/* Check port settings for clock and data line */
|
2021-10-20 12:07:40 -07:00
|
|
|
#if !(defined(PS2_CLOCK_PIN))
|
2021-08-05 14:51:24 -07:00
|
|
|
# error "PS/2 clock setting is required in config.h"
|
|
|
|
#endif
|
|
|
|
|
2021-10-20 12:07:40 -07:00
|
|
|
#if !(defined(PS2_DATA_PIN))
|
2021-08-05 14:51:24 -07:00
|
|
|
# error "PS/2 data setting is required in config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clock
|
|
|
|
*/
|
|
|
|
void clock_init(void) {}
|
|
|
|
|
|
|
|
void clock_lo(void) {
|
2021-10-20 12:07:40 -07:00
|
|
|
palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_OUTPUT_OPENDRAIN);
|
|
|
|
palWriteLine(PS2_CLOCK_PIN, PAL_LOW);
|
2021-08-05 14:51:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void clock_hi(void) {
|
2021-10-20 12:07:40 -07:00
|
|
|
palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_OUTPUT_OPENDRAIN);
|
|
|
|
palWriteLine(PS2_CLOCK_PIN, PAL_HIGH);
|
2021-08-05 14:51:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool clock_in(void) {
|
2021-10-20 12:07:40 -07:00
|
|
|
palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_INPUT);
|
|
|
|
return palReadLine(PS2_CLOCK_PIN);
|
2021-08-05 14:51:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Data
|
|
|
|
*/
|
|
|
|
void data_init(void) {}
|
|
|
|
|
|
|
|
void data_lo(void) {
|
2021-10-20 12:07:40 -07:00
|
|
|
palSetLineMode(PS2_DATA_PIN, PAL_MODE_OUTPUT_OPENDRAIN);
|
|
|
|
palWriteLine(PS2_DATA_PIN, PAL_LOW);
|
2021-08-05 14:51:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void data_hi(void) {
|
2021-10-20 12:07:40 -07:00
|
|
|
palSetLineMode(PS2_DATA_PIN, PAL_MODE_OUTPUT_OPENDRAIN);
|
|
|
|
palWriteLine(PS2_DATA_PIN, PAL_HIGH);
|
2021-08-05 14:51:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool data_in(void) {
|
2021-10-20 12:07:40 -07:00
|
|
|
palSetLineMode(PS2_DATA_PIN, PAL_MODE_INPUT);
|
|
|
|
return palReadLine(PS2_DATA_PIN);
|
2021-08-05 14:51:24 -07:00
|
|
|
}
|