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@3:6163399b611e, 2020-02-11 (annotated)
- Committer:
- nepes_ai
- Date:
- Tue Feb 11 00:48:18 2020 +0000
- Revision:
- 3:6163399b611e
- Parent:
- 2:2812bcbcaaea
Release version 1.1.5
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 | 3:6163399b611e | 35 | * Revision History (v1.1.5) |
nepes_ai | 3:6163399b611e | 36 | * 2020/02/04 v1.1.5 Add dummy for switching between sd-card and nm spi |
nepes_ai | 2:2812bcbcaaea | 37 | * 2018/06/22 v1.1.4 Minor changes |
nepes_ai | 1:0c6bf23f2fc8 | 38 | * 2018/01/03 v1.1.3 Add burst-mode read |
nepes_ai | 1:0c6bf23f2fc8 | 39 | * 2017/12/20 v1.1.2 Modify the structure of neurondata |
nepes_ai | 1:0c6bf23f2fc8 | 40 | * 2017/12/11 v1.1.1 Add Powersave command and Minor changes to the library |
nepes_ai | 1:0c6bf23f2fc8 | 41 | * 2017/08/17 v1.0.0 First Release |
nepes_ai | 1:0c6bf23f2fc8 | 42 | */ |
nepes_ai | 1:0c6bf23f2fc8 | 43 | |
nepes_ai | 0:529602524696 | 44 | #ifndef _NEUROSHIELD_H |
nepes_ai | 0:529602524696 | 45 | #define _NEUROSHIELD_H |
nepes_ai | 0:529602524696 | 46 | |
nepes_ai | 0:529602524696 | 47 | #include <NeuroShieldSPI.h> |
nepes_ai | 0:529602524696 | 48 | |
nepes_ai | 0:529602524696 | 49 | #define NM_NCR 0x00 |
nepes_ai | 0:529602524696 | 50 | #define NM_COMP 0x01 |
nepes_ai | 0:529602524696 | 51 | #define NM_LCOMP 0x02 |
nepes_ai | 0:529602524696 | 52 | #define NM_DIST 0x03 |
nepes_ai | 0:529602524696 | 53 | #define NM_INDEXCOMP 0x03 |
nepes_ai | 0:529602524696 | 54 | #define NM_CAT 0x04 |
nepes_ai | 0:529602524696 | 55 | #define NM_AIF 0x05 |
nepes_ai | 0:529602524696 | 56 | #define NM_MINIF 0x06 |
nepes_ai | 0:529602524696 | 57 | #define NM_MAXIF 0x07 |
nepes_ai | 0:529602524696 | 58 | #define NM_TESTCOMP 0x08 |
nepes_ai | 0:529602524696 | 59 | #define NM_TESTCAT 0x09 |
nepes_ai | 0:529602524696 | 60 | #define NM_NID 0x0A |
nepes_ai | 0:529602524696 | 61 | #define NM_GCR 0x0B |
nepes_ai | 0:529602524696 | 62 | #define NM_RSTCHAIN 0x0C |
nepes_ai | 0:529602524696 | 63 | #define NM_NSR 0x0D |
nepes_ai | 0:529602524696 | 64 | #define NM_POWERSAVE 0x0E |
nepes_ai | 0:529602524696 | 65 | #define NM_NCOUNT 0x0F |
nepes_ai | 0:529602524696 | 66 | #define NM_FORGET 0x0F |
nepes_ai | 0:529602524696 | 67 | |
nepes_ai | 0:529602524696 | 68 | #define NEURON_SIZE 256 // memory capacity of each neuron in byte |
nepes_ai | 0:529602524696 | 69 | |
nepes_ai | 1:0c6bf23f2fc8 | 70 | #define POWERSAVE spi.write(NM_POWERSAVE, 1) |
nepes_ai | 1:0c6bf23f2fc8 | 71 | |
nepes_ai | 0:529602524696 | 72 | class NeuroShield |
nepes_ai | 0:529602524696 | 73 | { |
nepes_ai | 0:529602524696 | 74 | public: |
nepes_ai | 0:529602524696 | 75 | |
nepes_ai | 0:529602524696 | 76 | NeuroShield(); |
nepes_ai | 0:529602524696 | 77 | uint16_t begin(); |
nepes_ai | 0:529602524696 | 78 | |
nepes_ai | 0:529602524696 | 79 | void setNcr(uint16_t value); |
nepes_ai | 0:529602524696 | 80 | uint16_t getNcr(); |
nepes_ai | 0:529602524696 | 81 | void setComp(uint8_t value); |
nepes_ai | 0:529602524696 | 82 | uint8_t getComp(); |
nepes_ai | 0:529602524696 | 83 | void setLastComp(uint8_t value); |
nepes_ai | 0:529602524696 | 84 | void setIndexComp(uint16_t value); |
nepes_ai | 0:529602524696 | 85 | uint16_t getDist(); |
nepes_ai | 0:529602524696 | 86 | void setCat(uint16_t value); |
nepes_ai | 0:529602524696 | 87 | uint16_t getCat(); |
nepes_ai | 0:529602524696 | 88 | void setAif(uint16_t value); |
nepes_ai | 0:529602524696 | 89 | uint16_t getAif(); |
nepes_ai | 0:529602524696 | 90 | void setMinif(uint16_t value); |
nepes_ai | 0:529602524696 | 91 | uint16_t getMinif(); |
nepes_ai | 0:529602524696 | 92 | void setMaxif(uint16_t value); |
nepes_ai | 0:529602524696 | 93 | uint16_t getMaxif(); |
nepes_ai | 0:529602524696 | 94 | uint16_t getNid(); |
nepes_ai | 0:529602524696 | 95 | void setGcr(uint16_t value); |
nepes_ai | 0:529602524696 | 96 | uint16_t getGcr(); |
nepes_ai | 0:529602524696 | 97 | void resetChain(); |
nepes_ai | 0:529602524696 | 98 | void setNsr(uint16_t value); |
nepes_ai | 0:529602524696 | 99 | uint16_t getNsr(); |
nepes_ai | 0:529602524696 | 100 | uint16_t getNcount(); |
nepes_ai | 0:529602524696 | 101 | void setPowerSave(); |
nepes_ai | 0:529602524696 | 102 | void forget(); |
nepes_ai | 0:529602524696 | 103 | void forget(uint16_t maxif); |
nepes_ai | 0:529602524696 | 104 | |
nepes_ai | 0:529602524696 | 105 | void countTotalNeurons(); |
nepes_ai | 0:529602524696 | 106 | void clearNeurons(); |
nepes_ai | 0:529602524696 | 107 | |
nepes_ai | 0:529602524696 | 108 | void setContext(uint8_t context); |
nepes_ai | 0:529602524696 | 109 | void setContext(uint8_t context, uint16_t minif, uint16_t maxif); |
nepes_ai | 0:529602524696 | 110 | void getContext(uint8_t* context, uint16_t* minif, uint16_t* maxif); |
nepes_ai | 0:529602524696 | 111 | void setRbfClassifier(); |
nepes_ai | 0:529602524696 | 112 | void setKnnClassifier(); |
nepes_ai | 0:529602524696 | 113 | |
nepes_ai | 0:529602524696 | 114 | uint16_t broadcast(uint8_t vector[], uint16_t length); |
nepes_ai | 0:529602524696 | 115 | uint16_t learn(uint8_t vector[], uint16_t length, uint16_t category); |
nepes_ai | 0:529602524696 | 116 | uint16_t classify(uint8_t vector[], uint16_t length); |
nepes_ai | 0:529602524696 | 117 | uint16_t classify(uint8_t vector[], uint16_t length, uint16_t* distance, uint16_t* category, uint16_t* nid); |
nepes_ai | 0:529602524696 | 118 | 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 | 119 | |
nepes_ai | 1:0c6bf23f2fc8 | 120 | void readNeuron(uint16_t nid, uint16_t model[], uint16_t* ncr, uint16_t* aif, uint16_t* cat); |
nepes_ai | 1:0c6bf23f2fc8 | 121 | void readNeuron(uint16_t nid, uint16_t nuerons[]); |
nepes_ai | 1:0c6bf23f2fc8 | 122 | uint16_t readNeurons(uint16_t neurons[]); |
nepes_ai | 1:0c6bf23f2fc8 | 123 | void readCompVector(uint16_t* data, uint16_t size); |
nepes_ai | 1:0c6bf23f2fc8 | 124 | void writeNeurons(uint16_t neurons[], uint16_t ncount); |
nepes_ai | 1:0c6bf23f2fc8 | 125 | void writeCompVector(uint16_t* data, uint16_t size); |
nepes_ai | 0:529602524696 | 126 | |
nepes_ai | 0:529602524696 | 127 | uint16_t testCommand(uint8_t read_write, uint8_t reg, uint16_t data); |
nepes_ai | 0:529602524696 | 128 | |
nepes_ai | 0:529602524696 | 129 | uint16_t fpgaVersion(); |
nepes_ai | 0:529602524696 | 130 | void nm500Reset(); |
nepes_ai | 0:529602524696 | 131 | void ledSelect(uint8_t data); |
nepes_ai | 0:529602524696 | 132 | |
nepes_ai | 1:0c6bf23f2fc8 | 133 | uint16_t total_neurons; |
nepes_ai | 0:529602524696 | 134 | |
nepes_ai | 1:0c6bf23f2fc8 | 135 | private: |
nepes_ai | 1:0c6bf23f2fc8 | 136 | uint16_t support_burst_read; |
nepes_ai | 0:529602524696 | 137 | }; |
nepes_ai | 0:529602524696 | 138 | #endif |