V-USB by objective development is a nice library to connect AVR ATmegas and ATtinys via USB to hosts. All it requires is two MCU pins, one of which must be able to trigger an interrupt.
Coding efforts are a bit more complex than serial lines, simply because USB has so many options. Control transfers, bulk transfers, serial line emulation (CDC), optionally multiple endpoints, whatnot. Best idea is to take one of the sample projects and to hack it until it fits the purpose.
Especially small chips like the ATtiny2313 can be a bit a challenge. This MCU comes with only 2 kB of Flash memory, so binary size matters. Surprisingly, binary size changes considerably depending on which clock frequency the chip runs at.
The following collection was done with the very same code, which is about just enough to get a communications to the host running at all. Changed between compilations was only F_CPU. V-USB uses different code paths for each supported clock frequency. Target MCU was an ATtiny2313. RAM usage was always 46 bytes.
|F_CPU in kHz||Code size||Remarks|
|18000||2360 bytes||(requires CHECK_CRC enabled)|
Another observation: clocks of 12.8 Mhz and 16.5 MHz work without clock crystal, so with just the internal R/C oscillator. This oscillator needs calibration, there is an osccal method and an osctune method. The former one occupies 297 bytes, the latter one just 36 bytes.