]> Devi Nivas Git - smartwatch.git/commitdiff
Create splash screen
authorAdvaith Menon <noreply-git@bp4k.net>
Mon, 17 Nov 2025 08:59:29 +0000 (03:59 -0500)
committerAdvaith Menon <noreply-git@bp4k.net>
Mon, 17 Nov 2025 08:59:29 +0000 (03:59 -0500)
* Modify LCD_WIDTH and LCD_HEIGHT to correct values
* Mofify gl_setbaudWait to accept a baud change callback
* Add animation to display "SMART WATCH OS" on the screen
* Add home screen tiles generation functionality
* Test clock functionality in a debug mode

main/CMakeLists.txt
main/goldeloxSerial.c
main/goldeloxSerial.h
main/hello_world_main.c
main/pins.h
main/task_lcd.c [new file with mode: 0644]
main/task_lcd.h [new file with mode: 0644]

index f6bc1763e307e97268d5f2c7512ed10ef2c85c10..e300e74f23f09a66ad101f215c4cb5b8b15a2bdc 100644 (file)
@@ -1,5 +1,6 @@
 idf_component_register(SRCS "hello_world_main.c"
                             "goldeloxSerial.c"
+                            "task_lcd.c"
                        INCLUDE_DIRS "."
                        PRIV_REQUIRES esp_driver_gpio
                                      esp_driver_uart
index 91b97ab484f7973ef266448b1b7bb785a186723f..d4d72874728c97dc3f4101460163b785bc7a23ab 100644 (file)
@@ -1063,7 +1063,8 @@ void gl_blitComtoDisplay(gl_display_t *display, gl_word_t  X, gl_word_t  Y, gl_w
   GetAck(display->serif) ;
 }
 
-void gl_setbaudWait(gl_display_t *display, gl_word_t  Newrate)
+void gl_setbaudWait(gl_display_t *display, gl_word_t  Newrate,
+        void (*cb)())
 {
   unsigned char  towrite[4] ;
   towrite[0]= F_setbaudWait >> 8 ;
@@ -1072,6 +1073,7 @@ void gl_setbaudWait(gl_display_t *display, gl_word_t  Newrate)
   towrite[3]= Newrate ;
   WriteBytes(display->serif, towrite, 4) ;
   //SetThisBaudrate(Newrate) ; // change this systems baud rate to match new display rate, ACK is 100ms away
+  cb();
   GetAck(display->serif) ;
 }
 
index 06643feb277b6cc2b9f339f2dc378421d56cfc4b..eb073af2e0defab674a81c58428a10107b8c5ae1 100644 (file)
@@ -221,7 +221,7 @@ gl_word_t gl_sys_GetPmmC(gl_display_t *display) ;
 gl_word_t gl_sys_GetVersion(gl_display_t *display) ;
 
 // AVOID ME SINCE I DON"T CHANGE ESP BAUD RATE
-void gl_setbaudWait(gl_display_t *display, gl_word_t  Newrate) ;
+void gl_setbaudWait(gl_display_t *display, gl_word_t  Newrate, void (*cb)()) ;
 
 void gl_pokeB(gl_display_t *display, gl_word_t  Address, gl_word_t  ByteValue) ;
 void gl_pokeW(gl_display_t *display, gl_word_t  Address, gl_word_t  WordValue) ;
index 309d24f0acacf667afffcb7888066eca4c8f4760..a823780ea2fcf599809f41b587ff30dcdb28c3ed 100644 (file)
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 #include "driver/gpio.h"
-#include "driver/uart.h"
-
-#include "Goldelox_const4D.h"
-#include "goldeloxSerial.h"
 
 #include "pins.h"
+#include "task_lcd.h"
 
 
-const uart_port_t uart_num = UART_NUM_1;
-
-int write_tx(const void *data, size_t sz) {
-    return uart_write_bytes(uart_num, data, sz);
-}
-
-
-int read_rx(void *data, size_t sz, uint32_t wait_ms) {
-    if (sizeof(size_t) > sizeof(uint32_t) && sz > UINT32_MAX)
-        return -1;
-    return uart_read_bytes(uart_num, data, (uint32_t) sz,
-            (TickType_t) wait_ms / portTICK_PERIOD_MS);
-}
-
-
-int flush_rx() {
-    return (int) uart_flush(uart_num);
-}
-
-
-int flush_tx(uint32_t wait_ms) {
-    return (int) uart_wait_tx_done(uart_num,
-            (TickType_t) wait_ms / portTICK_PERIOD_MS);
-}
 
 void app_main(void)
 {
-    // Setup UART buffered IO with event queue
-    const int uart_buffer_size = UART_HW_FIFO_LEN(uart_num) + 4;
-    QueueHandle_t uart_queue;
-
-    gl_serif_t serif_ulcd = {
-        .write_tx = write_tx,
-        .read_rx = read_rx,
-        .flush_rx = flush_rx,
-        .flush_tx = flush_tx
-    };
-
-    gl_display_t disp;
-
     printf("Hello world!\n");
 
     ESP_ERROR_CHECK(gpio_reset_pin(PIN_BUTTON_WHITE));
@@ -84,41 +44,11 @@ void app_main(void)
     ESP_ERROR_CHECK(gpio_set_direction(PIN_VIBRATOR, GPIO_MODE_OUTPUT));
     ESP_ERROR_CHECK(gpio_set_drive_capability(PIN_VIBRATOR, GPIO_DRIVE_CAP_3));
 
-    ESP_ERROR_CHECK(gpio_reset_pin(PIN_ULCD_RESET));
-    ESP_ERROR_CHECK(gpio_set_direction(PIN_ULCD_RESET, GPIO_MODE_OUTPUT));
-    ESP_ERROR_CHECK(gpio_set_drive_capability(PIN_ULCD_RESET, GPIO_DRIVE_CAP_1));
 
     gpio_dump_io_configuration(stdout, (1ULL << PIN_VIBRATOR) | (1ULL << PIN_BUTTON_RED));
 
-    ESP_ERROR_CHECK(uart_driver_install(uart_num, uart_buffer_size, uart_buffer_size, 10, &uart_queue, 0));
-
-    uart_config_t uart_config = {
-        .baud_rate = 9600,
-        .data_bits = UART_DATA_8_BITS,
-        .parity = UART_PARITY_DISABLE,
-        .stop_bits = UART_STOP_BITS_1,
-        .flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS,
-        .rx_flow_ctrl_thresh = 10,
-    };
-    // Configure UART parameters
-    ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
-    // tx then rx
-    ESP_ERROR_CHECK(uart_set_pin(uart_num, PIN_ULCD_TX, PIN_ULCD_RX,
-                UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
+    lcd_task();
 
-    ESP_ERROR_CHECK(gpio_set_level(PIN_ULCD_RESET, 0));
-    vTaskDelay(100 / portTICK_PERIOD_MS);
-    ESP_ERROR_CHECK(gpio_set_level(PIN_ULCD_RESET, 1));
-    printf("Hello world!\n");
-
-    gl_init(&disp, &serif_ulcd);
-    printf("Hello world!\n");
-    gl_gfx_BGcolour(&disp, WHITE);
-    printf("Hello world!\n");
-    gl_gfx_Cls(&disp);
-    printf("Hello world!\n");
-    gl_gfx_CircleFilled(&disp, 72, 72, 20, TOMATO);
-    printf("Hello world!\n");
     /*
     for (int i = 10; i >= 0; i--) {
         printf("Restarting in %d seconds...\n", i);
index 6d4cb007ed3d0eee3708d11862b8735ff9fdd77a..04623f42f6bd1a7e546429c3a1cda01f381e1001 100644 (file)
@@ -3,6 +3,8 @@
 #ifndef __PINS_H__
 #define __PINS_H__
 
+#define FIRMWARE_VER "SWOS v0.1.0"
+
 #define PIN_BUTTON_WHITE 0
 #define PIN_BUTTON_GREEN 10
 #define PIN_BUTTON_YELLOW 11
diff --git a/main/task_lcd.c b/main/task_lcd.c
new file mode 100644 (file)
index 0000000..ee5ca7b
--- /dev/null
@@ -0,0 +1,174 @@
+#include <time.h>
+
+#include "freertos/FreeRTOS.h"
+#include "driver/gpio.h"
+#include "driver/uart.h"
+
+#include "Goldelox_const4D.h"
+#include "goldeloxSerial.h"
+
+#include "task_lcd.h"
+#include "pins.h"
+
+const uart_port_t uart_num = UART_NUM_1;
+
+int write_tx(const void *data, size_t sz) {
+    return uart_write_bytes(uart_num, data, sz);
+}
+
+
+int read_rx(void *data, size_t sz, uint32_t wait_ms) {
+    if (sizeof(size_t) > sizeof(uint32_t) && sz > UINT32_MAX)
+        return -1;
+    return uart_read_bytes(uart_num, data, (uint32_t) sz,
+            (TickType_t) wait_ms / portTICK_PERIOD_MS);
+}
+
+
+int flush_rx() {
+    return (int) uart_flush(uart_num);
+}
+
+
+int flush_tx(uint32_t wait_ms) {
+    return (int) uart_wait_tx_done(uart_num,
+            (TickType_t) wait_ms / portTICK_PERIOD_MS);
+}
+
+
+void faster_baud() {
+    uart_config_t uart_config = {
+        .baud_rate = 600000,
+        .data_bits = UART_DATA_8_BITS,
+        .parity = UART_PARITY_DISABLE,
+        .stop_bits = UART_STOP_BITS_1,
+        .flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS,
+        .rx_flow_ctrl_thresh = 10,
+    };
+    // Configure UART parameters
+    ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
+}
+
+void lcd_task(void) {
+    // Setup UART buffered IO with event queue
+    const int uart_buffer_size = UART_HW_FIFO_LEN(uart_num) + 4;
+    QueueHandle_t uart_queue;
+
+    gl_serif_t serif_ulcd = {
+        .write_tx = write_tx,
+        .read_rx = read_rx,
+        .flush_rx = flush_rx,
+        .flush_tx = flush_tx
+    };
+
+    gl_display_t disp;
+
+    ESP_ERROR_CHECK(gpio_reset_pin(PIN_ULCD_RESET));
+    ESP_ERROR_CHECK(gpio_set_direction(PIN_ULCD_RESET, GPIO_MODE_OUTPUT));
+    ESP_ERROR_CHECK(gpio_set_drive_capability(PIN_ULCD_RESET, GPIO_DRIVE_CAP_1));
+
+    ESP_ERROR_CHECK(uart_driver_install(uart_num, uart_buffer_size, uart_buffer_size, 10, &uart_queue, 0));
+
+    uart_config_t uart_config = {
+        .baud_rate = 9600,
+        .data_bits = UART_DATA_8_BITS,
+        .parity = UART_PARITY_DISABLE,
+        .stop_bits = UART_STOP_BITS_1,
+        .flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS,
+        .rx_flow_ctrl_thresh = 10,
+    };
+    // Configure UART parameters
+    ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
+    // tx then rx
+    ESP_ERROR_CHECK(uart_set_pin(uart_num, PIN_ULCD_TX, PIN_ULCD_RX,
+                UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
+
+    ESP_ERROR_CHECK(gpio_set_level(PIN_ULCD_RESET, 0));
+    vTaskDelay(100 / portTICK_PERIOD_MS);
+    ESP_ERROR_CHECK(gpio_set_level(PIN_ULCD_RESET, 1));
+    printf("Hello world!\n");
+
+    gl_init(&disp, &serif_ulcd);
+
+    /* change baud rate */
+    gl_setbaudWait(&disp, BAUD_600000, &faster_baud);
+    lcd_boot_flash(&disp);
+    lcd_clock_loop(&disp);
+}
+
+
+void lcd_boot_flash(gl_display_t *disp) {
+    gl_gfx_BGcolour(disp, WHITE);
+    gl_gfx_Cls(disp);
+
+    /* draw straps */
+    for (uint8_t r = 0; r <= LCD_HEIGHT; r+= 5) {
+        gl_gfx_RectangleFilled(disp,
+                LCD_WIDTH / 2 - BOOT_STRAP_WIDTH / 2 - BOOT_CIRCL_OFFSET,
+                LCD_HEIGHT / 2 - r / 2,
+                LCD_WIDTH / 2 + BOOT_STRAP_WIDTH / 2 - BOOT_CIRCL_OFFSET,
+                LCD_HEIGHT / 2 + r / 2, BLACK);
+        vTaskDelay(pdMS_TO_TICKS(10));
+    }
+
+    /* circle grows */
+    for (uint8_t r = 1; r <= BOOT_CIRCL_RAD; r += 1) {
+        gl_gfx_CircleFilled(disp,
+                LCD_WIDTH / 2 - BOOT_CIRCL_OFFSET,
+                LCD_HEIGHT / 2 , r,
+                TOMATO);
+        vTaskDelay(pdMS_TO_TICKS(15));
+    }
+
+
+    gl_txt_FGcolour(disp, BLACK);
+    gl_txt_BGcolour(disp, WHITE);
+    gl_txt_MoveCursor(disp, 6, 10);
+    gl_putstr(disp, (uint8_t *) "SMART");
+    gl_txt_MoveCursor(disp, 7, 10);
+    gl_putstr(disp, (uint8_t *) "WATCH");
+    gl_txt_MoveCursor(disp, 8, 10);
+    gl_putstr(disp, (uint8_t *) "OS (v1)");
+    gl_txt_MoveCursor(disp, 10, 10);
+    gl_putstr(disp, (uint8_t *) "Anish &");
+    gl_txt_MoveCursor(disp, 11, 10);
+    gl_putstr(disp, (uint8_t *) "Advaith");
+    vTaskDelay(pdMS_TO_TICKS(2000));
+}
+
+
+void lcd_clock_loop(gl_display_t *disp) {
+    gl_txt_FGcolour(disp, GREEN);
+    gl_txt_BGcolour(disp, BLACK);
+    gl_txt_MoveCursor(disp, 0, 0);
+    gl_putstr(disp, (uint8_t *) "Debug Clock Mode");
+    while (1) {
+        time_t tm = time(NULL);
+        char txt[10];
+        snprintf(txt, 10, "%lld", (long long) tm);
+        gl_txt_MoveCursor(disp, 1, 0);
+        gl_putstr(disp, (uint8_t *) txt);
+        vTaskDelay(pdMS_TO_TICKS(1000));
+    }
+}
+
+
+void lcd_homepage_loop(gl_display_t *disp) {
+    gl_gfx_BGcolour(disp, BLACK);
+    gl_gfx_Cls(disp);
+
+    for (uint8_t i = 0; i < APPSCR_RCNUM; ++i) {
+        for (uint8_t j = 0; j < APPSCR_RCNUM; ++j) {
+            printf("adding %d, %d [%d|%d|%d|%d]\n",
+                    i + 1, j + 1,
+                    APPSCR_TOPCALCW(i + 1), APPSCR_TOPCALCH(j + 1),
+                    APPSCR_TOPCALCW(i + 1) + APPSCR_PADCALCW(0),
+                    APPSCR_TOPCALCH(j + 1) + APPSCR_PADCALCH(0));
+            gl_gfx_RectangleFilled(disp,
+                    APPSCR_TOPCALCW(i + 1), APPSCR_TOPCALCH(j + 1),
+                    APPSCR_TOPCALCW(i + 1) + APPSCR_PADCALCW(0),
+                    APPSCR_TOPCALCH(j + 1) + APPSCR_PADCALCH(0),
+                    WHITE);
+        }
+    }
+}
diff --git a/main/task_lcd.h b/main/task_lcd.h
new file mode 100644 (file)
index 0000000..f499af2
--- /dev/null
@@ -0,0 +1,45 @@
+/**
+ * @file task_lcd.h
+ * @brief Deals with LCD-related tasks
+ */
+#pragma once
+
+#ifndef __TASK_LCD_H__
+#define __TASK_LCD_H__
+
+#include <stdint.h>
+
+#include "Goldelox_Types4D.h"
+
+#define LCD_WIDTH 128
+#define LCD_HEIGHT 128
+
+#define BOOT_CIRCL_RAD 30
+#define BOOT_STRAP_WIDTH 30
+#define BOOT_CIRCL_OFFSET 30
+
+#define APPSCR_PAD 5
+#define APPSCR_RCNUM 4 
+#define APPSCR_PADCALCW(x) (LCD_WIDTH - (APPSCR_RCNUM  * APPSCR_PAD)) \
+    / APPSCR_RCNUM + ((x) * APPSCR_PAD)
+#define APPSCR_PADCALCH(x) (LCD_HEIGHT - (APPSCR_RCNUM  * APPSCR_PAD)) \
+    / APPSCR_RCNUM + ((x) * APPSCR_PAD)
+#define APPSCR_TOPCALCW(x) ((x) * APPSCR_PAD) + (((x) - 1) * APPSCR_PADCALCW(0))
+#define APPSCR_TOPCALCH(x) ((x) * APPSCR_PAD) + (((x) - 1) * APPSCR_PADCALCH(0))
+
+typedef struct {
+    uint8_t width;
+    uint8_t height;
+    uint16_t *data;
+} lcd_icon_t;
+
+
+void lcd_homepage_loop(gl_display_t *);
+
+void lcd_clock_loop(gl_display_t *);
+
+void lcd_boot_flash(gl_display_t *);
+
+void lcd_task(void);
+
+#endif