Skip to content

Commit

Permalink
[BREAKING] Update espp for LVGL v9 and refactor some components (#87)
Browse files Browse the repository at this point in the history
* chore: Update to LVGL v9

* wip trying to get it working...

* update espp to latest main

* update espp submodule

* update to latest espp

* move haptics into box-emu component

* wip guis

* update color format

* fix sms color

* added log about how many were loaded

* update menu task management

* update gui to use HRT for task and have roller use quick animation

* update to use latest apis - use new haptics apis and such

* decrease default transition time and refresh period, add 80mhz flash freq

* decrease lvgl memory from 60k to 40k

* minor update

* update styling and handle case that there is no gamepad

* dont fail out of main if no haptics

* update espp with latest apis for esp-box, display drivers fixes, and update box-emu accordingly

* update lvgl memory after finding failure at 40k with selector in menu
  • Loading branch information
finger563 committed Aug 23, 2024
1 parent 1aac948 commit 9a3d37b
Show file tree
Hide file tree
Showing 46 changed files with 1,623 additions and 913 deletions.
1 change: 1 addition & 0 deletions components/box-emu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ idf_component_register(
"button"
"display"
"display_drivers"
"drv2605"
"mcp23x17"
"input_drivers"
"tt21100"
Expand Down
20 changes: 16 additions & 4 deletions components/box-emu/include/box-emu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "aw9523.hpp"
#include "base_component.hpp"
#include "button.hpp"
#include "drv2605.hpp"
#include "events.hpp"
#include "high_resolution_timer.hpp"
#include "keypad_input.hpp"
Expand All @@ -36,6 +37,8 @@
#include "gamepad_state.hpp"
#include "video_setting.hpp"

#include "make_color.h"

class BoxEmu : public espp::BaseComponent {
public:
/// The Version of the BoxEmu
Expand All @@ -59,10 +62,6 @@ class BoxEmu : public espp::BaseComponent {

static constexpr char mount_point[] = "/sdcard";

static uint16_t make_color(uint8_t r, uint8_t g, uint8_t b) {
return lv_color_make(r,g,b).full;
}

/// Get the version of the BoxEmu that was detected
/// \return The version of the BoxEmu that was detected
/// \see Version
Expand Down Expand Up @@ -129,6 +128,16 @@ class BoxEmu : public espp::BaseComponent {
VideoSetting video_setting() const;
void video_setting(const VideoSetting setting);

/////////////////////////////////////////////////////////////////////////////
// Haptic Motor (DRV2605)
/////////////////////////////////////////////////////////////////////////////

bool initialize_haptics();
std::shared_ptr<espp::Drv2605> haptics() const;
void play_haptic_effect();
void play_haptic_effect(int effect);
void set_haptic_effect(int effect);

/////////////////////////////////////////////////////////////////////////////
// USB
/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -319,6 +328,9 @@ class BoxEmu : public espp::BaseComponent {
const uint16_t* palette_{nullptr};
size_t palette_size_{256};

// haptics
std::shared_ptr<espp::Drv2605> haptic_motor_{nullptr};

// usb
std::atomic<bool> usb_enabled_{false};
usb_phy_handle_t jtag_phy_;
Expand Down
70 changes: 69 additions & 1 deletion components/box-emu/src/box-emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ bool BoxEmu::initialize_box() {
return false;
}
static constexpr size_t pixel_buffer_size = espp::EspBox::lcd_width() * num_rows_in_framebuffer;
static constexpr int update_period_ms = 16;
espp::Task::BaseConfig display_task_config = {
.name = "Display",
.stack_size_bytes = 6 * 1024,
.priority = 10,
.core_id = 1,
};
// initialize the LVGL display for the esp-box
if (!box.initialize_display(pixel_buffer_size)) {
if (!box.initialize_display(pixel_buffer_size, display_task_config, update_period_ms)) {
logger_.error("Failed to initialize display!");
return false;
}
Expand Down Expand Up @@ -496,6 +503,67 @@ void BoxEmu::video_setting(const VideoSetting setting) {
video_setting_ = setting;
}

/////////////////////////////////////////////////////////////////////////////
// Haptic Motor
/////////////////////////////////////////////////////////////////////////////

bool BoxEmu::initialize_haptics() {
if (haptic_motor_) {
logger_.error("Haptics already initialized!");
return false;
}
logger_.info("Initializing haptics");
haptic_motor_ = std::make_shared<espp::Drv2605>(espp::Drv2605::Config{
.device_address = espp::Drv2605::DEFAULT_ADDRESS,
.write = std::bind(&espp::I2c::write, &external_i2c_, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3),
.read_register = std::bind(&espp::I2c::read_at_register, &external_i2c_, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4),
.motor_type = espp::Drv2605::MotorType::LRA
});
// we're using an LRA motor, so select th LRA library.
std::error_code ec;
haptic_motor_->select_library(espp::Drv2605::Library::LRA, ec);
if (ec) {
logger_.error("Error selecting LRA library: {}", ec.message());
return false;
}
return true;
}

std::shared_ptr<espp::Drv2605> BoxEmu::haptics() const {
return haptic_motor_;
}

void BoxEmu::play_haptic_effect() {
if (haptic_motor_ == nullptr) {
logger_.error("Haptic motor not initialized!");
return;
}
std::error_code ec;
haptic_motor_->start(ec);
if (ec) {
logger_.error("Error starting haptic motor: {}", ec.message());
}
}

void BoxEmu::play_haptic_effect(int effect) {
if (haptic_motor_ == nullptr) {
logger_.error("Haptic motor not initialized!");
return;
}
set_haptic_effect(effect);
play_haptic_effect();
}

void BoxEmu::set_haptic_effect(int effect) {
if (haptic_motor_ == nullptr) {
logger_.error("Haptic motor not initialized!");
return;
}
std::error_code ec;
haptic_motor_->set_waveform(0, (espp::Drv2605::Waveform)(effect), ec);
haptic_motor_->set_waveform(1, espp::Drv2605::Waveform::END, ec);
}

/////////////////////////////////////////////////////////////////////////////
// USB
/////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion components/box-emu/src/make_color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#include <lvgl/lvgl.h>

extern "C" uint16_t make_color(uint8_t r, uint8_t g, uint8_t b) {
return lv_color_make(r,g,b).full;
return lv_color_to_u16(lv_color_make(r, g, b));
}
2 changes: 1 addition & 1 deletion components/espp
Submodule espp updated 144 files
12 changes: 9 additions & 3 deletions components/genesis/gwenesis/src/vdp/gwenesis_vdp_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ __license__ = "GPLv3"
#define VDP_MEM_DISABLE_LOGGING 1

static inline uint16_t to_pixel(uint16_t value) {
// convert rgb 444 to bgr 565
return
((value & 0xe00) << 1) |
((value & 0x0e0) >> 5) |
((value & 0x00e) << 4);
((value & 0xe00)) >> 7 | // red
((value & 0x0e0)) << 3 | // green
((value & 0x00e)) << 12; // blue
// was:
/* return */
/* ((value & 0xe00) << 1) | */
/* ((value & 0x0e0) >> 5) | */
/* ((value & 0x00e) << 4); */
}

#if !VDP_MEM_DISABLE_LOGGING
Expand Down
4 changes: 2 additions & 2 deletions components/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "src" "generated" "generated/screens" "generated/components"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "generated"
REQUIRES lvgl task display logger jpeg rom_info box-emu)
SRC_DIRS "src" "generated" "generated/screens" "generated/components" "generated/images"
REQUIRES lvgl timer display logger jpeg rom_info box-emu)
2 changes: 1 addition & 1 deletion components/gui/generated/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ SET(SOURCES screens/ui_romscreen.c
ui.c
components/ui_comp_hook.c
ui_helpers.c
ui_events.c)
ui_temporary_image.c)

add_library(ui ${SOURCES})
2 changes: 1 addition & 1 deletion components/gui/generated/filelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ screens/ui_settingsscreen.c
ui.c
components/ui_comp_hook.c
ui_helpers.c
ui_events.c
ui_temporary_image.c
Loading

0 comments on commit 9a3d37b

Please sign in to comment.