mirror of
https://github.com/whowechina/aic_pico.git
synced 2025-01-18 19:14:02 +01:00
A separate gui file to handle touch screen
This commit is contained in:
parent
301217a2a4
commit
1bc71ea3d4
@ -13,7 +13,7 @@ function(make_firmware board board_def)
|
||||
|
||||
add_executable(${board}
|
||||
main.c save.c config.c commands.c light.c keypad.c
|
||||
cst816t.c st7789.c
|
||||
cst816t.c st7789.c gui.c
|
||||
cli.c usb_descriptors.c)
|
||||
target_compile_definitions(${board} PUBLIC ${board_def})
|
||||
pico_enable_stdio_usb(${board} 1)
|
||||
|
108
firmware/src/gui.c
Normal file
108
firmware/src/gui.c
Normal file
@ -0,0 +1,108 @@
|
||||
|
||||
/*
|
||||
* GUI on a Touch Display (ST7789 + CST816)
|
||||
* WHowe <github.com/whowechina>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "pico/stdio.h"
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
#include "save.h"
|
||||
#include "cli.h"
|
||||
#include "nfc.h"
|
||||
|
||||
#include "st7789.h"
|
||||
#include "cst816t.h"
|
||||
|
||||
#include "conthrax.h"
|
||||
#include "upheaval.h"
|
||||
#include "light.h"
|
||||
#include "gui.h"
|
||||
|
||||
void gui_init()
|
||||
{
|
||||
cst816t_init_i2c(i2c1, 3, 2);
|
||||
cst816t_init(i2c1, 5, 4);
|
||||
cst816t_crop(10, 230, 35, 250, 240, 280);
|
||||
st7789_init_spi(spi1, 10, 11, 9);
|
||||
st7789_init(spi1, 8, 7, 0);
|
||||
st7789_crop(0, 20, 240, 280, true);
|
||||
}
|
||||
|
||||
void gui_level(uint8_t level)
|
||||
{
|
||||
st7789_dimmer(255 - level);
|
||||
}
|
||||
|
||||
static void run_numpad()
|
||||
{
|
||||
static uint16_t phase = 0;
|
||||
phase++;
|
||||
for (int i = 0; i < 240; i++) {
|
||||
st7789_vline(i, 0, 320,
|
||||
st7789_rgb565(rgb32_from_hsv(phase % 256 + i, 255, 128)), 0xff);
|
||||
}
|
||||
|
||||
static struct {
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
char c;
|
||||
} signs[] = {
|
||||
{24, 26, '7'},
|
||||
{104, 26, '8'},
|
||||
{184, 26, '9'},
|
||||
{24, 96, '4'},
|
||||
{104, 96, '5'},
|
||||
{184, 96, '6'},
|
||||
{24, 166, '1'},
|
||||
{104, 166, '2'},
|
||||
{184, 166, '3'},
|
||||
{24, 236, '0'},
|
||||
{104, 236, ':'},
|
||||
{184, 236, ';'},
|
||||
};
|
||||
|
||||
uint32_t color = rgb32_from_hsv(time_us_32() / 100000, 200, 250);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
st7789_char(signs[i].x + 2, signs[i].y + 2, signs[i].c, &lv_conthrax, st7789_rgb565(0x101010));
|
||||
st7789_char(signs[i].x, signs[i].y, signs[i].c, &lv_conthrax, st7789_rgb565(color));
|
||||
}
|
||||
}
|
||||
|
||||
static void run_status()
|
||||
{
|
||||
char buf[32];
|
||||
|
||||
st7789_text(5, 5, "SN:", &lv_upheaval, 1, st7789_rgb565(0x00ff00));
|
||||
sprintf(buf, "%016llx", board_id_64());
|
||||
st7789_text(5, 25, buf, &lv_upheaval, 1, st7789_rgb565(0x808080));
|
||||
|
||||
st7789_text(5, 45, "Built:", &lv_upheaval, 1, st7789_rgb565(0x00ff00));
|
||||
st7789_text(5, 65, built_time, &lv_upheaval, 1, st7789_rgb565(0x808080));
|
||||
|
||||
st7789_text(5, 85, "NFC Module:", &lv_upheaval, 1, st7789_rgb565(0x00ff00));
|
||||
sprintf(buf, "%s (%s)\n", nfc_module_name(), nfc_module_version());
|
||||
st7789_text(5, 105, buf, &lv_upheaval, 1, st7789_rgb565(0x808080));
|
||||
}
|
||||
|
||||
void gui_loop()
|
||||
{
|
||||
uint8_t page = 1;
|
||||
|
||||
switch (page) {
|
||||
case 0:
|
||||
run_numpad();
|
||||
break;
|
||||
case 1:
|
||||
run_status();
|
||||
break;
|
||||
}
|
||||
|
||||
st7789_render(true);
|
||||
}
|
19
firmware/src/gui.h
Normal file
19
firmware/src/gui.h
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
/*
|
||||
* GUI on a Touch Display (ST7789 + CST816)
|
||||
* WHowe <github.com/whowechina>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GUI_H
|
||||
#define GUI_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void gui_init();
|
||||
void gui_level(uint8_t level);
|
||||
void gui_loop();
|
||||
|
||||
|
||||
#endif
|
@ -35,11 +35,7 @@
|
||||
#include "commands.h"
|
||||
#include "light.h"
|
||||
#include "keypad.h"
|
||||
|
||||
#include "st7789.h"
|
||||
#include "cst816t.h"
|
||||
|
||||
#include "conthrax.h"
|
||||
#include "gui.h"
|
||||
|
||||
#define DEBUG(...) if (aic_runtime.debug) printf(__VA_ARGS__)
|
||||
|
||||
@ -126,50 +122,13 @@ static void light_mode_update()
|
||||
was_cardio = cardio;
|
||||
}
|
||||
|
||||
static void disp_loop()
|
||||
{
|
||||
static uint16_t phase = 0;
|
||||
phase = (phase + 1) % 256;
|
||||
for (int i = 0; i < 240; i++) {
|
||||
st7789_vline(i, 0, 320,
|
||||
st7789_rgb565(rgb32_from_hsv(phase + i, 255, 128)), 0xff);
|
||||
}
|
||||
|
||||
static struct {
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
char c;
|
||||
} signs[] = {
|
||||
{24, 26, '7'},
|
||||
{104, 26, '8'},
|
||||
{184, 26, '9'},
|
||||
{24, 96, '4'},
|
||||
{104, 96, '5'},
|
||||
{184, 96, '6'},
|
||||
{24, 166, '1'},
|
||||
{104, 166, '2'},
|
||||
{184, 166, '3'},
|
||||
{24, 236, '0'},
|
||||
{104, 236, ':'},
|
||||
{184, 236, ';'},
|
||||
};
|
||||
|
||||
uint32_t color = rgb32_from_hsv(time_us_32() / 100000, 200, 200);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
st7789_char(signs[i].x + 2, signs[i].y + 2, signs[i].c, &lv_conthrax, st7789_rgb565(0x101010));
|
||||
st7789_char(signs[i].x, signs[i].y, signs[i].c, &lv_conthrax, st7789_rgb565(color));
|
||||
}
|
||||
}
|
||||
|
||||
static mutex_t core1_io_lock;
|
||||
static void core1_loop()
|
||||
{
|
||||
while (1) {
|
||||
if (mutex_try_enter(&core1_io_lock, NULL)) {
|
||||
if (aic_runtime.touch) {
|
||||
st7789_dimmer(255 - aic_cfg->lcd.backlight);
|
||||
disp_loop();
|
||||
st7789_render(true);
|
||||
gui_loop();
|
||||
}
|
||||
light_update();
|
||||
mutex_exit(&core1_io_lock);
|
||||
@ -420,12 +379,8 @@ void init()
|
||||
bana_init(cdc_reader_putc);
|
||||
|
||||
if (aic_runtime.touch) {
|
||||
cst816t_init_i2c(i2c1, 3, 2);
|
||||
cst816t_init(i2c1, 5, 4);
|
||||
cst816t_crop(10, 230, 35, 250, 240, 280);
|
||||
st7789_init_spi(spi1, 10, 11, 9);
|
||||
st7789_init(spi1, 8, 7, 0);
|
||||
st7789_crop(0, 20, 240, 280, true);
|
||||
gui_init();
|
||||
gui_level(aic_cfg->lcd.backlight);
|
||||
}
|
||||
|
||||
cli_init("aic_pico>", "\n << AIC Pico >>\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user