def prepare_pin(self, pin_id, in_out=Pin.OUT):
        if pin_id is not None:
            pin = Pin(pin_id, in_out)
            new_pin = Controller.Mock()
            new_pin.pin_id = pin_id
            new_pin.value = pin.value

            if in_out == Pin.OUT:
                new_pin.low = lambda: pin.value(0)
                new_pin.high = lambda: pin.value(1)
            else:
                new_pin.irq = pin.irq

            return new_pin
    def prepare_spi(self, spi):

        if spi:
            new_spi = Controller.Mock()

            def transfer(pin_ss, address, value=0x00):
                response = bytearray(1)

                pin_ss.low()

                spi.write(bytes([address]))
                spi.write_readinto(bytes([value]), response)

                pin_ss.high()

                return response

            new_spi.transfer = transfer
            new_spi.close = spi.deinit
            return new_spi