Skip to content

Commit

Permalink
support GPIO joypad
Browse files Browse the repository at this point in the history
  • Loading branch information
suzukiplan committed Feb 12, 2024
1 parent b21e863 commit de03ea3
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ VGS-Zero での USB ジョイパッドのサポートリストを示します。
> パソコンでの利用に際して専用のデバイスドライバを必要とするものや、XInput対応のゲームコントローラー(比較的新しいゲームコントローラー)は、全く認識できなかったり、認識できても一部のキー入力が効かないものが多い傾向があるので非推奨です。
> SUZUKIPLAN が主に使用している製品は Elecom JC-U3312 と HXBE37823 です。Elecom JC-U3312 は EOL (製造終了) の商品のため入手が難しいかもしれません。HXBE37823 は [Aliexpress](https://ja.aliexpress.com/item/1005001905753033.html) に 300 円前後の安価なものが沢山あり、[Amazon](https://www.amazon.co.jp/dp/B07M7SYX11/) でも購入可能です。(ただし、HXBE37823 は上下左右の移動をする時に斜め入力が入ってしまうものがあり、感度の品質面に難があるかもしれませんが、[Battle Marine](https://github.com/suzukiplan/bmarine-zero/) のように左右に移動方向を絞ったゲームであれば快適にプレイできます)
#### (GPIO Joypad)

RaspberryPi Zero 2W の GPIO に次のピンアサインで直接ボタンを接続することもできます。

| Button | GPIO |
|:------:|:----:|
| Up | 22 |
| Down | 5 |
| Left | 26 |
| Right | 6 |
| A | 24 |
| B | 25 |
| Start | 4 |
| Select | 23 |

RaspberryPi Zero 2W Pin Map

_※ GND の接続も必要です_

> GPIO 接続に関する詳細は [こちらの記事](https://note.com/suzukiplan/n/ncccafb305eae) をご参照ください。
>
> VGS-Zero 対応のジョイスティック・ジョイパッドは、企業(商業ハード)or 個人(同人ハード)に関係なく SUZUKIPLAN からのライセンス不要で自由に開発・販売していただくことが可能です。_(ライセンスは不要ですがサポートもしないスタイルなので、販売に伴う消費者へのサポート対応等は販売元の責任で行ってください)_
#### (Launch Sequence)

起動手順は次の通りです。
Expand Down
Binary file modified image/kernel8.img
Binary file not shown.
Binary file modified lib/sdcc/vgs0.lib
Binary file not shown.
33 changes: 33 additions & 0 deletions src/rpizero2/src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ CKernel::CKernel(void) : screen(480, 384),
sound(&vchiq, (TVCHIQSoundDestination)options.GetSoundOption()),
emmc(&interrupt, &timer, &led),
mcm(CMemorySystem::Get()),
gpioUp(22, GPIOModeInputPullUp),
gpioDown(5, GPIOModeInputPullUp),
gpioLeft(26, GPIOModeInputPullUp),
gpioRight(6, GPIOModeInputPullUp),
gpioA(24, GPIOModeInputPullUp),
gpioB(25, GPIOModeInputPullUp),
gpioStart(4, GPIOModeInputPullUp),
gpioSelect(23, GPIOModeInputPullUp),
gamePad(nullptr)
{
led.Blink(5);
Expand Down Expand Up @@ -296,6 +304,31 @@ TShutdownMode CKernel::run(void)
// update status of the peripheral devices
updateUsbStatus();

// Check GPIO joystick if usb gamepad is not connected
if (!gamePad) {
auto up = gpioUp.Read();
auto dw = gpioDown.Read();
auto le = gpioLeft.Read();
auto ri = gpioRight.Read();
auto t1 = gpioA.Read();
auto t2 = gpioB.Read();
auto st = gpioStart.Read();
auto se = gpioSelect.Read();
if (LOW == le && LOW == ri) {
; // 左右を同時に押している場合は入力を無視
} else {
pad1_ = 0;
pad1_ |= LOW == t1 ? VGS0_JOYPAD_T1 : 0;
pad1_ |= LOW == t2 ? VGS0_JOYPAD_T2 : 0;
pad1_ |= LOW == st ? VGS0_JOYPAD_ST : 0;
pad1_ |= LOW == se ? VGS0_JOYPAD_SE : 0;
pad1_ |= LOW == up ? VGS0_JOYPAD_UP : 0;
pad1_ |= LOW == dw ? VGS0_JOYPAD_DW : 0;
pad1_ |= LOW == le ? VGS0_JOYPAD_LE : 0;
pad1_ |= LOW == ri ? VGS0_JOYPAD_RI : 0;
}
}

// reset pending
if (pendingCounter_) {
uint16_t col = 0b0001100011100111;
Expand Down
9 changes: 9 additions & 0 deletions src/rpizero2/src/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <circle/types.h>
#include <circle/usb/usbgamepad.h>
#include <circle/usb/usbhcidevice.h>
#include <circle/gpiopin.h>
#include <fatfs/ff.h>
#include <vc4/sound/vchiqsoundbasedevice.h>
#include <vc4/sound/vchiqsounddevice.h>
Expand Down Expand Up @@ -58,6 +59,14 @@ class CKernel
CEMMCDevice emmc;
FATFS fatFs;
MultiCoreManager mcm;
CGPIOPin gpioUp;
CGPIOPin gpioDown;
CGPIOPin gpioLeft;
CGPIOPin gpioRight;
CGPIOPin gpioA;
CGPIOPin gpioB;
CGPIOPin gpioStart;
CGPIOPin gpioSelect;
CUSBGamePadDevice* volatile gamePad;
void updateUsbStatus(void);
};

0 comments on commit de03ea3

Please sign in to comment.