Files
ioiolib/IOIOLib/doc/ioio/lib/api/TwiMaster.html
2012-01-24 13:04:09 -05:00

364 lines
16 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.6.0_29) on Mon Nov 28 00:50:35 PST 2011 -->
<TITLE>
TwiMaster
</TITLE>
<META NAME="date" CONTENT="2011-11-28">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="TwiMaster";
}
}
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="windowTitle();">
<HR>
<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A>
<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/TwiMaster.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../ioio/lib/api/SpiMaster.Result.html" title="interface in ioio.lib.api"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../ioio/lib/api/TwiMaster.Rate.html" title="enum in ioio.lib.api"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html?ioio/lib/api/TwiMaster.html" target="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="TwiMaster.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
&nbsp;<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY:&nbsp;<A HREF="#nested_class_summary">NESTED</A>&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A>
<!-- ========= END OF TOP NAVBAR ========= -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
ioio.lib.api</FONT>
<BR>
Interface TwiMaster</H2>
<DL>
<DT><B>All Superinterfaces:</B> <DD><A HREF="../../../ioio/lib/api/Closeable.html" title="interface in ioio.lib.api">Closeable</A></DD>
</DL>
<HR>
<DL>
<DT><PRE>public interface <B>TwiMaster</B><DT>extends <A HREF="../../../ioio/lib/api/Closeable.html" title="interface in ioio.lib.api">Closeable</A></DL>
</PRE>
<P>
An interface for controlling a TWI module, in TWI bus-master mode, enabling
communication with multiple TWI-enabled slave modules.
<p>
TWI (Two-Wire Interface) is a common hardware communication protocol,
enabling half-duplex, synchronous point-to-multi-point data transfer. It
requires a physical connection of two lines (SDA, SCL) shared by all the bus
nodes, where the SDA is open-drain and externally pulled-up. TwiMaster
instances are obtained by calling
<CODE>IOIO#openTwiMaster(int, Rate, boolean)</CODE>.
<p>
TWI is the generic name for the specific I2C and SMBus protocols, differing
mostly by the voltage levels they require. This module supports both.
<p>
A TWI transaction is comprised of optional sending of a data buffer from the
master to a single slave, followed by an optional reception of a data buffer
from that slave. Slaves are designated by addresses, which may be 7-bit
(common) or 10-bit (less common). TWI transactions may fail, as a result of
the slave not responding or as result of the slave NACK'ing the request. Such
a transaction is executed using the
<A HREF="../../../ioio/lib/api/TwiMaster.html#writeRead(int, boolean, byte[], int, byte[], int)"><CODE>writeRead(int, boolean, byte[], int, byte[], int)</CODE></A> method.
<p>
The instance is alive since its creation. If the connection with the IOIO
drops at any point, the instance transitions to a disconnected state, in
<p>
The instance is alive since its creation. If the connection with the IOIO
drops at any point, the instance transitions to a disconnected state, in
which every attempt to use it (except <A HREF="../../../ioio/lib/api/Closeable.html#close()"><CODE>Closeable.close()</CODE></A>) will throw a
<A HREF="../../../ioio/lib/api/exception/ConnectionLostException.html" title="class in ioio.lib.api.exception"><CODE>ConnectionLostException</CODE></A>. Whenever <A HREF="../../../ioio/lib/api/Closeable.html#close()"><CODE>Closeable.close()</CODE></A> is invoked the
instance may no longer be used. Any resources associated with it are freed
and can be reused.
<p>
Typical usage:
<pre>
<code>// Uses the SDA1/SCL1 pins, I2C volatege levels at 100KHz.
TwiMaster twi = ioio.openTwiMaster(1, TwiMaster.RATE_100KHz, false);
final byte[] request = new byte[]{ 0x23, 0x45 };
final byte[] response = new byte[3];
if (twi.writeRead(0x19, false, request, 2, response, 3)) {
// response is valid
...
} else {
// handle error
}
twi.close(); // free TWI module and pins
</code></pre>
<P>
<P>
<DL>
<DT><B>See Also:</B><DD><CODE>IOIO#openTwiMaster(int, Rate, boolean)</CODE></DL>
<HR>
<P>
<!-- ======== NESTED CLASS SUMMARY ======== -->
<A NAME="nested_class_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Nested Class Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;class</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../ioio/lib/api/TwiMaster.Rate.html" title="enum in ioio.lib.api">TwiMaster.Rate</A></B></CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;interface</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../ioio/lib/api/TwiMaster.Result.html" title="interface in ioio.lib.api">TwiMaster.Result</A></B></CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;An object that can be waited on for asynchronous calls.</TD>
</TR>
</TABLE>
&nbsp;
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Method Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;boolean</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../ioio/lib/api/TwiMaster.html#writeRead(int, boolean, byte[], int, byte[], int)">writeRead</A></B>(int&nbsp;address,
boolean&nbsp;tenBitAddr,
byte[]&nbsp;writeData,
int&nbsp;writeSize,
byte[]&nbsp;readData,
int&nbsp;readSize)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Perform a single TWI transaction which includes optional transmission and
optional reception of data to a single slave.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../../../ioio/lib/api/TwiMaster.Result.html" title="interface in ioio.lib.api">TwiMaster.Result</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../ioio/lib/api/TwiMaster.html#writeReadAsync(int, boolean, byte[], int, byte[], int)">writeReadAsync</A></B>(int&nbsp;address,
boolean&nbsp;tenBitAddr,
byte[]&nbsp;writeData,
int&nbsp;writeSize,
byte[]&nbsp;readData,
int&nbsp;readSize)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Asynchronous version of
<A HREF="../../../ioio/lib/api/TwiMaster.html#writeRead(int, boolean, byte[], int, byte[], int)"><CODE>writeRead(int, boolean, byte[], int, byte[], int)</CODE></A>.</TD>
</TR>
</TABLE>
&nbsp;<A NAME="methods_inherited_from_class_ioio.lib.api.Closeable"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TH ALIGN="left"><B>Methods inherited from interface ioio.lib.api.<A HREF="../../../ioio/lib/api/Closeable.html" title="interface in ioio.lib.api">Closeable</A></B></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><A HREF="../../../ioio/lib/api/Closeable.html#close()">close</A></CODE></TD>
</TR>
</TABLE>
&nbsp;
<P>
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Method Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="writeRead(int, boolean, byte[], int, byte[], int)"><!-- --></A><H3>
writeRead</H3>
<PRE>
boolean <B>writeRead</B>(int&nbsp;address,
boolean&nbsp;tenBitAddr,
byte[]&nbsp;writeData,
int&nbsp;writeSize,
byte[]&nbsp;readData,
int&nbsp;readSize)
throws <A HREF="../../../ioio/lib/api/exception/ConnectionLostException.html" title="class in ioio.lib.api.exception">ConnectionLostException</A>,
java.lang.InterruptedException</PRE>
<DL>
<DD>Perform a single TWI transaction which includes optional transmission and
optional reception of data to a single slave. This is a blocking
operation that can take a few milliseconds to a few tens of milliseconds.
To abort this operation, client can interrupt the blocked thread.
<P>
<DD><DL>
</DL>
</DD>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>address</CODE> - The slave address, either 7-bit or 10-bit. Note that in some
TWI device documentation the documented addresses are actually
2x the address values used here, as they regard the trailing
0-bit as part of the address.<DD><CODE>tenBitAddr</CODE> - Whether this is a 10-bit addressing mode.<DD><CODE>writeData</CODE> - The request data.<DD><CODE>writeSize</CODE> - The number of bytes to write. Valid value are 0-255.<DD><CODE>readData</CODE> - The array where the response should be stored.<DD><CODE>readSize</CODE> - The expected number of response bytes. Valid value are 0-255.
<DT><B>Returns:</B><DD>Whether operation succeeded.
<DT><B>Throws:</B>
<DD><CODE><A HREF="../../../ioio/lib/api/exception/ConnectionLostException.html" title="class in ioio.lib.api.exception">ConnectionLostException</A></CODE> - Connection to the IOIO has been lost.
<DD><CODE>java.lang.InterruptedException</CODE> - Calling thread has been interrupted.</DL>
</DD>
</DL>
<HR>
<A NAME="writeReadAsync(int, boolean, byte[], int, byte[], int)"><!-- --></A><H3>
writeReadAsync</H3>
<PRE>
<A HREF="../../../ioio/lib/api/TwiMaster.Result.html" title="interface in ioio.lib.api">TwiMaster.Result</A> <B>writeReadAsync</B>(int&nbsp;address,
boolean&nbsp;tenBitAddr,
byte[]&nbsp;writeData,
int&nbsp;writeSize,
byte[]&nbsp;readData,
int&nbsp;readSize)
throws <A HREF="../../../ioio/lib/api/exception/ConnectionLostException.html" title="class in ioio.lib.api.exception">ConnectionLostException</A></PRE>
<DL>
<DD>Asynchronous version of
<A HREF="../../../ioio/lib/api/TwiMaster.html#writeRead(int, boolean, byte[], int, byte[], int)"><CODE>writeRead(int, boolean, byte[], int, byte[], int)</CODE></A>. Returns
immediately and provides a <A HREF="../../../ioio/lib/api/TwiMaster.Result.html" title="interface in ioio.lib.api"><CODE>TwiMaster.Result</CODE></A> object on which the client can
wait for the result.
<P>
<DD><DL>
</DL>
</DD>
<DD><DL>
<DT><B>Throws:</B>
<DD><CODE><A HREF="../../../ioio/lib/api/exception/ConnectionLostException.html" title="class in ioio.lib.api.exception">ConnectionLostException</A></CODE><DT><B>See Also:</B><DD><A HREF="../../../ioio/lib/api/TwiMaster.html#writeRead(int, boolean, byte[], int, byte[], int)"><CODE>writeRead(int, boolean, byte[], int, byte[], int)</CODE></A></DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<A NAME="navbar_bottom"><!-- --></A>
<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/TwiMaster.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../ioio/lib/api/SpiMaster.Result.html" title="interface in ioio.lib.api"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../ioio/lib/api/TwiMaster.Rate.html" title="enum in ioio.lib.api"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html?ioio/lib/api/TwiMaster.html" target="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="TwiMaster.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
&nbsp;<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY:&nbsp;<A HREF="#nested_class_summary">NESTED</A>&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_bottom"></A>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<HR>
</BODY>
</HTML>