Added support for banked registers

Dependents:   Component_Test_Interface FalconWing MX_Spoile_Test Simple_Power_Distribution ... more

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Mon Dec 20 15:53:38 2010 +0000
Parent:
0:1a9288cc0630
Child:
2:2d4ee919e8a7
Commit message:
Cleaned up and added documentation

Changed in this revision

MCP23017.cpp Show annotated file Show diff for this revision Revisions of this file
MCP23017.h Show annotated file Show diff for this revision Revisions of this file
--- a/MCP23017.cpp	Sat Dec 18 18:49:19 2010 +0000
+++ b/MCP23017.cpp	Mon Dec 20 15:53:38 2010 +0000
@@ -3,18 +3,29 @@
 *
 * Released under the MIT License: http://mbed.org/license/mit
 *
-* version 0.2
+* version 0.2 Initial Release
+* version 0.3 Cleaned up
 */
 
 #include "mbed.h"
 #include "MCP23017.h"
 
+/** Create an MCP23017 object connected to the specified I2C object and using the specified deviceAddress
+*
+* @param I2C &i2c the I2C port to connect to 
+* @param char deviceAddress the address of the MSC23017
+*/
 MCP23017::MCP23017(I2C &i2c, char deviceAddress) : _i2c(i2c) {
     _writeOpcode = deviceAddress & 0xFE; // low order bit = 0 for write
     _readOpcode  = deviceAddress | 0x01; // low order bit = 1 for read
     _init();
 }
 
+/** Read from specified MCP23017 register
+*
+* @param char address the internal registeraddress of the MSC23017
+* @returns data from register 
+*/
 char MCP23017::_read(char address) {
     char data[2];
     char result;
@@ -27,6 +38,10 @@
 }
 
 
+/** Write to specified MCP23017 register
+*
+* @param char address the internal registeraddress of the MSC23017
+*/
 void MCP23017::_write(char address, char byte) {
     char data[2];
 
@@ -36,15 +51,30 @@
 }
 
 
+/** Init MCP23017
+*
+* @param
+* @returns 
+*/
 void MCP23017::_init() {
     _write(IOCON, (IOCON_BYTE_MODE | IOCON_HAEN )); // Hardware addressing on, operations toggle between A and B registers
 
 }
 
+/** Set I/O direction of specified MCP23017 Port
+*
+* @param Port Port address (Port_A or Port_B)
+* @param char direction pin direction (0 = output, 1 = input)
+*/
 void MCP23017::direction(Port port, char direction) {
     _write(port + IODIRA, direction);
 }
 
+/** Set Pull-Up Resistors on specified MCP23017 Port
+*
+* @param Port Port address (Port_A or Port_B)
+* @param char offOrOn per pin (0 = off, 1 = on)
+*/
 void MCP23017::configurePullUps(Port port, char offOrOn) {
     _write(port + GPPUA, offOrOn);
 }
@@ -82,51 +112,21 @@
     _write(port + INTCONA, interruptControlBits);
 }
 
+/** Write to specified MCP23017 Port
+*
+* @param Port Port address (Port_A or Port_B)
+* @param char byte data to write
+*/
 void MCP23017::write(Port port, char byte) {
     _write(port + OLATA, byte);
-    
-//faster    (56 sec for lcd init)
-//   char data[2];
-//
-//   data[0] = OLATA + port;
-//   data[1] = byte;
-//   _i2c.write(_writeOpcode, data, 2);    // Write data to selected Register
-
-//faster  47 sec for complete init
-//   _i2c.start();
-//   _i2c.write(_writeOpcode);    // Select Device
-//   _i2c.write(OLATA + port);    // Select Register
-//   _i2c.write(byte);            // Write data to selected Register
-//   _i2c.stop();  
 }
     
-
+/** Read from specified MCP23017 Port
+*
+* @param Port Port address (Port_A or Port_B)
+* @returns data from Port 
+*/
 char MCP23017::read(Port port) {
     return _read(port + GPIOA);
 }
 
-// Optimised Databus write operation for Graphics LCD.
-//   Port A is used as databus, Port B is used as controlbus.
-//
-void MCP23017::databus_write(char data, char ctrl_1, char ctrl_2, char ctrl_3, char ctrl_4) {
-
-   _i2c.start();
-   _i2c.write(_writeOpcode);    // Select Device
-   _i2c.write(OLATA);           // Select Register A
-
-//Remove separate CS Low, to speed up
-//   _i2c.write(data);            // Write data to Port A Register and Auto-incr to Register B
-//   _i2c.write(ctrl_1);          // Write control to Port B  and Auto-incr to Register A
-   
-   _i2c.write(data);            // Write data to Port A Register and Auto-incr to Register B
-   _i2c.write(ctrl_2);          // Write control to Port B  and Auto-incr to Register A
-   
-   _i2c.write(data);            // Write data to Port A Register and Auto-incr to Register B
-   _i2c.write(ctrl_3);          // Write control to Port B  and Auto-incr to Register A
-
-//Remove separate CS High, to speed up
-//   _i2c.write(data);            // Write data to Port A Register and Auto-incr to Register B
-//   _i2c.write(ctrl_4);          // Write control to Port B  and Auto-incr to Register A
-   
-   _i2c.stop();  
-}
\ No newline at end of file
--- a/MCP23017.h	Sat Dec 18 18:49:19 2010 +0000
+++ b/MCP23017.h	Mon Dec 20 15:53:38 2010 +0000
@@ -3,7 +3,8 @@
 *
 * Released under the MIT License: http://mbed.org/license/mit
 *
-* version 0.2
+* version 0.2 Initial Release
+* version 0.3 Cleaned up
 */
 #include "mbed.h"
 
@@ -59,7 +60,7 @@
     void interruptControl(Port port, char interruptControlBits);
     char read(Port port);
     void write(Port port, char byte);
-    void databus_write(char data, char ctrl_1, char ctrl_2, char ctrl_3, char ctrl_4);
+
 protected:
     I2C &_i2c;
     void _init();