Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions components/box-emu/example/main/box_emu_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ static size_t load_audio() {
}

// these are configured in the CMakeLists.txt file
extern const char wav_start[] asm("_binary_click_wav_start"); // cppcheck-suppress syntaxError
extern const char wav_end[] asm("_binary_click_wav_end"); // cppcheck-suppress syntaxError
extern const char wav_start[] asm("_binary_click_wav_start");
extern const char wav_end[] asm("_binary_click_wav_end");

// -1 due to the size being 1 byte too large, I think because end is the byte
// immediately after the last byte in the memory but I'm not sure - cmm 2022-08-20
//
// Suppression as these are linker symbols and cppcheck doesn't know how to ensure
// they are the same object
// cppcheck-suppress comparePointers
// cppcheck-suppress subtractPointers
size_t wav_size = (wav_end - wav_start) - 1;
FILE *fp = fmemopen((void *)wav_start, wav_size, "rb");
// read the file into the audio_bytes vector
Expand Down
27 changes: 14 additions & 13 deletions components/box-emu/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
## IDF Component Manager Manifest File
dependencies:
idf: ">=5.5"
espressif/esp_tinyusb: ">=2.0"
idf: '>=5.5'
espressif/esp_tinyusb: '>=2.0'
lvgl/lvgl: '>=9.2.2'
espp/adc: ">=1.0"
espp/aw9523: ">=1.0"
espp/button: ">=1.0"
espp/drv2605: ">=1.0"
espp/esp-box: ">=1.0"
espp/event_manager: ">=1.0"
espp/max1704x: ">=1.0"
espp/mcp23x17: ">=1.0"
espp/task: ">=1.0"
espp/timer: ">=1.0"
espp/serialization: ">=1.0"
espp/adc: '>=1.0'
espp/aw9523: '>=1.0'
espp/button: '>=1.0'
espp/drv2605: '>=1.0'
espp/esp-box: '>=1.0'
espp/event_manager: '>=1.0'
espp/max1704x: '>=1.0'
espp/mcp23x17: '>=1.0'
espp/task: '>=1.0'
espp/timer: '>=1.0'
espp/serialization: '>=1.0'
espressif/usb: '>=1.4.1'
2 changes: 1 addition & 1 deletion components/box-emu/include/box-emu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <esp_vfs_fat.h>
#include <sdmmc_cmd.h>

#include <hal/usb_phy_types.h>
// #include <hal/usb_phy_types.h>
#include <esp_private/usb_phy.h>

#include <tinyusb.h>
Expand Down
55 changes: 35 additions & 20 deletions components/box-emu/src/box-emu.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "box-emu.hpp"

#include <cstring>

BoxEmu::BoxEmu() : espp::BaseComponent("BoxEmu") {
detect();
}
Expand Down Expand Up @@ -498,7 +500,7 @@ void BoxEmu::palette(const uint16_t *palette, size_t size) {
palette_size_ = size;
}

