this is the Peter Barrett USBHostShell program, a bit modified for being a bit more talkactive, just to let u know how the USB protocol layer is going on, and all the data trasnfers. Also there is a small implementation of HID descriptors, but not functional... yet :S the aim is to at least implement the gamepad HID, and make an array of function pointer to each HID function

Dependencies:   mbed

Committer:
Sergio
Date:
Mon Sep 13 12:40:05 2010 +0000
Revision:
0:e1e03118b8fe

        

Who changed what in which revision?

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