ROBOSTEP_3rd_SHARE / Mbed 2 deprecated PS3conOut2

Dependencies:   mbed

Fork of PS3conOut by ROBOSTEP_3rd_SHARE

Committer:
ideguti
Date:
Sat Apr 18 06:27:36 2015 +0000
Revision:
0:0805c5a1b328
koueki you no program

Who changed what in which revision?

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