mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 23:27:49 +01:00
fixes
This commit is contained in:
@@ -86,38 +86,26 @@ void AppSystem::run() {
|
||||
lastInputState = inputNow;
|
||||
}
|
||||
|
||||
if (!events.empty()) {
|
||||
for (const auto& evt: events) {
|
||||
dispatchEvent(evt);
|
||||
if (handlePendingSwitchRequest()) {
|
||||
lastInputState = context.input.readState();
|
||||
break;
|
||||
}
|
||||
for (const auto& evt: events) {
|
||||
dispatchEvent(evt);
|
||||
if (handlePendingSwitchRequest()) {
|
||||
break;
|
||||
}
|
||||
if (handlePendingSwitchRequest())
|
||||
continue;
|
||||
// Process newly generated events without blocking
|
||||
continue;
|
||||
}
|
||||
|
||||
if (handlePendingSwitchRequest())
|
||||
continue;
|
||||
|
||||
const std::uint32_t waitBase = context.clock.millis();
|
||||
const std::uint32_t waitMs = nextTimerDueMs(waitBase);
|
||||
TickType_t waitTicks;
|
||||
if (waitMs == std::numeric_limits<std::uint32_t>::max()) {
|
||||
waitTicks = portMAX_DELAY;
|
||||
} else if (waitMs == 0) {
|
||||
waitTicks = 0;
|
||||
} else {
|
||||
waitTicks = pdMS_TO_TICKS(waitMs);
|
||||
if (waitTicks == 0)
|
||||
waitTicks = 1;
|
||||
}
|
||||
|
||||
ulTaskNotifyTake(pdTRUE, waitTicks);
|
||||
if (waitTicks == 0)
|
||||
taskYIELD();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ public:
|
||||
performStep();
|
||||
const uint64_t frameEndUs = esp_timer_get_time();
|
||||
const uint64_t elapsedUs = (frameEndUs >= frameStartUs) ? (frameEndUs - frameStartUs) : 0;
|
||||
printf("Step took %" PRIu64 " us\n", elapsedUs);
|
||||
GB_PERF_ONLY(printf("Step took %" PRIu64 " us\n", elapsedUs));
|
||||
scheduleAfterFrame(elapsedUs);
|
||||
return;
|
||||
}
|
||||
@@ -1240,7 +1240,8 @@ private:
|
||||
self->unloadRom();
|
||||
}
|
||||
|
||||
static void lcdDrawLine(struct gb_s* gb, const uint8_t pixels[160], const uint_fast8_t line) {
|
||||
__attribute__((optimize("Ofast"))) static void lcdDrawLine(struct gb_s* gb, const uint8_t pixels[160],
|
||||
const uint_fast8_t line) {
|
||||
auto* self = fromGb(gb);
|
||||
if (!self || line >= LCD_HEIGHT)
|
||||
return;
|
||||
|
||||
@@ -81,42 +81,17 @@ static void delay(unsigned long long loop) {
|
||||
void Buttons::pooler() {
|
||||
while (true) {
|
||||
BaseType_t xResult = xTaskNotifyWait(pdFALSE, ULONG_MAX, nullptr, portMAX_DELAY);
|
||||
while (true) {
|
||||
auto reset = [&]() {
|
||||
i2c_master_bus_rm_device(dev_handle);
|
||||
ESP_ERROR_CHECK(i2c_master_bus_add_device(I2cGlobal::get().get_bus_handle(), &dev_cfg, &dev_handle));
|
||||
uint8_t buf2[2];
|
||||
buf2[0] = 6;
|
||||
buf2[1] = 0xFF;
|
||||
ESP_ERROR_CHECK(i2c_master_transmit(dev_handle, buf2, sizeof(buf2), -1));
|
||||
buf2[0] = 7;
|
||||
buf2[1] = 0x80;
|
||||
ESP_ERROR_CHECK(i2c_master_transmit(dev_handle, buf2, sizeof(buf2), -1));
|
||||
};
|
||||
uint8_t reg = 0;
|
||||
uint8_t buffer;
|
||||
auto err = i2c_master_transmit_receive(dev_handle, ®, sizeof(reg), reinterpret_cast<uint8_t*>(&buffer),
|
||||
1, 100);
|
||||
if (err != ESP_OK) {
|
||||
printf("Error reading buttons: %d\n", err);
|
||||
reset();
|
||||
continue;
|
||||
}
|
||||
_current = buffer;
|
||||
printf("Read buttons: 0x%02X\n", _current);
|
||||
// read second port too to clear the interrupt
|
||||
reg = 1;
|
||||
err = i2c_master_transmit_receive(dev_handle, ®, sizeof(reg), reinterpret_cast<uint8_t*>(&buffer), 1,
|
||||
100);
|
||||
if (err != ESP_OK) {
|
||||
printf("Error reading buttons: %d\n", err);
|
||||
reset();
|
||||
continue;
|
||||
}
|
||||
if (_listener)
|
||||
xTaskNotifyGive(_listener);
|
||||
break;
|
||||
}
|
||||
uint8_t reg = 0;
|
||||
uint8_t buffer;
|
||||
ESP_ERROR_CHECK(
|
||||
i2c_master_transmit_receive(dev_handle, ®, sizeof(reg), reinterpret_cast<uint8_t*>(&buffer), 1, -1));
|
||||
_current = buffer;
|
||||
// read second port too to clear the interrupt
|
||||
reg = 1;
|
||||
ESP_ERROR_CHECK(
|
||||
i2c_master_transmit_receive(dev_handle, ®, sizeof(reg), reinterpret_cast<uint8_t*>(&buffer), 1, -1));
|
||||
if (_listener)
|
||||
xTaskNotifyGive(_listener);
|
||||
}
|
||||
}
|
||||
uint8_t Buttons::get_pressed() { return _current; }
|
||||
|
||||
@@ -130,16 +130,16 @@ void SMD::async_draw_start() {
|
||||
}
|
||||
|
||||
void SMD::async_draw_wait() {
|
||||
SemaphoreHandle_t sem = s_bufferSem[s_drawBufIdx];
|
||||
uint64_t waitedUs = 0;
|
||||
SemaphoreHandle_t sem = s_bufferSem[s_drawBufIdx];
|
||||
// uint64_t waitedUs = 0;
|
||||
if (!uxSemaphoreGetCount(sem)) {
|
||||
uint64_t start = esp_timer_get_time();
|
||||
// uint64_t start = esp_timer_get_time();
|
||||
if (!xSemaphoreTake(sem, portMAX_DELAY))
|
||||
assert(false);
|
||||
if (!xSemaphoreGive(sem))
|
||||
assert(false);
|
||||
waitedUs = esp_timer_get_time() - start;
|
||||
// waitedUs = esp_timer_get_time() - start;
|
||||
}
|
||||
if (waitedUs)
|
||||
printf("Waited %" PRIu64 " us\n", waitedUs);
|
||||
// if (waitedUs)
|
||||
// printf("Waited %" PRIu64 " us\n", waitedUs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user