summaryrefslogtreecommitdiff
path: root/platforms/avr/drivers/ps2/ps2_io.c
blob: fb8747437294bf6bfe4f621df8a70a69a6730da2 (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"
#include "gpio.h"
#include "wait.h"

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

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

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

void clock_lo(void) {
    // Transition from input with pull-up to output low via Hi-Z instead of output high
    gpio_write_pin_low(PS2_CLOCK_PIN);
    gpio_set_pin_output(PS2_CLOCK_PIN);
}

void clock_hi(void) {
    gpio_set_pin_input_high(PS2_CLOCK_PIN);
}

bool clock_in(void) {
    gpio_set_pin_input_high(PS2_CLOCK_PIN);
    wait_us(1);
    return gpio_read_pin(PS2_CLOCK_PIN);
}

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

void data_lo(void) {
    // Transition from input with pull-up to output low via Hi-Z instead of output high
    gpio_write_pin_low(PS2_DATA_PIN);
    gpio_set_pin_output(PS2_DATA_PIN);
}

void data_hi(void) {
    gpio_set_pin_input_high(PS2_DATA_PIN);
}

bool data_in(void) {
    gpio_set_pin_input_high(PS2_DATA_PIN);
    wait_us(1);
    return gpio_read_pin(PS2_DATA_PIN);
}