2019年5月15日 星期三

小紅點 (SK-8855) 控制 -- 初步實驗 (2019-05-16)

一直想把 Thinkpad 鍵盤的小紅點 (Trackpoint) 改裝的機械鍵盤,經過了好多年,可能超過十年吧,才搞清楚它就是 PS/2 的界面。而且它是一個完整獨立的滑鼠控制電路,按鍵是由它接出來的。網路實在太棒了,靠著網路上的使用者,眾志成城,不過要懂行的人有耐心地把腳位找出來才行。


下面是這幾天實驗的結果,用一個舊的 PS2 滑鼠的接線,把它連上。剛開始都不會動,以為失敗了,後來才知道粗心,把線接錯了。修正接線後,接上電腦的 PS2 接頭,在 LINUX 下不會動作。改成 PS2-to-USB 的轉接器,游標就會動了。

這個小紅點模組是 SK-8855 鍵盤拆下來的,它也是 T400S T410 T410S T410i T420 T420S T420i T510 T510i W510 W520 X220 X220S X220T 所用的鍵盤模組。



列出裝置
# xinput
⎡ Virtual core pointer                     id=2 [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer               id=4 [slave  pointer  (2)]
⎜   ↳ Barcode Reader                           id=11 [slave  pointer  (2)]
⎣ Virtual core keyboard                    id=3 [master keyboard (2)]
    ↳ Virtual core XTEST keyboard              id=5 [slave  keyboard (3)]
    ↳ Power Button                             id=6 [slave  keyboard (3)]
    ↳ Power Button                             id=7 [slave  keyboard (3)]
    ↳ Barcode Reader                           id=12 [slave  keyboard (3)]
只能這樣設定
# xinput --set-prop "pointer:Barcode Reader " "libinput Scroll Method Enabled" 0 0 1
# xinput --set-prop "pointer:Barcode Reader " "libinput Accel Speed" 1

若用以往外接鍵盤的設定方式,會出錯
# lsusb
Bus 002 Device 003: ID 13ba:0018 PCPlay Barcode PCP-BCG4209
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

找出它的 vendor id
## dmesg | grep -i barcode
[    1.418650] usb 2-1.3: Product: Barcode Reader
[    1.421480] input: Barcode Reader  as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/0003:13BA:0018.0001/input/input12
[    1.473593] hid-generic 0003:13BA:0018.0001: input,hidraw0: USB HID v1.10 Keyboard [Barcode Reader ] on usb-0000:00:1d.0-1.3/input0
[    1.477591] input: Barcode Reader  as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/0003:13BA:0018.0002/input/input13
[    1.529468] hid-generic 0003:13BA:0018.0002: input,hidraw1: USB HID v1.10 Mouse [Barcode Reader ] on usb-0000:00:1d.0-1.3/input1
[  556.083375] input: Barcode Reader  as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/0003:13BA:0018.0006/input/input266
[  556.135284] hid-generic 0003:13BA:0018.0006: input,hidraw0: USB HID v1.10 Mouse [Barcode Reader ] on usb-0000:00:1d.0-1.3/input1
[  964.634192] input: Barcode Reader  as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/0003:13BA:0018.0007/input/input267
[  964.686307] hid-generic 0003:13BA:0018.0007: input,hidraw0: USB HID v1.10 Mouse [Barcode Reader ] on usb-0000:00:1d.0-1.3/input1

設定程式
#pyusb imports
import usb.core 
import usb.util

# speed value
speed = 0x09
# 13020900 00000000 00
speed_dat = [0x13, 0x02, speed, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
# sensitivity value
sens_dat = [0x4, 0x6a, 0x3, 0xfc, 0x38]

dev = usb.core.find(idVendor=0x13ba, idProduct=0x0018)
# 21 09 0313 0001
dev.ctrl_transfer(0x21, 0x09, 0x0313, 0x01, speed_dat)
dev.ctrl_transfer(0x21, 0x9, 0x304, 0x1, sens_dat)
執行結果,不支援 dev.ctrl_transfer() 
# echo 2-1.3:1.1 > /sys/bus/usb/drivers/usbhid/unbind
# python2 trackpoint-script_barcode.py
python-exec: Invalid impl in /etc/python-exec/python-exec.conf: python3.4
Traceback (most recent call last):
  File "trackpoint-script_barcode.py", line 14, in <module>
    dev.ctrl_transfer(0x21, 0x09, 0x0313, 0x01, speed_dat)
  File "/usr/lib64/python2.7/site-packages/usb/core.py", line 1043, in ctrl_transfer
    self.__get_timeout(timeout))
  File "/usr/lib64/python2.7/site-packages/usb/backend/libusb1.py", line 883, in ctrl_transfer
    timeout))
  File "/usr/lib64/python2.7/site-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error
這個,我對 USB 控制器不熟,暫時沒辦法了。有空再來拔 SK-8855 外接 USB 鍵盤的控制器來測試。

不過,至少又往前進了一大步,搞清楚了一些東西,以後可以繼續做下去。


沒有留言:

張貼留言

網誌存檔