Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
697 changes: 697 additions & 0 deletions yoRadio/src/ST7567/ST7567.cpp

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions yoRadio/src/ST7567/ST7567.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/**********************************************************************************
* This is a library for ST7567 Monochrome LCD Display.
* These displays use I2C or SPI to communicate
*
* This is a free library WITH NO WARRANTY, use it at your own risk!
***********************************************************************************
* This library depends on Adafruit GFX library at
* https://github.com/adafruit/Adafruit-GFX-Library
* being present on your system. Please make sure you have installed the latest
* version before using this library.
***********************************************************************************/

#if defined(ARDUINO_STM32_FEATHER)
typedef class HardwareSPI SPIClass;
#endif

#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>

#if defined(__AVR__)
typedef volatile uint8_t PortReg;
typedef uint8_t PortMask;
#define HAVE_PORTREG
#elif defined(__SAM3X8E__)
typedef volatile RwReg PortReg;
typedef uint32_t PortMask;
#define HAVE_PORTREG
#elif (defined(__arm__) || defined(ARDUINO_FEATHER52)) && \
!defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_RP2040)
typedef volatile uint32_t PortReg;
typedef uint32_t PortMask;
#define HAVE_PORTREG
#endif

#define LCDWIDTH 128
#define LCDHEIGHT 64

#define BLACK 1
#define WHITE 0
#define INVERSE 2

#define ST7567_I2C_ADDRESS 0x3F

#define CMD_DISPLAY_OFF 0xAE
#define CMD_DISPLAY_ON 0xAF

#define CMD_SET_DISP_START_LINE 0x40
#define CMD_SET_PAGE 0xB0

#define CMD_SET_COLUMN_UPPER 0x10
#define CMD_SET_COLUMN_LOWER 0x00

#define CMD_SEG_DIRECTION_NORMAL 0xA0
#define CMD_SEG_DIRECTION_REVERSE 0xA1

#define CMD_SET_DISP_NORMAL 0xA6
#define CMD_SET_DISP_REVERSE 0xA7

#define CMD_SET_ALLPTS_NORMAL 0xA4
#define CMD_SET_ALLPTS_ON 0xA5
#define CMD_SET_BIAS_9 0xA2
#define CMD_SET_BIAS_7 0xA3

#define CMD_RMW 0xE0 // Read-modify-Write (column address increment: Read:+0, Write:+1)
#define CMD_RMW_CLEAR 0xEE // END Read-modify-Write
#define CMD_INTERNAL_RESET 0xE2
#define CMD_SET_COM_NORMAL 0xC0
#define CMD_SET_COM_REVERSE 0xC8
#define CMD_SET_POWER_CONTROL 0x28
#define CMD_SET_RESISTOR_RATIO 0x20 // regulation ratio RR[2:0]
#define CMD_SET_VOLUME_FIRST 0x81
#define CMD_SET_VOLUME_SECOND 0 // EV[5:0]
#define CMD_NOP 0xE3

