NetBSDでWacom Intuos 2ペンタブレットを使う

この記事は、NetBSD Advent Calendar 2017のすっかり遅くなった15日目の記事です。

はじめに

Wacom Intuos 2 A4 XD-0912-Uと言うペンタブレットを入手した。 残念ながら絵心はないのだが、NetBSDで使えないのはもったいないので、 使えるようにしてみた。

XD-0912-Uは、A4サイズのペンタブレットで、ペンは傾きも検出できるもので、 売られていた当時は、旗艦モデルだったような気がする。 ただし、今はWindows 7までしか対応しておらず、Windows 10では使用できないので Windowsでは使用は難しいかもしれない。

NetBSDのペンタブレットサポートを考える

ペンタブレットは、マウスとは違い、絶対的な位置情報を発信する必要がある。 NetBSDの既存の仕組みを見てみると、絶対的な位置情報を扱うものとして、 uts(4)というUSB接続タッチパネルの仕組みがあるが、 ペンタブレットをフル活用するには、筆圧、ペンの傾きをサポートする必要がある。 wsmouse(4)の仕組みも、筆圧やペンの傾きの情報を扱えるようには 設計されていないようだ。

と言うことで、uhid(4)を使っている既存の仕組みを改造してサポートする のが現実的だ。 デバイスの初期化はNetBSDカーネルで行い、 OpenBSD用のX windows systemであるXenocaraに含まれている xf86-input-usbtabletを改造して、 対応することにした。

NetBSDカーネルでの初期化

初期化は、基本的には既存のWacom製のペンタブレットと同じで、インターフェイスに 0x0202というデータを送ることで初期化できる。 Wacom Intuos 2は、0x0202による初期化をしないと、相対的な位置情報を USBマウスのように発信してくる。 USBマウスとして動かなくなったら正しく初期化できたと分かる。

uhid(4)の出力を解析する

LinuxのWacom用のデバイスドライバーに関連する資料などを 見ながら、実際にペンを動かして確認してみることにする。


$ cat /dev/uhid0 | od -x
のように実行した上で、ペンタブレット上でペンを動かして出力される データを確認して行く。 ですが、結局はデータの最初の部分がどのようになるかを把握する以上の ことはできなかった。

仕方がないのでLinuxのソースコードを読んでみることにした。。 主には、 drivers/input/tablet/wacom_wac.c を見れば良かった。 LinuxのWacomサポートは、evdevの仕組みで出力すると言うことのようなので、 出力は参考にならないが、ペンタブレットからの入力をデコードする部分の 必要な演算は分かる。 中身自体は、どこで切って入力値にするかと言うだけなので、 あまり面白みはなかった。

本当は、X.orgのインプットモジュールを書く方法について、 きちんとまとめておきたいのだが、今回は割愛して、実際の使用方法に移る。

使い方

以下のようにソースコードを取得し、ビルドし、配置する。 ここで、X.orgはNetBSDのxsrcを使っているので、pkgsrcから導入した場合には、 /usr/pkg以下に配置する必要があるだろう。


$ git clone git@github.com:ryoon/xf86-input-usbtablet.git
$ cd xf86-input-usbtablet
$ ./configure
$ make
# cp src/.libs/usbtablet_drv.so /usr/X11R7/lib/modules/drivers

残念ながら自動的にこのxf86-input-usbtabletドライバーを使用してくれるような ことはない。 以下のように/etc/X11/xorg.confに追加しておく必要がある。 赤字の部分が重要である。


Section "ServerLayout"
 Identifier     "X.org Configured"
 Screen      0  "Screen0" 0 0
 Screen      1  "Screen1" RightOf "Screen0"
 InputDevice    "Mouse0" "CorePointer"
 InputDevice    "Keyboard0" "CoreKeyboard"

 InputDevice    "w_stylus" "SendCoreEvents"
 InputDevice    "w_eraser" "SendCoreEvents" 

EndSection

Section "Files"
 ModulePath   "/usr/X11R7/lib/modules"
 FontPath     "/usr/X11R7/lib/X11/fonts/misc/"
 FontPath     "/usr/X11R7/lib/X11/fonts/TTF/"
 FontPath     "/usr/X11R7/lib/X11/fonts/Type1/"
 FontPath     "/usr/X11R7/lib/X11/fonts/75dpi/"
 FontPath     "/usr/X11R7/lib/X11/fonts/100dpi/"
 FontPath     "/usr/pkg/share/fonts/X11/TTF/"
 FontPath     "/usr/pkg/share/fonts/X11/local/"
EndSection

Section "Module"
 Load  "dbe"
# Load  "dri"
# Load  "dri2"
 Load  "extmod"
 Load  "glx"
 Load  "record"
 Load  "shadow"
