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