/************************************************************************/
/*																		*/
/*	cm1kwire.h	--	I2c Driver for the CM1k chip			            */
/*	based on BSB_BrainCard												*/
/************************************************************************/
/*																		
 *	BraincardNeurons.cpp	--	Driver for the Braincard			        	
 *  revision 1.1, September 16, 2016
 *  Updated November 30, 2016 
 *	Copyright (c) 2016, General Vision Inc, All rights reserved	
 *
 * http://general-vision.com/documentation/TM_NeuroMem_Technology_Reference_Guide.pdf
 *
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors
 * may be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
/******************************************************************************/
#include "Wire.h"

extern "C" {
  #include <stdint.h>
}


const unsigned char CM1K=0x4A;
const int NCR=0x00;
const int COMP=0x01;
const int LCOMP=0x02;
const int DIST=0x03;
const int INDEXCOMP=0x03; 
const int CAT=0x04;
const int AIF=0x05;
const int MINIF=0x06;
const int MAXIF=0x07;
const int TESTCOMP=0x08;
const int TESTCAT=0x09;
const int NID=0x0A;
const int GCR=0x0B;
const int RESETCHAIN=0x0C;
const int NSR=0x0D;
const int NCOUNT=0x0F;	
const int FORGET=0x0F;

//CM1K reco logic registers
const int LEFT=0x11;
const int TOP=0x12;
const int NWIDTH=0x13;
const int NHEIGHT=0x14;
const int BWIDTH=0x15;
const int BHEIGHT=0x16;
const int RSR=0x1C;
const int RTDIST=0x1D;
const int RTCAT=0x1E;
const int ROIINIT=0x1F;

const int MAXVECLENGTH=256;

class cm1kwire
{
	public:
	
		cm1kwire();

		//R/W registers
		int Read(unsigned char module, unsigned char reg);
		void Write(unsigned char module, unsigned char reg, int value);

		//Operations on single vector
		void Broadcast(unsigned char vector[], int length);
		int Learn(unsigned char vector[], int length, int category);
		int BestMatch(unsigned char vector[], int length, int* distance, int* category, int* nid);
		int Recognize(unsigned char vector[], int length, int K, int distance[], int category[], int nid[]);

		//Loading and retrieval of neurons' content
		void ReadNeuron(int neuronID, unsigned char neuron[]);
		void ReadNeurons(unsigned char neurons[], int ncount);
		void WriteNeurons(unsigned char neurons[], int ncount);
		

	
		
		
		
};

