From 554237acd86e32487564ce1be8a30e7a2f85cf86 Mon Sep 17 00:00:00 2001
From: Eric Brombaugh <ebrombaugh1@cox.net>
Date: Sun, 7 May 2023 10:36:02 -0700
Subject: [PATCH] Updated README

---
 examples/spi_oled/README.md  |  6 +--
 examples/spi_oled/spi_oled.c | 95 ++++++++++++++++++------------------
 2 files changed, 51 insertions(+), 50 deletions(-)

diff --git a/examples/spi_oled/README.md b/examples/spi_oled/README.md
index 254b78b..5363f92 100644
--- a/examples/spi_oled/README.md
+++ b/examples/spi_oled/README.md
@@ -8,11 +8,11 @@ different graphic screens to test out the various drawing primitives.
 
 ## Build options
 There are two build-time options in the oled.h source:
-* OLED_PSZ - the number of bytes to send per SPI data packet. The default value
+* SSD1306_PSZ - the number of bytes to send per SPI data packet. The default value
 of 32 seems to work well. Smaller values are allowed but may result in slower
 refresh rates.
-* OLED_64X32, OLED_128X32, OLED_128X64 - choose only one of these depending on
-the type of OLED you've got.
+* SSD1306_64X32, SSD1306_128X32, SSD1306_128X64 - choose only one of these
+depending on the type of OLED you've got.
 
 ## Use
 Connect an SSD1306-based OLED in SPI interface mode as follows:
diff --git a/examples/spi_oled/spi_oled.c b/examples/spi_oled/spi_oled.c
index 991ba3e..7359bb2 100644
--- a/examples/spi_oled/spi_oled.c
+++ b/examples/spi_oled/spi_oled.c
@@ -9,8 +9,8 @@
 
 #include "ch32v003fun.h"
 #include <stdio.h>
-#include <stdlib.h>
-#include "oled.h"
+#include "ssd1306_spi.h"
+#include "ssd1306.h"
 
 /* White Noise Generator State */
 #define NOISE_BITS 8
