Skip to content

Commit

Permalink
Add driver for wave share 4.2in display, added file based fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
squix78 committed Nov 1, 2017
1 parent 4ebc101 commit e6ab7a4
Show file tree
Hide file tree
Showing 11 changed files with 939 additions and 186 deletions.
91 changes: 91 additions & 0 deletions examples/EPaper/EPD_WaveShare_42/EPD_WaveShare_42.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
The MIT License (MIT)
Copyright (c) 2017 by Daniel Eichhorn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Please note: I am spending a lot of my free time in developing Software and Hardware
for these projects. Please consider supporting me by
a) Buying my hardware kits from https://blog.squix.org/shop
b) Send a donation: https://www.paypal.me/squix/5USD
c) Or using this affiliate link while shopping: https://www.banggood.com/?p=6R31122484684201508S
See more at https://blog.squix.org
Demo for the buffered graphics library. Renders a 3D cube
*/

#include <SPI.h>
#include "EPD_WaveShare_42.h"
#include "MiniGrafx.h"
#include "DisplayDriver.h"

/*
Connect the following pins:
Display NodeMCU
BUSY D1
RST D2
DC D8
CS D3
CLK D5
DIN D7
GND GND
3.3V 3V3
*/
/*#define CS D3
#define RST D2
#define DC D8
#define BUSY D1*/

#define CS 15 // D8
#define RST 2 // D4
#define DC 5 // D1
#define BUSY 4 // D2

#define SCREEN_WIDTH 400
#define SCREEN_HEIGHT 300
#define BITS_PER_PIXEL 1


uint16_t palette[] = {0, 1};

EPD_WaveShare42 epd(CS, RST, DC, BUSY);
MiniGrafx gfx = MiniGrafx(&epd, BITS_PER_PIXEL, palette);

void setup() {
Serial.begin(115200);
gfx.init();

}

uint8_t rotation = 0;

void loop() {


gfx.fillBuffer(1);
gfx.setColor(0);
gfx.setFont(ArialMT_Plain_10);
gfx.drawLine(0, 0, gfx.getWidth(), gfx.getHeight());
gfx.drawString(10, 10, "Hello World");
gfx.setFont(ArialMT_Plain_16);
gfx.drawString(10, 30, "Everything works!");
gfx.setFont(ArialMT_Plain_24);
gfx.drawString(10, 55, "Yes! Millis: " + String(millis()));
gfx.commit();
delay(15000);

}
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Mini Grafx",
"version": "0.0.13",
"version": "0.0.14",
"keywords": "embedded, graphics, tft, oled, e-paper",
"description": "A generic graphics library containing several drivers for TFT, OLED and e-paper displays",
"repository":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Mini Grafx
version=0.0.13
version=0.0.14
author=Daniel Eichhorn
maintainer=Daniel Eichhorn <[email protected]>
sentence=Graphics Library for embedded devices with a framebuffer
Expand Down
20 changes: 10 additions & 10 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html

