Major rewrite.  Removed all uncessary code, improved state checks for
tx/rx modes, reduce code size further, switched to bitmasks for
register fields.