EndSection

Section "InputDevice"
 Identifier  "Keyboard0"
 Driver      "kbd"
EndSection

Section "InputDevice"
 Identifier  "Mouse0"
 Driver      "mouse"
 Option     "Protocol" "wsmouse"
 Option     "Device" "/dev/wsmouse"
 Option     "ZAxisMapping" "4 5 6 7"
 Option     "Emulate3Buttons" "on"
EndSection


Section "InputDevice"
 Identifier "w_stylus"
 Driver "usbtablet"
 Option "Type" "stylus"
 Option "Device" "/dev/uhid0"
 Option "Mode" "Absolute"
 Option "Threshold" "10"
# Option "DebugLevel" "99"
EndSection

Section "InputDevice"
 Identifier "w_eraser"
 Driver "usbtablet"
 Option "Type" "eraser"
 Option "Device" "/dev/uhid0"
 Option "Mode" "Absolute"
# Option "DebugLevel" "99"
EndSection


Section "Monitor"
 Identifier   "Monitor0"
 VendorName   "Monitor Vendor"
 ModelName    "Monitor Model"
EndSection

Section "Monitor"
 Identifier   "Monitor1"
 VendorName   "Monitor Vendor"
 ModelName    "Monitor Model"
EndSection

Section "Device"
  Option     "NoAccel" "True"
        #Option     "AccelMethod"
        #Option     "Backlight"
        Option     "DRI" "False"
        #Option     "ColorKey"
        #Option     "VideoKey"
        #Option     "Tiling"
        #Option     "LinearFramebuffer"
        #Option     "SwapbuffersWait"
        #Option     "TripleBuffer"
        #Option     "XvPreferOverlay"
        #Option     "HotPlug"
        #Option     "ReprobeOutputs"
        #Option     "XvMC"
        #Option     "ZaphodHeads"
        #Option     "TearFree"
        #Option     "PerCrtcPixmaps"
        #Option     "FallbackDebug"
        #Option     "DebugFlushBatches"
        #Option     "DebugFlushCaches"
        #Option     "DebugWait"
        #Option     "BufferCache"
 Identifier  "Card0"
# Option     "AccelMethod" "SNA"
# Option     "AccelMethod" "UXA"
 Driver      "intel"
 BusID       "PCI:0:2:0"
EndSection

Section "Screen"
 Identifier "Screen0"
 Device     "Card0"
 Monitor    "Monitor0"
 SubSection "Display"
  Viewport   0 0
  Depth     1
 EndSubSection
 SubSection "Display"
  Viewport   0 0
  Depth     4
 EndSubSection
 SubSection "Display"
  Viewport   0 0
  Depth     8
 EndSubSection
 SubSection "Display"
  Viewport   0 0
  Depth     15
 EndSubSection
 SubSection "Display"
  Viewport   0 0
  Depth     16
 EndSubSection
 SubSection "Display"
  Viewport   0 0
  Depth     24
 EndSubSection
EndSection

Section "Screen"
 Identifier "Screen1"
 Device     "Card1"
 Monitor    "Monitor1"
 SubSection "Display"
  Viewport   0 0
  Depth     1
 EndSubSection
 SubSection "Display"
  Viewport   0 0
  Depth     4
 EndSubSection
 SubSection "Display"
  Viewport   0 0
  Depth     8
 EndSubSection
 SubSection "Display"
  Viewport   0 0
  Depth     15
 EndSubSection
 SubSection "Display"
  Viewport   0 0
  Depth     16
 EndSubSection
 SubSection "Display"
  Viewport   0 0
  Depth     24
 EndSubSection
EndSection

これで、pkgsrc/graphics/gimpでペンと消しゴムが使用できる。

一応、今も売っているはずのでIntuos Art CTH-690/K0でも動くのだが、 uhid(4)の何かのバグに突き当たっているようなので、お勧めはしない。

まとめ

Wacom Intuos 2をNetBSDで動くようにできた。 私は絵心は皆無なので、実際にこれを使って絵を描いてみると、致命的な 間違いをしていることが分かるかもしれない。特にペンの傾きは不安である。

ついでに、Wacom Favoで、ペンの傾きを正しく無視するようにしたので、 Wacom Favoユーザーにも使ってもらえると良いかもしれない。 Gimpがsegfaultで終了しなくなる。

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。

pkgsrc/mail/dkimproxyを使ってみたが、受信時の動作は、現在の用途には合わないようだった

とある過去に利用者のいたドメインを所有しているのだが、相当に雑な運用だったようで、いまだにSPAM以外の電子メールが来るし、 そのドメインの存在しないアカウントを装った電子メールが多く送信されているようだった。 しばらく、キャッチオール設定をして受信してみて気付いた...