Compare commits

...

6 Commits

Author SHA1 Message Date
56a58fca79 display init function 2021-08-13 07:23:48 +02:00
32a71e956f reorganize files 2021-08-13 07:15:43 +02:00
8057e659a3 add centered text 2021-08-13 06:05:55 +02:00
908ecfc1d7 add variable spacing and scalable font 2021-08-13 06:05:13 +02:00
c4519fd92f change pixels in font 2021-08-13 06:03:35 +02:00
5232d4c089 add proportional font 2021-08-12 04:29:51 +02:00
6 changed files with 215 additions and 134 deletions

74
main/display.c Normal file
View File

@@ -0,0 +1,74 @@
#include "driver/gpio.h"
#include "display.h"
uint8_t fb[64][128][3];
void write_bits(uint8_t r1, uint8_t g1, uint8_t b1, uint8_t r2, uint8_t g2, uint8_t b2){
gpio_set_level(GPIO_R1, r1);
gpio_set_level(GPIO_G1, g1);
gpio_set_level(GPIO_B1, b1);
gpio_set_level(GPIO_R2, r2);
gpio_set_level(GPIO_G2, g2);
gpio_set_level(GPIO_B2, b2);
}
void write_address(uint8_t addr){
gpio_set_level(GPIO_A, addr&0x01);
gpio_set_level(GPIO_B, (addr&0x02)>>1);
gpio_set_level(GPIO_C, (addr&0x04)>>2);
gpio_set_level(GPIO_D, (addr&0x08)>>3);
gpio_set_level(GPIO_E, (addr&0x10)>>4);
}
void latch(){
gpio_set_level(GPIO_LAT, 0);
gpio_set_level(GPIO_LAT, 1);
}
void clock(){
gpio_set_level(GPIO_CLK, 1);
gpio_set_level(GPIO_CLK, 0);
}
void display_init(){
gpio_config_t io_conf;
//disable interrupt
io_conf.intr_type = GPIO_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask =
(1ULL<<GPIO_LAT)|(1ULL<<GPIO_OE)|(1ULL<<GPIO_CLK)
|(1ULL<<GPIO_R1)|(1ULL<<GPIO_G1)|(1ULL<<GPIO_B1)|(1ULL<<GPIO_R2)|(1ULL<<GPIO_G2)|(1ULL<<GPIO_B2)
|(1ULL<<GPIO_A)|(1ULL<<GPIO_B)|(1ULL<<GPIO_C)|(1ULL<<GPIO_D)|(1ULL<<GPIO_E);
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
gpio_config(&io_conf);
gpio_set_level(GPIO_OE, 0);
write_bits(0,0,0,0,0,0);
for(uint8_t i=0;i<128;i++){
clock();
}
latch();
gpio_set_level(GPIO_OE, 1);
gpio_set_level(GPIO_OE, 0);
}
void display_cycle(){
static uint8_t line = 0;
for(uint8_t i=0;i<128;i++){
write_bits(fb[line][i][0],fb[line][i][1],fb[line][i][2],fb[32+line][i][0],fb[32+line][i][1],fb[32+line][i][2]);
clock();
}
gpio_set_level(GPIO_OE, 1);
latch();
write_address(line);
gpio_set_level(GPIO_OE, 0);
line = (line + 1)%32;
}

36
main/display.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef _DISPLAY_H_
#define _DISPLAY_H_
#include <stdint.h>
#define DISPLAY_WIDTH 128
#define DISPLAY_HEIGHT 64
#define GPIO_R1 25
#define GPIO_G1 26
#define GPIO_B1 27
#define GPIO_R2 14
#define GPIO_G2 12
#define GPIO_B2 13
#define GPIO_CLK 16
#define GPIO_OE 15
#define GPIO_LAT 4
#define GPIO_A 23
#define GPIO_B 19
#define GPIO_C 5
#define GPIO_D 17
#define GPIO_E 18
extern uint8_t fb[64][128][3];
void write_bits(uint8_t r1, uint8_t g1, uint8_t b1, uint8_t r2, uint8_t g2, uint8_t b2);
void write_address(uint8_t addr);
void latch(void);
void clock(void);
void display_init(void);
void display_cycle(void);
#endif

View File