/*! The controller object for ST7567 displays */
class ST7567 : public Adafruit_GFX {
public:
ST7567(uint8_t w, uint8_t h, TwoWire *twi = &Wire,
int8_t rst_pin = -1, uint32_t clkDuring = 400000UL,
uint32_t clkAfter = 100000UL);
ST7567(uint8_t w, uint8_t h, int8_t mosi_pin, int8_t sclk_pin,
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
ST7567(uint8_t w, uint8_t h, SPIClass *spi_ptr, int8_t dc_pin,
int8_t rst_pin, int8_t cs_pin, uint32_t bitrate = 4000000UL);
~ST7567(void);

bool begin(uint8_t i2caddr = ST7567_I2C_ADDRESS, bool reset = true, bool periphBegin = true);
void display(void);
void clearDisplay(void);
void invertDisplay(bool i);
void drawPixel(int16_t x, int16_t y, uint16_t color);
void st7567_command(uint8_t c);
bool getPixel(int16_t x, int16_t y);
uint8_t *getBuffer(void);

void setContrast(uint8_t val);
uint8_t getContrast(void);

void sleep(void);
void wake(void);

protected:
inline void SPIwrite(uint8_t d) __attribute__((always_inline));
void st7567_command1(uint8_t c);
void st7567_commandList(const uint8_t *c, uint8_t n);

void updateBoundingBox(uint8_t xmin, uint8_t ymin, uint8_t xmax,
uint8_t ymax);
uint8_t xUpdateMin, xUpdateMax, yUpdateMin, yUpdateMax;

SPIClass *spi; ///< Initialized during construction when using SPI. See
///< SPI.cpp, SPI.h
TwoWire *wire; ///< Initialized during construction when using I2C. See
///< Wire.cpp, Wire.h
uint8_t *buffer; ///< Buffer data used for display buffer. Allocated when
///< begin method is called.

int8_t i2caddr; ///< I2C address initialized when begin method is called.
int8_t mosiPin; ///< (Master Out Slave In) set when using SPI set during
///< construction.
int8_t clkPin; ///< (Clock Pin) set when using SPI set during construction.
int8_t dcPin; ///< (Data Pin) set when using SPI set during construction.
int8_t
csPin; ///< (Chip Select Pin) set when using SPI set during construction.
int8_t rstPin; ///< Display reset pin assignment. Set during construction.

#ifdef HAVE_PORTREG
PortReg *mosiPort, *clkPort, *dcPort, *csPort;
PortMask mosiPinMask, clkPinMask, dcPinMask, csPinMask;
#endif
#if ARDUINO >= 157
uint32_t wireClk; ///< Wire speed for ST7567 transfers
uint32_t restoreClk; ///< Wire speed following ST7567 transfers
#endif
uint8_t _contrast = 0x30; ///< contrast setting (0x00~0x3F)
#if defined(SPI_HAS_TRANSACTION)
protected:
// Allow sub-class to change
SPISettings spiSettings;
#endif
};
2 changes: 1 addition & 1 deletion yoRadio/src/core/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ void Display::flip(){ dsp.flip(); }
void Display::invert(){ dsp.invert(); }

void Display::setContrast(){
#if DSP_MODEL==DSP_NOKIA5110
#if DSP_MODEL==DSP_NOKIA5110 || DSP_MODEL==DSP_ST7567
dsp.setContrast(config.store.contrast);
#endif
}
Expand Down
3 changes: 2 additions & 1 deletion yoRadio/src/core/netserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ void NetServer::processQueue(){
if (BRIGHTNESS_PIN != 255 || nxtn || dbgact) APPEND_GROUP("group_brightness");
if (DSP_CAN_FLIPPED || dbgact) APPEND_GROUP("group_tft");
if (TS_MODEL != TS_MODEL_UNDEFINED || dbgact) APPEND_GROUP("group_touch");
if (DSP_MODEL == DSP_NOKIA5110) APPEND_GROUP("group_nokia");
if (DSP_MODEL == DSP_NOKIA5110 ||
DSP_MODEL==DSP_ST7567) APPEND_GROUP("group_nokia");
APPEND_GROUP("group_timezone");
if (SHOW_WEATHER || dbgact) APPEND_GROUP("group_weather");
APPEND_GROUP("group_controls");
Expand Down
1 change: 1 addition & 0 deletions yoRadio/src/core/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
#define DSP_2002 26 // 20x2 https://aliexpress.com/item/32812259852.html
#define DSP_2002I2C 27 // 20x2 https://aliexpress.com/item/32812259852.html
#define DSP_ST7789_170 28 // 320x170 1.9' https://aliexpress.com/item/1005008723378017.html
#define DSP_ST7567 29 // 128x64 1.8' https://www.aliexpress.com/item/1005005476901548.html
#define DSP_CUSTOM 101 // your display

#ifndef DSP_MODEL
Expand Down
69 changes: 69 additions & 0 deletions yoRadio/src/displays/conf/displayST7567conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*************************************************************************************
ST7567 128x64 displays configuration file.
Copy this file to yoRadio/src/displays/conf/displayST7567conf_custom.h
and modify it
More info on https://github.com/e2002/yoradio/wiki/Widgets#widgets-description
*************************************************************************************/

#ifndef displayST7567conf_h
#define displayST7567conf_h

#define DSP_WIDTH 128
#define TFT_FRAMEWDT 1
#define MAX_WIDTH DSP_WIDTH-TFT_FRAMEWDT*2

#define HIDE_HEAPBAR
#define HIDE_VOL
#define HIDE_VU

#define bootLogoTop 8

/* SROLLS */ /* {{ left, top, fontsize, align }, buffsize, uppercase, width, scrolldelay, scrolldelta, scrolltime } */
const ScrollConfig metaConf PROGMEM = {{ TFT_FRAMEWDT+1, TFT_FRAMEWDT+1, 1, WA_LEFT }, 140, true, MAX_WIDTH, 5000, 6, 1000 };
const ScrollConfig title1Conf PROGMEM = {{ 0, 13, 1, WA_LEFT }, 140, true, DSP_WIDTH-6*4, 5000, 6, 800 };
const ScrollConfig title2Conf PROGMEM = {{ 0, 22, 1, WA_LEFT }, 140, true, DSP_WIDTH, 5000, 6, 800 };
const ScrollConfig playlistConf PROGMEM = {{ TFT_FRAMEWDT, 30, 1, WA_LEFT }, 140, true, MAX_WIDTH, 500, 6, 800 };
const ScrollConfig apTitleConf PROGMEM = {{ TFT_FRAMEWDT+1, TFT_FRAMEWDT+1, 1, WA_CENTER }, 140, false, MAX_WIDTH-2, 0, 6, 800 };
const ScrollConfig apSettConf PROGMEM = {{ TFT_FRAMEWDT, 64-7, 1, WA_LEFT }, 140, false, MAX_WIDTH, 0, 6, 800 };
const ScrollConfig weatherConf PROGMEM = {{ 0, 64-11, 1, WA_LEFT }, 140, true, DSP_WIDTH-6*4, 0, 6, 800 }; // ПОГОДА!!

/* BACKGROUNGC9106DS */ /* {{ left, top, fontsize, align }, width, height, outlined } */
const FillConfig metaBGConf PROGMEM = {{ 0, 0, 0, WA_LEFT }, DSP_WIDTH, 11, false };
const FillConfig metaBGConfInv PROGMEM = {{ 0, 11, 0, WA_LEFT }, DSP_WIDTH, 1, false };
const FillConfig volbarConf PROGMEM = {{ 0, 64-1-1-1, 0, WA_LEFT }, DSP_WIDTH, 3, true };
const FillConfig playlBGConf PROGMEM = {{ 0, 26, 0, WA_LEFT }, DSP_WIDTH, 12, false };
const FillConfig heapbarConf PROGMEM = {{ 0, 63, 0, WA_LEFT }, DSP_WIDTH, 1, false };

/* WIDGETS */ /* { left, top, fontsize, align } */
const WidgetConfig bootstrConf PROGMEM = { 0, 64-8, 1, WA_CENTER };
const WidgetConfig bitrateConf PROGMEM = { 0, 13, 1, WA_RIGHT };
//const WidgetConfig voltxtConf PROGMEM = { 32, 108, 1, WA_RIGHT };
const WidgetConfig iptxtConf PROGMEM = { 0, 64-11, 1, WA_LEFT };
const WidgetConfig rssiConf PROGMEM = { 0, 64-11, 1, WA_RIGHT };
const WidgetConfig numConf PROGMEM = { 0, 26, 0, WA_CENTER };
const WidgetConfig apNameConf PROGMEM = { 0, 18, 1, WA_CENTER };
const WidgetConfig apName2Conf PROGMEM = { 0, 26, 1, WA_CENTER };
const WidgetConfig apPassConf PROGMEM = { 0, 37, 1, WA_CENTER };
const WidgetConfig apPass2Conf PROGMEM = { 0, 45, 1, WA_CENTER };
const WidgetConfig clockConf PROGMEM = { 6, 34, 0, WA_CENTER };
const WidgetConfig vuConf PROGMEM = { 1, 28, 1, WA_LEFT };

const WidgetConfig bootWdtConf PROGMEM = { 0, 64-8*2-5, 1, WA_CENTER };
const ProgressConfig bootPrgConf PROGMEM = { 90, 10, 4 };

/* BANDS */ /* { onebandwidth, onebandheight, bandsHspace, bandsVspace, numofbands, fadespeed } */
const VUBandsConfig bandsConf PROGMEM = { 12, 48, 2, 1, 8, 3 };

/* STRINGS */
const char numtxtFmt[] PROGMEM = "%d";
const char rssiFmt[] PROGMEM = "%d";
const char iptxtFmt[] PROGMEM = "%s";
//const char voltxtFmt[] PROGMEM = "%d";
const char bitrateFmt[] PROGMEM = "%d";

/* MOVES */ /* { left, top, width } */
const MoveConfig clockMove PROGMEM = { 0, 0, -1 };
const MoveConfig weatherMove PROGMEM = { 0, 0, -1 };
const MoveConfig weatherMoveVU PROGMEM = { 0, 0, -1 };

#endif
47 changes: 47 additions & 0 deletions yoRadio/src/displays/displayST7567.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "../core/options.h"
#if DSP_MODEL==DSP_ST7567
#include "dspcore.h"
#include <Wire.h>
#include "../core/config.h"

#define LOGO_WIDTH 21
#define LOGO_HEIGHT 32


#if DSP_HSPI
DspCore::DspCore(): ST7567(128, 64, &SPI2, TFT_DC, TFT_RST, TFT_CS) {}
#else
DspCore::DspCore(): ST7567(128, 64, &SPI, TFT_DC, TFT_RST, TFT_CS) {}
#endif

void DspCore::initDisplay() {
#include "tools/oledcolorfix.h"
begin();
setContrast(config.store.contrast);
cp437(true);
flip();
invert();
setTextWrap(false);
}

void DspCore::clearDsp(bool black) {
fillScreen(TFT_BG);
}

void DspCore::flip(){
setRotation(config.store.flipscreen?2:0);
}

void DspCore::invert(){
invertDisplay(config.store.invertdisplay);
}

void DspCore::sleep(void) {
ST7567::sleep();
}

void DspCore::wake(void) {
ST7567::wake();
}

#endif
31 changes: 31 additions & 0 deletions yoRadio/src/displays/displayST7567.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef displayST7567_h
#define displayST7567_h

#include "Arduino.h"
#include <Adafruit_GFX.h>
#include "../ST7567/ST7567.h"
#include "fonts/bootlogo21x32.h"

typedef GFXcanvas1 Canvas;
typedef ST7567 yoDisplay;

#include "tools/commongfx.h"

#if __has_include("conf/displayST7567conf_custom.h")
#include "conf/displayST7567conf_custom.h"
#else
#include "conf/displayST7567conf.h"
#endif

/*
* OLED COLORS
*/
#define BOOT_PRG_COLOR BLACK
#define BOOT_TXT_COLOR BLACK
#define PINK BLACK
#define SILVER BLACK
#define TFT_BG WHITE
#define TFT_FG BLACK
#define TFT_LOGO BLACK

#endif
5 changes: 5 additions & 0 deletions yoRadio/src/displays/dspcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@
#define DSP_OLED
#include "displayST7920.h"

#elif DSP_MODEL==DSP_ST7567
#define TIME_SIZE 2
#define DSP_OLED
#include "displayST7567.h"

#endif

//extern DspCore dsp;
Expand Down