Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: NeuroShield_SimpleScript NeuroShield_andIMU NeuroShield_Gesture_Recognition
NeuroShield.h@1:0c6bf23f2fc8, 2018-01-25 (annotated)
- Committer:
- nepes_ai
- Date:
- Thu Jan 25 02:20:37 2018 +0000
- Revision:
- 1:0c6bf23f2fc8
- Parent:
- 0:529602524696
- Child:
- 2:2812bcbcaaea
Release version 1.1.3; ; Add burst-mode read function; Modify HW/FPGA version information; Modify the structure of neurondata; Add POWERSAVE command
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| nepes_ai | 0:529602524696 | 1 | /* | 
| nepes_ai | 0:529602524696 | 2 | * NeuroShield.cpp - Driver for NeuroShield | 
| nepes_ai | 0:529602524696 | 3 | * Copyright (c) 2016, General Vision Inc, All rights reserved | 
| nepes_ai | 0:529602524696 | 4 | * Copyright (c) 2017, nepes inc, All rights reserved. | 
| nepes_ai | 0:529602524696 | 5 | * | 
| nepes_ai | 0:529602524696 | 6 | * Redistribution and use in source and binary forms, with or without | 
| nepes_ai | 0:529602524696 | 7 | * modification, are permitted provided that the following conditions are met: | 
| nepes_ai | 0:529602524696 | 8 | * | 
| nepes_ai | 0:529602524696 | 9 | * 1. Redistributions of source code must retain the above copyright notice, | 
| nepes_ai | 0:529602524696 | 10 | * this list of conditions and the following disclaimer. | 
| nepes_ai | 0:529602524696 | 11 | * | 
| nepes_ai | 0:529602524696 | 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, | 
| nepes_ai | 0:529602524696 | 13 | * this list of conditions and the following disclaimer in the documentation | 
| nepes_ai | 0:529602524696 | 14 | * and/or other materials provided with the distribution. | 
| nepes_ai | 0:529602524696 | 15 | * | 
| nepes_ai | 0:529602524696 | 16 | * 3. Neither the name of the copyright holder nor the names of its contributors | 
| nepes_ai | 0:529602524696 | 17 | * may be used to endorse or promote products derived from this software without | 
| nepes_ai | 0:529602524696 | 18 | * specific prior written permission. | 
| nepes_ai | 0:529602524696 | 19 | * | 
| nepes_ai | 0:529602524696 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
| nepes_ai | 0:529602524696 | 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
| nepes_ai | 0:529602524696 | 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 
| nepes_ai | 0:529602524696 | 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | 
| nepes_ai | 0:529602524696 | 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 
| nepes_ai | 0:529602524696 | 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 
| nepes_ai | 0:529602524696 | 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 
| nepes_ai | 0:529602524696 | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 
| nepes_ai | 0:529602524696 | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 
| nepes_ai | 0:529602524696 | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 
| nepes_ai | 0:529602524696 | 30 | * POSSIBILITY OF SUCH DAMAGE. | 
| nepes_ai | 0:529602524696 | 31 | * | 
| nepes_ai | 0:529602524696 | 32 | */ | 
| nepes_ai | 0:529602524696 | 33 | |
| nepes_ai | 1:0c6bf23f2fc8 | 34 | /* | 
| nepes_ai | 1:0c6bf23f2fc8 | 35 | * Revision History (v1.1.3) | 
| nepes_ai | 1:0c6bf23f2fc8 | 36 | * 2018/01/03 v1.1.3 Add burst-mode read | 
| nepes_ai | 1:0c6bf23f2fc8 | 37 | * 2017/12/20 v1.1.2 Modify the structure of neurondata | 
| nepes_ai | 1:0c6bf23f2fc8 | 38 | * 2017/12/11 v1.1.1 Add Powersave command and Minor changes to the library | 
| nepes_ai | 1:0c6bf23f2fc8 | 39 | * 2017/08/17 v1.0.0 First Release | 
| nepes_ai | 1:0c6bf23f2fc8 | 40 | */ | 
| nepes_ai | 1:0c6bf23f2fc8 | 41 | |
| nepes_ai | 0:529602524696 | 42 | #ifndef _NEUROSHIELD_H | 
| nepes_ai | 0:529602524696 | 43 | #define _NEUROSHIELD_H | 
| nepes_ai | 0:529602524696 | 44 | |
| nepes_ai | 0:529602524696 | 45 | #include <NeuroShieldSPI.h> | 
| nepes_ai | 0:529602524696 | 46 | |
| nepes_ai | 0:529602524696 | 47 | #define NM_NCR 0x00 | 
| nepes_ai | 0:529602524696 | 48 | #define NM_COMP 0x01 | 
| nepes_ai | 0:529602524696 | 49 | #define NM_LCOMP 0x02 | 
| nepes_ai | 0:529602524696 | 50 | #define NM_DIST 0x03 | 
| nepes_ai | 0:529602524696 | 51 | #define NM_INDEXCOMP 0x03 | 
| nepes_ai | 0:529602524696 | 52 | #define NM_CAT 0x04 | 
| nepes_ai | 0:529602524696 | 53 | #define NM_AIF 0x05 | 
| nepes_ai | 0:529602524696 | 54 | #define NM_MINIF 0x06 | 
| nepes_ai | 0:529602524696 | 55 | #define NM_MAXIF 0x07 | 
| nepes_ai | 0:529602524696 | 56 | #define NM_TESTCOMP 0x08 | 
| nepes_ai | 0:529602524696 | 57 | #define NM_TESTCAT 0x09 | 
| nepes_ai | 0:529602524696 | 58 | #define NM_NID 0x0A | 
| nepes_ai | 0:529602524696 | 59 | #define NM_GCR 0x0B | 
| nepes_ai | 0:529602524696 | 60 | #define NM_RSTCHAIN 0x0C | 
| nepes_ai | 0:529602524696 | 61 | #define NM_NSR 0x0D | 
| nepes_ai | 0:529602524696 | 62 | #define NM_POWERSAVE 0x0E | 
| nepes_ai | 0:529602524696 | 63 | #define NM_NCOUNT 0x0F | 
| nepes_ai | 0:529602524696 | 64 | #define NM_FORGET 0x0F | 
| nepes_ai | 0:529602524696 | 65 | |
| nepes_ai | 0:529602524696 | 66 | #define NEURON_SIZE 256 // memory capacity of each neuron in byte | 
| nepes_ai | 0:529602524696 | 67 | |
| nepes_ai | 1:0c6bf23f2fc8 | 68 | #define POWERSAVE spi.write(NM_POWERSAVE, 1) | 
| nepes_ai | 1:0c6bf23f2fc8 | 69 | |
| nepes_ai | 0:529602524696 | 70 | class NeuroShield | 
| nepes_ai | 0:529602524696 | 71 | { | 
| nepes_ai | 0:529602524696 | 72 | public: | 
| nepes_ai | 0:529602524696 | 73 | |
| nepes_ai | 0:529602524696 | 74 | NeuroShield(); | 
| nepes_ai | 0:529602524696 | 75 | uint16_t begin(); | 
| nepes_ai | 0:529602524696 | 76 | |
| nepes_ai | 0:529602524696 | 77 | void setNcr(uint16_t value); | 
| nepes_ai | 0:529602524696 | 78 | uint16_t getNcr(); | 
| nepes_ai | 0:529602524696 | 79 | void setComp(uint8_t value); | 
| nepes_ai | 0:529602524696 | 80 | uint8_t getComp(); | 
| nepes_ai | 0:529602524696 | 81 | void setLastComp(uint8_t value); | 
| nepes_ai | 0:529602524696 | 82 | void setIndexComp(uint16_t value); | 
| nepes_ai | 0:529602524696 | 83 | uint16_t getDist(); | 
| nepes_ai | 0:529602524696 | 84 | void setCat(uint16_t value); | 
| nepes_ai | 0:529602524696 | 85 | uint16_t getCat(); | 
| nepes_ai | 0:529602524696 | 86 | void setAif(uint16_t value); | 
| nepes_ai | 0:529602524696 | 87 | uint16_t getAif(); | 
| nepes_ai | 0:529602524696 | 88 | void setMinif(uint16_t value); | 
| nepes_ai | 0:529602524696 | 89 | uint16_t getMinif(); | 
| nepes_ai | 0:529602524696 | 90 | void setMaxif(uint16_t value); | 
| nepes_ai | 0:529602524696 | 91 | uint16_t getMaxif(); | 
| nepes_ai | 0:529602524696 | 92 | uint16_t getNid(); | 
| nepes_ai | 0:529602524696 | 93 | void setGcr(uint16_t value); | 
| nepes_ai | 0:529602524696 | 94 | uint16_t getGcr(); | 
| nepes_ai | 0:529602524696 | 95 | void resetChain(); | 
| nepes_ai | 0:529602524696 | 96 | void setNsr(uint16_t value); | 
| nepes_ai | 0:529602524696 | 97 | uint16_t getNsr(); | 
| nepes_ai | 0:529602524696 | 98 | uint16_t getNcount(); | 
| nepes_ai | 0:529602524696 | 99 | void setPowerSave(); | 
| nepes_ai | 0:529602524696 | 100 | void forget(); | 
| nepes_ai | 0:529602524696 | 101 | void forget(uint16_t maxif); | 
| nepes_ai | 0:529602524696 | 102 | |
| nepes_ai | 0:529602524696 | 103 | void countTotalNeurons(); | 
| nepes_ai | 0:529602524696 | 104 | void clearNeurons(); | 
| nepes_ai | 0:529602524696 | 105 | |
| nepes_ai | 0:529602524696 | 106 | void setContext(uint8_t context); | 
| nepes_ai | 0:529602524696 | 107 | void setContext(uint8_t context, uint16_t minif, uint16_t maxif); | 
| nepes_ai | 0:529602524696 | 108 | void getContext(uint8_t* context, uint16_t* minif, uint16_t* maxif); | 
| nepes_ai | 0:529602524696 | 109 | void setRbfClassifier(); | 
| nepes_ai | 0:529602524696 | 110 | void setKnnClassifier(); | 
| nepes_ai | 0:529602524696 | 111 | |
| nepes_ai | 0:529602524696 | 112 | uint16_t broadcast(uint8_t vector[], uint16_t length); | 
| nepes_ai | 0:529602524696 | 113 | uint16_t learn(uint8_t vector[], uint16_t length, uint16_t category); | 
| nepes_ai | 0:529602524696 | 114 | uint16_t classify(uint8_t vector[], uint16_t length); | 
| nepes_ai | 0:529602524696 | 115 | uint16_t classify(uint8_t vector[], uint16_t length, uint16_t* distance, uint16_t* category, uint16_t* nid); | 
| nepes_ai | 0:529602524696 | 116 | uint16_t classify(uint8_t vector[], uint16_t length, uint16_t k, uint16_t distance[], uint16_t category[], uint16_t nid[]); | 
| nepes_ai | 0:529602524696 | 117 | |
| nepes_ai | 1:0c6bf23f2fc8 | 118 | void readNeuron(uint16_t nid, uint16_t model[], uint16_t* ncr, uint16_t* aif, uint16_t* cat); | 
| nepes_ai | 1:0c6bf23f2fc8 | 119 | void readNeuron(uint16_t nid, uint16_t nuerons[]); | 
| nepes_ai | 1:0c6bf23f2fc8 | 120 | uint16_t readNeurons(uint16_t neurons[]); | 
| nepes_ai | 1:0c6bf23f2fc8 | 121 | void readCompVector(uint16_t* data, uint16_t size); | 
| nepes_ai | 1:0c6bf23f2fc8 | 122 | void writeNeurons(uint16_t neurons[], uint16_t ncount); | 
| nepes_ai | 1:0c6bf23f2fc8 | 123 | void writeCompVector(uint16_t* data, uint16_t size); | 
| nepes_ai | 0:529602524696 | 124 | |
| nepes_ai | 0:529602524696 | 125 | uint16_t testCommand(uint8_t read_write, uint8_t reg, uint16_t data); | 
| nepes_ai | 0:529602524696 | 126 | |
| nepes_ai | 0:529602524696 | 127 | uint16_t fpgaVersion(); | 
| nepes_ai | 0:529602524696 | 128 | void nm500Reset(); | 
| nepes_ai | 0:529602524696 | 129 | void ledSelect(uint8_t data); | 
| nepes_ai | 0:529602524696 | 130 | |
| nepes_ai | 1:0c6bf23f2fc8 | 131 | uint16_t total_neurons; | 
| nepes_ai | 0:529602524696 | 132 | |
| nepes_ai | 1:0c6bf23f2fc8 | 133 | private: | 
| nepes_ai | 1:0c6bf23f2fc8 | 134 | uint16_t support_burst_read; | 
| nepes_ai | 0:529602524696 | 135 | }; | 
| nepes_ai | 0:529602524696 | 136 | #endif |