Developing your own blocks for SpinCAD Designer

Software questions and issues with the FV-1

Moderator: frank

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

Developing your own blocks for SpinCAD Designer

Post by Digital Larry » Tue Apr 30, 2013 6:25 am

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&#58;//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&#123;

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

	public InputCADBlock&#40;int x, int y&#41; &#123;
		super&#40;x, y&#41;;
		addOutputPin&#40;this&#41;;
		addOutputPin&#40;this&#41;;
		setName&#40;"Input"&#41;;
		setBorderColor&#40;Color.darkGray&#41;;
	&#125;
	
	public void generateCode&#40;SpinFXBlock eP&#41; &#123;
		System.out.println&#40;"Input codegen!"&#41;;
		SpinCADPin p = this.getPin&#40;"Output 1"&#41;;
		p.setRegister&#40;ADCL&#41;;
		p = this.getPin&#40;"Output 2"&#41;;
		p.setRegister&#40;ADCR&#41;;
	&#125;
&#125;
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&#40;this&#41;;
		addOutputPin&#40;this&#41;;
		setName&#40;"Input"&#41;;
		setBorderColor&#40;Color.darkGray&#41;;
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&#40;SpinFXBlock eP&#41; &#123;
		System.out.println&#40;"Input codegen!"&#41;;
		SpinCADPin p = this.getPin&#40;"Output 1"&#41;;
		p.setRegister&#40;ADCL&#41;;
		p = this.getPin&#40;"Output 2"&#41;;
		p.setRegister&#40;ADCR&#41;;
	&#125;
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