Merge branch 'next_timing'

This commit is contained in:
tmk 2022-04-17 08:55:20 +09:00
commit 732dfbb3ed
5 changed files with 1301 additions and 1229 deletions

View file

@ -1,45 +1,70 @@
NeXT non-ADB Keyboard Converter NeXT non-ADB Keyboard Converter
------------------------------- ===============================
With this converter you can use NeXT keyboard(non-ADB) on modern computer.
See this for details.
https://github.com/tmk/tmk_keyboard/wiki/NeXT
Wiring
------
Connections to ATmega32U2/U4
FROM(Pin3): PD0
TO(Pin2): PD1
PSW(Pin4): PD4
GND(Pin5): GND
VCC(Pin1): VCC
Pinouts
-------
Socket on converter from front:
_____
GND / 5 4 \ PSW
FROM | 3 2 | TO
| 1 | VCC
`-----'
FROM: keyboard to computer
TO: computer to keyboard
PSW: Power key
Cable connector inside keyboard case: Cable connector inside keyboard case:
+-----+
|Black|\
|Green|-\
|Yello|--\-------- to computer via Mini-Din 5a Connector
|Orang|--/--------
|Red |-/
|Brown|/
+-----+
Black - Ground to outer metal part of Mini Din 5a connector (not used) +-----+
Green - Ground |Black|\
Yellow - Power button signal |Green|-\
Orange - Keyboard Out |Yello|--\-------- to computer via Mini-Din 5 plug
Red - Keyboard In |Orang|--/--------
Brown - Vcc |Red |-/
|Brown|/
+-----+
Black: FG
Green: GND
Yellow: PSW(Power key)
Orange: FROM Keyboard
Red: TO Keyboard
Brown: VCC
ATmega32u4 connections (pinout provided for Arduino Pro Micro):
Keyboard out (orange) : PD0 (pin 3)
Keyboard in (red) : PD1 (pin 2)
Power Button (yellow) : PD4 (pin 4)
Ground (black) : GND
Vcc (brown) : VCC
See attached next_timings.jpg file for a detailed illustration of NeXT keyboard protocol timings. Protocol
--------
See this for NeXT keyboard protocol.
Power button signal line is normally high when the keyboard is powered/initialized. It is pulled to ground when pressed. The converter automatically translates this to a "normal" keypress with code 0x5A. This connection is technically optional, the only side effect of not making this connection is the power key will do nothing. - https://github.com/tmk/tmk_keyboard/wiki/NeXT#next-keyboard-protocol
Converter is based heavily on Ladyada's original "USB NeXT Keyboard with Arduino Micro" tutorial (http://learn.adafruit.com/usb-next-keyboard-with-arduino-micro/overview). If you build this converter, show Adafruit some love and do it using an Arduino Micro (http://www.adafruit.com/products/1315) or their ATmega 32u4 Breakout Board (http://www.adafruit.com/products/296). Arduino Micro should work fine using the Arduino Pro Micro configuration above, same pins numbers and everything.
TODO:
Notes
----- -----
LEDs indicates Caps Lock state in current implementation.
I believe it might be possible to run the keyboard off of 3V; during testing I observed that the keyboard could sometimes function even without Vcc connected as long as the ground connection was good and the Keyboard In line was connected. If that works it should be easy to do a Bluetooth conversion and run the keyboard right off of a LiPo battery without a boost circuit
Utilize second LED as status indicator for good initialization; also try to make hot plugging much more robust.
Figure a better use for the Power button. Too easy to hit it by mistake to use for Suspend or Power Off - maybe move cap to different part of the board and consider that
Figure out a better use for the lock LEDs. Right now they just light up when you press shift. Lame. Maybe implement proper Caps/Num/Scroll Locks
Original Project
----------------
Converter is based heavily on Ladyada's original "USB NeXT Keyboard with Arduino Micro" tutorial (http://learn.adafruit.com/usb-next-keyboard-with-arduino-micro/overview). If you build this converter, show Adafruit some love and do it using an Arduino Micro (http://www.adafruit.com/products/1315) or their ATmega 32u4 Breakout Board (http://www.adafruit.com/products/296). Arduino Micro should work fine using the Arduino Pro Micro configuration above, same pins numbers and everything.

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 398 KiB

View file

@ -59,16 +59,10 @@ static inline void query(void);
static inline void reset(void); static inline void reset(void);
static inline uint32_t response(void); static inline uint32_t response(void);
/* The keyboard sends signal with 50us pulse width on OUT line #define out_hi_delay(intervals) do { out_hi(); _delay_us((NEXT_KBD_TIMING) * intervals); } while (0);
* while it seems to miss the 50us pulse on In line. #define out_lo_delay(intervals) do { out_lo(); _delay_us((NEXT_KBD_TIMING) * intervals); } while (0);
* next_kbd_set_leds() often fails to sync LED status with 50us #define query_delay(intervals) do { query(); _delay_us((NEXT_KBD_TIMING) * intervals); } while (0);
* but it works well with 51us(+1us) on TMK converter(ATMeaga32u2) at least. #define reset_delay(intervals) do { reset(); _delay_us((NEXT_KBD_TIMING) * intervals); } while (0);
* TODO: test on Teensy and Pro Micro configuration
*/
#define out_hi_delay(intervals) do { out_hi(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0);
#define out_lo_delay(intervals) do { out_lo(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0);
#define query_delay(intervals) do { query(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0);
#define reset_delay(intervals) do { reset(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0);
void next_kbd_init(void) void next_kbd_init(void)
{ {
@ -144,34 +138,14 @@ static inline uint32_t response(void)
sei(); sei();
return 0; return 0;
} }
_delay_us(NEXT_KBD_TIMING / 2); _delay_us(NEXT_KBD_TIMING / 2 - 1);
for (; i < 22; i++) for (; i < 22; i++)
{ {
if (NEXT_KBD_READ) if (NEXT_KBD_READ)
{ {
data |= ((uint32_t) 1 << i); data |= (uint32_t)1 << 22;
/* Note:
* My testing with the ATmega32u4 showed that there might
* something wrong with the timing here; by the end of the
* second data byte some of the modifiers can get bumped out
* to the next bit over if we just cycle through the data
* based on the expected interval. There is a bit (i = 10)
* in the middle of the data that is always on followed by
* one that is always off - so we'll use that to reset our
* timing in case we've gotten ahead of the keyboard;
*/
if (i == 10)
{
i++;
while (NEXT_KBD_READ) ;
_delay_us(NEXT_KBD_TIMING / 2);
}
} else {
/* redundant - but I don't want to remove if it might screw
* up the timing
*/
data |= ((uint32_t) 0 << i);
} }
data >>= 1;
_delay_us(NEXT_KBD_TIMING); _delay_us(NEXT_KBD_TIMING);
} }

View file

@ -51,7 +51,9 @@ POSSIBILITY OF SUCH DAMAGE.
#define NEXT_KBD_H #define NEXT_KBD_H
#define NEXT_KBD_KMBUS_IDLE 0x300600 #define NEXT_KBD_KMBUS_IDLE 0x300600
#define NEXT_KBD_TIMING 50
// https://github.com/tmk/tmk_keyboard/issues/704
#define NEXT_KBD_TIMING 52
extern uint8_t next_kbd_error; extern uint8_t next_kbd_error;