BlackOneとAndroidの連携デモプログラム AndroidAccessoryを改造してBlackOneとAndroidが連携できるようにしました。 サポートしているのは、デモアプリの ”Buttons” B1-SW1, B2-SW2, B3-SW3 ”LED2” RGB-LED のみです。 LCDに表示するイメージをマイクロSDカードに入れてLCDのソケットに挿入しておく必要があります。 イメージは、320X240ドットで”\Image”という名前のフォルダの直下に”10.jpg”という名前で入れてください。

Dependencies:   TextLCD mbed

Revision:
0:7b556109fd46
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Dec 23 04:33:33 2011 +0000
@@ -0,0 +1,142 @@
+ /*
+Copyright (c) 2010 Peter Barrett
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "mbed.h"
+#include "USBHost.h"
+#include "Utils.h"
+#include "FATFileSystem.h"
+#include "TextLCD.h"
+
+TextLCD lcd(p10, p9, p15, p16, p22, p23);
+
+Serial e_Disp2(p9, p10); // tx, rx
+
+int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize);
+int MassStorage_Read(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
+int MassStorage_Write(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
+
+class USBFileSystem : public FATFileSystem
+{
+    int _device;
+    u32 _blockSize;
+    u32 _blockCount;
+    
+public:
+    USBFileSystem() : FATFileSystem("usb"),_device(0),_blockSize(0),_blockCount(0)
+    {
+    }
+    
+    void SetDevice(int device)
+    {
+        _device = device;
+    }
+    
+    virtual int disk_initialize()
+    {
+        return MassStorage_ReadCapacity(_device,&_blockCount,&_blockSize);
+    }
+    
+    virtual int disk_write(const char *buffer, int block_number)
+    {
+        return MassStorage_Write(_device,block_number,1,(u8*)buffer,_blockSize);
+    }
+    
+    virtual int disk_read(char *buffer, int block_number)
+    {
+        return MassStorage_Read(_device,block_number,1,(u8*)buffer,_blockSize);
+    }
+        
+    virtual int disk_sectors()
+    {
+        return _blockCount;
+    }
+};
+
+void DumpFS(int depth, int count)
+{
+    DIR *d = opendir("/usb");
+    if (!d)
+    {
+        e_Disp2.printf("USB file system borked\r\n");
+        return;
+    }
+
+    e_Disp2.printf("\nDumping root dir\r\n");
+    struct dirent *p;
+    for(;;)
+    {
+        p = readdir(d);
+        if (!p)
+            break;
+        int len = sizeof( dirent);
+       e_Disp2.printf("%s %d\n", p->d_name, len);
+    }
+    closedir(d);
+}
+
+int OnDiskInsert(int device)
+{
+    USBFileSystem fs;
+    fs.SetDevice(device);
+    DumpFS(0,0);
+    return 0;
+}
+
+/*
+    Simple test shell to exercise mouse,keyboard,mass storage and hubs.
+    Add 2 15k pulldown resistors between D+/D- and ground, attach a usb socket and have at it.
+*/
+
+Serial pc(USBTX, USBRX);
+int GetConsoleChar()
+{
+    if (!pc.readable())
+        return -1;
+    char c = pc.getc();
+    pc.putc(c); // echo
+    return c;
+}
+void Title_TXT()
+{
+    lcd.cls();
+    lcd.locate(0, 0);
+    lcd.printf("Black One Boad");
+    lcd.locate(0, 1);
+    lcd.printf("* Android ADK *");
+}
+   
+void Title()
+{
+  e_Disp2.printf("\x1b@0Z"); // clear all
+  e_Disp2.printf("\x1b@10;0I");
+  e_Disp2.printf("\x1b@30Z");
+}
+
+void TestShell();
+
+int main()
+{
+    Title(); // Display Demo Image on Color LCD
+    pc.baud(9600);
+//    e_Disp2.printf("BlueUSB\n\rNow get a bunch of usb or bluetooth things and plug them in\r\n");
+    TestShell();
+}