/// <summary> /// Starts the Treehopper's SPI interface. /// </summary> /// <param name="Mode">Configures clock polarity and phase</param> /// <param name="RateMHz"></param> /// <param name="ChipSelect"></param> /// <param name="ChipSelectPolarity"></param> /// <param name="ChipSelectDelayMilliseconds"></param> /// <param name="InputMode">Chooses whether incoming data is sampled in the middle of the valid data period, or at the end. Most modern sensors produce valid output data in the middle of the waveform period.</param> public void Start(SPIMode Mode, double RateMHz, Pin ChipSelect = null, PinPolarity ChipSelectPolarity = PinPolarity.ActiveLow, int ChipSelectDelayMilliseconds = 0, SPISampleMode InputMode = SPISampleMode.Middle) { this.ChipSelect = ChipSelect; this.ChipSelectPolarity = ChipSelectPolarity; if (this.ChipSelect != null) { this.ChipSelect.MakeDigitalOutput(); if (ChipSelectPolarity == PinPolarity.ActiveLow) { this.ChipSelect.DigitalValue = true; } else { this.ChipSelect.DigitalValue = false; } } double SSPADD = (120.0 / RateMHz - 1); if (SSPADD > 255) { throw new Exception("SPI Rate out of limits. Valid rate is 46.875 kHz - 12 MHz"); } byte[] dataToSend = new byte[4]; dataToSend[0] = (byte)DeviceCommands.SPIConfig; dataToSend[1] = (byte)Mode; dataToSend[2] = (byte)InputMode; dataToSend[3] = (byte)SSPADD; device.sendCommsConfigPacket(dataToSend); }
/// <summary> /// Constructor for Pin class /// </summary> /// <param name="inOut">String containing whether Pin is an input ("in" /// or an output "out"</param> /// <param name="pinName">String containing Pin name</param> /// <param name="busSize">Integer containing the number of values contained by /// the Pin</param> public Pin(PinPolarity polarity, String pinName, int busSize) { this.polarity = polarity; this.pinNames = new string[] { pinName }; this.busSize = busSize; this.expected = new char[busSize]; this.pinVal = new char[busSize]; this.shape = null; }
/// <summary> /// constructor that takes a list of alternate pin names /// </summary> /// <param name="polarity">input/output/wire</param> /// <param name="pinNames">string of possible pin names</param> /// <param name="shape">the shape representing the strokes of the pin</param> public Pin(PinPolarity polarity, String[] pinNames, Sketch.Shape shape) { this.polarity = polarity; this.pinNames = pinNames; this.busSize = 1; this.expected = new char[busSize]; this.pinVal = new char[busSize]; this.shape = shape; }
/// <summary> /// Constructor for Pin class /// </summary> /// <param name="inOut">String containing whether Pin is an input ("in" /// or an output "out"</param> /// <param name="pinName">String containing Pin name</param> /// <param name="pinVal">Integer array containing values held by this instance /// of the Pin</param> public Pin(PinPolarity polarity, String pinName, char[] pinVal) { this.polarity = polarity; this.pinNames = new string[] { pinName }; this.pinVal = new char[pinVal.Length]; this.pinVal = pinVal; this.expected = null; this.busSize = pinVal.Length; this.shape = null; }
/// <summary> /// Converts list of pins into a .tv test vector file /// </summary> /// <param name="pins">List of pins List of pins to be converted to testvectors</param> /// <param name="filename">String containing a filename that exists in the desired /// testvector destination directory</param> public void pins2testVectors(List <List <Pin> > pinMatrix, String filename) { String dir = Path.GetDirectoryName(filename); TextWriter tw = new StreamWriter(dir + "\\testVect.tv"); PinPolarity prevType = PinPolarity.Input; //nested foreach to pull out the appropriate testvector rows foreach (List <Pin> pins in pinMatrix) { foreach (Pin instance in pins) { //if its changing from an input to an output, write an underscore if (prevType.Equals(PinPolarity.Input) && instance.Polarity.Equals(PinPolarity.Ouput)) { tw.Write("_"); } //if its going from output to input, a newline is required else if (prevType.Equals(PinPolarity.Ouput) && instance.Polarity.Equals(PinPolarity.Input)) { tw.WriteLine(); } //While the pin value is conventionally held in the //pinVal variable, in the truthtable code, the pinName //stores the value tw.Write(instance.PinName); //update the previous type prevType = instance.Polarity; } } tw.Close(); }
/// <summary> /// Starts the Treehopper's SPI interface. /// </summary> /// <param name="Mode">Configures clock polarity and phase</param> /// <param name="RateMHz"></param> /// <param name="ChipSelect"></param> /// <param name="ChipSelectPolarity"></param> /// <param name="ChipSelectDelayMilliseconds"></param> /// <param name="InputMode">Chooses whether incoming data is sampled in the middle of the valid data period, or at the end. Most modern sensors produce valid output data in the middle of the waveform period.</param> public void Start(SPIMode Mode, double RateMHz, Pin ChipSelect = null, PinPolarity ChipSelectPolarity = PinPolarity.ActiveLow, int ChipSelectDelayMilliseconds = 0, SPISampleMode InputMode = SPISampleMode.Middle) { this.ChipSelect = ChipSelect; this.ChipSelectPolarity = ChipSelectPolarity; if(this.ChipSelect != null) { this.ChipSelect.MakeDigitalOutput(); if (ChipSelectPolarity == PinPolarity.ActiveLow) this.ChipSelect.DigitalValue = true; else this.ChipSelect.DigitalValue = false; } double SSPADD = (120.0 / RateMHz - 1); if (SSPADD > 255) { throw new Exception("SPI Rate out of limits. Valid rate is 46.875 kHz - 12 MHz"); } byte[] dataToSend = new byte[4]; dataToSend[0] = (byte)DeviceCommands.SPIConfig; dataToSend[1] = (byte)Mode; dataToSend[2] = (byte)InputMode; dataToSend[3] = (byte)SSPADD; device.sendCommsConfigPacket(dataToSend); }