diff options
Diffstat (limited to 'protocol/ps2_busywait.c')
| -rw-r--r-- | protocol/ps2_busywait.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/protocol/ps2_busywait.c b/protocol/ps2_busywait.c index 05dd7b27e..a64933219 100644 --- a/protocol/ps2_busywait.c +++ b/protocol/ps2_busywait.c | |||
| @@ -40,8 +40,9 @@ POSSIBILITY OF SUCH DAMAGE. | |||
| 40 | */ | 40 | */ |
| 41 | 41 | ||
| 42 | #include <stdbool.h> | 42 | #include <stdbool.h> |
| 43 | #include <util/delay.h> | 43 | #include "wait.h" |
| 44 | #include "ps2.h" | 44 | #include "ps2.h" |
| 45 | #include "ps2_io.h" | ||
| 45 | #include "debug.h" | 46 | #include "debug.h" |
| 46 | 47 | ||
| 47 | 48 | ||
| @@ -58,8 +59,11 @@ uint8_t ps2_error = PS2_ERR_NONE; | |||
| 58 | 59 | ||
| 59 | void ps2_host_init(void) | 60 | void ps2_host_init(void) |
| 60 | { | 61 | { |
| 62 | clock_init(); | ||
| 63 | data_init(); | ||
| 64 | |||
| 61 | // POR(150-2000ms) plus BAT(300-500ms) may take 2.5sec([3]p.20) | 65 | // POR(150-2000ms) plus BAT(300-500ms) may take 2.5sec([3]p.20) |
| 62 | _delay_ms(2500); | 66 | wait_ms(2500); |
| 63 | 67 | ||
| 64 | inhibit(); | 68 | inhibit(); |
| 65 | } | 69 | } |
| @@ -71,7 +75,7 @@ uint8_t ps2_host_send(uint8_t data) | |||
| 71 | 75 | ||
| 72 | /* terminate a transmission if we have */ | 76 | /* terminate a transmission if we have */ |
| 73 | inhibit(); | 77 | inhibit(); |
| 74 | _delay_us(100); // 100us [4]p.13, [5]p.50 | 78 | wait_us(100); // 100us [4]p.13, [5]p.50 |
| 75 | 79 | ||
| 76 | /* 'Request to Send' and Start bit */ | 80 | /* 'Request to Send' and Start bit */ |
| 77 | data_lo(); | 81 | data_lo(); |
| @@ -80,7 +84,7 @@ uint8_t ps2_host_send(uint8_t data) | |||
| 80 | 84 | ||
| 81 | /* Data bit */ | 85 | /* Data bit */ |
| 82 | for (uint8_t i = 0; i < 8; i++) { | 86 | for (uint8_t i = 0; i < 8; i++) { |
| 83 | _delay_us(15); | 87 | wait_us(15); |
| 84 | if (data&(1<<i)) { | 88 | if (data&(1<<i)) { |
| 85 | parity = !parity; | 89 | parity = !parity; |
| 86 | data_hi(); | 90 | data_hi(); |
| @@ -92,13 +96,13 @@ uint8_t ps2_host_send(uint8_t data) | |||
| 92 | } | 96 | } |
| 93 | 97 | ||
| 94 | /* Parity bit */ | 98 | /* Parity bit */ |
| 95 | _delay_us(15); | 99 | wait_us(15); |
| 96 | if (parity) { data_hi(); } else { data_lo(); } | 100 | if (parity) { data_hi(); } else { data_lo(); } |
| 97 | WAIT(clock_hi, 50, 4); | 101 | WAIT(clock_hi, 50, 4); |
| 98 | WAIT(clock_lo, 50, 5); | 102 | WAIT(clock_lo, 50, 5); |
| 99 | 103 | ||
| 100 | /* Stop bit */ | 104 | /* Stop bit */ |
| 101 | _delay_us(15); | 105 | wait_us(15); |
| 102 | data_hi(); | 106 | data_hi(); |
| 103 | 107 | ||
| 104 | /* Ack */ | 108 | /* Ack */ |
