copy stuff from display example
Some checks failed
Build / build (macos-12) (push) Waiting to run
Build / build (macos-14) (push) Waiting to run
Build / build (windows-2022) (push) Waiting to run
Build / build (ubuntu-22.04) (push) Failing after 16s
Documentation / build (push) Successful in 6s

This commit is contained in:
2024-04-23 22:44:03 -06:00
parent ef9a359293
commit 8bf321c11c
2 changed files with 96 additions and 1 deletions

View File

@ -5,3 +5,14 @@
CONFIG_SENSOR=y
CONFIG_BLINK=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_DISPLAY=y
CONFIG_LOG=y
CONFIG_CFB_LOG_LEVEL_DBG=y
CONFIG_CHARACTER_FRAMEBUFFER=y

View File

@ -6,6 +6,7 @@
#include <zephyr/kernel.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/logging/log.h>
#include <zephyr/display/cfb.h>
#include <app/drivers/blink.h>
@ -18,6 +19,89 @@ LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
int main(void)
{
const struct device *dev;
uint16_t x_res;
uint16_t y_res;
uint16_t rows;
uint8_t ppt;
uint8_t font_width;
uint8_t font_height;
dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
if (!device_is_ready(dev))
{
printf("Device %s not ready\n", dev->name);
return 0;
}
if (display_set_pixel_format(dev, PIXEL_FORMAT_MONO10) != 0)
{
if (display_set_pixel_format(dev, PIXEL_FORMAT_MONO01) != 0)
{
printf("Failed to set required pixel format");
return 0;
}
}
printf("Initialized %s\n", dev->name);
if (cfb_framebuffer_init(dev))
{
printf("Framebuffer initialization failed!\n");
return 0;
}
cfb_framebuffer_clear(dev, true);
display_blanking_off(dev);
x_res = cfb_get_display_parameter(dev, CFB_DISPLAY_WIDTH);
y_res = cfb_get_display_parameter(dev, CFB_DISPLAY_HEIGH);
rows = cfb_get_display_parameter(dev, CFB_DISPLAY_ROWS);
ppt = cfb_get_display_parameter(dev, CFB_DISPLAY_PPT);
for (int idx = 0; idx < 42; idx++)
{
if (cfb_get_font_size(dev, idx, &font_width, &font_height))
{
break;
}
cfb_framebuffer_set_font(dev, idx);
printf("font width %d, font height %d\n",
font_width, font_height);
}
printf("x_res %d, y_res %d, ppt %d, rows %d, cols %d\n",
x_res,
y_res,
ppt,
rows,
cfb_get_display_parameter(dev, CFB_DISPLAY_COLS));
cfb_framebuffer_invert(dev);
cfb_set_kerning(dev, 3);
while (1)
{
for (int i = 0; i < MIN(x_res, y_res); i++)
{
cfb_framebuffer_clear(dev, false);
if (cfb_print(dev,
"0123456789mMgj!\"§$%&/()=",
i, i))
{
printf("Failed to print a string\n");
continue;
}
cfb_framebuffer_finalize(dev);
#if defined(CONFIG_ARCH_POSIX)
k_sleep(K_MSEC(20));
#endif
}
}
int ret;
unsigned int period_ms = BLINK_PERIOD_MS_MAX;
const struct device *sensor, *blink;
@ -78,7 +162,7 @@ int main(void)
}
printk("Proximity detected, setting LED period to %u ms\n",
period_ms);
period_ms);
blink_set_period_ms(blink, period_ms);
}