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

Committer:
techand
Date:
Fri Dec 23 04:33:33 2011 +0000
Revision:
0:7b556109fd46

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
techand 0:7b556109fd46 1 /*
techand 0:7b556109fd46 2 Copyright (c) 2010 Peter Barrett
techand 0:7b556109fd46 3
techand 0:7b556109fd46 4 Permission is hereby granted, free of charge, to any person obtaining a copy
techand 0:7b556109fd46 5 of this software and associated documentation files (the "Software"), to deal
techand 0:7b556109fd46 6 in the Software without restriction, including without limitation the rights
techand 0:7b556109fd46 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
techand 0:7b556109fd46 8 copies of the Software, and to permit persons to whom the Software is
techand 0:7b556109fd46 9 furnished to do so, subject to the following conditions:
techand 0:7b556109fd46 10
techand 0:7b556109fd46 11 The above copyright notice and this permission notice shall be included in
techand 0:7b556109fd46 12 all copies or substantial portions of the Software.
techand 0:7b556109fd46 13
techand 0:7b556109fd46 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
techand 0:7b556109fd46 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
techand 0:7b556109fd46 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
techand 0:7b556109fd46 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
techand 0:7b556109fd46 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
techand 0:7b556109fd46 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
techand 0:7b556109fd46 20 THE SOFTWARE.
techand 0:7b556109fd46 21 */
techand 0:7b556109fd46 22
techand 0:7b556109fd46 23 #include "mbed.h"
techand 0:7b556109fd46 24 #include "USBHost.h"
techand 0:7b556109fd46 25 #include "Utils.h"
techand 0:7b556109fd46 26 #include "FATFileSystem.h"
techand 0:7b556109fd46 27 #include "TextLCD.h"
techand 0:7b556109fd46 28
techand 0:7b556109fd46 29 TextLCD lcd(p10, p9, p15, p16, p22, p23);
techand 0:7b556109fd46 30
techand 0:7b556109fd46 31 Serial e_Disp2(p9, p10); // tx, rx
techand 0:7b556109fd46 32
techand 0:7b556109fd46 33 int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize);
techand 0:7b556109fd46 34 int MassStorage_Read(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
techand 0:7b556109fd46 35 int MassStorage_Write(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
techand 0:7b556109fd46 36
techand 0:7b556109fd46 37 class USBFileSystem : public FATFileSystem
techand 0:7b556109fd46 38 {
techand 0:7b556109fd46 39 int _device;
techand 0:7b556109fd46 40 u32 _blockSize;
techand 0:7b556109fd46 41 u32 _blockCount;
techand 0:7b556109fd46 42
techand 0:7b556109fd46 43 public:
techand 0:7b556109fd46 44 USBFileSystem() : FATFileSystem("usb"),_device(0),_blockSize(0),_blockCount(0)
techand 0:7b556109fd46 45 {
techand 0:7b556109fd46 46 }
techand 0:7b556109fd46 47
techand 0:7b556109fd46 48 void SetDevice(int device)
techand 0:7b556109fd46 49 {
techand 0:7b556109fd46 50 _device = device;
techand 0:7b556109fd46 51 }
techand 0:7b556109fd46 52
techand 0:7b556109fd46 53 virtual int disk_initialize()
techand 0:7b556109fd46 54 {
techand 0:7b556109fd46 55 return MassStorage_ReadCapacity(_device,&_blockCount,&_blockSize);
techand 0:7b556109fd46 56 }
techand 0:7b556109fd46 57
techand 0:7b556109fd46 58 virtual int disk_write(const char *buffer, int block_number)
techand 0:7b556109fd46 59 {
techand 0:7b556109fd46 60 return MassStorage_Write(_device,block_number,1,(u8*)buffer,_blockSize);
techand 0:7b556109fd46 61 }
techand 0:7b556109fd46 62
techand 0:7b556109fd46 63 virtual int disk_read(char *buffer, int block_number)
techand 0:7b556109fd46 64 {
techand 0:7b556109fd46 65 return MassStorage_Read(_device,block_number,1,(u8*)buffer,_blockSize);
techand 0:7b556109fd46 66 }
techand 0:7b556109fd46 67
techand 0:7b556109fd46 68 virtual int disk_sectors()
techand 0:7b556109fd46 69 {
techand 0:7b556109fd46 70 return _blockCount;
techand 0:7b556109fd46 71 }
techand 0:7b556109fd46 72 };
techand 0:7b556109fd46 73
techand 0:7b556109fd46 74 void DumpFS(int depth, int count)
techand 0:7b556109fd46 75 {
techand 0:7b556109fd46 76 DIR *d = opendir("/usb");
techand 0:7b556109fd46 77 if (!d)
techand 0:7b556109fd46 78 {
techand 0:7b556109fd46 79 e_Disp2.printf("USB file system borked\r\n");
techand 0:7b556109fd46 80 return;
techand 0:7b556109fd46 81 }
techand 0:7b556109fd46 82
techand 0:7b556109fd46 83 e_Disp2.printf("\nDumping root dir\r\n");
techand 0:7b556109fd46 84 struct dirent *p;
techand 0:7b556109fd46 85 for(;;)
techand 0:7b556109fd46 86 {
techand 0:7b556109fd46 87 p = readdir(d);
techand 0:7b556109fd46 88 if (!p)
techand 0:7b556109fd46 89 break;
techand 0:7b556109fd46 90 int len = sizeof( dirent);
techand 0:7b556109fd46 91 e_Disp2.printf("%s %d\n", p->d_name, len);
techand 0:7b556109fd46 92 }
techand 0:7b556109fd46 93 closedir(d);
techand 0:7b556109fd46 94 }
techand 0:7b556109fd46 95
techand 0:7b556109fd46 96 int OnDiskInsert(int device)
techand 0:7b556109fd46 97 {
techand 0:7b556109fd46 98 USBFileSystem fs;
techand 0:7b556109fd46 99 fs.SetDevice(device);
techand 0:7b556109fd46 100 DumpFS(0,0);
techand 0:7b556109fd46 101 return 0;
techand 0:7b556109fd46 102 }
techand 0:7b556109fd46 103
techand 0:7b556109fd46 104 /*
techand 0:7b556109fd46 105 Simple test shell to exercise mouse,keyboard,mass storage and hubs.
techand 0:7b556109fd46 106 Add 2 15k pulldown resistors between D+/D- and ground, attach a usb socket and have at it.
techand 0:7b556109fd46 107 */
techand 0:7b556109fd46 108
techand 0:7b556109fd46 109 Serial pc(USBTX, USBRX);
techand 0:7b556109fd46 110 int GetConsoleChar()
techand 0:7b556109fd46 111 {
techand 0:7b556109fd46 112 if (!pc.readable())
techand 0:7b556109fd46 113 return -1;
techand 0:7b556109fd46 114 char c = pc.getc();
techand 0:7b556109fd46 115 pc.putc(c); // echo
techand 0:7b556109fd46 116 return c;
techand 0:7b556109fd46 117 }
techand 0:7b556109fd46 118 void Title_TXT()
techand 0:7b556109fd46 119 {
techand 0:7b556109fd46 120 lcd.cls();
techand 0:7b556109fd46 121 lcd.locate(0, 0);
techand 0:7b556109fd46 122 lcd.printf("Black One Boad");
techand 0:7b556109fd46 123 lcd.locate(0, 1);
techand 0:7b556109fd46 124 lcd.printf("* Android ADK *");
techand 0:7b556109fd46 125 }
techand 0:7b556109fd46 126
techand 0:7b556109fd46 127 void Title()
techand 0:7b556109fd46 128 {
techand 0:7b556109fd46 129 e_Disp2.printf("\x1b@0Z"); // clear all
techand 0:7b556109fd46 130 e_Disp2.printf("\x1b@10;0I");
techand 0:7b556109fd46 131 e_Disp2.printf("\x1b@30Z");
techand 0:7b556109fd46 132 }
techand 0:7b556109fd46 133
techand 0:7b556109fd46 134 void TestShell();
techand 0:7b556109fd46 135
techand 0:7b556109fd46 136 int main()
techand 0:7b556109fd46 137 {
techand 0:7b556109fd46 138 Title(); // Display Demo Image on Color LCD
techand 0:7b556109fd46 139 pc.baud(9600);
techand 0:7b556109fd46 140 // e_Disp2.printf("BlueUSB\n\rNow get a bunch of usb or bluetooth things and plug them in\r\n");
techand 0:7b556109fd46 141 TestShell();
techand 0:7b556109fd46 142 }