Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement LVGL 8.4 #434

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,48 @@
"array": "c",
"string": "c",
"string_view": "c",
"*.tcc": "c"
"*.tcc": "c",
"esp_lvgl_port.h": "c",
"cstdint": "c",
"regex": "c",
"i2c_bitaxe.h": "c",
"i2c_master.h": "c",
"nvs_config.h": "c",
"display.h": "c",
"esp_lcd_panel_vendor.h": "c",
"esp_lcd_panel_st7789.h": "c",
"esp_lcd_panel_ssd1306.h": "c",
"esp_lcd_panel_io.h": "c",
"esp_lcd_panel_ops.h": "c",
"esp_lcd_io_i2c.h": "c",
"esp_lcd_types.h": "c",
"i2c.h": "c",
"cstdlib": "c",
"i2c_types.h": "c",
"esp_lcd_panel_dev.h": "c",
"bitset": "c",
"memory": "c",
"random": "c",
"future": "c",
"optional": "c",
"esp_lcd_panel_interface.h": "c",
"span": "c",
"oled.h": "c",
"charconv": "c",
"chrono": "c",
"format": "c",
"ratio": "c",
"system_error": "c",
"functional": "c",
"tuple": "c",
"type_traits": "c",
"utility": "c",
"compare": "c"
},
"editor.formatOnSave": false,
"cSpell.words": [
"ssid"
],
"idf.port": "/dev/cu.usbmodem1434301",
"idf.port": "/dev/ttyACM0",
"C_Cpp.intelliSenseEngine": "Tag Parser"
}
5 changes: 3 additions & 2 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ SRCS
"adc.c"
"DS4432U.c"
"EMC2101.c"
"fonts.c"
"i2c_bitaxe.c"
"INA260.c"
"led_controller.c"
"main.c"
"nvs_config.c"
"oled.c"
"display.c"
"system.c"
"TPS546.c"
"vcore.c"
"work_queue.c"
"nvs_device.c"
"lv_font_portfolio-6x8.c"
"logo.c"
"./http_server/http_server.c"
"./self_test/self_test.c"
"./tasks/stratum_task.c"
Expand Down
157 changes: 157 additions & 0 deletions main/display.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_timer.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_ops.h"
#include "esp_err.h"
#include "esp_log.h"
#include "lvgl.h"
#include "esp_lvgl_port.h"
#include "nvs_config.h"
#include "i2c_bitaxe.h"
#include "driver/i2c_master.h"
#include "driver/i2c_types.h"
#include "esp_lcd_panel_ssd1306.h"

#define SSD1306_I2C_ADDRESS 0x3C

#define LCD_H_RES 128
#define LCD_V_RES 32
#define LCD_CMD_BITS 8
#define LCD_PARAM_BITS 8

static bool is_display_active = false;

static const char * TAG = "display";

static lv_style_t style;
extern const lv_font_t lv_font_portfolio_6x8;
extern const lv_img_dsc_t logo;

esp_err_t display_init(void)
{
uint8_t flip_screen = nvs_config_get_u16(NVS_CONFIG_FLIP_SCREEN, 1);
uint8_t invert_screen = nvs_config_get_u16(NVS_CONFIG_INVERT_SCREEN, 0);

i2c_master_bus_handle_t i2c_master_bus_handle;
ESP_ERROR_CHECK(i2c_bitaxe_get_master_bus_handle(&i2c_master_bus_handle));

ESP_LOGI(TAG, "Install panel IO");
esp_lcd_panel_io_handle_t io_handle = NULL;
esp_lcd_panel_io_i2c_config_t io_config = {
.scl_speed_hz = I2C_BUS_SPEED_HZ,
.dev_addr = SSD1306_I2C_ADDRESS,
.control_phase_bytes = 1,
.lcd_cmd_bits = LCD_CMD_BITS,
.lcd_param_bits = LCD_PARAM_BITS,
.dc_bit_offset = 6
};

ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(i2c_master_bus_handle, &io_config, &io_handle));

ESP_LOGI(TAG, "Install SSD1306 panel driver");
esp_lcd_panel_handle_t panel_handle = NULL;
esp_lcd_panel_dev_config_t panel_config = {
.bits_per_pixel = 1,
.reset_gpio_num = -1,
.color_space = ESP_LCD_COLOR_SPACE_MONOCHROME,
};

esp_lcd_panel_ssd1306_config_t ssd1306_config = {
.height = LCD_V_RES,
};
panel_config.vendor_config = &ssd1306_config;

ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(io_handle, &panel_config, &panel_handle));

ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
// ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, false, false));
ESP_ERROR_CHECK(esp_lcd_panel_invert_color(panel_handle, invert_screen));

ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));

ESP_LOGI(TAG, "Initialize LVGL");
const lvgl_port_cfg_t lvgl_cfg = ESP_LVGL_PORT_INIT_CONFIG();
lvgl_port_init(&lvgl_cfg);

