Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: AdaFruit_RGBLCDShield MCP23017 mbed RTclock
Fork of MCP_test by
Diff: AdaFruit_RGBLCDShield.cpp
- Revision:
- 4:d70e37f6c6bd
- Parent:
- 3:ed09f95739df
- Child:
- 5:6c9ee7e3a20c
--- a/AdaFruit_RGBLCDShield.cpp Sat Aug 02 12:39:25 2014 +0000 +++ b/AdaFruit_RGBLCDShield.cpp Sat Aug 02 13:50:40 2014 +0000 @@ -13,12 +13,23 @@ BSD license, all text above must be included in any redistribution ****************************************************/ - #include "Adafruit_RGBLCDShield.h" #include <stdio.h> #include <string.h> #include <inttypes.h> + +// New MBED code +#define OUTPUT DIR_OUTPUT +#define INPUT DIR_INPUT + +#define LOW 0 +#define HIGH 1 + +#define delayMicroseconds(a) wait(a / 1000000) + +/* Remove Arduino i2c (wire) interface + #include <Wire.h> #ifdef __AVR__ #define WIRE Wire @@ -31,6 +42,7 @@ #else #include "WProgram.h" #endif +*/ // When the display powers up, it is configured as follows: // @@ -51,7 +63,10 @@ // can't assume that its in that state when a sketch starts (and the // RGBLCDShield constructor is called). -Adafruit_RGBLCDShield::Adafruit_RGBLCDShield() { +Adafruit_RGBLCDShield::Adafruit_RGBLCDShield(MCP23017 & inMCP) + : Serial(SERIAL_TX, SERIAL_RX) + , _i2c(inMCP) +{ _i2cAddr = 0; _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; @@ -73,9 +88,6 @@ // we can't begin() yet :( } - - - void Adafruit_RGBLCDShield::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) @@ -115,8 +127,8 @@ // check if i2c if (_i2cAddr != 255) { //_i2c.begin(_i2cAddr); - WIRE.begin(); - _i2c.begin(); + //WIRE.begin(); + //_i2c->begin(); _i2c.pinMode(8, OUTPUT); _i2c.pinMode(6, OUTPUT); @@ -133,8 +145,10 @@ for (uint8_t i=0; i<5; i++) { _i2c.pinMode(_button_pins[i], INPUT); - _i2c.pullUp(_button_pins[i], 1); + //_i2c.pullUp(_button_pins[i], 1); } + + _i2c.internalPullupMask(0xffff); } if (lines > 1) { @@ -302,7 +316,7 @@ location &= 0x7; // we only have 8 locations 0-7 command(LCD_SETCGRAMADDR | (location << 3)); for (int i=0; i<8; i++) { - write(charmap[i]); + _putc(charmap[i]); } command(LCD_SETDDRAMADDR); // unfortunately resets the location to 0,0 } @@ -319,8 +333,10 @@ return 1; } #else -inline void Adafruit_RGBLCDShield::write(uint8_t value) { +//inline void Adafruit_RGBLCDShield::write(uint8_t value) { +int Adafruit_RGBLCDShield::_putc(int value) { send(value, HIGH); + return 1; } #endif @@ -333,7 +349,8 @@ _i2c.digitalWrite(p, d); } else { // straightup IO - digitalWrite(p, d); + // @@@ TURNED OFF @@@ + //digitalWrite(p, d); } } @@ -352,7 +369,8 @@ _i2c.pinMode(p, d); } else { // straightup IO - pinMode(p, d); + //@@@ TURNED OFF @@@ + //pinMode(p, d); } } @@ -386,7 +404,8 @@ if (_i2cAddr != 255) { uint16_t out = 0; - out = _i2c.readGPIOAB(); + //out = _i2c.readGPIOAB(); + out = _i2c.digitalWordRead(); // speed up for i2c since its sluggish for (int i = 0; i < 4; i++) { @@ -397,15 +416,21 @@ // make sure enable is low out &= ~(1 << _enable_pin); - _i2c.writeGPIOAB(out); + //_i2c.writeGPIOAB(out); + _i2c.digitalWordWrite(out); // pulse enable delayMicroseconds(1); out |= (1 << _enable_pin); - _i2c.writeGPIOAB(out); + //_i2c.writeGPIOAB(out); + _i2c.digitalWordWrite(out); + delayMicroseconds(1); out &= ~(1 << _enable_pin); - _i2c.writeGPIOAB(out); + + //_i2c.writeGPIOAB(out); + _i2c.digitalWordWrite(out); + delayMicroseconds(100); } else {