Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ch32v003fun
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Horn
ch32v003fun
Commits
554237ac
Commit
554237ac
authored
1 year ago
by
Eric Brombaugh
Browse files
Options
Downloads
Patches
Plain Diff
Updated README
parent
1c5436b7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/spi_oled/README.md
+3
-3
3 additions, 3 deletions
examples/spi_oled/README.md
examples/spi_oled/spi_oled.c
+48
-47
48 additions, 47 deletions
examples/spi_oled/spi_oled.c
with
51 additions
and
50 deletions
examples/spi_oled/README.md
+
3
−
3
View file @
554237ac
...
...
@@ -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:
...
...
This diff is collapsed.
Click to expand it.
examples/spi_oled/spi_oled.c
+
48
−
47
View file @
554237ac
...
...
@@ -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
++
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment