mch2022-template-app/main/main.c

55 lines
1.5 KiB
C
Raw Normal View History

2022-06-02 23:30:50 +00:00
2022-06-08 14:24:28 +00:00
// This file contains a simple hello world app which you can base you own apps on.
2022-05-30 21:56:23 +00:00
2022-06-08 14:24:28 +00:00
#include "main.h"
#include "hardware.h"
#include "pax_gfx.h"
#include "pax_codecs.h"
#include "ili9341.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "esp_system.h"
2022-05-16 21:07:30 +00:00
static pax_buf_t buf;
2022-06-08 14:24:28 +00:00
xQueueHandle buttonQueue;
2022-06-08 14:24:28 +00:00
static const char *TAG = "mch2022-demo-app";
2022-06-08 14:24:28 +00:00
void disp_flush() {
ili9341_write(get_ili9341(), buf.buf);
2022-06-06 02:01:49 +00:00
}
2022-06-08 14:24:28 +00:00
void app_main() {
// Init HW.
bsp_init();
bsp_rp2040_init();
buttonQueue = get_rp2040()->queue;
2022-06-08 14:24:28 +00:00
// Init GFX.
pax_buf_init(&buf, NULL, 320, 240, PAX_BUF_16_565RGB);
2022-06-05 23:07:58 +00:00
while (1) {
// Pick a random background color.
int hue = esp_random() & 255;
pax_col_t col = pax_col_hsv(hue, 255 /*saturation*/, 255 /*brighness*/);
// Show some random color hello world.
pax_background(&buf, col);
char *text = "Hello, World!";
const pax_font_t *font = pax_get_font("saira condensed");
pax_vec1_t dims = pax_text_size(font, font->default_size, text);
pax_draw_text(
&buf, 0xff000000, font, font->default_size,
(buf.width - dims.x) / 2.0,
(buf.height - dims.y) / 2.0,
text
);
disp_flush();
// Await any button press and do another cycle.
rp2040_input_message_t message;
xQueueReceive(buttonQueue, &message, portMAX_DELAY);
}
}