#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
-#include <util/delay.h>
#include "print.h"
#include "util.h"
#include "debug.h"
#include "host.h"
#include "led.h"
#include "timer.h"
+#include "wait.h"
if (reg3) {
xprintf(" addr:%d, reg3:%04X\n", addr, reg3);
}
- _delay_ms(20);
}
}
DDRD |= (1<<6); PORTD |= (1<<6);
adb_host_init();
- // wait for keyboard to boot up and receive command
- _delay_ms(2000);
+
+ // wait for line and device to be stable
+ wait_ms(100);
device_scan();
uint8_t addr;
again:
- // Some old mouses seems to need wait between commands.
- _delay_ms(20);
mouse_handler = (reg3 = adb_host_talk(orig_addr, ADB_REG_3)) & 0xFF;
if (!reg3) return;
dmprintf("addr%d reg3: %02X\n", orig_addr, reg3);
// Move device to tmp address
- _delay_ms(20);
adb_host_flush(orig_addr);
- _delay_ms(20);
adb_host_listen(orig_addr, ADB_REG_3, ((reg3 >> 8) & 0xF0) | ADB_ADDR_TMP, 0xFE);
adb_host_flush(ADB_ADDR_TMP);
- _delay_ms(20);
mouse_handler = (reg3 = adb_host_talk(ADB_ADDR_TMP, ADB_REG_3)) & 0xFF;
if (!reg3) {
dmprintf("move fail\n");
detect_again:
if (mouse_handler == ADB_HANDLER_CLASSIC1_MOUSE || mouse_handler == ADB_HANDLER_CLASSIC2_MOUSE) {
- _delay_ms(20);
adb_host_flush(addr);
adb_host_listen(addr, ADB_REG_3, (reg3 >> 8), ADB_HANDLER_EXTENDED_MOUSE);
- _delay_ms(20);
mouse_handler = (reg3 = adb_host_talk(addr, ADB_REG_3)) & 0xFF;
if (mouse_handler == ADB_HANDLER_CLASSIC1_MOUSE) {
- _delay_ms(20);
adb_host_flush(addr);
adb_host_listen(addr, ADB_REG_3, (reg3 >> 8), ADB_HANDLER_CLASSIC2_MOUSE);
- _delay_ms(20);
mouse_handler = (reg3 = adb_host_talk(addr, ADB_REG_3)) & 0xFF;
}
// 7 : num of buttons
uint8_t len;
uint8_t buf[8];
- _delay_ms(20);
len = adb_host_talk_buf(addr, ADB_REG_1, buf, sizeof(buf));
if (len > 5) {
static uint8_t cmd1[] = { 0xE7, 0x8C, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x94 };
static uint8_t cmd2[] = { 0xA5, 0x14, 0x00, 0x00, 0x69, 0xFF, 0xFF, 0x27 };
- _delay_ms(20);
adb_host_flush(addr);
adb_host_listen_buf(addr, ADB_REG_2, cmd1, sizeof(cmd1));
adb_host_flush(addr);
// Move all mouses to a address after init to be polled
- _delay_ms(20);
adb_host_flush(addr);
adb_host_listen(addr, ADB_REG_3, ((reg3 >> 8) & 0xF0) | ADB_ADDR_MOUSE_POLL, 0xFE);
adb_host_flush(ADB_ADDR_MOUSE_POLL);
- _delay_ms(20);
mouse_handler = (reg3 = adb_host_talk(addr, ADB_REG_3)) & 0xFF;
if (reg3) {
dmprintf("detect again\n");
static uint16_t detect_ms;
if (timer_elapsed(detect_ms) > 1000) {
detect_ms = timer_read();
- dmprintf(".");
// check new device on addr3
mouse_init(ADB_ADDR_MOUSE);
}