项目是Kevincoooool参加某个大赛开源的项目,原理图和代码开源。希望大家遵守开源协议,勿做商用或者售卖。
#include "lvgl.h" #include "stdio.h" #include #include #include "esp_system.h" #include "esp_vfs.h" #include "esp_spiffs.h" typedef struct { uint16_t min; uint16_t max; uint8_t bpp; uint8_t reserved[3]; } x_header_t; typedef struct { uint32_t pos; } x_table_t; typedef struct { uint8_t adv_w; uint8_t box_w; uint8_t box_h; int8_t ofs_x; int8_t ofs_y; uint8_t r; } glyph_dsc_t; static x_header_t __g_xbf_hd = { .min = 0x0020, .max = 0xff1a, .bpp = 4, }; char *Font_buff = NULL; // static uint8_t __g_font_buf[240]; //如bin文件存在SPI FLASH可使用此buff static void init_font(void) { FILE *ff = fopen("/spiffs/myFont.bin", "r"); if (ff == NULL) { printf("Failed to open file for reading"); return; } fseek(ff, 0, SEEK_END); long lSize = ftell(ff); rewind(ff); printf("Lsize %ld", lSize); static uint8_t first_in = 1; if (first_in == 1) { first_in = 0; Font_buff = (char *)malloc(sizeof(char) * lSize); } int br = fread(Font_buff, 1, lSize, ff); printf("Bytes read %d", br); fclose(ff); } static uint8_t *__user_font_getdata(int offset, int size) { //如字模保存在SPI FLASH, SPIFLASH_Read(__g_font_buf,offset,size); //如字模已加载到SDRAM,直接返回偏移地址即可如:return (uint8_t*)(sdram_fontddr+offset); static uint8_t first_in = 1; if (first_in == 1)//第一次进入的时候初始化外部字体 { first_in = 0; init_font(); } return (uint8_t*)(Font_buff+offset); // return __g_font_buf; } static const uint8_t *__user_font_get_bitmap(const lv_font_t *font, uint32_t unicode_letter) { if (unicode_letter > __g_xbf_hd.max || unicode_letter < __g_xbf_hd.min) { return NULL; } uint32_t unicode_offset = sizeof(x_header_t) + (unicode_letter - __g_xbf_hd.min) * 4; uint32_t *p_pos = (uint32_t *)__user_font_getdata(unicode_offset, 4); if (p_pos[0] != 0) { uint32_t pos = p_pos[0]; glyph_dsc_t *gdsc = (glyph_dsc_t *)__user_font_getdata(pos, sizeof(glyph_dsc_t)); return __user_font_getdata(pos + sizeof(glyph_dsc_t), gdsc->box_w * gdsc->box_h * __g_xbf_hd.bpp / 8); } return NULL; } static bool __user_font_get_glyph_dsc(const lv_font_t *font, lv_font_glyph_dsc_t *dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { if (unicode_letter > __g_xbf_hd.max || unicode_letter < __g_xbf_hd.min) { return NULL; } uint32_t unicode_offset = sizeof(x_header_t) + (unicode_letter - __g_xbf_hd.min) * 4; uint32_t *p_pos = (uint32_t *)__user_font_getdata(unicode_offset, 4); if (p_pos[0] != 0) { glyph_dsc_t *gdsc = (glyph_dsc_t *)__user_font_getdata(p_pos[0], sizeof(glyph_dsc_t)); dsc_out->adv_w = gdsc->adv_w; dsc_out->box_h = gdsc->box_h; dsc_out->box_w = gdsc->box_w; dsc_out->ofs_x = gdsc->ofs_x; dsc_out->ofs_y = gdsc->ofs_y; dsc_out->bpp = __g_xbf_hd.bpp; return true; } return false; } //AliHYAiHei-Beta,,-1 //字模高度:24 //XBF字体,外部bin文件 lv_font_t myFont = { .get_glyph_bitmap = __user_font_get_bitmap, .get_glyph_dsc = __user_font_get_glyph_dsc, .line_height = 24, .base_line = 0, }; LV_FONT_DECLARE(myFont); lv_obj_t *label = lv_label_create(obj, NULL); lv_obj_set_style_local_text_font(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &myFont);
本节我们实现一个基本能工作的手动浇水装置,即通过按下按键来闭合继发器让小水泵进行浇水。
本小节通过点亮LED和串口输出两个程序,来初步掌握ArduinoIDE、了解GPIO和串口使用、同时把开发环境与开发板的连接,上传程序的各环节跑通,
本程序是小鹏物联网智能浇花套件的单机版程序(不连接物联网),供同学们参考。
本文介绍ESP32中的中断机制,以及如何通过GPIO中断实现按钮控制。重点讲解了如何设置中断服务例程、处理中断抖动问题,并提供了消除中断抖动的示例代码。
本文主要介绍在未联网(AP热点)情况下实现WEB交互界面的CSS和javascript库。
本文介绍如何使用Arduino-ESP32库中的API函数获取ESP32的芯片、RAM信息等,并提供了一个示例程序代码。
ESP32系列(包括ESP32-S3)搭载Xtensa双核处理器,默认情况下Arduino框架仅使用单核运行用户代码,通过多核编程,可以充分利用硬件资源来提升系统响应和性能。
ESP32 芯片有34个物理GPIO管脚。每个GPIO管脚都可用作一个通用IO,或连接一个内部的外设信号。IO_MUX ¹、RTC IO MUX 和GPIO交换矩阵用于将信号从外设传输至GPIO管脚。
ESP32Encoder库是一个利用ESP32脉冲计数器硬件外设实现高效旋转编码器读取的软件库。
本文对比了几款适合物联网开发的盒子硬件参数,供大家参考。
专属教研服务系统,助您构建STEM课程体系,打造一站式教学环境。