Skip to content

Commit

Permalink
Merge pull request #15 from caternuson/iss14_cleanup
Browse files Browse the repository at this point in the history
I2C Cleanup
  • Loading branch information
caternuson authored Nov 28, 2022
2 parents 06a3c73 + 5c3592e commit f710b3c
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 259 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [pull_request, push, repository_dispatch]
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v1
with:
Expand All @@ -20,10 +20,10 @@ jobs:
run: bash ci/actions_install.sh

- name: test platforms
run: python3 ci/build_platform.py main_platforms trinket_3v trinket_5v
run: python3 ci/build_platform.py main_platforms

- name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .

- name: doxygen
env:
Expand Down
37 changes: 19 additions & 18 deletions Adafruit_LiquidCrystal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
* BSD license, all text above must be included in any redistribution
*/
#include "Adafruit_LiquidCrystal.h"
#include "Arduino.h"
#include <inttypes.h>
#include <stdio.h>
#include <string.h>

// FOR Arduino Due
#if !defined(_BV)
Expand Down Expand Up @@ -73,8 +69,9 @@ Adafruit_LiquidCrystal::Adafruit_LiquidCrystal(uint8_t rs, uint8_t enable,
init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0);
}

Adafruit_LiquidCrystal::Adafruit_LiquidCrystal(uint8_t i2caddr) {
_i2cAddr = i2caddr;
Adafruit_LiquidCrystal::Adafruit_LiquidCrystal(uint8_t i2caddr, TwoWire *wire) {
_i2cAddr = i2caddr <= 0x07 ? 0x20 | i2caddr : i2caddr;
_wire = wire;

_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;

Expand Down Expand Up @@ -140,20 +137,22 @@ void Adafruit_LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw,
_displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
}

void Adafruit_LiquidCrystal::begin(uint8_t cols, uint8_t lines,
bool Adafruit_LiquidCrystal::begin(uint8_t cols, uint8_t lines,
uint8_t dotsize) {
(void)cols; // Workaround to avoid compiler warning.
// check if i2c
if (_i2cAddr != 255) {
_i2c.begin(_i2cAddr);
if (!_mcp.begin_I2C(_i2cAddr, _wire))
return false;

_i2c.pinMode(7, OUTPUT); // backlight
_i2c.digitalWrite(7, HIGH); // backlight
_mcp.pinMode(7, OUTPUT); // backlight
_mcp.digitalWrite(7, HIGH); // backlight

for (uint8_t i = 0; i < 4; i++)
_pinMode(_data_pins[i], OUTPUT);

_i2c.pinMode(_rs_pin, OUTPUT);
_i2c.pinMode(_enable_pin, OUTPUT);
_mcp.pinMode(_rs_pin, OUTPUT);
_mcp.pinMode(_enable_pin, OUTPUT);
} else if (_SPIclock != 255) {
pinMode(_SPIdata, OUTPUT);
pinMode(_SPIclock, OUTPUT);
Expand Down Expand Up @@ -241,6 +240,8 @@ void Adafruit_LiquidCrystal::begin(uint8_t cols, uint8_t lines,
_displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
// set the entry mode
command(LCD_ENTRYMODESET | _displaymode);

return true;
}

/********** high level commands, for the user! */
Expand Down Expand Up @@ -354,7 +355,7 @@ inline void Adafruit_LiquidCrystal::write(uint8_t value) { send(value, HIGH); }
void Adafruit_LiquidCrystal::_digitalWrite(uint8_t p, uint8_t d) {
if (_i2cAddr != 255) {
// an i2c command
_i2c.digitalWrite(p, d);
_mcp.digitalWrite(p, d);
} else if (_SPIclock != 255) {
if (d == HIGH)
_SPIbuff |= (1 << p);
Expand Down Expand Up @@ -382,7 +383,7 @@ void Adafruit_LiquidCrystal::setBacklight(uint8_t status) {
void Adafruit_LiquidCrystal::_pinMode(uint8_t p, uint8_t d) {
if (_i2cAddr != 255) {
// an i2c command
_i2c.pinMode(p, d);
_mcp.pinMode(p, d);
} else if (_SPIclock != 255) {
// nothing!
} else {
Expand Down Expand Up @@ -421,7 +422,7 @@ void Adafruit_LiquidCrystal::write4bits(uint8_t value) {
if (_i2cAddr != 255) {
uint8_t out = 0;

out = _i2c.readGPIO();
out = _mcp.readGPIO();

// speed up for i2c since its sluggish
for (int i = 0; i < 4; i++) {
Expand All @@ -432,15 +433,15 @@ void Adafruit_LiquidCrystal::write4bits(uint8_t value) {
// make sure enable is low
out &= ~_BV(_enable_pin);

_i2c.writeGPIO(out);
_mcp.writeGPIO(out);

// pulse enable
delayMicroseconds(1);
out |= _BV(_enable_pin);
_i2c.writeGPIO(out);
_mcp.writeGPIO(out);
delayMicroseconds(1);
out &= ~_BV(_enable_pin);
_i2c.writeGPIO(out);
_mcp.writeGPIO(out);
delayMicroseconds(100);
} else {
for (int i = 0; i < 4; i++) {
Expand Down
14 changes: 8 additions & 6 deletions Adafruit_LiquidCrystal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

#include "Arduino.h"
#include "Print.h"
#include "utility/Adafruit_MCP23008.h"
#include <inttypes.h>
#include <Adafruit_MCP23X08.h>

// commands
#define LCD_CLEARDISPLAY 0x01 //!< Clear display, set cursor position to zero
Expand Down Expand Up @@ -118,9 +117,11 @@ class Adafruit_LiquidCrystal : public Print {

/*!
* @brief LiquidCrystal constructor for connection over i2c
* @param i2cAddr I2C address of the display
* @param i2cAddr Address of the display. Can use either actual I2C address
* (0x20, 0x21, etc.) or offset from 0x20 base address (0, 1, etc.).
* @param wire Optional pointer to Wire instance to use. Defaults to Wire.
*/
Adafruit_LiquidCrystal(uint8_t i2cAddr);
Adafruit_LiquidCrystal(uint8_t i2cAddr, TwoWire *wire = &Wire);
/*!
* @brief LiquidCrystal constructor for connection over SPI
* @param data Data pin
Expand Down Expand Up @@ -156,7 +157,7 @@ class Adafruit_LiquidCrystal : public Print {
* @param charsize Sets the charactersize
* @return Returns true when connection was successful
*/
void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
bool begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);

/*!
* @brief High-level command to clear the display
Expand Down Expand Up @@ -274,7 +275,8 @@ class Adafruit_LiquidCrystal : public Print {
uint8_t _SPIbuff;

uint8_t _i2cAddr;
Adafruit_MCP23008 _i2c;
TwoWire *_wire;
Adafruit_MCP23X08 _mcp;
};

#endif
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
LiquidCrystal Library - Autoscroll
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch demonstrates the use of the autoscroll()
and noAutoscroll() functions to make new text scroll or not.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
Expand All @@ -19,28 +19,28 @@
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
by Tom Igoe
modified 25 July 2009
by David A. Mellis
http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/

// include the library code:
#include "Wire.h"
#include "LiquidCrystal.h"
#include "Adafruit_LiquidCrystal.h"

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Adafruit_LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
// set up the LCD's number of columns and rows:
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
}

Expand All @@ -64,7 +64,7 @@ void loop() {
}
// turn off automatic scrolling
lcd.noAutoscroll();

// clear screen for the next loop:
lcd.clear();
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
Demonstration sketch for Adafruit i2c/SPI LCD backpack
using MCP23008 I2C expander
( http://www.ladyada.net/products/i2cspilcdbackpack/index.html )
( https://learn.adafruit.com/i2c-spi-lcd-backpack )
This sketch prints "Hello World!" to the LCD
and shows the time.
The circuit:
* 5V to Arduino 5V pin
* GND to Arduino GND pin
Expand All @@ -14,15 +14,23 @@
*/

// include the library code:
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"

// Connect via i2c, default address #0 (A0-A2 not jumpered)
Adafruit_LiquidCrystal lcd(0);

void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
Serial.begin(115200);
// while(!Serial);
Serial.println("LCD Character Backpack I2C Test.");

// set up the LCD's number of rows and columns:
if (!lcd.begin(16, 2)) {
Serial.println("Could not init backpack. Check wiring.");
while(1);
}
Serial.println("Backpack init'd.");

// Print a message to the LCD.
lcd.print("hello, world!");
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ paragraph=Fork of LiquidCrystal HD44780-compatible LCD driver library, now with
category=Display
url=https://github.com/adafruit/LiquidCrystal/
architectures=*
depends=Adafruit MCP23017 Arduino Library
Loading

0 comments on commit f710b3c

Please sign in to comment.