2015-04-09 18:32:04 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include "ps2_io.h"
|
|
|
|
#include "gpio_api.h"
|
|
|
|
|
|
|
|
static gpio_t clock;
|
|
|
|
static gpio_t data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clock
|
|
|
|
*/
|
2019-08-30 20:19:03 +02:00
|
|
|
void clock_init(void) {
|
2015-04-09 18:32:04 +02:00
|
|
|
gpio_init(&clock, P0_9);
|
2019-08-30 20:19:03 +02:00
|
|
|
gpio_mode(&clock, OpenDrain | PullNone);
|
2015-04-09 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
void clock_lo(void) {
|
2015-04-09 18:32:04 +02:00
|
|
|
gpio_dir(&clock, PIN_OUTPUT);
|
|
|
|
gpio_write(&clock, 0);
|
|
|
|
}
|
2019-08-30 20:19:03 +02:00
|
|
|
void clock_hi(void) {
|
2015-04-09 18:32:04 +02:00
|
|
|
gpio_dir(&clock, PIN_OUTPUT);
|
|
|
|
gpio_write(&clock, 1);
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
bool clock_in(void) {
|
2015-04-09 18:32:04 +02:00
|
|
|
gpio_dir(&clock, PIN_INPUT);
|
|
|
|
return gpio_read(&clock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Data
|
|
|
|
*/
|
2019-08-30 20:19:03 +02:00
|
|
|
void data_init(void) {
|
2015-04-09 18:32:04 +02:00
|
|
|
gpio_init(&data, P0_8);
|
2019-08-30 20:19:03 +02:00
|
|
|
gpio_mode(&data, OpenDrain | PullNone);
|
2015-04-09 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
void data_lo(void) {
|
2015-04-09 18:32:04 +02:00
|
|
|
gpio_dir(&data, PIN_OUTPUT);
|
|
|
|
gpio_write(&data, 0);
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
void data_hi(void) {
|
2015-04-09 18:32:04 +02:00
|
|
|
gpio_dir(&data, PIN_OUTPUT);
|
|
|
|
gpio_write(&data, 1);
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
bool data_in(void) {
|
2015-04-09 18:32:04 +02:00
|
|
|
gpio_dir(&data, PIN_INPUT);
|
|
|
|
return gpio_read(&data);
|
|
|
|
}
|