feat(xteink): count guest ADC reads per channel

Host tooling needs to know when the guest has actually sampled a button,
since the firmware only polls the resistor ladder between e-ink refreshes.
This commit is contained in:
2026-07-26 11:18:28 -04:00
parent 55d801ca9e
commit d613b079ef
3 changed files with 10 additions and 3 deletions
+8 -3
View File
@@ -26,9 +26,11 @@ static uint64_t esp32c3_adc_read(void *opaque, hwaddr addr, unsigned size)
return ADC_DONE;
}
if (addr == ADC_DATA1 || addr == ADC_DATA2) {
return s->channel < ESP32C3_ADC_CHANNELS
? MIN(qatomic_read(&s->input[s->channel]), ADC_MAX)
: ADC_MAX;
if (s->channel >= ESP32C3_ADC_CHANNELS) {
return ADC_MAX;
}
qatomic_inc(&s->samples[s->channel]);
return MIN(qatomic_read(&s->input[s->channel]), ADC_MAX);
}
return s->regs[addr / 4];
}
@@ -60,6 +62,7 @@ static void esp32c3_adc_reset_hold(Object *obj, ResetType type)
memset(s->regs, 0, sizeof(s->regs));
for (int i = 0; i < ESP32C3_ADC_CHANNELS; i++) {
s->input[i] = ADC_MAX;
s->samples[i] = 0;
}
s->channel = 0;
}
@@ -75,6 +78,8 @@ static void esp32c3_adc_init(Object *obj)
for (int i = 0; i < ESP32C3_ADC_CHANNELS; i++) {
object_property_add_uint32_ptr(obj, "adci[*]", &s->input[i],
OBJ_PROP_FLAG_READWRITE);
object_property_add_uint32_ptr(obj, "adcsamples[*]", &s->samples[i],
OBJ_PROP_FLAG_READ);
}
esp32c3_adc_reset_hold(obj, RESET_TYPE_COLD);
}
+2
View File
@@ -13,5 +13,7 @@ struct ESP32C3AdcState {
MemoryRegion iomem;
uint32_t regs[ESP32C3_ADC_IO_SIZE / sizeof(uint32_t)];
uint32_t input[ESP32C3_ADC_CHANNELS];
/* Sample counters let a host driver hold a button until the guest has actually read it. */
uint32_t samples[ESP32C3_ADC_CHANNELS];
uint8_t channel;
};