![](/media/cache/profiles/2e92962c0b6996add9517e4242ea9bdc.50x50_q85.jpg)
Test application for the library MCP23017_I2C
Dependencies: DebugLibrary MCP23017_I2C mbed
Diff: main.cpp
- Revision:
- 3:3f23faf5f7eb
- Parent:
- 2:83b9df729e73
--- a/main.cpp Fri Jan 09 15:36:08 2015 +0000 +++ b/main.cpp Tue Jan 13 10:09:13 2015 +0000 @@ -44,25 +44,34 @@ g_gpioExp.write(GPB3, 0); break; case 'g': - g_gpioExp.write(GPB7, 1); + g_gpioExp.write(GPB4, 1); break; case 'h': + g_gpioExp.write(GPB4, 0); + break; + case 'i': + g_gpioExp.write(GPB7, 1); + break; + case 'j': g_gpioExp.write(GPB7, 0); break; - case 'i': { + case 'r': + g_gpioExp.reset(); + break; + case 's': { std::list<unsigned char> lcdBus; - lcdBus.push_back(GPA7); + lcdBus.push_back(GPA7); // First item in the list lcdBus.push_back(GPA6); lcdBus.push_back(GPA5); lcdBus.push_back(GPA4); unsigned char busId = g_gpioExp.createBus(lcdBus); - g_gpioExp.busWrite(busId, 0x000A); // GPA7=1, GPA6=0, GPA5=1, GPA4=0 + g_gpioExp.busWrite(busId, 0x000A); // GPA7=1, GPA6=0, GPA5=1, GPA4=0 - LSB is GPB4, MSB is GPA7 + wait_us(20); + g_gpioExp.busWrite(busId, 0x0000); // GPA7=1, GPA6=0, GPA5=1, GPA4=0 + wait_us(20); g_gpioExp.deleteBus(busId); } break; - case 'r': - g_gpioExp.reset(); - break; default: std::cout << "Invalid user choice\r" << std::endl; break; @@ -80,15 +89,18 @@ { char value; std::cout << "\r" << std::endl << "\r" << std::endl << "MCP23017_I2C v0.1\r" << std::endl; - std::cout << "\tSet PortB-0 :\t\ta\r" << std::endl; - std::cout << "\tUnset PortB-0 :\t\tb\r" << std::endl; - std::cout << "\tSet PortB-2 :\t\tc\r" << std::endl; - std::cout << "\tUnset PortB-2 :\t\td\r" << std::endl; - std::cout << "\tSet PortB-3 :\t\te\r" << std::endl; - std::cout << "\tUnset PortB-3 :\t\tf\r" << std::endl; - std::cout << "\tSet PortB-7 :\t\tg\r" << std::endl; - std::cout << "\tUnset PortB-7 :\t\th\r" << std::endl; - std::cout << "\tReset device :\t\tr\r" << std::endl; + std::cout << "\tSet MUX_EN1 (PortB-0) :\t\ta\r" << std::endl; + std::cout << "\tUnset MUX_EN1 (PortB-0) :\t\tb\r" << std::endl; + std::cout << "\tSet MUX_ADDR0 (PortB-2) :\t\tc\r" << std::endl; + std::cout << "\tUnset MUX_ADDR0 (PortB-2) :\t\td\r" << std::endl; + std::cout << "\tSet MUX_ADDR1 (PortB-3) :\t\te\r" << std::endl; + std::cout << "\tUnset MUX_ADDR1 (PortB-3) :\t\tf\r" << std::endl; + std::cout << "\tSet MUX_ADDR2 (PortB-4) :\t\tg\r" << std::endl; + std::cout << "\tUnset MUX_ADDR2 (PortB-4) :\t\th\r" << std::endl; + std::cout << "\tSet BOARD_EN (PortB-7) :\t\ti\r" << std::endl; + std::cout << "\tUnset BOARD_EN (PortB-7) :\t\tj\r" << std::endl; + std::cout << "\tReset device :\t\tr\r" << std::endl; + std::cout << "\tBus test :\t\ts\r" << std::endl; std::cout << "Enter your choice: " << std::flush; value = getchar(); std::cout << "\r" << std::endl; @@ -98,7 +110,7 @@ void GpioAIntr() { unsigned char gpioId, gpioValue; wait(0.6); // Debounce timer - g_gpioExp.getLastInterruptPin(&gpioId, &gpioValue); // Get interrupt info and clear it + g_gpioExp.getLastInterruptPinAndValue(&gpioId, &gpioValue); // Get interrupt info and clear it std::cout << "\r" << std::endl << "GpioAIntr: interrupt on pin #" << std::hex << std::setw(2) << std::setfill('0') << static_cast<unsigned int>(gpioId) << " - value: " << static_cast<unsigned int>(gpioValue) << "\r" << std::endl; }