cis001v2

Committer:
thomashaine
Date:
Thu Jun 18 14:34:24 2020 +0000
Revision:
1:5060c8ea0ccd
Parent:
0:e7352f4f3dcb
Child:
2:53ca7bc14ed5
rev2

Who changed what in which revision?

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