public override bool Setup()
        {
            spiPort = YSpiPort.FirstSpiPort();
            if (spiPort == null)
            {
                Console.WriteLine("No Yocto-Spi detected");
                return(false);
            }

            YModule      module       = spiPort.get_module();
            string       errmsg       = "";
            string       serialNumber = module.get_serialNumber();
            YPowerOutput powerOutput  = YPowerOutput.FindPowerOutput(serialNumber + ".powerOutput");

            powerOutput.set_voltage(YPowerOutput.VOLTAGE_OUT3V3);
            spiPort.set_voltageLevel(YSpiPort.VOLTAGELEVEL_TTL3V);
            spiPort.set_spiMode("2000000,0,msb");
            spiPort.set_protocol("Frame:1ms");
            spiPort.set_ssPolarity(YSpiPort.SSPOLARITY_ACTIVE_LOW);
            module.saveToFlash();
            YAPI.Sleep(25, ref errmsg);
            spiPort.writeHex(SET_MODE_4);
            YAPI.Sleep(5, ref errmsg);

            string[] commands = { READ_STATUS, READ_STATUS, READ_STATUS, READ_ID, SET_ANGLES };
            Frame[]  result;
            if (!SendAndReceive(commands, out result))
            {
                Console.WriteLine("Failed to initialize SCL3300 (communication error)");
                return(false);
            }
            if (!_chip_ready)
            {
                Console.WriteLine("SCL3300 startup failed (rs={4})", result[2].rs);
                return(false);
            }
            if ((result[3].data & 0xff) != 0xc1)
            {
                Console.WriteLine("Unexpected SCL3300 identification (WHOAMI={0})", (result[3].data & 0xff));
                return(false);
            }
            if (!DecodeStatus(result[2]))
            {
                Console.WriteLine("SCL3300 Status bad, chip reset is required");
                return(false);
            }
            Console.WriteLine("SCL3300 is ready");
            return(true);
        }
Example #2
0
 public void ArrivalCallback(YModule module)
 {
     // Check if the device features a SPI Port
     for (int i = 0; i < module.functionCount(); i++)
     {
         if (module.functionType(i) == "SpiPort")
         {
             // SPI Port found, use it
             string identifier = module.get_serialNumber() + "." + module.functionId(i);
             Log("Using " + identifier);
             spiPort = YSpiPort.FindSpiPort(identifier);
             spiPort.set_spiMode("0,0,lsb");
             spiPort.reset();
         }
     }
 }