forked from l29ah/libmpsse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.PYTHON.html
285 lines (245 loc) · 18.7 KB
/
README.PYTHON.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module mpsse</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>mpsse</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/lib/python2.6/dist-packages/mpsse.py">/usr/lib/python2.6/dist-packages/mpsse.py</a><br><a href="http://docs.python.org/library/mpsse">Module Docs</a></font></td></tr></table>
<p></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="pylibmpsse.html">pylibmpsse</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="mpsse.html#MPSSE">MPSSE</a>
</font></dt></dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="MPSSE">class <strong>MPSSE</strong></a></font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Python class wrapper for libmpsse.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="MPSSE-__init__"><strong>__init__</strong></a>(self, mode<font color="#909090">=None</font>, frequency<font color="#909090">=100000</font>, endianess<font color="#909090">=0</font>)</dt><dd><tt>Class constructor.<br>
<br>
@mode - The <a href="#MPSSE">MPSSE</a> mode to use, one of: SPI0, SPI1, SPI2, SPI3, I2C, GPIO, BITBANG, None.<br>
If None, no attempt will be made to connect to the FTDI chip. Use this if you want to call the Open method manually.<br>
@frequency - The frequency to use for the specified serial protocol, in hertz (default: 100KHz).<br>
@endianess - The endianess of data transfers, one of: MSB, LSB (default: MSB).<br>
<br>
Returns None.</tt></dd></dl>
<dl><dt><a name="MPSSE-Open"><strong>Open</strong></a>(self, vid, pid, mode, frequency<font color="#909090">=100000</font>, endianess<font color="#909090">=0</font>, interface<font color="#909090">=1</font>, description<font color="#909090">=None</font>, serial<font color="#909090">=None</font>, index<font color="#909090">=0</font>)</dt><dd><tt>Opens the specified FTDI device.<br>
Called internally by __init__ if the __init__ mode is not None.<br>
<br>
@vid - FTDI USB vendor ID.<br>
@pid - FTDI USB product ID.<br>
@mode - The <a href="#MPSSE">MPSSE</a> mode to use, one of: SPI0, SPI1, SPI2, SPI3, I2C, GPIO, BITBANG.<br>
@frequency - The frequency to use for the specified serial protocol, in hertz (default: 100KHz).<br>
@endianess - The endianess of data transfers, one of: MSB, LSB (default: MSB).<br>
@interface - The interface to use on the FTDI chip, one of: IFACE_A, IFACE_B, IFACE_C, IFACE_D, IFACE_ANY (default: IFACE_A).<br>
@description - FTDI device product description (default: None).<br>
@serial - FTDI device serial number (default: None).<br>
@index - Number of matching device to open if there are more than one, starts with zero (default: 0).<br>
<br>
Returns MPSSE_OK on success.<br>
Raises an exeption on failure.</tt></dd></dl>
<dl><dt><a name="MPSSE-Close"><strong>Close</strong></a>(self)</dt><dd><tt>Closes the FTDI device connection, deinitializes libftdi, and frees the libmpsse context.<br>
<br>
Returns None.</tt></dd></dl>
<dl><dt><a name="MPSSE-EnableBitmode"><strong>EnableBitmode</strong></a>(self, tf)</dt><dd><tt>Enables/disables bitwise data transfers.<br>
Called internally by ReadBits and WriteBites.<br>
<br>
@tf - Set to 1 to enable bitwise transfers, 0 to disable.<br>
<br>
Returns None.</tt></dd></dl>
<dl><dt><a name="MPSSE-ErrorString"><strong>ErrorString</strong></a>(self)</dt><dd><tt>Returns the last libftdi error string.</tt></dd></dl>
<dl><dt><a name="MPSSE-FlushAfterRead"><strong>FlushAfterRead</strong></a>(self, tf)</dt><dd><tt>Enables / disables the explicit flushing of the recieve buffer after each read operation.<br>
<br>
@tf - Set to 1 to enable flushing, 0 to disable (disabled by default).<br>
<br>
Returns None.</tt></dd></dl>
<dl><dt><a name="MPSSE-GetAck"><strong>GetAck</strong></a>(self)</dt><dd><tt>Returns the last received ACK bit.<br>
<br>
Returns one of: ACK, NACK.</tt></dd></dl>
<dl><dt><a name="MPSSE-GetClock"><strong>GetClock</strong></a>(self)</dt><dd><tt>Returns the currently configured clock rate, in hertz.</tt></dd></dl>
<dl><dt><a name="MPSSE-GetDescription"><strong>GetDescription</strong></a>(self)</dt><dd><tt>Returns the description of the FTDI chip, if any. <br>
This will only be populated if __init__ was used to open the device.</tt></dd></dl>
<dl><dt><a name="MPSSE-GetPid"><strong>GetPid</strong></a>(self)</dt><dd><tt>Returns the product ID of the FTDI chip.</tt></dd></dl>
<dl><dt><a name="MPSSE-GetVid"><strong>GetVid</strong></a>(self)</dt><dd><tt>Returns the vendor ID of the FTDI chip.</tt></dd></dl>
<dl><dt><a name="MPSSE-PinHigh"><strong>PinHigh</strong></a>(self, pin)</dt><dd><tt>Sets the specified GPIO pin high.<br>
<br>
@pin - Pin number 0 - 11 in GPIO mode.<br>
In all other modes, one of: GPIOL0, GPIOL1, GPIOL2, GPIOL3, GPIOH0, GPIOH1, GPIOH2, GPIOH3, GPIOH4, GPIOH5, GPIOH6, GPIOH7.<br>
<br>
Returns MPSSE_OK on success.<br>
Raises an exception on failure.</tt></dd></dl>
<dl><dt><a name="MPSSE-PinLow"><strong>PinLow</strong></a>(self, pin)</dt><dd><tt>Sets the specified GPIO pin low.<br>
<br>
@pin - Pin number 0 - 11 in GPIO mode.<br>
In all other modes, one of: GPIOL0, GPIOL1, GPIOL2, GPIOL3, GPIOH0, GPIOH1, GPIOH2, GPIOH3, GPIOH4, GPIOH5, GPIOH6, GPIOH7.<br>
<br>
Returns MPSSE_OK on success.<br>
Raises an exception on failure.</tt></dd></dl>
<dl><dt><a name="MPSSE-PinState"><strong>PinState</strong></a>(self, pin, state<font color="#909090">=-1</font>)</dt><dd><tt>Checks the current state of the pins.<br>
For use in BITBANG mode only.<br>
<br>
@pin - The pin number whose state you want to check. <br>
@state - The value returned by ReadPins. If not specified, ReadPins will be called automatically.<br>
<br>
Returns a 1 if the pin is high, 0 if the pin is low.</tt></dd></dl>
<dl><dt><a name="MPSSE-Read"><strong>Read</strong></a>(self, size)</dt><dd><tt>Reads bytes over the selected serial protocol.<br>
<br>
@size - Number of bytes to read.<br>
<br>
Returns a string of size bytes.</tt></dd></dl>
<dl><dt><a name="MPSSE-ReadBits"><strong>ReadBits</strong></a>(self, n)</dt><dd><tt>Performs a bitwise read of up to 8 bits at a time.<br>
<br>
@n - Number of bits to read.<br>
<br>
Returns an integer value with the read bits set.</tt></dd></dl>
<dl><dt><a name="MPSSE-ReadPins"><strong>ReadPins</strong></a>(self)</dt><dd><tt>Reads the current state of the chip's pins.<br>
For use in BITBANG mode only.<br>
<br>
Returns an integer with the corresponding pin's bits set.</tt></dd></dl>
<dl><dt><a name="MPSSE-SendAcks"><strong>SendAcks</strong></a>(self)</dt><dd><tt>Causes all subsequent I2C read operations to respond with an acknowledgement.<br>
<br>
Returns None.</tt></dd></dl>
<dl><dt><a name="MPSSE-SendNacks"><strong>SendNacks</strong></a>(self)</dt><dd><tt>Causes all subsequent I2C read operations to respond with a no-acknowledgement.<br>
<br>
Returns None.</tt></dd></dl>
<dl><dt><a name="MPSSE-SetAck"><strong>SetAck</strong></a>(self, ack)</dt><dd><tt>Sets the transmitted ACK bit.<br>
For use only in I2C mode.<br>
<br>
@ack - One of: ACK, NACK.<br>
<br>
Returns None.</tt></dd></dl>
<dl><dt><a name="MPSSE-SetCSIdle"><strong>SetCSIdle</strong></a>(self, idle)</dt><dd><tt>Sets the idle state of the chip select pin.<br>
<br>
@idle - Set to 1 to idle high, 0 to idle low (CS idles high by default).<br>
<br>
Returns None.</tt></dd></dl>
<dl><dt><a name="MPSSE-SetClock"><strong>SetClock</strong></a>(self, frequency)</dt><dd><tt>Sets the appropriate divisor for the desired clock frequency.<br>
Called internally by __init__ and Open.<br>
<br>
@frequency - The desired clock frequency, in hertz.<br>
<br>
Returns MPSSE_OK on success.<br>
Raises an exception on failure.</tt></dd></dl>
<dl><dt><a name="MPSSE-SetDirection"><strong>SetDirection</strong></a>(self, direction)</dt><dd><tt>Sets the input/output direction of pins as determined by direction (1 = Output, 0 = Input). <br>
For use in BITBANG mode only.<br>
<br>
@direction - Byte indicating input/output direction of each bit (1 is output, 0 is input). <br>
<br>
Returns MPSSE_OK on success.<br>
Raises an exception on failure.</tt></dd></dl>
<dl><dt><a name="MPSSE-SetLoopback"><strong>SetLoopback</strong></a>(self, enable)</dt><dd><tt>Enable / disable internal loopback. Loopback is disabled by default.<br>
<br>
@enable - Set to 1 to enable loopback, 0 to disable (disabled by default).<br>
<br>
Returns MPSSE_OK on success.<br>
Raises an exception on failure.</tt></dd></dl>
<dl><dt><a name="MPSSE-SetMode"><strong>SetMode</strong></a>(self, mode, endianess)</dt><dd><tt>Sets the appropriate transmit and receive commands based on the requested mode and byte order.<br>
Called internally by __init__ and Open.<br>
<br>
@mode - The <a href="#MPSSE">MPSSE</a> mode to use, one of: SPI0, SPI1, SPI2, SPI3, I2C, GPIO, BITBANG.<br>
@endianess - The endianess of data transfers, one of: MSB, LSB.<br>
<br>
Returns MPSSE_OK on success.<br>
Raises an exception on failure.</tt></dd></dl>
<dl><dt><a name="MPSSE-Start"><strong>Start</strong></a>(self)</dt><dd><tt>Send data start condition.<br>
<br>
Returns MPSSE_OK on success.<br>
Raises an exception on failure.</tt></dd></dl>
<dl><dt><a name="MPSSE-Stop"><strong>Stop</strong></a>(self)</dt><dd><tt>Send data stop condition.<br>
<br>
Returns MPSSE_OK on success.<br>
Raises an exception on failure.</tt></dd></dl>
<dl><dt><a name="MPSSE-Transfer"><strong>Transfer</strong></a>(self, data)</dt><dd><tt>Transfers data over the selected serial protocol.<br>
For use only in SPI0, SPI1, SPI2, SPI3 modes.<br>
<br>
@data - A string of bytes to be written.<br>
<br>
Returns a string of len(data) bytes.</tt></dd></dl>
<dl><dt><a name="MPSSE-Tristate"><strong>Tristate</strong></a>(self)</dt><dd><tt>Puts all I/O pins into a tristate mode (FT232H only).</tt></dd></dl>
<dl><dt><a name="MPSSE-Version"><strong>Version</strong></a>(self)</dt><dd><tt>Returns the libmpsse version number.<br>
High nibble is major, low nibble is minor.</tt></dd></dl>
<dl><dt><a name="MPSSE-Write"><strong>Write</strong></a>(self, data)</dt><dd><tt>Writes bytes out via the selected serial protocol.<br>
<br>
@data - A string of bytes to be written.<br>
<br>
Returns MPSSE_OK on success.<br>
Raises an exception on failure.</tt></dd></dl>
<dl><dt><a name="MPSSE-WriteBits"><strong>WriteBits</strong></a>(self, bits, n)</dt><dd><tt>Performs a bitwise write of up to 8 bits at a time.<br>
<br>
@bits - An integer of bits to be written.<br>
@n - Transmit n number of least-significant bits.<br>
<br>
Returns MPSSE_OK on success.<br>
Raises an exception on failure.</tt></dd></dl>
<dl><dt><a name="MPSSE-WritePins"><strong>WritePins</strong></a>(self, data)</dt><dd><tt>Writes a new state to the chip's pins.<br>
For use in BITBANG mode only.<br>
<br>
@data - An integer with the bits set to the desired pin states (1 = output, 0 = input).<br>
<br>
Returns MPSSE_OK on success.<br>
Raises an exception on failure.</tt></dd></dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>ACK</strong> = 0<br>
<strong>BITBANG</strong> = 7<br>
<strong>FIFTEEN_MHZ</strong> = 15000000<br>
<strong>FIVE_MHZ</strong> = 5000000<br>
<strong>FOUR_HUNDRED_KHZ</strong> = 400000<br>
<strong>GPIO</strong> = 6<br>
<strong>GPIOH0</strong> = 4<br>
<strong>GPIOH1</strong> = 5<br>
<strong>GPIOH2</strong> = 6<br>
<strong>GPIOH3</strong> = 7<br>
<strong>GPIOH4</strong> = 8<br>
<strong>GPIOH5</strong> = 9<br>
<strong>GPIOH6</strong> = 10<br>
<strong>GPIOH7</strong> = 11<br>
<strong>GPIOL0</strong> = 0<br>
<strong>GPIOL1</strong> = 1<br>
<strong>GPIOL2</strong> = 2<br>
<strong>GPIOL3</strong> = 3<br>
<strong>I2C</strong> = 5<br>
<strong>IFACE_A</strong> = 1<br>
<strong>IFACE_ANY</strong> = 0<br>
<strong>IFACE_B</strong> = 2<br>
<strong>IFACE_C</strong> = 3<br>
<strong>IFACE_D</strong> = 4<br>
<strong>LSB</strong> = 8<br>
<strong>MPSSE_FAIL</strong> = -1<br>
<strong>MPSSE_OK</strong> = 0<br>
<strong>MSB</strong> = 0<br>
<strong>NACK</strong> = 1<br>
<strong>ONE_HUNDRED_KHZ</strong> = 100000<br>
<strong>ONE_MHZ</strong> = 1000000<br>
<strong>SIX_MHZ</strong> = 6000000<br>
<strong>SPI0</strong> = 1<br>
<strong>SPI1</strong> = 2<br>
<strong>SPI2</strong> = 3<br>
<strong>SPI3</strong> = 4<br>
<strong>TEN_MHZ</strong> = 10000000<br>
<strong>THIRTY_MHZ</strong> = 30000000<br>
<strong>TWELVE_MHZ</strong> = 12000000<br>
<strong>TWO_MHZ</strong> = 2000000</td></tr></table>
</body></html>