Skip to content

Commit

Permalink
Merge pull request #377 from mathertel/master
Browse files Browse the repository at this point in the history
Arduino_Wire and Arduino_SH1106 changes
  • Loading branch information
moononournation authored Nov 12, 2023
2 parents dc8ffe3 + 1454233 commit d49ce1a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
13 changes: 12 additions & 1 deletion src/databus/Arduino_Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ Arduino_Wire::
Arduino_Wire(uint8_t i2c_addr, TwoWire *wire)
: _i2c_addr(i2c_addr), _wire(wire) {}

bool Arduino_Wire::begin(int32_t, int8_t)
bool Arduino_Wire::begin(int32_t speed, int8_t)
{

if (speed != GFX_NOT_DEFINED)
{
_speed = speed;
_wire->setClock(_speed);
}

_wire->begin();

// find device
Expand All @@ -28,6 +35,10 @@ bool Arduino_Wire::begin(int32_t, int8_t)
void Arduino_Wire::beginWrite()
{
// Serial.println("Wire::beginWrite()");
if (_speed != GFX_NOT_DEFINED)
{
_wire->setClock(_speed);
}
_wire->beginTransmission(_i2c_addr);
}

Expand Down
1 change: 1 addition & 0 deletions src/databus/Arduino_Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Arduino_Wire : public Arduino_DataBus
TwoWire *_wire;
uint8_t _i2c_addr;

int32_t _speed;
private:
};

Expand Down
48 changes: 23 additions & 25 deletions src/display/Arduino_SH1106.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ Arduino_SH1106::Arduino_SH1106(Arduino_DataBus *bus, int8_t rst, int16_t w, int1

bool Arduino_SH1106::begin(int32_t speed)
{
Serial.println("** begin()");
// Serial.println("SH1106::begin()");

if (!_bus)
{
Serial.println("** bus not given");
Serial.println("SH1106::bus not given");
}
else if (!_bus->begin(speed))
{
Serial.println("bus not started");
Serial.println("SH1106::bus not started");
return false;
}

Serial.println("** Initialize Display");
// Serial.println("SH1106::Initialize Display");

if (_rst != GFX_NOT_DEFINED)
{
Expand Down Expand Up @@ -102,27 +102,25 @@ bool Arduino_SH1106::begin(int32_t speed)

void Arduino_SH1106::drawBitmap(int16_t xStart, int16_t yStart, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg)
{
Serial.printf("drawBitmap %d/%d w:%d h:%d\n", xStart, yStart, w, h);
// Serial.printf("SH1106::drawBitmap %d/%d w:%d h:%d\n", xStart, yStart, w, h);
unsigned long now = millis();
uint16_t bufferLength = TWI_BUFFER_LENGTH;

// transfer the whole bitmap
for (uint8_t p = 0; p < _pages; p++)
{
uint8_t *pptr = bitmap + (p * w); // page start pointer
uint16_t bytesOut = 0;

// start page sequence
uint8_t seq[] = {
BEGIN_WRITE,
WRITE_BYTES, 4,
0x00, // sequence of commands
SH110X_SETPAGEADDR + p, // set page
SH110X_SETLOWCOLUMN + 2, // set column
SH110X_SETHIGHCOLUMN + 0,
END_WRITE};
_bus->batchOperation(seq, sizeof(seq));
_bus->beginWrite();
_bus->write(0x00);
_bus->write(SH110X_SETPAGEADDR + p);
_bus->write(SH110X_SETLOWCOLUMN + 2); // set column
_bus->write(SH110X_SETHIGHCOLUMN + 0);
_bus->endWrite();

// send out page data
uint8_t *pptr = bitmap + (p * w); // page start pointer
uint16_t bytesOut = 0;

for (int x = 0; x < w; x++)
{

Expand All @@ -133,11 +131,10 @@ void Arduino_SH1106::drawBitmap(int16_t xStart, int16_t yStart, uint8_t *bitmap,
bytesOut = 1;
}

_bus->write(*pptr);
pptr++;
_bus->write(*pptr++);
bytesOut++;

if (bytesOut == TWI_BUFFER_LENGTH)
if (bytesOut == bufferLength)
{
_bus->endWrite();
bytesOut = 0;
Expand All @@ -148,26 +145,28 @@ void Arduino_SH1106::drawBitmap(int16_t xStart, int16_t yStart, uint8_t *bitmap,
_bus->endWrite();
}
}

Serial.printf("SH1106::drawBitmap %d ms\n", millis() - now);
} // drawBitmap()

void Arduino_SH1106::drawIndexedBitmap(int16_t, int16_t, uint8_t *, uint16_t *, int16_t, int16_t, int16_t)
{
Serial.println("Not Implemented drawIndexedBitmap()");
Serial.println("SH1106::Not Implemented drawIndexedBitmap()");
}

void Arduino_SH1106::draw3bitRGBBitmap(int16_t, int16_t, uint8_t *bitmap, int16_t w, int16_t h)
{
Serial.println("Not Implemented draw3bitRGBBitmap()");
Serial.println("SH1106::Not Implemented draw3bitRGBBitmap()");
}

void Arduino_SH1106::draw16bitRGBBitmap(int16_t, int16_t, uint16_t *, int16_t, int16_t)
{
Serial.println("Not Implemented draw16bitRGBBitmap()");
Serial.println("SH1106::Not Implemented draw16bitRGBBitmap()");
}

void Arduino_SH1106::draw24bitRGBBitmap(int16_t, int16_t, uint8_t *, int16_t, int16_t)
{
Serial.println("Not Implemented draw24bitRGBBitmap()");
Serial.println("SH1106::Not Implemented draw24bitRGBBitmap()");
}

void Arduino_SH1106::invertDisplay(bool i)
Expand Down Expand Up @@ -196,4 +195,3 @@ void Arduino_SH1106::displayOff(void)
END_WRITE};
_bus->batchOperation(seq, sizeof(seq));
}

1 change: 0 additions & 1 deletion src/display/Arduino_SH1106.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#define _Arduino_SH1106_H_

#include <Arduino.h>
#include <Print.h>
#include <Arduino_GFX.h>

class Arduino_SH1106 : public Arduino_G
Expand Down

0 comments on commit d49ce1a

Please sign in to comment.