UNPKG

rpi-softspi

Version:

Software SPI implementation to use any Raspberry Pi pins as a SPI interface

1,635 lines (421 loc) • 19.2 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: SoftSPI</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Class: SoftSPI</h1> <section> <header> <h2>SoftSPI</h2> <div class="class-description">Represents a SPI (Serial Peripheral Interface) using user defined pins. So it is a software solution instead of using the hardware SPI. The class implements the SPI protocol (<a href="https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus">https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus</a>), but currently without a frequency support.</div> </header> <article> <div class="container-overview"> <h2>Constructor</h2> <h4 class="name" id="SoftSPI"><span class="type-signature"></span>new SoftSPI<span class="signature">(options)</span><span class="type-signature"></span></h4> <div class="description"> Creates a new SPI instance for a slave device. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last"> <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>clock</code></td> <td class="type"> <span class="param-type">Number</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">Pin for clock (SCLK)</td> </tr> <tr> <td class="name"><code>miso</code></td> <td class="type"> <span class="param-type">Number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last">Pin for master input slave output (MISO)</td> </tr> <tr> <td class="name"><code>mosi</code></td> <td class="type"> <span class="param-type">Number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last">Pin for master output slave input (MOSI)</td> </tr> <tr> <td class="name"><code>client</code></td> <td class="type"> <span class="param-type">Number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last">Pin for client select (CS)</td> </tr> <tr> <td class="name"><code>clientSelect</code></td> <td class="type"> <span class="param-type">Number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> LOW (0) </td> <td class="description last">Clients needed polarity for activation</td> </tr> <tr> <td class="name"><code>mode</code></td> <td class="type"> <span class="param-type">Number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> 0 </td> <td class="description last">SPI mode (0 - 3)</td> </tr> <tr> <td class="name"><code>bitOrder</code></td> <td class="type"> <span class="param-type">Number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> MSB (1) </td> <td class="description last">Most Significant Bit (MSB = 1) or Least Significant Bit (LSB = 0)</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="softspi.js.html">softspi.js</a>, <a href="softspi.js.html#line15">line 15</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Members</h3> <h4 class="name" id=".LSB"><span class="type-signature">(static, constant) </span>LSB<span class="type-signature"></span></h4> <div class="description"> Least Significatn Bit (= 0) </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="softspi.js.html">softspi.js</a>, <a href="softspi.js.html#line67">line 67</a> </li></ul></dd> </dl> <h4 class="name" id=".MSB"><span class="type-signature">(static, constant) </span>MSB<span class="type-signature"></span></h4> <div class="description"> Most Significant Bit (= 1) </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="softspi.js.html">softspi.js</a>, <a href="softspi.js.html#line59">line 59</a> </li></ul></dd> </dl> <h4 class="name" id="bitOrder"><span class="type-signature"></span>bitOrder<span class="type-signature"></span></h4> <div class="description"> Returns the bit order. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="softspi.js.html">softspi.js</a>, <a href="softspi.js.html#line142">line 142</a> </li></ul></dd> </dl> <h4 class="name" id="bitOrder"><span class="type-signature"></span>bitOrder<span class="type-signature"></span></h4> <div class="description"> Sets the bit order at transfering data. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="softspi.js.html">softspi.js</a>, <a href="softspi.js.html#line121">line 121</a> </li></ul></dd> </dl> <h4 class="name" id="mode"><span class="type-signature"></span>mode<span class="type-signature"></span></h4> <div class="description"> Returns the SPI mode. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="softspi.js.html">softspi.js</a>, <a href="softspi.js.html#line111">line 111</a> </li></ul></dd> </dl> <h4 class="name" id="mode"><span class="type-signature"></span>mode<span class="type-signature"></span></h4> <div class="description"> Sets the SPI mode. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="softspi.js.html">softspi.js</a>, <a href="softspi.js.html#line91">line 91</a> </li></ul></dd> </dl> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="close"><span class="type-signature"></span>close<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="SoftSPI.html">SoftSPI</a>}</span></h4> <div class="description"> Closes the connection to the client by closing the pins. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="softspi.js.html">softspi.js</a>, <a href="softspi.js.html#line333">line 333</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="SoftSPI.html">SoftSPI</a></span> </dd> </dl> <h4 class="name" id="open"><span class="type-signature"></span>open<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="SoftSPI.html">SoftSPI</a>}</span></h4> <div class="description"> Opens the connection to the client by setting up the pins. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="softspi.js.html">softspi.js</a>, <a href="softspi.js.html#line200">line 200</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="SoftSPI.html">SoftSPI</a></span> </dd> </dl> <h4 class="name" id="read"><span class="type-signature"></span>read<span class="signature">(bytes)</span><span class="type-signature"> &rarr; {Array}</span></h4> <div class="description"> Reads the number of bytes from client and supplies them as an array. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>bytes</code></td> <td class="type"> <span class="param-type">Number</span> </td> <td class="description last">Number of bytes to read</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="softspi.js.html">softspi.js</a>, <a href="softspi.js.html#line240">line 240</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">Array</span> </dd> </dl> <h4 class="name" id="transfer"><span class="type-signature"></span>transfer<span class="signature">(data, read<span class="signature-attributes">opt</span>, write<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Array}</span></h4> <div class="description"> Transfers the given data to the client and returns data from the client. The given data can be any data, which is transformable to a byte array. Returns the read data from the client as an array. Each element is one byte. The read data has exactly the same number of bytes like the written data. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>data</code></td> <td class="type"> <span class="param-type">Any</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>read</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> true </td> <td class="description last">Read data from the client</td> </tr> <tr> <td class="name"><code>write</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> true </td> <td class="description last">Write data to the client</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="softspi.js.html">softspi.js</a>, <a href="softspi.js.html#line310">line 310</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">Array</span> </dd> </dl> <h4 class="name" id="write"><span class="type-signature"></span>write<span class="signature">(data)</span><span class="type-signature"> &rarr; {<a href="SoftSPI.html">SoftSPI</a>}</span></h4> <div class="description"> Writes the given data to the client. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>data</code></td> <td class="type"> <span class="param-type">Any</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="softspi.js.html">softspi.js</a>, <a href="softspi.js.html#line250">line 250</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="SoftSPI.html">SoftSPI</a></span> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SoftSPI.html">SoftSPI</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Aug 14 2017 01:12:19 GMT+0200 (Mitteleuropäische Sommerzeit) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>