Skip to content

Commit ddf8993

Browse files
Version 2.7.0, see changelog
1 parent 6ad4a2e commit ddf8993

83 files changed

Lines changed: 3430 additions & 4911 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/cppcheck.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#name: Cppcheck Static Analysis
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
cppcheck:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Install cppcheck
18+
run: sudo apt-get install -y cppcheck
19+
20+
- name: Run cppcheck
21+
run: cppcheck --project=display.cppcheck --error-exitcode=1
22+
23+
- name: Report cppcheck version
24+
run: cppcheck --version
25+
26+
- name: Run cppcheck
27+
run: cppcheck --project=display.cppcheck --error-exitcode=1

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ build/
55
examples/Bin
66
examples/Build
77
display-cppcheck-build-dir/
8-
display.cppcheck
9-
geany_test_project
10-
display_RPI_geany.geany
8+
display_rpi.geany
119
run.sh
1210

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Display Library for Linux based Single Board Computers
22

3-
[![Website](https://img.shields.io/badge/Website-Link-blue.svg)](https://gavinlyonsrepo.github.io/) [![Rss](https://img.shields.io/badge/Subscribe-RSS-yellow.svg)](https://gavinlyonsrepo.github.io//feed.xml) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/whitelight976)
4-
53
[![logo image](https://github.com/gavinlyonsrepo/Display_Lib_RPI/blob/main/extra/images/logo.png)](https://github.com/gavinlyonsrepo/Display_Lib_RPI/blob/main/extra/images/logo.png)
64

75
## Table of contents
@@ -34,6 +32,8 @@
3432
4. Dependency: [lgpio C Library](https://abyz.me.uk/lg/lgpio.html), Provides SPI,I2C, and GPIO control.
3533
5. Mutiple displays supported, see supported-devices, new components can be added.
3634
6. Tested and developed on Raspberry Pis see tool chain for more details.
35+
7. Cppcheck Status: [![Cppcheck](https://github.com/gavinlyonsrepo/Display_Lib_RPI/actions/workflows/cppcheck.yml/badge.svg)](https://github.com/gavinlyonsrepo/Display_Lib_RPI/actions/workflows/cppcheck.yml)
36+
8. Donations welcome: [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/whitelight976)
3737

3838
## Installation
3939

@@ -55,13 +55,13 @@ Open a Terminal in a folder where you want to download,build & test library
5555
Run following command to download latest release from github.
5656

5757
```sh
58-
curl -sL https://github.com/gavinlyonsrepo/Display_Lib_RPI/archive/2.6.0.tar.gz | tar xz
58+
curl -sL https://github.com/gavinlyonsrepo/Display_Lib_RPI/archive/2.7.0.tar.gz | tar xz
5959
```
6060

6161
3. Install library : Run 'make' and 'sudo make install' to run the makefile to build and then install library. It will be installed to usr/local/lib and usr/local/include by default.
6262

6363
```sh
64-
cd Display_Lib_RPI-2.6.0
64+
cd Display_Lib_RPI-2.7.0
6565
make
6666
sudo make install
6767
```

display.cppcheck

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project version="1">
3+
<builddir>display-cppcheck-build-dir</builddir>
4+
<analyze-all-vs-configs>false</analyze-all-vs-configs>
5+
<check-headers>true</check-headers>
6+
<check-unused-templates>true</check-unused-templates>
7+
<inline-suppression>true</inline-suppression>
8+
<max-ctu-depth>2</max-ctu-depth>
9+
<max-template-recursion>100</max-template-recursion>
10+
<includedir>
11+
<dir name="include"/>
12+
</includedir>
13+
<paths>
14+
<dir name="examples"/>
15+
<dir name="src"/>
16+
</paths>
17+
<suppressions>
18+
<suppression>unusedPrivateFunction</suppression>
19+
<suppression>missingIncludeSystem</suppression>
20+
<suppression>unusedFunction</suppression>
21+
<suppression>missingInclude</suppression>
22+
<suppression>normalCheckLevelMaxBranches</suppression>
23+
</suppressions>
24+
<check-level-normal/>
25+
<project-name>display</project-name>
26+
</project>

examples/Makefile

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
# ================================================
3838

3939
# ================= MAX7219_7SEG ================
40-
#SRC=max7219/tests_hwspi
41-
#SRC=max7219/tests_swspi
40+
#SRC=max7219/tests
4241
#SRC=max7219/bcdmode
4342
#SRC=max7219/clock_demo
4443
#SRC=max7219/cascade_demo
@@ -55,8 +54,7 @@
5554
# ================================================
5655

5756
# ================= HD44780 LCD I2C ==============
58-
#SRC=hd44780/test_16x02
59-
#SRC=hd44780/test_20x04
57+
#SRC=hd44780/tests
6058
#=================================================
6159

6260
# ================= SSD1306 OLED I2C =============
@@ -72,27 +70,18 @@
7270
#=================================================
7371

7472
# ========== ERM19264_UC1609 LCD SPI==============
75-
#SRC=erm19264/hello_world
76-
#SRC=erm19264/text_graphics_functions
77-
#SRC=erm19264/framerate_per_sec
78-
#SRC=erm19264/bitmap
79-
#SRC=erm19264/software_spi
73+
#SRC=erm19264/tests
8074
#=================================================
8175

8276
# ================ NOKIA5110 LCD SPI=============
8377
#SRC=nokia5110/helloworld
84-
#SRC=nokia5110/text_graphics_functions
85-
#SRC=nokia5110/framerate_test
86-
#SRC=nokia5110/framerate_test_swspi
87-
#SRC=nokia5110/bitmap
78+
#SRC=nokia5110/tests
8879
#=================================================
8980

9081
# ============= CH1115 OLED SPI ==================
91-
#SRC=ch1115/hello_world
92-
#SRC=ch1115/text_graphics_functions
82+
#SRC=ch1115/text_graphics_functions_tests
83+
#SRC=ch1115/bitmap_test
9384
#SRC=ch1115/framerate_test
94-
#SRC=ch1115/framerate_test_swspi
95-
#SRC=ch1115/bitmap
9685
#================================================
9786

9887
# =========== SH1106 or SH1107 OLED I2C ==========
@@ -115,10 +104,9 @@
115104

116105
# =============== ILI9341 TFT LCD SPI ============
117106
#SRC=ili9341/hello_world
118-
#SRC=ili9341/bitmap_tests
119-
#SRC=ili9341/text_graphics_functions
120-
#SRC=ili9341/touch_screen
107+
#SRC=ili9341/tests
121108
#SRC=ili9341/read_diagnostic_swspi
109+
#SRC=ili9341/touch_screen
122110
#SRC=ili9341/demos
123111
#=================================================
124112

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
@file examples/ch1115/bitmap/main.cpp
2+
@file examples/ch1115/bitmap_test/main.cpp
33
@brief Example file for ER_OLEDM1_CH1115 display, showing how to display bitmaps. HW SPI.
44
@test
55
-# Test 301 OLEDBitmap method
Lines changed: 78 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/*!
22
@file examples/ch1115/framerate_test/main.cpp
3-
@brief Example file for ER_OLEDM1_CH1115 display, measuring Frame rate per second)FPS, HW SPI
3+
@brief Example file for ER_OLEDM1_CH1115 display, measuring Frame rate per second (FPS)
4+
Configurable HW or SW SPI at compile time.
5+
@author Gavin Lyons.
46
@test
5-
-# Test 601 FPS HW SPI
7+
-# Test 601 hardware SPI
8+
-# Test 602 software SPI
69
*/
710

811
#include <ctime>
@@ -11,64 +14,97 @@
1114

1215
/// @cond
1316

14-
//GPIO
15-
const uint8_t RES = 25; // GPIO pin number pick any you want
16-
const uint8_t DC = 24; // GPIO pin number pick any you want
17-
int GPIO_CHIP_DEVICE = 0; // GPIO chip device number usually 0
17+
// -------------------------------------------------------------------------
18+
// CONFIGURATION: Comment out for software SPI, leave in for hardware SPI
19+
// -------------------------------------------------------------------------
20+
#define hardwareSPI
1821

19-
// Screen
22+
// ==== Globals & Common Settings ====
2023
const uint8_t MY_OLED_WIDTH = 128;
2124
const uint8_t MY_OLED_HEIGHT = 64;
22-
#define FULLSCREEN (MY_OLED_WIDTH * (MY_OLED_HEIGHT/8)) // 1024 bytes = 128 * 64/8
23-
const uint8_t OLEDcontrast = 0x80; //Constrast 00 to FF , 0x80 is default.
24-
25-
// SPi
26-
// Hardware SPI setup
27-
int HWSPI_DEVICE = 0; // A SPI device, >= 0. which SPI interface to use
28-
int HWSPI_CHANNEL = 0; // A SPI channel, >= 0. Which Chip enable pin to use
29-
int HWSPI_SPEED = 8000000; // The speed of serial communication in bits per second.
30-
int HWSPI_FLAGS = 0; // last 2 LSB bits define SPI mode, see readme, mode 0 for this device
25+
const uint8_t OLEDcontrast = 0x80; // Contrast 00 to FF, 0x80 is default.
26+
#define myScreenSize (MY_OLED_WIDTH * (MY_OLED_HEIGHT/8))
3127

32-
ERMCH1115 myOLED(MY_OLED_WIDTH ,MY_OLED_HEIGHT , RES, DC) ; // instantiate an object
28+
// Common GPIO
29+
const uint8_t RES = 25; // GPIO pin number pick any you want
30+
const uint8_t DC = 24; // GPIO pin number pick any you want
31+
int GPIO_CHIP_DEVICE = 0; // GPIO chip device number usually 0
3332

34-
// vars for the test
33+
// Test variables
3534
uint16_t count = 0;
3635
bool colour = 1;
37-
uint64_t previousCounter =0;
38-
uint16_t countLimit = 1500;
39-
40-
// =============== Function prototype ================
36+
uint64_t previousCounter = 0;
37+
38+
// =========================================================================
39+
// SPI-Specific Parameters & Object Initialization
40+
// =========================================================================
41+
#ifdef hardwareSPI
42+
uint16_t countLimit = 1500; // HW SPI limit
43+
// Hardware SPI setup parameters
44+
int SPI_DEVICE = 0; // A SPI device, >= 0. which SPI interface to use
45+
int SPI_CHANNEL = 0; // A SPI channel, >= 0. Which Chip enable pin to use
46+
int SPI_SPEED = 1000000; // The speed of serial communication in bits per second.
47+
int SPI_FLAGS = 0; // last 2 LSB bits define SPI mode, mode 0 for this device
48+
// Constructor variant for Hardware SPI
49+
ERMCH1115 myOLED(MY_OLED_WIDTH, MY_OLED_HEIGHT, RES, DC);
50+
#else // Software SPI Mode active
51+
uint16_t countLimit = 1500; // SW SPI
52+
// Software SPI pin mappings
53+
const uint8_t DIN = 5;
54+
const uint8_t SCLK = 6;
55+
const uint8_t CS = 21;
56+
// Constructor variant for Software SPI
57+
ERMCH1115 myOLED(MY_OLED_WIDTH, MY_OLED_HEIGHT, RES, DC, CS, SCLK, DIN);
58+
#endif
59+
// ===
60+
61+
// === Function prototypes ===
4162
bool Setup(void);
4263
void myTest(void);
4364
void EndTest(void);
4465
void display(long , int );
4566
static uint64_t counter( void );
4667

47-
// ======================= Main ===================
68+
// === Main ===
4869
int main()
4970
{
5071
if(!Setup()) return -1;
5172
myTest();
5273
EndTest();
5374
return 0;
5475
}
55-
// ======================= End of main ===================
76+
// === End of main ===
5677

5778

5879
bool Setup(void)
5980
{
6081
printf("OLED Begin\r\n");
61-
printf("lgpio library Version Number :: %i\r\n",lguVersion());
82+
printf("lgpio library Version Number :: %i\r\n", lguVersion());
6283
printf("Display_LIB_RPI Library version number :: %u\r\n", rdlib::LibraryVersion());
6384
delayMilliSecRDL(50);
6485

65-
if(myOLED.OLEDbegin(OLEDcontrast, HWSPI_DEVICE, HWSPI_CHANNEL, HWSPI_SPEED, HWSPI_FLAGS, GPIO_CHIP_DEVICE ) != rdlib::Success) // initialize the OLED
86+
#ifdef hardwareSPI
87+
printf("Running in HARDWARE SPI Mode...\r\n");
88+
// Initialize using Hardware SPI parameters
89+
if(myOLED.OLEDbegin(OLEDcontrast, SPI_DEVICE, SPI_CHANNEL, SPI_SPEED, SPI_FLAGS, GPIO_CHIP_DEVICE) != rdlib::Success)
90+
{
91+
printf("Error 1201: Setup GPIO/HW SPI failed, \r\n");
92+
return false;
93+
}
94+
#else
95+
printf("Running in SOFTWARE SPI Mode...\r\n");
96+
// Initialize using Software SPI parameters
97+
if(myOLED.OLEDbegin(OLEDcontrast, GPIO_CHIP_DEVICE) != rdlib::Success)
6698
{
67-
printf("Error 1202: Setup : Cannot start spi, \r\n");
99+
printf("Error 1202: Setup GPIO/SW SPI failed, \r\n");
68100
return false;
69101
}
70102
delayMilliSecRDL(50);
71-
myOLED.OLEDFillScreen(0x0F); //splash screen bars
103+
printf("Software SPI Freq delay is set to %u uS \n", myOLED.OLEDHighFreqDelayGet());
104+
#endif
105+
106+
delayMilliSecRDL(50);
107+
myOLED.OLEDFillScreen(0x0F); // splash screen bars
72108
delayMilliSecRDL(1500);
73109
return true;
74110
}
@@ -82,12 +118,18 @@ void EndTest(void)
82118

83119
void myTest() {
84120

121+
#ifdef hardwareSPI
122+
printf("FPS HW SPI:: test ends at %u\r\n", countLimit);
123+
#else
124+
printf("FPS SW SPI:: test ends at %u\r\n", countLimit);
125+
#endif
126+
85127
// Buffer setup, Define a buffer to cover whole screen
86-
uint8_t screenBuffer[FULLSCREEN]; // 1024 bytes = 128 * 64/8
87-
if (myOLED.OLEDSetBufferPtr(MY_OLED_WIDTH,MY_OLED_HEIGHT, screenBuffer) != rdlib::Success) return;
128+
uint8_t screenBuffer[myScreenSize]; // 1024 bytes = 128 * 64/8
129+
if (myOLED.OLEDSetBufferPtr(MY_OLED_WIDTH, MY_OLED_HEIGHT, screenBuffer) != rdlib::Success) return;
88130

89131
myOLED.OLEDclearBuffer(); // Clear buffer
90-
printf("FPS HW SPI:: test ends at %u\r\n",countLimit );
132+
91133
while (count < countLimit)
92134
{
93135
static long framerate = 0;
@@ -96,10 +138,8 @@ void myTest() {
96138
count++;
97139
delayMilliSecRDL(1);
98140
}
99-
100141
}
101142

102-
103143
// Function to display left hand side buffer
104144
void display(long currentFramerate, int count)
105145
{
@@ -113,6 +153,7 @@ void display(long currentFramerate, int count)
113153
myOLED.print(count);
114154

115155
// Values to count frame rate per second
156+
// cppcheck-suppress variableScope
116157
static long lastFramerate = 0;
117158
static uint16_t fps;
118159
uint64_t currentCounter = counter();
@@ -140,14 +181,12 @@ void display(long currentFramerate, int count)
140181
myOLED.OLEDupdate();
141182
}
142183

143-
//This returns nano-seconds as a 64-bit unsigned number, monotonically increasing,
144-
//probably since system boot.
145-
//The actual resolution looks like microseconds. returns nanoseconds
184+
// This returns nano-seconds as a 64-bit unsigned number.
146185
static uint64_t counter( void )
147186
{
148-
struct timespec now;
149-
clock_gettime( CLOCK_MONOTONIC, &now );
150-
return ((uint64_t)now.tv_sec * 1000000000U) + (uint64_t)now.tv_nsec;
187+
struct timespec now;
188+
clock_gettime( CLOCK_MONOTONIC, &now );
189+
return ((uint64_t)now.tv_sec * 1000000000U) + (uint64_t)now.tv_nsec;
151190
}
152191

153192
/// @endcond

0 commit comments

Comments
 (0)