Developing your own blocks for SpinCAD Designer

Software questions and issues with the FV-1

Moderator: frank

Post Reply
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Developing your own blocks for SpinCAD Designer

Post by Digital Larry »

Since I based SpinCAD Designer heavily on Andrew Kilpatrick's "ElmGen" Java project, and since Andrew released that code to open source under the GPL3 license, I am compelled to do the same when I begin my beta trial.

Here is a sneak peek at one of the simplest CAD blocks - the input CAD block.

Code: Select all

/* SpinCAD Designer - DSP Development Tool for the Spin FV-1
 * Copyright (C)2013 - Gary Worsham
 * Based on ElmGen by Andrew Kilpatrick
 * 
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 	
 */

package com.holycityaudio.SpinCAD.CADBlocks;

import java.awt.Color;

import com.holycityaudio.SpinCAD.SpinCADBlock;
import com.holycityaudio.SpinCAD.SpinCADPin;
import com.holycityaudio.SpinCAD.fxblocks.basic.SpinFXBlock;

public class InputCADBlock extends SpinCADBlock{

	/**
	 * 
	 */
	private static final long serialVersionUID = -4680315672929089295L;

	public InputCADBlock(int x, int y) {
		super(x, y);
		addOutputPin(this);
		addOutputPin(this);
		setName("Input");
		setBorderColor(Color.darkGray);
	}
	
	public void generateCode(SpinFXBlock eP) {
		System.out.println("Input codegen!");
		SpinCADPin p = this.getPin("Output 1");
		p.setRegister(ADCL);
		p = this.getPin("Output 2");
		p.setRegister(ADCR);
	}
}
Every SpinCAD block extends the SpinCADBlock class. I'll show that later but I wanted to zoom in on an actual block because those of you who are interested in SpinCAD will inevitably want to write your own blocks for it.

We'll skip the "super(x,y)" statement to start.

Code: Select all

		addOutputPin(this);
		addOutputPin(this);
		setName("Input");
		setBorderColor(Color.darkGray);
These 4 lines accomplish the following:
1) Add an output pin.
2) Add another output pin.
3) Set the name of this block to "Input"
4) Set the border color to dark gray. This color is used to draw the block.

So, for each type of block, you add pins (they can be input, output, control input, or control output), give the block a name (which is displayed on the block) and set the color.

You can also create intermediate classes to group your blocks according to some parameter. For example, ModulationCADBlocks are all green and have a minimum of one input pin, while POTCADBlocks are all pink and have a single control output.

Below this we have the "generateCode" function that is part of all SpinCADBlocks and is called every time we add or delete a block, make a connection, and for good measure, just before we run the simulator or save the Spin ASM file.

Code: Select all

	
public void generateCode(SpinFXBlock eP) {
		System.out.println("Input codegen!");
		SpinCADPin p = this.getPin("Output 1");
		p.setRegister(ADCL);
		p = this.getPin("Output 2");
		p.setRegister(ADCR);
	}
The InputCADBlock doesn't actually generate any code. If you dropped an InputCADBlock into your design, and it was the only thing there, and tried to run the simulator, nothing would happen.

However it DOES associate the Output 1 pin with FV-1 register ADCL and the Output 2 pin with register ADCR. You'll see how this is used when I describe the OutputCADBlock class.
Post Reply