adb_usb: Fix mouse_init
This commit is contained in:
parent
35da7a8d70
commit
66e97371ba
3 changed files with 225 additions and 75 deletions
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2011 Jun WAKO <wakojun@gmail.com>
|
||||
Copyright 2011-19 Jun WAKO <wakojun@gmail.com>
|
||||
Copyright 2013 Shay Green <gblargg@gmail.com>
|
||||
|
||||
This software is licensed with a Modified BSD License.
|
||||
|
|
@ -113,18 +113,71 @@ uint8_t adb_host_talk_buf(uint8_t addr, uint8_t reg, uint8_t *buf, uint8_t len)
|
|||
attention();
|
||||
send_byte((addr<<4) | ADB_CMD_TALK | reg);
|
||||
place_bit0(); // Stopbit(0)
|
||||
// TODO: Service Request(Srq):
|
||||
// Device holds low part of comannd stopbit for 140-260us
|
||||
//
|
||||
// Command:
|
||||
// ......._ ______________________ ___ ............_ -------
|
||||
// | | | | | | |
|
||||
// Command | | | | | Data bytes | |
|
||||
// ........|___| | 140-260 |__| |_............|___|
|
||||
// |stop0 | Tlt Stop-to-Start |start1| |stop0 |
|
||||
//
|
||||
// Command without data:
|
||||
// ......._ __________________________
|
||||
// | |
|
||||
// Command | |
|
||||
// ........|___| | 140-260 |
|
||||
// |stop0 | Tlt Stop-to-Start |
|
||||
//
|
||||
// Service Request:
|
||||
// ......._ ______ ___ ............_ -------
|
||||
// | 140-260 | | | | | |
|
||||
// Command | Service Request | | | | Data bytes | |
|
||||
// ........|___________________| |__| |_............|___|
|
||||
// |stop0 | |start1| |stop0 |
|
||||
// ......._ __________
|
||||
// | 140-260 |
|
||||
// Command | Service Request |
|
||||
// ........|___________________|
|
||||
// |stop0 |
|
||||
// This can be happened?
|
||||
// ......._ ______________________ ___ ............_ -----
|
||||
// | | | | | | 140-260 |
|
||||
// Command | | | | | Data bytes | Service Request |
|
||||
// ........|___| | 140-260 |__| |_............|_________________|
|
||||
// |stop0 | Tlt Stop-to-Start |start1| |stop0 |
|
||||
//
|
||||
// "Service requests are issued by the devices during a very specific time at the
|
||||
// end of the reception of the command packet.
|
||||
// If a device in need of service issues a service request, it must do so within
|
||||
// the 65 µs of the Stop Bit’s low time and maintain the line low for a total of 300 µs."
|
||||
//
|
||||
// "A device sends a Service Request signal by holding the bus low during the low
|
||||
// portion of the stop bit of any command or data transaction. The device must lengthen
|
||||
// the stop by a minimum of 140 J.lS beyond its normal duration, as shown in Figure 8-15."
|
||||
// http://ww1.microchip.com/downloads/en/AppNotes/00591b.pdf
|
||||
if (!wait_data_hi(500)) { // Service Request(310us Adjustable Keyboard): just ignored
|
||||
xprintf("R");
|
||||
sei();
|
||||
return -30; // something wrong
|
||||
return 0;
|
||||
}
|
||||
if (!wait_data_lo(500)) { // Tlt/Stop to Start(140-260us)
|
||||
sei();
|
||||
return 0; // No data to send
|
||||
return 0; // No data from device(not error);
|
||||
}
|
||||
|
||||
// start bit(1)
|
||||
if (!wait_data_hi(40)) return 0;
|
||||
if (!wait_data_lo(100)) return 0;
|
||||
if (!wait_data_hi(40)) {
|
||||
xprintf("S");
|
||||
sei();
|
||||
return 0;
|
||||
}
|
||||
if (!wait_data_lo(100)) {
|
||||
xprintf("s");
|
||||
sei();
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t n = 0; // bit count
|
||||
do {
|
||||
|
|
@ -143,7 +196,7 @@ uint8_t adb_host_talk_buf(uint8_t addr, uint8_t reg, uint8_t *buf, uint8_t len)
|
|||
|
||||
uint8_t hi = (uint8_t) wait_data_lo(lo);
|
||||
if (!hi)
|
||||
goto error; // stop bit extedned by Srq
|
||||
goto error; // stop bit extedned by Srq?
|
||||
|
||||
if (n/8 >= len) continue; // can't store in buf
|
||||
|
||||
|
|
@ -174,6 +227,7 @@ void adb_host_listen_buf(uint8_t addr, uint8_t reg, uint8_t *buf, uint8_t len)
|
|||
attention();
|
||||
send_byte((addr<<4) | ADB_CMD_LISTEN | reg);
|
||||
place_bit0(); // Stopbit(0)
|
||||
// TODO: Service Request
|
||||
_delay_us(200); // Tlt/Stop to Start
|
||||
place_bit1(); // Startbit(1)
|
||||
for (int8_t i = 0; i < len; i++) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2011 Jun WAKO <wakojun@gmail.com>
|
||||
Copyright 2011-19 Jun WAKO <wakojun@gmail.com>
|
||||
|
||||
This software is licensed with a Modified BSD License.
|
||||
All of this is supposed to be Free Software, Open Source, DFSG-free,
|
||||
|
|
@ -54,11 +54,23 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
/* ADB commands */
|
||||
// Default Address
|
||||
#define ADB_ADDR_0 0
|
||||
#define ADB_ADDR_DONGLE 1
|
||||
#define ADB_ADDR_KEYBOARD 2
|
||||
#define ADB_ADDR_MOUSE 3
|
||||
#define ADB_ADDR_TABLET 4
|
||||
#define ADB_ADDR_APPLIANCE 7
|
||||
#define ADB_ADDR_8 8
|
||||
#define ADB_ADDR_9 9
|
||||
#define ADB_ADDR_10 10
|
||||
#define ADB_ADDR_11 11
|
||||
#define ADB_ADDR_12 12
|
||||
#define ADB_ADDR_13 13
|
||||
#define ADB_ADDR_14 14
|
||||
#define ADB_ADDR_15 15
|
||||
// for temporary purpose, do not use for polling
|
||||
#define ADB_ADDR_TMP 15
|
||||
#define ADB_ADDR_MOUSE_POLL 10
|
||||
// Command Type
|
||||
#define ADB_CMD_RESET 0
|
||||
#define ADB_CMD_FLUSH 1
|
||||
|
|
@ -80,6 +92,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#define ADB_HANDLER_CLASSIC1_MOUSE 0x01
|
||||
#define ADB_HANDLER_CLASSIC2_MOUSE 0x02
|
||||
#define ADB_HANDLER_EXTENDED_MOUSE 0x04
|
||||
#define ADB_HANDLER_TURBO_MOUSE 0x32
|
||||
|
||||
|
||||
// ADB host
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue