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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001  /*
00002 Copyright (c) 2010 Peter Barrett
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
00021 */
00022 
00023 #include "mbed.h"
00024 #include "USBHost.h"
00025 #include "Utils.h"
00026 #include "FATFileSystem.h"
00027 #include "TextLCD.h"
00028 
00029 TextLCD lcd(p10, p9, p15, p16, p22, p23);
00030 
00031 Serial e_Disp2(p9, p10); // tx, rx
00032 
00033 int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize);
00034 int MassStorage_Read(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
00035 int MassStorage_Write(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
00036 
00037 class USBFileSystem : public FATFileSystem
00038 {
00039     int _device;
00040     u32 _blockSize;
00041     u32 _blockCount;
00042     
00043 public:
00044     USBFileSystem() : FATFileSystem("usb"),_device(0),_blockSize(0),_blockCount(0)
00045     {
00046     }
00047     
00048     void SetDevice(int device)
00049     {
00050         _device = device;
00051     }
00052     
00053     virtual int disk_initialize()
00054     {
00055         return MassStorage_ReadCapacity(_device,&_blockCount,&_blockSize);
00056     }
00057     
00058     virtual int disk_write(const char *buffer, int block_number)
00059     {
00060         return MassStorage_Write(_device,block_number,1,(u8*)buffer,_blockSize);
00061     }
00062     
00063     virtual int disk_read(char *buffer, int block_number)
00064     {
00065         return MassStorage_Read(_device,block_number,1,(u8*)buffer,_blockSize);
00066     }
00067         
00068     virtual int disk_sectors()
00069     {
00070         return _blockCount;
00071     }
00072 };
00073 
00074 void DumpFS(int depth, int count)
00075 {
00076     DIR *d = opendir("/usb");
00077     if (!d)
00078     {
00079         e_Disp2.printf("USB file system borked\r\n");
00080         return;
00081     }
00082 
00083     e_Disp2.printf("\nDumping root dir\r\n");
00084     struct dirent *p;
00085     for(;;)
00086     {
00087         p = readdir(d);
00088         if (!p)
00089             break;
00090         int len = sizeof( dirent);
00091        e_Disp2.printf("%s %d\n", p->d_name, len);
00092     }
00093     closedir(d);
00094 }
00095 
00096 int OnDiskInsert(int device)
00097 {
00098     USBFileSystem fs;
00099     fs.SetDevice(device);
00100     DumpFS(0,0);
00101     return 0;
00102 }
00103 
00104 /*
00105     Simple test shell to exercise mouse,keyboard,mass storage and hubs.
00106     Add 2 15k pulldown resistors between D+/D- and ground, attach a usb socket and have at it.
00107 */
00108 
00109 Serial pc(USBTX, USBRX);
00110 int GetConsoleChar()
00111 {
00112     if (!pc.readable())
00113         return -1;
00114     char c = pc.getc();
00115     pc.putc(c); // echo
00116     return c;
00117 }
00118 void Title_TXT()
00119 {
00120     lcd.cls();
00121     lcd.locate(0, 0);
00122     lcd.printf("Black One Boad");
00123     lcd.locate(0, 1);
00124     lcd.printf("* Android ADK *");
00125 }
00126    
00127 void Title()
00128 {
00129   e_Disp2.printf("\x1b@0Z"); // clear all
00130   e_Disp2.printf("\x1b@10;0I");
00131   e_Disp2.printf("\x1b@30Z");
00132 }
00133 
00134 void TestShell();
00135 
00136 int main()
00137 {
00138     Title(); // Display Demo Image on Color LCD
00139     pc.baud(9600);
00140 //    e_Disp2.printf("BlueUSB\n\rNow get a bunch of usb or bluetooth things and plug them in\r\n");
00141     TestShell();
00142 }