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