From 32a71e956f413dcb9ef392ce159078d7f42469f4 Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Fri, 13 Aug 2021 07:15:43 +0200 Subject: [PATCH] reorganize files --- main/display.c | 46 +++++++++ main/display.h | 35 +++++++ main/font.c | 101 +++++++++++++++++++ main/hello_world_main.c | 262 ------------------------------------------------ main/main.c | 66 ++++++++++++ main/text.c | 50 +++++++++ main/text.h | 12 +++ 7 files changed, 310 insertions(+), 262 deletions(-) create mode 100644 main/display.c create mode 100644 main/display.h create mode 100644 main/font.c delete mode 100644 main/hello_world_main.c create mode 100644 main/main.c create mode 100644 main/text.c create mode 100644 main/text.h diff --git a/main/display.c b/main/display.c new file mode 100644 index 0000000..e0c67ed --- /dev/null +++ b/main/display.c @@ -0,0 +1,46 @@ +#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_cycle(){ + printf("test"); + 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; +} diff --git a/main/display.h b/main/display.h new file mode 100644 index 0000000..56ab6d5 --- /dev/null +++ b/main/display.h @@ -0,0 +1,35 @@ +#ifndef _DISPLAY_H_ +#define _DISPLAY_H_ + +#include + +#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_cycle(void); + +#endif diff --git a/main/font.c b/main/font.c new file mode 100644 index 0000000..d878def --- /dev/null +++ b/main/font.c @@ -0,0 +1,101 @@ +#include + +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}, // " + {0x14,0x7f,0x14,0x7f,0x14,0x00,0x00}, // # + {0x6f,0x49,0xc9,0x7b,0x00,0x00,0x00}, // $ + {0x63,0x13,0x08,0x64,0x63,0x00,0x00}, // % + {0x7f,0xc9,0x49,0x63,0x00,0x00,0x00}, // & + {0x03,0x00,0x00,0x00,0x00,0x00,0x00}, // ' + {0x3e,0x41,0x00,0x00,0x00,0x00,0x00}, // ( + {0x41,0x3e,0x00,0x00,0x00,0x00,0x00}, // ) + {0x0a,0x04,0x1f,0x04,0x0a,0x00,0x00}, // * + {0x08,0x08,0x3e,0x08,0x08,0x00,0x00}, // + + {0xc0,0x00,0x00,0x00,0x00,0x00,0x00}, // , + {0x08,0x08,0x08,0x08,0x00,0x00,0x00}, // - + {0x40,0x00,0x00,0x00,0x00,0x00,0x00}, // . + {0x60,0x10,0x08,0x04,0x03,0x00,0x00}, // / + {0x7f,0x41,0x41,0x7f,0x00,0x00,0x00}, // 0 + {0x01,0x7f,0x00,0x00,0x00,0x00,0x00}, // 1 + {0x7b,0x49,0x49,0x6f,0x00,0x00,0x00}, // 2 + {0x63,0x49,0x49,0x7f,0x00,0x00,0x00}, // 3 + {0x0f,0x08,0x08,0x7f,0x00,0x00,0x00}, // 4 + {0x6f,0x49,0x49,0x7b,0x00,0x00,0x00}, // 5 + {0x7f,0x49,0x49,0x7b,0x00,0x00,0x00}, // 6 + {0x03,0x01,0x01,0x7f,0x00,0x00,0x00}, // 7 + {0x7f,0x49,0x49,0x7f,0x00,0x00,0x00}, // 8 + {0x0f,0x09,0x09,0x7f,0x00,0x00,0x00}, // 9 + {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}, // = + {0x22,0x14,0x08,0x00,0x00,0x00,0x00}, // > + {0x03,0x59,0x09,0x0f,0x00,0x00,0x00}, // ? + {0x7f,0x41,0x5d,0x55,0x5f,0x00,0x00}, // @ + {0x7f,0x09,0x09,0x7f,0x00,0x00,0x00}, // A + {0x7f,0x49,0x49,0x77,0x00,0x00,0x00}, // B + {0x7f,0x41,0x41,0x63,0x00,0x00,0x00}, // C + {0x7f,0x41,0x41,0x3e,0x00,0x00,0x00}, // D + {0x7f,0x49,0x49,0x63,0x00,0x00,0x00}, // E + {0x7f,0x09,0x09,0x03,0x00,0x00,0x00}, // F + {0x7f,0x41,0x49,0x7b,0x00,0x00,0x00}, // G + {0x7f,0x08,0x08,0x7f,0x00,0x00,0x00}, // H + {0x41,0x7f,0x41,0x00,0x00,0x00,0x00}, // I + {0x60,0x40,0x40,0x7f,0x00,0x00,0x00}, // J + {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,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 + {0x7f,0x09,0x09,0x77,0x00,0x00,0x00}, // R + {0x6f,0x49,0x49,0x7b,0x00,0x00,0x00}, // S + {0x01,0x01,0x7f,0x01,0x01,0x00,0x00}, // T + {0x7f,0x40,0x40,0x7f,0x00,0x00,0x00}, // U + {0x7f,0x20,0x10,0x0f,0x00,0x00,0x00}, // V + {0x7f,0x40,0x40,0x7f,0x40,0x40,0x7f}, // W + {0x77,0x08,0x08,0x77,0x00,0x00,0x00}, // X + {0x6f,0x48,0x48,0x7f,0x00,0x00,0x00}, // Y + {0x71,0x49,0x49,0x47,0x00,0x00,0x00}, // Z + {0x7f,0x41,0x00,0x00,0x00,0x00,0x00}, // [ + {0x03,0x04,0x08,0x10,0x60,0x00,0x00}, // "\" + {0x41,0x7f,0x00,0x00,0x00,0x00,0x00}, // ] + {0x04,0x02,0x01,0x02,0x04,0x00,0x00}, // ^ + {0x80,0x80,0x80,0x80,0x00,0x00,0x00}, // _ + {0x03,0x00,0x00,0x00,0x00,0x00,0x00}, // ` + {0x74,0x54,0x54,0x7c,0x00,0x00,0x00}, // a + {0x7f,0x44,0x44,0x7c,0x00,0x00,0x00}, // b + {0x7c,0x44,0x44,0x6c,0x00,0x00,0x00}, // c + {0x7c,0x44,0x44,0x7f,0x00,0x00,0x00}, // d + {0x7c,0x54,0x54,0x5c,0x00,0x00,0x00}, // e + {0x7f,0x05,0x05,0x01,0x00,0x00,0x00}, // f + {0xbc,0xa4,0xa4,0xfc,0x00,0x00,0x00}, // g + {0x7f,0x04,0x04,0x7c,0x00,0x00,0x00}, // h + {0x7d,0x00,0x00,0x00,0x00,0x00,0x00}, // i + {0x80,0xfd,0x00,0x00,0x00,0x00,0x00}, // j + {0x7f,0x04,0x04,0x7a,0x00,0x00,0x00}, // k + {0x7f,0x00,0x00,0x00,0x00,0x00,0x00}, // l + {0x7c,0x04,0x04,0x7c,0x04,0x04,0x7c}, // m + {0x7c,0x04,0x04,0x7c,0x00,0x00,0x00}, // n + {0x7c,0x44,0x44,0x7c,0x00,0x00,0x00}, // o + {0xfc,0x44,0x44,0x7c,0x00,0x00,0x00}, // p + {0x7c,0x44,0x44,0xfc,0x00,0x00,0x00}, // q + {0x7c,0x04,0x04,0x0c,0x00,0x00,0x00}, // r + {0x5c,0x54,0x54,0x74,0x00,0x00,0x00}, // s + {0x7f,0x44,0x44,0x60,0x00,0x00,0x00}, // t + {0x7c,0x40,0x40,0x7c,0x00,0x00,0x00}, // u + {0x7c,0x20,0x10,0x0c,0x00,0x00,0x00}, // v + {0x7c,0x40,0x40,0x7c,0x40,0x40,0x7c}, // w + {0x6c,0x10,0x10,0x6c,0x00,0x00,0x00}, // x + {0xbc,0xa0,0xa0,0xfc,0x00,0x00,0x00}, // y + {0x64,0x54,0x54,0x4c,0x00,0x00,0x00}, // z + {0x08,0x3e,0x41,0x00,0x00,0x00,0x00}, // { + {0xff,0x00,0x00,0x00,0x00,0x00,0x00}, // | + {0x41,0x3e,0x08,0x00,0x00,0x00,0x00}, // } + {0x1c,0x04,0x1c,0x10,0x1c,0x00,0x00}, // ~ + {0x00,0x00,0x00,0x00,0x00,0x00,0x00} +}; + diff --git a/main/hello_world_main.c b/main/hello_world_main.c deleted file mode 100644 index c6a5aca..0000000 --- a/main/hello_world_main.c +++ /dev/null @@ -1,262 +0,0 @@ -/* 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 -#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] = { - {0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // - {0x5f,0x00,0x00,0x00,0x00,0x00,0x00}, // ! - {0x03,0x00,0x03,0x00,0x00,0x00,0x00}, // " - {0x14,0x7f,0x14,0x7f,0x14,0x00,0x00}, // # - {0x6f,0x49,0xc9,0x7b,0x00,0x00,0x00}, // $ - {0x63,0x13,0x08,0x64,0x63,0x00,0x00}, // % - {0x7f,0xc9,0x49,0x63,0x00,0x00,0x00}, // & - {0x03,0x00,0x00,0x00,0x00,0x00,0x00}, // ' - {0x3e,0x41,0x00,0x00,0x00,0x00,0x00}, // ( - {0x41,0x3e,0x00,0x00,0x00,0x00,0x00}, // ) - {0x0a,0x04,0x1f,0x04,0x0a,0x00,0x00}, // * - {0x08,0x08,0x3e,0x08,0x08,0x00,0x00}, // + - {0xc0,0x00,0x00,0x00,0x00,0x00,0x00}, // , - {0x08,0x08,0x08,0x08,0x00,0x00,0x00}, // - - {0x40,0x00,0x00,0x00,0x00,0x00,0x00}, // . - {0x60,0x10,0x08,0x04,0x03,0x00,0x00}, // / - {0x7f,0x41,0x41,0x7f,0x00,0x00,0x00}, // 0 - {0x01,0x7f,0x00,0x00,0x00,0x00,0x00}, // 1 - {0x7b,0x49,0x49,0x6f,0x00,0x00,0x00}, // 2 - {0x63,0x49,0x49,0x7f,0x00,0x00,0x00}, // 3 - {0x0f,0x08,0x08,0x7f,0x00,0x00,0x00}, // 4 - {0x6f,0x49,0x49,0x7b,0x00,0x00,0x00}, // 5 - {0x7f,0x49,0x49,0x7b,0x00,0x00,0x00}, // 6 - {0x03,0x01,0x01,0x7f,0x00,0x00,0x00}, // 7 - {0x7f,0x49,0x49,0x7f,0x00,0x00,0x00}, // 8 - {0x0f,0x09,0x09,0x7f,0x00,0x00,0x00}, // 9 - {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}, // = - {0x22,0x14,0x08,0x00,0x00,0x00,0x00}, // > - {0x03,0x59,0x09,0x0f,0x00,0x00,0x00}, // ? - {0x7f,0x41,0x5d,0x55,0x5f,0x00,0x00}, // @ - {0x7f,0x09,0x09,0x7f,0x00,0x00,0x00}, // A - {0x7f,0x49,0x49,0x77,0x00,0x00,0x00}, // B - {0x7f,0x41,0x41,0x63,0x00,0x00,0x00}, // C - {0x7f,0x41,0x41,0x3e,0x00,0x00,0x00}, // D - {0x7f,0x49,0x49,0x63,0x00,0x00,0x00}, // E - {0x7f,0x09,0x09,0x03,0x00,0x00,0x00}, // F - {0x7f,0x41,0x49,0x7b,0x00,0x00,0x00}, // G - {0x7f,0x08,0x08,0x7f,0x00,0x00,0x00}, // H - {0x41,0x7f,0x41,0x00,0x00,0x00,0x00}, // I - {0x60,0x40,0x40,0x7f,0x00,0x00,0x00}, // J - {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,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 - {0x7f,0x09,0x09,0x77,0x00,0x00,0x00}, // R - {0x6f,0x49,0x49,0x7b,0x00,0x00,0x00}, // S - {0x01,0x01,0x7f,0x01,0x01,0x00,0x00}, // T - {0x7f,0x40,0x40,0x7f,0x00,0x00,0x00}, // U - {0x7f,0x20,0x10,0x0f,0x00,0x00,0x00}, // V - {0x7f,0x40,0x40,0x7f,0x40,0x40,0x7f}, // W - {0x77,0x08,0x08,0x77,0x00,0x00,0x00}, // X - {0x6f,0x48,0x48,0x7f,0x00,0x00,0x00}, // Y - {0x71,0x49,0x49,0x47,0x00,0x00,0x00}, // Z - {0x7f,0x41,0x00,0x00,0x00,0x00,0x00}, // [ - {0x03,0x04,0x08,0x10,0x60,0x00,0x00}, // "\" - {0x41,0x7f,0x00,0x00,0x00,0x00,0x00}, // ] - {0x04,0x02,0x01,0x02,0x04,0x00,0x00}, // ^ - {0x80,0x80,0x80,0x80,0x00,0x00,0x00}, // _ - {0x03,0x00,0x00,0x00,0x00,0x00,0x00}, // ` - {0x74,0x54,0x54,0x7c,0x00,0x00,0x00}, // a - {0x7f,0x44,0x44,0x7c,0x00,0x00,0x00}, // b - {0x7c,0x44,0x44,0x6c,0x00,0x00,0x00}, // c - {0x7c,0x44,0x44,0x7f,0x00,0x00,0x00}, // d - {0x7c,0x54,0x54,0x5c,0x00,0x00,0x00}, // e - {0x7f,0x05,0x05,0x01,0x00,0x00,0x00}, // f - {0xbc,0xa4,0xa4,0xfc,0x00,0x00,0x00}, // g - {0x7f,0x04,0x04,0x7c,0x00,0x00,0x00}, // h - {0x7d,0x00,0x00,0x00,0x00,0x00,0x00}, // i - {0x80,0xfd,0x00,0x00,0x00,0x00,0x00}, // j - {0x7f,0x04,0x04,0x7a,0x00,0x00,0x00}, // k - {0x7f,0x00,0x00,0x00,0x00,0x00,0x00}, // l - {0x7c,0x04,0x04,0x7c,0x04,0x04,0x7c}, // m - {0x7c,0x04,0x04,0x7c,0x00,0x00,0x00}, // n - {0x7c,0x44,0x44,0x7c,0x00,0x00,0x00}, // o - {0xfc,0x44,0x44,0x7c,0x00,0x00,0x00}, // p - {0x7c,0x44,0x44,0xfc,0x00,0x00,0x00}, // q - {0x7c,0x04,0x04,0x0c,0x00,0x00,0x00}, // r - {0x5c,0x54,0x54,0x74,0x00,0x00,0x00}, // s - {0x7f,0x44,0x44,0x60,0x00,0x00,0x00}, // t - {0x7c,0x40,0x40,0x7c,0x00,0x00,0x00}, // u - {0x7c,0x20,0x10,0x0c,0x00,0x00,0x00}, // v - {0x7c,0x40,0x40,0x7c,0x40,0x40,0x7c}, // w - {0x6c,0x10,0x10,0x6c,0x00,0x00,0x00}, // x - {0xbc,0xa0,0xa0,0xfc,0x00,0x00,0x00}, // y - {0x64,0x54,0x54,0x4c,0x00,0x00,0x00}, // z - {0x08,0x3e,0x41,0x00,0x00,0x00,0x00}, // { - {0xff,0x00,0x00,0x00,0x00,0x00,0x00}, // | - {0x41,0x3e,0x08,0x00,0x00,0x00,0x00}, // } - {0x1c,0x04,0x1c,0x10,0x1c,0x00,0x00}, // ~ - {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); -} - -uint8_t check_chr_width(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 line, uint8_t pos, 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; - for(int x=0;x +#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"); + + put_line(fb, 2, "429 Amalienplatz", 1, 1); + + 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< +#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; + for(int x=0;x +#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