mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-02-28 11:54:30 +03:00
restructuring
This commit is contained in:
42
F1:F103/LED_Screen/scrtest/Makefile
Normal file
42
F1:F103/LED_Screen/scrtest/Makefile
Normal file
@@ -0,0 +1,42 @@
|
||||
# run `make DEF=...` to add extra defines
|
||||
PROGRAM := scrtest
|
||||
LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all
|
||||
SRCS := $(wildcard *.c)
|
||||
DEFINES := $(DEF) -D_XOPEN_SOURCE=1111
|
||||
OBJDIR := mk
|
||||
CFLAGS += -O2 -Wall -Wextra -Wno-trampolines -std=gnu99
|
||||
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o))
|
||||
DEPS := $(OBJS:.o=.d)
|
||||
CC = gcc
|
||||
#CXX = g++
|
||||
|
||||
|
||||
all : $(OBJDIR) $(PROGRAM)
|
||||
|
||||
$(PROGRAM) : $(OBJS)
|
||||
@echo -e "\t\tLD $(PROGRAM)"
|
||||
$(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
ifneq ($(MAKECMDGOALS),clean)
|
||||
-include $(DEPS)
|
||||
endif
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
@echo -e "\t\tCC $<"
|
||||
$(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $<
|
||||
|
||||
clean:
|
||||
@echo -e "\t\tCLEAN"
|
||||
@rm -f $(OBJS) $(DEPS)
|
||||
@rmdir $(OBJDIR) 2>/dev/null || true
|
||||
|
||||
xclean: clean
|
||||
@rm -f $(PROGRAM)
|
||||
|
||||
gentags:
|
||||
CFLAGS="$(CFLAGS) $(DEFINES)" geany -g $(PROGRAM).c.tags *[hc] 2>/dev/null
|
||||
|
||||
.PHONY: gentags clean xclean
|
||||
1
F1:F103/LED_Screen/scrtest/Readme
Normal file
1
F1:F103/LED_Screen/scrtest/Readme
Normal file
@@ -0,0 +1 @@
|
||||
This is simple thing to test new fonts & algos
|
||||
4326
F1:F103/LED_Screen/scrtest/font14.h
Normal file
4326
F1:F103/LED_Screen/scrtest/font14.h
Normal file
File diff suppressed because it is too large
Load Diff
4322
F1:F103/LED_Screen/scrtest/font16.h
Normal file
4322
F1:F103/LED_Screen/scrtest/font16.h
Normal file
File diff suppressed because it is too large
Load Diff
330
F1:F103/LED_Screen/scrtest/fonts.c
Normal file
330
F1:F103/LED_Screen/scrtest/fonts.c
Normal file
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* This file is part of the LED_screen project.
|
||||
* Copyright 2019 Edward V. Emelianov <eddy@sao.ru, edward.emelianoff@gmail.com>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stddef.h>
|
||||
#include "fonts.h"
|
||||
|
||||
/* Bash-script to generate the symbols
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
function bits(){
|
||||
Ans=""
|
||||
for x in $(seq 7 -1 0); do
|
||||
B=$((1<<$x))
|
||||
if [ $(($1&$B)) -ne 0 ]; then Ans="${Ans}X"
|
||||
else Ans="${Ans}_"
|
||||
fi
|
||||
done
|
||||
echo $Ans
|
||||
}
|
||||
|
||||
for x in $(seq 0 255); do
|
||||
printf "#define $(bits $x)\t0x%02x\n" $x
|
||||
done
|
||||
|
||||
*/
|
||||
|
||||
#define ________ 0x00
|
||||
#define _______X 0x01
|
||||
#define ______X_ 0x02
|
||||
#define ______XX 0x03
|
||||
#define _____X__ 0x04
|
||||
#define _____X_X 0x05
|
||||
#define _____XX_ 0x06
|
||||
#define _____XXX 0x07
|
||||
#define ____X___ 0x08
|
||||
#define ____X__X 0x09
|
||||
#define ____X_X_ 0x0a
|
||||
#define ____X_XX 0x0b
|
||||
#define ____XX__ 0x0c
|
||||
#define ____XX_X 0x0d
|
||||
#define ____XXX_ 0x0e
|
||||
#define ____XXXX 0x0f
|
||||
#define ___X____ 0x10
|
||||
#define ___X___X 0x11
|
||||
#define ___X__X_ 0x12
|
||||
#define ___X__XX 0x13
|
||||
#define ___X_X__ 0x14
|
||||
#define ___X_X_X 0x15
|
||||
#define ___X_XX_ 0x16
|
||||
#define ___X_XXX 0x17
|
||||
#define ___XX___ 0x18
|
||||
#define ___XX__X 0x19
|
||||
#define ___XX_X_ 0x1a
|
||||
#define ___XX_XX 0x1b
|
||||
#define ___XXX__ 0x1c
|
||||
#define ___XXX_X 0x1d
|
||||
#define ___XXXX_ 0x1e
|
||||
#define ___XXXXX 0x1f
|
||||
#define __X_____ 0x20
|
||||
#define __X____X 0x21
|
||||
#define __X___X_ 0x22
|
||||
#define __X___XX 0x23
|
||||
#define __X__X__ 0x24
|
||||
#define __X__X_X 0x25
|
||||
#define __X__XX_ 0x26
|
||||
#define __X__XXX 0x27
|
||||
#define __X_X___ 0x28
|
||||
#define __X_X__X 0x29
|
||||
#define __X_X_X_ 0x2a
|
||||
#define __X_X_XX 0x2b
|
||||
#define __X_XX__ 0x2c
|
||||
#define __X_XX_X 0x2d
|
||||
#define __X_XXX_ 0x2e
|
||||
#define __X_XXXX 0x2f
|
||||
#define __XX____ 0x30
|
||||
#define __XX___X 0x31
|
||||
#define __XX__X_ 0x32
|
||||
#define __XX__XX 0x33
|
||||
#define __XX_X__ 0x34
|
||||
#define __XX_X_X 0x35
|
||||
#define __XX_XX_ 0x36
|
||||
#define __XX_XXX 0x37
|
||||
#define __XXX___ 0x38
|
||||
#define __XXX__X 0x39
|
||||
#define __XXX_X_ 0x3a
|
||||
#define __XXX_XX 0x3b
|
||||
#define __XXXX__ 0x3c
|
||||
#define __XXXX_X 0x3d
|
||||
#define __XXXXX_ 0x3e
|
||||
#define __XXXXXX 0x3f
|
||||
#define _X______ 0x40
|
||||
#define _X_____X 0x41
|
||||
#define _X____X_ 0x42
|
||||
#define _X____XX 0x43
|
||||
#define _X___X__ 0x44
|
||||
#define _X___X_X 0x45
|
||||
#define _X___XX_ 0x46
|
||||
#define _X___XXX 0x47
|
||||
#define _X__X___ 0x48
|
||||
#define _X__X__X 0x49
|
||||
#define _X__X_X_ 0x4a
|
||||
#define _X__X_XX 0x4b
|
||||
#define _X__XX__ 0x4c
|
||||
#define _X__XX_X 0x4d
|
||||
#define _X__XXX_ 0x4e
|
||||
#define _X__XXXX 0x4f
|
||||
#define _X_X____ 0x50
|
||||
#define _X_X___X 0x51
|
||||
#define _X_X__X_ 0x52
|
||||
#define _X_X__XX 0x53
|
||||
#define _X_X_X__ 0x54
|
||||
#define _X_X_X_X 0x55
|
||||
#define _X_X_XX_ 0x56
|
||||
#define _X_X_XXX 0x57
|
||||
#define _X_XX___ 0x58
|
||||
#define _X_XX__X 0x59
|
||||
#define _X_XX_X_ 0x5a
|
||||
#define _X_XX_XX 0x5b
|
||||
#define _X_XXX__ 0x5c
|
||||
#define _X_XXX_X 0x5d
|
||||
#define _X_XXXX_ 0x5e
|
||||
#define _X_XXXXX 0x5f
|
||||
#define _XX_____ 0x60
|
||||
#define _XX____X 0x61
|
||||
#define _XX___X_ 0x62
|
||||
#define _XX___XX 0x63
|
||||
#define _XX__X__ 0x64
|
||||
#define _XX__X_X 0x65
|
||||
#define _XX__XX_ 0x66
|
||||
#define _XX__XXX 0x67
|
||||
#define _XX_X___ 0x68
|
||||
#define _XX_X__X 0x69
|
||||
#define _XX_X_X_ 0x6a
|
||||
#define _XX_X_XX 0x6b
|
||||
#define _XX_XX__ 0x6c
|
||||
#define _XX_XX_X 0x6d
|
||||
#define _XX_XXX_ 0x6e
|
||||
#define _XX_XXXX 0x6f
|
||||
#define _XXX____ 0x70
|
||||
#define _XXX___X 0x71
|
||||
#define _XXX__X_ 0x72
|
||||
#define _XXX__XX 0x73
|
||||
#define _XXX_X__ 0x74
|
||||
#define _XXX_X_X 0x75
|
||||
#define _XXX_XX_ 0x76
|
||||
#define _XXX_XXX 0x77
|
||||
#define _XXXX___ 0x78
|
||||
#define _XXXX__X 0x79
|
||||
#define _XXXX_X_ 0x7a
|
||||
#define _XXXX_XX 0x7b
|
||||
#define _XXXXX__ 0x7c
|
||||
#define _XXXXX_X 0x7d
|
||||
#define _XXXXXX_ 0x7e
|
||||
#define _XXXXXXX 0x7f
|
||||
#define X_______ 0x80
|
||||
#define X______X 0x81
|
||||
#define X_____X_ 0x82
|
||||
#define X_____XX 0x83
|
||||
#define X____X__ 0x84
|
||||
#define X____X_X 0x85
|
||||
#define X____XX_ 0x86
|
||||
#define X____XXX 0x87
|
||||
#define X___X___ 0x88
|
||||
#define X___X__X 0x89
|
||||
#define X___X_X_ 0x8a
|
||||
#define X___X_XX 0x8b
|
||||
#define X___XX__ 0x8c
|
||||
#define X___XX_X 0x8d
|
||||
#define X___XXX_ 0x8e
|
||||
#define X___XXXX 0x8f
|
||||
#define X__X____ 0x90
|
||||
#define X__X___X 0x91
|
||||
#define X__X__X_ 0x92
|
||||
#define X__X__XX 0x93
|
||||
#define X__X_X__ 0x94
|
||||
#define X__X_X_X 0x95
|
||||
#define X__X_XX_ 0x96
|
||||
#define X__X_XXX 0x97
|
||||
#define X__XX___ 0x98
|
||||
#define X__XX__X 0x99
|
||||
#define X__XX_X_ 0x9a
|
||||
#define X__XX_XX 0x9b
|
||||
#define X__XXX__ 0x9c
|
||||
#define X__XXX_X 0x9d
|
||||
#define X__XXXX_ 0x9e
|
||||
#define X__XXXXX 0x9f
|
||||
#define X_X_____ 0xa0
|
||||
#define X_X____X 0xa1
|
||||
#define X_X___X_ 0xa2
|
||||
#define X_X___XX 0xa3
|
||||
#define X_X__X__ 0xa4
|
||||
#define X_X__X_X 0xa5
|
||||
#define X_X__XX_ 0xa6
|
||||
#define X_X__XXX 0xa7
|
||||
#define X_X_X___ 0xa8
|
||||
#define X_X_X__X 0xa9
|
||||
#define X_X_X_X_ 0xaa
|
||||
#define X_X_X_XX 0xab
|
||||
#define X_X_XX__ 0xac
|
||||
#define X_X_XX_X 0xad
|
||||
#define X_X_XXX_ 0xae
|
||||
#define X_X_XXXX 0xaf
|
||||
#define X_XX____ 0xb0
|
||||
#define X_XX___X 0xb1
|
||||
#define X_XX__X_ 0xb2
|
||||
#define X_XX__XX 0xb3
|
||||
#define X_XX_X__ 0xb4
|
||||
#define X_XX_X_X 0xb5
|
||||
#define X_XX_XX_ 0xb6
|
||||
#define X_XX_XXX 0xb7
|
||||
#define X_XXX___ 0xb8
|
||||
#define X_XXX__X 0xb9
|
||||
#define X_XXX_X_ 0xba
|
||||
#define X_XXX_XX 0xbb
|
||||
#define X_XXXX__ 0xbc
|
||||
#define X_XXXX_X 0xbd
|
||||
#define X_XXXXX_ 0xbe
|
||||
#define X_XXXXXX 0xbf
|
||||
#define XX______ 0xc0
|
||||
#define XX_____X 0xc1
|
||||
#define XX____X_ 0xc2
|
||||
#define XX____XX 0xc3
|
||||
#define XX___X__ 0xc4
|
||||
#define XX___X_X 0xc5
|
||||
#define XX___XX_ 0xc6
|
||||
#define XX___XXX 0xc7
|
||||
#define XX__X___ 0xc8
|
||||
#define XX__X__X 0xc9
|
||||
#define XX__X_X_ 0xca
|
||||
#define XX__X_XX 0xcb
|
||||
#define XX__XX__ 0xcc
|
||||
#define XX__XX_X 0xcd
|
||||
#define XX__XXX_ 0xce
|
||||
#define XX__XXXX 0xcf
|
||||
#define XX_X____ 0xd0
|
||||
#define XX_X___X 0xd1
|
||||
#define XX_X__X_ 0xd2
|
||||
#define XX_X__XX 0xd3
|
||||
#define XX_X_X__ 0xd4
|
||||
#define XX_X_X_X 0xd5
|
||||
#define XX_X_XX_ 0xd6
|
||||
#define XX_X_XXX 0xd7
|
||||
#define XX_XX___ 0xd8
|
||||
#define XX_XX__X 0xd9
|
||||
#define XX_XX_X_ 0xda
|
||||
#define XX_XX_XX 0xdb
|
||||
#define XX_XXX__ 0xdc
|
||||
#define XX_XXX_X 0xdd
|
||||
#define XX_XXXX_ 0xde
|
||||
#define XX_XXXXX 0xdf
|
||||
#define XXX_____ 0xe0
|
||||
#define XXX____X 0xe1
|
||||
#define XXX___X_ 0xe2
|
||||
#define XXX___XX 0xe3
|
||||
#define XXX__X__ 0xe4
|
||||
#define XXX__X_X 0xe5
|
||||
#define XXX__XX_ 0xe6
|
||||
#define XXX__XXX 0xe7
|
||||
#define XXX_X___ 0xe8
|
||||
#define XXX_X__X 0xe9
|
||||
#define XXX_X_X_ 0xea
|
||||
#define XXX_X_XX 0xeb
|
||||
#define XXX_XX__ 0xec
|
||||
#define XXX_XX_X 0xed
|
||||
#define XXX_XXX_ 0xee
|
||||
#define XXX_XXXX 0xef
|
||||
#define XXXX____ 0xf0
|
||||
#define XXXX___X 0xf1
|
||||
#define XXXX__X_ 0xf2
|
||||
#define XXXX__XX 0xf3
|
||||
#define XXXX_X__ 0xf4
|
||||
#define XXXX_X_X 0xf5
|
||||
#define XXXX_XX_ 0xf6
|
||||
#define XXXX_XXX 0xf7
|
||||
#define XXXXX___ 0xf8
|
||||
#define XXXXX__X 0xf9
|
||||
#define XXXXX_X_ 0xfa
|
||||
#define XXXXX_XX 0xfb
|
||||
#define XXXXXX__ 0xfc
|
||||
#define XXXXXX_X 0xfd
|
||||
#define XXXXXXX_ 0xfe
|
||||
#define XXXXXXXX 0xff
|
||||
|
||||
// here are fonts themself
|
||||
#include "font14.h"
|
||||
#include "font16.h"
|
||||
|
||||
static const afont FONTS[] = {
|
||||
[FONT14] = {font14_table, FONT14HEIGHT, FONT14BYTES, FONT14BASELINE},
|
||||
[FONT16] = {font16_table, FONT16HEIGHT, FONT16BYTES, FONT16BASELINE}
|
||||
};
|
||||
|
||||
const afont *curfont = &FONTS[FONT14];
|
||||
|
||||
/**
|
||||
* @brief choose_font - font selector
|
||||
* @param newfont - font to choose
|
||||
* @return 0 if all OK
|
||||
*/
|
||||
int choose_font(font_t newfont){
|
||||
if(newfont >= FONT_T_MAX || newfont <= FONT_T_MIN) return 1;
|
||||
curfont = &FONTS[newfont];
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
// getters for current font values
|
||||
uint8_t fontheight(){return curfont->height;}
|
||||
uint8_t fontbaseline(){return curfont->baseline;}
|
||||
uint8_t fontbytes(){return curfont->bytes;}
|
||||
*/
|
||||
|
||||
const uint8_t *font_char(uint8_t Char){
|
||||
if(Char < FIRST_SYMBOL_CODE) return NULL;
|
||||
return &curfont->font[(Char - FIRST_SYMBOL_CODE)*(curfont->bytes+1)];
|
||||
}
|
||||
54
F1:F103/LED_Screen/scrtest/fonts.h
Normal file
54
F1:F103/LED_Screen/scrtest/fonts.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of the LED_screen project.
|
||||
* Copyright 2019 Edward V. Emelianov <eddy@sao.ru, edward.emelianoff@gmail.com>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef FONTS_H__
|
||||
#define FONTS_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// code number of first symbol in font table
|
||||
#define FIRST_SYMBOL_CODE 32
|
||||
// total amount of symbols - all without first 32
|
||||
#define SYMBOLS_AMOUNT (256-FIRST_SYMBOL_CODE)
|
||||
|
||||
// type for font choosing
|
||||
typedef enum{
|
||||
FONT_T_MIN = -1, // no fonts <= this
|
||||
FONT14, // 16x16, font height near 14px
|
||||
FONT16, // 16x16, font height 16px
|
||||
FONT_T_MAX // no fonts >= this
|
||||
} font_t;
|
||||
|
||||
int choose_font(font_t newfont);
|
||||
/* uint8_t fontheight();
|
||||
uint8_t fontbaseline();
|
||||
uint8_t fontbytes(); */
|
||||
const uint8_t *font_char(uint8_t Char);
|
||||
|
||||
|
||||
typedef struct{
|
||||
const uint8_t *font;// font inself
|
||||
uint8_t height; // full font matrix height
|
||||
uint8_t bytes; // amount of bytes in font matrix
|
||||
uint8_t baseline; // baseline position (coordinate from bottom line)
|
||||
} afont;
|
||||
|
||||
extern const afont *curfont;
|
||||
|
||||
#endif // FONTS_H__
|
||||
113
F1:F103/LED_Screen/scrtest/main.c
Normal file
113
F1:F103/LED_Screen/scrtest/main.c
Normal file
@@ -0,0 +1,113 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "fonts.h"
|
||||
#include "screen.h"
|
||||
|
||||
#define WHITE "\033[1;38;40m"
|
||||
#define RED "\033[1;31;40m"
|
||||
#define GREEN "\033[1;32;40m"
|
||||
#define BLUE "\033[1;34;40m"
|
||||
#define YELLOW "\033[1;33;40m"
|
||||
#define DEFCOL "\033[0m"
|
||||
|
||||
void dumpC(uint8_t C){
|
||||
for(int i = 7; i > -1; --i)
|
||||
if(C & 1<<i) printf("*");
|
||||
else printf(" ");
|
||||
}
|
||||
|
||||
void chcolr(int n){
|
||||
switch(n){
|
||||
case 0:
|
||||
printf(RED);
|
||||
break;
|
||||
case 1:
|
||||
printf(GREEN);
|
||||
break;
|
||||
case 2:
|
||||
printf(BLUE);
|
||||
break;
|
||||
default:
|
||||
printf(YELLOW);
|
||||
}
|
||||
}
|
||||
|
||||
void dumpbuf(){
|
||||
uint8_t *buf = getScreenBuf();
|
||||
printf(WHITE " ");
|
||||
for(int x = 0; x < 4; ++x){
|
||||
printf("%d... ...", x);
|
||||
}
|
||||
printf("|");
|
||||
for(int x = 4; x < 8; ++x){
|
||||
printf("%d... ...", x);
|
||||
}
|
||||
printf(DEFCOL "\n");
|
||||
for(int y = 0; y < 16; ++y){
|
||||
chcolr(y%4);
|
||||
printf("%02d|", y);
|
||||
for(int x = 0; x < 4; ++x){
|
||||
dumpC(*buf++);
|
||||
}
|
||||
printf("|");
|
||||
for(int x = 4; x < 8; ++x){
|
||||
dumpC(*buf++);
|
||||
}
|
||||
printf("|" DEFCOL "\n");
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t dmabuf[4][SCREENBUF_SZ/4];
|
||||
void CSB(){
|
||||
uint8_t *screenbuf = getScreenBuf();
|
||||
for(uint8_t partNo = 0; partNo < 4; ++ partNo){ // cycle by strings
|
||||
uint8_t *dmaptr = dmabuf[partNo];
|
||||
for(int X = 0; X < SCREEN_WIDTH/8; ++X){
|
||||
for(int Y = SCREEN_HEIGHT-4+partNo; Y >= 0; Y -= 4){ // and cycle by Y
|
||||
*dmaptr++ = screenbuf[X + Y*(SCREEN_WIDTH/8)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void dumpdmastr(uint8_t n){
|
||||
if(n > 3) return;
|
||||
printf("\n");
|
||||
chcolr(n);
|
||||
printf("BUF[%d]:\n", n);
|
||||
uint8_t *ptr = dmabuf[n];
|
||||
for(int y = 0; y < 4; ++y){
|
||||
printf("%02d|", y);
|
||||
for(int x = 0; x < 4; ++x){
|
||||
dumpC(*ptr++);
|
||||
}
|
||||
printf("|");
|
||||
for(int x = 4; x < 8; ++x){
|
||||
dumpC(*ptr++);
|
||||
}
|
||||
printf("|\n");
|
||||
}
|
||||
printf(DEFCOL);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
if(argc != 2){
|
||||
fprintf(stderr, "USAGE: %s string\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
printf("\n\nFONT14:\n\n");
|
||||
PutStringAt(0, 15-curfont->baseline, argv[1]);
|
||||
dumpbuf();
|
||||
CSB(); //ConvertScreenBuf();
|
||||
for(uint8_t i = 0; i < 4; ++i) dumpdmastr(i);
|
||||
/*
|
||||
printf("\n\nFONT16:\n\n");
|
||||
choose_font(FONT16);
|
||||
PutStringAt(0, 15-curfont->baseline, argv[1]);
|
||||
dumpbuf();
|
||||
// CSB(); //ConvertScreenBuf();
|
||||
// for(uint8_t i = 0; i < 4; ++i) dumpdmastr(i);
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
115
F1:F103/LED_Screen/scrtest/screen.c
Normal file
115
F1:F103/LED_Screen/scrtest/screen.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* This file is part of the LED_screen project.
|
||||
* Copyright 2019 Edward V. Emelianov <eddy@sao.ru, edward.emelianoff@gmail.com>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h> // memset, memcpy
|
||||
#include <stdio.h>
|
||||
#include "fonts.h"
|
||||
#include "screen.h"
|
||||
|
||||
// !!!FOR LITTLE-ENDIAN!!!
|
||||
|
||||
// X coordinate - from left to right!
|
||||
// Y coordinate - from top to bottom!
|
||||
// (0,0) is top left corner
|
||||
|
||||
// all-screen buffer
|
||||
static uint8_t screenbuf[SCREENBUF_SZ];
|
||||
// buffers for DMA - for each of four parts
|
||||
static uint8_t dmabuf[4][SCREENBUF_SZ/4];
|
||||
|
||||
/**
|
||||
* @brief FillScreen - fill screen buffer with 0 or 1
|
||||
* @param setclear - !=1 to set & ==0 to reset
|
||||
*/
|
||||
void FillScreen(uint8_t setclear){
|
||||
uint8_t pattern = 0;
|
||||
if(setclear) pattern = 0xff;
|
||||
memset(screenbuf, pattern, SCREENBUF_SZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DrawPix - set or clear pixel
|
||||
* @param X, Y - pixel coordinates (could be outside of screen)
|
||||
* @param pix - == 1 to set and 0 to clear
|
||||
*/
|
||||
void DrawPix(int16_t X, int16_t Y, uint8_t pix){
|
||||
if(X < 0 || X > SCREEN_WIDTH-1 || Y < 0 || Y > SCREEN_HEIGHT-1) return; // outside of screen
|
||||
// now calculate coordinate of pixel
|
||||
uint8_t *ptr = &screenbuf[Y*SCREEN_WIDTH/8 + X/8];
|
||||
if(SCREEN_IS_NEGATIVE)pix = !pix;
|
||||
if(pix) *ptr |= 1 << (7 - (X%8)); // only for little-endian
|
||||
else *ptr &= ~(1 << (7 - (X%8))); // only for little-endian
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DrawCharAt - draws character @ position X,Y (this point is left baseline corner of char!)
|
||||
* @param X, Y - started point
|
||||
* @param Char - char to draw
|
||||
* @return char width
|
||||
*/
|
||||
uint8_t DrawCharAt(int16_t X, int16_t Y, uint8_t Char){
|
||||
const uint8_t *curchar = font_char(Char);
|
||||
if(!curchar) return 0;
|
||||
// now change Y coordinate to left upper corner of font
|
||||
Y += 1 - curfont->height + curfont->baseline;
|
||||
// height and width of letter in pixels
|
||||
uint8_t h = curfont->height, w = *curchar++; // now curchar is pointer to bits array
|
||||
uint8_t lw = curfont->bytes / h; // width of letter in bytes
|
||||
for(uint8_t row = 0; row <= h; ++row){
|
||||
for(uint8_t col = 0; col < w; ++col){
|
||||
DrawPix(X + col, Y + row, curchar[row*lw + (col/8)] & (1 << (7 - (col%8)))); // only for little-endian
|
||||
}
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ConvertScreenBuf - convert scscreenbuf into dmabuf
|
||||
*/
|
||||
void ConvertScreenBuf(){
|
||||
for(uint8_t partNo = 0; partNo < 4; ++ partNo){ // cycle by strings
|
||||
uint8_t *dmaptr = dmabuf[partNo];
|
||||
for(int X = 0; X < SCREEN_WIDTH/8; ++X){
|
||||
for(int Y = SCREEN_HEIGHT-4+partNo; Y >= 0; Y -= 4){ // and cycle by Y
|
||||
*dmaptr++ = screenbuf[X + Y*(SCREEN_WIDTH/8)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief PutStringAt - draw text string @ screen
|
||||
* @param X, Y - base coordinates
|
||||
* @param str - string to draw
|
||||
* @return - text width in pixels
|
||||
*/
|
||||
uint8_t PutStringAt(int16_t X, int16_t Y, char *str){
|
||||
if(!str) return 0;
|
||||
int16_t Xold = X;
|
||||
while(*str){
|
||||
X += DrawCharAt(X, Y, *str++);
|
||||
}
|
||||
return X - Xold;
|
||||
}
|
||||
|
||||
uint8_t *getScreenBuf(){return screenbuf;}
|
||||
uint8_t *getDmaBuf(uint8_t N){
|
||||
if(N > 3) return NULL;
|
||||
return dmabuf[N];
|
||||
}
|
||||
43
F1:F103/LED_Screen/scrtest/screen.h
Normal file
43
F1:F103/LED_Screen/scrtest/screen.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is part of the LED_screen project.
|
||||
* Copyright 2019 Edward V. Emelianov <eddy@sao.ru, edward.emelianoff@gmail.com>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef SCREEN_H__
|
||||
#define SCREEN_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// display size in px
|
||||
// PANEL_WIDTH is width of one panel
|
||||
#define PANEL_WIDTH 32
|
||||
// SCREEN_WIDTH is total screen width
|
||||
#define SCREEN_WIDTH 64
|
||||
#define SCREEN_HEIGHT 16
|
||||
#define SCREENBUF_SZ (SCREEN_WIDTH*SCREEN_HEIGHT/8)
|
||||
|
||||
// screen is positive (1->on, 0->off)
|
||||
#define SCREEN_IS_NEGATIVE 0
|
||||
|
||||
void FillScreen(uint8_t setclear);
|
||||
void DrawPix(int16_t X, int16_t Y, uint8_t pix);
|
||||
uint8_t DrawCharAt(int16_t X, int16_t Y, uint8_t Char);
|
||||
void ConvertScreenBuf();
|
||||
uint8_t PutStringAt(int16_t X, int16_t Y, char *str);
|
||||
uint8_t *getScreenBuf();
|
||||
uint8_t *getDmaBuf(uint8_t N);
|
||||
#endif // SCREEN_H__
|
||||
BIN
F1:F103/LED_Screen/scrtest/scrtest
Normal file
BIN
F1:F103/LED_Screen/scrtest/scrtest
Normal file
Binary file not shown.
Reference in New Issue
Block a user