MCPcopy Create free account
hub / github.com/PaulStoffregen/PS2Keyboard / ps2interrupt

Function ps2interrupt

PS2Keyboard.cpp:62–92  ·  view source on GitHub ↗

The ISR for the external interrupt

Source from the content-addressed store, hash-verified

60
61// The ISR for the external interrupt
62void ps2interrupt(void)
63{
64 static uint8_t bitcount=0;
65 static uint8_t incoming=0;
66 static uint32_t prev_ms=0;
67 uint32_t now_ms;
68 uint8_t n, val;
69
70 val = digitalRead(DataPin);
71 now_ms = millis();
72 if (now_ms - prev_ms > 250) {
73 bitcount = 0;
74 incoming = 0;
75 }
76 prev_ms = now_ms;
77 n = bitcount - 1;
78 if (n <= 7) {
79 incoming |= (val << n);
80 }
81 bitcount++;
82 if (bitcount == 11) {
83 uint8_t i = head + 1;
84 if (i >= BUFFER_SIZE) i = 0;
85 if (i != tail) {
86 buffer[i] = incoming;
87 head = i;
88 }
89 bitcount = 0;
90 incoming = 0;
91 }
92}
93
94static inline uint8_t get_scan_code(void)
95{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected