Files
tactility/TactilityC/Source/tt_mdns.cpp
Adolfo Reyna 75178652e2 feat(lvgl+mdns): complete canvas API + fix GB blank render + mDNS browse API
lvgl-module/symbols.c:
- canvas: full LVGL9 docs API (get_buf, get_image, get_px, get_draw_buf,
  set_palette, copy_buf, init_layer, finish_layer, buf_size) – was only 5 symbols
- draw_buf: create/destroy/init/dup/copy/goto/clear/width_to_stride/align/palette/from_image/to_image
- cache: lv_draw_buf_invalidate_cache, flush_cache, lv_image_cache_drop – critical bugfix for
  GameBoy (and any direct framebuffer) where raw buf mutated but image cache stale -> FPS but no image.
- draw layer helpers, image scale/rotation/pivot/offset, transform scales for GB 2x/3x integer scaling

Reason blank screen: lv_canvas in LVGL9 is lv_image backed by draw_buf. Mutating raw pointer
without lv_image_cache_drop + invalidate_cache leaves stale texture. Timer was calling
lv_obj_invalidate only. Now exports needed symbols and app fixed to drop cache each frame.

mDNS (preserve from local WIP, sits on top of 60764979 'kidsOS-XXXX' mdns init):
- Tactility/network/Mdns.h/cpp: C++ browse + resolveHostname wrappers around esp-idf mdns 1.3.2
  (PTR query, txt records, address extraction, POSIX stub)
- TactilityC/tt_mdns.h/cpp: C copy-based API for ELF apps (TT_MDNS_MAX_RESULTS 32,
  capped addresses/txt, hostname->IP resolve)
- TactilityC/tt_init.cpp: export tt_mdns_is_available / browse / resolve_hostname symbols

Test plan:
- firmware build for es3c28p --dev
- release-sdk-current.py
- GameBoy app build against new SDK (0 missing symbols expected)
- push both branches to personal gitea
2026-07-20 12:32:00 -04:00

77 lines
2.8 KiB
C++

#include "tt_mdns.h"
#include <Tactility/network/Mdns.h>
#include <cstring>
#include <algorithm>
extern "C" {
bool tt_mdns_is_available() {
return tt::network::mdns::isAvailable();
}
bool tt_mdns_browse(const char* serviceType, const char* proto, uint32_t timeoutMs, size_t maxResults, TtMdnsBrowseResult* outResult) {
if (outResult == nullptr) return false;
if (serviceType == nullptr || proto == nullptr) return false;
memset(outResult, 0, sizeof(TtMdnsBrowseResult));
uint32_t effectiveTimeout = timeoutMs == 0 ? 3000 : timeoutMs;
size_t effectiveMax = maxResults == 0 ? 20 : maxResults;
effectiveMax = std::min<size_t>(effectiveMax, TT_MDNS_MAX_RESULTS);
std::vector<tt::network::mdns::Service> services;
if (!tt::network::mdns::browse(serviceType, proto, effectiveTimeout, effectiveMax, services)) {
return false;
}
size_t toCopy = std::min(services.size(), static_cast<size_t>(TT_MDNS_MAX_RESULTS));
for (size_t i = 0; i < toCopy; i++) {
const auto& src = services[i];
auto& dst = outResult->services[i];
strncpy(dst.instanceName, src.instanceName.c_str(), TT_MDNS_INSTANCE_LEN - 1);
strncpy(dst.serviceType, src.serviceType.c_str(), TT_MDNS_SERVICE_TYPE_LEN - 1);
strncpy(dst.proto, src.proto.c_str(), TT_MDNS_PROTO_LEN - 1);
strncpy(dst.hostname, src.hostname.c_str(), TT_MDNS_HOSTNAME_LEN - 1);
dst.port = src.port;
dst.ttl = src.ttl;
strncpy(dst.primaryAddress, src.primaryAddress.c_str(), TT_MDNS_IP_LEN - 1);
size_t addrCount = std::min(src.addresses.size(), static_cast<size_t>(TT_MDNS_MAX_ADDRESSES));
dst.addressCount = static_cast<uint8_t>(addrCount);
for (size_t a = 0; a < addrCount; a++) {
strncpy(dst.addresses[a], src.addresses[a].c_str(), TT_MDNS_IP_LEN - 1);
}
size_t txtCount = std::min(src.txtRecords.size(), static_cast<size_t>(TT_MDNS_MAX_TXT_RECORDS));
dst.txtCount = static_cast<uint8_t>(txtCount);
size_t idx = 0;
for (const auto& kv : src.txtRecords) {
if (idx >= txtCount) break;
strncpy(dst.txtRecords[idx].key, kv.first.c_str(), TT_MDNS_TXT_KEY_LEN - 1);
strncpy(dst.txtRecords[idx].value, kv.second.c_str(), TT_MDNS_TXT_VALUE_LEN - 1);
idx++;
}
}
outResult->count = static_cast<uint8_t>(toCopy);
return true;
}
bool tt_mdns_resolve_hostname(const char* hostname, uint32_t timeoutMs, char* outIp) {
if (hostname == nullptr || outIp == nullptr) return false;
memset(outIp, 0, TT_MDNS_IP_LEN);
uint32_t effectiveTimeout = timeoutMs == 0 ? 2000 : timeoutMs;
std::string ip;
if (!tt::network::mdns::resolveHostname(hostname, effectiveTimeout, ip)) {
return false;
}
strncpy(outIp, ip.c_str(), TT_MDNS_IP_LEN - 1);
return true;
}
} // extern "C"