Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 124 lines (98 sloc) 3.354 kB
d4acac8 @CupNoodles Added modifications by alendria here http://forums.adafruit.com/viewt…
CupNoodles authored
1 #include "/opt/local/include/usb.h"
f423d9c @CupNoodles First commit - copied from http://spokepov.cvs.sourceforge.net/viewvc…
CupNoodles authored
2
3 enum { SERIAL=1, PARALLEL, USB};
4
5 enum {CLK, MOSI, MISO, RESET}; //pins!
6
7 #define COMP_CMD_RDEEPROM 0x85
8 #define COMP_CMD_WREEPROM 0x86
9 #define COMP_CMD_RDEEPROM16 0x87
10 #define COMP_CMD_WREEPROM16 0x88
11
12
13
14 // these are specifically assigned to USBtiny courtesy of Adafruit Industries,
15 // if you need your own VID and PIDs you can get them for cheap from
16 // www.mecanique.co.uk so please don't reuse these. Thanks!
17
18 #define USBDEV_VENDOR 0x1781
19 #define USBDEV_PRODUCT 0x0C9F
20
21 enum
22 {
23 // Generic requests
24 USBTINY_ECHO, // echo test
25 USBTINY_READ, // read byte (wIndex:address)
26 USBTINY_WRITE, // write byte (wIndex:address, wValue:value)
27 USBTINY_CLR, // clear bit (wIndex:address, wValue:bitno)
28 USBTINY_SET, // set bit (wIndex:address, wValue:bitno)
29 // Programming requests
30 USBTINY_POWERUP, // apply power (wValue:SCK-period, wIndex:RESET)
31 USBTINY_POWERDOWN, // remove power from chip
32 USBTINY_SPI, // issue SPI command (wValue:c1c0, wIndex:c3c2)
33 USBTINY_POLL_BYTES, // set poll bytes for write (wValue:p1p2)
34 USBTINY_FLASH_READ, // read flash (wIndex:address)
35 USBTINY_FLASH_WRITE, // write flash (wIndex:address, wValue:timeout)
36 USBTINY_EEPROM_READ, // read eeprom (wIndex:address)
37 USBTINY_EEPROM_WRITE, // write eeprom (wIndex:address, wValue:timeout)
38 USBTINY_DDRWRITE, // set port direction
39 USBTINY_SPI1 // a single SPI command
40 };
41
42 enum
43 {
44 RESET_LOW = 0,
45 RESET_HIGH = 1,
46 SCK_MIN = 1, // usec (target clock >= 4 MHz)
47 SCK_MAX = 250, // usec (target clock >= 16 KHz)
48 SCK_DEFAULT = 10, // usec (target clock >= 0.4 MHz)
49 CHUNK_SIZE = 128, // must be power of 2 less than 256
50 USB_TIMEOUT = 500, // msec
51 };
52
53 class SpokePOVComm {
54 public:
55 virtual void setpin(int b, bool val=true) = 0;
56 virtual bool getpin(int b) = 0;
57 virtual ~SpokePOVComm(void) {};
58 virtual bool IsOK(void) = 0;
59 void reset(void);
60 int getfd(void);
61 bool readbyte(unsigned int,unsigned char *);
62 bool read16byte(unsigned int,unsigned char *);
63 bool writebyte(unsigned int, unsigned char);
64 bool write16byte(unsigned int addr, unsigned char *data);
65 bool spi_xfer(unsigned char c);
66 bool spi_get(unsigned char *c);
67
68 protected:
69 wxString port;
70 int fd;
71 int type;
72
73 public:
74 int delay;
75 };
76
77
78 //////////////////////////////////////////////////
79
80
81 class USBComm: public SpokePOVComm {
82 public:
83 USBComm(void);
84 ~USBComm();
85 bool IsOK(void);
86 void setpin(int b, bool val=true);
87 bool getpin(int b);
88 bool usbspi_xfer(unsigned char c);
89 bool usbspi_get(unsigned char *c);
90
91 void usb_control ( int req, int val, int index );
92 int usb_in ( int req, int val, int index, unsigned char *buf, int buflen, int umax );
93 int usb_out ( int req, int val, int index, unsigned char* buf, int buflen, int umax );
94
95 private:
96 usb_dev_handle* usb_handle;
97 };
98
99 //////////////////////////////////////////////////
100
101
102 class SerialComm: public SpokePOVComm {
103 public:
104 SerialComm(wxString);
105 ~SerialComm();
106 void setpin(int b, bool val=true);
107 bool getpin(int b);
108 bool IsOK(void);
109 };
110
111
112 //////////////////////////////////////////////////////////////////////////
113
114 class ParallelComm: public SpokePOVComm {
115 public:
116 ParallelComm(wxString);
117 ~ParallelComm(void);
118 void setpin(int b, bool val=true);
119 bool getpin(int b);
120 bool IsOK(void);
121 };
122
123 SpokePOVComm *CommFactory(wxString type, wxString port);
Something went wrong with that request. Please try again.