!Arduboy->Gamebuino移植メモ
音とLCD(OLED)の制御を書き直せば基本的に動く。
音はシンプルにarduinoのtoneを使っていると移植が簡単
Gamebuino->Arduboyはみんな同じライブラリを使っていることもあってもっと簡単なはず。
このドキュメントでは Arduino->Gamebuinoに絞って記載する。
!!液晶制御ピン
!!!arduboy dev
>>
#define CS 6
#define DC 4
#define RST 12
<<
!!!arduboy
>>
#define CS 12
#define DC 4
#define RST 6
<<
!!!Gamebuino
>>
#define CS 15
#define DC 16
#define RST 14
<<
!!液晶初期化コード
液晶によりますが、、
!!!OLED 128x64
http://www.aitendo.com/product/7273
これはArduboyのものとよく似ている。初期化シーケンスが少し違う(とおもわれる)
>>
SPI.transfer(0xd5);
SPI.transfer(0xf0);
SPI.transfer(0x8d);
SPI.transfer(0x14);
SPI.transfer(0xa1);
SPI.transfer(0xc8);
SPI.transfer(0x81);
SPI.transfer(0xcf);
SPI.transfer(0xd9);
SPI.transfer(0xf1);
SPI.transfer(0xaf);
SPI.transfer(0x20);
SPI.transfer(0x00);
<<
!!!FSTN 128x64
http://www.aitendo.com/product/10007
Gamebuinoクローンで使ったもの。初期化シーケンスや制御方法が違う。
>>
SPI.transfer(0xe2);
SPI.transfer(0x40);
SPI.transfer(0xa0);
SPI.transfer(0xc8);
SPI.transfer(0xa6);
SPI.transfer(0xa2);
SPI.transfer(0x2f);
SPI.transfer(0xf8);
SPI.transfer(0x00);
SPI.transfer(0x23);
SPI.transfer(0x81);
SPI.transfer(0x30);
SPI.transfer(0xac);
SPI.transfer(0xa1);
SPI.transfer(0xc0);
SPI.transfer(0x00);
SPI.transfer(0xaf);
SPI.transfer(0xa5);
SPI.transfer(0xa4);
SPI.transfer(0xb0);
SPI.transfer(0x10);
<<
!!!NOKIA 5110
84x48 Gamebuinoはまさにこの液晶だったはず。Arduboyのゲームを動かすためには解像度が足りない
http://www.aitendo.com/product/1164
>>
まだ触ったことがない(買ってはいるが積んでる)
<<
!!ADC制御
GamebuinoはAtmega328でArduboyはatmega32u4とかだったはず、レジスタが微妙に違う
>>
#if defined(MY_GAMEBUINO_1) || defined(MY_GAMEBUINO_2)
#define ADC_VOLTAGE (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
#else
#define ADC_VOLTAGE (_BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
#endif
<<
!!ボタンなど
!!!arduboy dev
>>
#define LEFT_BUTTON _BV(5)
#define RIGHT_BUTTON _BV(2)
#define UP_BUTTON _BV(4)
#define DOWN_BUTTON _BV(6)
#define A_BUTTON _BV(1)
#define B_BUTTON _BV(0)
#define PIN_LEFT_BUTTON 9
#define PIN_RIGHT_BUTTON 5
#define PIN_UP_BUTTON 8
#define PIN_DOWN_BUTTON 10
#define PIN_A_BUTTON A0
#define PIN_B_BUTTON A1
#define PIN_SPEAKER_1 A2
#define PIN_SPEAKER_2 A2
<<
>>
// down, left, up
buttons = ((~PINB) & B01110000);
// right button
buttons = buttons | (((~PINC) & B01000000) >> 4);
// A and B
buttons = buttons | (((~PINF) & B11000000) >> 6);
<<
!!! arduboy
>>
#define LEFT_BUTTON _BV(5)
#define RIGHT_BUTTON _BV(6)
#define UP_BUTTON _BV(7)
#define DOWN_BUTTON _BV(4)
#define A_BUTTON _BV(3)
#define B_BUTTON _BV(2)
#define PIN_LEFT_BUTTON A2
#define PIN_RIGHT_BUTTON A1
#define PIN_UP_BUTTON A0
#define PIN_DOWN_BUTTON A3
#define PIN_A_BUTTON 7
#define PIN_B_BUTTON 8
#define PIN_SPEAKER_1 5
#define PIN_SPEAKER_2 13
<<
>>
// down, up, left right
buttons = ((~PINF) & B11110000);
// A (left)
buttons = buttons | (((~PINE) & B01000000) >> 3);
// B (right)
buttons = buttons | (((~PINB) & B00010000) >> 2);
<<
!!!Gamebuino
PIN_SPEAKER_2は存在しない
これを利用したコードはうまく動かない
>>
#define LEFT_BUTTON _BV(1)
#define RIGHT_BUTTON _BV(6)
#define UP_BUTTON _BV(7)
#define DOWN_BUTTON _BV(0)
#define A_BUTTON _BV(4)
#define B_BUTTON _BV(2)
#define PIN_LEFT_BUTTON 9
#define PIN_RIGHT_BUTTON 6
#define PIN_UP_BUTTON 7
#define PIN_DOWN_BUTTON 8
#define PIN_A_BUTTON 4
#define PIN_B_BUTTON 2
#define PIN_SPEAKER_1 3
<<
>>
buttons = ((~PIND) & B11010100); // 7(up), 6(right), 4(a), 2(b)
buttons = buttons | ((~PINB) & B00000011); // 1(left), 0(down)
buttons = buttons | ((~PINC) & B00001000); // 3(c)
<<
!!!不要なタイマーの停止
Gamebuinoだとtone関数で音を鳴らすときにtimer2を使うので、もしArduboyでtimer2を停止している処理がある場合は、それをやめる
!!!バックライト
Gamebuinoはバックライトもプログラマブルになっているが、ArduboyはOLEDのため、そもそもバックライトが存在しない。
とりあえずバックライトのピンをOUTPUTにしてHIGHにしておけばOK
5643382
wiki
1469961116