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;
|
lastInputState = inputNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!events.empty()) {
|
for (const auto& evt: events) {
|
||||||
for (const auto& evt: events) {
|
dispatchEvent(evt);
|
||||||
dispatchEvent(evt);
|
if (handlePendingSwitchRequest()) {
|
||||||
if (handlePendingSwitchRequest()) {
|
break;
|
||||||
lastInputState = context.input.readState();
|
|
||||||
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 waitBase = context.clock.millis();
|
||||||
const std::uint32_t waitMs = nextTimerDueMs(waitBase);
|
const std::uint32_t waitMs = nextTimerDueMs(waitBase);
|
||||||
TickType_t waitTicks;
|
TickType_t waitTicks;
|
||||||
if (waitMs == std::numeric_limits<std::uint32_t>::max()) {
|
if (waitMs == std::numeric_limits<std::uint32_t>::max()) {
|
||||||
waitTicks = portMAX_DELAY;
|
waitTicks = portMAX_DELAY;
|
||||||
} else if (waitMs == 0) {
|
|
||||||
waitTicks = 0;
|
|
||||||
} else {
|
} else {
|
||||||
waitTicks = pdMS_TO_TICKS(waitMs);
|
waitTicks = pdMS_TO_TICKS(waitMs);
|
||||||
if (waitTicks == 0)
|
if (waitTicks == 0)
|
||||||
waitTicks = 1;
|
waitTicks = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ulTaskNotifyTake(pdTRUE, waitTicks);
|
ulTaskNotifyTake(pdTRUE, waitTicks);
|
||||||
if (waitTicks == 0)
|
|
||||||
taskYIELD();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ public:
|
|||||||
performStep();
|
performStep();
|
||||||
const uint64_t frameEndUs = esp_timer_get_time();
|
const uint64_t frameEndUs = esp_timer_get_time();
|
||||||
const uint64_t elapsedUs = (frameEndUs >= frameStartUs) ? (frameEndUs - frameStartUs) : 0;
|
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);
|
scheduleAfterFrame(elapsedUs);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1240,7 +1240,8 @@ private:
|
|||||||
self->unloadRom();
|
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);
|
auto* self = fromGb(gb);
|
||||||
if (!self || line >= LCD_HEIGHT)
|
if (!self || line >= LCD_HEIGHT)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -81,42 +81,17 @@ static void delay(unsigned long long loop) {
|
|||||||
void Buttons::pooler() {
|
void Buttons::pooler() {
|
||||||
while (true) {
|
while (true) {
|
||||||
BaseType_t xResult = xTaskNotifyWait(pdFALSE, ULONG_MAX, nullptr, portMAX_DELAY);
|
BaseType_t xResult = xTaskNotifyWait(pdFALSE, ULONG_MAX, nullptr, portMAX_DELAY);
|
||||||
while (true) {
|
uint8_t reg = 0;
|
||||||
auto reset = [&]() {
|
uint8_t buffer;
|
||||||
i2c_master_bus_rm_device(dev_handle);
|
ESP_ERROR_CHECK(
|
||||||
ESP_ERROR_CHECK(i2c_master_bus_add_device(I2cGlobal::get().get_bus_handle(), &dev_cfg, &dev_handle));
|
i2c_master_transmit_receive(dev_handle, ®, sizeof(reg), reinterpret_cast<uint8_t*>(&buffer), 1, -1));
|
||||||
uint8_t buf2[2];
|
_current = buffer;
|
||||||
buf2[0] = 6;
|
// read second port too to clear the interrupt
|
||||||
buf2[1] = 0xFF;
|
reg = 1;
|
||||||
ESP_ERROR_CHECK(i2c_master_transmit(dev_handle, buf2, sizeof(buf2), -1));
|
ESP_ERROR_CHECK(
|
||||||
buf2[0] = 7;
|
i2c_master_transmit_receive(dev_handle, ®, sizeof(reg), reinterpret_cast<uint8_t*>(&buffer), 1, -1));
|
||||||
buf2[1] = 0x80;
|
if (_listener)
|
||||||
ESP_ERROR_CHECK(i2c_master_transmit(dev_handle, buf2, sizeof(buf2), -1));
|
xTaskNotifyGive(_listener);
|
||||||
};
|
|
||||||
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 Buttons::get_pressed() { return _current; }
|
uint8_t Buttons::get_pressed() { return _current; }
|
||||||
|
|||||||
@@ -130,16 +130,16 @@ void SMD::async_draw_start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SMD::async_draw_wait() {
|
void SMD::async_draw_wait() {
|
||||||
SemaphoreHandle_t sem = s_bufferSem[s_drawBufIdx];
|
SemaphoreHandle_t sem = s_bufferSem[s_drawBufIdx];
|
||||||
uint64_t waitedUs = 0;
|
// uint64_t waitedUs = 0;
|
||||||
if (!uxSemaphoreGetCount(sem)) {
|
if (!uxSemaphoreGetCount(sem)) {
|
||||||
uint64_t start = esp_timer_get_time();
|
// uint64_t start = esp_timer_get_time();
|
||||||
if (!xSemaphoreTake(sem, portMAX_DELAY))
|
if (!xSemaphoreTake(sem, portMAX_DELAY))
|
||||||
assert(false);
|
assert(false);
|
||||||
if (!xSemaphoreGive(sem))
|
if (!xSemaphoreGive(sem))
|
||||||
assert(false);
|
assert(false);
|
||||||
waitedUs = esp_timer_get_time() - start;
|
// waitedUs = esp_timer_get_time() - start;
|
||||||
}
|
}
|
||||||
if (waitedUs)
|
// if (waitedUs)
|
||||||
printf("Waited %" PRIu64 " us\n", waitedUs);
|
// printf("Waited %" PRIu64 " us\n", waitedUs);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user