Merge pull request #58 from zarya/SSD1306

Ssd1306 support
This commit is contained in:
Jonathan Naylor
2016-05-10 17:27:22 +01:00
10 changed files with 478 additions and 2 deletions

2
.gitignore vendored
View File

@@ -1,6 +1,8 @@
Debug
Release
x64
MMDVMHost
*.o
*.opendb
*.bak
*.obj

View File

@@ -42,7 +42,8 @@ enum SECTION {
SECTION_FUSION_NETWORK,
SECTION_TFTSERIAL,
SECTION_HD44780,
SECTION_NEXTION
SECTION_NEXTION,
SECTION_OLED
};
CConf::CConf(const std::string& file) :
@@ -121,7 +122,10 @@ m_hd44780PWMBright(),
m_hd44780PWMDim(),
m_nextionSize("2.4"),
m_nextionPort("/dev/ttyAMA0"),
m_nextionBrightness(50U)
m_nextionBrightness(50U),
m_oledType(3),
m_oledBrightness(0),
m_oledInvert(0)
{
}
@@ -173,6 +177,8 @@ bool CConf::read()
section = SECTION_HD44780;
else if (::strncmp(buffer, "[Nextion]", 9U) == 0)
section = SECTION_NEXTION;
else if (::strncmp(buffer, "[OLED]", 6U) == 0)
section = SECTION_OLED;
else
section = SECTION_NONE;
@@ -383,7 +389,15 @@ bool CConf::read()
m_nextionPort = value;
else if (::strcmp(key, "Brightness") == 0)
m_nextionBrightness = (unsigned int)::atoi(value);
} else if (section == SECTION_OLED) {
if (::strcmp(key, "Type") == 0)
m_oledType = (unsigned char)::atoi(value);
else if (::strcmp(key, "Port") == 0)
m_oledBrightness = (unsigned char)::atoi(value);
else if (::strcmp(key, "Brightness") == 0)
m_oledInvert = (unsigned char)::atoi(value);
}
}
::fclose(fp);
@@ -765,3 +779,18 @@ unsigned int CConf::getNextionBrightness() const
{
return m_nextionBrightness;
}
unsigned char CConf::getOLEDType() const
{
return m_oledType;
}
unsigned char CConf::getOLEDBrightness() const
{
return m_oledBrightness;
}
unsigned char CConf::getOLEDInvert() const
{
return m_oledInvert;
}

9
Conf.h
View File

@@ -133,6 +133,11 @@ public:
std::string getNextionPort() const;
unsigned int getNextionBrightness() const;
// The OLED section
unsigned char getOLEDType() const;
unsigned char getOLEDBrightness() const;
unsigned char getOLEDInvert() const;
private:
std::string m_file;
std::string m_callsign;
@@ -223,6 +228,10 @@ private:
std::string m_nextionSize;
std::string m_nextionPort;
unsigned int m_nextionBrightness;
unsigned char m_oledType;
unsigned char m_oledBrightness;
unsigned char m_oledInvert;
};
#endif

View File

@@ -106,3 +106,9 @@ PWMDim=16
Size=2.4
Port=/dev/ttyAMA0
Brightness=50
[OLED]
Type=3
Brightness=0
Invert=0

View File

