Satellite Observers Workbench. NOT yet complete, just published for forum posters to \"cherry pick\" pieces of code as requiered as an example.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usbeh_device.cpp Source File

usbeh_device.cpp

00001 /****************************************************************************
00002  *    Copyright 2010 Andy Kirkham, Stellar Technologies Ltd
00003  *    
00004  *    This file is part of the Satellite Observers Workbench (SOWB).
00005  *
00006  *    SOWB is free software: you can redistribute it and/or modify
00007  *    it under the terms of the GNU General Public License as published by
00008  *    the Free Software Foundation, either version 3 of the License, or
00009  *    (at your option) any later version.
00010  *
00011  *    SOWB is distributed in the hope that it will be useful,
00012  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *    GNU General Public License for more details.
00015  *
00016  *    You should have received a copy of the GNU General Public License
00017  *    along with SOWB.  If not, see <http://www.gnu.org/licenses/>.
00018  *
00019  *    $Id: main.cpp 5 2010-07-12 20:51:11Z ajk $
00020  *    
00021  ***************************************************************************/
00022  
00023 #include "sowb.h"
00024 #include "usbeh.h"
00025 #include "usbeh_endpoint.h"
00026 #include "usbeh_device.h"
00027 
00028 int USBEH_Device::init(USBEH_deviceDescriptor *d, int hub, int port, int addr, int lowSpeed) {
00029     this->hub  = hub;
00030     this->port = port;
00031     this->addr = addr;
00032     this->flags = lowSpeed;
00033     memset(endpoints,0xFF,sizeof(endpoints));
00034     return 0;    
00035 }
00036 
00037 
00038 int USBEH_Device::setEndpointIndex (int endpoint, int endpointIndex) {
00039     for (int i = 0; i < 16; i += 2) {
00040         if (endpoints[i] == 0xFF) {
00041             endpoints[i+0] = endpoint;
00042             endpoints[i+1] = endpointIndex;
00043             return 0;
00044         }
00045     }
00046     return -1;
00047 }
00048 
00049 int USBEH_Device::getEndpointIndex (int endpoint) {
00050     for (int i = 0; i < 16; i += 2) {
00051         if (endpoints[i] == endpoint) return endpoints[i+1];
00052         if (endpoints[i] == 0xFF) break;
00053     }
00054     return -1;
00055 }