summaryrefslogtreecommitdiffstats
path: root/tmk_core/protocol/ps2_io_chibios.c
blob: b672bd1f47fa95260ac0891766498394079c64a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdbool.h>
#include "ps2_io.h"

// chibiOS headers
#include "ch.h"
#include "hal.h"

/* Check port settings for clock and data line */
#if !(defined(PS2_CLOCK))
#    error "PS/2 clock setting is required in config.h"
#endif

#if !(defined(PS2_DATA))
#    error "PS/2 data setting is required in config.h"
#endif

/*
 * Clock
 */
void clock_init(void) {}

void clock_lo(void) {
    palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN);
    palWriteLine(PS2_CLOCK, PAL_LOW);
}

void clock_hi(void) {
    palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN);
    palWriteLine(PS2_CLOCK, PAL_HIGH);
}

bool clock_in(void) {
    palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT);
    return palReadLine(PS2_CLOCK);
}

/*
 * Data
 */
void data_init(void) {}

void data_lo(void) {
    palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN);
    palWriteLine(PS2_DATA, PAL_LOW);
}

void data_hi(void) {
    palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN);
    palWriteLine(PS2_DATA, PAL_HIGH);
}

bool data_in(void) {
    palSetLineMode(PS2_DATA, PAL_MODE_INPUT);
    return palReadLine(PS2_DATA);
}