Skip to content

Commit 9a3d37b

Browse files
authored
[BREAKING] Update espp for LVGL v9 and refactor some components (#87)
* 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
1 parent 1aac948 commit 9a3d37b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1623
-913
lines changed

components/box-emu/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ idf_component_register(
1818
"button"
1919
"display"
2020
"display_drivers"
21+
"drv2605"
2122
"mcp23x17"
2223
"input_drivers"
2324
"tt21100"

components/box-emu/include/box-emu.hpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "aw9523.hpp"
2323
#include "base_component.hpp"
2424
#include "button.hpp"
25+
#include "drv2605.hpp"
2526
#include "events.hpp"
2627
#include "high_resolution_timer.hpp"
2728
#include "keypad_input.hpp"
@@ -36,6 +37,8 @@
3637
#include "gamepad_state.hpp"
3738
#include "video_setting.hpp"
3839

40+
#include "make_color.h"
41+
3942
class BoxEmu : public espp::BaseComponent {
4043
public:
4144
/// The Version of the BoxEmu
@@ -59,10 +62,6 @@ class BoxEmu : public espp::BaseComponent {
5962

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

62-
static uint16_t make_color(uint8_t r, uint8_t g, uint8_t b) {
63-
return lv_color_make(r,g,b).full;
64-
}
65-
6665
/// Get the version of the BoxEmu that was detected
6766
/// \return The version of the BoxEmu that was detected
6867
/// \see Version
@@ -129,6 +128,16 @@ class BoxEmu : public espp::BaseComponent {
129128
VideoSetting video_setting() const;
130129
void video_setting(const VideoSetting setting);
131130

131+
/////////////////////////////////////////////////////////////////////////////
132+
// Haptic Motor (DRV2605)
133+
/////////////////////////////////////////////////////////////////////////////
134+
135+
bool initialize_haptics();
136+
std::shared_ptr<espp::Drv2605> haptics() const;
137+
void play_haptic_effect();
138+
void play_haptic_effect(int effect);
139+
void set_haptic_effect(int effect);
140+
132141
/////////////////////////////////////////////////////////////////////////////
133142
// USB
134143
/////////////////////////////////////////////////////////////////////////////
@@ -319,6 +328,9 @@ class BoxEmu : public espp::BaseComponent {
319328
const uint16_t* palette_{nullptr};
320329
size_t palette_size_{256};
321330

331+
// haptics
332+
std::shared_ptr<espp::Drv2605> haptic_motor_{nullptr};
333+
322334
// usb
323335
std::atomic<bool> usb_enabled_{false};
324336
usb_phy_handle_t jtag_phy_;

components/box-emu/src/box-emu.cpp

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,15 @@ bool BoxEmu::initialize_box() {
5050
return false;
5151
}
5252
static constexpr size_t pixel_buffer_size = espp::EspBox::lcd_width() * num_rows_in_framebuffer;
53+
static constexpr int update_period_ms = 16;
54+
espp::Task::BaseConfig display_task_config = {
55+
.name = "Display",
56+
.stack_size_bytes = 6 * 1024,
57+
.priority = 10,
58+
.core_id = 1,
59+
};
5360
// initialize the LVGL display for the esp-box
54-
if (!box.initialize_display(pixel_buffer_size)) {
61+
if (!box.initialize_display(pixel_buffer_size, display_task_config, update_period_ms)) {
5562
logger_.error("Failed to initialize display!");
5663
return false;
5764
}
@@ -496,6 +503,67 @@ void BoxEmu::video_setting(const VideoSetting setting) {
496503
video_setting_ = setting;
497504
}
498505

506+
/////////////////////////////////////////////////////////////////////////////
507+
// Haptic Motor
508+
/////////////////////////////////////////////////////////////////////////////
509+
510+
bool BoxEmu::initialize_haptics() {
511+
if (haptic_motor_) {
512+
logger_.error("Haptics already initialized!");
513+
return false;
514+
}
515+
logger_.info("Initializing haptics");
516+
haptic_motor_ = std::make_shared<espp::Drv2605>(espp::Drv2605::Config{
517+
.device_address = espp::Drv2605::DEFAULT_ADDRESS,
518+
.write = std::bind(&espp::I2c::write, &external_i2c_, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3),
519+
.read_register = std::bind(&espp::I2c::read_at_register, &external_i2c_, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4),
520+
.motor_type = espp::Drv2605::MotorType::LRA
521+
});
522+
// we're using an LRA motor, so select th LRA library.
523+
std::error_code ec;
524+
haptic_motor_->select_library(espp::Drv2605::Library::LRA, ec);
525+
if (ec) {
526+
logger_.error("Error selecting LRA library: {}", ec.message());
527+
return false;
528+
}
529+
return true;
530+
}
531+
532+
std::shared_ptr<espp::Drv2605> BoxEmu::haptics() const {
533+
return haptic_motor_;
534+
}
535+
536+
void BoxEmu::play_haptic_effect() {
537+
if (haptic_motor_ == nullptr) {
538+
logger_.error("Haptic motor not initialized!");
539+
return;
540+
}
541+
std::error_code ec;
542+
haptic_motor_->start(ec);
543+
if (ec) {
544+
logger_.error("Error starting haptic motor: {}", ec.message());
545+
}
546+
}
547+
548+
void BoxEmu::play_haptic_effect(int effect) {
549+
if (haptic_motor_ == nullptr) {
550+
logger_.error("Haptic motor not initialized!");
551+
return;
552+
}
553+
set_haptic_effect(effect);
554+
play_haptic_effect();
555+
}
556+
557+
void BoxEmu::set_haptic_effect(int effect) {
558+
if (haptic_motor_ == nullptr) {
559+
logger_.error("Haptic motor not initialized!");
560+
return;
561+
}
562+
std::error_code ec;
563+
haptic_motor_->set_waveform(0, (espp::Drv2605::Waveform)(effect), ec);
564+
haptic_motor_->set_waveform(1, espp::Drv2605::Waveform::END, ec);
565+
}
566+
499567
/////////////////////////////////////////////////////////////////////////////
500568
// USB
501569
/////////////////////////////////////////////////////////////////////////////

components/box-emu/src/make_color.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#include <lvgl/lvgl.h>
44

55
extern "C" uint16_t make_color(uint8_t r, uint8_t g, uint8_t b) {
6-
return lv_color_make(r,g,b).full;
6+
return lv_color_to_u16(lv_color_make(r, g, b));
77
}

components/espp

Submodule espp updated 144 files

components/genesis/gwenesis/src/vdp/gwenesis_vdp_mem.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ __license__ = "GPLv3"
3636
#define VDP_MEM_DISABLE_LOGGING 1
3737

3838
static inline uint16_t to_pixel(uint16_t value) {
39+
// convert rgb 444 to bgr 565
3940
return
40-
((value & 0xe00) << 1) |
41-
((value & 0x0e0) >> 5) |
42-
((value & 0x00e) << 4);
41+
((value & 0xe00)) >> 7 | // red
42+
((value & 0x0e0)) << 3 | // green
43+
((value & 0x00e)) << 12; // blue
44+
// was:
45+
/* return */
46+
/* ((value & 0xe00) << 1) | */
47+
/* ((value & 0x0e0) >> 5) | */
48+
/* ((value & 0x00e) << 4); */
4349
}
4450

4551
#if !VDP_MEM_DISABLE_LOGGING

components/gui/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
idf_component_register(
2-
SRC_DIRS "src" "generated" "generated/screens" "generated/components"
32
INCLUDE_DIRS "include"
43
PRIV_INCLUDE_DIRS "generated"
5-
REQUIRES lvgl task display logger jpeg rom_info box-emu)
4+
SRC_DIRS "src" "generated" "generated/screens" "generated/components" "generated/images"
5+
REQUIRES lvgl timer display logger jpeg rom_info box-emu)

components/gui/generated/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ SET(SOURCES screens/ui_romscreen.c
33
ui.c
44
components/ui_comp_hook.c
55
ui_helpers.c
6-
ui_events.c)
6+
ui_temporary_image.c)
77

88
add_library(ui ${SOURCES})

components/gui/generated/filelist.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ screens/ui_settingsscreen.c
33
ui.c
44
components/ui_comp_hook.c
55
ui_helpers.c
6-
ui_events.c
6+
ui_temporary_image.c

0 commit comments

Comments
 (0)