const lvgl_port_display_cfg_t disp_cfg = {
.io_handle = io_handle,
.panel_handle = panel_handle,
.buffer_size = LCD_H_RES * LCD_V_RES,
.double_buffer = true,
.hres = LCD_H_RES,
.vres = LCD_V_RES,
.monochrome = true,
.rotation = {
.swap_xy = false,
.mirror_x = !flip_screen, // The screen is not flipped, this is for backwards compatibility
.mirror_y = !flip_screen,
},
};
lvgl_port_add_disp(&disp_cfg);

lv_style_init(&style);
lv_style_set_text_font(&style, &lv_font_portfolio_6x8);

is_display_active = true;

return ESP_OK;
}

bool display_active(void)
{
return is_display_active;
}

void display_clear()
{
if (lvgl_port_lock(0)) {
lv_obj_t *scr = lv_scr_act();
lv_obj_clean(scr);
lvgl_port_unlock();
}
}

void display_show_status(const char *messages[], size_t message_count)
{
if (lvgl_port_lock(0)) {
lv_obj_t *scr = lv_scr_act();
lv_obj_clean(scr);

lv_obj_t *container = lv_obj_create(scr);
lv_obj_set_size(container, LCD_H_RES, LCD_V_RES);
lv_obj_align(container, LV_ALIGN_CENTER, 0, 0);

lv_obj_set_flex_flow(container, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(container, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);

for (int i = 0; i < message_count; i++)
{
lv_obj_t *label = lv_label_create(container);
lv_label_set_text(label, messages[i]);
lv_obj_add_style(label, &style, LV_PART_MAIN);
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_obj_set_width(label, LCD_H_RES);
}

lvgl_port_unlock();
}
}

void display_show_logo()
{
if (lvgl_port_lock(0)) {
lv_obj_t *scr = lv_scr_act();
lv_obj_clean(scr);

lv_obj_t *img = lv_img_create(scr);

lv_img_set_src(img, &logo);

lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);

lvgl_port_unlock();
}
}
10 changes: 10 additions & 0 deletions main/display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef DISPLAY_H_
#define DISPLAY_H_

esp_err_t display_init(void);
bool display_active(void);
void display_clear();
void display_show_status(const char *messages[], size_t message_count);
void display_show_logo();

#endif /* DISPLAY_H_ */
50 changes: 0 additions & 50 deletions main/fonts.c

This file was deleted.

1 change: 0 additions & 1 deletion main/global_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ typedef struct
uint64_t shares_accepted;
uint64_t shares_rejected;
int screen_page;
char oled_buf[20];
uint64_t best_nonce_diff;
char best_diff_string[DIFF_STRING_SIZE];
uint64_t best_session_nonce_diff;
Expand Down
9 changes: 7 additions & 2 deletions main/i2c_bitaxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#define I2C_MASTER_SCL_IO 48 /*!< GPIO number used for I2C master clock */
#define I2C_MASTER_SDA_IO 47 /*!< GPIO number used for I2C master data */
#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */

#define I2C_MASTER_NUM 0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
#define I2C_MASTER_TIMEOUT_MS 1000
Expand Down Expand Up @@ -41,12 +40,18 @@ esp_err_t i2c_bitaxe_add_device(uint8_t device_address, i2c_master_dev_handle_t
i2c_device_config_t dev_cfg = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = device_address,
.scl_speed_hz = I2C_MASTER_FREQ_HZ,
.scl_speed_hz = I2C_BUS_SPEED_HZ,
};

return i2c_master_bus_add_device(i2c_bus_handle, &dev_cfg, dev_handle);
}

esp_err_t i2c_bitaxe_get_master_bus_handle(i2c_master_bus_handle_t * dev_handle)
{
*dev_handle = i2c_bus_handle;
return ESP_OK;
}

/**
* @brief Read a sequence of I2C bytes
* @param dev_handle The I2C device handle
Expand Down
5 changes: 3 additions & 2 deletions main/i2c_bitaxe.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#define I2C_MASTER_H_

#include "driver/i2c_master.h"
//#include "driver/i2c.h"

#define I2C_BUS_SPEED_HZ 100000 /*!< I2C master clock frequency */

esp_err_t i2c_bitaxe_init(void);
esp_err_t i2c_bitaxe_add_device(uint8_t device_address, i2c_master_dev_handle_t * dev_handle);

esp_err_t i2c_bitaxe_get_master_bus_handle(i2c_master_bus_handle_t * dev_handle);

esp_err_t i2c_bitaxe_register_read(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint8_t * read_buf, size_t len);
esp_err_t i2c_bitaxe_register_write_byte(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint8_t data);
Expand Down
10 changes: 10 additions & 0 deletions main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## IDF Component Manager Manifest File
dependencies:
espressif/esp_lvgl_port: "=2.4.1"
## LVGL 9 is blocked by https://github.com/espressif/esp-idf/issues/14784
lvgl/lvgl:
version: "^8"
public: true
## Required IDF version
idf:
version: ">=5.2.0"
Loading