void IRAM_ATTR BoxEmu::push_frame(const void* frame) {
void BoxEmu::push_frame(const void* frame) {
if (video_queue_ == nullptr) {
logger_.error("video queue is null, make sure to call initialize_video() first!");
return;
Expand Down Expand Up @@ -655,6 +657,7 @@ bool BoxEmu::initialize_usb() {
.max_files = 5,
.allocation_unit_size = 2 * 1024, // sector size is 512 bytes, this should be between sector size and (128 * sector size). Larger means higher read/write performance and higher overhead for small files.
.disk_status_check_enable = false, // true if you see issues or are unmounted properly; slows down I/O
.use_one_fat = true,
};

tinyusb_msc_fatfs_config_t config_msc = {
Expand Down Expand Up @@ -773,7 +776,7 @@ bool BoxEmu::video_task_callback(std::mutex &m, std::condition_variable& cv, boo
int num_lines = std::min<int>(num_lines_to_write, lcd_height()-y);
// memset the buffer to 0
memset(_buf, 0, lcd_width() * num_lines * sizeof(Pixel));
box.write_lcd_frame(0, y + _y_offset, lcd_width(), num_lines, (uint8_t*)&_buf[0]);
box.write_lcd_frame(0, y + _y_offset, lcd_width(), num_lines, reinterpret_cast<uint8_t*>(&_buf[0]));
}

// now return
Expand All @@ -782,21 +785,38 @@ bool BoxEmu::video_task_callback(std::mutex &m, std::condition_variable& cv, boo

if (is_native()) {
if (has_palette()) {
const bool palette_is_power_of_two = palette_size_ && ((palette_size_ & (palette_size_ - 1)) == 0);
const size_t palette_mask = palette_size_ - 1;
for (int y=0; y<display_height_; y+= num_lines_to_write) {
uint16_t* _buf = (uint16_t*)((uint32_t)vram0 * (vram_index ^ 0x01) + (uint32_t)vram1 * vram_index);
vram_index = vram_index ^ 0x01;
int num_lines = std::min<int>(num_lines_to_write, display_height_-y);
const uint8_t* _frame = (const uint8_t*)_frame_ptr;
for (int i=0; i<num_lines; i++) {
// write two pixels (32 bits) at a time because it's faster
for (int j=0; j<display_width_/2; j++) {
int src_index = (y+i)*native_pitch_ + j * 2;
int dst_index = i*display_width_ + j * 2;
_buf[dst_index] = _palette[_frame[src_index] % palette_size_];
_buf[dst_index + 1] = _palette[_frame[src_index + 1] % palette_size_];
const uint8_t* src = _frame + (y + i) * native_pitch_;
uint16_t* dst = _buf + i * display_width_;
if (palette_is_power_of_two) {
int j = 0;
for (; j + 7 < display_width_; j += 8) {
dst[j + 0] = _palette[src[j + 0] & palette_mask];
dst[j + 1] = _palette[src[j + 1] & palette_mask];
dst[j + 2] = _palette[src[j + 2] & palette_mask];
dst[j + 3] = _palette[src[j + 3] & palette_mask];
dst[j + 4] = _palette[src[j + 4] & palette_mask];
dst[j + 5] = _palette[src[j + 5] & palette_mask];
dst[j + 6] = _palette[src[j + 6] & palette_mask];
dst[j + 7] = _palette[src[j + 7] & palette_mask];
}
for (; j < display_width_; j++) {
dst[j] = _palette[src[j] & palette_mask];
}
} else {
for (int j = 0; j < display_width_; j++) {
dst[j] = _palette[src[j] % palette_size_];
}
}
}
box.write_lcd_frame(_x_offset, y + _y_offset, display_width_, num_lines, (uint8_t*)&_buf[0]);
box.write_lcd_frame(_x_offset, y + _y_offset, display_width_, num_lines, reinterpret_cast<uint8_t*>(&_buf[0]));
}
} else {
// no palette
Expand All @@ -806,16 +826,11 @@ bool BoxEmu::video_task_callback(std::mutex &m, std::condition_variable& cv, boo
int num_lines = std::min<int>(num_lines_to_write, display_height_-y);
const uint16_t* _frame = (const uint16_t*)_frame_ptr;
for (int i=0; i<num_lines; i++) {
// write two pixels (32 bits) at a time because it's faster
for (int j=0; j<display_width_/2; j++) {
int src_index = (y+i)*native_pitch_ + j * 2;
int dst_index = i*display_width_ + j * 2;
// memcpy(&_buf[i*display_width_ + j * 2], &_frame[(y+i)*native_pitch_ + j * 2], 4);
_buf[dst_index] = _frame[src_index];
_buf[dst_index + 1] = _frame[src_index + 1];
}
const uint16_t* src = _frame + (y + i) * native_pitch_;
uint16_t* dst = _buf + i * display_width_;
std::memcpy(dst, src, display_width_ * sizeof(uint16_t));
}
box.write_lcd_frame(_x_offset, y + _y_offset, display_width_, num_lines, (uint8_t*)&_buf[0]);
box.write_lcd_frame(_x_offset, y + _y_offset, display_width_, num_lines, reinterpret_cast<uint8_t*>(&_buf[0]));
}
}
} else {
Expand Down Expand Up @@ -850,7 +865,7 @@ bool BoxEmu::video_task_callback(std::mutex &m, std::condition_variable& cv, boo
_buf[dst_index + 1] = _palette[_frame[src_index + 1] % palette_size_];
}
}
box.write_lcd_frame(0 + _x_offset, y, max_x, i, (uint8_t*)&_buf[0]);
box.write_lcd_frame(0 + _x_offset, y, max_x, i, reinterpret_cast<uint8_t*>(&_buf[0]));
}
} else {
// no palette
Expand All @@ -876,7 +891,7 @@ bool BoxEmu::video_task_callback(std::mutex &m, std::condition_variable& cv, boo
_buf[dst_index + 1] = _frame[src_index + 1];
}
}
box.write_lcd_frame(0 + _x_offset, y, max_x, i, (uint8_t*)&_buf[0]);
box.write_lcd_frame(0 + _x_offset, y, max_x, i, reinterpret_cast<uint8_t*>(&_buf[0]));
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions components/doom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ target_compile_options(${COMPONENT_LIB} PRIVATE
-Wno-misleading-indentation
-Wno-format-overflow
-Wno-char-subscripts
$<$<COMPILE_LANGUAGE:C>:-std=gnu17>
$<$<COMPILE_LANGUAGE:C>:-Wno-discarded-qualifiers>
$<$<COMPILE_LANGUAGE:C>:-Wno-error=incompatible-pointer-types>
$<$<COMPILE_LANGUAGE:C>:-Wno-error=compare-distinct-pointer-types>
-Wno-missing-field-initializers
-DHAVE_CONFIG_H
-O2
Expand Down
Loading
Loading