I was just taking a look at screen's source to try to figure out how hard it would be add a feature I want. I want an option when using screen to talk to a serial port to reverse the order of the bits in each character.
Does anyone know of any readily available serial port reader/writer for Unix and Unix-like systems that already has that?
I realize it seems like a really weird thing to want. I'm going some things with a small microcontroller (ATTiny 85). It does not have a UART, so right now when when I want to use serial for debugging I just bit bang it. The MCU does have a thing they call Universal Serial Interface (USI), which provides hardware support for shifting a byte in or out over a GPIO pin timed by a clock. USI is basically building blocks in hardware for the lowest level parts of serial communication. It does the things that can be hard in software because of timing, leaving the software to deal with the higher level aspects of the protocol.
I want to switch from bit banging to USI. Unfortunately when USI shifts a byte out of its send register to a pin, it shifts from the most significant bit side of the registers. UART protocol, which is what computers expect, wants the least significant bit first, so you've got to reverse the bytes before loading them into the USI's output register.
(They probably made USI MSB first because the serial protocols most likely for it to be used for are I2C and SPI. I2C is MSB first. SPI can go either way but MSB first is more common).
It's only a few instructions to do that swap, but MCUs can be quite constrained on space so it would be nice to not have to bother and instead do the swap on the receiving side.