Device emulation implemented in programmable circuits. In one aspect, an interface for providing control of a hardware device includes functional code embedded in circuitry of the interface. Emulator code is embedded in programmable circuitry of the interface to emulate the hardware device during testing of the functional code and the interface. Another aspect diagnoses errors in a system having an interface and a connected hardware device, using emulator code embedded in a programmable circuit of the interface.