Spin Semiconductor Forum Index Spin Semiconductor
Support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Developing your own blocks for SpinCAD Designer

 
Post new topic   Reply to topic    Spin Semiconductor Forum Index -> FV-1 software questions
View previous topic :: View next topic  
Author Message
Digital Larry



Joined: 12 Nov 2012
Posts: 274

PostPosted: Tue Apr 30, 2013 5:25 am    Post subject: Developing your own blocks for SpinCAD Designer Reply with quote

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:
/* 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:

      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:
   
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.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Spin Semiconductor Forum Index -> FV-1 software questions All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group