@@ -32,6 +32,10 @@
#include "HD44780.h"
#endif
#if defined(OLED)
#include "OLED.h"
#endif
#include <cstdio>
#include <vector>
@@ -763,6 +767,13 @@ void CMMDVMHost::createDisplay()
m_display = new CHD44780(rows, columns, m_callsign, dmrid, pins, pwm, pwmPin, pwmBright, pwmDim, m_duplex);
}
#endif
#if defined(OLED)
} else if (type == "OLED") {
unsigned char displayType = m_conf.getOLEDType();
unsigned char displayBrightness = m_conf.getOLEDBrightness();
unsigned char displayInvert = m_conf.getOLEDInvert();
m_display = new COLED(displayType, displayBrightness, displayInvert);
#endif
} else {
m_display = new CNullDisplay;

25
Makefile.Pi.OLED Normal file
View File

@@ -0,0 +1,25 @@
# This makefile is for use with the Raspberry Pi when using an HD44780 compatible display. The wiringpi library is needed.
CC = gcc
CXX = g++
CFLAGS = -g -O3 -Wall -std=c++0x -DOLED -I/usr/local/include
LIBS = -lArduiPi_OLED
LDFLAGS = -g -L/usr/local/lib
OBJECTS = \
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
DMRShortLC.o DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o OLED.o Log.o MMDVMHost.o \
Modem.o Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Timer.o UDPSocket.o Utils.o YSFControl.o \
YSFConvolution.o YSFFICH.o YSFParrot.o YSFPayload.o
all: MMDVMHost
MMDVMHost: $(OBJECTS)
$(CXX) $(OBJECTS) $(CFLAGS) $(LIBS) -o MMDVMHost
%.o: %.cpp
$(CXX) $(CFLAGS) -c -o $@ $<
clean:
$(RM) MMDVMHost *.o *.d *.bak *~

232
OLED.cpp Normal file
View File

@@ -0,0 +1,232 @@
/*
* Copyright (C) 2016 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "OLED.h"
COLED::COLED(unsigned char displayType, unsigned char displayBrightness, unsigned char displayInvert) :
m_displayType(displayType),
m_displayBrightness(displayBrightness),
m_displayInvert(displayInvert)
{
}
COLED::~COLED()
{
}
bool COLED::open()
{
// SPI
if (display.oled_is_spi_proto(m_displayType))
{
// SPI change parameters to fit to your LCD
if ( !display.init(OLED_SPI_DC,OLED_SPI_RESET,OLED_SPI_CS, m_displayType) )
return false;
}
else
{
// I2C change parameters to fit to your LCD
if ( !display.init(OLED_I2C_RESET, m_displayType) )
return false;
}
display.begin();
display.invertDisplay(m_displayInvert);
if (m_displayBrightness > 0)
display.setBrightness(m_displayBrightness);
// init done
display.clearDisplay(); // clears the screen buffer
display.display(); // display it (clear display)
OLED_statusbar();
display.setCursor(0,OLED_LINE1);
display.print("Startup");
display.display();
return true;
}
void COLED::setIdleInt()
{
m_mode = MODE_IDLE;
display.clearDisplay();
OLED_statusbar();
display.setCursor(0,display.height()/2);
display.setTextSize(3);
display.print("Idle");
display.setTextSize(1);
display.display();
display.startscrollright(0x02,0x0f);
}
void COLED::setErrorInt(const char* text)
{
m_mode = MODE_ERROR;
display.clearDisplay();
OLED_statusbar();
display.setCursor(0,OLED_LINE1);
display.printf("%s\n", text);
display.display();
}
void COLED::setLockoutInt()
{
m_mode = MODE_LOCKOUT;
display.clearDisplay();
OLED_statusbar();
display.setCursor(0,OLED_LINE1);
display.print("Lockout");
display.display();
}
void COLED::writeDStarInt(const char* my1, const char* my2, const char* your, const char* type, const char* reflector)
{
m_mode = MODE_DSTAR;
display.fillRect(0, OLED_LINE1, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE1);
display.printf("%s %.8s/%4.4s", type, my1, my2);
display.fillRect(0, OLED_LINE2, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE2);
display.printf("via %.8s", reflector);
display.fillRect(0, OLED_LINE3, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE3);
display.printf("%.8s <- %-8s", your, reflector);
OLED_statusbar();
display.display();
}
void COLED::clearDStarInt()
{
display.fillRect(0, OLED_LINE1, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE1);
display.print("Listening");
display.fillRect(0, OLED_LINE2, display.width(), 10, BLACK);
display.fillRect(0, OLED_LINE3, display.width(), 10, BLACK);
OLED_statusbar();
display.display();
}
void COLED::writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type)
{
if (m_mode != MODE_DMR) {
display.clearDisplay();
m_mode = MODE_DMR;
if (slotNo == 1U)
{
display.fillRect(0, OLED_LINE3, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE3);
display.print("2 Listening");
display.fillRect(0, OLED_LINE4, display.width(), 10, BLACK);
}
else
{
display.fillRect(0, OLED_LINE1, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE1);
display.print("1 Listening");
display.fillRect(0, OLED_LINE2, display.width(), 10, BLACK);
}
}
if (slotNo == 1U) {
display.fillRect(0, OLED_LINE1, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE1);
display.printf("%i %s %s", slotNo, type, src.c_str());
display.fillRect(0, OLED_LINE2, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE2);
display.printf("%s%s", group ? "TG" : "", dst.c_str());
} else {
display.fillRect(0, OLED_LINE3, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE3);
display.printf("%i %s %s", slotNo, type, src.c_str());
display.fillRect(0, OLED_LINE4, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE4);
display.printf("%s%s", group ? "TG" : "", dst.c_str());
}
OLED_statusbar();
display.display();
}
void COLED::clearDMRInt(unsigned int slotNo)
{
OLED_statusbar();
if (slotNo == 1U)
{
display.fillRect(0, OLED_LINE1, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE1);
display.print("1 Listening");
display.fillRect(0, OLED_LINE2, display.width(), 10, BLACK);
}
else
{
display.fillRect(0, OLED_LINE3, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE3);
display.print("2 Listening");
display.fillRect(0, OLED_LINE4, display.width(), 10, BLACK);
}
display.display();
}
void COLED::writeFusionInt(const char* source, const char* dest)
{
m_mode = MODE_YSF;
display.fillRect(0, OLED_LINE1, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE1);
display.printf("%.10s", source);
display.fillRect(0, OLED_LINE2, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE2);
display.printf("%.10s", dest);
OLED_statusbar();
display.display();
}
void COLED::clearFusionInt()
{
display.fillRect(0, OLED_LINE1, display.width(), 10, BLACK);
display.setCursor(0,OLED_LINE1);
display.print("Listening");
display.fillRect(0, OLED_LINE2, display.width(), 10, BLACK);
OLED_statusbar();
display.display();
}
void COLED::close()
{
display.close();
}
void COLED::OLED_statusbar()
{
display.stopscroll();
display.fillRect(0, 0, display.width(), 16, BLACK);
display.setTextColor(WHITE);
display.setCursor(0,0);
if (m_mode == MODE_DMR)
display.drawBitmap(0, 0, logo_dmr_bmp, 48, 16, WHITE);
else if (m_mode == MODE_DSTAR)
display.print("D-Star");
else if (m_mode == MODE_YSF)
display.print("Fusion");
else
display.drawBitmap(0, 0, logo_glcd_bmp, 16, 15, WHITE);
}

112
OLED.h Normal file
View File

@@ -0,0 +1,112 @@
/*
* Copyright (C) 2016 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if !defined(OLED_H)
#define OLED_H
#define OLED_STATUSBAR 0
#define OLED_LINE1 16
#define OLED_LINE2 26
#define OLED_LINE3 36
#define OLED_LINE4 46
#include "Display.h"
#include "Defines.h"
#include <string>
#include "ArduiPi_OLED_lib.h"
#include "Adafruit_GFX.h"
#include "ArduiPi_OLED.h"
static unsigned char logo_glcd_bmp[] =
{ 0b00101011, 0b11010100,
0b01010111, 0b11101010,
0b01010111, 0b11101010,
0b00101011, 0b11010100,
0b00000001, 0b10000000,
0b00000001, 0b10000000,
0b00000001, 0b10000000,
0b00000001, 0b10000000,
0b00000001, 0b10000000,
0b00000001, 0b10000000,
0b00000001, 0b10000000,
0b00000001, 0b10000000,
0b00000001, 0b10000000,
0b00000001, 0b10000000,
0b00000001, 0b10000000,
0b00000000, 0b00000000 };
//DMR 48x16 px
static unsigned char logo_dmr_bmp[] =
{ 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001,
0b10111111, 0b11111000, 0b01111000, 0b00011110, 0b01111111, 0b11100001,
0b10111111, 0b11111110, 0b01111100, 0b00111110, 0b01100000, 0b00011001,
0b10110000, 0b00001110, 0b01100110, 0b01100110, 0b01100000, 0b00011001,
0b10110000, 0b00000110, 0b01100011, 0b11000110, 0b01100000, 0b00011001,
0b10110000, 0b00000110, 0b01100001, 0b10000110, 0b01100000, 0b00011001,
0b10110000, 0b00000110, 0b01100000, 0b00000110, 0b01111111, 0b11111001,
0b10110000, 0b00000110, 0b01100000, 0b00000110, 0b01111000, 0b00000001,
0b10110000, 0b00000110, 0b01100000, 0b00000110, 0b01101100, 0b00000001,
0b10110000, 0b00000110, 0b01100000, 0b00000110, 0b01100110, 0b00000001,
0b10110000, 0b00001110, 0b01100000, 0b00000110, 0b01100011, 0b00000001,
0b10111111, 0b11111110, 0b01100000, 0b00000110, 0b01100001, 0b10000001,
0b10011111, 0b11111000, 0b01100000, 0b00000110, 0b01100000, 0b11000001,
0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001,
0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111
};
class COLED : public CDisplay
{
public:
COLED(unsigned char displayType, unsigned char displayBrighness, unsigned char displayInvert);
virtual ~COLED();
virtual bool open();
virtual void setIdleInt();
virtual void setErrorInt(const char* text);
virtual void setLockoutInt();
virtual void writeDStarInt(const char* my1, const char* my2, const char* your, const char* type, const char* reflector);
virtual void clearDStarInt();
virtual void writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type);
virtual void clearDMRInt(unsigned int slotNo);
virtual void writeFusionInt(const char* source, const char* dest);
virtual void clearFusionInt();
virtual void close();
private:
const char* m_slot1_state;
const char* m_slot2_state;
unsigned char m_mode;
unsigned char m_displayType;
unsigned char m_displayBrightness;
unsigned char m_displayInvert;
ArduiPi_OLED display;
void OLED_statusbar();
};
#endif

47
OLED.md Normal file
View File

@@ -0,0 +1,47 @@
# Prerequisite
Enable I2C and SPI modules directly with raspi-config tool, issue a
```
sudo raspi-config
```
Then go to menu Advanced Option, select SPI and under question ” Would you like the SPI kernel module to be loaded by default ?”, select Yes, Do the same thing for I2C Advanced Option.
As I dont use monitor or TV connected to Pi, I decreased dedicated video memory, always in raspi-config, go to Advanced Options then Memory Split, then type 16 Mo (the minimal) used for GPU, then select Finish, and select Yes when asked to reboot.
To be able to compile you will need the compiler and some others tools, issue a :
```
sudo apt-get install build-essential git-core libi2c-dev i2c-tools lm-sensors
```
*italic* Sometimes I2C and SPI modules are not started and thus he cannot start the sample code. The solution to start the modules at startup by adding the two following lines into the file /etc/modules
```
i2c-dev
spidev
```
Reboot, then you MUST see SPI and I2C devices with the following command
```
root@raspberrypi:~# ls /dev/i2c*
/dev/i2c-0
root@raspberrypi:~# ls /dev/spi*
/dev/spidev0.0 /dev/spidev0.1
```
# Installation of the generic Driver
The Driver is based on Adafruit Arduino library, I ported the code to be able to compile and run on Raspberry Pi but added also some features.
Get all the file from github dedicated repo :
```
git clone https://github.com/hallard/ArduiPi_OLED
cd ArduiPi_OLED
sudo make
```
# Building MMDVMHost
```
make -f Makefile.Pi.OLED
```
The initial guide is written by [Charles](http://hallard.me/adafruit-oled-display-driver-for-pi/)

View File

@@ -8,9 +8,12 @@ It builds on 32-bit and 64-bit Linux as well as on Windows using VS2015 on x86 a
- Nextion TFTs (sizes 2.4", 3.2" and 3.5")
- Adafruit 16x2 LCD+Keypad Kits
- TFT displays sold by Hobbytronics in UK
- OLED 128x64 (SSD1306)
The HD44780 displays are integrated with wiringPi for Raspberry Pi based platforms. The other displays can be directly connected to the UART on Raspberry Pis or with FT-232RL modules to any USB port.
The OLED display needs a extra lib see OLED.md
This software is licenced under the GPL v2 and is intended for amateur and educational use only. Use of this software for commercial purposes is strictly forbidden.
It is only to be used on the main DMR+, the main BrandMeister, and Phoenix (UK) networks. If you wish to use it on any other network, you must get written permission from myself, G4KLX. Each such request will be dealt with on a case-by-case basis.