adb_usb: Remove unnecessary waits
This commit is contained in:
parent
66e97371ba
commit
0fec847611
1 changed files with 4 additions and 18 deletions
|
|
@ -21,7 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include "print.h"
|
||||
#include "util.h"
|
||||
#include "debug.h"
|
||||
|
|
@ -31,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "host.h"
|
||||
#include "led.h"
|
||||
#include "timer.h"
|
||||
#include "wait.h"
|
||||
|
||||
|
||||
|
||||
|
|
@ -57,7 +57,6 @@ static void device_scan(void)
|
|||
if (reg3) {
|
||||
xprintf(" addr:%d, reg3:%04X\n", addr, reg3);
|
||||
}
|
||||
_delay_ms(20);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,8 +71,9 @@ void matrix_init(void)
|
|||
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();
|
||||
|
||||
|
|
@ -140,20 +140,15 @@ static void mouse_init(uint8_t orig_addr)
|
|||
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");
|
||||
|
|
@ -165,20 +160,16 @@ again:
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -201,7 +192,6 @@ detect_again:
|
|||
// 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) {
|
||||
|
|
@ -244,7 +234,6 @@ detect_again:
|
|||
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);
|
||||
|
|
@ -253,12 +242,10 @@ detect_again:
|
|||
|
||||
|
||||
// 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");
|
||||
|
|
@ -295,7 +282,6 @@ void adb_mouse_task(void)
|
|||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue