From 4bb0d155a7ec8df31427f63b2d740a112460557b Mon Sep 17 00:00:00 2001 From: dianjixz Date: Mon, 20 May 2024 09:24:18 +0800 Subject: [PATCH] [add] show_logo --- examples/show_logo/.gitignore | 6 +++++ examples/show_logo/SConstruct | 4 +++ examples/show_logo/config_defaults.mk | 11 ++++++++ examples/show_logo/main/Kconfig | 0 examples/show_logo/main/SConstruct | 33 +++++++++++++++++++++++ examples/show_logo/main/include/main.h | 3 +++ examples/show_logo/main/src/main.c | 37 ++++++++++++++++++++++++++ 7 files changed, 94 insertions(+) create mode 100644 examples/show_logo/.gitignore create mode 100644 examples/show_logo/SConstruct create mode 100644 examples/show_logo/config_defaults.mk create mode 100644 examples/show_logo/main/Kconfig create mode 100644 examples/show_logo/main/SConstruct create mode 100644 examples/show_logo/main/include/main.h create mode 100644 examples/show_logo/main/src/main.c diff --git a/examples/show_logo/.gitignore b/examples/show_logo/.gitignore new file mode 100644 index 0000000..76b743d --- /dev/null +++ b/examples/show_logo/.gitignore @@ -0,0 +1,6 @@ + +dist +build +.config.mk +.flash.conf.json + diff --git a/examples/show_logo/SConstruct b/examples/show_logo/SConstruct new file mode 100644 index 0000000..076d65c --- /dev/null +++ b/examples/show_logo/SConstruct @@ -0,0 +1,4 @@ +from pathlib import Path +import os +with open(str(Path(os.getcwd())/'..'/'..'/'tools'/'scons'/'project.py')) as f: + exec(f.read()) diff --git a/examples/show_logo/config_defaults.mk b/examples/show_logo/config_defaults.mk new file mode 100644 index 0000000..e399c58 --- /dev/null +++ b/examples/show_logo/config_defaults.mk @@ -0,0 +1,11 @@ +# unix +CONFIG_TOOLCHAIN_PATH="/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin" +# win +# CONFIG_TOOLCHAIN_PATH="..\\gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf\\bin" + +CONFIG_TOOLCHAIN_PREFIX="arm-linux-gnueabihf-" + +# CONFIG_MINICV2_COMPONENT_ENABLED=y +CONFIG_DEVICE_DRIVER_ENABLED=y +CONFIG_DEVICE_FRAMEBUFFER_ENABLED=y +CONFIG_STB_ENABLED=y \ No newline at end of file diff --git a/examples/show_logo/main/Kconfig b/examples/show_logo/main/Kconfig new file mode 100644 index 0000000..e69de29 diff --git a/examples/show_logo/main/SConstruct b/examples/show_logo/main/SConstruct new file mode 100644 index 0000000..0470fb5 --- /dev/null +++ b/examples/show_logo/main/SConstruct @@ -0,0 +1,33 @@ +# project_root/src/SConscript +import os +# Import the environment from the SConstruct file +Import('env') +with open(env['PROJECT_TOOL_S']) as f: + exec(f.read()) + + +SRCS = Glob('src/*.c*') +INCLUDE = [ADir('include'), ADir('.')] +PRIVATE_INCLUDE = [] +REQUIREMENTS = ['pthread', 'DeviceDriver', 'stb'] +STATIC_LIB = [] +DYNAMIC_LIB = [] +DEFINITIONS = [] +DEFINITIONS_PRIVATE = [] +LDFLAGS = [] +LINK_SEARCH_PATH = [] + + +env['COMPONENTS'].append({'target':env['PROJECT_NAME'], + 'SRCS':SRCS, + 'INCLUDE':INCLUDE, + 'PRIVATE_INCLUDE':PRIVATE_INCLUDE, + 'REQUIREMENTS':REQUIREMENTS, + 'STATIC_LIB':STATIC_LIB, + 'DYNAMIC_LIB':DYNAMIC_LIB, + 'DEFINITIONS':DEFINITIONS, + 'DEFINITIONS_PRIVATE':DEFINITIONS_PRIVATE, + 'LDFLAGS':LDFLAGS, + 'LINK_SEARCH_PATH':LINK_SEARCH_PATH, + 'REGISTER':'project' + }) \ No newline at end of file diff --git a/examples/show_logo/main/include/main.h b/examples/show_logo/main/include/main.h new file mode 100644 index 0000000..45dcbb0 --- /dev/null +++ b/examples/show_logo/main/include/main.h @@ -0,0 +1,3 @@ +#pragma once + + diff --git a/examples/show_logo/main/src/main.c b/examples/show_logo/main/src/main.c new file mode 100644 index 0000000..6ade42f --- /dev/null +++ b/examples/show_logo/main/src/main.c @@ -0,0 +1,37 @@ +#include +#include +#include "framebuffer/fbtools.h" + +#define STB_IMAGE_IMPLEMENTATION +#include "stb_image.h" + + +int main(int argc, char **argv) +{ + FBDEV fbdev; + memset(&fbdev, 0, sizeof(FBDEV)); + strcpy(fbdev.dev, "/dev/fb1"); + if (fb_open(&fbdev) == 0) + { + printf("open frame buffer error/n"); + return -1; + } + int w = fbdev.fb_var.xres; + int h = fbdev.fb_var.yres; + int color = fbdev.fb_var.bits_per_pixel; + + uint16_t *piex = fbdev.fb_mem; + + int iw, ih, n; + unsigned char *idata = stbi_load("/usr/local/m5stack/logo.jpg", &iw, &ih, &n, 0); + for (int i = 0; i < iw * ih; i++) + { + piex[i] = ((((idata[3 * i]) & 0xF8) << 8) | (((idata[3 * i + 1]) & 0xFC) << 3) | ((idata[3 * i + 2]) >> 3)); + } + stbi_image_free(idata); + + usleep(60 * 1000); + + fb_close(&fbdev); + return 0; +}