Library test v 0.4

Dependencies:   mbed MCP23S17

Files at this revision

API Documentation at this revision

Comitter:
romilly
Date:
Mon Aug 23 10:59:22 2010 +0000
Parent:
2:2e8fca65efaf
Child:
4:15297eea34f6
Commit message:

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Aug 22 15:39:32 2010 +0000
+++ b/main.cpp	Mon Aug 23 10:59:22 2010 +0000
@@ -7,7 +7,7 @@
 * NB this code is inteded to test the driver library, not the chip
 * which is assumed to work as specified
 * MCP23S17 datasheet http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf
-* version 0.2
+* version 0.3
 */
 
 #include "mbed.h"
@@ -44,40 +44,40 @@
 void testInputFromPortA() {
     reset();
     chipA0.output(); // prepare to output from the mbed
-    chip.directionA(0x01); // chip Port A bit 0 set to input
+    chip.direction(PORT_A,0x01); // chip Port A bit 0 set to input
     chipA0 = 0;
-    checkEqual(0, chip.inputA() && 0x1,"read from A0");
+    checkEqual(0, chip.read(PORT_A) && 0x1,"read from A0");
     chipA0 = 1;
-    checkEqual(1, chip.inputA() && 0x1,"read from A0");
+    checkEqual(1, chip.read(PORT_A) && 0x1,"read from A0");
 }
 
 void testInputFromPortB() {
     reset();
     chipB0.output(); // output from the mbed
-    chip.directionB(0x01); //  bit 0 set to input
+    chip.direction(PORT_B,0x01); //  bit 0 set to input
     chipB0 = 0;
-    checkEqual(0, chip.inputB() && 0x1,"read from B0");
+    checkEqual(0, chip.read(PORT_B) && 0x1,"read from B0");
     chipB0 = 1;
-    checkEqual(1, chip.inputB() && 0x1,"read from B0");
+    checkEqual(1, chip.read(PORT_B) && 0x1,"read from B0");
 }
 
 void testOutputToPortA() {
     reset();
     chipA0.input(); // input to the mbed
-    chip.directionA(0xFE); //  bit 0 set to output
-    chip.outputA(0x00);
+    chip.direction(PORT_A, 0xFE); //  bit 0 set to output
+    chip.write(PORT_A,0x00);
     checkEqual(0, int(chipA0),"write to A0");
-    chip.outputA(0x01);
+    chip.write(PORT_A,0x01);
     checkEqual(1, int(chipA0),"write to A0");
 }
 
 void testOutputToPortB() {
     reset();
     chipB0.input(); // input to the mbed
-    chip.directionB(0xFE); //  bit 0 set to output
-    chip.outputB(0x00);
+    chip.direction(PORT_B, 0xFE); //  bit 0 set to output
+    chip.write(PORT_B,0x00);
     checkEqual(0, int(chipB0),"write to B0");
-    chip.outputB(0x01);
+    chip.write(PORT_B,0x01);
     checkEqual(1, int(chipB0),"write to B0");
 }
 
@@ -85,11 +85,11 @@
 // NB by default both int pins are Active-LOW
     reset();
     chipA0.output(); // output from the mbed
-    chip.directionA(0x01); //  bit 0 set to input
+    chip.direction(PORT_A, 0x01); //  bit 0 set to input
     chipA0 = 1;
     checkEqual(1, int(chipIntA),"interrupts not yet enabled");
     chipA0 = 0;
-    chip.interruptEnableA(0x01); // interupt enabled on pin 0
+    chip.interruptEnable(PORT_A, 0x01); // interupt enabled on pin A0
     checkEqual(1, int(chipIntA), "value has not changed");
     chipA0 = 1;
     wait_us(1); // test fails without this - mbed is too darned fast!
@@ -100,9 +100,9 @@
 // NB by default both int pins are Active-LOW
     reset();
     chipB0.output(); // output from the mbed
-    chip.directionB(0x01); //  bit 0 set to input
+    chip.direction(PORT_B, 0x01); //  bit 0 set to input
     chipB0 = 1;
-    chip.interruptEnableB(0x01); // interupt enabled on pin 0
+    chip.interruptEnable(PORT_B, 0x01); // interupt enabled on pin 0
     wait_us(1); 
     checkEqual(0, int(chipIntB), "interruptB");
 }
@@ -110,9 +110,9 @@
 void testMirrorInterrupts() {
     reset();
     chipB0.output(); // output from the mbed
-    chip.directionB(0x01); //  bit 0 set to input
+    chip.direction(PORT_B, 0x01); //  bit 0 set to input
     chipB0 = 1;
-    chip.interruptEnableB(0x01); // interupt enabled on pin 0
+    chip.interruptEnable(PORT_B, 0x01); // interupt enabled on pin 0
     wait_us(1); 
     checkEqual(0, int(chipIntB), "interruptB");
     checkEqual(1, int(chipIntA), "before mirroring"); // no interrupt A yet
@@ -126,7 +126,7 @@
 
 void testInterruptPolarity() {
 // NB by default both int pins are Active-LOW
-// interrupt off (so LHIGH) after POR
+// interrupt off (so HIGH) after POR
     reset();
     checkEqual(1, int(chipIntA),"interrupt ACTIVE_LOW by default");
     chip.interruptPolarity(ACTIVE_HIGH);
@@ -140,13 +140,13 @@
 void testInterruptControlAndDefaultValueOnPortA() {
      reset();
      chipA0.output(); // output from the mbed
-     chip.directionA(0x01); //  bit 0 set to input
+     chip.direction(PORT_A, 0x01); //  bit 0 set to input
      chipA0 = 0;
      checkEqual(1, int(chipIntA),"interrupt ACTIVE_LOW by default");
-     chip.interruptEnableA(0x01); // interupt enabled on pin 0
-     chip.defaultValueA(0x01); // default value != input value
+     chip.interruptEnable(PORT_A, 0x01); // interupt enabled on pin 0
+     chip.defaultValue(PORT_A, 0x01); // default value != input value
      checkEqual(1, int(chipIntA),"still no interrupt"); // interrupt control still set to interrupt on change
-     chip.interruptControlA(0x01);
+     chip.interruptControl(PORT_A, 0x01);
      wait_us(1);
      checkEqual(0, int(chipIntA), "expecting interrupt as default != input");
 }
@@ -161,5 +161,8 @@
     testInterruptPolarity();
     testMirrorInterrupts();
     testInterruptControlAndDefaultValueOnPortA();
+    // testInterruptControlAndDefaultValueOnPortB();
+    // testInterruptCaptureA();
+    // testInterruptCaptureB();
     printf("all tests OK\r\n");
 }