;[env:d1_mini]
;platform = espressif8266
;board = d1_mini
;framework = arduino
;upload_speed = 921600
[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
upload_speed = 921600
;board_f_cpu = 160000000L
;upload_resetmethod = ck
;lib_deps = XPT2046_Touchscreen

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
upload_speed = 921600
;[env:esp32doit-devkit-v1]
;platform = espressif32
;board = esp32doit-devkit-v1
;framework = arduino
;upload_speed = 921600
104 changes: 29 additions & 75 deletions src/DisplayDriver.cpp
Original file line number Diff line number Diff line change
@@ -1,85 +1,42 @@
/*
This is the core graphics library for all our displays, providing a common
set of graphics primitives (points, lines, circles, etc.). It needs to be
paired with a hardware-specific library for each display device we carry
(to handle the lower-level functions).
Adafruit invests time and resources providing this open source code, please
support Adafruit & open-source hardware by purchasing products from Adafruit!
Copyright (c) 2013 Adafruit Industries. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/**
The MIT License (MIT)
Copyright (c) 2017 by Daniel Eichhorn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Please note: I am spending a lot of my free time in developing Software and Hardware
for these projects. Please consider supporting me by
a) Buying my hardware kits from https://blog.squix.org/shop
b) Send a donation: https://www.paypal.me/squix/5USD
c) Or using this affiliate link while shopping: https://www.banggood.com/?p=6R31122484684201508S
See more at https://blog.squix.org
Many thanks go to various contributors such as Adafruit, Waveshare.
*/

#include "DisplayDriver.h"
#ifdef __AVR__
#include <avr/pgmspace.h>
#elif defined(ESP8266) || defined(ESP32)
#include <pgmspace.h>
#endif

// Many (but maybe not all) non-AVR board installs define macros
// for compatibility with existing PROGMEM-reading AVR code.
// Do our own checks and defines here for good measure...

#ifndef pgm_read_byte
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#endif
#ifndef pgm_read_word
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
#endif
#ifndef pgm_read_dword
#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
#endif

// Pointers are a peculiar case...typically 16-bit on AVR boards,
// 32 bits elsewhere. Try to accommodate both...

#if !defined(__INT_MAX__) || (__INT_MAX__ > 0xFFFF)
#define pgm_read_pointer(addr) ((void *)pgm_read_dword(addr))
#else
#define pgm_read_pointer(addr) ((void *)pgm_read_word(addr))
#endif

#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif

#ifndef _swap_int16_t
#define _swap_int16_t(a, b) { int16_t t = a; a = b; b = t; }
#endif

DisplayDriver::DisplayDriver(int16_t w, int16_t h):
WIDTH(w), HEIGHT(h)
{
_width = WIDTH;
_height = HEIGHT;
rotation = 0;
cursor_y = cursor_x = 0;
textsize = 1;
textcolor = textbgcolor = 0xFFFF;
wrap = true;
_cp437 = false;

}

Expand Down Expand Up @@ -113,6 +70,3 @@ int16_t DisplayDriver::width(void) const {
int16_t DisplayDriver::height(void) const {
return _height;
}

/***************************************************************************/
// code for the GFX button UI element
45 changes: 32 additions & 13 deletions src/DisplayDriver.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
/**
The MIT License (MIT)
Copyright (c) 2017 by Daniel Eichhorn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Please note: I am spending a lot of my free time in developing Software and Hardware
for these projects. Please consider supporting me by
a) Buying my hardware kits from https://blog.squix.org/shop
b) Send a donation: https://www.paypal.me/squix/5USD
c) Or using this affiliate link while shopping: https://www.banggood.com/?p=6R31122484684201508S
See more at https://blog.squix.org
Demo for the buffered graphics library. Renders a 3D cube
*/

#ifndef _MINIGRAFX_DRIVER_H
#define _MINIGRAFX_DRIVER_H

Expand All @@ -17,8 +47,6 @@ class DisplayDriver {

virtual void setRotation(uint8_t r);
virtual void init() = 0;
//virtual uint16_t getScreenWidth() = 0;
//virtual uint16_t getScreenHeight() = 0;
virtual void writeBuffer(uint8_t *buffer, uint8_t bitsPerPixel, uint16_t *palette) = 0;

int16_t height(void) const;
Expand All @@ -30,17 +58,8 @@ class DisplayDriver {
protected:
const int16_t
WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes
int16_t
_width, _height, // Display w/h as modified by current rotation
cursor_x, cursor_y;
uint16_t
textcolor, textbgcolor;
uint8_t
textsize,
rotation;
boolean
wrap, // If set, 'wrap' text at right edge of display
_cp437; // If set, use correct CP437 charset (default is off)
int16_t _width, _height;
uint8_t rotation;

};

Expand Down
Loading

0 comments on commit e6ab7a4

Please sign in to comment.