cis001v2

Committer:
thomashaine
Date:
Tue Jan 05 17:06:15 2021 +0000
Revision:
6:b544e474f959
Parent:
5:2a13bec5f9a3
Child:
7:4c77f017b4b8
teset

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thomashaine 0:e7352f4f3dcb 1 /* Includes ------------------------------------------------------------------*/
thomashaine 0:e7352f4f3dcb 2 //my include
thomashaine 0:e7352f4f3dcb 3 #include "main.h"
thomashaine 0:e7352f4f3dcb 4 #include "common_task.h"
thomashaine 0:e7352f4f3dcb 5 #include "register_address.h"
thomashaine 0:e7352f4f3dcb 6
thomashaine 0:e7352f4f3dcb 7
thomashaine 0:e7352f4f3dcb 8 //mbed include
thomashaine 0:e7352f4f3dcb 9 #include "stm32h7xx_hal.h"
thomashaine 0:e7352f4f3dcb 10 #include "mbed.h"
thomashaine 0:e7352f4f3dcb 11 #include "EthernetInterface.h"
thomashaine 0:e7352f4f3dcb 12 #include "TCPServer.h"
thomashaine 0:e7352f4f3dcb 13 #include "TCPSocket.h"
thomashaine 6:b544e474f959 14 //#include "FastPWM.h"
thomashaine 0:e7352f4f3dcb 15
thomashaine 0:e7352f4f3dcb 16
thomashaine 0:e7352f4f3dcb 17 /* Private variables ---------------------------------------------------------*/
thomashaine 0:e7352f4f3dcb 18
thomashaine 0:e7352f4f3dcb 19 //DCMI & DMA stuff
thomashaine 0:e7352f4f3dcb 20 DCMI_HandleTypeDef hdcmi;
thomashaine 0:e7352f4f3dcb 21 DMA_HandleTypeDef hdma_dcmi;
thomashaine 0:e7352f4f3dcb 22
thomashaine 0:e7352f4f3dcb 23 // Virtual USB Serial port
thomashaine 0:e7352f4f3dcb 24 Serial pc(USBTX, USBRX);
thomashaine 0:e7352f4f3dcb 25
thomashaine 0:e7352f4f3dcb 26 // etherner stuff
thomashaine 0:e7352f4f3dcb 27 EthernetInterface eth;
thomashaine 0:e7352f4f3dcb 28
thomashaine 0:e7352f4f3dcb 29 TCPSocket socket; //data socket
thomashaine 0:e7352f4f3dcb 30 TCPSocket cs; //com sockey
thomashaine 0:e7352f4f3dcb 31
thomashaine 6:b544e474f959 32 char ServerIP[17]="10.10.130.12";
thomashaine 0:e7352f4f3dcb 33 int portnumber = 61477;
thomashaine 0:e7352f4f3dcb 34 int portnumber_com = 61478;
thomashaine 0:e7352f4f3dcb 35 char* commandbuffer;
thomashaine 1:5060c8ea0ccd 36 char* commandbuffertemp;
thomashaine 1:5060c8ea0ccd 37
thomashaine 0:e7352f4f3dcb 38
thomashaine 0:e7352f4f3dcb 39 int MSG_LEN=64;
thomashaine 0:e7352f4f3dcb 40
thomashaine 0:e7352f4f3dcb 41
thomashaine 0:e7352f4f3dcb 42 // SPI1
thomashaine 0:e7352f4f3dcb 43 SPI spi(PD_7, PB_4, PA_5); // mosi, miso, sclk
thomashaine 0:e7352f4f3dcb 44 DigitalOut SSN(PA_15);
thomashaine 0:e7352f4f3dcb 45
thomashaine 0:e7352f4f3dcb 46
thomashaine 0:e7352f4f3dcb 47 //LEDs
thomashaine 0:e7352f4f3dcb 48 DigitalOut led1(LED1); //PB_0
thomashaine 0:e7352f4f3dcb 49 DigitalOut led2(LED2); //PB7
thomashaine 0:e7352f4f3dcb 50 DigitalOut led3(LED3); //PB14
thomashaine 0:e7352f4f3dcb 51
thomashaine 0:e7352f4f3dcb 52
thomashaine 0:e7352f4f3dcb 53 // GPIOS
thomashaine 6:b544e474f959 54 DigitalOut RSTN(PA_0);
thomashaine 0:e7352f4f3dcb 55 DigitalOut SLEEPN(PA_2);
thomashaine 0:e7352f4f3dcb 56 DigitalOut CAPTURE(PA_9);
thomashaine 0:e7352f4f3dcb 57 InterruptIn button_capture(PC_13);
thomashaine 6:b544e474f959 58 InterruptIn irq_cis(PA_11); //TODO
thomashaine 6:b544e474f959 59 DigitalOut CONFIG1(PA_8); //TODO
thomashaine 6:b544e474f959 60 DigitalOut CONFIG2(PD_2); //TODO
thomashaine 6:b544e474f959 61 //FastPWM MCLK(PA_3);
thomashaine 0:e7352f4f3dcb 62
thomashaine 0:e7352f4f3dcb 63
thomashaine 0:e7352f4f3dcb 64 //keep track fo the number of line and frame read
thomashaine 0:e7352f4f3dcb 65 int line_read=0;
thomashaine 0:e7352f4f3dcb 66 int frame_read=0;
thomashaine 6:b544e474f959 67 int imSize=frame_bsize_10b;
thomashaine 0:e7352f4f3dcb 68
thomashaine 1:5060c8ea0ccd 69 // frame pointer and frame size
thomashaine 1:5060c8ea0ccd 70 char* FRAME_BUFFER;
thomashaine 0:e7352f4f3dcb 71
thomashaine 6:b544e474f959 72 int DEBUG=1;
thomashaine 0:e7352f4f3dcb 73
thomashaine 0:e7352f4f3dcb 74
thomashaine 0:e7352f4f3dcb 75
thomashaine 5:2a13bec5f9a3 76 /***********************************************************************************************
thomashaine 0:e7352f4f3dcb 77 *
thomashaine 0:e7352f4f3dcb 78 * Ethernet function
thomashaine 0:e7352f4f3dcb 79 *
thomashaine 0:e7352f4f3dcb 80 ************************************************************************************************/
thomashaine 5:2a13bec5f9a3 81
thomashaine 5:2a13bec5f9a3 82 /**
thomashaine 2:53ca7bc14ed5 83 @param none
thomashaine 2:53ca7bc14ed5 84 @return void
thomashaine 4:5d212241948a 85 @brief print the start of the frame stored in frame buffer
thomashaine 2:53ca7bc14ed5 86 */
thomashaine 0:e7352f4f3dcb 87
thomashaine 0:e7352f4f3dcb 88 void print_start_frame(){
thomashaine 0:e7352f4f3dcb 89 int i,j,k=0;
thomashaine 0:e7352f4f3dcb 90 int byte_sent=0;
thomashaine 0:e7352f4f3dcb 91
thomashaine 0:e7352f4f3dcb 92 for (i=0; i<1 ; i++){
thomashaine 0:e7352f4f3dcb 93 for (k=0; k<20; k++){
thomashaine 0:e7352f4f3dcb 94 for (j=0; j<32; j++){
thomashaine 0:e7352f4f3dcb 95 //pc.printf("%3i ",(uint8_t) *(FRAME_BUFFER+i*640+k*32+j));
thomashaine 0:e7352f4f3dcb 96 sprintf(commandbuffer, "%3i ",(uint8_t) *(FRAME_BUFFER+i*640+k*32+j));
thomashaine 0:e7352f4f3dcb 97 byte_sent=cs.send(commandbuffer, strlen(commandbuffer));
thomashaine 0:e7352f4f3dcb 98 }
thomashaine 0:e7352f4f3dcb 99 //pc.printf("\b\r\n");
thomashaine 0:e7352f4f3dcb 100 sprintf(commandbuffer, "\b\r\n");
thomashaine 0:e7352f4f3dcb 101 byte_sent=cs.send(commandbuffer, strlen(commandbuffer));
thomashaine 0:e7352f4f3dcb 102
thomashaine 0:e7352f4f3dcb 103 }
thomashaine 0:e7352f4f3dcb 104 }
thomashaine 0:e7352f4f3dcb 105 }
thomashaine 3:c9f65f6d2092 106
thomashaine 5:2a13bec5f9a3 107 /**
thomashaine 4:5d212241948a 108 @brief sent via the data socket the frame stored in frame buffer
thomashaine 2:53ca7bc14ed5 109 @param none
thomashaine 2:53ca7bc14ed5 110 @return the number of byte sent on the socket
thomashaine 2:53ca7bc14ed5 111 */
thomashaine 1:5060c8ea0ccd 112 int send_frame_ethernet_nohandshake_while(){
thomashaine 0:e7352f4f3dcb 113
thomashaine 1:5060c8ea0ccd 114 int byte_chunk_sent=0;
thomashaine 1:5060c8ea0ccd 115 int a=0;
thomashaine 1:5060c8ea0ccd 116 int pixel_per_chunk=2048;
thomashaine 1:5060c8ea0ccd 117 int bytes_per_pixel=2;
thomashaine 1:5060c8ea0ccd 118 int bytes_per_chunk=pixel_per_chunk*bytes_per_pixel;
thomashaine 1:5060c8ea0ccd 119 int byte_to_send=0;
thomashaine 1:5060c8ea0ccd 120 int byte_per_image=imSize;
thomashaine 0:e7352f4f3dcb 121
thomashaine 1:5060c8ea0ccd 122
thomashaine 1:5060c8ea0ccd 123 while (byte_chunk_sent<byte_per_image){
thomashaine 1:5060c8ea0ccd 124 byte_to_send=min(byte_per_image - byte_chunk_sent, bytes_per_chunk);
thomashaine 1:5060c8ea0ccd 125
thomashaine 1:5060c8ea0ccd 126 //pointer are world align. hence the divided by 4
thomashaine 1:5060c8ea0ccd 127 a = socket.send(FRAME_BUFFER+byte_chunk_sent/4 , byte_to_send);
thomashaine 1:5060c8ea0ccd 128 if(a<0){
thomashaine 6:b544e474f959 129 // non blocking may time out
thomashaine 6:b544e474f959 130 //pc.printf("error byte -1/ %d / %d\r\n",a,byte_chunk_sent);
thomashaine 1:5060c8ea0ccd 131 //return -1;
thomashaine 1:5060c8ea0ccd 132 } else {
thomashaine 1:5060c8ea0ccd 133 byte_chunk_sent += a;
thomashaine 1:5060c8ea0ccd 134 //pc.printf("%d sent - total sent %d\r\n",a,byte_chunk_sent);
thomashaine 1:5060c8ea0ccd 135 }
thomashaine 0:e7352f4f3dcb 136 }
thomashaine 0:e7352f4f3dcb 137
thomashaine 6:b544e474f959 138 //pc.printf("total of %d bytes sent\r\n",byte_chunk_sent);
thomashaine 0:e7352f4f3dcb 139
thomashaine 1:5060c8ea0ccd 140 return byte_chunk_sent;
thomashaine 0:e7352f4f3dcb 141
thomashaine 0:e7352f4f3dcb 142 }
thomashaine 0:e7352f4f3dcb 143
thomashaine 0:e7352f4f3dcb 144
thomashaine 0:e7352f4f3dcb 145
thomashaine 5:2a13bec5f9a3 146 /**********************************************************************************************
thomashaine 0:e7352f4f3dcb 147 *
thomashaine 0:e7352f4f3dcb 148 * capture function
thomashaine 0:e7352f4f3dcb 149 *
thomashaine 0:e7352f4f3dcb 150 ************************************************************************************************/
thomashaine 0:e7352f4f3dcb 151
thomashaine 0:e7352f4f3dcb 152
thomashaine 0:e7352f4f3dcb 153
thomashaine 0:e7352f4f3dcb 154
thomashaine 0:e7352f4f3dcb 155 //https://github.com/tomvdb/stm32f401-nucleo-basic-template/blob/master/Drivers/BSP/STM324x9I_EVAL/stm324x9i_eval_camera.c
thomashaine 5:2a13bec5f9a3 156 /**
thomashaine 4:5d212241948a 157 @brief start dcmi and start frame capture
thomashaine 3:c9f65f6d2092 158 @param none
thomashaine 3:c9f65f6d2092 159 @return void
thomashaine 3:c9f65f6d2092 160 */
thomashaine 0:e7352f4f3dcb 161 void start_capture_10b(){
thomashaine 0:e7352f4f3dcb 162
thomashaine 0:e7352f4f3dcb 163 frame_read=0;
thomashaine 0:e7352f4f3dcb 164 line_read=0;
thomashaine 0:e7352f4f3dcb 165
thomashaine 6:b544e474f959 166 //memset(FRAME_BUFFER,0,(size_t) frame_bsize_10b);
thomashaine 0:e7352f4f3dcb 167 //HAL_DCMI_Stop(&hdcmi);
thomashaine 0:e7352f4f3dcb 168 //pc.printf("starting snapshot 10b\r\n");
thomashaine 0:e7352f4f3dcb 169
thomashaine 0:e7352f4f3dcb 170 // disable crop features
thomashaine 0:e7352f4f3dcb 171 //HAL_DCMI_DisableCrop(&hdcmi);
thomashaine 0:e7352f4f3dcb 172
thomashaine 0:e7352f4f3dcb 173 //enable DCMI
thomashaine 0:e7352f4f3dcb 174 ///HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, (uint32_t) FRAME_BUFFER, Im_size);
thomashaine 0:e7352f4f3dcb 175 HAL_DCMI_Start_DMA (&hdcmi, DCMI_MODE_SNAPSHOT,(uint32_t) FRAME_BUFFER, (uint32_t) imSize);
thomashaine 0:e7352f4f3dcb 176
thomashaine 0:e7352f4f3dcb 177 //start capture
thomashaine 0:e7352f4f3dcb 178 TASK_SPI_WRITE(capture_add,1);
thomashaine 0:e7352f4f3dcb 179 wait_us(1000);
thomashaine 0:e7352f4f3dcb 180 TASK_SPI_WRITE(capture_add,0);
thomashaine 0:e7352f4f3dcb 181
thomashaine 0:e7352f4f3dcb 182 }
thomashaine 0:e7352f4f3dcb 183
thomashaine 0:e7352f4f3dcb 184
thomashaine 5:2a13bec5f9a3 185 /**
thomashaine 4:5d212241948a 186 @brief suspend DCMI
thomashaine 3:c9f65f6d2092 187 @param none
thomashaine 3:c9f65f6d2092 188 @return void
thomashaine 3:c9f65f6d2092 189 */
thomashaine 0:e7352f4f3dcb 190 void suspend_capture(void){
thomashaine 0:e7352f4f3dcb 191 // Suspend the Camera Capture //
thomashaine 0:e7352f4f3dcb 192 HAL_DCMI_Suspend(&hdcmi);
thomashaine 0:e7352f4f3dcb 193 }
thomashaine 0:e7352f4f3dcb 194
thomashaine 5:2a13bec5f9a3 195 /**
thomashaine 4:5d212241948a 196 @brief resume DCMI
thomashaine 3:c9f65f6d2092 197 @param none
thomashaine 3:c9f65f6d2092 198 @return void
thomashaine 3:c9f65f6d2092 199 */
thomashaine 0:e7352f4f3dcb 200 void resume_capture(void) {
thomashaine 0:e7352f4f3dcb 201 // Start the Camera Capture //
thomashaine 0:e7352f4f3dcb 202 HAL_DCMI_Resume(&hdcmi);
thomashaine 0:e7352f4f3dcb 203 }
thomashaine 0:e7352f4f3dcb 204
thomashaine 5:2a13bec5f9a3 205 /**
thomashaine 4:5d212241948a 206 @brief stop DCMI
thomashaine 3:c9f65f6d2092 207 @param none
thomashaine 3:c9f65f6d2092 208 @return void
thomashaine 3:c9f65f6d2092 209 */
thomashaine 0:e7352f4f3dcb 210 void stop_capture(void) {
thomashaine 0:e7352f4f3dcb 211 if(HAL_DCMI_Stop(&hdcmi) == HAL_OK){
thomashaine 3:c9f65f6d2092 212 pc.printf("Error stopping camera\n\r");
thomashaine 0:e7352f4f3dcb 213 }
thomashaine 0:e7352f4f3dcb 214 else{
thomashaine 3:c9f65f6d2092 215 pc.printf("Camera stopped\n\r");
thomashaine 0:e7352f4f3dcb 216 }
thomashaine 0:e7352f4f3dcb 217 }
thomashaine 0:e7352f4f3dcb 218
thomashaine 0:e7352f4f3dcb 219
thomashaine 3:c9f65f6d2092 220
thomashaine 5:2a13bec5f9a3 221 /**
thomashaine 4:5d212241948a 222 @brief override interrupt DCMI: on frame callback; send frame
thomashaine 3:c9f65f6d2092 223 @param none
thomashaine 3:c9f65f6d2092 224 @return void
thomashaine 3:c9f65f6d2092 225 */
thomashaine 6:b544e474f959 226 void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi){
thomashaine 6:b544e474f959 227 pc.printf("frame event callback: read %i lines \r\n",line_read);
thomashaine 6:b544e474f959 228 line_read=0;
thomashaine 1:5060c8ea0ccd 229 send_frame_ethernet_nohandshake_while();
thomashaine 0:e7352f4f3dcb 230 }
thomashaine 3:c9f65f6d2092 231
thomashaine 5:2a13bec5f9a3 232 /**
thomashaine 4:5d212241948a 233 @brief override interrupt DCMI: on vsync callback; increment frame count
thomashaine 3:c9f65f6d2092 234 @param none
thomashaine 3:c9f65f6d2092 235 @return void
thomashaine 3:c9f65f6d2092 236 */
thomashaine 0:e7352f4f3dcb 237 void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi){
thomashaine 0:e7352f4f3dcb 238 frame_read++;
thomashaine 0:e7352f4f3dcb 239 }
thomashaine 3:c9f65f6d2092 240
thomashaine 5:2a13bec5f9a3 241 /**
thomashaine 4:5d212241948a 242 @brief override interrupt DCMI: on hsync callback; inrement line count
thomashaine 3:c9f65f6d2092 243 @param none
thomashaine 3:c9f65f6d2092 244 @return void
thomashaine 3:c9f65f6d2092 245 */
thomashaine 0:e7352f4f3dcb 246 void HAL_DCMI_LineEventCallback (DCMI_HandleTypeDef *hdcmi){
thomashaine 0:e7352f4f3dcb 247 line_read++;
thomashaine 0:e7352f4f3dcb 248 }
thomashaine 0:e7352f4f3dcb 249
thomashaine 6:b544e474f959 250 /**
thomashaine 6:b544e474f959 251 @brief debug: set frmae buffer as a known pattern
thomashaine 6:b544e474f959 252 @param none
thomashaine 6:b544e474f959 253 @return void
thomashaine 6:b544e474f959 254 */
thomashaine 6:b544e474f959 255 void format_frame(int imSize){
thomashaine 6:b544e474f959 256
thomashaine 6:b544e474f959 257 for (int i=0;i<480;i++){
thomashaine 6:b544e474f959 258 for (int j=0;j<1280;j=j+2){
thomashaine 6:b544e474f959 259 *(FRAME_BUFFER+i*1280+j)= (char) j;
thomashaine 6:b544e474f959 260 *(FRAME_BUFFER+i*1280+j+1)=(char) (j/256);
thomashaine 6:b544e474f959 261 }
thomashaine 6:b544e474f959 262 pc.printf("%i - %i - %i\n\r",(int) FRAME_BUFFER, i, (int) FRAME_BUFFER+i*1280);
thomashaine 6:b544e474f959 263 }
thomashaine 6:b544e474f959 264 }
thomashaine 6:b544e474f959 265
thomashaine 0:e7352f4f3dcb 266
thomashaine 0:e7352f4f3dcb 267
thomashaine 5:2a13bec5f9a3 268 /**********************************************************************************************
thomashaine 0:e7352f4f3dcb 269 *
thomashaine 0:e7352f4f3dcb 270 * main function
thomashaine 0:e7352f4f3dcb 271 *
thomashaine 0:e7352f4f3dcb 272 ************************************************************************************************/
thomashaine 0:e7352f4f3dcb 273
thomashaine 0:e7352f4f3dcb 274 int main(void){
thomashaine 0:e7352f4f3dcb 275
thomashaine 0:e7352f4f3dcb 276
thomashaine 0:e7352f4f3dcb 277 uint8_t a,b,c,d=0;
thomashaine 0:e7352f4f3dcb 278 uint8_t mclk;
thomashaine 0:e7352f4f3dcb 279 uint8_t unlimited=0;
thomashaine 0:e7352f4f3dcb 280 int res;
thomashaine 0:e7352f4f3dcb 281 uint8_t SLEEPN_flag=0;
thomashaine 0:e7352f4f3dcb 282 uint8_t PBP_flag=0;
thomashaine 0:e7352f4f3dcb 283 uint8_t OEN_flag=0;
thomashaine 0:e7352f4f3dcb 284 int status=0;
thomashaine 0:e7352f4f3dcb 285 int byte_sent;
thomashaine 0:e7352f4f3dcb 286 char host_cmd[64];
thomashaine 0:e7352f4f3dcb 287 int loopcount=0;
thomashaine 0:e7352f4f3dcb 288 int button_pushed=0;
thomashaine 0:e7352f4f3dcb 289
thomashaine 0:e7352f4f3dcb 290 //ethernet
thomashaine 0:e7352f4f3dcb 291 char rbuffer[MSG_LEN];
thomashaine 0:e7352f4f3dcb 292 char * pch;
thomashaine 0:e7352f4f3dcb 293 int rcount;
thomashaine 0:e7352f4f3dcb 294 int data=0;
thomashaine 0:e7352f4f3dcb 295 int add=0;
thomashaine 0:e7352f4f3dcb 296 int readvalue=0;
thomashaine 0:e7352f4f3dcb 297 int i=0;
thomashaine 0:e7352f4f3dcb 298 int sizetosent=64;
thomashaine 6:b544e474f959 299
thomashaine 0:e7352f4f3dcb 300
thomashaine 5:2a13bec5f9a3 301 //***********************
thomashaine 6:b544e474f959 302 /* Initialize all configured peripherals - First thing to do */
thomashaine 5:2a13bec5f9a3 303 //***********************
thomashaine 0:e7352f4f3dcb 304 MX_GPIO_Init();
thomashaine 0:e7352f4f3dcb 305 MX_DMA_Init();
thomashaine 0:e7352f4f3dcb 306 MX_DCMI_Init_10b();
thomashaine 0:e7352f4f3dcb 307
thomashaine 5:2a13bec5f9a3 308 //************************
thomashaine 0:e7352f4f3dcb 309 // config serial print
thomashaine 5:2a13bec5f9a3 310 //************************
thomashaine 0:e7352f4f3dcb 311 pc.baud(115200);//Set baudrate here.
thomashaine 0:e7352f4f3dcb 312 pc.printf("*****************\r\n CIS001 \r\n*****************\r\n");
thomashaine 0:e7352f4f3dcb 313
thomashaine 5:2a13bec5f9a3 314 //************************
thomashaine 0:e7352f4f3dcb 315 // init pointer
thomashaine 5:2a13bec5f9a3 316 //************************
thomashaine 1:5060c8ea0ccd 317 //
thomashaine 6:b544e474f959 318 //!!!!!! attention : malloc is in num of words and not byte !!!!!!!! idem memset
thomashaine 1:5060c8ea0ccd 319 //
thomashaine 0:e7352f4f3dcb 320 //initialize frame buffer for 10b photo (malloc size en byte)
thomashaine 6:b544e474f959 321 //FRAME_BUFFER=(char *) malloc( frame_bsize_10b/4*sizeof(char));
thomashaine 6:b544e474f959 322 FRAME_BUFFER=(char *) malloc((size_t) frame_bsize_10b/4);
thomashaine 6:b544e474f959 323 //memset((void *)FRAME_BUFFER,2,(size_t) frame_bsize_10b/4);
thomashaine 6:b544e474f959 324 memset((void *)FRAME_BUFFER,2,(size_t) frame_bsize_10b/4);
thomashaine 6:b544e474f959 325
thomashaine 0:e7352f4f3dcb 326
thomashaine 0:e7352f4f3dcb 327 //initialize commandbuffer pointer
thomashaine 0:e7352f4f3dcb 328 commandbuffer=(char *) malloc((MSG_LEN+1)*sizeof(char));
thomashaine 1:5060c8ea0ccd 329 commandbuffertemp=(char *) malloc((MSG_LEN+1)*sizeof(char));
thomashaine 0:e7352f4f3dcb 330
thomashaine 5:2a13bec5f9a3 331 //************************
thomashaine 0:e7352f4f3dcb 332 // init spi
thomashaine 5:2a13bec5f9a3 333 //************************
thomashaine 0:e7352f4f3dcb 334 // Setup the spi for 16 bit data (2x8), high steady state clock,second edge capture, with a 5MHz clock rate
thomashaine 0:e7352f4f3dcb 335 /* mode | POL PHA
thomashaine 0:e7352f4f3dcb 336 -----+--------
thomashaine 0:e7352f4f3dcb 337 0 | 0 0
thomashaine 0:e7352f4f3dcb 338 1 | 0 1
thomashaine 0:e7352f4f3dcb 339 2 | 1 0
thomashaine 0:e7352f4f3dcb 340 3 | 1 1*/
thomashaine 0:e7352f4f3dcb 341 spi.format(16,0);
thomashaine 0:e7352f4f3dcb 342 spi.frequency(100000);
thomashaine 0:e7352f4f3dcb 343
thomashaine 6:b544e474f959 344
thomashaine 6:b544e474f959 345 //start generating MCLK
thomashaine 6:b544e474f959 346 uint32_t half_periode=4;
thomashaine 6:b544e474f959 347 //MCLK.prescaler(1);
thomashaine 6:b544e474f959 348 //MCLK.period_ticks(9);
thomashaine 6:b544e474f959 349 //MCLK.pulsewidth_ticks(half_periode);
thomashaine 6:b544e474f959 350 //mclk=1;
thomashaine 6:b544e474f959 351
thomashaine 6:b544e474f959 352
thomashaine 5:2a13bec5f9a3 353 //************************
thomashaine 0:e7352f4f3dcb 354 // reset leds
thomashaine 5:2a13bec5f9a3 355 //************************
thomashaine 0:e7352f4f3dcb 356 led1=0;
thomashaine 0:e7352f4f3dcb 357 led2=0;
thomashaine 0:e7352f4f3dcb 358 led3=0;
thomashaine 0:e7352f4f3dcb 359
thomashaine 5:2a13bec5f9a3 360 //************************
thomashaine 0:e7352f4f3dcb 361 //init CIS001
thomashaine 5:2a13bec5f9a3 362 //************************
thomashaine 0:e7352f4f3dcb 363 TASK_INIT();
thomashaine 0:e7352f4f3dcb 364
thomashaine 5:2a13bec5f9a3 365 //************************
thomashaine 0:e7352f4f3dcb 366 // Ethernet & socket stuff
thomashaine 5:2a13bec5f9a3 367 //************************
thomashaine 0:e7352f4f3dcb 368 pc.printf("Connecting Ethernet cable....\r\n");
thomashaine 0:e7352f4f3dcb 369 eth.connect();
thomashaine 0:e7352f4f3dcb 370 SocketAddress sockaddr;
thomashaine 0:e7352f4f3dcb 371 const char *mac = eth.get_mac_address();
thomashaine 0:e7352f4f3dcb 372 const char* ip = eth.get_ip_address();
thomashaine 0:e7352f4f3dcb 373 pc.printf("MAC Address is %s\r\n", mac ? mac : "No Mac");
thomashaine 0:e7352f4f3dcb 374 pc.printf("IP address is: %s\r\n", ip ? ip : "No IP");
thomashaine 0:e7352f4f3dcb 375 pc.printf("*****************\r\n");
thomashaine 0:e7352f4f3dcb 376 pc.printf("Nucleo CPU SystemCoreClock is %d MHz\r\n", SystemCoreClock/1000000);
thomashaine 0:e7352f4f3dcb 377 pc.printf("*****************\r\n");
thomashaine 0:e7352f4f3dcb 378
thomashaine 5:2a13bec5f9a3 379 //************************
thomashaine 0:e7352f4f3dcb 380 //open a new socket for printing information & debug
thomashaine 5:2a13bec5f9a3 381 //************************
thomashaine 0:e7352f4f3dcb 382 status=cs.open(&eth);
thomashaine 0:e7352f4f3dcb 383 if(status != 0){
thomashaine 0:e7352f4f3dcb 384 pc.printf("error open com interface\r\n");
thomashaine 0:e7352f4f3dcb 385 cs.close();
thomashaine 0:e7352f4f3dcb 386 return 1;
thomashaine 0:e7352f4f3dcb 387 }
thomashaine 0:e7352f4f3dcb 388 else{
thomashaine 0:e7352f4f3dcb 389 pc.printf("com interface open\r\n");
thomashaine 0:e7352f4f3dcb 390 }
thomashaine 0:e7352f4f3dcb 391
thomashaine 0:e7352f4f3dcb 392 status=cs.connect(ServerIP, portnumber_com);
thomashaine 0:e7352f4f3dcb 393 if(status !=0){
thomashaine 0:e7352f4f3dcb 394 pc.printf("error open com socket\r\n");
thomashaine 0:e7352f4f3dcb 395 cs.close();
thomashaine 0:e7352f4f3dcb 396 return 1;
thomashaine 0:e7352f4f3dcb 397 }else{
thomashaine 0:e7352f4f3dcb 398 pc.printf("socket com open\r\n");
thomashaine 0:e7352f4f3dcb 399 }
thomashaine 0:e7352f4f3dcb 400
thomashaine 0:e7352f4f3dcb 401 // send 10x test2 to the pc
thomashaine 6:b544e474f959 402 //sprintf(commandbuffer,"%64s","test2");
thomashaine 6:b544e474f959 403 //pc.printf("[%s]_%d\r\n",commandbuffer,strlen(commandbuffer));
thomashaine 6:b544e474f959 404 //byte_sent=0;
thomashaine 6:b544e474f959 405 //for(i=0; i<10;i++){
thomashaine 6:b544e474f959 406 // byte_sent+=cs.send(commandbuffer, strlen(commandbuffer));
thomashaine 6:b544e474f959 407 //}
thomashaine 6:b544e474f959 408 //sprintf(commandbuffer,"%64s","******************\nHello from Nucleo :)\n******************\n");
thomashaine 6:b544e474f959 409 //cs.send(commandbuffer, strlen(commandbuffer));
thomashaine 0:e7352f4f3dcb 410
thomashaine 0:e7352f4f3dcb 411
thomashaine 0:e7352f4f3dcb 412
thomashaine 0:e7352f4f3dcb 413
thomashaine 5:2a13bec5f9a3 414 //************************
thomashaine 0:e7352f4f3dcb 415 //open a new socket for data and command
thomashaine 5:2a13bec5f9a3 416 //************************
thomashaine 0:e7352f4f3dcb 417 status=socket.open(&eth);
thomashaine 0:e7352f4f3dcb 418 if(status != 0){
thomashaine 0:e7352f4f3dcb 419 //myprint("*error open interface\r\n");
thomashaine 0:e7352f4f3dcb 420 pc.printf("failed to Open socket\n\r");
thomashaine 0:e7352f4f3dcb 421 socket.close();
thomashaine 0:e7352f4f3dcb 422 return 1;
thomashaine 0:e7352f4f3dcb 423 }else{
thomashaine 0:e7352f4f3dcb 424 pc.printf("interface open\r\n");
thomashaine 0:e7352f4f3dcb 425 }
thomashaine 0:e7352f4f3dcb 426
thomashaine 0:e7352f4f3dcb 427 status=socket.connect(ServerIP, portnumber);
thomashaine 0:e7352f4f3dcb 428 if(status !=0){
thomashaine 0:e7352f4f3dcb 429 pc.printf("failed to connect to server\n\r");
thomashaine 0:e7352f4f3dcb 430 socket.close();
thomashaine 0:e7352f4f3dcb 431 return 1;
thomashaine 0:e7352f4f3dcb 432 }else{
thomashaine 0:e7352f4f3dcb 433 pc.printf("socket open\r\n");
thomashaine 0:e7352f4f3dcb 434 }
thomashaine 0:e7352f4f3dcb 435
thomashaine 6:b544e474f959 436
thomashaine 6:b544e474f959 437
thomashaine 6:b544e474f959 438 socket.set_blocking(false); // non blocking
thomashaine 6:b544e474f959 439 socket.set_timeout(1); // Timeout after (10)ms
thomashaine 0:e7352f4f3dcb 440
thomashaine 0:e7352f4f3dcb 441
thomashaine 0:e7352f4f3dcb 442
thomashaine 5:2a13bec5f9a3 443 //************************
thomashaine 0:e7352f4f3dcb 444 // Infinite loop
thomashaine 5:2a13bec5f9a3 445 //************************
thomashaine 0:e7352f4f3dcb 446 pc.printf("main loop\r\n");
thomashaine 0:e7352f4f3dcb 447 while (1){
thomashaine 0:e7352f4f3dcb 448 led2= !led2;
thomashaine 0:e7352f4f3dcb 449 loopcount++;
thomashaine 0:e7352f4f3dcb 450
thomashaine 5:2a13bec5f9a3 451 //************************
thomashaine 6:b544e474f959 452 // blink led every 1024 loop in the main loop
thomashaine 5:2a13bec5f9a3 453 //************************
thomashaine 6:b544e474f959 454 if(loopcount==1024){ // more or less evey second
thomashaine 0:e7352f4f3dcb 455 led1=!led1;
thomashaine 6:b544e474f959 456 loopcount=0;
thomashaine 0:e7352f4f3dcb 457 }
thomashaine 0:e7352f4f3dcb 458
thomashaine 0:e7352f4f3dcb 459
thomashaine 6:b544e474f959 460 //************************************************
thomashaine 0:e7352f4f3dcb 461 // do soemthing when button is pressed
thomashaine 6:b544e474f959 462 //************************************************
thomashaine 0:e7352f4f3dcb 463 if(button_capture==1 && button_pushed==0){
thomashaine 6:b544e474f959 464 pc.printf("bc\n\r");
thomashaine 0:e7352f4f3dcb 465 button_pushed=1;
thomashaine 0:e7352f4f3dcb 466
thomashaine 6:b544e474f959 467 // do something here
thomashaine 6:b544e474f959 468
thomashaine 0:e7352f4f3dcb 469 }else if(button_capture==0 && button_pushed==1){
thomashaine 0:e7352f4f3dcb 470 button_pushed=0;
thomashaine 0:e7352f4f3dcb 471 }
thomashaine 0:e7352f4f3dcb 472
thomashaine 0:e7352f4f3dcb 473
thomashaine 6:b544e474f959 474 //************************************************
thomashaine 6:b544e474f959 475 // listening for message (non bloacking)
thomashaine 6:b544e474f959 476 //************************************************
thomashaine 0:e7352f4f3dcb 477 rcount = socket.recv(&rbuffer, sizeof rbuffer);
thomashaine 0:e7352f4f3dcb 478 if(rcount>0){
thomashaine 6:b544e474f959 479 //************************************************
thomashaine 6:b544e474f959 480 // something was received :)
thomashaine 6:b544e474f959 481 //************************************************
thomashaine 6:b544e474f959 482 pc.printf("recv %d bytes [%.*s]\r\n", rcount, strstr(rbuffer, "\n") - rbuffer-1, rbuffer); // printr xx bytes of rbuffer computed by strstr(x)-x
thomashaine 0:e7352f4f3dcb 483
thomashaine 0:e7352f4f3dcb 484 pch = strtok (rbuffer," ");
thomashaine 0:e7352f4f3dcb 485
thomashaine 0:e7352f4f3dcb 486 if (pch != NULL) {
thomashaine 6:b544e474f959 487 //pc.printf("%s\r\n", pch);
thomashaine 0:e7352f4f3dcb 488
thomashaine 0:e7352f4f3dcb 489 if (strcmp (pch,"write")==0 || strcmp (pch,"WRITE")==0){
thomashaine 0:e7352f4f3dcb 490
thomashaine 0:e7352f4f3dcb 491 pch = strtok (NULL, " ");
thomashaine 0:e7352f4f3dcb 492 data=atoi(pch);
thomashaine 0:e7352f4f3dcb 493 pch = strtok (NULL, " ");
thomashaine 0:e7352f4f3dcb 494 add=atoi(pch);
thomashaine 0:e7352f4f3dcb 495 TASK_SPI_WRITE(add,data);
thomashaine 0:e7352f4f3dcb 496
thomashaine 1:5060c8ea0ccd 497 sprintf(commandbuffertemp, "done writing %d at %d", data, add);
thomashaine 1:5060c8ea0ccd 498 sprintf(commandbuffer,"%64s",commandbuffertemp);
thomashaine 0:e7352f4f3dcb 499 byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
thomashaine 0:e7352f4f3dcb 500 //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
thomashaine 0:e7352f4f3dcb 501
thomashaine 0:e7352f4f3dcb 502 }else if (strcmp (pch,"read")==0 || strcmp (pch,"READ")==0 ){
thomashaine 0:e7352f4f3dcb 503
thomashaine 0:e7352f4f3dcb 504 pch = strtok (NULL, " ");
thomashaine 0:e7352f4f3dcb 505 add=atoi(pch);
thomashaine 0:e7352f4f3dcb 506 readvalue = TASK_SPI_READ(add);
thomashaine 0:e7352f4f3dcb 507
thomashaine 1:5060c8ea0ccd 508 sprintf(commandbuffertemp, "%d/%d", readvalue,add);
thomashaine 1:5060c8ea0ccd 509 sprintf(commandbuffer,"%64s",commandbuffertemp);
thomashaine 0:e7352f4f3dcb 510 byte_sent=socket.send(commandbuffer,strlen(commandbuffer));
thomashaine 6:b544e474f959 511 //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
thomashaine 0:e7352f4f3dcb 512
thomashaine 1:5060c8ea0ccd 513 sprintf(commandbuffertemp, "done reading %d at %d", readvalue, add);
thomashaine 1:5060c8ea0ccd 514 sprintf(commandbuffer,"%64s",commandbuffertemp);
thomashaine 0:e7352f4f3dcb 515 byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
thomashaine 6:b544e474f959 516 //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
thomashaine 0:e7352f4f3dcb 517
thomashaine 0:e7352f4f3dcb 518 }else if (strcmp (pch,"capture")==0 ||strcmp (pch,"CAPTURE")==0){
thomashaine 0:e7352f4f3dcb 519 pch = strtok (NULL, " ");
thomashaine 0:e7352f4f3dcb 520 pc.printf("[%s]\n\r",pch);
thomashaine 4:5d212241948a 521 imSize=atoi(pch);
thomashaine 6:b544e474f959 522 sprintf(commandbuffertemp, "trying to capture image of %d bytes...", imSize);
thomashaine 1:5060c8ea0ccd 523 sprintf(commandbuffer,"%64s",commandbuffertemp);
thomashaine 6:b544e474f959 524 //byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
thomashaine 0:e7352f4f3dcb 525
thomashaine 6:b544e474f959 526 start_capture_10b();
thomashaine 6:b544e474f959 527 if(DEBUG==1){
thomashaine 6:b544e474f959 528 format_frame(imSize);
thomashaine 6:b544e474f959 529 byte_sent=send_frame_ethernet_nohandshake_while();
thomashaine 6:b544e474f959 530 sprintf(commandbuffertemp, "sent image of %d bytes/%d bytes", byte_sent,imSize);
thomashaine 6:b544e474f959 531 sprintf(commandbuffer,"%64s",commandbuffertemp);
thomashaine 6:b544e474f959 532 //byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
thomashaine 6:b544e474f959 533 //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
thomashaine 6:b544e474f959 534 }
thomashaine 0:e7352f4f3dcb 535
thomashaine 0:e7352f4f3dcb 536 }else if (strcmp (pch,"reset")==0 ||strcmp (pch,"RESET")==0){
thomashaine 0:e7352f4f3dcb 537 TASK_RSTN();
thomashaine 0:e7352f4f3dcb 538
thomashaine 1:5060c8ea0ccd 539 sprintf(commandbuffertemp, "done reseting chip");
thomashaine 1:5060c8ea0ccd 540 sprintf(commandbuffer,"%64s",commandbuffertemp);
thomashaine 0:e7352f4f3dcb 541 byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
thomashaine 0:e7352f4f3dcb 542 //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
thomashaine 0:e7352f4f3dcb 543
thomashaine 3:c9f65f6d2092 544 }else if (strcmp (pch,"test_spi")==0 ||strcmp (pch,"TEST_SPI")==0){
thomashaine 3:c9f65f6d2092 545 a=TASK_TEST_SPI();
thomashaine 3:c9f65f6d2092 546
thomashaine 3:c9f65f6d2092 547 if (a==1){
thomashaine 3:c9f65f6d2092 548 sprintf(commandbuffertemp, "test spi OK");
thomashaine 3:c9f65f6d2092 549 }else{
thomashaine 3:c9f65f6d2092 550 sprintf(commandbuffertemp, "test spi KO");
thomashaine 3:c9f65f6d2092 551 }
thomashaine 3:c9f65f6d2092 552 sprintf(commandbuffer,"%64s",commandbuffertemp);
thomashaine 3:c9f65f6d2092 553 byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
thomashaine 3:c9f65f6d2092 554
thomashaine 0:e7352f4f3dcb 555 }else if (strcmp (pch,"exit")==0 ||strcmp (pch,"EXIT")==0){
thomashaine 1:5060c8ea0ccd 556 sprintf(commandbuffer, "%64s","close com and data sockets");
thomashaine 0:e7352f4f3dcb 557 byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
thomashaine 0:e7352f4f3dcb 558 //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
thomashaine 0:e7352f4f3dcb 559 status=socket.close();
thomashaine 0:e7352f4f3dcb 560 status=cs.close();
thomashaine 0:e7352f4f3dcb 561
thomashaine 0:e7352f4f3dcb 562 }else{
thomashaine 1:5060c8ea0ccd 563 sprintf(commandbuffer, "%64s","command not recoginzed");
thomashaine 0:e7352f4f3dcb 564 byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
thomashaine 0:e7352f4f3dcb 565 //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
thomashaine 0:e7352f4f3dcb 566 }
thomashaine 0:e7352f4f3dcb 567 } else{ //tok is null
thomashaine 1:5060c8ea0ccd 568 sprintf(commandbuffer, "%64s","empty tok");
thomashaine 0:e7352f4f3dcb 569 byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
thomashaine 0:e7352f4f3dcb 570 //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
thomashaine 6:b544e474f959 571 }
thomashaine 0:e7352f4f3dcb 572
thomashaine 6:b544e474f959 573 }else{ // non blocking timed out and received <0
thomashaine 0:e7352f4f3dcb 574
thomashaine 0:e7352f4f3dcb 575 //sprintf(commandbuffer, "empty token\r\n");
thomashaine 0:e7352f4f3dcb 576 //myprint(commandbuffer);
thomashaine 0:e7352f4f3dcb 577 if(pc.readable()){
thomashaine 6:b544e474f959 578 pc.scanf("%s", (char *) &host_cmd);
thomashaine 0:e7352f4f3dcb 579 pch = strtok (rbuffer," ");
thomashaine 0:e7352f4f3dcb 580 if (strcmp(host_cmd,"port")==0 || strcmp(host_cmd,"PORT")==0) {
thomashaine 0:e7352f4f3dcb 581 sprintf(commandbuffer, "PORT\r\n");
thomashaine 0:e7352f4f3dcb 582 myprint(commandbuffer);
thomashaine 0:e7352f4f3dcb 583
thomashaine 0:e7352f4f3dcb 584 } else if (strcmp (pch,"write")==0 || strcmp (pch,"WRITE")==0){
thomashaine 0:e7352f4f3dcb 585
thomashaine 0:e7352f4f3dcb 586 pch = strtok (NULL, " ");
thomashaine 0:e7352f4f3dcb 587 data=atoi(pch);
thomashaine 0:e7352f4f3dcb 588 pch = strtok (NULL, " ");
thomashaine 0:e7352f4f3dcb 589 add=atoi(pch);
thomashaine 0:e7352f4f3dcb 590 TASK_SPI_WRITE(add,data);
thomashaine 0:e7352f4f3dcb 591
thomashaine 0:e7352f4f3dcb 592 sprintf(commandbuffer, "write %d at %d", data, add);
thomashaine 0:e7352f4f3dcb 593 byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
thomashaine 0:e7352f4f3dcb 594 pc.printf("[%s]%d\n\r",commandbuffer,byte_sent);
thomashaine 0:e7352f4f3dcb 595
thomashaine 0:e7352f4f3dcb 596 }
thomashaine 0:e7352f4f3dcb 597 }
thomashaine 0:e7352f4f3dcb 598
thomashaine 0:e7352f4f3dcb 599
thomashaine 0:e7352f4f3dcb 600 } //end non blocking timed-out
thomashaine 0:e7352f4f3dcb 601
thomashaine 0:e7352f4f3dcb 602
thomashaine 0:e7352f4f3dcb 603
thomashaine 0:e7352f4f3dcb 604
thomashaine 0:e7352f4f3dcb 605 } //end while(1) loop
thomashaine 0:e7352f4f3dcb 606
thomashaine 0:e7352f4f3dcb 607
thomashaine 0:e7352f4f3dcb 608 } // end main
thomashaine 0:e7352f4f3dcb 609
thomashaine 0:e7352f4f3dcb 610
thomashaine 0:e7352f4f3dcb 611
thomashaine 0:e7352f4f3dcb 612
thomashaine 0:e7352f4f3dcb 613
thomashaine 0:e7352f4f3dcb 614
thomashaine 0:e7352f4f3dcb 615
thomashaine 0:e7352f4f3dcb 616
thomashaine 0:e7352f4f3dcb 617
thomashaine 0:e7352f4f3dcb 618
thomashaine 5:2a13bec5f9a3 619 /***********************************************************************************************
thomashaine 0:e7352f4f3dcb 620 *
thomashaine 0:e7352f4f3dcb 621 * configuration function
thomashaine 0:e7352f4f3dcb 622 *
thomashaine 0:e7352f4f3dcb 623 ************************************************************************************************/
thomashaine 0:e7352f4f3dcb 624
thomashaine 3:c9f65f6d2092 625
thomashaine 5:2a13bec5f9a3 626 /**
thomashaine 4:5d212241948a 627 *@brief Initialize DCMI in 8b mode
thomashaine 3:c9f65f6d2092 628 *@param none
thomashaine 3:c9f65f6d2092 629 *@return void
thomashaine 3:c9f65f6d2092 630 */
thomashaine 0:e7352f4f3dcb 631 static void MX_DCMI_Init_8b(void)
thomashaine 0:e7352f4f3dcb 632 {
thomashaine 0:e7352f4f3dcb 633
thomashaine 0:e7352f4f3dcb 634 hdcmi.Instance = DCMI;
thomashaine 0:e7352f4f3dcb 635 hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE;
thomashaine 0:e7352f4f3dcb 636 hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_RISING;
thomashaine 0:e7352f4f3dcb 637 //hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING;
thomashaine 0:e7352f4f3dcb 638 //the data is not valid in the parallel interface, when VSYNC or HSYNC is at that level (high or low)
thomashaine 0:e7352f4f3dcb 639 hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW;
thomashaine 0:e7352f4f3dcb 640 hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW;
thomashaine 0:e7352f4f3dcb 641
thomashaine 0:e7352f4f3dcb 642 hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME;
thomashaine 0:e7352f4f3dcb 643 hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B;
thomashaine 0:e7352f4f3dcb 644 hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE;
thomashaine 0:e7352f4f3dcb 645 hdcmi.Init.ByteSelectMode = DCMI_BSM_ALL;
thomashaine 0:e7352f4f3dcb 646 hdcmi.Init.ByteSelectStart = DCMI_OEBS_ODD;
thomashaine 0:e7352f4f3dcb 647 hdcmi.Init.LineSelectMode = DCMI_LSM_ALL;
thomashaine 0:e7352f4f3dcb 648 hdcmi.Init.LineSelectStart = DCMI_OELS_ODD;
thomashaine 0:e7352f4f3dcb 649
thomashaine 0:e7352f4f3dcb 650 if (HAL_DCMI_Init(&hdcmi) != HAL_OK)
thomashaine 0:e7352f4f3dcb 651 {
thomashaine 0:e7352f4f3dcb 652 Error_Handler();
thomashaine 0:e7352f4f3dcb 653 }
thomashaine 0:e7352f4f3dcb 654
thomashaine 0:e7352f4f3dcb 655
thomashaine 0:e7352f4f3dcb 656 //check status
thomashaine 0:e7352f4f3dcb 657 /*HAL_DCMI_StateTypeDef status;
thomashaine 0:e7352f4f3dcb 658 status=HAL_DCMI_GetState(&hdcmi);
thomashaine 0:e7352f4f3dcb 659 if(status != HAL_OK){
thomashaine 0:e7352f4f3dcb 660 pc.printf("DCMI_init: %i\n\r",status);
thomashaine 0:e7352f4f3dcb 661 }*/
thomashaine 0:e7352f4f3dcb 662
thomashaine 0:e7352f4f3dcb 663 }
thomashaine 0:e7352f4f3dcb 664
thomashaine 0:e7352f4f3dcb 665
thomashaine 0:e7352f4f3dcb 666 /**
thomashaine 0:e7352f4f3dcb 667 * @brief DCMI Initialization Function
thomashaine 0:e7352f4f3dcb 668 * @param None
thomashaine 0:e7352f4f3dcb 669 * @retval None
thomashaine 0:e7352f4f3dcb 670 */
thomashaine 0:e7352f4f3dcb 671 static void MX_DCMI_Init_10b(void)
thomashaine 0:e7352f4f3dcb 672 {
thomashaine 0:e7352f4f3dcb 673
thomashaine 0:e7352f4f3dcb 674 hdcmi.Instance = DCMI;
thomashaine 0:e7352f4f3dcb 675 hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE;
thomashaine 0:e7352f4f3dcb 676 hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING;
thomashaine 0:e7352f4f3dcb 677 hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW;
thomashaine 0:e7352f4f3dcb 678 hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW;
thomashaine 0:e7352f4f3dcb 679 hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME;
thomashaine 0:e7352f4f3dcb 680 hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_10B;
thomashaine 0:e7352f4f3dcb 681 hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE;
thomashaine 0:e7352f4f3dcb 682 hdcmi.Init.ByteSelectMode = DCMI_BSM_ALL;
thomashaine 0:e7352f4f3dcb 683 hdcmi.Init.ByteSelectStart = DCMI_OEBS_ODD;
thomashaine 0:e7352f4f3dcb 684 hdcmi.Init.LineSelectMode = DCMI_LSM_ALL;
thomashaine 0:e7352f4f3dcb 685 hdcmi.Init.LineSelectStart = DCMI_OELS_ODD;
thomashaine 0:e7352f4f3dcb 686
thomashaine 0:e7352f4f3dcb 687 if (HAL_DCMI_Init(&hdcmi) != HAL_OK)
thomashaine 0:e7352f4f3dcb 688 {
thomashaine 0:e7352f4f3dcb 689 Error_Handler();
thomashaine 0:e7352f4f3dcb 690 }
thomashaine 0:e7352f4f3dcb 691
thomashaine 0:e7352f4f3dcb 692
thomashaine 0:e7352f4f3dcb 693 /* USER CODE BEGIN DCMI_Init 2 */
thomashaine 0:e7352f4f3dcb 694 //check status
thomashaine 0:e7352f4f3dcb 695 /*HAL_DCMI_StateTypeDef status;
thomashaine 0:e7352f4f3dcb 696 status=HAL_DCMI_GetState(&hdcmi);
thomashaine 0:e7352f4f3dcb 697 if(status != HAL_OK){
thomashaine 0:e7352f4f3dcb 698 pc.printf("DCMI_init: %i\n\r",status);
thomashaine 0:e7352f4f3dcb 699 }*/
thomashaine 0:e7352f4f3dcb 700 /* USER CODE END DCMI_Init 2 */
thomashaine 0:e7352f4f3dcb 701
thomashaine 0:e7352f4f3dcb 702 }
thomashaine 0:e7352f4f3dcb 703
thomashaine 0:e7352f4f3dcb 704
thomashaine 0:e7352f4f3dcb 705
thomashaine 0:e7352f4f3dcb 706
thomashaine 3:c9f65f6d2092 707
thomashaine 3:c9f65f6d2092 708 /**
thomashaine 3:c9f65f6d2092 709 * @brief Enable DMA controller clock
thomashaine 3:c9f65f6d2092 710 * @param None
thomashaine 3:c9f65f6d2092 711 * @retval None
thomashaine 0:e7352f4f3dcb 712 */
thomashaine 0:e7352f4f3dcb 713 static void MX_DMA_Init(void)
thomashaine 0:e7352f4f3dcb 714 {
thomashaine 0:e7352f4f3dcb 715
thomashaine 0:e7352f4f3dcb 716 /* DMA controller clock enable */
thomashaine 0:e7352f4f3dcb 717 __HAL_RCC_DMA1_CLK_ENABLE();
thomashaine 0:e7352f4f3dcb 718
thomashaine 0:e7352f4f3dcb 719 /* DMA interrupt init */
thomashaine 0:e7352f4f3dcb 720 /* DMA1_Stream0_IRQn interrupt configuration */
thomashaine 0:e7352f4f3dcb 721 HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0);
thomashaine 0:e7352f4f3dcb 722 HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);
thomashaine 0:e7352f4f3dcb 723
thomashaine 0:e7352f4f3dcb 724 }
thomashaine 0:e7352f4f3dcb 725
thomashaine 0:e7352f4f3dcb 726 /**
thomashaine 0:e7352f4f3dcb 727 * @brief GPIO Initialization Function
thomashaine 0:e7352f4f3dcb 728 * @param None
thomashaine 0:e7352f4f3dcb 729 * @retval None
thomashaine 0:e7352f4f3dcb 730 */
thomashaine 0:e7352f4f3dcb 731 static void MX_GPIO_Init(void)
thomashaine 0:e7352f4f3dcb 732 {
thomashaine 0:e7352f4f3dcb 733
thomashaine 0:e7352f4f3dcb 734 GPIO_InitTypeDef GPIO_InitStruct = {0};
thomashaine 0:e7352f4f3dcb 735
thomashaine 0:e7352f4f3dcb 736 /* GPIO Ports Clock Enable */
thomashaine 0:e7352f4f3dcb 737 __HAL_RCC_GPIOE_CLK_ENABLE();
thomashaine 0:e7352f4f3dcb 738 __HAL_RCC_GPIOC_CLK_ENABLE();
thomashaine 0:e7352f4f3dcb 739 __HAL_RCC_GPIOF_CLK_ENABLE();
thomashaine 0:e7352f4f3dcb 740 __HAL_RCC_GPIOH_CLK_ENABLE();
thomashaine 0:e7352f4f3dcb 741 __HAL_RCC_GPIOA_CLK_ENABLE();
thomashaine 0:e7352f4f3dcb 742 __HAL_RCC_GPIOB_CLK_ENABLE();
thomashaine 0:e7352f4f3dcb 743 __HAL_RCC_GPIOD_CLK_ENABLE();
thomashaine 0:e7352f4f3dcb 744 __HAL_RCC_GPIOG_CLK_ENABLE();
thomashaine 0:e7352f4f3dcb 745
thomashaine 0:e7352f4f3dcb 746 }
thomashaine 0:e7352f4f3dcb 747
thomashaine 0:e7352f4f3dcb 748
thomashaine 0:e7352f4f3dcb 749
thomashaine 0:e7352f4f3dcb 750
thomashaine 0:e7352f4f3dcb 751 /**
thomashaine 0:e7352f4f3dcb 752 * @brief This function is executed in case of error occurrence.
thomashaine 0:e7352f4f3dcb 753 * @retval None
thomashaine 0:e7352f4f3dcb 754 */
thomashaine 0:e7352f4f3dcb 755 void Error_Handler(void)
thomashaine 0:e7352f4f3dcb 756 {
thomashaine 0:e7352f4f3dcb 757 /* USER CODE BEGIN Error_Handler_Debug */
thomashaine 0:e7352f4f3dcb 758 /* User can add his own implementation to report the HAL error return state */
thomashaine 0:e7352f4f3dcb 759
thomashaine 0:e7352f4f3dcb 760 /* USER CODE END Error_Handler_Debug */
thomashaine 0:e7352f4f3dcb 761 }
thomashaine 0:e7352f4f3dcb 762
thomashaine 0:e7352f4f3dcb 763 #ifdef USE_FULL_ASSERT
thomashaine 0:e7352f4f3dcb 764 /**
thomashaine 0:e7352f4f3dcb 765 * @brief Reports the name of the source file and the source line number
thomashaine 0:e7352f4f3dcb 766 * where the assert_param error has occurred.
thomashaine 0:e7352f4f3dcb 767 * @param file: pointer to the source file name
thomashaine 0:e7352f4f3dcb 768 * @param line: assert_param error line source number
thomashaine 0:e7352f4f3dcb 769 * @retval None
thomashaine 0:e7352f4f3dcb 770 */
thomashaine 0:e7352f4f3dcb 771 void assert_failed(uint8_t *file, uint32_t line)
thomashaine 0:e7352f4f3dcb 772 {
thomashaine 0:e7352f4f3dcb 773 /* USER CODE BEGIN 6 */
thomashaine 0:e7352f4f3dcb 774 /* User can add his own implementation to report the file name and line number,
thomashaine 0:e7352f4f3dcb 775 tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
thomashaine 0:e7352f4f3dcb 776 /* USER CODE END 6 */
thomashaine 0:e7352f4f3dcb 777 }
thomashaine 0:e7352f4f3dcb 778 #endif /* USE_FULL_ASSERT */