NM500 / NeuroShield

Dependents:   NeuroShield_SimpleScript NeuroShield_andIMU NeuroShield_Gesture_Recognition

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers NeuroShield.h Source File

NeuroShield.h

00001 /*
00002  * NeuroShield.cpp - Driver for NeuroShield
00003  * Copyright (c) 2016, General Vision Inc, All rights reserved
00004  * Copyright (c) 2017, nepes inc, All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  * 1. Redistributions of source code must retain the above copyright notice,
00010  * this list of conditions and the following disclaimer.
00011  *
00012  * 2. Redistributions in binary form must reproduce the above copyright notice,
00013  * this list of conditions and the following disclaimer in the documentation
00014  * and/or other materials provided with the distribution.
00015  *
00016  * 3. Neither the name of the copyright holder nor the names of its contributors
00017  * may be used to endorse or promote products derived from this software without
00018  * specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00021  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00024  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00025  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00026  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00029  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030  * POSSIBILITY OF SUCH DAMAGE.
00031  *
00032  */
00033 
00034 /*
00035  * Revision History (v1.1.5)
00036  * 2020/02/04    v1.1.5    Add dummy for switching between sd-card and nm spi
00037  * 2018/06/22    v1.1.4    Minor changes
00038  * 2018/01/03    v1.1.3    Add burst-mode read
00039  * 2017/12/20    v1.1.2    Modify the structure of neurondata
00040  * 2017/12/11    v1.1.1    Add Powersave command and Minor changes to the library
00041  * 2017/08/17    v1.0.0    First Release
00042  */
00043 
00044 #ifndef _NEUROSHIELD_H
00045 #define _NEUROSHIELD_H
00046 
00047 #include <NeuroShieldSPI.h>
00048 
00049 #define NM_NCR          0x00
00050 #define NM_COMP         0x01
00051 #define NM_LCOMP        0x02
00052 #define NM_DIST         0x03
00053 #define NM_INDEXCOMP    0x03
00054 #define NM_CAT          0x04
00055 #define NM_AIF          0x05
00056 #define NM_MINIF        0x06
00057 #define NM_MAXIF        0x07
00058 #define NM_TESTCOMP     0x08
00059 #define NM_TESTCAT      0x09
00060 #define NM_NID          0x0A
00061 #define NM_GCR          0x0B
00062 #define NM_RSTCHAIN     0x0C
00063 #define NM_NSR          0x0D
00064 #define NM_POWERSAVE    0x0E
00065 #define NM_NCOUNT       0x0F
00066 #define NM_FORGET       0x0F
00067 
00068 #define NEURON_SIZE     256     // memory capacity of each neuron in byte
00069 
00070 #define POWERSAVE       spi.write(NM_POWERSAVE, 1)
00071 
00072 class NeuroShield
00073 {
00074     public:
00075     
00076         NeuroShield();
00077         uint16_t begin();
00078         
00079         void setNcr(uint16_t value);
00080         uint16_t getNcr();
00081         void setComp(uint8_t value);
00082         uint8_t getComp();
00083         void setLastComp(uint8_t value);
00084         void setIndexComp(uint16_t value);
00085         uint16_t getDist();
00086         void setCat(uint16_t value);
00087         uint16_t getCat();
00088         void setAif(uint16_t value);
00089         uint16_t getAif();
00090         void setMinif(uint16_t value);
00091         uint16_t getMinif();
00092         void setMaxif(uint16_t value);
00093         uint16_t getMaxif();
00094         uint16_t getNid();
00095         void setGcr(uint16_t value);
00096         uint16_t getGcr();
00097         void resetChain();
00098         void setNsr(uint16_t value);
00099         uint16_t getNsr();
00100         uint16_t getNcount();
00101         void setPowerSave();
00102         void forget();
00103         void forget(uint16_t maxif);
00104         
00105         void countTotalNeurons();
00106         void clearNeurons();
00107         
00108         void setContext(uint8_t context);
00109         void setContext(uint8_t context, uint16_t minif, uint16_t maxif);
00110         void getContext(uint8_t* context, uint16_t* minif, uint16_t* maxif);
00111         void setRbfClassifier();
00112         void setKnnClassifier();
00113         
00114         uint16_t broadcast(uint8_t vector[], uint16_t length);
00115         uint16_t learn(uint8_t vector[], uint16_t length, uint16_t category);
00116         uint16_t classify(uint8_t vector[], uint16_t length);
00117         uint16_t classify(uint8_t vector[], uint16_t length, uint16_t* distance, uint16_t* category, uint16_t* nid);
00118         uint16_t classify(uint8_t vector[], uint16_t length, uint16_t k, uint16_t distance[], uint16_t category[], uint16_t nid[]);
00119         
00120         void readNeuron(uint16_t nid, uint16_t model[], uint16_t* ncr, uint16_t* aif, uint16_t* cat);
00121         void readNeuron(uint16_t nid, uint16_t nuerons[]);
00122         uint16_t readNeurons(uint16_t neurons[]);
00123         void readCompVector(uint16_t* data, uint16_t size);
00124         void writeNeurons(uint16_t neurons[], uint16_t ncount);
00125         void writeCompVector(uint16_t* data, uint16_t size);
00126         
00127         uint16_t testCommand(uint8_t read_write, uint8_t reg, uint16_t data);
00128         
00129         uint16_t fpgaVersion();
00130         void nm500Reset();
00131         void ledSelect(uint8_t data);
00132         
00133         uint16_t total_neurons;
00134         
00135     private:
00136         uint16_t support_burst_read;
00137 };
00138 #endif