This commit is contained in:
lady ada 2020-08-23 13:42:11 -04:00
parent f30658f9e6
commit 1fe2f556e9
2 changed files with 25 additions and 24 deletions

View File

@ -60,10 +60,9 @@
@note Call the object's begin() function before use -- buffer
allocation is performed there!
*/
Adafruit_GrayOLED::Adafruit_GrayOLED(uint8_t bpp,
uint16_t w, uint16_t h, TwoWire *twi,
int8_t rst_pin, uint32_t clkDuring,
uint32_t clkAfter)
Adafruit_GrayOLED::Adafruit_GrayOLED(uint8_t bpp, uint16_t w, uint16_t h,
TwoWire *twi, int8_t rst_pin,
uint32_t clkDuring, uint32_t clkAfter)
: Adafruit_GFX(w, h), i2c_preclk(clkDuring), i2c_postclk(clkAfter),
buffer(NULL), dcPin(-1), csPin(-1), rstPin(rst_pin), _bpp(bpp) {
i2c_dev = NULL;
@ -97,12 +96,12 @@ Adafruit_GrayOLED::Adafruit_GrayOLED(uint8_t bpp,
@note Call the object's begin() function before use -- buffer
allocation is performed there!
*/
Adafruit_GrayOLED::Adafruit_GrayOLED(uint8_t bpp,
uint16_t w, uint16_t h, int8_t mosi_pin,
int8_t sclk_pin, int8_t dc_pin,
int8_t rst_pin, int8_t cs_pin)
: Adafruit_GFX(w, h), dcPin(dc_pin), csPin(cs_pin), rstPin(rst_pin),
_bpp(bpp) {
Adafruit_GrayOLED::Adafruit_GrayOLED(uint8_t bpp, uint16_t w, uint16_t h,
int8_t mosi_pin, int8_t sclk_pin,
int8_t dc_pin, int8_t rst_pin,
int8_t cs_pin)
: Adafruit_GFX(w, h), dcPin(dc_pin), csPin(cs_pin), rstPin(rst_pin),
_bpp(bpp) {
spi_dev = new Adafruit_SPIDevice(cs_pin, sclk_pin, -1, mosi_pin, 1000000);
}
@ -133,12 +132,12 @@ Adafruit_GrayOLED::Adafruit_GrayOLED(uint8_t bpp,
@note Call the object's begin() function before use -- buffer
allocation is performed there!
*/
Adafruit_GrayOLED::Adafruit_GrayOLED(uint8_t bpp,
uint16_t w, uint16_t h, SPIClass *spi,
int8_t dc_pin, int8_t rst_pin,
int8_t cs_pin, uint32_t bitrate)
: Adafruit_GFX(w, h), dcPin(dc_pin), csPin(cs_pin), rstPin(rst_pin),
_bpp(bpp) {
Adafruit_GrayOLED::Adafruit_GrayOLED(uint8_t bpp, uint16_t w, uint16_t h,
SPIClass *spi, int8_t dc_pin,
int8_t rst_pin, int8_t cs_pin,
uint32_t bitrate)
: Adafruit_GFX(w, h), dcPin(dc_pin), csPin(cs_pin), rstPin(rst_pin),
_bpp(bpp) {
spi_dev = new Adafruit_SPIDevice(cs_pin, bitrate, SPI_BITORDER_MSBFIRST,
SPI_MODE0, spi);
@ -224,7 +223,8 @@ bool Adafruit_GrayOLED::oled_commandList(const uint8_t *c, uint8_t n) {
bool Adafruit_GrayOLED::_init(uint8_t addr, bool reset) {
// attempt to malloc the bitmap framebuffer
if ((!buffer) && !(buffer = (uint8_t *)malloc(_bpp * WIDTH * ((HEIGHT + 7) / 8)))) {
if ((!buffer) &&
!(buffer = (uint8_t *)malloc(_bpp * WIDTH * ((HEIGHT + 7) / 8)))) {
return false;
}
@ -319,8 +319,8 @@ void Adafruit_GrayOLED::drawPixel(int16_t x, int16_t y, uint16_t color) {
}
}
if (_bpp == 4) {
uint8_t *pixelptr = &buffer[x/2 + (y * WIDTH / 2)];
//Serial.printf("(%d, %d) -> offset %d\n", x, y, x/2 + (y * WIDTH / 2));
uint8_t *pixelptr = &buffer[x / 2 + (y * WIDTH / 2)];
// Serial.printf("(%d, %d) -> offset %d\n", x, y, x/2 + (y * WIDTH / 2));
if (x % 2 == 0) { // even, left nibble
uint8_t t = pixelptr[0] & 0x0F;
t |= (color & 0xF) << 4;

View File

@ -49,10 +49,11 @@ public:
Adafruit_GrayOLED(uint8_t bpp, uint16_t w, uint16_t h, TwoWire *twi = &Wire,
int8_t rst_pin = -1, uint32_t preclk = 400000,
uint32_t postclk = 100000);
Adafruit_GrayOLED(uint8_t bpp, uint16_t w, uint16_t h, int8_t mosi_pin, int8_t sclk_pin,
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
Adafruit_GrayOLED(uint8_t bpp, uint16_t w, uint16_t h, SPIClass *spi, int8_t dc_pin,
int8_t rst_pin, int8_t cs_pin,
Adafruit_GrayOLED(uint8_t bpp, uint16_t w, uint16_t h, int8_t mosi_pin,
int8_t sclk_pin, int8_t dc_pin, int8_t rst_pin,
int8_t cs_pin);
Adafruit_GrayOLED(uint8_t bpp, uint16_t w, uint16_t h, SPIClass *spi,
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin,
uint32_t bitrate = 8000000UL);
~Adafruit_GrayOLED(void);
@ -90,7 +91,7 @@ protected:
csPin, ///< The Arduino pin connected to CS (for SPI)
rstPin; ///< The Arduino pin connected to reset (-1 if unused)
uint8_t _bpp = 1; ///< Bits per pixel color for this display
uint8_t _bpp = 1; ///< Bits per pixel color for this display
private:
TwoWire *_theWire = NULL; ///< The underlying hardware I2C
};