Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:0732b16d9a92, committed 2011-01-06
- Comitter:
- CE
- Date:
- Thu Jan 06 19:01:44 2011 +0000
- Commit message:
- R1A
Changed in this revision
diff -r 000000000000 -r 0732b16d9a92 FATFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FATFileSystem.lib Thu Jan 06 19:01:44 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_unsupported/code/fatfilesystem/ \ No newline at end of file
diff -r 000000000000 -r 0732b16d9a92 IniFileLib/IniFile.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/IniFileLib/IniFile.cpp Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,148 @@
+///////////////////////////////////////////////////////////////////////////////
+// IniFile: .ini file parser by rinos 2010
+///////////////////////////////////////////////////////////////////////////////
+
+#include "IniFile.h"
+#include <string.h>
+#include <stdlib.h>
+
+////////////////////////////////////////////////////////////////////////////////
+// defines
+const char INI_DELIM[] = " \t\r\n";
+const int INI_LINE_BUF= 256;
+
+////////////////////////////////////////////////////////////////////////////////
+// IniFile
+IniFile::IniFile(const char* file): m_fp(0) {
+ if(file) open(file);
+}
+IniFile::~IniFile(){
+ close();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// internal funcs
+IniFile::Status IniFile::strtrim(char* dst, const char* src, int dst_size){
+ if(!dst_size) return S_BUFFER_TOO_SHORT; // myStrcpy needs more than 1 byte for '\0'.
+
+ // Find valid string area
+ const char* p1 = strchr (src, '"');
+ const char* p2 = p1? strrchr(++p1, '"') : 0;
+ if(!p2){
+ // trim space or tab
+ for(p1 = src ; *p1 && strchr(INI_DELIM, *p1) ; p1++);
+ if(!*p1){ // all char is space or tab
+ *dst = 0;
+ return S_SUCCESS;
+ }
+ for(p2 = p1 + strlen(p1) ; strchr(INI_DELIM, p2[-1]) ; --p2);
+ }
+
+ // Check copy size
+ Status ret;
+ if(dst_size > p2 - p1){
+ dst_size = p2 - p1;
+ ret = S_SUCCESS;
+ } else {
+ dst_size--;
+ ret = S_BUFFER_TOO_SHORT;
+ }
+
+ // copy buffer
+ if(dst != p1) memmove(dst, p1, dst_size);
+ dst[dst_size] = 0;
+ return ret;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Access methods
+IniFile::Status IniFile::open(const char* file){
+ close();
+ m_fp = fopen(file, "r");
+ if(m_fp) return S_SUCCESS;
+
+ //printf("IniFile: Can't open %s\n", file);
+ return S_OPEN_ERROR;
+}
+
+IniFile::Status IniFile::close(){
+ if(!m_fp) return S_NOT_OPENED;
+
+ fclose(m_fp);
+ m_fp = 0;
+ return S_SUCCESS;
+}
+
+IniFile::Status IniFile::get(const char* key, char* ret, int ret_size){
+ if(!m_fp){
+ printf("IniFile::get %s S_OPEN_ERROR\n", key);
+ return S_OPEN_ERROR;
+ }
+
+ rewind(m_fp);
+ char line[INI_LINE_BUF];
+ while(fgets(line, sizeof(line), m_fp)){
+ if(*line == '#') continue; // comment line
+
+ char* p = strchr(line, '=');
+ if(!p || line == p) continue; // invalid line
+
+ *p++ = 0;
+ strtrim(line, line, p - line);
+ if(strcmp(line, key)) continue; // different key // stricmp?
+
+ // check data type
+ switch(ret_size){
+ case DTYPE_INT:
+ strtrim(line, p, INI_LINE_BUF);
+ *(int*)ret = strtoul(line, &p, 0);
+ //return p[0]? S_FORMAT_ERROR : S_SUCCESS; // check end
+ printf("IniFile::get %s INT %d\n", key, *(int*)ret);
+ return S_SUCCESS; // always success
+
+ case DTYPE_BOOL:
+ strtrim(line, p, INI_LINE_BUF);
+ switch(line[0]){
+ case 'T':
+ case 't': *(bool*)ret = true; break;
+ case 'F':
+ case 'f': *(bool*)ret = false; break;
+ default: *(bool*)ret = strtoul(line, &p, 0)? true : false;
+ }
+ printf("IniFile::get %s BOOL %d\n", key, *(bool*)ret);
+ return S_SUCCESS;
+
+ default: // string
+ {
+ Status sts = strtrim(ret, p, ret_size);
+ printf("IniFile::get %s = '%s'\n", key, ret_size? ret : "E");
+ return sts;
+ }
+ }
+ }
+ printf("IniFile::get S_NO_KEY'%s'\n", key);
+ return S_NO_KEY; // No key
+}
+IniFile::Status IniFile::get(const char* key, int& ret){
+ return get(key, (char*)&ret, DTYPE_INT);
+}
+IniFile::Status IniFile::get(const char* key, bool& ret){
+ return get(key, (char*)&ret, DTYPE_BOOL);
+}
+
+IniFile::Status IniFile::get(const IniFile::IniList* inilist){
+ Status ret = S_SUCCESS;
+ for(; inilist->key ; ++inilist){
+ Status sts = get(inilist->key, (char*)inilist->buf, inilist->typelen);
+ switch(sts){
+ case S_SUCCESS:
+ break;
+ case S_NO_KEY:
+ ret = sts; // continue
+ break;
+ default:
+ return sts; // fatal error
+ }
+ }
+ return ret;
+}
diff -r 000000000000 -r 0732b16d9a92 IniFileLib/IniFile.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/IniFileLib/IniFile.h Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,93 @@
+///////////////////////////////////////////////////////////////////////////////
+// IniFile: .ini file parser by rinos 2010
+///////////////////////////////////////////////////////////////////////////////
+
+// Ini file value (int/bool/string)
+// Key1 = 123 -> 123 (int)
+// Key2 = 0x123 -> 291 (int)
+// Key3 = FALSE -> false (bool)
+// Key4 = TRUE -> true (bool)
+// Key5 = 123 -> true (bool)
+// key6 = abc "def -> 'abc "def' (string)
+// key7 = " ghi "jkl " -> ' ghi "jkl '(string)
+// #comment line
+
+#ifndef __INI_FILE_H__
+#define __INI_FILE_H__
+
+#include "mbed.h"
+
+class IniFile{
+ // defines /////////////////////////////////////////////////////////////////
+public:
+ // data type
+ typedef enum {
+ DTYPE_INT = -1,
+ DTYPE_BOOL = -2,
+ // other string
+ } DataType;
+
+ // For the multiple read
+ struct IniList{
+ const char* key; // key name (set NULL for list end)
+ int typelen; // >0: buffer length, <0: DataType
+ void* buf; // return buffer
+ };
+
+ // error code
+ typedef enum {
+ S_SUCCESS,
+ S_OPEN_ERROR,
+ S_NOT_OPENED,
+ S_NO_KEY,
+ S_BUFFER_TOO_SHORT,
+ S_FORMAT_ERROR,
+ } Status;
+
+ // internal member/method //////////////////////////////////////////////////
+private:
+ FILE* m_fp;
+
+ // Invalid method
+protected:
+ IniFile(const IniFile& v);
+ const IniFile& operator =(const IniFile& v);
+
+public:
+ IniFile(const char* file = 0);
+ ~IniFile();
+
+ // Access methods
+ Status open(const char* file);
+ Status close();
+
+ Status get(const char* key, char* ret, int ret_size);
+ Status get(const char* key, int& ret);
+ Status get(const char* key, bool& ret);
+ Status get(const IniList* inilist);
+
+ // For easy acccess
+ static Status getval(const char* inifile, const char* key, char* ret, int ret_size){
+ return IniFile(inifile).get(key, ret, ret_size);
+ }
+ static Status getval(const char* inifile, const char* key, int& ret){
+ return IniFile(inifile).get(key, ret);
+ }
+ static Status getval(const char* inifile, const char* key, bool& ret){
+ return IniFile(inifile).get(key, ret);
+ }
+ static Status getval(const char* inifile, const IniList* inilist){
+ return IniFile(inifile).get(inilist);
+ }
+
+ // for string triming
+ static Status strtrim(char* dst, const char* src, int dst_size); // move to public
+};
+
+// for the table
+#define INIFILE_INT(key, val) {key, IniFile::DTYPE_INT, &val}
+#define INIFILE_BOOL(key, val) {key, IniFile::DTYPE_BOOL, &val}
+#define INIFILE_STR(key, buf, size) {key, size, buf}
+#define INIFILE_END 0
+
+#endif
diff -r 000000000000 -r 0732b16d9a92 MSCFileSystem.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MSCFileSystem.cpp Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,113 @@
+/* USB Mass Storage device file system
+ * Copyrigh (c) 2010, Igor Skochinsky
+ * based on SDFileStorage
+ * Copyright (c) 2008-2009, sford
+ */
+
+/* Introduction
+ * ------------
+ * TODO: write one
+ * we're basically using NXP's USBHotLite sample code, just plugging in our own FAT library
+ */
+
+#include "MSCFileSystem.h"
+#include "usbhost_inc.h"
+
+MSCFileSystem::MSCFileSystem(const char* name) :
+ FATFileSystem(name)
+{
+}
+
+void print_inquiry(USB_INT08U *inqReply)
+{
+ // see USB Mass Storage Class � UFI Command Specification,
+ // 4.2 INQUIRY Command
+ printf("Inquiry reply:\n");
+ uint8_t tmp = inqReply[0]&0x1F;
+ printf("Peripheral device type: %02Xh\n", tmp);
+ if ( tmp == 0 )
+ printf("\t- Direct access (floppy)\n");
+ else if ( tmp == 0x1F )
+ printf("\t- none (no FDD connected)\n");
+ else
+ printf("\t- unknown type\n");
+ tmp = inqReply[1] >> 7;
+ printf("Removable Media Bit: %d\n", tmp);
+ tmp = inqReply[2] & 3;
+ printf("ANSI Version: %02Xh\n", tmp);
+ if ( tmp != 0)
+ printf("\t- warning! must be 0\n");
+ tmp = (inqReply[2]>>3) & 3;
+ printf("ECMA Version: %02Xh\n", tmp);
+ if ( tmp != 0 )
+ printf("\t- warning! should be 0\n");
+ tmp = inqReply[2]>>6;
+ printf("ISO Version: %02Xh\n", tmp);
+ if ( tmp != 0 )
+ printf("\t- warning! should be 0\n");
+ tmp = inqReply[3] & 0xF;
+ printf("Response Data Format: %02Xh\n", tmp);
+ if ( tmp != 1 )
+ printf("\t- warning! should be 1\n");
+ tmp = inqReply[4];
+ printf("Additional length: %02Xh\n", tmp);
+ if ( tmp != 0x1F )
+ printf("\t- warning! should be 1Fh\n");
+ printf("Vendor Information: '%.8s'\n", &inqReply[8]);
+ printf("Product Identification: '%.16s'\n", &inqReply[16]);
+ printf("Product Revision: '%.4s'\n", &inqReply[32]);
+}
+
+int MSCFileSystem::initialise_msc()
+{
+ USB_INT32S rc;
+ USB_INT08U inquiryResult[INQUIRY_LENGTH];
+
+ //print_clock();
+ Host_Init(); /* Initialize the host controller */
+ rc = Host_EnumDev(); /* Enumerate the device connected */
+ if (rc != OK)
+ {
+ fprintf(stderr, "Could not enumerate device: %d\n", rc);
+ return rc;
+ }
+
+
+ /* Initialize the mass storage and scsi interfaces */
+ rc = MS_Init( &_blkSize, &_numBlks, inquiryResult );
+ if (rc != OK)
+ {
+ fprintf(stderr, "Could not initialize mass storage interface: %d\n", rc);
+ return rc;
+ }
+ printf("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize);
+ print_inquiry(inquiryResult);
+ // FATFileSystem supports only 512-byte blocks
+ return _blkSize == 512 ? OK : 1;
+}
+
+int MSCFileSystem::disk_initialize()
+{
+ if ( initialise_msc() != OK )
+ return 1;
+
+ return 0;
+}
+
+int MSCFileSystem::disk_write(const char *buffer, int block_number)
+{
+ if ( OK == MS_BulkSend(block_number, 1, (USB_INT08U *)buffer) )
+ return 0;
+ return 1;
+}
+
+int MSCFileSystem::disk_read(char *buffer, int block_number)
+{
+ if ( OK == MS_BulkRecv(block_number, 1, (USB_INT08U *)buffer) )
+ return 0;
+ return 1;
+}
+
+int MSCFileSystem::disk_status() { return 0; }
+int MSCFileSystem::disk_sync() { return 0; }
+int MSCFileSystem::disk_sectors() { return _numBlks; }
diff -r 000000000000 -r 0732b16d9a92 MSCFileSystem.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MSCFileSystem.h Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,49 @@
+/* USB Mass Storage device file system
+ * Copyrigh (c) 2010, Igor Skochinsky
+ * based on SDFileStorage
+ * Copyright (c) 2008-2009, sford
+ */
+
+#ifndef MSCFILESYSTEM_H
+#define MSCFILESYSTEM_H
+
+#include "mbed.h"
+#include "FATFileSystem.h"
+
+/* Class: MSCFileSystem
+ * Access the filesystem on an attached USB mass storage device (e.g. a memory stick)
+ *
+ * Example:
+ * > MSCFileSystem msc("msc");
+ * >
+ * > int main() {
+ * > FILE *fp = fopen("/msc/myfile.txt", "w");
+ * > fprintf(fp, "Hello World!\n");
+ * > fclose(fp);
+ * > }
+ */
+class MSCFileSystem : public FATFileSystem {
+public:
+
+ /* Constructor: MSCFileSystem
+ * Create the File System for accessing a USB mass storage device
+ *
+ * Parameters:
+ * name - The name used to access the filesystem
+ */
+ MSCFileSystem(const char* name);
+ virtual int disk_initialize();
+ virtual int disk_write(const char *buffer, int block_number);
+ virtual int disk_read(char *buffer, int block_number);
+ virtual int disk_status();
+ virtual int disk_sync();
+ virtual int disk_sectors();
+
+protected:
+
+ int initialise_msc();
+ uint32_t _numBlks;
+ uint32_t _blkSize;
+};
+
+#endif
diff -r 000000000000 -r 0732b16d9a92 TFT_4DGL_rev1/TFT_4DGL.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT_4DGL_rev1/TFT_4DGL.h Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,249 @@
+//
+// TFT_4DGL is a class to drive 4D Systems TFT touch screens
+//
+// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
+//
+// TFT_4DGL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// TFT_4DGL is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>.
+
+#include "mbed.h"
+
+#ifndef DEBUGMODE
+//#define DEBUGMODE 1
+#endif
+
+// Common WAIT value in millisecond
+#define TEMPO 1
+
+// 4DGL Functions values
+#define AUTOBAUD '\x55'
+#define CLS '\x45'
+#define BAUDRATE '\x51'
+#define VERSION '\x56'
+#define BCKGDCOLOR '\x42'
+#define DISPCONTROL '\x59'
+#define SETVOLUME '\x76'
+#define CIRCLE '\x43'
+#define TRIANGLE '\x47'
+#define LINE '\x4C'
+#define RECTANGLE '\x72'
+#define ELLIPSE '\x65'
+#define PIXEL '\x50'
+#define READPIXEL '\x52'
+#define SCREENCOPY '\x63'
+#define PENSIZE '\x70'
+#define SETFONT '\x46'
+#define TEXTMODE '\x4F'
+#define TEXTCHAR '\x54'
+#define GRAPHCHAR '\x74'
+#define TEXTSTRING '\x73'
+#define GRAPHSTRING '\x53'
+#define TEXTBUTTON '\x62'
+#define GETTOUCH '\x6F'
+#define WAITTOUCH '\x77'
+#define SETTOUCH '\x75'
+
+
+// Screen answers
+#define ACK '\x06'
+#define NAK '\x15'
+
+// Screen states
+#define OFF '\x00'
+#define ON '\x01'
+
+// Graphics modes
+#define SOLID '\x00'
+#define WIREFRAME '\x01'
+
+// Text modes
+#define TRANSPARENT '\x00'
+#define OPAQUE '\x01'
+
+// Fonts Sizes
+#define FONT_5X7 '\x00'
+#define FONT_8X8 '\x01'
+#define FONT_8X12 '\x02'
+#define FONT_12X16 '\x03'
+
+// Touch Values
+#define WAIT '\x00'
+#define PRESS '\x01'
+#define RELEASE '\x02'
+#define MOVE '\x03'
+#define STATUS '\x04'
+#define GETPOSITION '\x05'
+
+// Data speed
+#define BAUD_110 '\x00'
+#define BAUD_300 '\x01'
+#define BAUD_600 '\x02'
+#define BAUD_1200 '\x03'
+#define BAUD_2400 '\x04'
+#define BAUD_4800 '\x05'
+#define BAUD_9600 '\x06'
+#define BAUD_14400 '\x07'
+#define BAUD_19200 '\x09'
+#define BAUD_31250 '\x09'
+#define BAUD_38400 '\x0A'
+#define BAUD_56000 '\x0B'
+#define BAUD_57600 '\x0C'
+#define BAUD_115200 '\x0D'
+#define BAUD_128000 '\x0E'
+#define BAUD_256000 '\x0F'
+
+// Defined Colors
+#define WHITE 0xFFFFFF
+#define BLACK 0x000000
+//#define RED 0xFF0000
+#define GREEN 0x00FF00
+//#define BLUE 0x0000FF
+#define LGREY 0xBFBFBF
+#define DGREY 0x5F5F5F
+
+#define BLACK 0x000000 // Black 1
+#define CYAN 0x00ffff // Cyan 2
+#define RED 0xff0000 // Red 3
+#define DGREEN 0x00923f // Dark green 4
+#define ORANGE 0xffb400 // Orange 5
+#define GREY 0x969696 // Grey 6
+#define PINK 0xeea8a8 // Pink 7
+#define BROWN 0x996633 // Brown 8
+#define LGREEN 0x80ff80 // Light green 9
+#define BLUE 0x0000ff // Blue 10
+#define MAGENTA 0xff00ff // Magenta 11
+#define YELLOW 0xdddd00 // Yellow 12
+
+// Mode data
+#define BACKLIGHT '\x00'
+#define DISPLAY '\x01'
+#define CONTRAST '\x02'
+#define POWER '\x03'
+#define ORIENTATION '\x04'
+#define TOUCH_CTRL '\x05'
+#define IMAGE_FORMAT '\x06'
+#define PROTECT_FAT '\x08'
+
+// change this to your specific screen (newer versions) if needed
+// Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y
+#define SIZE_X 240
+#define SIZE_Y 320
+
+#define IS_LANDSCAPE 0
+#define IS_PORTRAIT 1
+
+// Screen orientation
+#define LANDSCAPE '\x01'
+#define LANDSCAPE_R '\x02'
+#define PORTRAIT '\x03'
+#define PORTRAIT_R '\x04'
+
+// Parameters
+#define ENABLE '\x00'
+#define DISABLE '\x01'
+#define RESET '\x02'
+
+#define NEW '\x00'
+#define OLD '\x01'
+
+#define DOWN '\x00'
+#define UP '\x01'
+
+#define PROTECT '\x00'
+#define UNPROTECT '\x02'
+
+//**************************************************************************
+class TFT_4DGL {
+
+public :
+
+ TFT_4DGL(PinName tx, PinName rx, PinName rst);
+
+// General Commands
+ void cls();
+ void reset();
+ void autobaud();
+ void baudrate(long);
+ void background_color(int);
+ void display_control(char, char);
+ void set_volume(char);
+
+// Graphics Commands
+ void circle(int, int, int, int);
+ void triangle(int, int, int, int, int, int, int);
+ void line(int, int, int, int, int);
+ void rectangle(int, int, int, int, int);
+ void ellipse(int, int, int, int, int);
+ void pixel(int, int, int);
+ int read_pixel(int, int);
+ void screen_copy(int, int, int, int, int, int);
+ void pen_size(char);
+ void SD_Card_Wav(char[]);
+ void Set_Volume(char);
+ void uSD_FAT_Image(char[], int, int, long);
+ void uSD_Image(int, int, long);
+ void uSD_Video(int, int, long);
+
+// Texts Commands
+ void set_font(char);
+ void text_mode(char);
+ void text_char(char, char, char, int);
+ void graphic_char(char, int, int, int, char, char);
+ void text_string(char *, char, char, char, int);
+ void graphic_string(char *, int, int, char, int, char, char);
+ void text_button(char *, char, int, int, int, char, int, char, char);
+
+ void locate(char, char);
+ void color(int);
+ void putc(char);
+ void puts(char *);
+
+// Touch Command
+ void touch_mode(char);
+ void get_touch(int *, int *);
+ void wait_touch(int);
+ void set_touch(int, int, int, int);
+ int touch_status(void);
+ void Pause_Until_Touch(int *, int *);
+
+// Screen Data
+ int type;
+ int revision;
+ int firmware;
+ int reserved1;
+ int reserved2;
+
+// Text data
+ char current_col;
+ char current_row;
+ int current_color;
+ char current_font;
+ char current_orientation;
+ char max_col;
+ char max_row;
+
+protected :
+
+ Serial _cmd;
+ DigitalOut _rst;
+
+ void freeBUFFER (void);
+ void writeBYTE (char);
+ int writeCOMMAND(char *, int);
+ int readVERSION (char *, int);
+ void getTOUCH (char *, int, int *,int *);
+ int getSTATUS (char *, int);
+ void version (void);
+};
+
+typedef unsigned char BYTE;
\ No newline at end of file
diff -r 000000000000 -r 0732b16d9a92 TFT_4DGL_rev1/TFT_4DGL_Graphics.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT_4DGL_rev1/TFT_4DGL_Graphics.cpp Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,400 @@
+//
+// TFT_4DGL is a class to drive 4D Systems TFT touch screens
+//
+// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
+//
+// TFT_4DGL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// TFT_4DGL is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>.
+
+#include "mbed.h"
+#include "TFT_4DGL.h"
+
+
+//****************************************************************************************************
+void TFT_4DGL :: circle(int x, int y , int radius, int color) { // draw a circle in (x,y)
+ char command[9]= "";
+
+ command[0] = CIRCLE;
+
+ command[1] = (x >> 8) & 0xFF;
+ command[2] = x & 0xFF;
+
+ command[3] = (y >> 8) & 0xFF;
+ command[4] = y & 0xFF;
+
+ command[5] = (radius >> 8) & 0xFF;
+ command[6] = radius & 0xFF;
+
+ int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+
+ writeCOMMAND(command, 9);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) { // draw a traingle
+ char command[15]= "";
+
+ command[0] = TRIANGLE;
+
+ command[1] = (x1 >> 8) & 0xFF;
+ command[2] = x1 & 0xFF;
+
+ command[3] = (y1 >> 8) & 0xFF;
+ command[4] = y1 & 0xFF;
+
+ command[5] = (x2 >> 8) & 0xFF;
+ command[6] = x2 & 0xFF;
+
+ command[7] = (y2 >> 8) & 0xFF;
+ command[8] = y2 & 0xFF;
+
+ command[9] = (x3 >> 8) & 0xFF;
+ command[10] = x3 & 0xFF;
+
+ command[11] = (y3 >> 8) & 0xFF;
+ command[12] = y3 & 0xFF;
+
+ int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[13] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[14] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+
+ writeCOMMAND(command, 15);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: line(int x1, int y1 , int x2, int y2, int color) { // draw a line
+ char command[11]= "";
+
+ command[0] = LINE;
+
+ command[1] = (x1 >> 8) & 0xFF;
+ command[2] = x1 & 0xFF;
+
+ command[3] = (y1 >> 8) & 0xFF;
+ command[4] = y1 & 0xFF;
+
+ command[5] = (x2 >> 8) & 0xFF;
+ command[6] = x2 & 0xFF;
+
+ command[7] = (y2 >> 8) & 0xFF;
+ command[8] = y2 & 0xFF;
+
+ int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+
+ writeCOMMAND(command, 11);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) { // draw a rectangle
+ char command[11]= "";
+
+ command[0] = RECTANGLE;
+
+ command[1] = (x1 >> 8) & 0xFF;
+ command[2] = x1 & 0xFF;
+
+ command[3] = (y1 >> 8) & 0xFF;
+ command[4] = y1 & 0xFF;
+
+ command[5] = (x2 >> 8) & 0xFF;
+ command[6] = x2 & 0xFF;
+
+ command[7] = (y2 >> 8) & 0xFF;
+ command[8] = y2 & 0xFF;
+
+ int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+
+ writeCOMMAND(command, 11);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color) { // draw an ellipse
+ char command[11]= "";
+
+ command[0] = ELLIPSE;
+
+ command[1] = (x >> 8) & 0xFF;
+ command[2] = x & 0xFF;
+
+ command[3] = (y >> 8) & 0xFF;
+ command[4] = y & 0xFF;
+
+ command[5] = (radius_x >> 8) & 0xFF;
+ command[6] = radius_x & 0xFF;
+
+ command[7] = (radius_y >> 8) & 0xFF;
+ command[8] = radius_y & 0xFF;
+
+ int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+
+ writeCOMMAND(command, 11);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: pixel(int x, int y, int color) { // draw a pixel
+ char command[7]= "";
+
+ command[0] = PIXEL;
+
+ command[1] = (x >> 8) & 0xFF;
+ command[2] = x & 0xFF;
+
+ command[3] = (y >> 8) & 0xFF;
+ command[4] = y & 0xFF;
+
+ int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[5] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[6] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+
+ writeCOMMAND(command, 7);
+}
+
+//******************************************************************************************************
+int TFT_4DGL :: read_pixel(int x, int y) { // read screen info and populate data
+
+ char command[5]= "";
+
+ command[0] = READPIXEL;
+
+ command[1] = (x >> 8) & 0xFF;
+ command[2] = x & 0xFF;
+
+ command[3] = (y >> 8) & 0xFF;
+ command[4] = y & 0xFF;
+
+ int i, temp = 0, color = 0, resp = 0;
+ char response[2] = "";
+
+ freeBUFFER();
+
+ for (i = 0; i < 5; i++) { // send all chars to serial port
+ writeBYTE(command[i]);
+ }
+
+ while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
+
+ while (_cmd.readable()) {
+ temp = _cmd.getc();
+ response[resp++] = (char)temp;
+ }
+
+ color = ((response[0] << 8) + response[1]);
+
+ return color; // WARNING : this is 16bits color, not 24bits... need to be fixed
+}
+
+//******************************************************************************************************
+void TFT_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) {
+
+ char command[13]= "";
+
+ command[0] = SCREENCOPY;
+
+ command[1] = (xs >> 8) & 0xFF;
+ command[2] = xs & 0xFF;
+
+ command[3] = (ys >> 8) & 0xFF;
+ command[4] = ys & 0xFF;
+
+ command[5] = (xd >> 8) & 0xFF;
+ command[6] = xd & 0xFF;
+
+ command[7] = (yd >> 8) & 0xFF;
+ command[8] = yd & 0xFF;
+
+ command[9] = (width >> 8) & 0xFF;
+ command[10] = width & 0xFF;
+
+ command[11] = (height >> 8) & 0xFF;
+ command[12] = height & 0xFF;
+
+ writeCOMMAND(command, 13);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: pen_size(char mode) { // set pen to SOLID or WIREFRAME
+ char command[2]= "";
+
+ command[0] = PENSIZE;
+ command[1] = mode;
+
+ writeCOMMAND(command, 2);
+}
+
+//****************************************************************************************************
+// This plays a .wav file from the FAT partition of an uSD Card
+// Not really recommended as the speaker on the uLCD-32PT is really bad!
+//****************************************************************************************************
+void TFT_4DGL :: SD_Card_Wav(char *Filename) {
+ char command[21]= "";
+ int Lgt=0;
+
+ command[0] = 0x40; //ext_cmd
+ command[1] = 0x6C; //Play Audio
+ command[2] = 0x01; //Option 0x00=Return at end, 0x01=Return now, 0x02=Stop, 0x03=Pause, 0x04=Resume, 0x05=Loop.
+ for(int i=0;Filename[i]!=0x00;i++){
+ command[i+3] = Filename[i];
+ Lgt = i;
+ }
+ command[Lgt+4] = 0x2E; //.
+ command[Lgt+5] = 0x77; //w
+ command[Lgt+6] = 0x61; //a
+ command[Lgt+7] = 0x76; //v
+ command[Lgt+8] = 0x00; //terminator
+
+ writeCOMMAND(command, Lgt+9);
+}
+
+//****************************************************************************************************
+// This sets the volume for the speaker on the uLCD-32PT
+//****************************************************************************************************
+void TFT_4DGL :: Set_Volume(char vol) {
+
+ char command[2]= "";
+
+ command[0] = 0x76; //cmd
+ command[1] = vol; //set volume
+
+ writeCOMMAND(command, 2);
+}
+
+//****************************************************************************************************
+// This displays an image on the screen that is stored on the FAT partition of an uSD Card
+// Sent Filename, X-pos, Y-pos, Sector Address - Display from the RAW partition is quicker
+//****************************************************************************************************
+void TFT_4DGL :: uSD_FAT_Image(char *Filename, int x, int y, long s) {
+ char X_MSB, X_LSB, Y_MSB, Y_LSB, S0, S1, S2, S3;
+ char command[25]= "";
+ int Lgt=0;
+
+ X_LSB = x&0x00FF;
+ X_MSB = (x >> 8);
+ Y_LSB = y&0x00FF;
+ Y_MSB = (y >> 8);
+
+ S0 = (s >> 20)&0x000000FF;
+ S1 = (s >> 16)&0x0000FF;
+ S2 = (s >> 8)&0x0000FF;
+ S3 = s&0x0000FF;;
+
+ command[0] = '@'; //ext_cmd
+ command[1] = 'm'; //FAT Image
+ for(int i=0;Filename[i]!=0x00;i++){
+ command[i+2] = Filename[i];
+ Lgt = i;
+ }
+ command[Lgt+3] = '.'; //.
+ command[Lgt+4] = 'G'; //G
+ command[Lgt+5] = 'C'; //C
+ command[Lgt+6] = 'I'; //I
+ command[Lgt+7] = 0x00; //Terminator
+ command[Lgt+8] = X_MSB; //X-Position MSB
+ command[Lgt+9] = X_LSB; //X-Position LSB
+ command[Lgt+10] = Y_MSB; //Y-Position MSB
+ command[Lgt+11] = Y_LSB; //Y-Position LSB
+ command[Lgt+12] = S0; //Sector Address 4 bytes
+ command[Lgt+13] = S1;
+ command[Lgt+14] = S2;
+ command[Lgt+15] = S3;
+
+ writeCOMMAND(command, Lgt+16);
+}
+
+//****************************************************************************************************
+// This displays an image on the screen in the NEW FORMAT
+// Sent X-pos, Y-pos, Sector Address - This is the recommended way to display images
+//****************************************************************************************************
+void TFT_4DGL :: uSD_Image(int x, int y, long s) {
+ char S1, S2, S3;
+ char X_MSB, X_LSB, Y_MSB, Y_LSB;
+ char command[9]= "";
+
+ X_LSB = x&0x00FF; //Work out the x position
+ X_MSB = (x >> 8);
+ Y_LSB = y&0x00FF; //Work out the y position
+ Y_MSB = (y >> 8);
+
+ S1 = (s >> 16)&0x0000FF; //Work out the sector address
+ S2 = (s >> 8)&0x0000FF;
+ S3 = s&0x0000FF;
+
+ command[0] = 0x40; //ext_cmd
+ command[1] = 0x49; //Display image
+ command[2] = X_MSB; //X position - 2 bytes
+ command[3] = X_LSB;
+ command[4] = Y_MSB; //Y position - 2 bytes
+ command[5] = Y_LSB;
+ command[6] = S1; //Sector address - 3 bytes
+ command[7] = S2;
+ command[8] = S3;
+
+ writeCOMMAND(command, 9);
+}
+
+//****************************************************************************************************
+// This displays an video on the screen in the NEW FORMAT
+// Sent X-pos, Y-pos, Sector Address - This is the recommended way to display video
+//****************************************************************************************************
+void TFT_4DGL :: uSD_Video(int x, int y, long s) {
+ char S1, S2, S3;
+ char X_MSB, X_LSB, Y_MSB, Y_LSB;
+ char command[10]= "";
+
+ X_LSB = x&0x00FF;
+ X_MSB = (x >> 8);
+ Y_LSB = y&0x00FF;
+ Y_MSB = (y >> 8);
+
+ S1 = (s >> 16)&0x0000FF;
+ S2 = (s >> 8)&0x0000FF;
+ S3 = s&0x0000FF;
+
+ command[0] = 0x40; //ext_cmd
+ command[1] = 0x56; //Display video
+ command[2] = X_MSB; //X position - 2 bytes
+ command[3] = X_LSB;
+ command[4] = Y_MSB; //Y position - 2 bytes
+ command[5] = Y_LSB;
+ command[6] = 0x00; //delay between frames
+ command[7] = S1; //Sector address - 3 bytes
+ command[8] = S2;
+ command[9] = S3;
+
+ writeCOMMAND(command, 10);
+}
diff -r 000000000000 -r 0732b16d9a92 TFT_4DGL_rev1/TFT_4DGL_Text.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT_4DGL_rev1/TFT_4DGL_Text.cpp Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,270 @@
+//
+// TFT_4DGL is a class to drive 4D Systems TFT touch screens
+//
+// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
+//
+// TFT_4DGL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// TFT_4DGL is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>.
+
+#include "mbed.h"
+#include "TFT_4DGL.h"
+
+//****************************************************************************************************
+void TFT_4DGL :: set_font(char mode) { // set font size
+ char command[2]= "";
+
+ int w, h, fx = 8, fy = 8;
+
+ command[0] = SETFONT;
+ command[1] = mode;
+
+ current_font = mode;
+
+ if (current_orientation == IS_PORTRAIT) {
+ w = SIZE_X;
+ h = SIZE_Y;
+ } else {
+ w = SIZE_Y;
+ h = SIZE_X;
+ }
+
+ switch (mode) {
+ case FONT_5X7 :
+ fx = 6;
+ fy = 8;
+ break;
+ case FONT_8X8 :
+ fx = 8;
+ fy = 8;
+ break;
+ case FONT_8X12 :
+ fx = 8;
+ fy = 12;
+ break;
+ case FONT_12X16 :
+ fx = 12;
+ fy = 16;
+ break;
+ }
+
+ max_col = w / fx;
+ max_row = h / fy;
+
+ writeCOMMAND(command, 2);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: text_mode(char mode) { // set text mode
+ char command[2]= "";
+
+ command[0] = TEXTMODE;
+ command[1] = mode;
+
+ writeCOMMAND(command, 2);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: text_char(char c, char col, char row, int color) { // draw a text char
+ char command[6]= "";
+
+ command[0] = TEXTCHAR;
+
+ command[1] = c;
+ command[2] = col;
+ command[3] = row;
+
+ int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+
+ writeCOMMAND(command, 8);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: graphic_char(char c, int x, int y, int color, char width, char height) { // draw a graphic char
+ char command[10]= "";
+
+ command[0] = GRAPHCHAR;
+
+ command[1] = c;
+
+ command[2] = (x >> 8) & 0xFF;
+ command[3] = x & 0xFF;
+
+ command[4] = (y >> 8) & 0xFF;
+ command[5] = y & 0xFF;
+
+ int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+
+ command[8] = width;
+
+ command[9] = height;
+
+ writeCOMMAND(command, 10);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: text_string(char *s, char col, char row, char font, int color) { // draw a text string
+
+ char command[1000]= "";
+ int size = strlen(s);
+ int i = 0;
+
+ command[0] = TEXTSTRING;
+
+ command[1] = col;
+ command[2] = row;
+
+ command[3] = font;
+
+ int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+
+ for (i=0; i<size; i++) command[6+i] = s[i];
+
+ command[6+size] = 0;
+
+ writeCOMMAND(command, 7 + size);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: graphic_string(char *s, int x, int y, char font, int color, char width, char height) { // draw a text string
+
+ char command[1000]= "";
+ int size = strlen(s);
+ int i = 0;
+
+ command[0] = GRAPHSTRING;
+
+ command[1] = (x >> 8) & 0xFF;
+ command[2] = x & 0xFF;
+
+ command[3] = (y >> 8) & 0xFF;
+ command[4] = y & 0xFF;
+
+ command[5] = font;
+
+ int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+
+ command[8] = width;
+
+ command[9] = height;
+
+ for (i=0; i<size; i++) command[10+i] = s[i];
+
+ command[10+size] = 0;
+
+ writeCOMMAND(command, 11 + size);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: text_button(char *s, char mode, int x, int y, int button_color, char font, int text_color, char width, char height) { // draw a text string
+
+ char command[1000]= "";
+ int size = strlen(s);
+ int i = 0, red5, green6, blue5;
+
+ command[0] = TEXTBUTTON;
+
+ command[1] = mode;
+
+ command[2] = (x >> 8) & 0xFF;
+ command[3] = x & 0xFF;
+
+ command[4] = (y >> 8) & 0xFF;
+ command[5] = y & 0xFF;
+
+ red5 = (button_color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ green6 = (button_color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ blue5 = (button_color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+
+ command[8] = font;
+
+ red5 = (text_color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ green6 = (text_color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ blue5 = (text_color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+
+ command[11] = width;
+
+ command[12] = height;
+
+ for (i=0; i<size; i++) command[13+i] = s[i];
+
+ command[13+size] = 0;
+
+ writeCOMMAND(command, 14 + size);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: locate(char col, char row) { // place text curssor at col, row
+ current_col = col;
+ current_row = row;
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: color(int color) { // set text color
+ current_color = color;
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: putc(char c) { // place char at current cursor position
+
+ text_char(c, current_col++, current_row, current_color);
+
+ if (current_col == max_col) {
+ current_col = 0;
+ current_row++;
+ }
+ if (current_row == max_row) {
+ current_row = 0;
+ }
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: puts(char *s) { // place string at current cursor position
+
+ text_string(s, current_col, current_row, current_font, current_color);
+
+ current_col += strlen(s);
+
+ if (current_col >= max_col) {
+ current_row += current_col / max_col;
+ current_col %= max_col;
+ }
+ if (current_row >= max_row) {
+ current_row %= max_row;
+ }
+}
\ No newline at end of file
diff -r 000000000000 -r 0732b16d9a92 TFT_4DGL_rev1/TFT_4DGL_Touch.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT_4DGL_rev1/TFT_4DGL_Touch.cpp Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,109 @@
+//
+// TFT_4DGL is a class to drive 4D Systems TFT touch screens
+//
+// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
+//
+// TFT_4DGL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// TFT_4DGL is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>.
+
+#include "mbed.h"
+#include "TFT_4DGL.h"
+
+//******************************************************************************************************
+void TFT_4DGL :: touch_mode(char mode) { // Send touch mode (WAIT, PRESS, RELEASE or MOVE)
+
+ char command[2]= "";
+
+ command[0] = GETTOUCH;
+ command[1] = mode;
+
+ writeCOMMAND(command, 2);
+}
+
+//******************************************************************************************************
+void TFT_4DGL :: get_touch(int *x, int *y) { // Get the touch coordinates
+
+ char command[2] = "";
+
+ command[0] = GETTOUCH;
+ command[1] = GETPOSITION;
+
+ getTOUCH(command, 2, x, y);
+}
+
+//******************************************************************************************************
+int TFT_4DGL :: touch_status(void) { // Get the touch screen status
+
+ char command[2] = "";
+
+ command[0] = GETTOUCH;
+ command[1] = STATUS;
+
+ return getSTATUS(command, 2);
+}
+
+
+//******************************************************************************************************
+void TFT_4DGL :: wait_touch(int delay) { // wait until touch within a delay in milliseconds
+
+ char command[3]= "";
+
+ command[0] = WAITTOUCH;
+
+ command[1] = (delay >> 8) & 0xFF;
+ command[2] = delay & 0xFF;
+
+ writeCOMMAND(command, 3);
+}
+
+//******************************************************************************************************
+void TFT_4DGL :: set_touch(int x1, int y1 , int x2, int y2) { // define touch area
+
+ char command[9]= "";
+
+ command[0] = SETTOUCH;
+
+ command[1] = (x1 >> 8) & 0xFF;
+ command[2] = x1 & 0xFF;
+
+ command[3] = (y1 >> 8) & 0xFF;
+ command[4] = y1 & 0xFF;
+
+ command[5] = (x2 >> 8) & 0xFF;
+ command[6] = x2 & 0xFF;
+
+ command[7] = (y2 >> 8) & 0xFF;
+ command[8] = y2 & 0xFF;
+
+ writeCOMMAND(command, 9);
+}
+
+//******************************************************************************************************
+// There is no way to have the uLCD-32PT trigger an interrupt when touched.
+// This function polls the screen and waits for a touch to regiester
+//******************************************************************************************************
+void TFT_4DGL :: Pause_Until_Touch(int *x, int *y) { // Actually waits for a TouchScreen release!
+
+ char TouchStatus = 0; //Initalise the TouchStatus as 0 = no touch activity
+ char command[2] = "";
+
+ do{
+ TouchStatus = touch_status(); //Get the touchscreen status
+ wait(0.1);
+ }while (TouchStatus != 2);
+
+ command[0] = GETTOUCH;
+ command[1] = GETPOSITION;
+
+ getTOUCH(command, 2, x, y);
+}
\ No newline at end of file
diff -r 000000000000 -r 0732b16d9a92 TFT_4DGL_rev1/TFT_4DGL_main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT_4DGL_rev1/TFT_4DGL_main.cpp Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,394 @@
+//
+// TFT_4DGL is a class to drive 4D Systems TFT touch screens
+//
+// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
+//
+// TFT_4DGL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// TFT_4DGL is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>.
+
+#include "mbed.h"
+#include "TFT_4DGL.h"
+
+Serial pc(USBTX,USBRX);
+//DigitalOut led1(LED1), led2(LED2);
+
+//******************************************************************************************************
+TFT_4DGL :: TFT_4DGL(PinName tx, PinName rx, PinName rst) : _cmd(tx, rx), _rst(rst) { // Constructor
+
+#if DEBUGMODE
+ pc.baud(115200);
+
+ pc.printf("\n\n\n");
+ pc.printf("********************\n\r");
+ pc.printf("TFT_4DGL CONSTRUCTOR\n\r");
+ pc.printf("********************\n\r");
+#endif
+
+ _rst = 1; // put RESET pin to high to start TFT screen
+
+ reset();
+ autobaud(); // send autobaud command
+ baudrate(256000); // set the initial baudrate to 256kbps - fastest supported by uLCD-32PT
+ cls(); // clear screen
+
+ current_col = 0; // initial cursor col
+ current_row = 0; // initial cursor row
+ current_color = WHITE; // initial text color
+ current_orientation = IS_PORTRAIT; // initial screen orientation
+
+ set_font(FONT_5X7); // initial font
+ text_mode(TRANSPARENT); // initial text mode
+ display_control(0x06,0x00); // initial Image control new format
+}
+
+//******************************************************************************************************
+void TFT_4DGL :: writeBYTE(char c) { // send a BYTE command to screen
+
+ _cmd.putc(c);
+
+#if DEBUGMODE
+ pc.printf(" Char sent : 0x%02X ",c);
+ pc.putc(c);
+ pc.printf(" \n\r");
+#endif
+
+}
+
+//******************************************************************************************************
+void TFT_4DGL :: freeBUFFER(void) { // Clear serial buffer before writing command
+
+ while (_cmd.readable()) _cmd.getc(); // clear buffer garbage
+}
+
+//******************************************************************************************************
+int TFT_4DGL :: writeCOMMAND(char *command, int number) { // send several BYTES making a command and return an answer
+
+#if DEBUGMODE
+ pc.printf("\n\r");
+ pc.printf("New COMMAND : 0x%02X\n\r", command[0]);
+#endif
+ int i, resp = 0;
+ freeBUFFER();
+
+ for (i = 0; i < number; i++) writeBYTE(command[i]); // send command to serial port
+
+ while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
+ if (_cmd.readable()) resp = _cmd.getc(); // read response if any
+ switch (resp) {
+ case ACK : // if OK return 1
+ resp = 1;
+ break;
+ case NAK : // if NOK return -1
+ resp = -1;
+ break;
+ default :
+ resp = 0; // else return 0
+ break;
+ }
+#if DEBUGMODE
+ pc.printf(" Answer received : %d\n\r",resp);
+#endif
+
+ return resp;
+}
+
+//**************************************************************************
+void TFT_4DGL :: reset() { // Reset Screen
+
+ _rst = 0; // put RESET pin to low
+ wait_ms(TEMPO); // wait a few milliseconds for command reception
+ _rst = 1; // put RESET back to high
+ wait(3); // wait 3s for screen to restart
+
+ freeBUFFER(); // clean buffer from possible garbage
+}
+
+//**************************************************************************
+void TFT_4DGL :: autobaud() { // send AutoBaud command (9600)
+ char command[1] = "";
+ command[0] = AUTOBAUD;
+ writeCOMMAND(command, 1);
+}
+
+//**************************************************************************
+void TFT_4DGL :: cls() { // clear screen
+ char command[1] = "";
+ command[0] = CLS;
+ writeCOMMAND(command, 1);
+}
+
+//**************************************************************************
+void TFT_4DGL :: version() { // get API version
+ char command[2] = "";
+ command[0] = VERSION;
+ command[1] = OFF;
+ readVERSION(command, 2);
+}
+
+//**************************************************************************
+void TFT_4DGL :: baudrate(long speed) { // set screen baud rate
+ char command[2]= "";
+ command[0] = BAUDRATE;
+ switch (speed) {
+ case 110 :
+ command[1] = BAUD_110;
+ break;
+ case 300 :
+ command[1] = BAUD_300;
+ break;
+ case 600 :
+ command[1] = BAUD_600;
+ break;
+ case 1200 :
+ command[1] = BAUD_1200;
+ break;
+ case 2400 :
+ command[1] = BAUD_2400;
+ break;
+ case 4800 :
+ command[1] = BAUD_4800;
+ break;
+ case 9600 :
+ command[1] = BAUD_9600;
+ break;
+ case 14400 :
+ command[1] = BAUD_14400;
+ break;
+ case 19200 :
+ command[1] = BAUD_19200;
+ break;
+ case 31250 :
+ command[1] = BAUD_31250;
+ break;
+ case 38400 :
+ command[1] = BAUD_38400;
+ break;
+ case 56000 :
+ command[1] = BAUD_56000;
+ break;
+ case 57600 :
+ command[1] = BAUD_57600;
+ break;
+ case 115200 :
+ command[1] = BAUD_115200;
+ break;
+ case 128000 :
+ command[1] = BAUD_128000;
+ break;
+ case 256000 :
+ command[1] = BAUD_256000;
+ break;
+ default :
+ command[1] = BAUD_9600;
+ speed = 9600;
+ break;
+ }
+
+#if DEBUGMODE
+ pc.printf("\n\r");
+ pc.printf("New COMMAND : 0x%02X\n\r", command[0]);
+#endif
+
+ int i, resp = 0;
+ freeBUFFER();
+
+ if(speed==256000)
+ speed=281000; //If baud rate is 256K comm at 281k - as instructed by 4DGL
+
+ for (i = 0; i <2; i++) writeBYTE(command[i]); // send command to serial port
+ _cmd.baud(speed); // set mbed to same speed
+
+ while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
+
+ if (_cmd.readable()) resp = _cmd.getc(); // read response if any
+ switch (resp) {
+ case ACK : // if OK return 1
+ resp = 1;
+ break;
+ case NAK : // if NOK return -1
+ resp = -1;
+ break;
+ default :
+ resp = 0; // else return 0
+ break;
+ }
+#if DEBUGMODE
+ pc.printf(" Baudrate reply received : %d\n\r",resp);
+#endif
+}
+
+//******************************************************************************************************
+int TFT_4DGL :: readVERSION(char *command, int number) { // read screen info and populate data
+
+ int i, temp = 0, resp = 0;
+ char response[5] = "";
+
+ freeBUFFER();
+
+ for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port
+
+ while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
+
+ while (_cmd.readable()) {
+ temp = _cmd.getc();
+ response[resp++] = (char)temp;
+ }
+ switch (resp) {
+ case 5 : // if OK populate data and return 1
+ type = response[0];
+ revision = response[1];
+ firmware = response[2];
+ reserved1 = response[3];
+ reserved2 = response[4];
+ resp = 1;
+ break;
+ default :
+ resp = 0; // else return 0
+ break;
+ }
+ return resp;
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: background_color(int color) { // set screen background color
+ char command[3]= ""; // input color is in 24bits like 0xRRGGBB
+
+ command[0] = BCKGDCOLOR;
+
+ int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+
+ writeCOMMAND(command, 3);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: display_control(char mode, char value) { // set screen mode to value
+ char command[3]= "";
+
+ command[0] = DISPCONTROL;
+ command[1] = mode;
+ command[2] = value;
+
+ if (mode == ORIENTATION) {
+ switch (value) {
+ case LANDSCAPE :
+ current_orientation = IS_LANDSCAPE;
+ break;
+ case LANDSCAPE_R :
+ current_orientation = IS_LANDSCAPE;
+ break;
+ case PORTRAIT :
+ current_orientation = IS_PORTRAIT;
+ break;
+ case PORTRAIT_R :
+ current_orientation = IS_PORTRAIT;
+ break;
+ }
+ set_font(current_font);
+ }
+ writeCOMMAND(command, 3);
+
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: set_volume(char value) { // set sound volume to value
+ char command[2]= "";
+
+ command[0] = SETVOLUME;
+ command[1] = value;
+
+ writeCOMMAND(command, 2);
+}
+
+
+//******************************************************************************************************
+void TFT_4DGL :: getTOUCH(char *command, int number, int *x, int *y) { // read screen info and populate data
+
+#if DEBUGMODE
+ pc.printf("\n\r");
+ pc.printf("New COMMAND : 0x%02X\n\r", command[0]);
+#endif
+ int i, temp = 0, resp = 0;
+ char response[5] = "";
+
+ freeBUFFER();
+
+ for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port
+
+ while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
+
+ while (_cmd.readable()) {
+ temp = _cmd.getc();
+ response[resp++] = (char)temp;
+ }
+
+#if DEBUGMODE
+ pc.printf(" Answer received %d : 0x%02X 0x%02X 0x%02X 0x%02X\n\r", resp, response[0], response[1], response[2], response[3]);
+#endif
+
+ switch (resp) {
+ case 4 : // if OK populate data
+ *x = ((response[0]<<8)+ response[1]) * (response[0] != 0xFF);
+ *y = ((response[2]<<8)+ response[3]) * (response[2] != 0xFF);
+ break;
+ default :
+ *x = -1;
+ *y = -1;
+ break;
+ }
+
+#if DEBUGMODE
+ pc.printf(" X,Y : %03d,%03d\n\r", *x, *y);
+#endif
+}
+
+//******************************************************************************************************
+int TFT_4DGL :: getSTATUS(char *command, int number) { // read screen info and populate data
+
+#if DEBUGMODE
+ pc.printf("\n\r");
+ pc.printf("New COMMAND : 0x%02X\n\r", command[0]);
+#endif
+
+ int i, temp = 0, resp = 0;
+ char response[5] = "";
+
+ freeBUFFER();
+
+ for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port
+
+ while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
+
+ while (_cmd.readable()) {
+ temp = _cmd.getc();
+ response[resp++] = (char)temp;
+ }
+ switch (resp) {
+ case 4 :
+ resp = (int)response[1]; // if OK populate data
+ break;
+ default :
+ resp = -1; // else return 0
+ break;
+ }
+
+#if DEBUGMODE
+ pc.printf(" Answer received : %d\n\r", resp);
+#endif
+
+ return resp;
+}
\ No newline at end of file
diff -r 000000000000 -r 0732b16d9a92 USBHostLite/usbhost_cpu.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBHostLite/usbhost_cpu.h Thu Jan 06 19:01:44 2011 +0000 @@ -0,0 +1,35 @@ +/* +************************************************************************************************************** +* NXP USB Host Stack +* +* (c) Copyright 2008, NXP SemiConductors +* (c) Copyright 2008, OnChip Technologies LLC +* All Rights Reserved +* +* www.nxp.com +* www.onchiptech.com +* +* File : usbhost_cpu.h +* Programmer(s) : Ravikanth.P +* Version : +* +************************************************************************************************************** +*/ + +#ifndef USBHOST_CPU_H +#define USBHOST_CPU_H + +/* +************************************************************************************************************** +* TYPE DEFINITIONS OF DATA TYPES +************************************************************************************************************** +*/ + +typedef unsigned int USB_INT32U; +typedef signed int USB_INT32S; +typedef unsigned short USB_INT16U; +typedef signed short USB_INT16S; +typedef unsigned char USB_INT08U; +typedef signed char USB_INT08S; + +#endif
diff -r 000000000000 -r 0732b16d9a92 USBHostLite/usbhost_err.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBHostLite/usbhost_err.h Thu Jan 06 19:01:44 2011 +0000 @@ -0,0 +1,63 @@ +/* +************************************************************************************************************** +* NXP USB Host Stack +* +* (c) Copyright 2008, NXP SemiConductors +* (c) Copyright 2008, OnChip Technologies LLC +* All Rights Reserved +* +* www.nxp.com +* www.onchiptech.com +* +* File : usbhost_err.h +* Programmer(s) : Ravikanth.P +* Version : +* +************************************************************************************************************** +*/ + +#ifndef USBHOST_ERR_H +#define USBHOST_ERR_H + + +/* +************************************************************************************************************** +* GENERAL DEFINITIONS +************************************************************************************************************** +*/ + +#define OK 0 +#define MATCH_FOUND 0 + +/* +************************************************************************************************************** +* HOST CONTROLLER SPECIFIC ERROR CODES +************************************************************************************************************** +*/ + +#define ERR_TD_FAIL -1 + +/* +************************************************************************************************************** +* MASS STORAGE SPECIFIC ERROR CODES +************************************************************************************************************** +*/ + +#define ERR_MS_CMD_FAILED -10 +#define ERR_BAD_CONFIGURATION -11 +#define ERR_NO_MS_INTERFACE -12 + +/* +************************************************************************************************************** +* FAT SPECIFIC ERROR CODES +************************************************************************************************************** +*/ + +#define MATCH_NOT_FOUND -20 +#define ERR_FAT_NOT_SUPPORTED -21 +#define ERR_OPEN_LIMIT_REACHED -22 +#define ERR_INVALID_BOOT_SIG -23 +#define ERR_INVALID_BOOT_SEC -24 +#define ERR_ROOT_DIR_FULL -25 + +#endif
diff -r 000000000000 -r 0732b16d9a92 USBHostLite/usbhost_inc.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBHostLite/usbhost_inc.h Thu Jan 06 19:01:44 2011 +0000 @@ -0,0 +1,39 @@ +/* +************************************************************************************************************** +* NXP USB Host Stack +* +* (c) Copyright 2008, NXP SemiConductors +* (c) Copyright 2008, OnChip Technologies LLC +* All Rights Reserved +* +* www.nxp.com +* www.onchiptech.com +* +* File : usbhost_inc.h +* Programmer(s) : Ravikanth.P +* Version : +* +************************************************************************************************************** +*/ + +#ifndef USBHOST_INC_H +#define USBHOST_INC_H + +/* +************************************************************************************************************** +* INCLUDE HEADER FILES +************************************************************************************************************** +*/ + +#include "usbhost_cpu.h" +#include "usbhost_err.h" +#include "usbhost_lpc17xx.h" +#include "usbhost_ms.h" +#include "mbed.h" + + +#ifdef TARGET_LPC2368 +#error "There is no USB host on the LPC2368!" +#endif + +#endif
diff -r 000000000000 -r 0732b16d9a92 USBHostLite/usbhost_lpc17xx.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHostLite/usbhost_lpc17xx.c Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,820 @@
+/*
+**************************************************************************************************************
+* NXP USB Host Stack
+*
+* (c) Copyright 2008, NXP SemiConductors
+* (c) Copyright 2008, OnChip Technologies LLC
+* All Rights Reserved
+*
+* www.nxp.com
+* www.onchiptech.com
+*
+* File : usbhost_lpc17xx.c
+* Programmer(s) : Ravikanth.P
+* Version :
+*
+**************************************************************************************************************
+*/
+
+/*
+**************************************************************************************************************
+* INCLUDE HEADER FILES
+**************************************************************************************************************
+*/
+
+#include "usbhost_lpc17xx.h"
+
+/*
+**************************************************************************************************************
+* GLOBAL VARIABLES
+**************************************************************************************************************
+*/
+int gUSBConnected;
+
+volatile USB_INT32U HOST_RhscIntr = 0; /* Root Hub Status Change interrupt */
+volatile USB_INT32U HOST_WdhIntr = 0; /* Semaphore to wait until the TD is submitted */
+volatile USB_INT08U HOST_TDControlStatus = 0;
+volatile HCED *EDCtrl; /* Control endpoint descriptor structure */
+volatile HCED *EDBulkIn; /* BulkIn endpoint descriptor structure */
+volatile HCED *EDBulkOut; /* BulkOut endpoint descriptor structure */
+volatile HCTD *TDHead; /* Head transfer descriptor structure */
+volatile HCTD *TDTail; /* Tail transfer descriptor structure */
+volatile HCCA *Hcca; /* Host Controller Communications Area structure */
+ USB_INT16U *TDBufNonVol; /* Identical to TDBuffer just to reduce compiler warnings */
+volatile USB_INT08U *TDBuffer; /* Current Buffer Pointer of transfer descriptor */
+
+// USB host structures
+// AHB SRAM block 1
+#define HOSTBASEADDR 0x2007C000
+// reserve memory for the linker
+static USB_INT08U HostBuf[0x200] __attribute__((at(HOSTBASEADDR)));
+/*
+**************************************************************************************************************
+* DELAY IN MILLI SECONDS
+*
+* Description: This function provides a delay in milli seconds
+*
+* Arguments : delay The delay required
+*
+* Returns : None
+*
+**************************************************************************************************************
+*/
+
+void Host_DelayMS (USB_INT32U delay)
+{
+ volatile USB_INT32U i;
+
+
+ for (i = 0; i < delay; i++) {
+ Host_DelayUS(1000);
+ }
+}
+
+/*
+**************************************************************************************************************
+* DELAY IN MICRO SECONDS
+*
+* Description: This function provides a delay in micro seconds
+*
+* Arguments : delay The delay required
+*
+* Returns : None
+*
+**************************************************************************************************************
+*/
+
+void Host_DelayUS (USB_INT32U delay)
+{
+ volatile USB_INT32U i;
+
+
+ for (i = 0; i < (4 * delay); i++) { /* This logic was tested. It gives app. 1 micro sec delay */
+ ;
+ }
+}
+
+// bits of the USB/OTG clock control register
+#define HOST_CLK_EN (1<<0)
+#define DEV_CLK_EN (1<<1)
+#define PORTSEL_CLK_EN (1<<3)
+#define AHB_CLK_EN (1<<4)
+
+// bits of the USB/OTG clock status register
+#define HOST_CLK_ON (1<<0)
+#define DEV_CLK_ON (1<<1)
+#define PORTSEL_CLK_ON (1<<3)
+#define AHB_CLK_ON (1<<4)
+
+// we need host clock, OTG/portsel clock and AHB clock
+#define CLOCK_MASK (HOST_CLK_EN | PORTSEL_CLK_EN | AHB_CLK_EN)
+
+/*
+**************************************************************************************************************
+* INITIALIZE THE HOST CONTROLLER
+*
+* Description: This function initializes lpc17xx host controller
+*
+* Arguments : None
+*
+* Returns :
+*
+**************************************************************************************************************
+*/
+void Host_Init (void)
+{
+ PRINT_Log("In Host_Init\n");
+ NVIC_DisableIRQ(USB_IRQn); /* Disable the USB interrupt source */
+
+ // turn on power for USB
+ LPC_SC->PCONP |= (1UL<<31);
+ // Enable USB host clock, port selection and AHB clock
+ LPC_USB->USBClkCtrl |= CLOCK_MASK;
+ // Wait for clocks to become available
+ while ((LPC_USB->USBClkSt & CLOCK_MASK) != CLOCK_MASK)
+ ;
+
+ // it seems the bits[0:1] mean the following
+ // 0: U1=device, U2=host
+ // 1: U1=host, U2=host
+ // 2: reserved
+ // 3: U1=host, U2=device
+ // NB: this register is only available if OTG clock (aka "port select") is enabled!!
+ // since we don't care about port 2, set just bit 0 to 1 (U1=host)
+ LPC_USB->OTGStCtrl |= 1;
+
+ // now that we've configured the ports, we can turn off the portsel clock
+ LPC_USB->USBClkCtrl &= ~PORTSEL_CLK_EN;
+
+ // power pins are not connected on mbed, so we can skip them
+ /* P1[18] = USB_UP_LED, 01 */
+ /* P1[19] = /USB_PPWR, 10 */
+ /* P1[22] = USB_PWRD, 10 */
+ /* P1[27] = /USB_OVRCR, 10 */
+ /*LPC_PINCON->PINSEL3 &= ~((3<<4) | (3<<6) | (3<<12) | (3<<22));
+ LPC_PINCON->PINSEL3 |= ((1<<4)|(2<<6) | (2<<12) | (2<<22)); // 0x00802080
+ */
+
+ // configure USB D+/D- pins
+ /* P0[29] = USB_D+, 01 */
+ /* P0[30] = USB_D-, 01 */
+ LPC_PINCON->PINSEL1 &= ~((3<<26) | (3<<28));
+ LPC_PINCON->PINSEL1 |= ((1<<26)|(1<<28)); // 0x14000000
+
+ PRINT_Log("Initializing Host Stack\n");
+
+ Hcca = (volatile HCCA *)(HostBuf+0x000);
+ TDHead = (volatile HCTD *)(HostBuf+0x100);
+ TDTail = (volatile HCTD *)(HostBuf+0x110);
+ EDCtrl = (volatile HCED *)(HostBuf+0x120);
+ EDBulkIn = (volatile HCED *)(HostBuf+0x130);
+ EDBulkOut = (volatile HCED *)(HostBuf+0x140);
+ TDBuffer = (volatile USB_INT08U *)(HostBuf+0x150);
+
+ /* Initialize all the TDs, EDs and HCCA to 0 */
+ Host_EDInit(EDCtrl);
+ Host_EDInit(EDBulkIn);
+ Host_EDInit(EDBulkOut);
+ Host_TDInit(TDHead);
+ Host_TDInit(TDTail);
+ Host_HCCAInit(Hcca);
+
+ Host_DelayMS(50); /* Wait 50 ms before apply reset */
+ LPC_USB->HcControl = 0; /* HARDWARE RESET */
+ LPC_USB->HcControlHeadED = 0; /* Initialize Control list head to Zero */
+ LPC_USB->HcBulkHeadED = 0; /* Initialize Bulk list head to Zero */
+
+ /* SOFTWARE RESET */
+ LPC_USB->HcCommandStatus = OR_CMD_STATUS_HCR;
+ LPC_USB->HcFmInterval = DEFAULT_FMINTERVAL; /* Write Fm Interval and Largest Data Packet Counter */
+
+ /* Put HC in operational state */
+ LPC_USB->HcControl = (LPC_USB->HcControl & (~OR_CONTROL_HCFS)) | OR_CONTROL_HC_OPER;
+ LPC_USB->HcRhStatus = OR_RH_STATUS_LPSC; /* Set Global Power */
+
+ LPC_USB->HcHCCA = (USB_INT32U)Hcca;
+ LPC_USB->HcInterruptStatus |= LPC_USB->HcInterruptStatus; /* Clear Interrrupt Status */
+
+
+ LPC_USB->HcInterruptEnable = OR_INTR_ENABLE_MIE |
+ OR_INTR_ENABLE_WDH |
+ OR_INTR_ENABLE_RHSC;
+
+ NVIC_SetPriority(USB_IRQn, 0); /* highest priority */
+ /* Enable the USB Interrupt */
+ NVIC_EnableIRQ(USB_IRQn);
+ PRINT_Log("Host Initialized\n");
+}
+
+/*
+**************************************************************************************************************
+* INTERRUPT SERVICE ROUTINE
+*
+* Description: This function services the interrupt caused by host controller
+*
+* Arguments : None
+*
+* Returns : None
+*
+**************************************************************************************************************
+*/
+
+void USB_IRQHandler (void) __irq
+{
+ USB_INT32U int_status;
+ USB_INT32U ie_status;
+
+ int_status = LPC_USB->HcInterruptStatus; /* Read Interrupt Status */
+ ie_status = LPC_USB->HcInterruptEnable; /* Read Interrupt enable status */
+
+ if (!(int_status & ie_status)) {
+ return;
+ } else {
+
+ int_status = int_status & ie_status;
+ if (int_status & OR_INTR_STATUS_RHSC) { /* Root hub status change interrupt */
+ if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CSC) {
+ if (LPC_USB->HcRhStatus & OR_RH_STATUS_DRWE) {
+ /*
+ * When DRWE is on, Connect Status Change
+ * means a remote wakeup event.
+ */
+ HOST_RhscIntr = 1;// JUST SOMETHING FOR A BREAKPOINT
+ }
+ else {
+ /*
+ * When DRWE is off, Connect Status Change
+ * is NOT a remote wakeup event
+ */
+ if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CCS) {
+ if (!gUSBConnected) {
+ HOST_TDControlStatus = 0;
+ HOST_WdhIntr = 0;
+ HOST_RhscIntr = 1;
+ gUSBConnected = 1;
+ }
+ else
+ PRINT_Log("Spurious status change (connected)?\n");
+ } else {
+ if (gUSBConnected) {
+ LPC_USB->HcInterruptEnable = 0; // why do we get multiple disc. rupts???
+ HOST_RhscIntr = 0;
+ gUSBConnected = 0;
+ }
+ else
+ PRINT_Log("Spurious status change (disconnected)?\n");
+ }
+ }
+ LPC_USB->HcRhPortStatus1 = OR_RH_PORT_CSC;
+ }
+ if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRSC) {
+ LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC;
+ }
+ }
+ if (int_status & OR_INTR_STATUS_WDH) { /* Writeback Done Head interrupt */
+ HOST_WdhIntr = 1;
+ HOST_TDControlStatus = (TDHead->Control >> 28) & 0xf;
+ }
+ LPC_USB->HcInterruptStatus = int_status; /* Clear interrupt status register */
+ }
+ return;
+}
+
+/*
+**************************************************************************************************************
+* PROCESS TRANSFER DESCRIPTOR
+*
+* Description: This function processes the transfer descriptor
+*
+* Arguments : ed Endpoint descriptor that contains this transfer descriptor
+* token SETUP, IN, OUT
+* buffer Current Buffer Pointer of the transfer descriptor
+* buffer_len Length of the buffer
+*
+* Returns : OK if TD submission is successful
+* ERROR if TD submission fails
+*
+**************************************************************************************************************
+*/
+
+USB_INT32S Host_ProcessTD (volatile HCED *ed,
+ volatile USB_INT32U token,
+ volatile USB_INT08U *buffer,
+ USB_INT32U buffer_len)
+{
+ volatile USB_INT32U td_toggle;
+
+
+ if (ed == EDCtrl) {
+ if (token == TD_SETUP) {
+ td_toggle = TD_TOGGLE_0;
+ } else {
+ td_toggle = TD_TOGGLE_1;
+ }
+ } else {
+ td_toggle = 0;
+ }
+ TDHead->Control = (TD_ROUNDING |
+ token |
+ TD_DELAY_INT(0) |
+ td_toggle |
+ TD_CC);
+ TDTail->Control = 0;
+ TDHead->CurrBufPtr = (USB_INT32U) buffer;
+ TDTail->CurrBufPtr = 0;
+ TDHead->Next = (USB_INT32U) TDTail;
+ TDTail->Next = 0;
+ TDHead->BufEnd = (USB_INT32U)(buffer + (buffer_len - 1));
+ TDTail->BufEnd = 0;
+
+ ed->HeadTd = (USB_INT32U)TDHead | ((ed->HeadTd) & 0x00000002);
+ ed->TailTd = (USB_INT32U)TDTail;
+ ed->Next = 0;
+
+ if (ed == EDCtrl) {
+ LPC_USB->HcControlHeadED = (USB_INT32U)ed;
+ LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_CLF;
+ LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_CLE;
+ } else {
+ LPC_USB->HcBulkHeadED = (USB_INT32U)ed;
+ LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_BLF;
+ LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_BLE;
+ }
+
+ Host_WDHWait();
+
+// if (!(TDHead->Control & 0xF0000000)) {
+ if (!HOST_TDControlStatus) {
+ return (OK);
+ } else {
+ return (ERR_TD_FAIL);
+ }
+}
+
+/*
+**************************************************************************************************************
+* ENUMERATE THE DEVICE
+*
+* Description: This function is used to enumerate the device connected
+*
+* Arguments : None
+*
+* Returns : None
+*
+**************************************************************************************************************
+*/
+
+USB_INT32S Host_EnumDev (void)
+{
+ USB_INT32S rc;
+
+ PRINT_Log("Connect a Mass Storage device\n");
+ while (!HOST_RhscIntr)
+ __WFI();
+ Host_DelayMS(100); /* USB 2.0 spec says atleast 50ms delay beore port reset */
+ LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRS; // Initiate port reset
+ while (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRS)
+ __WFI(); // Wait for port reset to complete...
+ LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; // ...and clear port reset signal
+ Host_DelayMS(200); /* Wait for 100 MS after port reset */
+
+ EDCtrl->Control = 8 << 16; /* Put max pkt size = 8 */
+ /* Read first 8 bytes of device desc */
+ rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_DEVICE, 0, TDBuffer, 8);
+ if (rc != OK) {
+ PRINT_Err(rc);
+ return (rc);
+ }
+ EDCtrl->Control = TDBuffer[7] << 16; /* Get max pkt size of endpoint 0 */
+ rc = HOST_SET_ADDRESS(1); /* Set the device address to 1 */
+ if (rc != OK) {
+ PRINT_Err(rc);
+ return (rc);
+ }
+ Host_DelayMS(2);
+ EDCtrl->Control = (EDCtrl->Control) | 1; /* Modify control pipe with address 1 */
+ /* Get the configuration descriptor */
+ rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, 9);
+ if (rc != OK) {
+ PRINT_Err(rc);
+ return (rc);
+ }
+ /* Get the first configuration data */
+ rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, ReadLE16U(&TDBuffer[2]));
+ if (rc != OK) {
+ PRINT_Err(rc);
+ return (rc);
+ }
+ rc = MS_ParseConfiguration(); /* Parse the configuration */
+ if (rc != OK) {
+ PRINT_Err(rc);
+ return (rc);
+ }
+ rc = USBH_SET_CONFIGURATION(1); /* Select device configuration 1 */
+ if (rc != OK) {
+ PRINT_Err(rc);
+ }
+ Host_DelayMS(100); /* Some devices may require this delay */
+ return (rc);
+}
+
+/*
+**************************************************************************************************************
+* RECEIVE THE CONTROL INFORMATION
+*
+* Description: This function is used to receive the control information
+*
+* Arguments : bm_request_type
+* b_request
+* w_value
+* w_index
+* w_length
+* buffer
+*
+* Returns : OK if Success
+* ERROR if Failed
+*
+**************************************************************************************************************
+*/
+
+USB_INT32S Host_CtrlRecv ( USB_INT08U bm_request_type,
+ USB_INT08U b_request,
+ USB_INT16U w_value,
+ USB_INT16U w_index,
+ USB_INT16U w_length,
+ volatile USB_INT08U *buffer)
+{
+ USB_INT32S rc;
+
+
+ Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length);
+ rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8);
+ if (rc == OK) {
+ if (w_length) {
+ rc = Host_ProcessTD(EDCtrl, TD_IN, TDBuffer, w_length);
+ }
+ if (rc == OK) {
+ rc = Host_ProcessTD(EDCtrl, TD_OUT, NULL, 0);
+ }
+ }
+ return (rc);
+}
+
+/*
+**************************************************************************************************************
+* SEND THE CONTROL INFORMATION
+*
+* Description: This function is used to send the control information
+*
+* Arguments : None
+*
+* Returns : OK if Success
+* ERR_INVALID_BOOTSIG if Failed
+*
+**************************************************************************************************************
+*/
+
+USB_INT32S Host_CtrlSend ( USB_INT08U bm_request_type,
+ USB_INT08U b_request,
+ USB_INT16U w_value,
+ USB_INT16U w_index,
+ USB_INT16U w_length,
+ volatile USB_INT08U *buffer)
+{
+ USB_INT32S rc;
+
+
+ Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length);
+
+ rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8);
+ if (rc == OK) {
+ if (w_length) {
+ rc = Host_ProcessTD(EDCtrl, TD_OUT, TDBuffer, w_length);
+ }
+ if (rc == OK) {
+ rc = Host_ProcessTD(EDCtrl, TD_IN, NULL, 0);
+ }
+ }
+ return (rc);
+}
+
+/*
+**************************************************************************************************************
+* FILL SETUP PACKET
+*
+* Description: This function is used to fill the setup packet
+*
+* Arguments : None
+*
+* Returns : OK if Success
+* ERR_INVALID_BOOTSIG if Failed
+*
+**************************************************************************************************************
+*/
+
+void Host_FillSetup (USB_INT08U bm_request_type,
+ USB_INT08U b_request,
+ USB_INT16U w_value,
+ USB_INT16U w_index,
+ USB_INT16U w_length)
+{
+ int i;
+ for (i=0;i<w_length;i++)
+ TDBuffer[i] = 0;
+
+ TDBuffer[0] = bm_request_type;
+ TDBuffer[1] = b_request;
+ WriteLE16U(&TDBuffer[2], w_value);
+ WriteLE16U(&TDBuffer[4], w_index);
+ WriteLE16U(&TDBuffer[6], w_length);
+}
+
+
+
+/*
+**************************************************************************************************************
+* INITIALIZE THE TRANSFER DESCRIPTOR
+*
+* Description: This function initializes transfer descriptor
+*
+* Arguments : Pointer to TD structure
+*
+* Returns : None
+*
+**************************************************************************************************************
+*/
+
+void Host_TDInit (volatile HCTD *td)
+{
+
+ td->Control = 0;
+ td->CurrBufPtr = 0;
+ td->Next = 0;
+ td->BufEnd = 0;
+}
+
+/*
+**************************************************************************************************************
+* INITIALIZE THE ENDPOINT DESCRIPTOR
+*
+* Description: This function initializes endpoint descriptor
+*
+* Arguments : Pointer to ED strcuture
+*
+* Returns : None
+*
+**************************************************************************************************************
+*/
+
+void Host_EDInit (volatile HCED *ed)
+{
+
+ ed->Control = 0;
+ ed->TailTd = 0;
+ ed->HeadTd = 0;
+ ed->Next = 0;
+}
+
+/*
+**************************************************************************************************************
+* INITIALIZE HOST CONTROLLER COMMUNICATIONS AREA
+*
+* Description: This function initializes host controller communications area
+*
+* Arguments : Pointer to HCCA
+*
+* Returns :
+*
+**************************************************************************************************************
+*/
+
+void Host_HCCAInit (volatile HCCA *hcca)
+{
+ USB_INT32U i;
+
+
+ for (i = 0; i < 32; i++) {
+
+ hcca->IntTable[i] = 0;
+ hcca->FrameNumber = 0;
+ hcca->DoneHead = 0;
+ }
+
+}
+
+/*
+**************************************************************************************************************
+* WAIT FOR WDH INTERRUPT
+*
+* Description: This function is infinite loop which breaks when ever a WDH interrupt rises
+*
+* Arguments : None
+*
+* Returns : None
+*
+**************************************************************************************************************
+*/
+
+void Host_WDHWait (void)
+{
+ while (!HOST_WdhIntr)
+ __WFI();
+
+ HOST_WdhIntr = 0;
+}
+
+/*
+**************************************************************************************************************
+* READ LE 32U
+*
+* Description: This function is used to read an unsigned integer from a character buffer in the platform
+* containing little endian processor
+*
+* Arguments : pmem Pointer to the character buffer
+*
+* Returns : val Unsigned integer
+*
+**************************************************************************************************************
+*/
+
+USB_INT32U ReadLE32U (volatile USB_INT08U *pmem)
+{
+ USB_INT32U val = *(USB_INT32U*)pmem;
+#ifdef __BIG_ENDIAN
+ return __REV(val);
+#else
+ return val;
+#endif
+}
+
+/*
+**************************************************************************************************************
+* WRITE LE 32U
+*
+* Description: This function is used to write an unsigned integer into a charecter buffer in the platform
+* containing little endian processor.
+*
+* Arguments : pmem Pointer to the charecter buffer
+* val Integer value to be placed in the charecter buffer
+*
+* Returns : None
+*
+**************************************************************************************************************
+*/
+
+void WriteLE32U (volatile USB_INT08U *pmem,
+ USB_INT32U val)
+{
+#ifdef __BIG_ENDIAN
+ *(USB_INT32U*)pmem = __REV(val);
+#else
+ *(USB_INT32U*)pmem = val;
+#endif
+}
+
+/*
+**************************************************************************************************************
+* READ LE 16U
+*
+* Description: This function is used to read an unsigned short integer from a charecter buffer in the platform
+* containing little endian processor
+*
+* Arguments : pmem Pointer to the charecter buffer
+*
+* Returns : val Unsigned short integer
+*
+**************************************************************************************************************
+*/
+
+USB_INT16U ReadLE16U (volatile USB_INT08U *pmem)
+{
+ USB_INT16U val = *(USB_INT16U*)pmem;
+#ifdef __BIG_ENDIAN
+ return __REV16(val);
+#else
+ return val;
+#endif
+}
+
+/*
+**************************************************************************************************************
+* WRITE LE 16U
+*
+* Description: This function is used to write an unsigned short integer into a charecter buffer in the
+* platform containing little endian processor
+*
+* Arguments : pmem Pointer to the charecter buffer
+* val Value to be placed in the charecter buffer
+*
+* Returns : None
+*
+**************************************************************************************************************
+*/
+
+void WriteLE16U (volatile USB_INT08U *pmem,
+ USB_INT16U val)
+{
+#ifdef __BIG_ENDIAN
+ *(USB_INT16U*)pmem = (__REV16(val) & 0xFFFF);
+#else
+ *(USB_INT16U*)pmem = val;
+#endif
+}
+
+/*
+**************************************************************************************************************
+* READ BE 32U
+*
+* Description: This function is used to read an unsigned integer from a charecter buffer in the platform
+* containing big endian processor
+*
+* Arguments : pmem Pointer to the charecter buffer
+*
+* Returns : val Unsigned integer
+*
+**************************************************************************************************************
+*/
+
+USB_INT32U ReadBE32U (volatile USB_INT08U *pmem)
+{
+ USB_INT32U val = *(USB_INT32U*)pmem;
+#ifdef __BIG_ENDIAN
+ return val;
+#else
+ return __REV(val);
+#endif
+}
+
+/*
+**************************************************************************************************************
+* WRITE BE 32U
+*
+* Description: This function is used to write an unsigned integer into a charecter buffer in the platform
+* containing big endian processor
+*
+* Arguments : pmem Pointer to the charecter buffer
+* val Value to be placed in the charecter buffer
+*
+* Returns : None
+*
+**************************************************************************************************************
+*/
+
+void WriteBE32U (volatile USB_INT08U *pmem,
+ USB_INT32U val)
+{
+#ifdef __BIG_ENDIAN
+ *(USB_INT32U*)pmem = val;
+#else
+ *(USB_INT32U*)pmem = __REV(val);
+#endif
+}
+
+/*
+**************************************************************************************************************
+* READ BE 16U
+*
+* Description: This function is used to read an unsigned short integer from a charecter buffer in the platform
+* containing big endian processor
+*
+* Arguments : pmem Pointer to the charecter buffer
+*
+* Returns : val Unsigned short integer
+*
+**************************************************************************************************************
+*/
+
+USB_INT16U ReadBE16U (volatile USB_INT08U *pmem)
+{
+ USB_INT16U val = *(USB_INT16U*)pmem;
+#ifdef __BIG_ENDIAN
+ return val;
+#else
+ return __REV16(val);
+#endif
+}
+
+/*
+**************************************************************************************************************
+* WRITE BE 16U
+*
+* Description: This function is used to write an unsigned short integer into the charecter buffer in the
+* platform containing big endian processor
+*
+* Arguments : pmem Pointer to the charecter buffer
+* val Value to be placed in the charecter buffer
+*
+* Returns : None
+*
+**************************************************************************************************************
+*/
+
+void WriteBE16U (volatile USB_INT08U *pmem,
+ USB_INT16U val)
+{
+#ifdef __BIG_ENDIAN
+ *(USB_INT16U*)pmem = val;
+#else
+ *(USB_INT16U*)pmem = (__REV16(val) & 0xFFFF);
+#endif
+}
diff -r 000000000000 -r 0732b16d9a92 USBHostLite/usbhost_lpc17xx.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHostLite/usbhost_lpc17xx.h Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,254 @@
+/*
+**************************************************************************************************************
+* NXP USB Host Stack
+*
+* (c) Copyright 2008, NXP SemiConductors
+* (c) Copyright 2008, OnChip Technologies LLC
+* All Rights Reserved
+*
+* www.nxp.com
+* www.onchiptech.com
+*
+* File : usbhost_lpc17xx.h
+* Programmer(s) : Ravikanth.P
+* Version :
+*
+**************************************************************************************************************
+*/
+
+#ifndef USBHOST_LPC17xx_H
+#define USBHOST_LPC17xx_H
+
+/*
+**************************************************************************************************************
+* INCLUDE HEADER FILES
+**************************************************************************************************************
+*/
+
+#include "usbhost_inc.h"
+
+/*
+**************************************************************************************************************
+* PRINT CONFIGURATION
+**************************************************************************************************************
+*/
+
+#define PRINT_ENABLE 1
+
+#if PRINT_ENABLE
+#define PRINT_Log(...) printf(__VA_ARGS__)
+#define PRINT_Err(rc) printf("ERROR: In %s at Line %u - rc = %d\n", __FUNCTION__, __LINE__, rc)
+
+#else
+#define PRINT_Log(...) do {} while(0)
+#define PRINT_Err(rc) do {} while(0)
+
+#endif
+
+/*
+**************************************************************************************************************
+* GENERAL DEFINITIONS
+**************************************************************************************************************
+*/
+
+#define DESC_LENGTH(x) x[0]
+#define DESC_TYPE(x) x[1]
+
+
+#define HOST_GET_DESCRIPTOR(descType, descIndex, data, length) \
+ Host_CtrlRecv(USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, GET_DESCRIPTOR, \
+ (descType << 8)|(descIndex), 0, length, data)
+
+#define HOST_SET_ADDRESS(new_addr) \
+ Host_CtrlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, SET_ADDRESS, \
+ new_addr, 0, 0, NULL)
+
+#define USBH_SET_CONFIGURATION(configNum) \
+ Host_CtrlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, SET_CONFIGURATION, \
+ configNum, 0, 0, NULL)
+
+#define USBH_SET_INTERFACE(ifNum, altNum) \
+ Host_CtrlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_INTERFACE, SET_INTERFACE, \
+ altNum, ifNum, 0, NULL)
+
+/*
+**************************************************************************************************************
+* OHCI OPERATIONAL REGISTER FIELD DEFINITIONS
+**************************************************************************************************************
+*/
+
+ /* ------------------ HcControl Register --------------------- */
+#define OR_CONTROL_CLE 0x00000010
+#define OR_CONTROL_BLE 0x00000020
+#define OR_CONTROL_HCFS 0x000000C0
+#define OR_CONTROL_HC_OPER 0x00000080
+ /* ----------------- HcCommandStatus Register ----------------- */
+#define OR_CMD_STATUS_HCR 0x00000001
+#define OR_CMD_STATUS_CLF 0x00000002
+#define OR_CMD_STATUS_BLF 0x00000004
+ /* --------------- HcInterruptStatus Register ----------------- */
+#define OR_INTR_STATUS_WDH 0x00000002
+#define OR_INTR_STATUS_RHSC 0x00000040
+ /* --------------- HcInterruptEnable Register ----------------- */
+#define OR_INTR_ENABLE_WDH 0x00000002
+#define OR_INTR_ENABLE_RHSC 0x00000040
+#define OR_INTR_ENABLE_MIE 0x80000000
+ /* ---------------- HcRhDescriptorA Register ------------------ */
+#define OR_RH_STATUS_LPSC 0x00010000
+#define OR_RH_STATUS_DRWE 0x00008000
+ /* -------------- HcRhPortStatus[1:NDP] Register -------------- */
+#define OR_RH_PORT_CCS 0x00000001
+#define OR_RH_PORT_PRS 0x00000010
+#define OR_RH_PORT_CSC 0x00010000
+#define OR_RH_PORT_PRSC 0x00100000
+
+
+/*
+**************************************************************************************************************
+* FRAME INTERVAL
+**************************************************************************************************************
+*/
+
+#define FI 0x2EDF /* 12000 bits per frame (-1) */
+#define DEFAULT_FMINTERVAL ((((6 * (FI - 210)) / 7) << 16) | FI)
+
+/*
+**************************************************************************************************************
+* TRANSFER DESCRIPTOR CONTROL FIELDS
+**************************************************************************************************************
+*/
+
+#define TD_ROUNDING (USB_INT32U) (0x00040000) /* Buffer Rounding */
+#define TD_SETUP (USB_INT32U)(0) /* Direction of Setup Packet */
+#define TD_IN (USB_INT32U)(0x00100000) /* Direction In */
+#define TD_OUT (USB_INT32U)(0x00080000) /* Direction Out */
+#define TD_DELAY_INT(x) (USB_INT32U)((x) << 21) /* Delay Interrupt */
+#define TD_TOGGLE_0 (USB_INT32U)(0x02000000) /* Toggle 0 */
+#define TD_TOGGLE_1 (USB_INT32U)(0x03000000) /* Toggle 1 */
+#define TD_CC (USB_INT32U)(0xF0000000) /* Completion Code */
+
+/*
+**************************************************************************************************************
+* USB STANDARD REQUEST DEFINITIONS
+**************************************************************************************************************
+*/
+
+#define USB_DESCRIPTOR_TYPE_DEVICE 1
+#define USB_DESCRIPTOR_TYPE_CONFIGURATION 2
+#define USB_DESCRIPTOR_TYPE_INTERFACE 4
+#define USB_DESCRIPTOR_TYPE_ENDPOINT 5
+ /* ----------- Control RequestType Fields ----------- */
+#define USB_DEVICE_TO_HOST 0x80
+#define USB_HOST_TO_DEVICE 0x00
+#define USB_REQUEST_TYPE_CLASS 0x20
+#define USB_RECIPIENT_DEVICE 0x00
+#define USB_RECIPIENT_INTERFACE 0x01
+ /* -------------- USB Standard Requests -------------- */
+#define SET_ADDRESS 5
+#define GET_DESCRIPTOR 6
+#define SET_CONFIGURATION 9
+#define SET_INTERFACE 11
+
+/*
+**************************************************************************************************************
+* TYPE DEFINITIONS
+**************************************************************************************************************
+*/
+
+typedef struct hcEd { /* ----------- HostController EndPoint Descriptor ------------- */
+ volatile USB_INT32U Control; /* Endpoint descriptor control */
+ volatile USB_INT32U TailTd; /* Physical address of tail in Transfer descriptor list */
+ volatile USB_INT32U HeadTd; /* Physcial address of head in Transfer descriptor list */
+ volatile USB_INT32U Next; /* Physical address of next Endpoint descriptor */
+} HCED;
+
+typedef struct hcTd { /* ------------ HostController Transfer Descriptor ------------ */
+ volatile USB_INT32U Control; /* Transfer descriptor control */
+ volatile USB_INT32U CurrBufPtr; /* Physical address of current buffer pointer */
+ volatile USB_INT32U Next; /* Physical pointer to next Transfer Descriptor */
+ volatile USB_INT32U BufEnd; /* Physical address of end of buffer */
+} HCTD;
+
+typedef struct hcca { /* ----------- Host Controller Communication Area ------------ */
+ volatile USB_INT32U IntTable[32]; /* Interrupt Table */
+ volatile USB_INT32U FrameNumber; /* Frame Number */
+ volatile USB_INT32U DoneHead; /* Done Head */
+ volatile USB_INT08U Reserved[116]; /* Reserved for future use */
+ volatile USB_INT08U Unknown[4]; /* Unused */
+} HCCA;
+
+/*
+**************************************************************************************************************
+* EXTERN DECLARATIONS
+**************************************************************************************************************
+*/
+
+extern volatile HCED *EDBulkIn; /* BulkIn endpoint descriptor structure */
+extern volatile HCED *EDBulkOut; /* BulkOut endpoint descriptor structure */
+extern volatile HCTD *TDHead; /* Head transfer descriptor structure */
+extern volatile HCTD *TDTail; /* Tail transfer descriptor structure */
+extern volatile USB_INT08U *TDBuffer; /* Current Buffer Pointer of transfer descriptor */
+
+/*
+**************************************************************************************************************
+* FUNCTION PROTOTYPES
+**************************************************************************************************************
+*/
+
+void Host_Init (void);
+
+extern "C" void USB_IRQHandler(void) __irq;
+
+USB_INT32S Host_EnumDev (void);
+
+USB_INT32S Host_ProcessTD(volatile HCED *ed,
+ volatile USB_INT32U token,
+ volatile USB_INT08U *buffer,
+ USB_INT32U buffer_len);
+
+void Host_DelayUS ( USB_INT32U delay);
+void Host_DelayMS ( USB_INT32U delay);
+
+
+void Host_TDInit (volatile HCTD *td);
+void Host_EDInit (volatile HCED *ed);
+void Host_HCCAInit (volatile HCCA *hcca);
+
+USB_INT32S Host_CtrlRecv ( USB_INT08U bm_request_type,
+ USB_INT08U b_request,
+ USB_INT16U w_value,
+ USB_INT16U w_index,
+ USB_INT16U w_length,
+ volatile USB_INT08U *buffer);
+
+USB_INT32S Host_CtrlSend ( USB_INT08U bm_request_type,
+ USB_INT08U b_request,
+ USB_INT16U w_value,
+ USB_INT16U w_index,
+ USB_INT16U w_length,
+ volatile USB_INT08U *buffer);
+
+void Host_FillSetup( USB_INT08U bm_request_type,
+ USB_INT08U b_request,
+ USB_INT16U w_value,
+ USB_INT16U w_index,
+ USB_INT16U w_length);
+
+
+void Host_WDHWait (void);
+
+
+USB_INT32U ReadLE32U (volatile USB_INT08U *pmem);
+void WriteLE32U (volatile USB_INT08U *pmem,
+ USB_INT32U val);
+USB_INT16U ReadLE16U (volatile USB_INT08U *pmem);
+void WriteLE16U (volatile USB_INT08U *pmem,
+ USB_INT16U val);
+USB_INT32U ReadBE32U (volatile USB_INT08U *pmem);
+void WriteBE32U (volatile USB_INT08U *pmem,
+ USB_INT32U val);
+USB_INT16U ReadBE16U (volatile USB_INT08U *pmem);
+void WriteBE16U (volatile USB_INT08U *pmem,
+ USB_INT16U val);
+
+#endif
diff -r 000000000000 -r 0732b16d9a92 USBHostLite/usbhost_ms.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHostLite/usbhost_ms.c Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,455 @@
+/*
+**************************************************************************************************************
+* NXP USB Host Stack
+*
+* (c) Copyright 2008, NXP SemiConductors
+* (c) Copyright 2008, OnChip Technologies LLC
+* All Rights Reserved
+*
+* www.nxp.com
+* www.onchiptech.com
+*
+* File : usbhost_ms.c
+* Programmer(s) : Ravikanth.P
+* Version :
+*
+**************************************************************************************************************
+*/
+
+/*
+**************************************************************************************************************
+* INCLUDE HEADER FILES
+**************************************************************************************************************
+*/
+
+#include "usbhost_ms.h"
+
+/*
+**************************************************************************************************************
+* GLOBAL VARIABLES
+**************************************************************************************************************
+*/
+
+USB_INT32U MS_BlkSize;
+
+/*
+**************************************************************************************************************
+* INITIALIZE MASS STORAGE INTERFACE
+*
+* Description: This function initializes the mass storage interface
+*
+* Arguments : None
+*
+* Returns : OK if Success
+* ERR_INVALID_BOOTSIG if Failed
+*
+**************************************************************************************************************
+*/
+
+USB_INT32S MS_Init (USB_INT32U *blkSize, USB_INT32U *numBlks, USB_INT08U *inquiryResult)
+{
+ USB_INT08U retry;
+ USB_INT32S rc;
+
+ MS_GetMaxLUN(); /* Get maximum logical unit number */
+ retry = 80;
+ while(retry) {
+ rc = MS_TestUnitReady(); /* Test whether the unit is ready */
+ if (rc == OK) {
+ break;
+ }
+ MS_GetSenseInfo(); /* Get sense information */
+ retry--;
+ }
+ if (rc != OK) {
+ PRINT_Err(rc);
+ return (rc);
+ }
+ rc = MS_ReadCapacity(numBlks, blkSize); /* Read capacity of the disk */
+ MS_BlkSize = *blkSize; // Set global
+ rc = MS_Inquire (inquiryResult);
+ return (rc);
+}
+/*
+**************************************************************************************************************
+* PARSE THE CONFIGURATION
+*
+* Description: This function is used to parse the configuration
+*
+* Arguments : None
+*
+* Returns : OK if Success
+* ERR_INVALID_BOOTSIG if Failed
+*
+**************************************************************************************************************
+*/
+
+USB_INT32S MS_ParseConfiguration (void)
+{
+ volatile USB_INT08U *desc_ptr;
+ USB_INT08U ms_int_found;
+
+
+ desc_ptr = TDBuffer;
+ ms_int_found = 0;
+
+ if (desc_ptr[1] != USB_DESCRIPTOR_TYPE_CONFIGURATION) {
+ return (ERR_BAD_CONFIGURATION);
+ }
+ desc_ptr += desc_ptr[0];
+
+ while (desc_ptr != TDBuffer + ReadLE16U(&TDBuffer[2])) {
+
+ switch (desc_ptr[1]) {
+
+ case USB_DESCRIPTOR_TYPE_INTERFACE: /* If it is an interface descriptor */
+ if (desc_ptr[5] == MASS_STORAGE_CLASS && /* check if the class is mass storage */
+ desc_ptr[6] == MASS_STORAGE_SUBCLASS_SCSI && /* check if the subclass is SCSI */
+ desc_ptr[7] == MASS_STORAGE_PROTOCOL_BO) { /* check if the protocol is Bulk only */
+ ms_int_found = 1;
+ desc_ptr += desc_ptr[0]; /* Move to next descriptor start */
+ }
+ break;
+
+ case USB_DESCRIPTOR_TYPE_ENDPOINT: /* If it is an endpoint descriptor */
+ if ((desc_ptr[3] & 0x03) == 0x02) { /* If it is Bulk endpoint */
+ if (desc_ptr[2] & 0x80) { /* If it is In endpoint */
+ EDBulkIn->Control = 1 | /* USB address */
+ ((desc_ptr[2] & 0x7F) << 7) | /* Endpoint address */
+ (2 << 11) | /* direction */
+ (ReadLE16U(&desc_ptr[4]) << 16); /* MaxPkt Size */
+ desc_ptr += desc_ptr[0]; /* Move to next descriptor start */
+ } else { /* If it is Out endpoint */
+ EDBulkOut->Control = 1 | /* USB address */
+ ((desc_ptr[2] & 0x7F) << 7) | /* Endpoint address */
+ (1 << 11) | /* direction */
+ (ReadLE16U(&desc_ptr[4]) << 16); /* MaxPkt Size */
+ desc_ptr += desc_ptr[0]; /* Move to next descriptor start */
+ }
+ } else { /* If it is not bulk end point */
+ desc_ptr += desc_ptr[0]; /* Move to next descriptor start */
+ }
+ break;
+
+ default: /* If the descriptor is neither interface nor endpoint */
+ desc_ptr += desc_ptr[0]; /* Move to next descriptor start */
+ break;
+ }
+ }
+ if (ms_int_found) {
+ PRINT_Log("Mass Storage device connected\n");
+ return (OK);
+ } else {
+ PRINT_Log("Not a Mass Storage device\n");
+ return (ERR_NO_MS_INTERFACE);
+ }
+}
+
+/*
+**************************************************************************************************************
+* GET MAXIMUM LOGICAL UNIT
+*
+* Description: This function returns the maximum logical unit from the device
+*
+* Arguments : None
+*
+* Returns : OK if Success
+* ERR_INVALID_BOOTSIG if Failed
+*
+**************************************************************************************************************
+*/
+
+USB_INT32S MS_GetMaxLUN (void)
+{
+ USB_INT32S rc;
+
+
+ rc = Host_CtrlRecv(USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE,
+ MS_GET_MAX_LUN_REQ,
+ 0,
+ 0,
+ 1,
+ TDBuffer);
+ return (rc);
+}
+
+/*
+**************************************************************************************************************
+* GET SENSE INFORMATION
+*
+* Description: This function is used to get sense information from the device
+*
+* Arguments : None
+*
+* Returns : OK if Success
+* ERROR if Failed
+*
+**************************************************************************************************************
+*/
+
+USB_INT32S MS_GetSenseInfo (void)
+{
+ USB_INT32S rc;
+
+
+ Fill_MSCommand(0, 0, 0, MS_DATA_DIR_IN, SCSI_CMD_REQUEST_SENSE, 6);
+ rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE);
+ if (rc == OK) {
+ rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, 18);
+ if (rc == OK) {
+ rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE);
+ if (rc == OK) {
+ if (TDBuffer[12] != 0) {
+ rc = ERR_MS_CMD_FAILED;
+ }
+ }
+ }
+ }
+ return (rc);
+}
+
+/*
+**************************************************************************************************************
+* TEST UNIT READY
+*
+* Description: This function is used to test whether the unit is ready or not
+*
+* Arguments : None
+*
+* Returns : OK if Success
+* ERROR if Failed
+*
+**************************************************************************************************************
+*/
+
+USB_INT32S MS_TestUnitReady (void)
+{
+ USB_INT32S rc;
+
+
+ Fill_MSCommand(0, 0, 0, MS_DATA_DIR_NONE, SCSI_CMD_TEST_UNIT_READY, 6);
+ rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE);
+ if (rc == OK) {
+ rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE);
+ if (rc == OK) {
+ if (TDBuffer[12] != 0) {
+ rc = ERR_MS_CMD_FAILED;
+ }
+ }
+ }
+ return (rc);
+}
+
+/*
+**************************************************************************************************************
+* READ CAPACITY
+*
+* Description: This function is used to read the capacity of the mass storage device
+*
+* Arguments : None
+*
+* Returns : OK if Success
+* ERROR if Failed
+*
+**************************************************************************************************************
+*/
+
+USB_INT32S MS_ReadCapacity (USB_INT32U *numBlks, USB_INT32U *blkSize)
+{
+ USB_INT32S rc;
+
+
+ Fill_MSCommand(0, 0, 0, MS_DATA_DIR_IN, SCSI_CMD_READ_CAPACITY, 10);
+ rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE);
+ if (rc == OK) {
+ rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, 8);
+ if (rc == OK) {
+ if (numBlks)
+ *numBlks = ReadBE32U(&TDBuffer[0]);
+ if (blkSize)
+ *blkSize = ReadBE32U(&TDBuffer[4]);
+ rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE);
+ if (rc == OK) {
+ if (TDBuffer[12] != 0) {
+ rc = ERR_MS_CMD_FAILED;
+ }
+ }
+ }
+ }
+ return (rc);
+}
+
+
+
+USB_INT32S MS_Inquire (USB_INT08U *response)
+{
+ USB_INT32S rc;
+ USB_INT32U i;
+
+ Fill_MSCommand(0, 0, 0, MS_DATA_DIR_IN, SCSI_CMD_INQUIRY, 6);
+ rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE);
+ if (rc == OK) {
+ rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, INQUIRY_LENGTH);
+ if (rc == OK) {
+ if (response) {
+ for ( i = 0; i < INQUIRY_LENGTH; i++ )
+ *response++ = *TDBuffer++;
+#if 0
+ MemCpy (response, TDBuffer, INQUIRY_LENGTH);
+ StrNullTrailingSpace (response->vendorID, SCSI_INQUIRY_VENDORCHARS);
+ StrNullTrailingSpace (response->productID, SCSI_INQUIRY_PRODUCTCHARS);
+ StrNullTrailingSpace (response->productRev, SCSI_INQUIRY_REVCHARS);
+#endif
+ }
+ rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE);
+ if (rc == OK) {
+ if (TDBuffer[12] != 0) { // bCSWStatus byte
+ rc = ERR_MS_CMD_FAILED;
+ }
+ }
+ }
+ }
+ return (rc);
+}
+
+/*
+**************************************************************************************************************
+* RECEIVE THE BULK DATA
+*
+* Description: This function is used to receive the bulk data
+*
+* Arguments : None
+*
+* Returns : OK if Success
+* ERR_INVALID_BOOTSIG if Failed
+*
+**************************************************************************************************************
+*/
+
+USB_INT32S MS_BulkRecv ( USB_INT32U block_number,
+ USB_INT16U num_blocks,
+ volatile USB_INT08U *user_buffer)
+{
+ USB_INT32S rc;
+ int i;
+ volatile USB_INT08U *c = user_buffer;
+ for (i=0;i<MS_BlkSize*num_blocks;i++)
+ *c++ = 0;
+
+
+ Fill_MSCommand(block_number, MS_BlkSize, num_blocks, MS_DATA_DIR_IN, SCSI_CMD_READ_10, 10);
+
+ rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE);
+ if (rc == OK) {
+ rc = Host_ProcessTD(EDBulkIn, TD_IN, user_buffer, MS_BlkSize * num_blocks);
+ if (rc == OK) {
+ rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE);
+ if (rc == OK) {
+ if (TDBuffer[12] != 0) {
+ rc = ERR_MS_CMD_FAILED;
+ }
+ }
+ }
+ }
+ return (rc);
+}
+
+/*
+**************************************************************************************************************
+* SEND BULK DATA
+*
+* Description: This function is used to send the bulk data
+*
+* Arguments : None
+*
+* Returns : OK if Success
+* ERR_INVALID_BOOTSIG if Failed
+*
+**************************************************************************************************************
+*/
+
+USB_INT32S MS_BulkSend ( USB_INT32U block_number,
+ USB_INT16U num_blocks,
+ volatile USB_INT08U *user_buffer)
+{
+ USB_INT32S rc;
+
+
+ Fill_MSCommand(block_number, MS_BlkSize, num_blocks, MS_DATA_DIR_OUT, SCSI_CMD_WRITE_10, 10);
+
+ rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE);
+ if (rc == OK) {
+ rc = Host_ProcessTD(EDBulkOut, TD_OUT, user_buffer, MS_BlkSize * num_blocks);
+ if (rc == OK) {
+ rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE);
+ if (rc == OK) {
+ if (TDBuffer[12] != 0) {
+ rc = ERR_MS_CMD_FAILED;
+ }
+ }
+ }
+ }
+ return (rc);
+}
+
+/*
+**************************************************************************************************************
+* FILL MASS STORAGE COMMAND
+*
+* Description: This function is used to fill the mass storage command
+*
+* Arguments : None
+*
+* Returns : OK if Success
+* ERR_INVALID_BOOTSIG if Failed
+*
+**************************************************************************************************************
+*/
+
+void Fill_MSCommand (USB_INT32U block_number,
+ USB_INT32U block_size,
+ USB_INT16U num_blocks,
+ MS_DATA_DIR direction,
+ USB_INT08U scsi_cmd,
+ USB_INT08U scsi_cmd_len)
+{
+ USB_INT32U data_len;
+ static USB_INT32U tag_cnt = 0;
+ USB_INT32U cnt;
+
+
+ for (cnt = 0; cnt < CBW_SIZE; cnt++) {
+ TDBuffer[cnt] = 0;
+ }
+ switch(scsi_cmd) {
+
+ case SCSI_CMD_TEST_UNIT_READY:
+ data_len = 0;
+ break;
+ case SCSI_CMD_READ_CAPACITY:
+ data_len = 8;
+ break;
+ case SCSI_CMD_REQUEST_SENSE:
+ data_len = 18;
+ break;
+ case SCSI_CMD_INQUIRY:
+ data_len = 36;
+ break;
+ default:
+ data_len = block_size * num_blocks;
+ break;
+ }
+ WriteLE32U(TDBuffer, CBW_SIGNATURE);
+ WriteLE32U(&TDBuffer[4], tag_cnt);
+ WriteLE32U(&TDBuffer[8], data_len);
+ TDBuffer[12] = (direction == MS_DATA_DIR_NONE) ? 0 : direction;
+ TDBuffer[14] = scsi_cmd_len; /* Length of the CBW */
+ TDBuffer[15] = scsi_cmd;
+ if ((scsi_cmd == SCSI_CMD_REQUEST_SENSE)
+ || (scsi_cmd == SCSI_CMD_INQUIRY)) {
+ TDBuffer[19] = (USB_INT08U)data_len;
+ } else {
+ WriteBE32U(&TDBuffer[17], block_number);
+ }
+ WriteBE16U(&TDBuffer[22], num_blocks);
+}
diff -r 000000000000 -r 0732b16d9a92 USBHostLite/usbhost_ms.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHostLite/usbhost_ms.h Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,101 @@
+/*
+**************************************************************************************************************
+* NXP USB Host Stack
+*
+* (c) Copyright 2008, NXP SemiConductors
+* (c) Copyright 2008, OnChip Technologies LLC
+* All Rights Reserved
+*
+* www.nxp.com
+* www.onchiptech.com
+*
+* File : usbhost_ms.h
+* Programmer(s) : Ravikanth.P
+* Version :
+*
+**************************************************************************************************************
+*/
+
+#ifndef USBHOST_MS_H
+#define USBHOST_MS_H
+
+/*
+**************************************************************************************************************
+* INCLUDE HEADER FILES
+**************************************************************************************************************
+*/
+
+#include "usbhost_inc.h"
+
+/*
+**************************************************************************************************************
+* MASS STORAGE SPECIFIC DEFINITIONS
+**************************************************************************************************************
+*/
+
+#define MS_GET_MAX_LUN_REQ 0xFE
+#define MASS_STORAGE_CLASS 0x08
+#define MASS_STORAGE_SUBCLASS_SCSI 0x06
+#define MASS_STORAGE_PROTOCOL_BO 0x50
+
+#define INQUIRY_LENGTH 36
+/*
+**************************************************************************************************************
+* SCSI SPECIFIC DEFINITIONS
+**************************************************************************************************************
+*/
+
+#define CBW_SIGNATURE 0x43425355
+#define CSW_SIGNATURE 0x53425355
+#define CBW_SIZE 31
+#define CSW_SIZE 13
+#define CSW_CMD_PASSED 0x00
+#define SCSI_CMD_REQUEST_SENSE 0x03
+#define SCSI_CMD_TEST_UNIT_READY 0x00
+#define SCSI_CMD_INQUIRY 0x12
+#define SCSI_CMD_READ_10 0x28
+#define SCSI_CMD_READ_CAPACITY 0x25
+#define SCSI_CMD_WRITE_10 0x2A
+
+/*
+**************************************************************************************************************
+* TYPE DEFINITIONS
+**************************************************************************************************************
+*/
+
+typedef enum ms_data_dir {
+
+ MS_DATA_DIR_IN = 0x80,
+ MS_DATA_DIR_OUT = 0x00,
+ MS_DATA_DIR_NONE = 0x01
+
+} MS_DATA_DIR;
+
+/*
+**************************************************************************************************************
+* FUNCTION PROTOTYPES
+**************************************************************************************************************
+*/
+
+USB_INT32S MS_BulkRecv ( USB_INT32U block_number,
+ USB_INT16U num_blocks,
+ volatile USB_INT08U *user_buffer);
+
+USB_INT32S MS_BulkSend ( USB_INT32U block_number,
+ USB_INT16U num_blocks,
+ volatile USB_INT08U *user_buffer);
+USB_INT32S MS_ParseConfiguration(void);
+USB_INT32S MS_TestUnitReady (void);
+USB_INT32S MS_ReadCapacity (USB_INT32U *numBlks, USB_INT32U *blkSize);
+USB_INT32S MS_GetMaxLUN (void);
+USB_INT32S MS_GetSenseInfo (void);
+USB_INT32S MS_Init (USB_INT32U *blkSize, USB_INT32U *numBlks, USB_INT08U *inquiryResult);
+USB_INT32S MS_Inquire (USB_INT08U *response);
+
+void Fill_MSCommand ( USB_INT32U block_number,
+ USB_INT32U block_size,
+ USB_INT16U num_blocks,
+ MS_DATA_DIR direction,
+ USB_INT08U scsi_cmd,
+ USB_INT08U scsi_cmd_len);
+#endif
diff -r 000000000000 -r 0732b16d9a92 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Jan 06 19:01:44 2011 +0000
@@ -0,0 +1,522 @@
+#include "mbed.h"
+#include "TFT_4DGL.h"
+#include "MSCFileSystem.h"
+#include "IniFile.h"
+
+// Ini file value (int/bool/string)
+// Key1 = 123 -> 123 (int)
+// Key2 = 0x123 -> 291 (int)
+// Key3 = FALSE -> false (bool)
+// Key4 = TRUE -> true (bool)
+// Key5 = 123 -> true (bool)
+// key6 = abc "def -> 'abc "def' (string)
+// key7 = " ghi "jkl " -> ' ghi "jkl '(string)
+// #comment line
+
+//uLCD-32PT(SGC) 4d-systems display
+
+TFT_4DGL display(p9,p10,p11); // serial tx, serial rx, reset pin;
+
+Serial pc2(USBTX, USBRX); // tx, rx
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+DigitalIn adc_stop(p12);
+
+AnalogIn Sense1(p15); //Sensor 1
+AnalogIn Sense2(p16); //Sensor 2
+AnalogIn Sense3(p17); //Sensor 3
+AnalogIn Sense4(p18); //Sensor 4
+AnalogIn Sense5(p19); //Sensor 5
+AnalogIn Sense6(p20); //Sensor 6
+
+Ticker t1; //Timer 1
+Ticker t2; //Timer 2
+Timer timer;
+
+#ifndef MAX
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+
+#ifndef MIN
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifndef ABS
+#define ABS(a) (((a) < 0) ? -(a) : (a))
+#endif
+
+#define ROOT_PATH "/local/"
+#define ROOT_LEN (sizeof(ROOT_PATH) - 1)
+
+const char INI_FILE[] = ROOT_PATH "param.ini";
+
+const char DEFAULT_ADC_FILENAME[] = "data.csv";
+const int DEFAULT_SAMPLES = 200;
+const int DEFAULT_SPEED = 100;
+
+const int INI_BUF = 100;
+
+
+// Function Declarations
+
+void tint1( void );
+void tint2( void );
+void alarm( int val, int lim);
+float convert( char *str);
+
+float analog1( int val2);
+float analog2( int val2);
+float analog3( int val2);
+float analog4( int val2);
+float analog5( int val2);
+float analog6( int val2);
+
+float FloatingAverage1( float newval1);
+float FloatingAverage2( float newval2);
+float FloatingAverage3( float newval3);
+float FloatingAverage4( float newval4);
+float FloatingAverage5( float newval5);
+float FloatingAverage6( float newval6);
+
+int intflag1;
+int intflag2;
+int x = 0, y = 0, status, xc = 0, yc = 0;
+
+int begin, end;
+float adc_time = 0.1;
+
+
+
+int main() {
+
+ char s[100];
+ unsigned int v1 = 0, v2 = 0, v3 = 0, v4 = 0, v5 = 0, v6 = 0;
+ unsigned int Dcount = 0;
+
+ float ComVal = 0.0;
+ unsigned short usCurrentValue;
+
+ float Voltage1;
+ float Voltage2;
+ float Voltage3;
+ float Voltage4;
+ float Voltage5;
+ float Voltage6;
+
+ pc2.baud(115200);
+
+ int file_nr = 0;
+
+ char clear[] = {27, '[', '2', 'J'};
+ char home[] = {27, '[', '0', '0', 'H'};
+
+ char adc_filename[INI_BUF];
+ int adc_samples = DEFAULT_SAMPLES;
+ int adc_speed_ms = DEFAULT_SPEED;
+
+ LocalFileSystem local("local");
+
+ {
+ pc2.printf("%s", clear);
+ pc2.printf("%s", home);
+
+ strcpy(adc_filename, DEFAULT_ADC_FILENAME);
+
+
+ IniFile::getval(INI_FILE, "FILENAME", adc_filename, sizeof(adc_filename));
+ IniFile::getval(INI_FILE, "SAMPLES", adc_samples);
+ IniFile::getval(INI_FILE, "SPEED", adc_speed_ms);
+
+ printf("\n\n");
+ printf("FILENAME = %s\n", adc_filename);
+ printf("SAMPLES = %d\n", adc_samples);
+ printf("SPEED = %d\n", adc_speed_ms);
+
+ wait(1);
+
+ adc_time = (float) adc_speed_ms/1000.0;
+ printf("\nadc_time = %.2f sec", adc_time);
+ }
+
+ display.baudrate(256000);
+
+
+ //display.uSD_Image(0, 0, 0x000000); //Display the mbed image - X-pos, Y-pos, Sector Address
+ //wait(4.0);
+ //display.cls();
+ //display.uSD_Image(80, 240, 0x00E2); //Display the mbed image - X-pos, Y-pos, Sector Address
+ //wait(4.0);
+ display.cls();
+
+
+ display.background_color(LGREY);
+ display.pen_size(WIREFRAME);
+ display.text_mode(TRANSPARENT);
+
+ display.text_string("ADC LOGGER ver 1.01", 3, 1, FONT_8X8, 0x000000);
+
+ display.pen_size(SOLID);
+ display.pen_size(WIREFRAME);
+ display.rectangle(18, 132, 220, 301, 0x000000);
+ display.pen_size(SOLID);
+ display.rectangle(19, 133, 219, 300, 0xFFFFFF);
+ display.text_string("SAMPLES : ", 3, 8, FONT_8X8, 0x000000);
+ display.text_string("ADC1: ", 3, 10, FONT_8X8, BLACK);
+ display.text_string("ADC2: ", 3, 11, FONT_8X8, BLUE);
+ display.text_string("ADC3: ", 3, 12, FONT_8X8, RED);
+ display.text_string("ADC4: ", 3, 13, FONT_8X8, DGREEN);
+ display.text_string("ADC5: ", 3, 14, FONT_8X8, BROWN);
+ display.text_string("ADC6: ", 3, 15, FONT_8X8, MAGENTA);
+
+ t1.attach(&tint1,adc_time);
+ t2.attach(&tint2,1.0);
+
+ display.set_font(FONT_8X8);
+ display.pen_size(SOLID);
+ display.text_mode(OPAQUE);
+ display.color( 0x000000);
+ display.display_control(TOUCH_CTRL, ENABLE);
+ display.set_touch(0, 0, 239, 319);
+
+ pc2.printf("%s", clear);
+ pc2.printf("%s", home);
+
+ while (1) {
+
+ MSCFileSystem msc("local"); // Mount flash drive under the name "local"
+
+ {
+
+ display.text_mode(TRANSPARENT);
+ display.text_button("START", UP, 20, 30, 0x00FF00, FONT_12X16, BLACK, 1, 1);
+ display.text_mode(OPAQUE);
+
+ while (!((x > 20 && x < 88) && (y > 30 && y < 53))) {
+ display.Pause_Until_Touch(&x, &y);
+ pc2.printf("x=%i\n",x);
+ pc2.printf("y=%i\n",y);
+ }
+
+ x = 0;
+ y = 0;
+
+ display.pen_size(SOLID);
+ display.rectangle(20, 30, 88, 53, LGREY);
+
+ Dcount = 19;
+ file_nr = file_nr + 1;
+
+ int i;
+ char path[INI_BUF];
+ sprintf(path, "/local/%i%s", file_nr, adc_filename);
+ printf(path, "\n/local/%i%s", file_nr, adc_filename);
+ printf("\n");
+ FILE *fp = fopen(path, "w"); // Open "adc_filename.csv" on the local file system for writing
+
+ display.rectangle(19, 133, 219, 300, 0xFFFFFF);
+
+ ComVal = adc_samples;
+
+ timer.start();
+ begin = timer.read_us();
+
+
+ for (i=0; i < ComVal ; i++) {
+
+ led4 = 1;
+
+ while (intflag1 == 0) {
+ wait_us(10);
+ }
+ intflag1 = 0;
+
+ pc2.printf("i = %i\n", i+1) ;
+
+ display.locate(13,8);
+ sprintf(s, "%d ",i+1);
+ display.puts(s);
+
+ display.locate(20,8);
+ sprintf(s, "(%.0f) ",ComVal);
+ display.puts(s);
+
+ Voltage1 = FloatingAverage1(analog1(usCurrentValue));
+ Voltage2 = FloatingAverage2(analog2(usCurrentValue));
+ Voltage3 = FloatingAverage3(analog3(usCurrentValue));
+ Voltage4 = FloatingAverage4(analog4(usCurrentValue));
+ Voltage5 = FloatingAverage5(analog5(usCurrentValue));
+ Voltage6 = FloatingAverage6(analog6(usCurrentValue));
+
+ if (Dcount >= 219) {
+ Dcount = 19;
+ display.rectangle(19, 133, 219, 300, 0xFFFFFF);
+ }
+
+ v1 = Voltage1 * 50;
+ v1 = 299 - v1;
+ display.pixel(Dcount, v1, BLACK);
+
+ v2 = Voltage2 * 50;
+ v2 = 299 - v2;
+ display.pixel(Dcount, v2, BLUE);
+
+ v3 = Voltage3 * 50;
+ v3 = 299 - v3;
+ display.pixel(Dcount, v3, RED);
+
+ v4 = Voltage4 * 50;
+ v4 = 299 - v4;
+ display.pixel(Dcount, v4, DGREEN);
+
+ v5 = Voltage5 * 50;
+ v5 = 299 - v5;
+ display.pixel(Dcount, v5, ORANGE);
+
+ v6 = Voltage6 * 50;
+ v6 = 299 - v6;
+ display.pixel(Dcount, v6, MAGENTA);
+
+ Dcount++;
+
+ if (intflag2 == 1) {
+
+ display.locate(9,10);
+ sprintf(s, "%.3f volt ", MAX(Voltage1,0));
+ display.puts(s);
+
+ display.locate(9,11);
+ sprintf(s, "%.3f volt ", MAX(Voltage2,0));
+ display.puts(s);
+
+ display.locate(9,12);
+ sprintf(s, "%.3f volt ", MAX(Voltage3,0));
+ display.puts(s);
+
+ display.locate(9,13);
+ sprintf(s, "%.3f volt ", MAX(Voltage4,0));
+ display.puts(s);
+
+ display.locate(9,14);
+ sprintf(s, "%.1f deg c ",Voltage5*100-273.12);
+ display.puts(s);
+
+ display.locate(9,15);
+ sprintf(s, "%.1f deg c ",Voltage6*100-273.12);
+ display.puts(s);
+
+ intflag2 = 0;
+ }
+
+ fprintf(fp, "%d\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\r\n",(i+1) , Voltage1, Voltage2, Voltage3, Voltage4, Voltage5, Voltage6);
+
+ if (!adc_stop) {
+ i = ComVal;
+ }
+
+ }
+
+ end = timer.read_us();
+ printf("Time = %d us\n", end - begin);
+ fclose(fp);
+ led4 = 0;
+
+ }
+ }
+
+}
+
+// Convert command
+float convert( char *str) {
+ float ComVal;
+ ComVal = atoi(str+1);
+
+ return ComVal;
+}
+
+// Interrupt for the Timer 1
+void tint1( void ) {
+ led2 = !led2;
+ intflag1 = 1;
+}
+
+// Interrupt for the Timer 2
+void tint2( void ) {
+ led3 = !led3;
+ intflag2 = 1;
+}
+
+// ADC1
+float analog1( int val2) {
+ float usCurrentValue = Sense1.read_u16()/16;
+ return usCurrentValue*3.3/4095;
+}
+// ADC2
+float analog2( int val2) {
+ float usCurrentValue = Sense2.read_u16()/16;
+ return usCurrentValue*3.3/4095;
+}
+// ADC3
+float analog3( int val2) {
+ float usCurrentValue = Sense3.read_u16()/16;
+ return usCurrentValue*3.3/4095;
+}
+// ADC4
+float analog4( int val2) {
+ float usCurrentValue = Sense4.read_u16()/16;
+ return usCurrentValue*3.3/4095;
+}
+// ADC5
+float analog5( int val2) {
+ float usCurrentValue = Sense5.read_u16()/16;
+ return usCurrentValue*3.3/4095;
+}
+// ADC6
+float analog6( int val2) {
+ float usCurrentValue = Sense6.read_u16()/16;
+ return usCurrentValue*3.3/4095;
+}
+
+// Floating Average routine 1
+float FloatingAverage1(float newval1) {
+ static float numbers[5];
+ static float sum = 0;
+ static int count = 0;
+ int size;
+ int i;
+
+ size = sizeof(numbers)/sizeof(float);
+
+ if (count < size) {
+ count++;
+ } else {
+ sum -= numbers[0];
+ }
+ for (i = size - count ; i < size-1; i++) {
+ numbers[i] = numbers[i+1];
+ }
+ sum += newval1;
+ numbers[size-1] = newval1;
+
+ return sum / (float)count;
+}
+// Floating Average routine 2
+float FloatingAverage2(float newval2) {
+ static float numbers[5];
+ static float sum = 0;
+ static int count = 0;
+ int size;
+ int i;
+
+ size = sizeof(numbers)/sizeof(float);
+
+ if (count < size) {
+ count++;
+ } else {
+ sum -= numbers[0];
+ }
+ for (i = size - count ; i < size-1; i++) {
+ numbers[i] = numbers[i+1];
+ }
+ sum += newval2;
+ numbers[size-1] = newval2;
+
+ return sum / (float)count;
+}
+// Floating Average routine 3
+float FloatingAverage3(float newval3) {
+ static float numbers[5];
+ static float sum = 0;
+ static int count = 0;
+ int size;
+ int i;
+
+ size = sizeof(numbers)/sizeof(float);
+
+ if (count < size) {
+ count++;
+ } else {
+ sum -= numbers[0];
+ }
+ for (i = size - count ; i < size-1; i++) {
+ numbers[i] = numbers[i+1];
+ }
+ sum += newval3;
+ numbers[size-1] = newval3;
+
+ return sum / (float)count;
+}
+// Floating Average routine 4
+float FloatingAverage4(float newval4) {
+ static float numbers[5];
+ static float sum = 0;
+ static int count = 0;
+ int size;
+ int i;
+
+ size = sizeof(numbers)/sizeof(float);
+
+ if (count < size) {
+ count++;
+ } else {
+ sum -= numbers[0];
+ }
+ for (i = size - count ; i < size-1; i++) {
+ numbers[i] = numbers[i+1];
+ }
+ sum += newval4;
+ numbers[size-1] = newval4;
+
+ return sum / (float)count;
+}
+// Floating Average routine 5
+float FloatingAverage5(float newval5) {
+ static float numbers[5];
+ static float sum = 0;
+ static int count = 0;
+ int size;
+ int i;
+
+ size = sizeof(numbers)/sizeof(float);
+
+ if (count < size) {
+ count++;
+ } else {
+ sum -= numbers[0];
+ }
+ for (i = size - count ; i < size-1; i++) {
+ numbers[i] = numbers[i+1];
+ }
+ sum += newval5;
+ numbers[size-1] = newval5;
+
+ return sum / (float)count;
+}
+// Floating Average routine 6
+float FloatingAverage6(float newval6) {
+ static float numbers[5];
+ static float sum = 0;
+ static int count = 0;
+ int size;
+ int i;
+
+ size = sizeof(numbers)/sizeof(float);
+
+ if (count < size) {
+ count++;
+ } else {
+ sum -= numbers[0];
+ }
+ for (i = size - count ; i < size-1; i++) {
+ numbers[i] = numbers[i+1];
+ }
+ sum += newval6;
+ numbers[size-1] = newval6;
+
+ return sum / (float)count;
+}
+
+
diff -r 000000000000 -r 0732b16d9a92 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jan 06 19:01:44 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e