@@ -1,48 +1,6 @@
/* Hello World Example
#include <stdint.h>
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "driver/gpio.h"
#ifdef CONFIG_IDF_TARGET_ESP32
#define CHIP_NAME "ESP32"
#endif
#ifdef CONFIG_IDF_TARGET_ESP32S2BETA
#define CHIP_NAME "ESP32-S2 Beta"
#endif
#define GPIO_R1 25
#define GPIO_G1 26
#define GPIO_B1 27
#define GPIO_R2 14
#define GPIO_G2 12
#define GPIO_B2 13
#define GPIO_CLK 16
#define GPIO_OE 15
#define GPIO_LAT 4
#define GPIO_A 23
#define GPIO_B 19
#define GPIO_C 5
#define GPIO_D 17
#define GPIO_E 18
uint8_t fb[64][128][3];
const unsigned char font[96][7] = {
const uint8_t font[96][7] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //
{0x5f,0x00,0x00,0x00,0x00,0x00,0x00}, // !
{0x03,0x00,0x03,0x00,0x00,0x00,0x00}, // "
@@ -69,7 +27,7 @@ const unsigned char font[96][7] = {
{0x03,0x01,0x01,0x7f,0x00,0x00,0x00}, // 7
{0x7f,0x49,0x49,0x7f,0x00,0x00,0x00}, // 8
{0x0f,0x09,0x09,0x7f,0x00,0x00,0x00}, // 9
{0x41,0x00,0x00,0x00,0x00,0x00,0x00}, // :
{0x22,0x00,0x00,0x00,0x00,0x00,0x00}, // :
{0xc1,0x00,0x00,0x00,0x00,0x00,0x00}, // ;
{0x08,0x14,0x22,0x00,0x00,0x00,0x00}, // <
{0x14,0x14,0x14,0x14,0x00,0x00,0x00}, // =
@@ -89,7 +47,7 @@ const unsigned char font[96][7] = {
{0x7f,0x08,0x08,0x77,0x00,0x00,0x00}, // K
{0x7f,0x40,0x40,0x60,0x00,0x00,0x00}, // L
{0x7f,0x01,0x01,0x7f,0x01,0x01,0x7f}, // M
{0x7f,0x01,0x01,0x7f,0x00,0x00,0x00}, // N
{0x7f,0x04,0x08,0x10,0x7f,0x00,0x00}, // N
{0x7f,0x41,0x41,0x7f,0x00,0x00,0x00}, // O
{0x7f,0x09,0x09,0x0f,0x00,0x00,0x00}, // P
{0x7f,0x41,0xc1,0x7f,0x00,0x00,0x00}, // Q
@@ -141,91 +99,3 @@ const unsigned char font[96][7] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00}
};
void write_bits(uint8_t r1, uint8_t g1, uint8_t b1, uint8_t r2, uint8_t g2, uint8_t b2){
gpio_set_level(GPIO_R1, r1);
gpio_set_level(GPIO_G1, g1);
gpio_set_level(GPIO_B1, b1);
gpio_set_level(GPIO_R2, r2);
gpio_set_level(GPIO_G2, g2);
gpio_set_level(GPIO_B2, b2);
}
void write_address(uint8_t addr){
gpio_set_level(GPIO_A, addr&0x01);
gpio_set_level(GPIO_B, (addr&0x02)>>1);
gpio_set_level(GPIO_C, (addr&0x04)>>2);
gpio_set_level(GPIO_D, (addr&0x08)>>3);
gpio_set_level(GPIO_E, (addr&0x10)>>4);
}
void put_chr(uint8_t line, uint8_t pos, uint8_t chr[]){
for(int i=0;i<8;i++)
for(int j=0;j<7;j++)
fb[1+(line*10)+i][(pos*8)+j][0] = (chr[j]&(1<<i))>>i;
}
void put_line(uint8_t line, char *str){
uint8_t pos = 0;
while(str[pos] != 0){
put_chr(line, pos, font[str[pos]-0x20]);
pos++;
}
}
void latch(){
gpio_set_level(GPIO_LAT, 0);
gpio_set_level(GPIO_LAT, 1);
}
void clock(){
gpio_set_level(GPIO_CLK, 1);
gpio_set_level(GPIO_CLK, 0);
}
void app_main(void)
{
printf("Hello world!\n");
put_line(0, "429 Amalienplatz");
put_line(1, "0123abcd");
gpio_config_t io_conf;
//disable interrupt
io_conf.intr_type = GPIO_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask =
(1ULL<<GPIO_LAT)|(1ULL<<GPIO_OE)|(1ULL<<GPIO_CLK)
|(1ULL<<GPIO_R1)|(1ULL<<GPIO_G1)|(1ULL<<GPIO_B1)|(1ULL<<GPIO_R2)|(1ULL<<GPIO_G2)|(1ULL<<GPIO_B2)
|(1ULL<<GPIO_A)|(1ULL<<GPIO_B)|(1ULL<<GPIO_C)|(1ULL<<GPIO_D)|(1ULL<<GPIO_E);
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
gpio_config(&io_conf);
gpio_set_level(GPIO_OE, 0);
write_bits(1,0,0,1,0,0);
for(uint8_t i=0;i<128;i++){
clock();
}
latch();
gpio_set_level(GPIO_OE, 1);
gpio_set_level(GPIO_OE, 0);
uint8_t line = 0;
for (;;) {
for(uint8_t i=0;i<128;i++){
write_bits(fb[line][i][0],fb[line][i][1],fb[line][i][2],fb[32+line][i][0],fb[32+line][i][1],fb[32+line][i][2]);
clock();
}
gpio_set_level(GPIO_OE, 1);
latch();
write_address(line);
gpio_set_level(GPIO_OE, 0);
line = (line + 1)%32;
}
}

39
main/main.c Normal file
View File

@@ -0,0 +1,39 @@
/* Hello World Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "driver/gpio.h"
#include "display.h"
#include "text.h"
#ifdef CONFIG_IDF_TARGET_ESP32
#define CHIP_NAME "ESP32"
#endif
#ifdef CONFIG_IDF_TARGET_ESP32S2BETA
#define CHIP_NAME "ESP32-S2 Beta"
#endif
void app_main(void)
{
printf("Hello world!\n");
display_init();
put_line(fb, 2, "429 Amalienplatz", 1, 1);
for (;;) {
display_cycle();
}
}

50
main/text.c Normal file
View File

@@ -0,0 +1,50 @@
#include <stdint.h>
#include "text.h"
uint8_t check_chr_width(const uint8_t chr[]){
for(int i=6;i>=0;i--)
if(chr[i] != 0)
return i;
return 2; //space character
}
void put_chr(uint8_t framebuffer[DISPLAY_HEIGHT][DISPLAY_WIDTH][3], uint8_t line, uint8_t pos, const uint8_t chr[], uint8_t size){
for(int i=0;i<8;i++)
for(int j=0;j<7;j++){
uint8_t val = (chr[j]&(1<<i))>>i;
for(int x=0;x<size;x++)
for(int y=0;y<size;y++)
framebuffer[1+(line*10)+(i*size)+y][(pos)+(j*size)+x][0] = val;
}
}
void put_line(uint8_t framebuffer[DISPLAY_HEIGHT][DISPLAY_WIDTH][3], uint8_t line, char *str, uint8_t spacing, uint8_t size){
uint8_t pos = 0;
uint8_t disp_pos = 0;
while(str[pos] != 0){
put_chr(framebuffer, line, disp_pos, font[str[pos]-0x20], size);
disp_pos += (check_chr_width(font[str[pos]-0x20]) + 1 + spacing)*size;
pos++;
}
}
void put_line_center(uint8_t framebuffer[DISPLAY_HEIGHT][DISPLAY_WIDTH][3], uint8_t line, char *str, uint8_t spacing, uint8_t size){
uint8_t pos = 0;
uint8_t txt_length = 0;
while(str[pos] != 0){
txt_length += (check_chr_width(font[str[pos]-0x20]) + 1 + spacing)*size;
pos++;
}
pos=0;
uint8_t disp_pos = (DISPLAY_WIDTH/2) - (txt_length/2);
while(str[pos] != 0){
put_chr(framebuffer, line, disp_pos, font[str[pos]-0x20], size);
disp_pos += (check_chr_width(font[str[pos]-0x20]) + 1 + spacing)*size;
pos++;
}
}

12
main/text.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef _TEXT_H_
#define _TEXT_H_
#include <stdint.h>
#include "display.h"
extern const uint8_t font[96][7];
void put_line(uint8_t framebuffer[DISPLAY_HEIGHT][DISPLAY_WIDTH][3], uint8_t line, char *str, uint8_t spacing, uint8_t size);
void put_line_center(uint8_t framebuffer[DISPLAY_HEIGHT][DISPLAY_WIDTH][3], uint8_t line, char *str, uint8_t spacing, uint8_t size);
#endif