├── Additional results on feature extraction method.docx ├── Deployment ├── Source_DS_CNN_7layers_76f │ ├── DA7212.cpp │ ├── DA7212.h │ ├── DS_CNN │ │ ├── ds_cnn.cpp │ │ ├── ds_cnn.h │ │ ├── ds_cnn_weights - Copy.h │ │ └── ds_cnn_weights.h │ ├── KWS_DS_CNN │ │ ├── kws_ds_cnn.cpp │ │ └── kws_ds_cnn.h │ ├── LOG_MEL │ │ ├── log_mel.cpp │ │ └── log_mel.h │ ├── ds_cnn_main │ │ ├── main.cpp │ │ ├── wav_data.h │ │ ├── wav_data1.h │ │ └── wav_data_stop.h │ └── f87f06292637 │ │ ├── .hg_archival.txt │ │ ├── Display │ │ ├── LCD.cpp │ │ ├── LCD.h │ │ ├── TFT.cpp │ │ ├── TFT.h │ │ ├── TFT932x.cpp │ │ └── TFT932x.h │ │ ├── Font │ │ ├── Arial12x12.h │ │ ├── Arial24x23.h │ │ ├── Arial28x28.h │ │ ├── Arial43x48_numb.h │ │ └── Terminal6x8.h │ │ ├── Graphics │ │ ├── GraphicsDisplay.cpp │ │ ├── GraphicsDisplay.h │ │ ├── TextDisplay.cpp │ │ └── TextDisplay.h │ │ ├── Inits │ │ ├── ILI9327.cpp │ │ ├── ILI9327.h │ │ ├── ILI932x.cpp │ │ ├── ILI932x.h │ │ ├── ILI9341.cpp │ │ ├── ILI9341.h │ │ ├── ILI9486.cpp │ │ ├── ILI9486.h │ │ ├── IST3020.cpp │ │ ├── IST3020.h │ │ ├── S6D04D1.cpp │ │ ├── S6D04D1.h │ │ ├── SEPS225.cpp │ │ ├── SEPS225.h │ │ ├── SSD1306.cpp │ │ ├── SSD1306.h │ │ ├── ST7565.cpp │ │ ├── ST7565.h │ │ ├── TFT_MIPI.cpp │ │ ├── TFT_MIPI.h │ │ ├── UC1608.cpp │ │ └── UC1608.h │ │ └── Protocols │ │ ├── BUS16.cpp │ │ ├── BUS16.h │ │ ├── BUS8.cpp │ │ ├── BUS8.h │ │ ├── I2C_bus.cpp │ │ ├── I2C_bus.h │ │ ├── PAR16.cpp │ │ ├── PAR16.h │ │ ├── PAR8.cpp │ │ ├── PAR8.h │ │ ├── Protocols.h │ │ ├── SPI16.cpp │ │ ├── SPI16.h │ │ ├── SPI8.cpp │ │ └── SPI8.h └── arm_depthwise_separable_conv_HWC_q7_nonsquare.c ├── LICENSE ├── README.md ├── __pycache__ ├── input_data.cpython-36.pyc └── models.cpython-36.pyc ├── auto_test_streaming.py ├── freeze.py ├── generate_streaming_test_wav.py ├── get_activations.py ├── get_weights.py ├── input_data.py ├── models.py ├── quant_weights.py ├── train.py ├── trainTest.py ├── trainTest_quant.py └── work └── DS_CNN └── DS_CNN_7layers_76f_wSize_20ms_wStride_20ms ├── retrain_logs └── train │ ├── events.out.tfevents.1549397696.DESKTOP-PE4UDT9 │ ├── events.out.tfevents.1549397772.DESKTOP-PE4UDT9 │ └── events.out.tfevents.1549397791.DESKTOP-PE4UDT9 └── training ├── ds_cnn.pbtxt └── ds_cnn_labels.txt /Additional results on feature extraction method.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterMS123/KWS-DS-CNN-for-embedded/dd78e3daa2db067a5583776422db49154ffeb9ae/Additional results on feature extraction method.docx -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/DS_CNN/ds_cnn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Arm Limited or its affiliates. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the License); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | ************************************************************************** 19 | * 20 | * Modifications Copyright 2018 Peter Mølgaard Sørensen 21 | * Implementation of depthwise separable CNN instead of DNN 22 | */ 23 | 24 | #ifndef KWS_DS_CNN_H 25 | #define KWS_DS_CNN_H 26 | 27 | #include "ds_cnn_weights.h" 28 | #include "arm_nnfunctions.h" 29 | #include "arm_math.h" 30 | #include "log_mel.h" 31 | #include "mbed.h" 32 | /* Network Structure 33 | 34 | 49x20 input features 35 | | 36 | CONV1: 2D convolution with 76 kernels (10x4). T_stride = 2, F_stride = 1 (ReLu actication) -> Output size (25*20*76) 37 | | 38 | Depthwise convolution 1, 76 kernels (3x3), T_stride =2, F_stride = 2 (ReLu actication) -> Output size (13*10*76) 39 | | 40 | Pointwise convolution 1, 76 kernels (1x1), T_stride =1, F_stride = 1 (ReLu actication) -> Output size (13*10*76) 41 | | 42 | Depthwise convolution 2, 76 kernels (3x3), T_stride =1, F_stride = 1 (ReLu actication) -> Output size (13*10*76) 43 | | 44 | Pointwise convolution 2, 76 kernels (1x1), T_stride =1, F_stride = 1 (ReLu actication) -> Output size (13*10*76) 45 | | 46 | Depthwise convolution 3, 76 kernels (3x3), T_stride =1, F_stride = 1 (ReLu actication) -> Output size (13*10*76) 47 | | 48 | Pointwise convolution 3, 76 kernels (1x1), T_stride =1, F_stride = 1 (ReLu actication) -> Output size (13*10*76) 49 | | 50 | Depthwise convolution 4, 76 kernels (3x3), T_stride =1, F_stride = 1 (ReLu actication) -> Output size (13*10*76) 51 | | 52 | Pointwise convolution 4, 76 kernels (1x1), T_stride =1, F_stride = 1 (ReLu actication) -> Output size (13*10*76) 53 | | 54 | Depthwise convolution 5, 76 kernels (3x3), T_stride =1, F_stride = 1 (ReLu actication) -> Output size (13*10*76) 55 | | 56 | Pointwise convolution 5, 76 kernels (1x1), T_stride =1, F_stride = 1 (ReLu actication) -> Output size (13*10*76) 57 | | 58 | Depthwise convolution 6, 76 kernels (3x3), T_stride =1, F_stride = 1 (ReLu actication) -> Output size (13*10*76) 59 | | 60 | Pointwise convolution 6, 76 kernels (1x1), T_stride =1, F_stride = 1 (ReLu actication) -> Output size (13*10*76) 61 | | 62 | Average pooling, window size (13*10) -> Output size (76) 63 | | 64 | Fully Connected layer, 12 output nodes (Softmax activation) 65 | 66 | */ 67 | 68 | #define IN_DIM (NUM_FRAMES*NUM_FBANK_BINS) 69 | #define OUT_DIM 12 70 | #define CONV1_OUT_DIM (25*20*76) 71 | #define DW_CONV_OUT_DIM (13*10*76) 72 | #define PW_CONV_OUT_DIM (13*10*76) 73 | #define AVG_POOL_OUT_DIM 76 74 | #define CONV1_WT_DIM (10*4*76) 75 | #define CONV1_BIAS_DIM 76 76 | #define DW_CONV_WT_DIM (3*3*76) 77 | #define DW_CONV_BIAS_DIM 76 78 | #define PW_CONV_WT_DIM (76*76) 79 | #define PW_CONV_BIAS_DIM 76 80 | #define FC_WT_DIM (12*76) 81 | #define FC_BIAS_DIM 12 82 | #define VEC_BUFFER_MAX (2*10*4*76) 83 | #define SCRATCH_BUFFER_SIZE (CONV1_OUT_DIM + DW_CONV_OUT_DIM + VEC_BUFFER_MAX) 84 | 85 | // Layer 1 parameters 86 | #define CONV1_IN_DIM_X 20 // Frequency along x-axis 87 | #define CONV1_IN_DIM_Y 49 // Time along y-axis 88 | #define CONV1_IN_CH 76 // Fake, actually 1 89 | #define CONV1_KERNEL_DIM_X 4 90 | #define CONV1_KERNEL_DIM_Y 10 91 | #define CONV1_PADDING_X 1 // Left side padding 92 | #define CONV1_PADDING_Y 4 // Top padding 93 | #define CONV1_STRIDE_X 1 94 | #define CONV1_STRIDE_Y 2 95 | #define CONV1_OUT_DIM_X 20 // Frequency along x-axis 96 | #define CONV1_OUT_DIM_Y 25 // Time along y-axis 97 | #define CONV1_OUT_CH 76 98 | 99 | // Layer 2 depthwise parameters 100 | #define DW_CONV1_IN_DIM_X 20 // Frequency along x-axis 101 | #define DW_CONV1_IN_DIM_Y 25 // Time along y-axis 102 | #define DW_CONV_IN_CH 76 103 | #define DW_CONV_KERNEL_DIM_X 3 104 | #define DW_CONV_KERNEL_DIM_Y 3 105 | #define DW_CONV1_PADDING_X 0 // Left side padding 106 | #define DW_CONV1_PADDING_Y 1 // Top padding 107 | #define DW_CONV1_STRIDE_X 2 108 | #define DW_CONV1_STRIDE_Y 2 109 | #define DW_CONV_OUT_DIM_X 10 // Frequency along x-axis 110 | #define DW_CONV_OUT_DIM_Y 13 // Time along y-axis 111 | #define DW_CONV_OUT_CH 76 112 | 113 | //layer 3-5 depthwise paramters 114 | #define DW_CONV_IN_DIM_X 10 // Frequency along x-axis 115 | #define DW_CONV_IN_DIM_Y 13 // Time along y-axis 116 | #define DW_CONV_PADDING_X 1 // Left side padding 117 | #define DW_CONV_PADDING_Y 1 // Top padding 118 | #define DW_CONV_STRIDE_X 1 119 | #define DW_CONV_STRIDE_Y 1 120 | 121 | 122 | // Pointwise conv paramters 123 | #define PW_CONV_IN_DIM_X 10 // Frequency along x-axis 124 | #define PW_CONV_IN_DIM_Y 13 // Time along y-axis 125 | #define PW_CONV_IN_CH 76 126 | #define PW_CONV_KERNEL_DIM_X 1 127 | #define PW_CONV_KERNEL_DIM_Y 1 128 | #define PW_CONV_PADDING_X 0 // Left side padding 129 | #define PW_CONV_PADDING_Y 0 // Top padding 130 | #define PW_CONV_STRIDE_X 1 131 | #define PW_CONV_STRIDE_Y 1 132 | #define PW_CONV_OUT_DIM_X 10 // Frequency along x-axis 133 | #define PW_CONV_OUT_DIM_Y 13 // Time along y-axis 134 | #define PW_CONV_OUT_CH 76 135 | 136 | 137 | 138 | class DS_CNN { 139 | 140 | public: 141 | DS_CNN(q7_t* scratch_pad); 142 | ~DS_CNN(); 143 | void run_nn(q7_t* in_data, q7_t* out_data); 144 | 145 | private: 146 | 147 | q7_t* conv1_out; 148 | q7_t* dw_conv1_out; 149 | q7_t* pw_conv1_out; 150 | q7_t* dw_conv2_out; 151 | q7_t* pw_conv2_out; 152 | q7_t* dw_conv3_out; 153 | q7_t* pw_conv3_out; 154 | q7_t* dw_conv4_out; 155 | q7_t* pw_conv4_out; 156 | q7_t* dw_conv5_out; 157 | q7_t* pw_conv5_out; 158 | q7_t* dw_conv6_out; 159 | q7_t* pw_conv6_out; 160 | q7_t* avg_pool_out; 161 | q7_t* fc_out; 162 | q15_t* vec_buffer; 163 | static q7_t const conv1_wt[CONV1_WT_DIM]; 164 | static q7_t const conv1_bias[CONV1_BIAS_DIM]; 165 | static q7_t const dw_conv1_wt[DW_CONV_WT_DIM]; 166 | static q7_t const dw_conv1_bias[DW_CONV_BIAS_DIM]; 167 | static q7_t const pw_conv1_wt[PW_CONV_WT_DIM]; 168 | static q7_t const pw_conv1_bias[PW_CONV_BIAS_DIM]; 169 | static q7_t const dw_conv2_wt[DW_CONV_WT_DIM]; 170 | static q7_t const dw_conv2_bias[DW_CONV_BIAS_DIM]; 171 | static q7_t const pw_conv2_wt[PW_CONV_WT_DIM]; 172 | static q7_t const pw_conv2_bias[PW_CONV_BIAS_DIM]; 173 | static q7_t const dw_conv3_wt[DW_CONV_WT_DIM]; 174 | static q7_t const dw_conv3_bias[DW_CONV_BIAS_DIM]; 175 | static q7_t const pw_conv3_wt[PW_CONV_WT_DIM]; 176 | static q7_t const pw_conv3_bias[PW_CONV_BIAS_DIM]; 177 | static q7_t const dw_conv4_wt[DW_CONV_WT_DIM]; 178 | static q7_t const dw_conv4_bias[DW_CONV_BIAS_DIM]; 179 | static q7_t const pw_conv4_wt[PW_CONV_WT_DIM]; 180 | static q7_t const pw_conv4_bias[PW_CONV_BIAS_DIM]; 181 | static q7_t const dw_conv5_wt[DW_CONV_WT_DIM]; 182 | static q7_t const dw_conv5_bias[DW_CONV_BIAS_DIM]; 183 | static q7_t const pw_conv5_wt[PW_CONV_WT_DIM]; 184 | static q7_t const pw_conv5_bias[PW_CONV_BIAS_DIM]; 185 | static q7_t const dw_conv6_wt[DW_CONV_WT_DIM]; 186 | static q7_t const dw_conv6_bias[DW_CONV_BIAS_DIM]; 187 | static q7_t const pw_conv6_wt[PW_CONV_WT_DIM]; 188 | static q7_t const pw_conv6_bias[PW_CONV_BIAS_DIM]; 189 | static q7_t const fc_wt[FC_WT_DIM]; 190 | static q7_t const fc_bias[FC_BIAS_DIM]; 191 | 192 | 193 | 194 | }; 195 | 196 | #endif 197 | -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/KWS_DS_CNN/kws_ds_cnn.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Arm Limited or its affiliates. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the License); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | ************************************************************************** 19 | * 20 | * Modifications Copyright 2018 Peter Mølgaard Sørensen 21 | * KWS system uses MFSC (log-mel) features instead of MFCC. DNN classifier replaced with depthwise separable CNN 22 | */ 23 | 24 | /* 25 | * Description: Keyword spotting example code using MFSC feature extraction 26 | * and DS-CNN model. 27 | */ 28 | 29 | #include "kws_ds_cnn.h" 30 | #include "string.h" 31 | 32 | KWS_DS_CNN::KWS_DS_CNN(int16_t* audio_buffer, q7_t* scratch_buffer) 33 | : audio_buffer(audio_buffer) 34 | { 35 | log_mel = new LOG_MEL; 36 | nn = new DS_CNN(scratch_buffer); 37 | } 38 | 39 | KWS_DS_CNN::~KWS_DS_CNN() 40 | { 41 | delete log_mel; 42 | delete nn; 43 | } 44 | 45 | void KWS_DS_CNN::extract_features() 46 | { 47 | int32_t log_mel_buffer_head=0; 48 | for (uint16_t f = 0; f < NUM_FRAMES; f++) { 49 | log_mel->log_mel_compute(audio_buffer+(f*FRAME_SHIFT),3,&log_mel_buffer[log_mel_buffer_head]); 50 | log_mel_buffer_head += NUM_FBANK_BINS; 51 | } 52 | 53 | } 54 | 55 | /* This overloaded function is used in streaming audio case */ 56 | void KWS_DS_CNN::extract_features(uint16_t num_frames) 57 | { 58 | 59 | //move old features left 60 | memmove(log_mel_buffer,log_mel_buffer+(num_frames*NUM_FBANK_BINS),(NUM_FRAMES-num_frames)*NUM_FBANK_BINS); 61 | //compute features only for the newly recorded audio 62 | int32_t log_mel_buffer_head = (NUM_FRAMES-num_frames)*NUM_FBANK_BINS; 63 | 64 | for (uint16_t f = 0; f < num_frames; f++) { 65 | log_mel->log_mel_compute(audio_buffer+(f*FRAME_SHIFT),2,&log_mel_buffer[log_mel_buffer_head]); 66 | 67 | log_mel_buffer_head += NUM_FBANK_BINS; 68 | } 69 | } 70 | 71 | void KWS_DS_CNN::classify() 72 | { 73 | nn->run_nn(log_mel_buffer, output); 74 | 75 | // Softmax 76 | arm_softmax_q7(output,OUT_DIM,output); 77 | 78 | //do any post processing here 79 | } 80 | 81 | int KWS_DS_CNN::get_top_detection(q7_t* prediction) 82 | { 83 | int max_ind=0; 84 | int max_val=-128; 85 | for(int i=0;i0;i--) { 98 | for(int j=0;j 30 | 31 | #include "log_mel.h" 32 | #include "float.h" 33 | 34 | LOG_MEL::LOG_MEL() { 35 | 36 | // Round-up to nearest power of 2. 37 | frame_len_padded = pow(2,ceil((log(FRAME_LEN)/log(2)))); 38 | 39 | frame = new float[frame_len_padded]; 40 | buffer = new float[frame_len_padded]; 41 | mel_energies = new float[NUM_FBANK_BINS]; 42 | 43 | //create window function 44 | window_func = new float[FRAME_LEN]; 45 | for (int i = 0; i < FRAME_LEN; i++) 46 | window_func[i] = 0.5 - 0.5*cos(M_2PI * ((float)i) / (FRAME_LEN)); 47 | 48 | //create mel filterbank 49 | fbank_filter_first = new int32_t[NUM_FBANK_BINS]; 50 | fbank_filter_last = new int32_t[NUM_FBANK_BINS];; 51 | mel_fbank = create_mel_fbank(); 52 | 53 | 54 | //initialize FFT 55 | rfft = new arm_rfft_fast_instance_f32; 56 | arm_rfft_fast_init_f32(rfft, frame_len_padded); 57 | 58 | } 59 | 60 | LOG_MEL::~LOG_MEL() { 61 | delete []frame; 62 | delete [] buffer; 63 | delete []mel_energies; 64 | delete []window_func; 65 | delete []fbank_filter_first; 66 | delete []fbank_filter_last; 67 | delete rfft; 68 | for(int i=0;i left_mel && mel < right_mel) { 102 | float weight; 103 | if (mel <= center_mel) { 104 | weight = (mel - left_mel) / (center_mel - left_mel); 105 | } else { 106 | weight = (right_mel-mel) / (right_mel-center_mel); 107 | } 108 | this_bin[i] = weight; 109 | if (first_index == -1) 110 | first_index = i; 111 | last_index = i; 112 | } 113 | } 114 | 115 | fbank_filter_first[bin] = first_index; 116 | fbank_filter_last[bin] = last_index; 117 | mel_fbank[bin] = new float[last_index-first_index+1]; 118 | 119 | int32_t j = 0; 120 | //copy the part we care about 121 | for (i = first_index; i <= last_index; i++) { 122 | mel_fbank[bin][j++] = this_bin[i]; 123 | } 124 | } 125 | delete []this_bin; 126 | return mel_fbank; 127 | } 128 | 129 | void LOG_MEL::log_mel_compute(const int16_t * data, uint16_t dec_bits, int8_t * log_mel_out) { 130 | 131 | int32_t i, j, bin; 132 | 133 | //TensorFlow way of normalizing .wav data to (-1,1) 134 | for (i = 0; i < FRAME_LEN; i++) { 135 | frame[i] = (float)data[i]/(1<<15); 136 | } 137 | //Fill up remaining with zeros 138 | memset(&frame[FRAME_LEN], 0, sizeof(float) * (frame_len_padded-FRAME_LEN)); 139 | 140 | for (i = 0; i < FRAME_LEN; i++) { 141 | frame[i] *= window_func[i]; 142 | } 143 | 144 | //Compute FFT 145 | arm_rfft_fast_f32(rfft, frame, buffer, 0); 146 | 147 | //Convert to power spectrum 148 | //frame is stored as [real0, realN/2-1, real1, im1, real2, im2, ...] 149 | int32_t half_dim = frame_len_padded/2; 150 | float first_energy = buffer[0] * buffer[0], 151 | last_energy = buffer[1] * buffer[1]; // handle this special case 152 | for (i = 1; i < half_dim; i++) { 153 | float real = buffer[i*2], im = buffer[i*2 + 1]; 154 | buffer[i] = real*real + im*im; 155 | } 156 | buffer[0] = first_energy; 157 | buffer[half_dim] = last_energy; 158 | 159 | float sqrt_data; 160 | //Apply mel filterbanks 161 | for (bin = 0; bin < NUM_FBANK_BINS; bin++) { 162 | j = 0; 163 | float mel_energy = 0; 164 | int32_t first_index = fbank_filter_first[bin]; 165 | int32_t last_index = fbank_filter_last[bin]; 166 | for (i = first_index; i <= last_index; i++) { 167 | //arm_sqrt_f32(buffer[i],&sqrt_data); 168 | sqrt_data = buffer[i]; 169 | mel_energy += (sqrt_data) * mel_fbank[bin][j++]; 170 | } 171 | mel_energies[bin] = mel_energy; 172 | 173 | //avoid log of zero 174 | //if (mel_energy == 0.0) 175 | // mel_energies[bin] = FLT_MIN; 176 | } 177 | 178 | //Take log 179 | for (bin = 0; bin < NUM_FBANK_BINS; bin++){ 180 | mel_energies[bin] = logf(mel_energies[bin] + 1e-6); 181 | //Input is Qx.dec_bits (from quantization step) 182 | mel_energies[bin] *= (0x1<= 127) 185 | log_mel_out[bin] = 127; 186 | else if(mel_energies[bin] <= -128) 187 | log_mel_out[bin] = -128; 188 | else 189 | log_mel_out[bin] = mel_energies[bin]; 190 | } 191 | 192 | } 193 | -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/LOG_MEL/log_mel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Arm Limited or its affiliates. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the License); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | ************************************************************************** 19 | * 20 | * Modifications Copyright 2018 Peter Mølgaard Sørensen 21 | * Removed DCT to generate MFSC features instead of MFCC. Power spectrogram is used instead of magnitude 22 | */ 23 | 24 | #ifndef KWS_LOG_MEL_H 25 | #define KWS_LOG_MEL_H 26 | 27 | #include "arm_math.h" 28 | #include "string.h" 29 | 30 | #define SAMP_FREQ 16000 31 | #define FRAME_SHIFT_MS 20 32 | #define FRAME_LENGTH_MS 40 33 | 34 | #define NUM_FBANK_BINS 20 35 | #define NUM_MFCC_COEFFS 10 36 | #define MEL_LOW_FREQ 20 37 | #define MEL_HIGH_FREQ 4000 38 | 39 | #define FRAME_SHIFT ((int16_t)(SAMP_FREQ * 0.001 * FRAME_SHIFT_MS)) 40 | #define FRAME_LEN ((int16_t)(SAMP_FREQ * 0.001 * FRAME_LENGTH_MS)) 41 | 42 | #define NUM_FRAMES 49 43 | #define LOG_MEL_BUFFER_SIZE (NUM_FRAMES*NUM_FBANK_BINS) 44 | 45 | #define M_2PI 6.283185307179586476925286766559005 46 | 47 | class LOG_MEL{ 48 | private: 49 | int32_t frame_len_padded; 50 | float * frame; 51 | float * buffer; 52 | float * mel_energies; 53 | float * window_func; 54 | int32_t * fbank_filter_first; 55 | int32_t * fbank_filter_last; 56 | float ** mel_fbank; 57 | float * dct_matrix; 58 | arm_rfft_fast_instance_f32 * rfft; 59 | float ** create_mel_fbank(); 60 | 61 | static inline float InverseMelScale(float mel_freq) { 62 | return 700.0f * (expf (mel_freq / 1127.0f) - 1.0f); 63 | } 64 | 65 | static inline float MelScale(float freq) { 66 | return 1127.0f * logf (1.0f + freq / 700.0f); 67 | } 68 | 69 | public: 70 | LOG_MEL(); 71 | ~LOG_MEL(); 72 | void log_mel_compute(const int16_t* data, uint16_t dec_bits, int8_t* log_mel_out); 73 | }; 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/.hg_archival.txt: -------------------------------------------------------------------------------- 1 | repo: 75ec1b3cde178a667330936f1ae505da0ff6127f 2 | node: f87f062926376ca21fb7bd6c3c7501177520d8ce 3 | branch: default 4 | latesttag: null 5 | latesttagdistance: 33 6 | -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Display/LCD.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef MBED_LCD_H 3 | #define MBED_LCD_H 4 | 5 | #if DEVICE_PORTINOUT 6 | #include "PAR8.h" 7 | #include "PAR16.h" 8 | #endif 9 | 10 | #include "BUS8.h" 11 | #include "SPI8.h" 12 | #include "SPI16.h" 13 | #include "I2C_bus.h" 14 | #include "Protocols.h" 15 | 16 | #include "GraphicsDisplay.h" 17 | 18 | // undefine the KL43Z and KL46Z LCD macro 19 | #ifdef LCD 20 | #undef LCD 21 | #endif 22 | 23 | /** Draw mode 24 | * NORMAl 25 | * XOR set pixel by xor the screen 26 | */ 27 | enum {NORMAL,XOR}; 28 | 29 | /** Mirror mode */ 30 | enum mirror_t {X,Y,XY,NONE}; 31 | 32 | 33 | /** A common base class for monochrome Display 34 | */ 35 | class LCD : public GraphicsDisplay 36 | { 37 | 38 | public: 39 | 40 | /** Create a monochrome LCD Parallel Port interface 41 | * @param name The name used by the parent class to access the interface 42 | */ 43 | LCD(proto_t displayproto,PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name); 44 | 45 | /** Create a monochrome LCD Parallel Bus interface 46 | * @param name The name used by the parent class to access the interface 47 | */ 48 | LCD(proto_t displayproto,PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name); 49 | 50 | /** Create a monochrome LCD SPI interface 51 | * @param name The name used by the parent class to access the interface 52 | */ 53 | LCD(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name); 54 | 55 | /** Create a monochrome LCD I2C interface 56 | * @param name The name used by the parent class to access the interface 57 | */ 58 | LCD(proto_t displayproto, int Hz, int address,PinName sda, PinName scl, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name); 59 | 60 | 61 | /** Destructor 62 | * will free framebuffer 63 | */ 64 | virtual ~LCD(); 65 | 66 | 67 | 68 | /////// functions that come for free, but can be overwritten/////////////////////////////////////////////////// 69 | /////// ----------------------------------------------------/////////////////////////////////////////////////// 70 | 71 | /** Draw a pixel in the specified color. 72 | * @param x is the horizontal offset to this pixel. 73 | * @param y is the vertical offset to this pixel. 74 | * @param color defines the color for the pixel. 75 | */ 76 | virtual void pixel(int x, int y, unsigned short color); 77 | 78 | /** Set the window, which controls where items are written to the screen. 79 | * When something hits the window width, it wraps back to the left side 80 | * and down a row. If the initial write is outside the window, it will 81 | * be captured into the window when it crosses a boundary. 82 | * @param x is the left edge in pixels. 83 | * @param y is the top edge in pixels. 84 | * @param w is the window width in pixels. 85 | * @param h is the window height in pixels. 86 | */ 87 | virtual void window(int x, int y, int w, int h); 88 | 89 | /** Read pixel color at location 90 | * @param x is the horizontal offset to this pixel. 91 | * @param y is the vertical offset to this pixel. 92 | * @returns 16bit color, 0000=Black(pixel set), FFFF=White(pixel clear). 93 | */ 94 | virtual unsigned short pixelread(int x, int y); 95 | 96 | /** Push a single pixel into the window and increment position. 97 | * You must first call window() then push pixels in loop. 98 | * @param color is the pixel color. 99 | */ 100 | virtual void window_pushpixel(unsigned short color); 101 | 102 | /** Push some pixels of the same color into the window and increment position. 103 | * You must first call window() then push pixels. 104 | * @param color is the pixel color. 105 | * @param count: how many 106 | */ 107 | virtual void window_pushpixel(unsigned short color, unsigned int count); 108 | 109 | /** Push array of pixel colors into the window and increment position. 110 | * You must first call window() then push pixels. 111 | * @param color is the pixel color. 112 | */ 113 | virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght); 114 | 115 | /** Framebuffer is used, it needs to be sent to LCD from time to time 116 | */ 117 | virtual void copy_to_lcd(); 118 | 119 | /** set the contrast of the screen 120 | * 121 | * @param o contrast 0-63 122 | * @note may be overrided in case of not standard command 123 | */ 124 | virtual void set_contrast(int o); 125 | 126 | /** read the contrast level 127 | * 128 | */ 129 | int get_contrast(void); 130 | 131 | /** display inverted colors 132 | * 133 | * @param o = 0 normal, 1 invert 134 | */ 135 | void invert(unsigned char o); 136 | 137 | /** clear the entire screen 138 | * The inherited one sets windomax then fill with background color 139 | * We override it to speedup 140 | */ 141 | virtual void cls(); 142 | 143 | /** Set the orientation of the screen 144 | * x,y: 0,0 is always top left 145 | * 146 | * @param o direction to use the screen (0-3) 147 | * 0 = -90° 148 | * 1 = default 0° 149 | * 2 = +90° 150 | * 3 = +180° 151 | * 152 | */ 153 | void set_orientation(int o); 154 | 155 | /** Set ChipSelect high or low 156 | * @param enable 0/1 157 | */ 158 | virtual void BusEnable(bool enable); 159 | 160 | /** get display X size in pixels (native, orientation independent) 161 | * @returns X size in pixels 162 | */ 163 | int sizeX(); 164 | 165 | /** get display Y size in pixels (native, orientation independent) 166 | * @returns Y size in pixels 167 | */ 168 | int sizeY(); 169 | 170 | //////////////////////////////////////////////////////////////////////////////// 171 | // not implemented yet 172 | ////////////////////////////////////////////////////////////////// 173 | // virtual unsigned short pixelread(int x, int y){return 0;}; 174 | virtual void window4read(int x, int y, int w, int h){}; 175 | void setscrollarea (int startY, int areasize){}; 176 | void scroll (int lines){}; 177 | void scrollreset(){}; 178 | void FastWindow(bool enable){}; 179 | 180 | unsigned int tftID; 181 | 182 | 183 | 184 | 185 | protected: 186 | 187 | /** set mirror mode 188 | * @note may be overridden by specific display init class in case of not standard cmds or inverted wiring 189 | * @param mode NONE, X, Y, XY 190 | */ 191 | virtual void mirrorXY(mirror_t mode); 192 | 193 | ////// functions needed by parent class /////////////////////////////////////// 194 | ////// -------------------------------- /////////////////////////////////////// 195 | 196 | /** Send 8bit command to display controller 197 | * 198 | * @param cmd: byte to send 199 | * @note if protocol is SPI16, it will insert NOP cmd before, so if cmd is a 2byte cmd, the second cmd will be broken. Use wr_cmd16 for 2bytes cmds 200 | */ 201 | void wr_cmd8(unsigned char cmd); 202 | 203 | /** Send 8bit data to display controller 204 | * 205 | * @param data: byte to send 206 | * 207 | */ 208 | void wr_data8(unsigned char data); 209 | 210 | /** Send 16bit command to display controller 211 | * 212 | * @param cmd: halfword to send 213 | * 214 | */ 215 | void wr_cmd16(unsigned short cmd); 216 | 217 | /** Send same 16bit pixeldata to display controller multiple times 218 | * 219 | * @param data: halfword to send 220 | * @param count: how many 221 | * 222 | */ 223 | virtual void wr_gram(unsigned short data, unsigned int count); 224 | 225 | /** Send array of pixeldata shorts to display controller 226 | * 227 | * @param data: unsigned short pixeldata array 228 | * @param lenght: lenght (in shorts) 229 | * 230 | */ 231 | virtual void wr_grambuf(unsigned short* data, unsigned int lenght); 232 | 233 | /** HW reset sequence (without display init commands) 234 | */ 235 | void hw_reset(); 236 | 237 | int draw_mode; 238 | int contrast; 239 | 240 | private: 241 | 242 | Protocols* proto; 243 | unsigned char *buffer; 244 | unsigned short *buffer16; 245 | const int screensize_X; 246 | const int screensize_Y; 247 | const int _LCDPAGES; 248 | const int _IC_X_SEGS; 249 | const int _IC_Y_COMS; 250 | const int _IC_PAGES; 251 | 252 | int page_offset; 253 | int col_offset; 254 | // pixel location 255 | int cur_x; 256 | int cur_y; 257 | // window location 258 | int win_x1; 259 | int win_x2; 260 | int win_y1; 261 | int win_y2; 262 | int orientation; 263 | bool useNOP; 264 | }; 265 | 266 | #endif -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Font/Terminal6x8.h: -------------------------------------------------------------------------------- 1 | //Font Generated by MikroElektronika GLCD Font Creator 1.2.0.0 2 | //MikroElektronika 2011 3 | //http://www.mikroe.com 4 | 5 | //GLCD FontName : Terminal6x8 6 | //GLCD FontSize : 6 x 8 7 | #ifdef TOOLCHAIN_GCC 8 | const unsigned char Terminal6x8[] __attribute__((aligned (2))) = { 9 | #else 10 | __align(2) 11 | const unsigned char Terminal6x8[] = { 12 | #endif 13 | 0xFF/*unused*/,6,8,0xFF/*unused*/, 14 | 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 15 | 0x05, 0x00, 0x00, 0x06, 0x5F, 0x06, 0x00, // Code for char ! 16 | 0x06, 0x00, 0x07, 0x03, 0x00, 0x07, 0x03, // Code for char " 17 | 0x06, 0x00, 0x24, 0x7E, 0x24, 0x7E, 0x24, // Code for char # 18 | 0x05, 0x00, 0x24, 0x2B, 0x6A, 0x12, 0x00, // Code for char $ 19 | 0x06, 0x00, 0x63, 0x13, 0x08, 0x64, 0x63, // Code for char % 20 | 0x06, 0x00, 0x36, 0x49, 0x56, 0x20, 0x50, // Code for char & 21 | 0x04, 0x00, 0x00, 0x07, 0x03, 0x00, 0x00, // Code for char ' 22 | 0x04, 0x00, 0x00, 0x3E, 0x41, 0x00, 0x00, // Code for char ( 23 | 0x04, 0x00, 0x00, 0x41, 0x3E, 0x00, 0x00, // Code for char ) 24 | 0x06, 0x00, 0x08, 0x3E, 0x1C, 0x3E, 0x08, // Code for char * 25 | 0x06, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, // Code for char + 26 | 0x04, 0x00, 0x00, 0xE0, 0x60, 0x00, 0x00, // Code for char , 27 | 0x06, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, // Code for char - 28 | 0x04, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, // Code for char . 29 | 0x06, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, // Code for char / 30 | 0x06, 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, // Code for char 0 31 | 0x05, 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, // Code for char 1 32 | 0x06, 0x00, 0x62, 0x51, 0x49, 0x49, 0x46, // Code for char 2 33 | 0x06, 0x00, 0x22, 0x49, 0x49, 0x49, 0x36, // Code for char 3 34 | 0x06, 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, // Code for char 4 35 | 0x06, 0x00, 0x2F, 0x49, 0x49, 0x49, 0x31, // Code for char 5 36 | 0x06, 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30, // Code for char 6 37 | 0x06, 0x00, 0x01, 0x71, 0x09, 0x05, 0x03, // Code for char 7 38 | 0x06, 0x00, 0x36, 0x49, 0x49, 0x49, 0x36, // Code for char 8 39 | 0x06, 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, // Code for char 9 40 | 0x04, 0x00, 0x00, 0x6C, 0x6C, 0x00, 0x00, // Code for char : 41 | 0x04, 0x00, 0x00, 0xEC, 0x6C, 0x00, 0x00, // Code for char ; 42 | 0x05, 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, // Code for char < 43 | 0x06, 0x00, 0x24, 0x24, 0x24, 0x24, 0x24, // Code for char = 44 | 0x06, 0x00, 0x00, 0x41, 0x22, 0x14, 0x08, // Code for char > 45 | 0x06, 0x00, 0x02, 0x01, 0x59, 0x09, 0x06, // Code for char ? 46 | 0x06, 0x00, 0x3E, 0x41, 0x5D, 0x55, 0x1E, // Code for char @ 47 | 0x06, 0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E, // Code for char A 48 | 0x06, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, // Code for char B 49 | 0x06, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, // Code for char C 50 | 0x06, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x3E, // Code for char D 51 | 0x06, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, // Code for char E 52 | 0x06, 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, // Code for char F 53 | 0x06, 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A, // Code for char G 54 | 0x06, 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, // Code for char H 55 | 0x05, 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, // Code for char I 56 | 0x06, 0x00, 0x30, 0x40, 0x40, 0x40, 0x3F, // Code for char J 57 | 0x06, 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, // Code for char K 58 | 0x06, 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, // Code for char L 59 | 0x06, 0x00, 0x7F, 0x02, 0x04, 0x02, 0x7F, // Code for char M 60 | 0x06, 0x00, 0x7F, 0x02, 0x04, 0x08, 0x7F, // Code for char N 61 | 0x06, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, // Code for char O 62 | 0x06, 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, // Code for char P 63 | 0x06, 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, // Code for char Q 64 | 0x06, 0x00, 0x7F, 0x09, 0x09, 0x19, 0x66, // Code for char R 65 | 0x06, 0x00, 0x26, 0x49, 0x49, 0x49, 0x32, // Code for char S 66 | 0x06, 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, // Code for char T 67 | 0x06, 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, // Code for char U 68 | 0x06, 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, // Code for char V 69 | 0x06, 0x00, 0x3F, 0x40, 0x3C, 0x40, 0x3F, // Code for char W 70 | 0x06, 0x00, 0x63, 0x14, 0x08, 0x14, 0x63, // Code for char X 71 | 0x06, 0x00, 0x07, 0x08, 0x70, 0x08, 0x07, // Code for char Y 72 | 0x05, 0x00, 0x71, 0x49, 0x45, 0x43, 0x00, // Code for char Z 73 | 0x05, 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00, // Code for char [ 74 | 0x06, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, // Code for char BackSlash 75 | 0x05, 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00, // Code for char ] 76 | 0x06, 0x00, 0x04, 0x02, 0x01, 0x02, 0x04, // Code for char ^ 77 | 0x06, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // Code for char _ 78 | 0x04, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00, // Code for char ` 79 | 0x06, 0x00, 0x20, 0x54, 0x54, 0x54, 0x78, // Code for char a 80 | 0x06, 0x00, 0x7F, 0x44, 0x44, 0x44, 0x38, // Code for char b 81 | 0x06, 0x00, 0x38, 0x44, 0x44, 0x44, 0x28, // Code for char c 82 | 0x06, 0x00, 0x38, 0x44, 0x44, 0x44, 0x7F, // Code for char d 83 | 0x06, 0x00, 0x38, 0x54, 0x54, 0x54, 0x08, // Code for char e 84 | 0x05, 0x00, 0x08, 0x7E, 0x09, 0x09, 0x00, // Code for char f 85 | 0x06, 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C, // Code for char g 86 | 0x05, 0x00, 0x7F, 0x04, 0x04, 0x78, 0x00, // Code for char h 87 | 0x05, 0x00, 0x00, 0x00, 0x7D, 0x40, 0x00, // Code for char i 88 | 0x05, 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00, // Code for char j 89 | 0x05, 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, // Code for char k 90 | 0x05, 0x00, 0x00, 0x00, 0x7F, 0x40, 0x00, // Code for char l 91 | 0x06, 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78, // Code for char m 92 | 0x05, 0x00, 0x7C, 0x04, 0x04, 0x78, 0x00, // Code for char n 93 | 0x06, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, // Code for char o 94 | 0x06, 0x00, 0xFC, 0x44, 0x44, 0x44, 0x38, // Code for char p 95 | 0x06, 0x00, 0x38, 0x44, 0x44, 0x44, 0xFC, // Code for char q 96 | 0x06, 0x00, 0x44, 0x78, 0x44, 0x04, 0x08, // Code for char r 97 | 0x06, 0x00, 0x08, 0x54, 0x54, 0x54, 0x20, // Code for char s 98 | 0x05, 0x00, 0x04, 0x3E, 0x44, 0x24, 0x00, // Code for char t 99 | 0x05, 0x00, 0x3C, 0x40, 0x20, 0x7C, 0x00, // Code for char u 100 | 0x06, 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, // Code for char v 101 | 0x06, 0x00, 0x3C, 0x60, 0x30, 0x60, 0x3C, // Code for char w 102 | 0x05, 0x00, 0x6C, 0x10, 0x10, 0x6C, 0x00, // Code for char x 103 | 0x05, 0x00, 0x9C, 0xA0, 0x60, 0x3C, 0x00, // Code for char y 104 | 0x05, 0x00, 0x64, 0x54, 0x54, 0x4C, 0x00, // Code for char z 105 | 0x05, 0x00, 0x08, 0x3E, 0x41, 0x41, 0x00, // Code for char { 106 | 0x04, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, // Code for char | 107 | 0x06, 0x00, 0x00, 0x41, 0x41, 0x3E, 0x08, // Code for char } 108 | 0x05, 0x00, 0x02, 0x01, 0x02, 0x01, 0x00, // Code for char ~ 109 | 0x06, 0x00, 0x3C, 0x26, 0x23, 0x26, 0x3C // Code for char  110 | }; 111 | 112 | -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Graphics/TextDisplay.cpp: -------------------------------------------------------------------------------- 1 | /* mbed TextDisplay Display Library Base Class 2 | * Copyright (c) 2007-2009 sford 3 | * Released under the MIT License: http://mbed.org/license/mit 4 | */ 5 | 6 | #include "TextDisplay.h" 7 | 8 | TextDisplay::TextDisplay(const char *name) : Stream(name){ 9 | _row = 0; 10 | _column = 0; 11 | if (name == NULL) { 12 | _path = NULL; 13 | } else { 14 | _path = new char[strlen(name) + 2]; 15 | sprintf(_path, "/%s", name); 16 | } 17 | } 18 | 19 | int TextDisplay::_putc(int value) { 20 | if(value == '\n') { 21 | _column = 0; 22 | _row++; 23 | if(_row >= rows()) { 24 | _row = 0; 25 | } 26 | } else { 27 | character(_column, _row, value); 28 | _column++; 29 | if(_column >= columns()) { 30 | _column = 0; 31 | _row++; 32 | if(_row >= rows()) { 33 | _row = 0; 34 | } 35 | } 36 | } 37 | return value; 38 | } 39 | 40 | // crude cls implementation, should generally be overwritten in derived class 41 | void TextDisplay::cls() { 42 | locate(0, 0); 43 | for(int i=0; idisplay SEGs wiring inverted) 50 | // wr_cmd8(0xA0); // ADC select seg0-seg223 51 | //wr_cmd8(0xA1); // ADC select seg223-seg0 52 | // wr_cmd8(0xC8); // SHL select com63-com0 53 | //wr_cmd8(0xC0); // SHL select com0-com63 54 | 55 | wr_cmd8(0x2F); // //Power Control:internal, LCD capacitance 60nf-90nf 56 | wait_ms(10); 57 | 58 | // wr_cmd8(0x81);//Set Gain and Potentiometer 59 | // wr_cmd8(0x40|26);//Set Gain and Potentiometer xx xxxxxx 60 | set_contrast(26); 61 | 62 | wr_cmd8(0x88); //disable colum/page address wraparound 63 | wr_cmd8(0xA4); // LCD display ram (EntireDisplayOn disable) 64 | wr_cmd8(0x40); // start line = 0 65 | wr_cmd8(0xA6); // display normal (1 = illuminated) 66 | wr_cmd8(0xAF); // display ON 67 | 68 | } 69 | //////////////////////////////////////////////////////////////////// 70 | // functions that overrides the standard ones implemented in LCD.cpp 71 | //////////////////////////////////////////////////////////////////// 72 | void UC1608::mirrorXY(mirror_t mode) 73 | { 74 | switch (mode) 75 | { 76 | case(NONE): 77 | wr_cmd8(0xC4); // this is in real X mirror command, but my display have SEGs wired inverted, so assume this is the default no-x-mirror 78 | break; 79 | case(X): 80 | wr_cmd8(0xC0); 81 | break; 82 | case(Y): 83 | wr_cmd8(0xCC); 84 | break; 85 | case(XY): 86 | wr_cmd8(0xC8); 87 | break; 88 | } 89 | } 90 | void UC1608::set_contrast(int o) 91 | { 92 | contrast = o; 93 | // wr_cmd8(0x81); // set volume 94 | // wr_cmd8(0x40|(o&0x3F)); 95 | wr_cmd16(0x8140|(o&0x3F)); 96 | } 97 | void UC1608::BusEnable(bool enable) 98 | { 99 | LCD::BusEnable(!enable); // crap IC has CS not inverted (active HIGH) 100 | } -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Inits/UC1608.h: -------------------------------------------------------------------------------- 1 | #ifndef MBED_UC1608_H 2 | #define MBED_UC1608_H 3 | 4 | 5 | 6 | #include "mbed.h" 7 | #include "LCD.h" 8 | 9 | /** Class for UC1608 display controller 10 | * to be copypasted and adapted for other controllers 11 | */ 12 | class UC1608 : public LCD 13 | { 14 | 15 | public: 16 | 17 | /** Create a PAR display interface 18 | * @param displayproto only supports PAR_8 19 | * @param port GPIO port name to use 20 | * @param CS pin connected to CS of display 21 | * @param reset pin connected to RESET of display 22 | * @param DC pin connected to data/command of display 23 | * @param WR pin connected to SDI of display 24 | * @param RD pin connected to RS of display 25 | * @param name The name used by the parent class to access the interface 26 | * @param LCDSIZE_X x size in pixel - optional 27 | * @param LCDSIZE_Y y size in pixel - optional 28 | */ 29 | UC1608(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char* name, unsigned int LCDSIZE_X = 240, unsigned int LCDSIZE_Y = 120); 30 | 31 | /** Create an SPI display interface 32 | * @param displayproto SPI_8 or SPI_16 33 | * @param Hz SPI speed in Hz 34 | * @param mosi SPI pin 35 | * @param miso SPI pin 36 | * @param sclk SPI pin 37 | * @param CS pin connected to CS of display 38 | * @param reset pin connected to RESET of display 39 | * @param DC pin connected to data/command of display 40 | * @param name The name used by the parent class to access the interface 41 | * @param LCDSIZE_X x size in pixel - optional 42 | * @param LCDSIZE_Y y size in pixel - optional 43 | */ 44 | UC1608(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char* name , unsigned int LCDSIZE_X = 240, unsigned int LCDSIZE_Y = 120); 45 | 46 | /** set the contrast of the screen 47 | * @note here overrided because of not standard command 48 | * @param o contrast 0-63 49 | */ 50 | virtual void set_contrast(int o); 51 | 52 | /** Set ChipSelect high or low 53 | * @note here overriding the std one, cause CS inverted 54 | * @param enable 0/1 55 | */ 56 | virtual void BusEnable(bool enable); 57 | 58 | protected: 59 | 60 | 61 | /** Init command sequence 62 | */ 63 | void init(); 64 | 65 | /** set mirror mode 66 | * @note here overriding the LCD class default one because of not standard commands 67 | * @param mode NONE, X, Y, XY 68 | */ 69 | virtual void mirrorXY(mirror_t mode); 70 | 71 | 72 | 73 | 74 | 75 | }; 76 | #endif -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/BUS16.cpp: -------------------------------------------------------------------------------- 1 | /* mbed UniGraphic library - BUS16 protocol class 2 | * Copyright (c) 2015 Giuliano Dianda 3 | * Released under the MIT License: http://mbed.org/license/mit 4 | * 5 | * Derived work of: 6 | * 7 | * mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller 8 | * Copyright (c) 2013 Peter Drescher - DC2PD 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 16 | * THE SOFTWARE. 17 | */ 18 | #include "BUS16.h" 19 | 20 | BUS16::BUS16(PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD) 21 | : _bus(buspins), _CS(CS), _reset(reset), _DC(DC), _WR(WR), _RD(RD) 22 | { 23 | _reset = 1; 24 | _DC=1; 25 | _WR=1; 26 | _RD=1; 27 | _CS=1; 28 | _bus.mode(PullNone); 29 | _bus.output(); // will re-enable our GPIO port 30 | hw_reset(); 31 | } 32 | 33 | void BUS16::wr_cmd8(unsigned char cmd) 34 | { 35 | _DC = 0; // 0=cmd 36 | _bus.write(cmd); // write 8bit 37 | _WR=0; 38 | _WR=1; 39 | _DC = 1; // 1=data next 40 | } 41 | void BUS16::wr_data8(unsigned char data) 42 | { 43 | _bus.write(data); // write 8bit 44 | _WR=0; 45 | _WR=1; 46 | } 47 | void BUS16::wr_cmd16(unsigned short cmd) 48 | { 49 | _DC = 0; // 0=cmd 50 | _bus.write(cmd>>8); // write 8bit 51 | _WR=0; 52 | _WR=1; 53 | _bus.write(cmd&0xFF); // write 8bit 54 | _WR=0; 55 | _WR=1; 56 | _DC = 1; // 1=data next 57 | } 58 | void BUS16::wr_data16(unsigned short data) 59 | { 60 | _bus.write(data>>8); // write 8bit 61 | _WR=0; 62 | _WR=1; 63 | _bus.write(data&0xFF); // write 8bit 64 | _WR=0; 65 | _WR=1; 66 | } 67 | void BUS16::wr_gram(unsigned short data) 68 | { 69 | _bus.write(data); // write 16bit 70 | _WR=0; 71 | _WR=1; 72 | } 73 | void BUS16::wr_gram(unsigned short data, unsigned int count) 74 | { 75 | while(count) 76 | { 77 | _bus.write(data); // rewrite even if same data, otherwise too much fast 78 | _WR=0; 79 | _WR=1; 80 | count--; 81 | } 82 | } 83 | void BUS16::wr_grambuf(unsigned short* data, unsigned int lenght) 84 | { 85 | while(lenght) 86 | { 87 | _bus.write(*data); // write 16bit 88 | _WR=0; 89 | _WR=1; 90 | data++; 91 | lenght--; 92 | } 93 | } 94 | unsigned short BUS16::rd_gram(bool convert) 95 | { 96 | unsigned int r=0; 97 | _bus.input(); 98 | 99 | _RD = 0; 100 | _bus.read(); //dummy read 101 | _RD = 1; 102 | 103 | _RD = 0; 104 | // _RD = 0; // add wait 105 | r |= _bus.read(); 106 | _RD = 1; 107 | if(convert) 108 | { 109 | r <<= 8; 110 | _RD = 0; 111 | // _RD = 0; // add wait 112 | r |= _bus.read()>>8; //MSB of port read is blue, LSB is red of next pixel 113 | _RD = 1; 114 | // gram is 18bit/pixel, if you set 16bit/pixel (cmd 3A), during writing the 16bits are expanded to 18bit 115 | // during reading, you read the raw 18bit gram 116 | r = RGB24to16((r&0xFF0000)>>16, (r&0xFF00)>>8, r&0xFF);// 18bit pixel padded to 24bits, rrrrrr00_gggggg00_bbbbbb00, converted to 16bit 117 | } 118 | _bus.output(); 119 | return (unsigned short)r; 120 | } 121 | unsigned int BUS16::rd_reg_data32(unsigned char reg) 122 | { 123 | wr_cmd8(reg); 124 | unsigned int r=0; 125 | // _DC = 1; // 1=data 126 | _bus.input(); 127 | 128 | _RD = 0; 129 | _bus.read(); //dummy read 130 | _RD = 1; 131 | 132 | _RD = 0; 133 | // _RD = 0; // add wait 134 | r |= (_bus.read()&0xFF); 135 | r <<= 8; 136 | _RD = 1; 137 | 138 | _RD = 0; 139 | // _RD = 0; // add wait 140 | r |= (_bus.read()&0xFF); 141 | r <<= 8; 142 | _RD = 1; 143 | 144 | _RD = 0; 145 | // _RD = 0; // add wait 146 | r |= (_bus.read()&0xFF); 147 | r <<= 8; 148 | _RD = 1; 149 | 150 | _RD = 0; 151 | // _RD = 0; // add wait 152 | r |= (_bus.read()&0xFF); 153 | _RD = 1; 154 | 155 | _CS = 1; // toggle CS to interupt the cmd in case was not supported 156 | _CS = 0; 157 | 158 | _bus.output(); 159 | return r; 160 | } 161 | // in Par mode EXTC regs (0xB0-0xFF) can be directly read 162 | unsigned int BUS16::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) 163 | { 164 | return rd_reg_data32(reg); 165 | } 166 | // ILI932x specific 167 | void BUS16::dummyread() 168 | { 169 | _bus.input(); 170 | _RD = 0; 171 | _bus.read(); // dummy read 172 | _RD=1; 173 | // _bus.output(); 174 | } 175 | // ILI932x specific 176 | void BUS16::reg_select(unsigned char reg, bool forread) 177 | { 178 | _DC = 0; 179 | _bus.write(reg); // write 16bit 180 | _WR=0; 181 | _WR=1; 182 | _DC = 1; // 1=data next 183 | } 184 | // ILI932x specific 185 | void BUS16::reg_write(unsigned char reg, unsigned short data) 186 | { 187 | _DC = 0; 188 | _bus.write(reg); // write 16bit 189 | _WR=0; 190 | _WR=1; 191 | _DC = 1; 192 | _bus.write(data); // write 16bit 193 | _WR=0; 194 | _WR=1; 195 | } 196 | // ILI932x specific 197 | unsigned short BUS16::reg_read(unsigned char reg) 198 | { 199 | unsigned short r=0; 200 | _DC = 0; 201 | _bus.write(reg); // write 16bit 202 | _WR=0; 203 | _WR=1; 204 | _DC = 1; 205 | _bus.input(); 206 | _RD=0; 207 | r |= _bus.read(); // read 16bit 208 | _RD=1; 209 | _bus.output(); 210 | return r; 211 | } 212 | void BUS16::hw_reset() 213 | { 214 | wait_ms(15); 215 | _DC = 1; 216 | _CS = 1; 217 | _WR = 1; 218 | _RD = 1; 219 | _reset = 0; // display reset 220 | wait_ms(2); 221 | _reset = 1; // end reset 222 | wait_ms(100); 223 | } 224 | void BUS16::BusEnable(bool enable) 225 | { 226 | _CS = enable ? 0:1; 227 | } -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/BUS16.h: -------------------------------------------------------------------------------- 1 | #ifndef BUS16_H 2 | #define BUS16_H 3 | 4 | #include "mbed.h" 5 | #include "Protocols.h" 6 | //#include "GraphicsDisplay.h" 7 | 8 | /** Parallel 16bit interface 9 | */ 10 | class BUS16 : public Protocols 11 | { 12 | public: 13 | 14 | /** Create a BUS16 display interface with scattered pins and 5 control pins 15 | * 16 | * @param buspins array of PinNames to group as Bus 17 | * @param CS pin connected to CS of display 18 | * @param reset pin connected to RESET of display 19 | * @param DC pin connected to data/command of display 20 | * @param WR pin connected to SDI of display 21 | * @param RD pin connected to RS of display 22 | */ 23 | BUS16(PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD); 24 | 25 | protected: 26 | 27 | /** Send 8bit command to display controller 28 | * 29 | * @param cmd: byte to send 30 | * 31 | */ 32 | virtual void wr_cmd8(unsigned char cmd); 33 | 34 | /** Send 8bit data to display controller 35 | * 36 | * @param data: byte to send 37 | * 38 | */ 39 | virtual void wr_data8(unsigned char data); 40 | 41 | /** Send 2x8bit command to display controller 42 | * 43 | * @param cmd: halfword to send 44 | * @note 2cycles using pins[7:0] 45 | */ 46 | virtual void wr_cmd16(unsigned short cmd); 47 | 48 | /** Send 2x8bit data to display controller 49 | * 50 | * @param data: halfword to send 51 | * @note 2cycles using pins[7:0], only gram write cmd uses pins[15:8] 52 | */ 53 | virtual void wr_data16(unsigned short data); 54 | 55 | /** Send 16bit pixeldata to display controller 56 | * 57 | * @param data: halfword to send 58 | * @note here using all pins[15:0] 59 | */ 60 | virtual void wr_gram(unsigned short data); 61 | 62 | /** Send same 16bit pixeldata to display controller multiple times 63 | * 64 | * @param data: halfword to send 65 | * @param count: how many 66 | * @note here using all pins[15:0] 67 | */ 68 | virtual void wr_gram(unsigned short data, unsigned int count); 69 | 70 | /** Send array of pixeldata shorts to display controller 71 | * 72 | * @param data: unsigned short pixeldata array 73 | * @param lenght: lenght (in shorts) 74 | * @note here using all pins[15:0] 75 | */ 76 | virtual void wr_grambuf(unsigned short* data, unsigned int lenght); 77 | 78 | /** Read 16bit pixeldata from display controller (with dummy cycle) 79 | * 80 | * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit 81 | * @returns 16bit color 82 | */ 83 | virtual unsigned short rd_gram(bool convert); 84 | 85 | /** Read 4x8bit register data (with dummy cycle) 86 | * @param reg the register to read 87 | * @returns data as uint 88 | * 89 | */ 90 | virtual unsigned int rd_reg_data32(unsigned char reg); 91 | 92 | /** Read 3x8bit ExtendedCommands register data 93 | * @param reg the register to read 94 | * @returns data as uint 95 | * @note EXTC regs (0xB0 to 0xFF) are read/write registers, for Parallel mode directly accessible in both directions 96 | */ 97 | virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd); 98 | 99 | /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent 100 | * for PAR protocols: a signle RD bit toggle 101 | * for SPI8: 8clocks 102 | * for SPI16: 16 clocks 103 | */ 104 | virtual void dummyread (); 105 | 106 | /** ILI932x specific, select register for a successive write or read 107 | * 108 | * @param reg register to be selected 109 | * @param forread false = a write next (default), true = a read next 110 | * @note forread only used by SPI protocols 111 | */ 112 | virtual void reg_select(unsigned char reg, bool forread =false); 113 | 114 | /** ILI932x specific, write register with data 115 | * 116 | * @param reg register to write 117 | * @param data 16bit data 118 | */ 119 | virtual void reg_write(unsigned char reg, unsigned short data); 120 | 121 | /** ILI932x specific, read register 122 | * 123 | * @param reg register to be read 124 | * @returns 16bit register value 125 | */ 126 | virtual unsigned short reg_read(unsigned char reg); 127 | 128 | /** HW reset sequence (without display init commands) 129 | */ 130 | virtual void hw_reset(); 131 | 132 | /** Set ChipSelect high or low 133 | * @param enable 0/1 134 | */ 135 | virtual void BusEnable(bool enable); 136 | 137 | 138 | 139 | private: 140 | 141 | BusInOut _bus; 142 | DigitalOut _CS; 143 | DigitalOut _reset; 144 | DigitalOut _DC; 145 | DigitalOut _WR; 146 | DigitalOut _RD; 147 | 148 | }; 149 | #endif -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/BUS8.cpp: -------------------------------------------------------------------------------- 1 | /* mbed UniGraphic library - BUS8 protocol class 2 | * Copyright (c) 2015 Giuliano Dianda 3 | * Released under the MIT License: http://mbed.org/license/mit 4 | * 5 | * Derived work of: 6 | * 7 | * mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller 8 | * Copyright (c) 2013 Peter Drescher - DC2PD 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 16 | * THE SOFTWARE. 17 | */ 18 | 19 | #include "BUS8.h" 20 | 21 | BUS8::BUS8(PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD) 22 | : _bus(buspins), _CS(CS), _reset(reset), _DC(DC), _WR(WR), _RD(RD) 23 | { 24 | _reset = 1; 25 | _DC=1; 26 | _WR=1; 27 | _RD=1; 28 | _CS=1; 29 | _bus.mode(PullNone); 30 | _bus.output(); // will re-enable our GPIO port 31 | hw_reset(); 32 | } 33 | 34 | void BUS8::wr_cmd8(unsigned char cmd) 35 | { 36 | _DC = 0; // 0=cmd 37 | _bus.write(cmd); // write 8bit 38 | _WR=0; 39 | _WR=1; 40 | _DC = 1; // 1=data next 41 | } 42 | void BUS8::wr_data8(unsigned char data) 43 | { 44 | _bus.write(data); // write 8bit 45 | _WR=0; 46 | _WR=1; 47 | } 48 | void BUS8::wr_cmd16(unsigned short cmd) 49 | { 50 | _DC = 0; // 0=cmd 51 | _bus.write(cmd>>8); // write 8bit 52 | _WR=0; 53 | _WR=1; 54 | _bus.write(cmd&0xFF); // write 8bit 55 | _WR=0; 56 | _WR=1; 57 | _DC = 1; // 1=data next 58 | } 59 | void BUS8::wr_data16(unsigned short data) 60 | { 61 | _bus.write(data>>8); // write 8bit 62 | _WR=0; 63 | _WR=1; 64 | _bus.write(data&0xFF); // write 8bit 65 | _WR=0; 66 | _WR=1; 67 | } 68 | void BUS8::wr_gram(unsigned short data) 69 | { 70 | _bus.write(data>>8); // write 8bit 71 | _WR=0; 72 | _WR=1; 73 | _bus.write(data&0xFF); // write 8bit 74 | _WR=0; 75 | _WR=1; 76 | } 77 | void BUS8::wr_gram(unsigned short data, unsigned int count) 78 | { 79 | if((data>>8)==(data&0xFF)) 80 | { 81 | count<<=1; 82 | // _bus.write(data); // write 8bit 83 | while(count) 84 | { 85 | _bus.write(data); // rewrite even if same data, otherwise too much fast 86 | _WR=0; 87 | _WR=1; 88 | count--; 89 | } 90 | } 91 | else 92 | { 93 | while(count) 94 | { 95 | _bus.write(data>>8); // write 8bit 96 | _WR=0; 97 | _WR=1; 98 | _bus.write(data&0xFF); // write 8bit 99 | _WR=0; 100 | _WR=1; 101 | count--; 102 | } 103 | } 104 | } 105 | void BUS8::wr_grambuf(unsigned short* data, unsigned int lenght) 106 | { 107 | while(lenght) 108 | { 109 | _bus.write((*data)>>8); // write 8bit 110 | _WR=0; 111 | _WR=1; 112 | _bus.write((*data)&0xFF); // write 8bit 113 | _WR=0; 114 | _WR=1; 115 | data++; 116 | lenght--; 117 | } 118 | } 119 | unsigned short BUS8::rd_gram(bool convert) 120 | { 121 | unsigned int r=0; 122 | _bus.input(); 123 | 124 | _RD = 0; 125 | _RD = 0; // add wait 126 | _bus.read(); //dummy read 127 | _RD = 1; 128 | 129 | _RD = 0; 130 | _RD = 0; // add wait 131 | r |= _bus.read(); 132 | _RD = 1; 133 | r <<= 8; 134 | 135 | _RD = 0; 136 | _RD = 0; // add wait 137 | r |= _bus.read(); 138 | _RD = 1; 139 | if(convert) 140 | { 141 | r <<= 8; 142 | _RD = 0; 143 | // _RD = 0; // add wait 144 | r |= _bus.read(); 145 | _RD = 1; 146 | // gram is 18bit/pixel, if you set 16bit/pixel (cmd 3A), during writing the 16bits are expanded to 18bit 147 | // during reading, you read the raw 18bit gram 148 | r = RGB24to16((r&0xFF0000)>>16, (r&0xFF00)>>8, r&0xFF);// 18bit pixel padded to 24bits, rrrrrr00_gggggg00_bbbbbb00, converted to 16bit 149 | } 150 | _bus.output(); 151 | return (unsigned short)r; 152 | } 153 | unsigned int BUS8::rd_reg_data32(unsigned char reg) 154 | { 155 | wr_cmd8(reg); 156 | unsigned int r=0; 157 | _bus.input(); 158 | 159 | _RD = 0; 160 | _bus.read(); //dummy read 161 | _RD = 1; 162 | 163 | _RD = 0; 164 | // _RD = 0; // add wait 165 | r |= (_bus.read()&0xFF); 166 | r <<= 8; 167 | _RD = 1; 168 | 169 | _RD = 0; 170 | // _RD = 0; // add wait 171 | r |= (_bus.read()&0xFF); 172 | r <<= 8; 173 | _RD = 1; 174 | 175 | _RD = 0; 176 | // _RD = 0; // add wait 177 | r |= (_bus.read()&0xFF); 178 | r <<= 8; 179 | _RD = 1; 180 | 181 | _RD = 0; 182 | // _RD = 0; // add wait 183 | r |= (_bus.read()&0xFF); 184 | _RD = 1; 185 | 186 | _CS = 1; // force CS HIG to interupt the cmd in case was not supported 187 | _CS = 0; 188 | _bus.output(); 189 | return r; 190 | } 191 | // in Par mode EXTC regs (0xB0-0xFF) can be directly read 192 | unsigned int BUS8::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) 193 | { 194 | return rd_reg_data32(reg); 195 | } 196 | // ILI932x specific 197 | void BUS8::dummyread() 198 | { 199 | _bus.input(); 200 | _RD=0; 201 | _RD=0; // add wait 202 | _bus.read(); // dummy read 203 | _RD=1; 204 | // _bus.output(); 205 | } 206 | // ILI932x specific 207 | void BUS8::reg_select(unsigned char reg, bool forread) 208 | { 209 | _DC = 0; 210 | _bus.write(0); // write MSB 211 | _WR=0; 212 | _WR=1; 213 | _bus.write(reg); // write LSB 214 | _WR=0; 215 | _WR=1; 216 | _DC = 1; // 1=data next 217 | } 218 | // ILI932x specific 219 | void BUS8::reg_write(unsigned char reg, unsigned short data) 220 | { 221 | _DC = 0; 222 | _bus.write(0); // write MSB 223 | _WR=0; 224 | _WR=1; 225 | _bus.write(reg); // write MSB 226 | _WR=0; 227 | _WR=1; 228 | _DC = 1; 229 | _bus.write(data>>8); 230 | _WR=0; 231 | _WR=1; 232 | _bus.write(data&0xFF); 233 | _WR=0; 234 | _WR=1; 235 | } 236 | // ILI932x specific 237 | unsigned short BUS8::reg_read(unsigned char reg) 238 | { 239 | unsigned short r=0; 240 | _DC = 0; 241 | _bus.write(0); 242 | _WR=0; 243 | _WR=1; 244 | _bus.write(reg); 245 | _WR=0; 246 | _WR=1; 247 | _DC = 1; 248 | _bus.input(); 249 | _RD=0; 250 | r |= _bus.read(); // read 8bit 251 | _RD=1; 252 | r <<= 8; 253 | _RD=0; 254 | r |= _bus.read(); // read 8bit 255 | _RD=1; 256 | _bus.output(); 257 | 258 | return r; 259 | } 260 | void BUS8::hw_reset() 261 | { 262 | wait_ms(15); 263 | _DC = 1; 264 | _CS = 1; 265 | _WR = 1; 266 | _RD = 1; 267 | _reset = 0; // display reset 268 | wait_ms(2); 269 | _reset = 1; // end reset 270 | wait_ms(100); 271 | } 272 | void BUS8::BusEnable(bool enable) 273 | { 274 | _CS = enable ? 0:1; 275 | } -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/BUS8.h: -------------------------------------------------------------------------------- 1 | #ifndef BUS8_H 2 | #define BUS8_H 3 | 4 | #include "mbed.h" 5 | #include "Protocols.h" 6 | //#include "GraphicsDisplay.h" 7 | 8 | /** Parallel 8bit interface 9 | */ 10 | class BUS8 : public Protocols 11 | { 12 | public: 13 | 14 | /** Create a BUS8 display interface with scattered pins and 5 control pins 15 | * 16 | * @param buspins array of PinName to group as Bus 17 | * , i.e PinName buspins[8]={PC_0,PC_1,PC_2,PC_3,D9,D8,D7,D6}; 18 | * @param CS pin connected to CS of display 19 | * @param reset pin connected to RESET of display 20 | * @param DC pin connected to data/command of display 21 | * @param WR pin connected to SDI of display 22 | * @param RD pin connected to RS of display 23 | */ 24 | BUS8(PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD); 25 | 26 | protected: 27 | 28 | /** Send 8bit command to display controller 29 | * 30 | * @param cmd: byte to send 31 | * 32 | */ 33 | virtual void wr_cmd8(unsigned char cmd); 34 | 35 | /** Send 8bit data to display controller 36 | * 37 | * @param data: byte to send 38 | * 39 | */ 40 | virtual void wr_data8(unsigned char data); 41 | 42 | /** Send 2x8bit command to display controller 43 | * 44 | * @param cmd: halfword to send 45 | * 46 | */ 47 | virtual void wr_cmd16(unsigned short cmd); 48 | 49 | /** Send 2x8bit data to display controller 50 | * 51 | * @param data: halfword to send 52 | * 53 | */ 54 | virtual void wr_data16(unsigned short data); 55 | 56 | /** Send 16bit pixeldata to display controller 57 | * 58 | * @param data: halfword to send 59 | * 60 | */ 61 | virtual void wr_gram(unsigned short data); 62 | 63 | /** Send same 16bit pixeldata to display controller multiple times 64 | * 65 | * @param data: halfword to send 66 | * @param count: how many 67 | * 68 | */ 69 | virtual void wr_gram(unsigned short data, unsigned int count); 70 | 71 | /** Send array of pixeldata shorts to display controller 72 | * 73 | * @param data: unsigned short pixeldata array 74 | * @param lenght: lenght (in shorts) 75 | * 76 | */ 77 | virtual void wr_grambuf(unsigned short* data, unsigned int lenght); 78 | 79 | /** Read 16bit pixeldata from display controller (with dummy cycle) 80 | * 81 | * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit 82 | * @returns 16bit color 83 | */ 84 | virtual unsigned short rd_gram(bool convert); 85 | 86 | /** Read 4x8bit register data (with dummy cycle) 87 | * @param reg the register to read 88 | * @returns data as uint 89 | * 90 | */ 91 | virtual unsigned int rd_reg_data32(unsigned char reg); 92 | 93 | /** Read 3x8bit ExtendedCommands register data 94 | * @param reg the register to read 95 | * @returns data as uint 96 | * @note EXTC regs (0xB0 to 0xFF) are read/write registers, for Parallel mode directly accessible in both directions 97 | */ 98 | virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd); 99 | 100 | /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent 101 | * for PAR protocols: a signle RD bit toggle 102 | * for SPI8: 8clocks 103 | * for SPI16: 16 clocks 104 | */ 105 | virtual void dummyread (); 106 | 107 | /** ILI932x specific, select register for a successive write or read 108 | * 109 | * @param reg register to be selected 110 | * @param forread false = a write next (default), true = a read next 111 | * @note forread only used by SPI protocols 112 | */ 113 | virtual void reg_select(unsigned char reg, bool forread =false); 114 | 115 | /** ILI932x specific, write register with data 116 | * 117 | * @param reg register to write 118 | * @param data 16bit data 119 | */ 120 | virtual void reg_write(unsigned char reg, unsigned short data); 121 | 122 | /** ILI932x specific, read register 123 | * 124 | * @param reg register to be read 125 | * @returns 16bit register value 126 | */ 127 | virtual unsigned short reg_read(unsigned char reg); 128 | 129 | /** HW reset sequence (without display init commands) 130 | */ 131 | virtual void hw_reset(); 132 | 133 | /** Set ChipSelect high or low 134 | * @param enable 0/1 135 | */ 136 | virtual void BusEnable(bool enable); 137 | 138 | 139 | 140 | private: 141 | 142 | BusInOut _bus; 143 | DigitalOut _CS; 144 | DigitalOut _reset; 145 | DigitalOut _DC; 146 | DigitalOut _WR; 147 | DigitalOut _RD; 148 | 149 | }; 150 | #endif -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/I2C_bus.cpp: -------------------------------------------------------------------------------- 1 | /* mbed UniGraphic library - I2C protocol class 2 | * Copyright (c) 2017 Peter Drescher 3 | * Released under the MIT License: http://mbed.org/license/mit 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 8 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 9 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 10 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 11 | * THE SOFTWARE. 12 | */ 13 | 14 | #include "I2C_bus.h" 15 | 16 | I2C_bus::I2C_bus(int Hz, int address, PinName sda, PinName scl) 17 | : _i2c(sda,scl) 18 | { 19 | _i2c.frequency(Hz); 20 | _address = address; 21 | //hw_reset(); 22 | } 23 | 24 | void I2C_bus::wr_cmd8(unsigned char cmd) 25 | { 26 | char tmp[2]; 27 | tmp[0] = 0x00; //command 28 | tmp[1] = cmd; 29 | _i2c.write(_address,tmp,2); 30 | } 31 | void I2C_bus::wr_data8(unsigned char data) 32 | { 33 | _i2c.write(data); // write 8bit 34 | } 35 | void I2C_bus::wr_cmd16(unsigned short cmd) 36 | { 37 | char tmp[3]; 38 | tmp[0] = 00; //command 39 | tmp[1] = cmd>>8; 40 | tmp[2] = cmd&0xFF; 41 | 42 | _i2c.write(_address,tmp,3); 43 | } 44 | void I2C_bus::wr_data16(unsigned short data) 45 | { 46 | _i2c.write(data>>8); // write 8bit 47 | _i2c.write(data&0xFF); // write 8bit 48 | } 49 | void I2C_bus::wr_gram(unsigned short data) 50 | { 51 | _i2c.write(data>>8); // write 8bit 52 | _i2c.write(data&0xFF); // write 8bit 53 | } 54 | void I2C_bus::wr_gram(unsigned short data, unsigned int count) 55 | { 56 | _i2c.start(); 57 | _i2c.write(_address); 58 | _i2c.write(0x40); // data continue 59 | if((data>>8)==(data&0xFF)) 60 | { 61 | count<<=1; 62 | while(count) 63 | { 64 | _i2c.write(data); // write 8bit 65 | count--; 66 | } 67 | } 68 | else 69 | { 70 | while(count) 71 | { 72 | _i2c.write(data>>8); // write 8bit 73 | _i2c.write(data&0xFF); // write 8bit 74 | count--; 75 | } 76 | } 77 | _i2c.stop(); 78 | } 79 | void I2C_bus::wr_grambuf(unsigned short* data, unsigned int lenght) 80 | { 81 | _i2c.start(); 82 | _i2c.write(_address); 83 | _i2c.write(0x40); // data continue 84 | while(lenght) 85 | { 86 | _i2c.write((*data)>>8); // write 8bit 87 | _i2c.write((*data)&0xFF); // write 8bit 88 | data++; 89 | lenght--; 90 | } 91 | _i2c.stop(); 92 | } 93 | 94 | void I2C_bus::hw_reset() 95 | { 96 | 97 | } 98 | void I2C_bus::BusEnable(bool enable) 99 | { 100 | } 101 | 102 | void I2C_bus::reg_select(unsigned char reg, bool forread) 103 | { 104 | } 105 | 106 | unsigned int I2C_bus::rd_reg_data32(unsigned char reg) 107 | { 108 | return 0; 109 | } 110 | 111 | unsigned int I2C_bus::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) 112 | { 113 | return 0; 114 | } 115 | 116 | void I2C_bus::dummyread() 117 | { 118 | } 119 | 120 | unsigned short I2C_bus::rd_gram(bool convert) 121 | { 122 | return (0); 123 | } 124 | 125 | unsigned short I2C_bus::reg_read(unsigned char reg) 126 | { 127 | return (0); 128 | } 129 | 130 | void I2C_bus::reg_write(unsigned char reg, unsigned short data) 131 | { 132 | } -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/I2C_bus.h: -------------------------------------------------------------------------------- 1 | #ifndef I2C_bus_H 2 | #define I2C_bus_H 3 | 4 | #include "mbed.h" 5 | #include "Protocols.h" 6 | 7 | /** I2C interface 8 | */ 9 | class I2C_bus : public Protocols 10 | { 11 | public: 12 | 13 | /** Create an I2C display interface 14 | * 15 | * @param I2C frquency 16 | * @param I2C address 17 | * @param I2C pin sda 18 | * @param I2C pin scl 19 | */ 20 | I2C_bus(int Hz, int address,PinName sda, PinName scl); 21 | 22 | protected: 23 | 24 | /** Send 8bit command to display controller 25 | * 26 | * @param cmd: byte to send 27 | * 28 | */ 29 | virtual void wr_cmd8(unsigned char cmd); 30 | 31 | /** Send 8bit data to display controller 32 | * 33 | * @param data: byte to send 34 | * 35 | */ 36 | virtual void wr_data8(unsigned char data); 37 | 38 | /** Send 2x8bit command to display controller 39 | * 40 | * @param cmd: halfword to send 41 | * @note in SPI_16 mode a single 16bit transfer will be done 42 | */ 43 | virtual void wr_cmd16(unsigned short cmd); 44 | 45 | /** Send 2x8bit data to display controller 46 | * 47 | * @param data: halfword to send 48 | * @note in SPI_16 mode a single 16bit transfer will be done 49 | */ 50 | virtual void wr_data16(unsigned short data); 51 | 52 | /** Send 16bit pixeldata to display controller 53 | * 54 | * @param data: halfword to send 55 | * 56 | */ 57 | virtual void wr_gram(unsigned short data); 58 | 59 | /** Send same 16bit pixeldata to display controller multiple times 60 | * 61 | * @param data: halfword to send 62 | * @param count: how many 63 | * 64 | */ 65 | virtual void wr_gram(unsigned short data, unsigned int count); 66 | 67 | /** Send array of pixeldata shorts to display controller 68 | * 69 | * @param data: unsigned short pixeldata array 70 | * @param lenght: lenght (in shorts) 71 | * 72 | */ 73 | virtual void wr_grambuf(unsigned short* data, unsigned int lenght); 74 | 75 | /** Read 16bit pixeldata from display controller (with dummy cycle) 76 | * 77 | * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit 78 | * @returns 16bit color 79 | */ 80 | virtual unsigned short rd_gram(bool convert); 81 | 82 | /** Read 4x8bit register data ( 83 | * reading from display ia I2C is not implemented in most controllers ! 84 | * 85 | */ 86 | virtual unsigned int rd_reg_data32(unsigned char reg); 87 | 88 | /** Read 3x8bit ExtendedCommands register data 89 | * reading from display ia I2C is not implemented in most controllers ! 90 | */ 91 | virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd); 92 | 93 | /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent 94 | * reading from display ia I2C is not implemented in most controllers ! 95 | */ 96 | virtual void dummyread (); 97 | 98 | /** ILI932x specific, select register for a successive write or read 99 | * 100 | * reading from display ia I2C is not implemented in most controllers ! 101 | */ 102 | virtual void reg_select(unsigned char reg, bool forread =false); 103 | 104 | /** ILI932x specific, write register with data 105 | * 106 | * @param reg register to write 107 | * @param data 16bit data 108 | * not implemented for I2C ! 109 | */ 110 | virtual void reg_write(unsigned char reg, unsigned short data); 111 | 112 | /** ILI932x specific, read register 113 | * 114 | * @param reg register to be read 115 | * @returns 16bit register value 116 | * not implemented for I2C ! 117 | */ 118 | virtual unsigned short reg_read(unsigned char reg); 119 | 120 | /** HW reset sequence (without display init commands) 121 | * most I2C displays have no reset signal ! 122 | */ 123 | virtual void hw_reset(); 124 | 125 | /** Set ChipSelect high or low 126 | * @param enable 0/1 127 | * not implemented for I2C ! 128 | */ 129 | virtual void BusEnable(bool enable); 130 | 131 | private: 132 | 133 | I2C _i2c; 134 | int _address; 135 | 136 | }; 137 | 138 | 139 | #endif -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/PAR16.cpp: -------------------------------------------------------------------------------- 1 | /* mbed UniGraphic library - PAR16 protocol class 2 | * Copyright (c) 2015 Giuliano Dianda 3 | * Released under the MIT License: http://mbed.org/license/mit 4 | * 5 | * Derived work of: 6 | * 7 | * mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller 8 | * Copyright (c) 2013 Peter Drescher - DC2PD 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 16 | * THE SOFTWARE. 17 | */ 18 | #include "platform.h" 19 | #if DEVICE_PORTINOUT 20 | 21 | #include "PAR16.h" 22 | 23 | PAR16::PAR16(PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD) 24 | : _port(port,0xFFFF), _CS(CS), _reset(reset), _DC(DC), _WR(WR), _RD(RD) 25 | { 26 | _reset = 1; 27 | _DC=1; 28 | _WR=1; 29 | _RD=1; 30 | _CS=1; 31 | _port.mode(PullNone); 32 | _port.output(); // will re-enable our GPIO port 33 | hw_reset(); 34 | } 35 | 36 | void PAR16::wr_cmd8(unsigned char cmd) 37 | { 38 | _DC = 0; // 0=cmd 39 | _port.write(cmd); // write 8bit 40 | _WR=0; 41 | _WR=1; 42 | _DC = 1; // 1=data next 43 | } 44 | void PAR16::wr_data8(unsigned char data) 45 | { 46 | _port.write(data); // write 8bit 47 | _WR=0; 48 | _WR=1; 49 | } 50 | void PAR16::wr_cmd16(unsigned short cmd) 51 | { 52 | _DC = 0; // 0=cmd 53 | _port.write(cmd>>8); // write 8bit 54 | _WR=0; 55 | _WR=1; 56 | _port.write(cmd&0xFF); // write 8bit 57 | _WR=0; 58 | _WR=1; 59 | _DC = 1; // 1=data next 60 | } 61 | void PAR16::wr_data16(unsigned short data) 62 | { 63 | _port.write(data>>8); // write 8bit 64 | _WR=0; 65 | _WR=1; 66 | _port.write(data&0xFF); // write 8bit 67 | _WR=0; 68 | _WR=1; 69 | } 70 | void PAR16::wr_gram(unsigned short data) 71 | { 72 | _port.write(data); // write 16bit 73 | _WR=0; 74 | _WR=1; 75 | } 76 | void PAR16::wr_gram(unsigned short data, unsigned int count) 77 | { 78 | while(count) 79 | { 80 | _port.write(data); // rewrite even if same data, otherwise too much fast 81 | _WR=0; 82 | _WR=1; 83 | count--; 84 | } 85 | } 86 | void PAR16::wr_grambuf(unsigned short* data, unsigned int lenght) 87 | { 88 | while(lenght) 89 | { 90 | _port.write(*data); // write 16bit 91 | _WR=0; 92 | _WR=1; 93 | data++; 94 | lenght--; 95 | } 96 | } 97 | unsigned short PAR16::rd_gram(bool convert) 98 | { 99 | unsigned int r=0; 100 | _port.input(); 101 | 102 | _RD = 0; 103 | _port.read(); //dummy read 104 | _RD = 1; 105 | 106 | _RD = 0; 107 | // _RD = 0; // add wait 108 | r |= _port.read(); 109 | _RD = 1; 110 | if(convert) 111 | { 112 | r <<= 8; 113 | _RD = 0; 114 | // _RD = 0; // add wait 115 | r |= _port.read()>>8; //MSB of port read is blue, LSB is red of next pixel 116 | _RD = 1; 117 | // gram is 18bit/pixel, if you set 16bit/pixel (cmd 3A), during writing the 16bits are expanded to 18bit 118 | // during reading, you read the raw 18bit gram 119 | r = RGB24to16((r&0xFF0000)>>16, (r&0xFF00)>>8, r&0xFF);// 18bit pixel padded to 24bits, rrrrrr00_gggggg00_bbbbbb00, converted to 16bit 120 | } 121 | _port.output(); 122 | return (unsigned short)r; 123 | } 124 | unsigned int PAR16::rd_reg_data32(unsigned char reg) 125 | { 126 | wr_cmd8(reg); 127 | unsigned int r=0; 128 | // _DC = 1; // 1=data 129 | _port.input(); 130 | 131 | _RD = 0; 132 | _port.read(); //dummy read 133 | _RD = 1; 134 | 135 | _RD = 0; 136 | // _RD = 0; // add wait 137 | r |= (_port.read()&0xFF); 138 | r <<= 8; 139 | _RD = 1; 140 | 141 | _RD = 0; 142 | // _RD = 0; // add wait 143 | r |= (_port.read()&0xFF); 144 | r <<= 8; 145 | _RD = 1; 146 | 147 | _RD = 0; 148 | // _RD = 0; // add wait 149 | r |= (_port.read()&0xFF); 150 | r <<= 8; 151 | _RD = 1; 152 | 153 | _RD = 0; 154 | // _RD = 0; // add wait 155 | r |= (_port.read()&0xFF); 156 | _RD = 1; 157 | 158 | _CS = 1; // toggle CS to interupt the cmd in case was not supported 159 | _CS = 0; 160 | 161 | _port.output(); 162 | return r; 163 | } 164 | // in Par mode EXTC regs (0xB0-0xFF) can be directly read 165 | unsigned int PAR16::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) 166 | { 167 | return rd_reg_data32(reg); 168 | } 169 | // ILI932x specific 170 | void PAR16::dummyread() 171 | { 172 | _port.input(); 173 | _RD = 0; 174 | _port.read(); // dummy read 175 | _RD=1; 176 | // _port.output(); 177 | } 178 | // ILI932x specific 179 | void PAR16::reg_select(unsigned char reg, bool forread) 180 | { 181 | _DC = 0; 182 | _port.write(reg); // write 16bit 183 | _WR=0; 184 | _WR=1; 185 | _DC = 1; // 1=data next 186 | } 187 | // ILI932x specific 188 | void PAR16::reg_write(unsigned char reg, unsigned short data) 189 | { 190 | _DC = 0; 191 | _port.write(reg); // write 16bit 192 | _WR=0; 193 | _WR=1; 194 | _DC = 1; 195 | _port.write(data); // write 16bit 196 | _WR=0; 197 | _WR=1; 198 | } 199 | // ILI932x specific 200 | unsigned short PAR16::reg_read(unsigned char reg) 201 | { 202 | unsigned short r=0; 203 | _DC = 0; 204 | _port.write(reg); // write 16bit 205 | _WR=0; 206 | _WR=1; 207 | _DC = 1; 208 | _port.input(); 209 | _RD=0; 210 | r |= _port.read(); // read 16bit 211 | _RD=1; 212 | _port.output(); 213 | return r; 214 | } 215 | void PAR16::hw_reset() 216 | { 217 | wait_ms(15); 218 | _DC = 1; 219 | _CS = 1; 220 | _WR = 1; 221 | _RD = 1; 222 | _reset = 0; // display reset 223 | wait_ms(2); 224 | _reset = 1; // end reset 225 | wait_ms(100); 226 | } 227 | void PAR16::BusEnable(bool enable) 228 | { 229 | _CS = enable ? 0:1; 230 | } 231 | 232 | #endif -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/PAR16.h: -------------------------------------------------------------------------------- 1 | #ifndef PAR16_H 2 | #define PAR16_H 3 | 4 | #include "mbed.h" 5 | #include "Protocols.h" 6 | 7 | #if DEVICE_PORTINOUT 8 | 9 | //#include "GraphicsDisplay.h" 10 | 11 | /** Parallel 16bit interface 12 | */ 13 | class PAR16 : public Protocols 14 | { 15 | public: 16 | 17 | /** Create a PAR16 display interface with a GPIO port and 5 control pins 18 | * 19 | * @param port GPIO port to use 20 | * @param CS pin connected to CS of display 21 | * @param reset pin connected to RESET of display 22 | * @param DC pin connected to data/command of display 23 | * @param WR pin connected to SDI of display 24 | * @param RD pin connected to RS of display 25 | */ 26 | PAR16(PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD); 27 | 28 | protected: 29 | 30 | /** Send 8bit command to display controller 31 | * 32 | * @param cmd: byte to send 33 | * 34 | */ 35 | virtual void wr_cmd8(unsigned char cmd); 36 | 37 | /** Send 8bit data to display controller 38 | * 39 | * @param data: byte to send 40 | * 41 | */ 42 | virtual void wr_data8(unsigned char data); 43 | 44 | /** Send 2x8bit command to display controller 45 | * 46 | * @param cmd: halfword to send 47 | * @note 2cycles using pins[7:0] 48 | */ 49 | virtual void wr_cmd16(unsigned short cmd); 50 | 51 | /** Send 2x8bit data to display controller 52 | * 53 | * @param data: halfword to send 54 | * @note 2cycles using pins[7:0], only gram write cmd uses pins[15:8] 55 | */ 56 | virtual void wr_data16(unsigned short data); 57 | 58 | /** Send 16bit pixeldata to display controller 59 | * 60 | * @param data: halfword to send 61 | * @note here using all pins[15:0] 62 | */ 63 | virtual void wr_gram(unsigned short data); 64 | 65 | /** Send same 16bit pixeldata to display controller multiple times 66 | * 67 | * @param data: halfword to send 68 | * @param count: how many 69 | * @note here using all pins[15:0] 70 | */ 71 | virtual void wr_gram(unsigned short data, unsigned int count); 72 | 73 | /** Send array of pixeldata shorts to display controller 74 | * 75 | * @param data: unsigned short pixeldata array 76 | * @param lenght: lenght (in shorts) 77 | * @note here using all pins[15:0] 78 | */ 79 | virtual void wr_grambuf(unsigned short* data, unsigned int lenght); 80 | 81 | /** Read 16bit pixeldata from display controller (with dummy cycle) 82 | * 83 | * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit 84 | * @returns 16bit color 85 | */ 86 | virtual unsigned short rd_gram(bool convert); 87 | 88 | /** Read 4x8bit register data (with dummy cycle) 89 | * @param reg the register to read 90 | * @returns data as uint 91 | * 92 | */ 93 | virtual unsigned int rd_reg_data32(unsigned char reg); 94 | 95 | /** Read 3x8bit ExtendedCommands register data 96 | * @param reg the register to read 97 | * @returns data as uint 98 | * @note EXTC regs (0xB0 to 0xFF) are read/write registers, for Parallel mode directly accessible in both directions 99 | */ 100 | virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd); 101 | 102 | /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent 103 | * for PAR protocols: a signle RD bit toggle 104 | * for SPI8: 8clocks 105 | * for SPI16: 16 clocks 106 | */ 107 | virtual void dummyread (); 108 | 109 | /** ILI932x specific, select register for a successive write or read 110 | * 111 | * @param reg register to be selected 112 | * @param forread false = a write next (default), true = a read next 113 | * @note forread only used by SPI protocols 114 | */ 115 | virtual void reg_select(unsigned char reg, bool forread =false); 116 | 117 | /** ILI932x specific, write register with data 118 | * 119 | * @param reg register to write 120 | * @param data 16bit data 121 | */ 122 | virtual void reg_write(unsigned char reg, unsigned short data); 123 | 124 | /** ILI932x specific, read register 125 | * 126 | * @param reg register to be read 127 | * @returns 16bit register value 128 | */ 129 | virtual unsigned short reg_read(unsigned char reg); 130 | 131 | /** HW reset sequence (without display init commands) 132 | */ 133 | virtual void hw_reset(); 134 | 135 | /** Set ChipSelect high or low 136 | * @param enable 0/1 137 | */ 138 | virtual void BusEnable(bool enable); 139 | 140 | 141 | 142 | private: 143 | 144 | PortInOut _port; 145 | DigitalOut _CS; 146 | DigitalOut _reset; 147 | DigitalOut _DC; 148 | DigitalOut _WR; 149 | DigitalOut _RD; 150 | 151 | }; 152 | #endif 153 | 154 | #endif -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/PAR8.cpp: -------------------------------------------------------------------------------- 1 | /* mbed UniGraphic library - PAR8 protocol class 2 | * Copyright (c) 2015 Giuliano Dianda 3 | * Released under the MIT License: http://mbed.org/license/mit 4 | * 5 | * Derived work of: 6 | * 7 | * mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller 8 | * Copyright (c) 2013 Peter Drescher - DC2PD 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 16 | * THE SOFTWARE. 17 | */ 18 | #include "platform.h" 19 | #if DEVICE_PORTINOUT 20 | 21 | #include "PAR8.h" 22 | 23 | PAR8::PAR8(PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD) 24 | : _port(port,0xFF), _CS(CS), _reset(reset), _DC(DC), _WR(WR), _RD(RD) 25 | { 26 | _reset = 1; 27 | _DC=1; 28 | _WR=1; 29 | _RD=1; 30 | _CS=1; 31 | _port.mode(PullNone); 32 | _port.output(); // will re-enable our GPIO port 33 | hw_reset(); 34 | } 35 | 36 | void PAR8::wr_cmd8(unsigned char cmd) 37 | { 38 | _DC = 0; // 0=cmd 39 | _port.write(cmd); // write 8bit 40 | _WR=0; 41 | _WR=1; 42 | _DC = 1; // 1=data next 43 | } 44 | void PAR8::wr_data8(unsigned char data) 45 | { 46 | _port.write(data); // write 8bit 47 | _WR=0; 48 | _WR=1; 49 | } 50 | void PAR8::wr_cmd16(unsigned short cmd) 51 | { 52 | _DC = 0; // 0=cmd 53 | _port.write(cmd>>8); // write 8bit 54 | _WR=0; 55 | _WR=1; 56 | _port.write(cmd&0xFF); // write 8bit 57 | _WR=0; 58 | _WR=1; 59 | _DC = 1; // 1=data next 60 | } 61 | void PAR8::wr_data16(unsigned short data) 62 | { 63 | _port.write(data>>8); // write 8bit 64 | _WR=0; 65 | _WR=1; 66 | _port.write(data&0xFF); // write 8bit 67 | _WR=0; 68 | _WR=1; 69 | } 70 | void PAR8::wr_gram(unsigned short data) 71 | { 72 | _port.write(data>>8); // write 8bit 73 | _WR=0; 74 | _WR=1; 75 | _port.write(data&0xFF); // write 8bit 76 | _WR=0; 77 | _WR=1; 78 | } 79 | void PAR8::wr_gram(unsigned short data, unsigned int count) 80 | { 81 | if((data>>8)==(data&0xFF)) 82 | { 83 | count<<=1; 84 | // _port.write(data); // write 8bit 85 | while(count) 86 | { 87 | _port.write(data); // rewrite even if same data, otherwise too much fast 88 | _WR=0; 89 | _WR=1; 90 | count--; 91 | } 92 | } 93 | else 94 | { 95 | while(count) 96 | { 97 | _port.write(data>>8); // write 8bit 98 | _WR=0; 99 | _WR=1; 100 | _port.write(data&0xFF); // write 8bit 101 | _WR=0; 102 | _WR=1; 103 | count--; 104 | } 105 | } 106 | } 107 | void PAR8::wr_grambuf(unsigned short* data, unsigned int lenght) 108 | { 109 | while(lenght) 110 | { 111 | _port.write((*data)>>8); // write 8bit 112 | _WR=0; 113 | _WR=1; 114 | _port.write((*data)&0xFF); // write 8bit 115 | _WR=0; 116 | _WR=1; 117 | data++; 118 | lenght--; 119 | } 120 | } 121 | unsigned short PAR8::rd_gram(bool convert) 122 | { 123 | unsigned int r=0; 124 | _port.input(); 125 | 126 | _RD = 0; 127 | _RD = 0; // add wait 128 | _port.read(); //dummy read 129 | _RD = 1; 130 | 131 | _RD = 0; 132 | _RD = 0; // add wait 133 | r |= _port.read(); 134 | _RD = 1; 135 | r <<= 8; 136 | 137 | _RD = 0; 138 | _RD = 0; // add wait 139 | r |= _port.read(); 140 | _RD = 1; 141 | if(convert) 142 | { 143 | r <<= 8; 144 | _RD = 0; 145 | // _RD = 0; // add wait 146 | r |= _port.read(); 147 | _RD = 1; 148 | // gram is 18bit/pixel, if you set 16bit/pixel (cmd 3A), during writing the 16bits are expanded to 18bit 149 | // during reading, you read the raw 18bit gram 150 | r = RGB24to16((r&0xFF0000)>>16, (r&0xFF00)>>8, r&0xFF);// 18bit pixel padded to 24bits, rrrrrr00_gggggg00_bbbbbb00, converted to 16bit 151 | } 152 | _port.output(); 153 | return (unsigned short)r; 154 | } 155 | unsigned int PAR8::rd_reg_data32(unsigned char reg) 156 | { 157 | wr_cmd8(reg); 158 | unsigned int r=0; 159 | _port.input(); 160 | 161 | _RD = 0; 162 | _port.read(); //dummy read 163 | _RD = 1; 164 | 165 | _RD = 0; 166 | // _RD = 0; // add wait 167 | r |= (_port.read()&0xFF); 168 | r <<= 8; 169 | _RD = 1; 170 | 171 | _RD = 0; 172 | // _RD = 0; // add wait 173 | r |= (_port.read()&0xFF); 174 | r <<= 8; 175 | _RD = 1; 176 | 177 | _RD = 0; 178 | // _RD = 0; // add wait 179 | r |= (_port.read()&0xFF); 180 | r <<= 8; 181 | _RD = 1; 182 | 183 | _RD = 0; 184 | // _RD = 0; // add wait 185 | r |= (_port.read()&0xFF); 186 | _RD = 1; 187 | 188 | _CS = 1; // force CS HIG to interupt the cmd in case was not supported 189 | _CS = 0; 190 | _port.output(); 191 | return r; 192 | } 193 | // in Par mode EXTC regs (0xB0-0xFF) can be directly read 194 | unsigned int PAR8::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) 195 | { 196 | return rd_reg_data32(reg); 197 | } 198 | // ILI932x specific 199 | void PAR8::dummyread() 200 | { 201 | _port.input(); 202 | _RD=0; 203 | _RD=0; // add wait 204 | _port.read(); // dummy read 205 | _RD=1; 206 | // _port.output(); 207 | } 208 | // ILI932x specific 209 | void PAR8::reg_select(unsigned char reg, bool forread) 210 | { 211 | _DC = 0; 212 | _port.write(0); // write MSB 213 | _WR=0; 214 | _WR=1; 215 | _port.write(reg); // write LSB 216 | _WR=0; 217 | _WR=1; 218 | _DC = 1; // 1=data next 219 | } 220 | // ILI932x specific 221 | void PAR8::reg_write(unsigned char reg, unsigned short data) 222 | { 223 | _DC = 0; 224 | _port.write(0); // write MSB 225 | _WR=0; 226 | _WR=1; 227 | _port.write(reg); // write MSB 228 | _WR=0; 229 | _WR=1; 230 | _DC = 1; 231 | _port.write(data>>8); 232 | _WR=0; 233 | _WR=1; 234 | _port.write(data&0xFF); 235 | _WR=0; 236 | _WR=1; 237 | } 238 | // ILI932x specific 239 | unsigned short PAR8::reg_read(unsigned char reg) 240 | { 241 | unsigned short r=0; 242 | _DC = 0; 243 | _port.write(0); 244 | _WR=0; 245 | _WR=1; 246 | _port.write(reg); 247 | _WR=0; 248 | _WR=1; 249 | _DC = 1; 250 | _port.input(); 251 | _RD=0; 252 | r |= _port.read(); // read 8bit 253 | _RD=1; 254 | r <<= 8; 255 | _RD=0; 256 | r |= _port.read(); // read 8bit 257 | _RD=1; 258 | _port.output(); 259 | 260 | return r; 261 | } 262 | void PAR8::hw_reset() 263 | { 264 | wait_ms(15); 265 | _DC = 1; 266 | _CS = 1; 267 | _WR = 1; 268 | _RD = 1; 269 | _reset = 0; // display reset 270 | wait_ms(2); 271 | _reset = 1; // end reset 272 | wait_ms(100); 273 | } 274 | void PAR8::BusEnable(bool enable) 275 | { 276 | _CS = enable ? 0:1; 277 | } 278 | 279 | #endif -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/PAR8.h: -------------------------------------------------------------------------------- 1 | #ifndef PAR8_H 2 | #define PAR8_H 3 | 4 | #include "mbed.h" 5 | #include "Protocols.h" 6 | 7 | #if DEVICE_PORTINOUT 8 | //#include "GraphicsDisplay.h" 9 | 10 | /** Parallel 8bit interface 11 | */ 12 | class PAR8 : public Protocols 13 | { 14 | public: 15 | 16 | /** Create a PAR8 display interface with a GPIO port and 5 control pins 17 | * 18 | * @param port GPIO port to use 19 | * @param CS pin connected to CS of display 20 | * @param reset pin connected to RESET of display 21 | * @param DC pin connected to data/command of display 22 | * @param WR pin connected to SDI of display 23 | * @param RD pin connected to RS of display 24 | */ 25 | PAR8(PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD); 26 | 27 | protected: 28 | 29 | /** Send 8bit command to display controller 30 | * 31 | * @param cmd: byte to send 32 | * 33 | */ 34 | virtual void wr_cmd8(unsigned char cmd); 35 | 36 | /** Send 8bit data to display controller 37 | * 38 | * @param data: byte to send 39 | * 40 | */ 41 | virtual void wr_data8(unsigned char data); 42 | 43 | /** Send 2x8bit command to display controller 44 | * 45 | * @param cmd: halfword to send 46 | * 47 | */ 48 | virtual void wr_cmd16(unsigned short cmd); 49 | 50 | /** Send 2x8bit data to display controller 51 | * 52 | * @param data: halfword to send 53 | * 54 | */ 55 | virtual void wr_data16(unsigned short data); 56 | 57 | /** Send 16bit pixeldata to display controller 58 | * 59 | * @param data: halfword to send 60 | * 61 | */ 62 | virtual void wr_gram(unsigned short data); 63 | 64 | /** Send same 16bit pixeldata to display controller multiple times 65 | * 66 | * @param data: halfword to send 67 | * @param count: how many 68 | * 69 | */ 70 | virtual void wr_gram(unsigned short data, unsigned int count); 71 | 72 | /** Send array of pixeldata shorts to display controller 73 | * 74 | * @param data: unsigned short pixeldata array 75 | * @param lenght: lenght (in shorts) 76 | * 77 | */ 78 | virtual void wr_grambuf(unsigned short* data, unsigned int lenght); 79 | 80 | /** Read 16bit pixeldata from display controller (with dummy cycle) 81 | * 82 | * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit 83 | * @returns 16bit color 84 | */ 85 | virtual unsigned short rd_gram(bool convert); 86 | 87 | /** Read 4x8bit register data (with dummy cycle) 88 | * @param reg the register to read 89 | * @returns data as uint 90 | * 91 | */ 92 | virtual unsigned int rd_reg_data32(unsigned char reg); 93 | 94 | /** Read 3x8bit ExtendedCommands register data 95 | * @param reg the register to read 96 | * @returns data as uint 97 | * @note EXTC regs (0xB0 to 0xFF) are read/write registers, for Parallel mode directly accessible in both directions 98 | */ 99 | virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd); 100 | 101 | /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent 102 | * for PAR protocols: a signle RD bit toggle 103 | * for SPI8: 8clocks 104 | * for SPI16: 16 clocks 105 | */ 106 | virtual void dummyread (); 107 | 108 | /** ILI932x specific, select register for a successive write or read 109 | * 110 | * @param reg register to be selected 111 | * @param forread false = a write next (default), true = a read next 112 | * @note forread only used by SPI protocols 113 | */ 114 | virtual void reg_select(unsigned char reg, bool forread =false); 115 | 116 | /** ILI932x specific, write register with data 117 | * 118 | * @param reg register to write 119 | * @param data 16bit data 120 | */ 121 | virtual void reg_write(unsigned char reg, unsigned short data); 122 | 123 | /** ILI932x specific, read register 124 | * 125 | * @param reg register to be read 126 | * @returns 16bit register value 127 | */ 128 | virtual unsigned short reg_read(unsigned char reg); 129 | 130 | /** HW reset sequence (without display init commands) 131 | */ 132 | virtual void hw_reset(); 133 | 134 | /** Set ChipSelect high or low 135 | * @param enable 0/1 136 | */ 137 | virtual void BusEnable(bool enable); 138 | 139 | 140 | 141 | private: 142 | 143 | PortInOut _port; 144 | DigitalOut _CS; 145 | DigitalOut _reset; 146 | DigitalOut _DC; 147 | DigitalOut _WR; 148 | DigitalOut _RD; 149 | 150 | }; 151 | #endif 152 | 153 | #endif -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/Protocols.h: -------------------------------------------------------------------------------- 1 | /* mbed UniGraphic library - Abstract protocol class 2 | * Copyright (c) 2015 Giuliano Dianda 3 | * Released under the MIT License: http://mbed.org/license/mit 4 | */ 5 | 6 | /** @file Protocols.h 7 | */ 8 | #ifndef Protocols_H 9 | #define Protocols_H 10 | 11 | #include "mbed.h" 12 | 13 | #define RGB24to16(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue 14 | #define BGR2RGB(color) (((color&0x1F)<<11) | (color&0x7E0) | ((color&0xF800)>>11)) 15 | 16 | #define FLIP_NONE 0 17 | #define FLIP_X 1 18 | #define FLIP_Y 2 19 | 20 | //#define USE_CS 21 | 22 | /** Protocol types 23 | */ 24 | #include "platform.h" 25 | 26 | #if DEVICE_PORTINOUT 27 | enum proto_t { 28 | PAR_8 /**< Parallel 8bit, port pins 0 to 7 */ 29 | ,PAR_16 /**< Parallel 16bit, port pins 0 to 15 */ 30 | ,BUS_8 /**< Parallel 8bit, scattered pins */ 31 | ,BUS_16 /**< Parallel 16bit, scattered pins */ 32 | ,SPI_8 /**< SPI 8bit */ 33 | ,SPI_16 /**< SPI 16bit */ 34 | ,I2C_ /**< I2C */ 35 | }; 36 | #else 37 | enum proto_t { 38 | BUS_8 /**< Parallel 8bit, scattered pins */ 39 | ,BUS_16 /**< Parallel 16bit, scattered pins */ 40 | ,SPI_8 /**< SPI 8bit */ 41 | ,SPI_16 /**< SPI 16bit */ 42 | ,I2C_ /**< I2C */ 43 | }; 44 | #endif 45 | 46 | 47 | /** Abstract interface class for spi and parallel protocols 48 | */ 49 | class Protocols 50 | { 51 | public: 52 | 53 | /** Send 8bit command to display controller 54 | * 55 | * @param cmd: byte to send 56 | * 57 | */ 58 | virtual void wr_cmd8(unsigned char cmd) = 0; 59 | 60 | /** Send 8bit data to display controller 61 | * 62 | * @param data: byte to send 63 | * 64 | */ 65 | virtual void wr_data8(unsigned char data) = 0; 66 | 67 | /** Send 2x8bit command to display controller 68 | * 69 | * @param cmd: halfword to send 70 | * 71 | */ 72 | virtual void wr_cmd16(unsigned short cmd) = 0; 73 | 74 | /** Send 2x8bit data to display controller 75 | * 76 | * @param data: halfword to send 77 | * 78 | */ 79 | virtual void wr_data16(unsigned short data) = 0; 80 | 81 | /** Send 16bit pixeldata to display controller 82 | * 83 | * @param data: halfword to send 84 | * 85 | */ 86 | virtual void wr_gram(unsigned short data) = 0; 87 | 88 | /** Send same 16bit pixeldata to display controller multiple times 89 | * 90 | * @param data: halfword to send 91 | * @param count: how many 92 | * 93 | */ 94 | virtual void wr_gram(unsigned short data, unsigned int count) = 0; 95 | 96 | /** Send array of pixeldata shorts to display controller 97 | * 98 | * @param data: unsigned short pixeldata array 99 | * @param lenght: lenght (in shorts) 100 | * 101 | */ 102 | virtual void wr_grambuf(unsigned short* data, unsigned int lenght) = 0; 103 | 104 | /** Read 16bit pixeldata from display controller (with dummy cycle) 105 | * 106 | * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit 107 | * @returns 16bit color 108 | */ 109 | virtual unsigned short rd_gram(bool convert) = 0; 110 | 111 | /** Read 4x8bit register data (with dummy cycle) 112 | * @param reg the register to read 113 | * @returns data as uint 114 | * 115 | */ 116 | virtual unsigned int rd_reg_data32(unsigned char reg) = 0; 117 | 118 | /** Read 3x8bit ExtendedCommands register data 119 | * @param reg the register to read 120 | * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers 121 | * @returns data as uint 122 | * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode 123 | */ 124 | virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) = 0; 125 | 126 | /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent 127 | * for PAR protocols: a signle RD bit toggle 128 | * for SPI8: 8clocks 129 | * for SPI16: 16 clocks 130 | */ 131 | virtual void dummyread () = 0; 132 | 133 | /** ILI932x specific, select register for a successive write or read 134 | * 135 | * @param reg register to be selected 136 | * @param forread false = a write next (default), true = a read next 137 | * @note forread only used by SPI protocols 138 | */ 139 | virtual void reg_select(unsigned char reg, bool forread =false) = 0; 140 | 141 | /** ILI932x specific, write register with data 142 | * 143 | * @param reg register to write 144 | * @param data 16bit data 145 | */ 146 | virtual void reg_write(unsigned char reg, unsigned short data) = 0; 147 | 148 | /** ILI932x specific, read register 149 | * 150 | * @param reg register to be read 151 | * @returns 16bit register value 152 | */ 153 | virtual unsigned short reg_read(unsigned char reg) = 0; 154 | 155 | /** HW reset sequence (without display init commands) 156 | */ 157 | virtual void hw_reset() = 0; 158 | 159 | /** Set ChipSelect high or low 160 | * @param enable 0/1 161 | */ 162 | virtual void BusEnable(bool enable) = 0; 163 | 164 | }; 165 | #endif -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/SPI16.cpp: -------------------------------------------------------------------------------- 1 | /* mbed UniGraphic library - SPI16 protocol class 2 | * Copyright (c) 2015 Giuliano Dianda 3 | * Released under the MIT License: http://mbed.org/license/mit 4 | * 5 | * Derived work of: 6 | * 7 | * mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller 8 | * Copyright (c) 2013 Peter Drescher - DC2PD 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 16 | * THE SOFTWARE. 17 | */ 18 | 19 | #include "SPI16.h" 20 | 21 | SPI16::SPI16(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC) 22 | : _CS(CS), _spi(mosi, miso, sclk), _reset(reset), _DC(DC) 23 | { 24 | _reset = 1; 25 | _DC=1; 26 | _CS=1; 27 | _spi.format(16,0); // 8 bit spi mode 0 28 | // _spi.frequency(12000000); // 10 Mhz SPI clock, 12mhz for F411 29 | _spi.frequency(Hz); 30 | hw_reset(); 31 | } 32 | 33 | void SPI16::wr_cmd8(unsigned char cmd) 34 | { 35 | _spi.format(8,0); // it takes time, better use wr_cmd16 with NOP cmd 36 | _DC.write(0); // 0=cmd 37 | _spi.write(cmd); // write 8bit 38 | _spi.format(16,0); 39 | _DC.write(1); // 1=data next 40 | } 41 | void SPI16::wr_data8(unsigned char data) 42 | { 43 | _spi.format(8,0); // it takes time, check prev cmd parameter, in case use wr_data16 with repeated byte 44 | _spi.write(data); // write 8bit 45 | _spi.format(16,0); 46 | } 47 | void SPI16::wr_cmd16(unsigned short cmd) 48 | { 49 | _DC.write(0); // 0=cmd 50 | _spi.write(cmd); // write 16bit 51 | _DC.write(1); // 1=data next 52 | } 53 | void SPI16::wr_data16(unsigned short data) 54 | { 55 | _spi.write(data); // write 16bit 56 | } 57 | void SPI16::wr_gram(unsigned short data) 58 | { 59 | _spi.write(data); // write 16bit 60 | } 61 | void SPI16::wr_gram(unsigned short data, unsigned int count) 62 | { 63 | while(count) 64 | { 65 | _spi.write(data); 66 | count--; 67 | } 68 | } 69 | void SPI16::wr_grambuf(unsigned short* data, unsigned int lenght) 70 | { 71 | while(lenght) 72 | { 73 | _spi.write(*data); 74 | data++; 75 | lenght--; 76 | } 77 | } 78 | unsigned short SPI16::rd_gram(bool convert) 79 | { 80 | unsigned int r=0; 81 | r |= _spi.write(0); // 16bit, whole first byte is dummy, second is red 82 | r <<= 16; 83 | r |= _spi.write(0); 84 | if(convert) 85 | { 86 | // gram is 18bit/pixel, if you set 16bit/pixel (cmd 3A), during writing the 16bits are expanded to 18bit 87 | // during reading, you read the raw 18bit gram 88 | r = RGB24to16((r&0xFF0000)>>16, (r&0xFF00)>>8, r&0xFF);// 18bit pixel padded to 24bits, rrrrrr00_gggggg00_bbbbbb00, converted to 16bit 89 | } 90 | else r >>= 8; 91 | _CS = 1; // force CS HIG to interupt the "read state" 92 | _CS = 0; 93 | 94 | return (unsigned short)r; 95 | } 96 | unsigned int SPI16::rd_reg_data32(unsigned char reg) 97 | { 98 | wr_cmd8(reg); 99 | unsigned int r=0; 100 | 101 | r |= _spi.write(0); // we get only 15bit valid, first bit was the dummy cycle 102 | r <<= 16; 103 | r |= _spi.write(0); 104 | r <<= 1; // 32bits are aligned, now collecting bit_0 105 | r |= (_spi.write(0) >> 15); 106 | // we clocked 15 more bit so ILI waiting for 16th, we need to reset spi bus 107 | _CS = 1; // force CS HIG to interupt the cmd 108 | _CS = 0; 109 | return r; 110 | } 111 | unsigned int SPI16::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) 112 | { 113 | unsigned int r=0; 114 | for(int regparam=1; regparam<4; regparam++) // when reading EXTC regs, first parameter is always dummy, so start with 1 115 | { 116 | wr_cmd8(SPIreadenablecmd); // spi-in enable cmd, 0xD9 (ili9341) or 0xFB (ili9488) or don't know 117 | wr_data8(0xF0|regparam); // in low nibble specify which reg parameter we want 118 | wr_cmd8(reg); // now send cmd (select register we want to read) 119 | r <<= 8; 120 | r |= (_spi.write(0) >> 8); 121 | } 122 | _CS = 1; // force CS HIG to interupt the cmd 123 | _CS = 0; 124 | 125 | return r; 126 | } 127 | // ILI932x specific 128 | void SPI16::dummyread() 129 | { 130 | _spi.write(0); // dummy read 131 | } 132 | // ILI932x specific 133 | void SPI16::reg_select(unsigned char reg, bool forread) 134 | { 135 | _CS = 1; //fixme: really needed? 136 | _CS = 0; //fixme: really needed? 137 | _spi.write(0x70); // write 0070 138 | _spi.write(reg); // write 16bit 139 | _CS = 1; //fixme: really needed? 140 | _CS = 0; //fixme: really needed? 141 | if(forread) _spi.write(0x73); 142 | else _spi.write(0x72); 143 | } 144 | // ILI932x specific 145 | void SPI16::reg_write(unsigned char reg, unsigned short data) 146 | { 147 | _CS = 1; //fixme: really needed? 148 | _CS = 0; //fixme: really needed? 149 | _spi.write(0x70); // write 0070 150 | _spi.write(reg); // write 16bit 151 | _CS = 1; //fixme: really needed? 152 | _CS = 0; //fixme: really needed? 153 | _spi.write(0x72); // write 0072 154 | _spi.write(data); // write 16bit 155 | } 156 | // ILI932x specific 157 | unsigned short SPI16::reg_read(unsigned char reg) 158 | { 159 | unsigned int r=0; 160 | _CS = 1; //fixme: really needed? 161 | _CS = 0; //fixme: really needed? 162 | _spi.write(0x70); // write 0070 163 | _spi.write(reg); // write 16bit 164 | _CS = 1; //fixme: really needed? 165 | _CS = 0; //fixme: really needed? 166 | _spi.write(0x73); // write 0073 167 | r |= _spi.write(0); // read 16bit, 8bit dummy + 8bit valid 168 | r <<= 16; 169 | r |= _spi.write(0); // read 16bit 170 | 171 | _CS = 1; //fixme: to resync, maybe really needed 172 | _CS = 0; //fixme: to resync, maybe really needed 173 | return (r>>8); 174 | } 175 | void SPI16::hw_reset() 176 | { 177 | wait_ms(15); 178 | _DC = 1; 179 | _CS = 1; 180 | _reset = 0; // display reset 181 | wait_ms(2); 182 | _reset = 1; // end reset 183 | wait_ms(100); 184 | } 185 | void SPI16::BusEnable(bool enable) 186 | { 187 | _CS = enable ? 0:1; 188 | } -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/SPI16.h: -------------------------------------------------------------------------------- 1 | #ifndef SPI16_H 2 | #define SPI16_H 3 | 4 | #define NDEBUG // avoid MBED_ASSERT to halt process when PinName DC==NC 5 | 6 | #include "mbed.h" 7 | #include "Protocols.h" 8 | //#include "GraphicsDisplay.h" 9 | 10 | /** SPI 16bit interface 11 | */ 12 | class SPI16 : public Protocols 13 | { 14 | public: 15 | 16 | /** Create an SPI 8bit display interface with 3 control pins 17 | * 18 | * @param SPI mosi 19 | * @param SPI miso 20 | * @param SPI sclk 21 | * @param CS pin connected to CS of display 22 | * @param reset pin connected to RESET of display 23 | * @param DC pin connected to data/command of display 24 | */ 25 | SPI16(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC=NC); 26 | 27 | protected: 28 | 29 | /** Send 8bit command to display controller 30 | * 31 | * @note switches spi format 16->8->16, better use wr_cmd16 with NOP in front 32 | * @param cmd: byte to send 33 | * 34 | */ 35 | virtual void wr_cmd8(unsigned char cmd); 36 | 37 | /** Send 8bit data to display controller 38 | * 39 | * @note switches spi format 16->8->16, better use wr_data16 with repeated byte (if does not hurt) 40 | * @param data: byte to send 41 | * 42 | */ 43 | virtual void wr_data8(unsigned char data); 44 | 45 | /** Send 2x8bit command to display controller 46 | * 47 | * @param cmd: halfword to send 48 | * @note in SPI_16 mode a single 16bit transfer will be done 49 | */ 50 | virtual void wr_cmd16(unsigned short cmd); 51 | 52 | /** Send 2x8bit data to display controller 53 | * 54 | * @param data: halfword to send 55 | * @note in SPI_16 mode a single 16bit transfer will be done 56 | */ 57 | virtual void wr_data16(unsigned short data); 58 | 59 | /** Send 16bit pixeldata to display controller 60 | * 61 | * @param data: halfword to send 62 | * 63 | */ 64 | virtual void wr_gram(unsigned short data); 65 | 66 | /** Send same 16bit pixeldata to display controller multiple times 67 | * 68 | * @param data: halfword to send 69 | * @param count: how many 70 | * 71 | */ 72 | virtual void wr_gram(unsigned short data, unsigned int count); 73 | 74 | /** Send array of pixeldata shorts to display controller 75 | * 76 | * @param data: unsigned short pixeldata array 77 | * @param lenght: lenght (in shorts) 78 | * 79 | */ 80 | virtual void wr_grambuf(unsigned short* data, unsigned int lenght); 81 | 82 | /** Read 16bit pixeldata from display controller (with dummy cycle) 83 | * 84 | * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit 85 | * @returns 16bit color 86 | */ 87 | virtual unsigned short rd_gram(bool convert); 88 | 89 | /** Read 4x8bit register data (with dummy cycle) 90 | * @param reg the register to read 91 | * @returns data as uint 92 | * 93 | */ 94 | virtual unsigned int rd_reg_data32(unsigned char reg); 95 | 96 | /** Read 3x8bit ExtendedCommands register data 97 | * @param reg the register to read 98 | * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers 99 | * @returns data as uint 100 | * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode 101 | */ 102 | virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd); 103 | 104 | /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent 105 | * for PAR protocols: a signle RD bit toggle 106 | * for SPI8: 8clocks 107 | * for SPI16: 16 clocks 108 | */ 109 | virtual void dummyread (); 110 | 111 | /** ILI932x specific, select register for a successive write or read 112 | * 113 | * @param reg register to be selected 114 | * @param forread false = a write next (default), true = a read next 115 | * @note forread only used by SPI protocols 116 | */ 117 | virtual void reg_select(unsigned char reg, bool forread =false); 118 | 119 | /** ILI932x specific, write register with data 120 | * 121 | * @param reg register to write 122 | * @param data 16bit data 123 | */ 124 | virtual void reg_write(unsigned char reg, unsigned short data); 125 | 126 | /** ILI932x specific, read register 127 | * 128 | * @param reg register to be read 129 | * @returns 16bit register value 130 | */ 131 | virtual unsigned short reg_read(unsigned char reg); 132 | 133 | /** HW reset sequence (without display init commands) 134 | */ 135 | virtual void hw_reset(); 136 | 137 | /** Set ChipSelect high or low 138 | * @param enable 0/1 139 | */ 140 | virtual void BusEnable(bool enable); 141 | 142 | DigitalOut _CS; 143 | 144 | private: 145 | 146 | SPI _spi; 147 | DigitalOut _reset; 148 | DigitalOut _DC; 149 | 150 | }; 151 | #endif -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/SPI8.cpp: -------------------------------------------------------------------------------- 1 | /* mbed UniGraphic library - SPI8 protocol class 2 | * Copyright (c) 2015 Giuliano Dianda 3 | * Released under the MIT License: http://mbed.org/license/mit 4 | * 5 | * Derived work of: 6 | * 7 | * mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller 8 | * Copyright (c) 2013 Peter Drescher - DC2PD 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 16 | * THE SOFTWARE. 17 | */ 18 | 19 | #include "SPI8.h" 20 | 21 | 22 | SPI8::SPI8(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC) 23 | : _CS(CS), _spi(mosi, miso, sclk), _reset(reset), _DC(DC) 24 | { 25 | _reset = 1; 26 | _DC=1; 27 | _CS=1; 28 | _spi.format(8,0); // 8 bit spi mode 0 29 | _spi.frequency(Hz); 30 | hw_reset(); 31 | } 32 | 33 | void SPI8::wr_cmd8(unsigned char cmd) 34 | { 35 | _DC.write(0); // 0=cmd 36 | _spi.write(cmd); // write 8bit 37 | _DC.write(1); // 1=data next 38 | } 39 | void SPI8::wr_data8(unsigned char data) 40 | { 41 | _spi.write(data); // write 8bit 42 | } 43 | void SPI8::wr_cmd16(unsigned short cmd) 44 | { 45 | _DC.write(0); // 0=cmd 46 | _spi.write(cmd>>8); // write 8bit 47 | _spi.write(cmd&0xFF); // write 8bit 48 | _DC.write(1); // 1=data next 49 | } 50 | void SPI8::wr_data16(unsigned short data) 51 | { 52 | _spi.write(data>>8); // write 8bit 53 | _spi.write(data&0xFF); // write 8bit 54 | } 55 | void SPI8::wr_gram(unsigned short data) 56 | { 57 | _spi.write(data>>8); // write 8bit 58 | _spi.write(data&0xFF); // write 8bit 59 | } 60 | void SPI8::wr_gram(unsigned short data, unsigned int count) 61 | { 62 | if((data>>8)==(data&0xFF)) 63 | { 64 | count<<=1; 65 | while(count) 66 | { 67 | _spi.write(data); // write 8bit 68 | count--; 69 | } 70 | } 71 | else 72 | { 73 | while(count) 74 | { 75 | _spi.write(data>>8); // write 8bit 76 | _spi.write(data&0xFF); // write 8bit 77 | count--; 78 | } 79 | } 80 | } 81 | void SPI8::wr_grambuf(unsigned short* data, unsigned int lenght) 82 | { 83 | while(lenght) 84 | { 85 | _spi.write((*data)>>8); // write 8bit 86 | _spi.write((*data)&0xFF); // write 8bit 87 | data++; 88 | lenght--; 89 | } 90 | } 91 | unsigned short SPI8::rd_gram(bool convert) 92 | { 93 | unsigned int r=0; 94 | _spi.write(0); // whole first byte is dummy 95 | r |= _spi.write(0); 96 | r <<= 8; 97 | r |= _spi.write(0); 98 | if(convert) 99 | { 100 | r <<= 8; 101 | r |= _spi.write(0); 102 | // gram is 18bit/pixel, if you set 16bit/pixel (cmd 3A), during writing the 16bits are expanded to 18bit 103 | // during reading, you read the raw 18bit gram 104 | r = RGB24to16((r&0xFF0000)>>16, (r&0xFF00)>>8, r&0xFF);// 18bit pixel padded to 24bits, rrrrrr00_gggggg00_bbbbbb00, converted to 16bit 105 | } 106 | _CS = 1; // force CS HIG to interupt the "read state" 107 | _CS = 0; 108 | return (unsigned short)r; 109 | } 110 | unsigned int SPI8::rd_reg_data32(unsigned char reg) 111 | { 112 | wr_cmd8(reg); 113 | unsigned int r=0; 114 | 115 | r |= _spi.write(0); // we get only 7bit valid, first bit was the dummy cycle 116 | r <<= 8; 117 | r |= _spi.write(0); 118 | r <<= 8; 119 | r |= _spi.write(0); 120 | r <<= 8; 121 | r |= _spi.write(0); 122 | r <<= 1; // 32bits are aligned, now collecting bit_0 123 | r |= (_spi.write(0) >> 7); 124 | // we clocked 7 more bit so ILI waiting for 8th, we need to reset spi bus 125 | _CS = 1; // force CS HIG to interupt the cmd 126 | _CS = 0; 127 | return r; 128 | } 129 | unsigned int SPI8::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) 130 | { 131 | unsigned int r=0; 132 | for(int regparam=1; regparam<4; regparam++) // when reading EXTC regs, first parameter is always dummy, so start with 1 133 | { 134 | wr_cmd8(SPIreadenablecmd); // spi-in enable cmd, 0xD9 (ili9341) or 0xFB (ili9488) or don't know 135 | wr_data8(0xF0|regparam); // in low nibble specify which reg parameter we want 136 | wr_cmd8(reg); // now send cmd (select register we want to read) 137 | r <<= 8; 138 | r |= _spi.write(0); 139 | // r = _spi.write(0) >> 8; for 16bit 140 | } 141 | _CS = 1; // force CS HIG to interupt the cmd 142 | _CS = 0; 143 | return r; 144 | } 145 | // ILI932x specific 146 | void SPI8::dummyread() 147 | { 148 | _spi.write(0); // dummy read 149 | } 150 | // ILI932x specific 151 | void SPI8::reg_select(unsigned char reg, bool forread) 152 | { 153 | _CS = 1; //fixme: really needed? 154 | _CS = 0; //fixme: really needed? 155 | _spi.write(0x70); 156 | _spi.write(0); // write MSB 157 | _spi.write(reg); // write LSB 158 | _CS = 1; //fixme: really needed? 159 | _CS = 0; //fixme: really needed? 160 | if(forread) _spi.write(0x73); 161 | else _spi.write(0x72); 162 | } 163 | // ILI932x specific 164 | void SPI8::reg_write(unsigned char reg, unsigned short data) 165 | { 166 | _CS = 1; //fixme: really needed? 167 | _CS = 0; //fixme: really needed? 168 | _spi.write(0x70); 169 | _spi.write(0); // write MSB 170 | _spi.write(reg); // write LSB 171 | _CS = 1; //fixme: really needed? 172 | _CS = 0; //fixme: really needed? 173 | _spi.write(0x72); 174 | _spi.write(data>>8); 175 | _spi.write(data&0xFF); 176 | } 177 | // ILI932x specific 178 | unsigned short SPI8::reg_read(unsigned char reg) 179 | { 180 | unsigned short r=0; 181 | _CS = 1; //fixme: really needed? 182 | _CS = 0; //fixme: really needed? 183 | _spi.write(0x70); 184 | _spi.write(0); // write MSB 185 | _spi.write(reg); // write LSB 186 | _CS = 1; //fixme: really needed? 187 | _CS = 0; //fixme: really needed? 188 | _spi.write(0x73); 189 | _spi.write(0); // dummy read 190 | r = _spi.write(0); // read 8bit 191 | r <<= 8; 192 | r |= _spi.write(0); // read 8bit 193 | return r; 194 | } 195 | void SPI8::hw_reset() 196 | { 197 | wait_ms(15); 198 | _DC = 1; 199 | _CS = 1; 200 | _reset = 0; // display reset 201 | wait_ms(2); 202 | _reset = 1; // end reset 203 | wait_ms(100); 204 | } 205 | void SPI8::BusEnable(bool enable) 206 | { 207 | _CS = enable ? 0:1; 208 | } -------------------------------------------------------------------------------- /Deployment/Source_DS_CNN_7layers_76f/f87f06292637/Protocols/SPI8.h: -------------------------------------------------------------------------------- 1 | #ifndef SPI8_H 2 | #define SPI8_H 3 | 4 | #define NDEBUG // avoid MBED_ASSERT to halt process when PinName DC==NC 5 | 6 | #include "mbed.h" 7 | #include "Protocols.h" 8 | //#include "GraphicsDisplay.h" 9 | 10 | /** SPI 8bit interface 11 | */ 12 | class SPI8 : public Protocols 13 | { 14 | public: 15 | 16 | /** Create an SPI 8bit display interface with 3 control pins 17 | * 18 | * @param SPI mosi 19 | * @param SPI miso 20 | * @param SPI sclk 21 | * @param CS pin connected to CS of display 22 | * @param reset pin connected to RESET of display 23 | * @param DC pin connected to data/command of display 24 | */ 25 | SPI8(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC=NC); 26 | 27 | protected: 28 | 29 | /** Send 8bit command to display controller 30 | * 31 | * @param cmd: byte to send 32 | * 33 | */ 34 | virtual void wr_cmd8(unsigned char cmd); 35 | 36 | /** Send 8bit data to display controller 37 | * 38 | * @param data: byte to send 39 | * 40 | */ 41 | virtual void wr_data8(unsigned char data); 42 | 43 | /** Send 2x8bit command to display controller 44 | * 45 | * @param cmd: halfword to send 46 | */ 47 | virtual void wr_cmd16(unsigned short cmd); 48 | 49 | /** Send 2x8bit data to display controller 50 | * 51 | * @param data: halfword to send 52 | * 53 | */ 54 | virtual void wr_data16(unsigned short data); 55 | 56 | /** Send 16bit pixeldata to display controller 57 | * 58 | * @param data: halfword to send 59 | * 60 | */ 61 | virtual void wr_gram(unsigned short data); 62 | 63 | /** Send same 16bit pixeldata to display controller multiple times 64 | * 65 | * @param data: halfword to send 66 | * @param count: how many 67 | * 68 | */ 69 | virtual void wr_gram(unsigned short data, unsigned int count); 70 | 71 | /** Send array of pixeldata shorts to display controller 72 | * 73 | * @param data: unsigned short pixeldata array 74 | * @param lenght: lenght (in shorts) 75 | * 76 | */ 77 | virtual void wr_grambuf(unsigned short* data, unsigned int lenght); 78 | 79 | /** Read 16bit pixeldata from display controller (with dummy cycle) 80 | * 81 | * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit 82 | * @returns 16bit color 83 | */ 84 | virtual unsigned short rd_gram(bool convert); 85 | 86 | /** Read 4x8bit register data (with dummy cycle) 87 | * @param reg the register to read 88 | * @returns data as uint 89 | * 90 | */ 91 | virtual unsigned int rd_reg_data32(unsigned char reg); 92 | 93 | /** Read 3x8bit ExtendedCommands register data 94 | * @param reg the register to read 95 | * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers 96 | * @returns data as uint 97 | * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode 98 | */ 99 | virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd); 100 | 101 | /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent 102 | * for PAR protocols: a signle RD bit toggle 103 | * for SPI8: 8clocks 104 | * for SPI16: 16 clocks 105 | */ 106 | virtual void dummyread (); 107 | 108 | /** ILI932x specific, select register for a successive write or read 109 | * 110 | * @param reg register to be selected 111 | * @param forread false = a write next (default), true = a read next 112 | * @note forread only used by SPI protocols 113 | */ 114 | virtual void reg_select(unsigned char reg, bool forread =false); 115 | 116 | /** ILI932x specific, write register with data 117 | * 118 | * @param reg register to write 119 | * @param data 16bit data 120 | */ 121 | virtual void reg_write(unsigned char reg, unsigned short data); 122 | 123 | /** ILI932x specific, read register 124 | * 125 | * @param reg register to be read 126 | * @returns 16bit register value 127 | */ 128 | virtual unsigned short reg_read(unsigned char reg); 129 | 130 | /** HW reset sequence (without display init commands) 131 | */ 132 | virtual void hw_reset(); 133 | 134 | /** Set ChipSelect high or low 135 | * @param enable 0/1 136 | */ 137 | virtual void BusEnable(bool enable); 138 | 139 | DigitalOut _CS; 140 | 141 | private: 142 | 143 | SPI _spi; 144 | DigitalOut _reset; 145 | DigitalOut _DC; 146 | 147 | }; 148 | #endif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KWS-DS-CNN-for-embedded 2 | This repository contains modified python scripts, based on the Speech Commands Tensorflow example, for training tensorflow models based on depthwise separable convolutional neural networks for keyword spotting. It also contains scripts for quantizing trained networks and evaluating performance in single-inference tests and on continuous audio streams. 3 | C++ source code for implementation of a pretrained network on the Cortex M4 based FRDM K66F development board is also included. 4 | 5 | # Training and deployment 6 | To train networks and deploying them to ARM Cortex-M boards, the guides from [ARM's](https://github.com/ARM-software/ML-KWS-for-MCU) should be followed. 7 | 8 | **Note:** After cloning the CMSIS-NN library, the "CMSIS\NN\Source\ConvolutionFunctions\arm_depthwise_separable_conv_HWC_q7_nonsquare.c" function must be replaced with the slightly modified version found in this repository. 9 | 10 | 11 | -------------------------------------------------------------------------------- /__pycache__/input_data.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterMS123/KWS-DS-CNN-for-embedded/dd78e3daa2db067a5583776422db49154ffeb9ae/__pycache__/input_data.cpython-36.pyc -------------------------------------------------------------------------------- /__pycache__/models.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterMS123/KWS-DS-CNN-for-embedded/dd78e3daa2db067a5583776422db49154ffeb9ae/__pycache__/models.cpython-36.pyc -------------------------------------------------------------------------------- /work/DS_CNN/DS_CNN_7layers_76f_wSize_20ms_wStride_20ms/retrain_logs/train/events.out.tfevents.1549397696.DESKTOP-PE4UDT9: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterMS123/KWS-DS-CNN-for-embedded/dd78e3daa2db067a5583776422db49154ffeb9ae/work/DS_CNN/DS_CNN_7layers_76f_wSize_20ms_wStride_20ms/retrain_logs/train/events.out.tfevents.1549397696.DESKTOP-PE4UDT9 -------------------------------------------------------------------------------- /work/DS_CNN/DS_CNN_7layers_76f_wSize_20ms_wStride_20ms/retrain_logs/train/events.out.tfevents.1549397772.DESKTOP-PE4UDT9: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterMS123/KWS-DS-CNN-for-embedded/dd78e3daa2db067a5583776422db49154ffeb9ae/work/DS_CNN/DS_CNN_7layers_76f_wSize_20ms_wStride_20ms/retrain_logs/train/events.out.tfevents.1549397772.DESKTOP-PE4UDT9 -------------------------------------------------------------------------------- /work/DS_CNN/DS_CNN_7layers_76f_wSize_20ms_wStride_20ms/retrain_logs/train/events.out.tfevents.1549397791.DESKTOP-PE4UDT9: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterMS123/KWS-DS-CNN-for-embedded/dd78e3daa2db067a5583776422db49154ffeb9ae/work/DS_CNN/DS_CNN_7layers_76f_wSize_20ms_wStride_20ms/retrain_logs/train/events.out.tfevents.1549397791.DESKTOP-PE4UDT9 -------------------------------------------------------------------------------- /work/DS_CNN/DS_CNN_7layers_76f_wSize_20ms_wStride_20ms/training/ds_cnn_labels.txt: -------------------------------------------------------------------------------- 1 | _silence_ 2 | _unknown_ 3 | yes 4 | no 5 | up 6 | down 7 | left 8 | right 9 | on 10 | off 11 | stop 12 | go --------------------------------------------------------------------------------