Skip to content

Commit

Permalink
fix(display_drivers): fix inline declaration for swap_xy and mutex (#295
Browse files Browse the repository at this point in the history
)
  • Loading branch information
finger563 authored Jul 29, 2024
1 parent 702b96c commit b8fb0b8
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 46 deletions.
47 changes: 25 additions & 22 deletions components/display/include/display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

namespace espp {

/**
* @brief Possible orientations of the display.
*/
enum class DisplayRotation : uint8_t { LANDSCAPE, PORTRAIT, LANDSCAPE_INVERTED, PORTRAIT_INVERTED };
/**
* @brief Possible orientations of the display.
*/
enum class DisplayRotation : uint8_t { LANDSCAPE, PORTRAIT, LANDSCAPE_INVERTED, PORTRAIT_INVERTED };

/**
* @brief Signals used by LVGL to let the post_transfer_callback know
* whether or not to call lv_disp_flush_ready.
*/
enum class DisplaySignal : uint32_t { NONE, FLUSH };
/**
* @brief Signals used by LVGL to let the post_transfer_callback know
* whether or not to call lv_disp_flush_ready.
*/
enum class DisplaySignal : uint32_t { NONE, FLUSH };

/**
* @brief Wrapper class around LVGL display buffer and display driver.
Expand All @@ -36,8 +36,8 @@ namespace espp {
* For more information, see
* https://docs.lvgl.io/9.1/porting/display.html#display-interface
*
* @tparam Pixel The pixel format to be used for the display. This allows the class to be used with displays
* of different color depths and formats.
* @tparam Pixel The pixel format to be used for the display. This allows the class to be used with
* displays of different color depths and formats.
*/
template <typename Pixel> class Display : public BaseComponent {
public:
Expand All @@ -61,7 +61,8 @@ template <typename Pixel> class Display : public BaseComponent {
size_t height; /**< Height of the display, in pixels. */
size_t pixel_buffer_size; /**< Size of the display buffer in pixels. */
flush_fn flush_callback; /**< Function provided to LVGL for it to flush data to the display. */
rotation_fn rotation_callback{nullptr}; /**< Function used to configure display with new rotation setting. */
rotation_fn rotation_callback{
nullptr}; /**< Function used to configure display with new rotation setting. */
gpio_num_t backlight_pin; /**< GPIO pin for the backlight. */
bool backlight_on_value{
true}; /**< Value to write to the backlight pin to turn the backlight on. */
Expand All @@ -76,7 +77,8 @@ template <typename Pixel> class Display : public BaseComponent {
uint32_t allocation_flags{
MALLOC_CAP_8BIT |
MALLOC_CAP_DMA}; /**< For configuring how the display buffer is allocated*/
DisplayRotation rotation{DisplayRotation::LANDSCAPE}; /**< Default / Initial rotation of the display. */
DisplayRotation rotation{
DisplayRotation::LANDSCAPE}; /**< Default / Initial rotation of the display. */
bool software_rotation_enabled{
true}; /**< Enable LVGL software display rotation, incurs additional overhead. */
Logger::Verbosity log_level{Logger::Verbosity::WARN}; /**< Verbosity for the Display logger_. */
Expand All @@ -94,7 +96,8 @@ template <typename Pixel> class Display : public BaseComponent {
size_t height; /**< Height of the display, in pixels. */
size_t pixel_buffer_size; /**< Size of the display buffer in pixels. */
flush_fn flush_callback; /**< Function provided to LVGL for it to flush data to the display. */
rotation_fn rotation_callback{nullptr}; /**< Function used to configure display with new rotation setting. */
rotation_fn rotation_callback{
nullptr}; /**< Function used to configure display with new rotation setting. */
gpio_num_t backlight_pin; /**< GPIO pin for the backlight. */
bool backlight_on_value{
true}; /**< Value to write to the backlight pin to turn the backlight on. */
Expand All @@ -103,8 +106,9 @@ template <typename Pixel> class Display : public BaseComponent {
.priority = 20,
.core_id = 0}; /**< Task configuration. */
std::chrono::duration<float> update_period{
0.01}; /**< How frequently to run the update function. */
DisplayRotation rotation{DisplayRotation::LANDSCAPE}; /**< Default / Initial rotation of the display. */
0.01}; /**< How frequently to run the update function. */
DisplayRotation rotation{
DisplayRotation::LANDSCAPE}; /**< Default / Initial rotation of the display. */
bool software_rotation_enabled{
true}; /**< Enable LVGL software display rotation, incurs additional overhead. */
Logger::Verbosity log_level{Logger::Verbosity::WARN}; /**< Verbosity for the Display logger_. */
Expand Down Expand Up @@ -140,8 +144,7 @@ template <typename Pixel> class Display : public BaseComponent {
assert(vram_1_ != NULL);
}
created_vram_ = true;
init(config.flush_callback, config.rotation_callback, config.rotation,
config.task_config);
init(config.flush_callback, config.rotation_callback, config.rotation, config.task_config);
set_brightness(1.0f);
}

Expand All @@ -168,8 +171,7 @@ template <typename Pixel> class Display : public BaseComponent {
.duty_resolution = LEDC_TIMER_10_BIT})
, update_period_(config.update_period) {
logger_.debug("Initializing with non-allocating config!");
init(config.flush_callback, config.rotation_callback, config.rotation,
config.task_config);
init(config.flush_callback, config.rotation_callback, config.rotation, config.task_config);
}

/**
Expand Down Expand Up @@ -271,7 +273,7 @@ template <typename Pixel> class Display : public BaseComponent {
* @brief LVGL event handler.
*/
static void event_cb(lv_event_t *event) {
if(event->code == LV_EVENT_RESOLUTION_CHANGED) {
if (event->code == LV_EVENT_RESOLUTION_CHANGED) {
auto rotation = lv_display_get_rotation(lv_display_get_default());
auto rotation_callback = reinterpret_cast<rotation_fn>(lv_event_get_user_data(event));
if (rotation_callback != nullptr) {
Expand All @@ -289,7 +291,8 @@ template <typename Pixel> class Display : public BaseComponent {
* @param rotation Default / initial rotation of the display.
* @param task_config Configuration for the task that runs the lvgl tick
*/
void init(flush_fn flush_callback, rotation_fn rotation_callback, DisplayRotation rotation, const Task::BaseConfig &task_config) {
void init(flush_fn flush_callback, rotation_fn rotation_callback, DisplayRotation rotation,
const Task::BaseConfig &task_config) {
lv_init();

display_ = lv_display_create(width_, height_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ void IRAM_ATTR lcd_send_lines(int xs, int ys, int xe, int ye, const uint8_t *dat
trans[0].tx_data[0] = (uint8_t)espp::Gc9a01::Command::caset;
#endif
trans[1].tx_data[0] = (xs) >> 8;
trans[1].tx_data[1] = (xs) & 0xff;
trans[1].tx_data[1] = (xs)&0xff;
trans[1].tx_data[2] = (xe) >> 8;
trans[1].tx_data[3] = (xe) & 0xff;
trans[1].tx_data[3] = (xe)&0xff;
#if CONFIG_HARDWARE_WROVER_KIT
trans[2].tx_data[0] = (uint8_t)espp::Ili9341::Command::raset;
#elif CONFIG_HARDWARE_TTGO || CONFIG_HARDWARE_BOX
Expand All @@ -142,9 +142,9 @@ void IRAM_ATTR lcd_send_lines(int xs, int ys, int xe, int ye, const uint8_t *dat
trans[2].tx_data[0] = (uint8_t)espp::Gc9a01::Command::raset;
#endif
trans[3].tx_data[0] = (ys) >> 8;
trans[3].tx_data[1] = (ys) & 0xff;
trans[3].tx_data[1] = (ys)&0xff;
trans[3].tx_data[2] = (ye) >> 8;
trans[3].tx_data[3] = (ye) & 0xff;
trans[3].tx_data[3] = (ye)&0xff;
#if CONFIG_HARDWARE_WROVER_KIT
trans[4].tx_data[0] = (uint8_t)espp::Ili9341::Command::ramwr;
#elif CONFIG_HARDWARE_TTGO || CONFIG_HARDWARE_BOX
Expand Down
4 changes: 2 additions & 2 deletions components/display_drivers/include/gc9a01.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class Gc9a01 {
static gpio_num_t dc_pin_;
static int offset_x_;
static int offset_y_;
static inline bool swap_xy_ = false;
static inline std::mutex spi_mutex_{};
static bool swap_xy_;
static std::mutex spi_mutex_;
};
} // namespace espp
4 changes: 2 additions & 2 deletions components/display_drivers/include/ili9341.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class Ili9341 {
static gpio_num_t dc_pin_;
static int offset_x_;
static int offset_y_;
static inline bool swap_xy_ = false;
static inline std::mutex spi_mutex_{};
static bool swap_xy_;
static std::mutex spi_mutex_;
};
} // namespace espp
4 changes: 2 additions & 2 deletions components/display_drivers/include/st7789.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class St7789 {
static gpio_num_t dc_pin_;
static int offset_x_;
static int offset_y_;
static inline bool swap_xy_ = false;
static inline std::mutex spi_mutex_{};
static bool swap_xy_;
static std::mutex spi_mutex_;
};
} // namespace espp
2 changes: 2 additions & 0 deletions components/display_drivers/src/gc9a01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ gpio_num_t espp::Gc9a01::reset_pin_;
gpio_num_t espp::Gc9a01::dc_pin_;
int espp::Gc9a01::offset_x_;
int espp::Gc9a01::offset_y_;
bool espp::Gc9a01::swap_xy_ = false;
std::mutex espp::Gc9a01::spi_mutex_;
2 changes: 2 additions & 0 deletions components/display_drivers/src/ili9341.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ gpio_num_t espp::Ili9341::reset_pin_;
gpio_num_t espp::Ili9341::dc_pin_;
int espp::Ili9341::offset_x_;
int espp::Ili9341::offset_y_;
bool espp::Ili9341::swap_xy_ = false;
std::mutex espp::Ili9341::spi_mutex_;
2 changes: 2 additions & 0 deletions components/display_drivers/src/st7789.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ gpio_num_t espp::St7789::reset_pin_;
gpio_num_t espp::St7789::dc_pin_;
int espp::St7789::offset_x_;
int espp::St7789::offset_y_;
bool espp::St7789::swap_xy_ = false;
std::mutex espp::St7789::spi_mutex_;
18 changes: 8 additions & 10 deletions components/esp-box/include/esp-box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class EspBox : public BaseComponent {
static constexpr auto touch_interrupt_level = espp::Interrupt::ActiveLevel::HIGH;
static constexpr auto touch_interrupt_type = espp::Interrupt::Type::RISING_EDGE;
static constexpr auto touch_interrupt_pullup_enabled = false;
}; // struct box3
}; // struct box3

// box:
struct box {
Expand Down Expand Up @@ -384,15 +384,13 @@ class EspBox : public BaseComponent {

// NOTE: the active level, interrupt type, and pullup configuration is set by
// detect(), since it depends on the box type
espp::Interrupt::PinConfig touch_interrupt_pin_{
.gpio_num = touch_interrupt,
.callback =
[this](const auto &event) {
update_touch();
if (touch_callback_) {
touch_callback_(touchpad_data());
}
}};
espp::Interrupt::PinConfig touch_interrupt_pin_{.gpio_num = touch_interrupt,
.callback = [this](const auto &event) {
update_touch();
if (touch_callback_) {
touch_callback_(touchpad_data());
}
}};

// we'll only add each interrupt pin if the initialize method is called
espp::Interrupt interrupts_{
Expand Down
2 changes: 1 addition & 1 deletion components/esp-box/src/esp-box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ bool EspBox::initialize_display(size_t pixel_buffer_size) {
}
// initialize the display / lvgl
using namespace std::chrono_literals;
display_ = std::make_shared<espp::Display<Pixel>>(espp::Display<Pixel >::AllocatingConfig{
display_ = std::make_shared<espp::Display<Pixel>>(espp::Display<Pixel>::AllocatingConfig{
.width = lcd_width_,
.height = lcd_height_,
.pixel_buffer_size = pixel_buffer_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ extern "C" void app_main(void) {
{
std::lock_guard<std::mutex> lock(lvgl_mutex);
int encoder_count = mt_display.encoder_value();
lv_label_set_text_fmt(
label, "Touch the screen!\nPress the button to clear circles.\nEncoder: %d", encoder_count);
lv_label_set_text_fmt(label,
"Touch the screen!\nPress the button to clear circles.\nEncoder: %d",
encoder_count);
}
// sleep for the remaining time
auto end = esp_timer_get_time();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ bool MatouchRotaryDisplay::initialize_display(size_t pixel_buffer_size) {
return true;
}

std::shared_ptr<espp::Display<MatouchRotaryDisplay::Pixel>> MatouchRotaryDisplay::display() const { return display_; }
std::shared_ptr<espp::Display<MatouchRotaryDisplay::Pixel>> MatouchRotaryDisplay::display() const {
return display_;
}

void IRAM_ATTR MatouchRotaryDisplay::lcd_wait_lines() {
spi_transaction_t *rtrans;
Expand Down

0 comments on commit b8fb0b8

Please sign in to comment.