This commit is contained in:
Crispy 2025-06-19 00:03:28 +02:00
parent f05d146af7
commit f1f20cb5e1
3 changed files with 34 additions and 65 deletions

View file

@ -6,6 +6,6 @@ CH32V003FUN:=../../ch32v003fun/ch32v003fun
include ../../ch32v003fun/ch32v003fun/ch32v003fun.mk
flash : build
gdb-multiarch -x gdbinit -ex 'load' -ex 'detach' -ex 'quit' $(TARGET).elf
gdb -x gdbinit -ex 'load' -ex 'detach' -ex 'quit' $(TARGET).elf
clean : cv_clean

View file

@ -1,7 +1,5 @@
#define SSD1306_128X32
#include "ch32v003fun.h"
#include <stdio.h>
#include "ssd1306_i2c.h"
#include "ssd1306.h"
@ -21,8 +19,7 @@ u32 reader = 0;
u32 frame[WIDTH];
int main()
{
int main() {
SystemInit();
// funGpioInitAll();
// funPinMode(PIN_LED, GPIO_CFGLR_OUT_10Mhz_PP);
@ -36,8 +33,7 @@ int main()
ssd1306_cmd(*cmd_list++);
clear_screen();
while (1)
{
while (1) {
decode_next_frame();
refresh_screen();
Delay_Ms(300);
@ -46,8 +42,7 @@ int main()
}
}
void refresh_screen()
{
void refresh_screen() {
ssd1306_cmd(SSD1306_COLUMNADDR);
ssd1306_cmd(X_OFFSET); // Column start address (0 = reset)
ssd1306_cmd(X_OFFSET + WIDTH - 1); // Column end address (127 = reset)
@ -60,27 +55,23 @@ void refresh_screen()
u8 x;
u8 packet_index;
u8 page = 0;
while (page < 8)
{
while (page < 8) {
/* odd rows are unused so each nybble is expanded */
packet[packet_index] = expand[(frame[x] >> (page * 4)) & 0xf];
x++;
packet_index++;
if (x == WIDTH)
{
if (x == WIDTH) {
x = 0;
page++;
}
if (packet_index == SSD1306_PSZ)
{
if (packet_index == SSD1306_PSZ) {
ssd1306_data(packet, SSD1306_PSZ);
packet_index = 0;
}
}
}
void clear_screen()
{
void clear_screen() {
ssd1306_cmd(SSD1306_COLUMNADDR);
ssd1306_cmd(0); // Column start address (0 = reset)
ssd1306_cmd(127); // Column end address (127 = reset)
@ -91,20 +82,17 @@ void clear_screen()
ssd1306_data(frame, SSD1306_PSZ);
}
u8 next_byte()
{
u8 next_byte() {
u8 byte = video[reader];
reader += 1;
return byte;
}
void fill_frame(u8 color)
{
void fill_frame(u8 color) {
memset(frame, color ? 0xFFFFFFFF : 0x00, sizeof(frame));
}
void set_pixel(u8 x, u8 y, u8 color)
{
void set_pixel(u8 x, u8 y, u8 color) {
if (color)
frame[x] |= (1 << (y & 31));
else
@ -116,11 +104,9 @@ void rle_vertical();
void bg_strips_h();
void cell_diff_8v();
void decode_next_frame()
{
void decode_next_frame() {
Encoding_t encoding = next_byte();
switch (encoding)
{
switch (encoding) {
#ifdef USE_FillBlack
case Encoding_FillBlack:
fill_frame(0);
@ -141,8 +127,8 @@ void decode_next_frame()
rle_vertical();
break;
#endif
#ifdef USE_BGStripsH
case Encoding_BGStripsH:
#ifdef USE_BGStripsH16
case Encoding_BGStripsH16:
bg_strips_h();
break;
#endif
@ -158,20 +144,16 @@ void decode_next_frame()
}
#ifdef USE_RLEHorizontal
void rle_horizontal()
{
void rle_horizontal() {
u8 x = 0;
u8 y = 0;
u8 color = 0;
while (y < HEIGHT)
{
while (y < HEIGHT) {
u8 run = next_byte();
for (int i = 0; i < run; i++)
{
for (int i = 0; i < run; i++) {
set_pixel(x, y, color);
x += 1;
if (x == WIDTH)
{
if (x == WIDTH) {
x = 0;
y += 1;
}
@ -182,20 +164,16 @@ void rle_horizontal()
#endif
#ifdef USE_RLEVertical
void rle_vertical()
{
void rle_vertical() {
u8 x = 0;
u8 y = 0;
u8 color = 0;
while (x < WIDTH)
{
while (x < WIDTH) {
u8 run = next_byte();
for (int i = 0; i < run; i++)
{
for (int i = 0; i < run; i++) {
set_pixel(x, y, color);
y += 1;
if (y == HEIGHT)
{
if (y == HEIGHT) {
y = 0;
x += 1;
}
@ -205,22 +183,19 @@ void rle_vertical()
}
#endif
#ifdef USE_BGStripsH
void bg_strips_h()
{
#ifdef USE_BGStripsH16
void bg_strips_h() {
u8 head = next_byte();
u8 bg = head >> 7;
u8 fg = 1 - bg;
fill_frame(bg);
u8 strip_count = head & 127;
for (u8 i = 0; i < strip_count; i++)
{
for (u8 i = 0; i < strip_count; i++) {
u16 packed = (next_byte() << 8) | next_byte();
u8 y = packed >> 11;
u8 x_start = (packed >> 5) & 0x3f;
u8 width = packed & 0x1f;
for (int x = x_start; x < (x_start + width); x++)
{
for (int x = x_start; x < (x_start + width); x++) {
set_pixel(x, y, fg);
}
}
@ -228,27 +203,21 @@ void bg_strips_h()
#endif
#ifdef USE_CellDiff8V
void cell_diff_8v()
{
void cell_diff_8v() {
u32 bitmap = (next_byte() << 16) | (next_byte() << 8) | next_byte();
u8 run_remaining = next_byte();
u8 color = 0;
for (u8 x = 0; x < WIDTH; x++)
{
for (u8 x = 0; x < WIDTH; x++) {
u8 cellx = x >> 3;
for (u8 y = 0; y < HEIGHT; y++)
{
for (u8 y = 0; y < HEIGHT; y++) {
u8 celly = y >> 3;
if (bitmap >> (cellx + (WIDTH / 8) * celly) & 1)
{
if (bitmap >> (cellx + (WIDTH / 8) * celly) & 1) {
// advance rle once
if (run_remaining == 0)
{
if (run_remaining == 0) {
run_remaining = next_byte();
color = 1 - color;
if (run_remaining == 0)
{
if (run_remaining == 0) {
run_remaining = next_byte();
color = 1 - color;
}