@@ -46,11 +46,11 @@ uint8_t rand8(void)
  */
 uint8_t getpix(uint8_t *buf, int16_t x, int16_t y)
 {
-	if((x<0) || (x>=OLED_W))
+	if((x<0) || (x>=SSD1306_W))
 		return 0;
-	if((y<0) || (y>=OLED_H))
+	if((y<0) || (y>=SSD1306_H))
 		return 0;
-	return buf[x+OLED_W*(y>>3)] & (1<<(y&7)) ? 1 : 0;
+	return buf[x+SSD1306_W*(y>>3)] & (1<<(y&7)) ? 1 : 0;
 }
 
 /*
@@ -58,14 +58,14 @@ uint8_t getpix(uint8_t *buf, int16_t x, int16_t y)
  */
 void conway(uint8_t *buf)
 {
-	uint8_t col[2][(OLED_H>>3)];
+	uint8_t col[2][(SSD1306_H>>3)];
 	int16_t x, y, B, b, sum, d, colidx = 0;
 	
 	/* iterate over columns */
-	for(x=0;x<OLED_W;x++)
+	for(x=0;x<SSD1306_W;x++)
 	{
 		/* iterate bytes in column */
-		for(B=0;B<(OLED_H>>3);B++)
+		for(B=0;B<(SSD1306_H>>3);B++)
 		{
 			/* init byte accum */
 			d = 0;
@@ -109,16 +109,16 @@ void conway(uint8_t *buf)
 		if(x>0)
 		{
 			/* update previous column */
-			for(y=0;y<(OLED_H>>3);y++)
-				buf[(x-1)+OLED_W*y] = col[colidx][y];
+			for(y=0;y<(SSD1306_H>>3);y++)
+				buf[(x-1)+SSD1306_W*y] = col[colidx][y];
 		}
 	}
 	
 	colidx ^= 1;
 
 	/* update final column */
-	for(y=0;y<(OLED_H>>3);y++)
-		buf[127+OLED_W*y] = col[colidx][y];
+	for(y=0;y<(SSD1306_H>>3);y++)
+		buf[127+SSD1306_W*y] = col[colidx][y];
 }
 
 int count = 0;
@@ -140,33 +140,34 @@ int main()
 	// init spi and oled
 	Delay_Ms( 100 );	// give OLED some more time
 	printf("initializing spi oled...");
-	if(!oled_init())
+	if(!ssd1306_spi_init())
 	{
+		ssd1306_init();
 		printf("done.\n\r");
 		
 #if 0
 		printf("Looping on test modes...");
 		while(1)
 		{
-			for(uint8_t mode=0;mode<(OLED_H>32?8:7);mode++)
+			for(uint8_t mode=0;mode<(SSD1306_H>32?8:7);mode++)
 			{
 				// clear buffer for next mode
-				oled_setbuf(0);
+				ssd1306_setbuf(0);
 
 				switch(mode)
 				{
 					case 0:
 						printf("buffer fill with binary\n\r");
-						for(int i=0;i<sizeof(oled_buffer);i++)
-							oled_buffer[i] = i;
+						for(int i=0;i<sizeof(ssd1306_buffer);i++)
+							ssd1306_buffer[i] = i;
 						break;
 					
 					case 1:
 						printf("pixel plots\n\r");
-						for(int i=0;i<OLED_W;i++)
+						for(int i=0;i<SSD1306_W;i++)
 						{
-							oled_drawPixel(i, i/(OLED_W/OLED_H), 1);
-							oled_drawPixel(i, OLED_H-1-(i/(OLED_W/OLED_H)), 1);
+							ssd1306_drawPixel(i, i/(SSD1306_W/SSD1306_H), 1);
+							ssd1306_drawPixel(i, SSD1306_H-1-(i/(SSD1306_W/SSD1306_H)), 1);
 						}
 						break;
 					
@@ -174,61 +175,61 @@ int main()
 						{
 							printf("Line plots\n\r");
 							uint8_t y= 0;
-							for(uint8_t x=0;x<OLED_W;x+=16)
+							for(uint8_t x=0;x<SSD1306_W;x+=16)
 							{
-								oled_drawLine(x, 0, OLED_W, y, 1);
-								oled_drawLine(OLED_W-x, OLED_H, 0, OLED_H-y, 1);
-								y+= OLED_H/8;
+								ssd1306_drawLine(x, 0, SSD1306_W, y, 1);
+								ssd1306_drawLine(SSD1306_W-x, SSD1306_H, 0, SSD1306_H-y, 1);
+								y+= SSD1306_H/8;
 							}
 						}
 						break;
 						
 					case 3:
 						printf("Circles empty and filled\n\r");
-						for(uint8_t x=0;x<OLED_W;x+=16)
+						for(uint8_t x=0;x<SSD1306_W;x+=16)
 							if(x<64)
-								oled_drawCircle(x, OLED_H/2, 15, 1);
+								ssd1306_drawCircle(x, SSD1306_H/2, 15, 1);
 							else
-								oled_fillCircle(x, OLED_H/2, 15, 1);
+								ssd1306_fillCircle(x, SSD1306_H/2, 15, 1);
 						break;
 					
 					case 4:
 						printf("Unscaled Text\n\r");
-						oled_drawstr(0,0, "This is a test", 1);
-						oled_drawstr(0,8, "of the emergency", 1);
-						oled_drawstr(0,16,"broadcasting", 1);
-						oled_drawstr(0,24,"system.",1);
-						if(OLED_H>32)
+						ssd1306_drawstr(0,0, "This is a test", 1);
+						ssd1306_drawstr(0,8, "of the emergency", 1);
+						ssd1306_drawstr(0,16,"broadcasting", 1);
+						ssd1306_drawstr(0,24,"system.",1);
+						if(SSD1306_H>32)
 						{
-							oled_drawstr(0,32, "Lorem ipsum", 1);
-							oled_drawstr(0,40, "dolor sit amet,", 1);
-							oled_drawstr(0,48,"consectetur", 1);
-							oled_drawstr(0,56,"adipiscing",1);
+							ssd1306_drawstr(0,32, "Lorem ipsum", 1);
+							ssd1306_drawstr(0,40, "dolor sit amet,", 1);
+							ssd1306_drawstr(0,48,"consectetur", 1);
+							ssd1306_drawstr(0,56,"adipiscing",1);
 						}
-						oled_xorrect(OLED_W/2, 0, OLED_W/2, OLED_W);
+						ssd1306_xorrect(SSD1306_W/2, 0, SSD1306_W/2, SSD1306_W);
 						break;
 						
 					case 5:
 						printf("Scaled Text 1, 2\n\r");
-						oled_drawstr_sz(0,0, "sz 8x8", 1, fontsize_8x8);
-						oled_drawstr_sz(0,16, "16x16", 1, fontsize_16x16);
+						ssd1306_drawstr_sz(0,0, "sz 8x8", 1, fontsize_8x8);
+						ssd1306_drawstr_sz(0,16, "16x16", 1, fontsize_16x16);
 						break;
 					
 					case 6:
 						printf("Scaled Text 4\n\r");
-						oled_drawstr_sz(0,0, "32x32", 1, fontsize_32x32);
+						ssd1306_drawstr_sz(0,0, "32x32", 1, fontsize_32x32);
 						break;
 					
 					
 					case 7:
 						printf("Scaled Text 8\n\r");
-						oled_drawstr_sz(0,0, "64", 1, fontsize_64x64);
+						ssd1306_drawstr_sz(0,0, "64", 1, fontsize_64x64);
 						break;
 
 					default:
 						break;
 				}
-				oled_refresh();
+				ssd1306_refresh();
 			
 				printf("count = %d\n\r", count++);
 				
@@ -242,19 +243,19 @@ int main()
 			int i;
 			
 			/* fill with random */
-			for(i=0;i<sizeof(oled_buffer);i++)
+			for(i=0;i<sizeof(ssd1306_buffer);i++)
 			{
-				oled_buffer[i] = rand8();
+				ssd1306_buffer[i] = rand8();
 			}
-			oled_refresh();
+			ssd1306_refresh();
 
 			/* run conway iterations */
 			for(i=0;i<500;i++)
 			{
-				conway(oled_buffer);
+				conway(ssd1306_buffer);
 				
 				/* refresh */
-				oled_refresh();
+				ssd1306_refresh();
 			}
 			
 			printf("count = %d\n\r", count++);
-- 
GitLab