|
@@ -0,0 +1,67 @@
|
|
|
+#include <kbf.h>
|
|
|
+
|
|
|
+#include <hd44780.h>
|
|
|
+
|
|
|
+#include <unity.h>
|
|
|
+#include <esp_task.h>
|
|
|
+#include <esp_task_wdt.h>
|
|
|
+
|
|
|
+static uint32_t get_time_sec() {
|
|
|
+ struct timeval tv{};
|
|
|
+ gettimeofday(&tv, nullptr);
|
|
|
+ return tv.tv_sec;
|
|
|
+}
|
|
|
+
|
|
|
+static const uint8_t char_data[] = {
|
|
|
+ 0x04, 0x0e, 0x0e, 0x0e, 0x1f, 0x00, 0x04, 0x00,
|
|
|
+ 0x1f, 0x11, 0x0a, 0x04, 0x0a, 0x11, 0x1f, 0x00
|
|
|
+};
|
|
|
+
|
|
|
+[[noreturn]] void lcd_test(void *) {
|
|
|
+ hd44780_t lcd = {
|
|
|
+ .write_cb = nullptr,
|
|
|
+ .pins = {
|
|
|
+ .rs = GPIO_NUM_32,
|
|
|
+ .e = GPIO_NUM_33,
|
|
|
+ .d4 = GPIO_NUM_25,
|
|
|
+ .d5 = GPIO_NUM_26,
|
|
|
+ .d6 = GPIO_NUM_27,
|
|
|
+ .d7 = GPIO_NUM_13,
|
|
|
+ .bl = HD44780_NOT_USED
|
|
|
+ },
|
|
|
+ .font = HD44780_FONT_5X8,
|
|
|
+ .lines = 2,
|
|
|
+ .backlight = true,
|
|
|
+ };
|
|
|
+
|
|
|
+ ESP_ERROR_CHECK(hd44780_init(&lcd));
|
|
|
+
|
|
|
+ hd44780_upload_character(&lcd, 0, char_data);
|
|
|
+ hd44780_upload_character(&lcd, 1, char_data + 8);
|
|
|
+
|
|
|
+ hd44780_gotoxy(&lcd, 0, 0);
|
|
|
+ hd44780_puts(&lcd, "\x08 Hello world!");
|
|
|
+ hd44780_gotoxy(&lcd, 0, 1);
|
|
|
+ hd44780_puts(&lcd, "\x09 ");
|
|
|
+
|
|
|
+ char time[16];
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ hd44780_gotoxy(&lcd, 2, 1);
|
|
|
+
|
|
|
+ snprintf(time, 7, "%u ", get_time_sec());
|
|
|
+ time[sizeof(time) - 1] = 0;
|
|
|
+
|
|
|
+ hd44780_puts(&lcd, time);
|
|
|
+
|
|
|
+ vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+[[noreturn]] TEST_CASE("LCD", "[esp-idf-lib]") {
|
|
|
+ xTaskCreate(lcd_test, "lcd_test", configMINIMAL_STACK_SIZE * 3, nullptr, 5, nullptr);
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ kbf::sleep(1000);
|
|
|
+ }
|
|
|
+}
|