33#include "esp_system.h"
44#include "driver/spi_master.h"
55#include "driver/gpio.h"
6+ #include "freertos/FreeRTOS.h"
7+ #include "freertos/task.h"
68
79
810#define LCD_HOST HSPI_HOST
@@ -508,3 +510,74 @@ uint8_t* get_font8x8_char(char chr) {
508510 return font8x8 + idx * 8 ;
509511}
510512
513+ void display_reset () {
514+ gpio_set_level (PIN_NUM_BCKL , 0 );
515+ gpio_set_level (PIN_NUM_RST , 0 );
516+ vTaskDelay (50 / portTICK_PERIOD_MS );
517+ gpio_set_level (PIN_NUM_RST , 1 );
518+ vTaskDelay (50 / portTICK_PERIOD_MS );
519+ }
520+
521+ void display_init () {
522+ spi_init ();
523+ gpio_init ();
524+ display_reset ();
525+ int cmd = 0 ;
526+ //Send all the commands
527+ while (init_cmds [cmd ].databytes != 0xff ) {
528+ spi_write_cmd (init_cmds [cmd ].cmd );
529+ spi_write_data (init_cmds [cmd ].data , init_cmds [cmd ].databytes & 0x1F );
530+ if (init_cmds [cmd ].databytes & 0x80 ) {
531+ vTaskDelay (100 / portTICK_PERIOD_MS );
532+ }
533+ cmd ++ ;
534+ }
535+
536+ spi_write_cmd (MADCTL );
537+ uint8_t data [16 ] = {0x08 };
538+ spi_write_data (data , 1 & 0x1F );
539+ spi_write_cmd (DISPLAY_INVERSION_ON );
540+ spi_write_cmd (WAKE );
541+ vTaskDelay (120 / portTICK_PERIOD_MS );
542+ spi_write_cmd (DISPLAY_ON );
543+ gpio_set_level (PIN_NUM_BCKL , 1 );
544+ }
545+
546+ uint16_t display_color (int32_t r , int32_t g , int32_t b ) {
547+ uint16_t color = 0 ;
548+ color |= ((r >> 3 ) << 11 );
549+ color |= ((g >> 2 ) << 5 );
550+ color |= ((b >> 3 ) << 0 );
551+ color = (color >> 8 ) | (color << 8 ); // big-endian
552+ return color ;
553+ }
554+
555+ void display_fill (uint16_t color ) {
556+ display_draw (fill , color , color );
557+ }
558+
559+ void display_show_heart_icon (uint16_t color , uint16_t background ) {
560+ display_draw (heart , color , background );
561+ }
562+
563+ void display_show_small_heart_icon (uint16_t color , uint16_t background ) {
564+ display_draw (small_heart , color , background );
565+ }
566+
567+ void display_show_happy_face_icon (uint16_t color , uint16_t background ) {
568+ display_draw (happy_face , color , background );
569+ }
570+
571+ void display_show_sad_face_icon (uint16_t color , uint16_t background ) {
572+ display_draw (sad_face , color , background );
573+ }
574+
575+ void display_show_string (char * str , uint16_t color , uint16_t background ) {
576+ display_text (str , color , background );
577+ }
578+
579+ void display_show_integer (int32_t integer , uint16_t color , uint16_t background ) {
580+ char buff [12 ]; // Max num length + blank
581+ sprintf (buff , "%ld" , integer );
582+ display_text (& buff , color , background );
583+ }
0 commit comments