あーさん日記

https://akkera102.sakura.ne.jp/gbadev/ の中の人

raspberry pi multiboot 実験2

wiringPiSPIでいけました。

#include <stdio.h>
#include <stdint.h>
#include <wiringPi.h>

void main(void)
{
	int r = wiringPiSPISetupMode(0, 100000, 3);
	printf("%d\n", r);

	uint8_t buf[4];

	printf("Looking for GBA\n");

	do
	{
		buf[0] = 0x00;
		buf[1] = 0x00;
		buf[2] = 0x62;
		buf[3] = 0x02;

		wiringPiSPIDataRW(0, &buf, 4);

		printf("r:0x%02x%02x%02x%02x\n", buf[0], buf[1], buf[2], buf[3]);
		usleep(10000);

	} while(buf[0] != 0x72 || buf[1] != 0x02 || buf[2] != 0x62 || buf[3] != 0x02);

	printf("Found GBA!\n");
}

mbedと比べてみると微妙に8bit目が長いです。とりあえず成功。
f:id:akkera102:20160520101221p:plain
ハマリポイントとしては待ち時間のところです。

usleep(1000000);

長すぎるとダメでした。