#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));
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);
--- /dev/null
+#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);
+ }
+ }
+}