tsb: use the named register surface

Direct register access now reads through the named surface
(hw::mcusr::wdrf.test(), hw::ucsr0b::write(...)) instead of the string form,
matching how libavr itself is written. Zero-overhead: pure 740 B, tricks 658 B,
asm 508 B unchanged, all byte-identical across modes, protocol green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-19 14:55:01 +02:00
parent 57d94cf631
commit f32a27ff15
3 changed files with 7 additions and 8 deletions

View File

@@ -237,10 +237,9 @@ void write_config()
// Minimal 115200 8N1 bring-up: 8N1 is the UCSR0C reset value, so only U2X0,
// UBRR0 (16 at 16 MHz → 2.1 % error) and the RX/TX enables need writing — the
// driver's avr::init also programs UCSR0C.
avr::hw::reg<"UCSR0A">::write(avr::hw::field<"UCSR0A", "U2X0">{}(1).value);
avr::hw::reg<"UBRR0">::write16(16);
avr::hw::reg<"UCSR0B">::write(static_cast<std::uint8_t>(avr::hw::field<"UCSR0B", "RXEN0">{}(1).value |
avr::hw::field<"UCSR0B", "TXEN0">{}(1).value));
avr::hw::ucsr0a::write(avr::hw::ucsr0a::u2x0(1).value);
avr::hw::ubrr0::write16(16);
avr::hw::ucsr0b::write(avr::hw::ucsr0b::rxen0(1), avr::hw::ucsr0b::txen0(1));
// The password gate that the canonical loader carries (compare host bytes
// against the config page, hang on mismatch) is dropped here: it is optional
@@ -250,8 +249,8 @@ void write_config()
std::uint8_t knocks = 0;
std::uint16_t idle = 0xFFFF;
while (knocks < 3) {
if (avr::hw::reg<"UCSR0A">::read() & avr::hw::field<"UCSR0A", "RXC0">{}(1).value)
knocks = avr::hw::reg<"UDR0">::read() == '@' ? knocks + 1 : 0;
if (avr::hw::ucsr0a::rxc0.test())
knocks = avr::hw::udr0::read() == '@' ? knocks + 1 : 0;
else if (--idle == 0)
appjump();
}