Add comments literally everywhere.
This commit is contained in:
parent
8df04ebece
commit
888d6cbdf8
2 changed files with 31 additions and 3 deletions
|
@ -1,20 +1,30 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
// For pin mappings.
|
||||
#include "hardware.h"
|
||||
// For graphics.
|
||||
#include "pax_gfx.h"
|
||||
// For PNG images.
|
||||
#include "pax_codecs.h"
|
||||
// The screen driver.
|
||||
#include "ili9341.h"
|
||||
// For all system settings and alike.
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "esp_system.h"
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
// For WiFi connectivity.
|
||||
#include "wifi_connect.h"
|
||||
#include "wifi_connection.h"
|
||||
// For exiting to the launcher.
|
||||
#include "soc/rtc.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
|
||||
// Updates the screen with the last drawing.
|
||||
void disp_flush();
|
||||
|
||||
// Exits the app, returning to the launcher.
|
||||
void exit_to_launcher();
|
||||
|
|
24
main/main.c
24
main/main.c
|
@ -8,22 +8,26 @@ xQueueHandle buttonQueue;
|
|||
|
||||
static const char *TAG = "mch2022-demo-app";
|
||||
|
||||
// Updates the screen with the last drawing.
|
||||
void disp_flush() {
|
||||
ili9341_write(get_ili9341(), buf.buf);
|
||||
}
|
||||
|
||||
// Exits the app, returning to the launcher.
|
||||
void exit_to_launcher() {
|
||||
REG_WRITE(RTC_CNTL_STORE0_REG, 0);
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
void app_main() {
|
||||
// Init HW.
|
||||
// Init the screen, the I2C and the SPI busses.
|
||||
bsp_init();
|
||||
// Init the RP2040 (responsible for buttons among other important things).
|
||||
bsp_rp2040_init();
|
||||
// This queue is used to await button presses.
|
||||
buttonQueue = get_rp2040()->queue;
|
||||
|
||||
// Init GFX.
|
||||
// Init graphics for the screen.
|
||||
pax_buf_init(&buf, NULL, 320, 240, PAX_BUF_16_565RGB);
|
||||
|
||||
// Init NVS.
|
||||
|
@ -38,22 +42,36 @@ void app_main() {
|
|||
pax_col_t col = pax_col_hsv(hue, 255 /*saturation*/, 255 /*brighness*/);
|
||||
|
||||
// Show some random color hello world.
|
||||
// Draw the background with aforementioned random color.
|
||||
pax_background(&buf, col);
|
||||
// This text is shown on screen.
|
||||
char *text = "Hello, World!";
|
||||
// Pick the font to draw in (this is the only one that looks nice this big).
|
||||
const pax_font_t *font = pax_get_font("saira condensed");
|
||||
// Determine how large the text is so it can be centered.
|
||||
pax_vec1_t dims = pax_text_size(font, font->default_size, text);
|
||||
// Use info to draw the centered text.
|
||||
pax_draw_text(
|
||||
&buf, 0xff000000, font, font->default_size,
|
||||
// Buffer to draw to.
|
||||
&buf, 0xff000000,
|
||||
// Font and size to use.
|
||||
font, font->default_size,
|
||||
// Position (top left corner) of the app.
|
||||
(buf.width - dims.x) / 2.0,
|
||||
(buf.height - dims.y) / 2.0,
|
||||
// The text to be shown.
|
||||
text
|
||||
);
|
||||
// Draws the entire graphics buffer to the screen.
|
||||
disp_flush();
|
||||
|
||||
// Await any button press and do another cycle.
|
||||
// Structure used to receive data.
|
||||
rp2040_input_message_t message;
|
||||
// Await forever (because of portMAX_DELAY), a button press.
|
||||
xQueueReceive(buttonQueue, &message, portMAX_DELAY);
|
||||
|
||||
// Is the home button currently pressed?
|
||||
if (message.input == RP2040_INPUT_BUTTON_HOME && message.state) {
|
||||
// If home is pressed, exit to launcher.
|
||||
exit_to_launcher();
|
||||
|
|
Loading…
Reference in a new issue