cis001v2

Committer:
thomashaine
Date:
Thu Jun 18 12:36:05 2020 +0000
Revision:
0:e7352f4f3dcb
Child:
1:5060c8ea0ccd
rev1

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