@@ -60,7 +60,6 @@ static inline void place_bit1(void);
60
60
static inline void send_byte (uint8_t data );
61
61
static inline uint16_t wait_data_lo (uint16_t us );
62
62
static inline uint16_t wait_data_hi (uint16_t us );
63
- static inline uint16_t adb_host_dev_recv (uint8_t device );
64
63
65
64
66
65
void adb_host_init (void )
@@ -87,49 +86,9 @@ bool adb_host_psw(void)
87
86
* <http://geekhack.org/index.php?topic=14290.msg1068919#msg1068919>
88
87
* <http://geekhack.org/index.php?topic=14290.msg1070139#msg1070139>
89
88
*/
90
-
91
- // ADB Bit Cells
92
- //
93
- // bit cell time: 70-130us
94
- // low part of bit0: 60-70% of bit cell
95
- // low part of bit1: 30-40% of bit cell
96
- //
97
- // bit cell time 70us 130us
98
- // --------------------------------------------
99
- // low part of bit0 42-49 78-91
100
- // high part of bit0 21-28 39-52
101
- // low part of bit1 21-28 39-52
102
- // high part of bit1 42-49 78-91
103
- //
104
- //
105
- // bit0:
106
- // 70us bit cell:
107
- // ____________~~~~~~
108
- // 42-49 21-28
109
- //
110
- // 130us bit cell:
111
- // ____________~~~~~~
112
- // 78-91 39-52
113
- //
114
- // bit1:
115
- // 70us bit cell:
116
- // ______~~~~~~~~~~~~
117
- // 21-28 42-49
118
- //
119
- // 130us bit cell:
120
- // ______~~~~~~~~~~~~
121
- // 39-52 78-91
122
- //
123
- // [from Apple IIgs Hardware Reference Second Edition]
124
-
125
- enum {
126
- ADDR_KEYB = 0x20 ,
127
- ADDR_MOUSE = 0x30
128
- };
129
-
130
89
uint16_t adb_host_kbd_recv (void )
131
90
{
132
- return adb_host_dev_recv ( ADDR_KEYB );
91
+ return adb_host_talk ( ADB_ADDR_KEYBOARD , ADB_REG_0 );
133
92
}
134
93
135
94
#ifdef ADB_MOUSE_ENABLE
@@ -139,16 +98,16 @@ void adb_mouse_init(void) {
139
98
140
99
uint16_t adb_host_mouse_recv (void )
141
100
{
142
- return adb_host_dev_recv ( ADDR_MOUSE );
101
+ return adb_host_talk ( ADB_ADDR_MOUSE , ADB_REG_0 );
143
102
}
144
103
#endif
145
104
146
- static inline uint16_t adb_host_dev_recv (uint8_t device )
105
+ uint16_t adb_host_talk (uint8_t addr , uint8_t reg )
147
106
{
148
107
uint16_t data = 0 ;
149
108
cli ();
150
109
attention ();
151
- send_byte (device | 0x0C ); // Addr:Keyboard(0010)/Mouse(0011), Cmd:Talk(11), Register0(00)
110
+ send_byte (( addr << 4 ) | ( ADB_CMD_TALK << 2 ) | reg );
152
111
place_bit0 (); // Stopbit(0)
153
112
if (!wait_data_hi (500 )) { // Service Request(310us Adjustable Keyboard): just ignored
154
113
sei ();
@@ -158,20 +117,20 @@ static inline uint16_t adb_host_dev_recv(uint8_t device)
158
117
sei ();
159
118
return 0 ; // No data to send
160
119
}
161
-
120
+
162
121
uint8_t n = 17 ; // start bit + 16 data bits
163
122
do {
164
123
uint8_t lo = (uint8_t ) wait_data_hi (130 );
165
124
if (!lo )
166
125
goto error ;
167
-
126
+
168
127
uint8_t hi = (uint8_t ) wait_data_lo (lo );
169
128
if (!hi )
170
129
goto error ;
171
-
130
+
172
131
hi = lo - hi ;
173
132
lo = 130 - lo ;
174
-
133
+
175
134
data <<= 1 ;
176
135
if (lo < hi ) {
177
136
data |= 1 ;
@@ -205,7 +164,7 @@ void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l)
205
164
place_bit0 (); // Stopbit(0)
206
165
_delay_us (200 ); // Tlt/Stop to Start
207
166
place_bit1 (); // Startbit(1)
208
- send_byte (data_h );
167
+ send_byte (data_h );
209
168
send_byte (data_l );
210
169
place_bit0 (); // Stopbit(0);
211
170
sei ();
@@ -375,7 +334,7 @@ Commands
375
334
A A A A 1 1 R R Talk(read from a device)
376
335
377
336
The command to read keycodes from keyboard is 0x2C which
378
- consist of keyboard address 2 and Talk against register 0.
337
+ consist of keyboard address 2 and Talk against register 0.
379
338
380
339
Address:
381
340
2: keyboard
@@ -457,7 +416,7 @@ Keyboard Data(Register0)
457
416
Keyboard LEDs & state of keys(Register2)
458
417
This register hold current state of three LEDs and nine keys.
459
418
The state of LEDs can be changed by sending Listen command.
460
-
419
+
461
420
1514 . . . . . . 7 6 5 . 3 2 1 0
462
421
| | | | | | | | | | | | | | | +- LED1(NumLock)
463
422
| | | | | | | | | | | | | | +--- LED2(CapsLock)
@@ -474,5 +433,46 @@ Keyboard LEDs & state of keys(Register2)
474
433
| +----------------------------- Delete
475
434
+------------------------------- Reserved
476
435
436
+ ADB Bit Cells
437
+ bit cell time: 70-130us
438
+ low part of bit0: 60-70% of bit cell
439
+ low part of bit1: 30-40% of bit cell
440
+
441
+ bit cell time 70us 130us
442
+ --------------------------------------------
443
+ low part of bit0 42-49 78-91
444
+ high part of bit0 21-28 39-52
445
+ low part of bit1 21-28 39-52
446
+ high part of bit1 42-49 78-91
447
+
448
+
449
+ bit0:
450
+ 70us bit cell:
451
+ ____________~~~~~~
452
+ 42-49 21-28
453
+
454
+ 130us bit cell:
455
+ ____________~~~~~~
456
+ 78-91 39-52
457
+
458
+ bit1:
459
+ 70us bit cell:
460
+ ______~~~~~~~~~~~~
461
+ 21-28 42-49
462
+
463
+ 130us bit cell:
464
+ ______~~~~~~~~~~~~
465
+ 39-52 78-91
466
+
467
+ [from Apple IIgs Hardware Reference Second Edition]
468
+
469
+ Keyboard Handle ID
470
+ Apple Standard Keyboard M0116: 0x01
471
+ Apple Extended Keyboard M0115: 0x02
472
+ Apple Extended Keyboard II M3501: 0x02
473
+ Apple Adjustable Keybaord: 0x10
474
+
475
+ http://lxr.free-electrons.com/source/drivers/macintosh/adbhid.c?v=4.4#L802
476
+
477
477
END_OF_ADB
478
478
*/
0 commit comments