SmartWheels self-driving race car. Designed for NXP Cup. Uses FRDM-KL25Z, area-scan camera, and simple image processing to detect and navigate any NXP spec track.

Dependencies:   TSI USBDevice mbed-dev

Fork of SmartWheels by haofan Zheng

Committer:
hazheng
Date:
Wed Apr 05 21:35:47 2017 +0000
Revision:
48:f76b5e252444
Parent:
46:a5eb9bd3bb55
Child:
50:c387c88141fb
Increased the camera speed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hazheng 28:271fc8445e89 1 #include "ArduCAM.h"
hazheng 28:271fc8445e89 2
hazheng 33:e3fcc4d6bb9b 3
hazheng 29:f87d8790f57d 4 #include "GlobalVariable.h"
hazheng 29:f87d8790f57d 5 #include "SWUSBServer.h"
hazheng 29:f87d8790f57d 6
hazheng 32:5badeff825dc 7 #include "CamRegBuf.h"
hazheng 32:5badeff825dc 8
hazheng 41:7b21c5e3599e 9 #include "ArduUTFT.h"
hazheng 41:7b21c5e3599e 10
hazheng 32:5badeff825dc 11 #include <string>
hazheng 32:5badeff825dc 12
hazheng 44:15de535c4005 13 #define CAM_BLK_CAL_LEFT 75
hazheng 44:15de535c4005 14 #define CAM_BLK_CAL_RIGHT 85
hazheng 44:15de535c4005 15
hazheng 46:a5eb9bd3bb55 16 //#define CAM_DISP_DEBUG
hazheng 48:f76b5e252444 17 //#define CAM_DISP_DEBUG_CENTER
hazheng 48:f76b5e252444 18 #define CAM_DISP_IMG
hazheng 46:a5eb9bd3bb55 19
hazheng 46:a5eb9bd3bb55 20 #ifdef __cplusplus
hazheng 46:a5eb9bd3bb55 21 extern "C" {
hazheng 46:a5eb9bd3bb55 22 #endif
hazheng 44:15de535c4005 23
hazheng 28:271fc8445e89 24 extern SPI g_spi_port;
hazheng 28:271fc8445e89 25
hazheng 46:a5eb9bd3bb55 26 static DigitalOut cam_cs(PIN_ACC_CS, 1);
hazheng 29:f87d8790f57d 27
hazheng 46:a5eb9bd3bb55 28 static uint8_t temp_mid_pos = RESOLUTION_WIDTH / 2;
hazheng 46:a5eb9bd3bb55 29 static uint8_t black_calibrate = 70;
hazheng 46:a5eb9bd3bb55 30 static volatile uint8_t centerLine[CAM_ROI_UPPER_LIMIT];
hazheng 44:15de535c4005 31 //volatile const uint8_t* outCenterLine = centerLine;
hazheng 46:a5eb9bd3bb55 32 static Thread * m_imgProcessThread = NULL;
hazheng 44:15de535c4005 33
hazheng 44:15de535c4005 34 void image_processing();
hazheng 44:15de535c4005 35 void cal_black_calibrate();
hazheng 34:f79db3bc2f86 36
hazheng 34:f79db3bc2f86 37 inline void ardu_cam_spi_write_8(int address, int value)
hazheng 29:f87d8790f57d 38 {
hazheng 34:f79db3bc2f86 39 // take the SS pin low to select the chip:
hazheng 34:f79db3bc2f86 40 cam_cs = 0;
hazheng 34:f79db3bc2f86 41 // send in the address and value via SPI:
hazheng 34:f79db3bc2f86 42 g_spi_port.write(address | 0x80);
hazheng 34:f79db3bc2f86 43 g_spi_port.write(value);
hazheng 34:f79db3bc2f86 44 // take the SS pin high to de-select the chip:
hazheng 34:f79db3bc2f86 45 cam_cs = 1;
hazheng 34:f79db3bc2f86 46 }
hazheng 34:f79db3bc2f86 47
hazheng 34:f79db3bc2f86 48 inline uint8_t ardu_cam_spi_read_8(int address)
hazheng 34:f79db3bc2f86 49 {
hazheng 34:f79db3bc2f86 50 // take the SS pin low to select the chip:
hazheng 29:f87d8790f57d 51 cam_cs = 0;
hazheng 34:f79db3bc2f86 52 // send in the address and value via SPI:
hazheng 34:f79db3bc2f86 53 g_spi_port.write(address & 0x7F);
hazheng 34:f79db3bc2f86 54 uint8_t value = static_cast<uint8_t>(g_spi_port.write(0x00));
hazheng 34:f79db3bc2f86 55 // take the SS pin high to de-select the chip:
hazheng 29:f87d8790f57d 56 cam_cs = 1;
hazheng 34:f79db3bc2f86 57 return value;
hazheng 34:f79db3bc2f86 58 }
hazheng 34:f79db3bc2f86 59 /*
hazheng 34:f79db3bc2f86 60 inline void ardu_cam_spi_set_burst()
hazheng 34:f79db3bc2f86 61 {
hazheng 34:f79db3bc2f86 62 cam_cs = 0;
hazheng 34:f79db3bc2f86 63
hazheng 34:f79db3bc2f86 64 g_spi_port.write(BURST_FIFO_READ & 0x7F);
hazheng 29:f87d8790f57d 65
hazheng 34:f79db3bc2f86 66 cam_cs = 1;
hazheng 34:f79db3bc2f86 67 }
hazheng 34:f79db3bc2f86 68
hazheng 34:f79db3bc2f86 69 inline uint16_t ardu_cam_spi_burst_read_16()
hazheng 34:f79db3bc2f86 70 {
hazheng 34:f79db3bc2f86 71 cam_cs = 0;
hazheng 29:f87d8790f57d 72
hazheng 34:f79db3bc2f86 73 uint16_t value = static_cast<uint16_t>(g_spi_port.write(0x00));
hazheng 34:f79db3bc2f86 74 value = (value << 8) & 0xFF00;
hazheng 34:f79db3bc2f86 75 value = value | static_cast<uint16_t>(g_spi_port.write(0x00));
hazheng 34:f79db3bc2f86 76
hazheng 34:f79db3bc2f86 77 cam_cs = 1;
hazheng 34:f79db3bc2f86 78 return value;
hazheng 29:f87d8790f57d 79 }
hazheng 29:f87d8790f57d 80 */
hazheng 29:f87d8790f57d 81
hazheng 29:f87d8790f57d 82
hazheng 28:271fc8445e89 83 bool ardu_cam_init()
hazheng 28:271fc8445e89 84 {
hazheng 32:5badeff825dc 85 char buf[20];
hazheng 32:5badeff825dc 86
hazheng 36:7e747e19f660 87 CamRegBuf * camReg = new CamRegBuf(g_core, CAM_SCCB_WRITE, CAM_SCCB_READ);
hazheng 36:7e747e19f660 88
hazheng 36:7e747e19f660 89 camReg->WriteRegSet(ResetProg);
hazheng 46:a5eb9bd3bb55 90 wait_ms(10);
hazheng 37:7074a6118d03 91 camReg->WriteRegSet(QVGA);
hazheng 44:15de535c4005 92 wait_ms(10);
hazheng 32:5badeff825dc 93
hazheng 36:7e747e19f660 94 #if defined(ARDUCAM_OV2640)
hazheng 32:5badeff825dc 95 camReg->SCCBWrite(0xff, 0x01);
hazheng 36:7e747e19f660 96 #endif
hazheng 36:7e747e19f660 97 uint8_t camVer = camReg->SCCBRead(CAM_PID_ADDR);
hazheng 32:5badeff825dc 98 sprintf(buf, "Cam VerH %#x", camVer);
hazheng 32:5badeff825dc 99 g_core.GetUSBServer().PushReliableMsg('D', buf);
hazheng 32:5badeff825dc 100
hazheng 36:7e747e19f660 101 camVer = camReg->SCCBRead(CAM_VER_ADDR);
hazheng 32:5badeff825dc 102 sprintf(buf, "Cam VerL %#x", camVer);
hazheng 32:5badeff825dc 103 g_core.GetUSBServer().PushReliableMsg('D', buf);
hazheng 36:7e747e19f660 104
hazheng 36:7e747e19f660 105
hazheng 32:5badeff825dc 106 delete camReg;
hazheng 32:5badeff825dc 107 camReg = NULL;
hazheng 32:5badeff825dc 108
hazheng 32:5badeff825dc 109
hazheng 32:5badeff825dc 110
hazheng 32:5badeff825dc 111
hazheng 34:f79db3bc2f86 112 uint8_t VerNum = ardu_cam_spi_read_8(0x40);
hazheng 34:f79db3bc2f86 113 VerNum = ardu_cam_spi_read_8(0x40);
hazheng 29:f87d8790f57d 114
hazheng 32:5badeff825dc 115
hazheng 29:f87d8790f57d 116 sprintf(buf, "Ardu Ver %#x", VerNum);
hazheng 29:f87d8790f57d 117 g_core.GetUSBServer().PushReliableMsg('D', buf);
hazheng 29:f87d8790f57d 118
hazheng 34:f79db3bc2f86 119 ardu_cam_spi_write_8(ARDUCHIP_TEST1, ARDUCHIP_TEST_MSG);
hazheng 34:f79db3bc2f86 120 uint8_t testV = ardu_cam_spi_read_8(ARDUCHIP_TEST1);
hazheng 35:ac4fcca21560 121 if(VerNum != ARDUCHIP_VER_NUM || testV != ARDUCHIP_TEST_MSG)
hazheng 29:f87d8790f57d 122 {
hazheng 29:f87d8790f57d 123 g_core.GetUSBServer().PushReliableMsg('D', "CameraInit Fa");
hazheng 29:f87d8790f57d 124 return false;
hazheng 29:f87d8790f57d 125 }
hazheng 29:f87d8790f57d 126 g_core.GetUSBServer().PushReliableMsg('D', "CameraInit Su");
hazheng 29:f87d8790f57d 127
hazheng 35:ac4fcca21560 128 //ardu_cam_set_mode(MCU2LCD_MODE);
hazheng 43:0d1886f4848a 129 ardu_cam_spi_write_8(ARDUCHIP_CAP_CTRL, 0x00);
hazheng 44:15de535c4005 130 //ardu_cam_start_capture();
hazheng 29:f87d8790f57d 131
hazheng 28:271fc8445e89 132
hazheng 32:5badeff825dc 133 //unsigned char tempV = ardu_cam_read_reg(ARDUCHIP_MODE);
hazheng 32:5badeff825dc 134 //sprintf(buf, "Ardu Stat %#x", tempV);
hazheng 32:5badeff825dc 135 //g_core.GetUSBServer().PushReliableMsg('D', buf);
hazheng 29:f87d8790f57d 136
hazheng 32:5badeff825dc 137 //tempV = ardu_cam_read_reg(ARDUCHIP_CAP_CTRL);
hazheng 32:5badeff825dc 138 //sprintf(buf, "Ardu FS1 %#x", tempV);
hazheng 32:5badeff825dc 139 //g_core.GetUSBServer().PushReliableMsg('D', buf);
hazheng 44:15de535c4005 140 cal_black_calibrate();
hazheng 46:a5eb9bd3bb55 141 m_imgProcessThread = new Thread;
hazheng 46:a5eb9bd3bb55 142 m_imgProcessThread->start(callback(image_processing));
hazheng 29:f87d8790f57d 143
hazheng 29:f87d8790f57d 144 return true;
hazheng 29:f87d8790f57d 145 }
hazheng 29:f87d8790f57d 146
hazheng 29:f87d8790f57d 147 void ardu_cam_start_capture()
hazheng 29:f87d8790f57d 148 {
hazheng 34:f79db3bc2f86 149 ardu_cam_spi_write_8(ARDUCHIP_FIFO, FIFO_CLEAR_MASK);
hazheng 48:f76b5e252444 150
hazheng 34:f79db3bc2f86 151 ardu_cam_spi_write_8(ARDUCHIP_FIFO, FIFO_START_MASK);
hazheng 29:f87d8790f57d 152 }
hazheng 29:f87d8790f57d 153
hazheng 32:5badeff825dc 154 uint32_t ardu_cam_get_fifo_length()
hazheng 32:5badeff825dc 155 {
hazheng 32:5badeff825dc 156 uint32_t len1,len2,len3,length=0;
hazheng 34:f79db3bc2f86 157 len1 = ardu_cam_spi_read_8(FIFO_SIZE1);
hazheng 34:f79db3bc2f86 158 len2 = ardu_cam_spi_read_8(FIFO_SIZE2);
hazheng 34:f79db3bc2f86 159 len3 = ardu_cam_spi_read_8(FIFO_SIZE3) & 0x07;
hazheng 32:5badeff825dc 160 length = ((len3 << 16) | (len2 << 8) | len1) & 0x07ffff;
hazheng 32:5badeff825dc 161 return length;
hazheng 32:5badeff825dc 162 }
hazheng 32:5badeff825dc 163
hazheng 32:5badeff825dc 164 uint8_t ardu_cam_get_pixel()
hazheng 32:5badeff825dc 165 {
hazheng 34:f79db3bc2f86 166 uint16_t VH = ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 34:f79db3bc2f86 167 uint16_t VL = ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 34:f79db3bc2f86 168 //uint16_t VL = ardu_cam_spi_burst_read_16();
hazheng 32:5badeff825dc 169
hazheng 32:5badeff825dc 170 VL = (VL & 0x00FF) | ((VH << 8) & 0xFF00);
hazheng 33:e3fcc4d6bb9b 171 uint8_t ch = ((VL & 0xF800) >> 9);// << 2;
hazheng 33:e3fcc4d6bb9b 172 float pixel = (static_cast<float>(ch) * 0.21);
hazheng 32:5badeff825dc 173
hazheng 33:e3fcc4d6bb9b 174 ch = ((VL & 0x07E0) >> 3);// << 2;
hazheng 33:e3fcc4d6bb9b 175 pixel += (static_cast<float>(ch) * 0.72);
hazheng 32:5badeff825dc 176
hazheng 33:e3fcc4d6bb9b 177 ch = (VL & 0x001F) << 2;
hazheng 33:e3fcc4d6bb9b 178 pixel += (static_cast<float>(ch) * 0.07);
hazheng 32:5badeff825dc 179
hazheng 32:5badeff825dc 180 return static_cast<uint8_t>(pixel);
hazheng 32:5badeff825dc 181 }
hazheng 32:5badeff825dc 182
hazheng 32:5badeff825dc 183 void ardu_cam_print_debug()
hazheng 32:5badeff825dc 184 {
hazheng 32:5badeff825dc 185 uint32_t len = ardu_cam_get_fifo_length();
hazheng 32:5badeff825dc 186 char buf[20];
hazheng 32:5badeff825dc 187 sprintf(buf, "Cam L %#x", len);
hazheng 32:5badeff825dc 188 g_core.GetUSBServer().PushReliableMsg('D', buf);
hazheng 32:5badeff825dc 189
hazheng 33:e3fcc4d6bb9b 190 //if(len < (RESOLUTION_HEIGHT * RESOLUTION_WIDTH * 2))
hazheng 33:e3fcc4d6bb9b 191 // return;
hazheng 33:e3fcc4d6bb9b 192
hazheng 33:e3fcc4d6bb9b 193 //Begin output the picture
hazheng 32:5badeff825dc 194 std::string lineBuf;
hazheng 37:7074a6118d03 195 #if defined(MANUAL_REDUCE_RESULOTION_BY2)
hazheng 37:7074a6118d03 196 lineBuf.resize((RESOLUTION_WIDTH / 2) + 1);
hazheng 37:7074a6118d03 197 #else
hazheng 33:e3fcc4d6bb9b 198 lineBuf.resize(RESOLUTION_WIDTH + 1);
hazheng 37:7074a6118d03 199 #endif
hazheng 32:5badeff825dc 200
hazheng 34:f79db3bc2f86 201 //ardu_cam_spi_set_burst();
hazheng 41:7b21c5e3599e 202
hazheng 42:c4e1606087ff 203 //ardu_cam_get_pixel(); //Get the first dummy pixel
hazheng 41:7b21c5e3599e 204
hazheng 43:0d1886f4848a 205
hazheng 33:e3fcc4d6bb9b 206 for (uint8_t i = 0; i < RESOLUTION_HEIGHT; ++i)
hazheng 32:5badeff825dc 207 {
hazheng 37:7074a6118d03 208 #if defined(MANUAL_REDUCE_RESULOTION_BY2)
hazheng 37:7074a6118d03 209 lineBuf[0] = i / 2;
hazheng 37:7074a6118d03 210
hazheng 37:7074a6118d03 211 for (int j = 0; j < RESOLUTION_WIDTH; ++j)
hazheng 37:7074a6118d03 212 {
hazheng 37:7074a6118d03 213 if(i % 2 == 0 || j % 2 == 0)
hazheng 37:7074a6118d03 214 {
hazheng 37:7074a6118d03 215 ardu_cam_get_pixel();
hazheng 37:7074a6118d03 216 }
hazheng 37:7074a6118d03 217 else
hazheng 37:7074a6118d03 218 {
hazheng 37:7074a6118d03 219 lineBuf[(j / 2) + 1] = ardu_cam_get_pixel();
hazheng 37:7074a6118d03 220 }
hazheng 37:7074a6118d03 221 }
hazheng 37:7074a6118d03 222
hazheng 37:7074a6118d03 223 if(i % 2 == 0)
hazheng 37:7074a6118d03 224 {
hazheng 37:7074a6118d03 225
hazheng 37:7074a6118d03 226 }
hazheng 37:7074a6118d03 227 else
hazheng 37:7074a6118d03 228 {
hazheng 37:7074a6118d03 229 g_core.GetUSBServer().PushReliableMsg('P', lineBuf);
hazheng 37:7074a6118d03 230 wait(0.35);
hazheng 37:7074a6118d03 231 }
hazheng 37:7074a6118d03 232
hazheng 37:7074a6118d03 233 #else
hazheng 37:7074a6118d03 234
hazheng 32:5badeff825dc 235 lineBuf[0] = i;
hazheng 32:5badeff825dc 236
hazheng 33:e3fcc4d6bb9b 237 for (int j = 0; j < RESOLUTION_WIDTH; ++j)
hazheng 32:5badeff825dc 238 {
hazheng 33:e3fcc4d6bb9b 239 //uint8_t p = ardu_cam_get_pixel();
hazheng 33:e3fcc4d6bb9b 240 lineBuf[j + 1] = ardu_cam_get_pixel();
hazheng 32:5badeff825dc 241 }
hazheng 32:5badeff825dc 242
hazheng 32:5badeff825dc 243 g_core.GetUSBServer().PushReliableMsg('P', lineBuf);
hazheng 35:ac4fcca21560 244 wait(0.35);
hazheng 37:7074a6118d03 245
hazheng 37:7074a6118d03 246 #endif
hazheng 37:7074a6118d03 247
hazheng 32:5badeff825dc 248 }
hazheng 43:0d1886f4848a 249
hazheng 43:0d1886f4848a 250 }
hazheng 43:0d1886f4848a 251
hazheng 44:15de535c4005 252 uint8_t ardu_cam_is_capture_finished()
hazheng 44:15de535c4005 253 {
hazheng 44:15de535c4005 254 return (ardu_cam_spi_read_8(ARDUCHIP_TRIG) & CAP_DONE_MASK);
hazheng 44:15de535c4005 255 }
hazheng 44:15de535c4005 256
hazheng 44:15de535c4005 257 void cal_black_calibrate()
hazheng 44:15de535c4005 258 {
hazheng 44:15de535c4005 259 ardu_cam_start_capture();
hazheng 44:15de535c4005 260
hazheng 44:15de535c4005 261 while (!(ardu_cam_spi_read_8(ARDUCHIP_TRIG) & CAP_DONE_MASK));
hazheng 44:15de535c4005 262
hazheng 44:15de535c4005 263 float temp = 0.0f;
hazheng 44:15de535c4005 264 static uint16_t pixel = 0x00;
hazheng 44:15de535c4005 265 for (uint8_t j = 0; j < RESOLUTION_WIDTH; ++j)
hazheng 44:15de535c4005 266 {
hazheng 44:15de535c4005 267 pixel = static_cast<uint16_t>(ardu_cam_spi_read_8(SINGLE_FIFO_READ)) << 8;
hazheng 44:15de535c4005 268 pixel = pixel | ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 46:a5eb9bd3bb55 269
hazheng 44:15de535c4005 270 if(CAM_BLK_CAL_LEFT < j && j <= CAM_BLK_CAL_RIGHT)
hazheng 44:15de535c4005 271 {
hazheng 44:15de535c4005 272 temp += static_cast<uint8_t>((pixel >> 3) & 0x00FF);
hazheng 44:15de535c4005 273 }
hazheng 44:15de535c4005 274 }
hazheng 44:15de535c4005 275 temp = temp / (CAM_BLK_CAL_RIGHT - CAM_BLK_CAL_LEFT);
hazheng 44:15de535c4005 276 black_calibrate = temp * 0.7f;
hazheng 44:15de535c4005 277 }
hazheng 44:15de535c4005 278
hazheng 44:15de535c4005 279 inline void get_img_row_info(const uint8_t display, const uint8_t rowI, uint8_t * left, uint8_t * right)
hazheng 44:15de535c4005 280 {
hazheng 44:15de535c4005 281 *left = 0;
hazheng 44:15de535c4005 282 *right = RESOLUTION_WIDTH;
hazheng 44:15de535c4005 283 uint8_t isRightFound = 0;
hazheng 44:15de535c4005 284 /*
hazheng 44:15de535c4005 285 #ifdef IMAGE_DISPLAY_TO_SCREEN
hazheng 44:15de535c4005 286 if(display)
hazheng 44:15de535c4005 287 {
hazheng 44:15de535c4005 288 ardu_utft_set_camimg_row(CAM_ROI_UPPER_LIMIT - rowI);
hazheng 44:15de535c4005 289 }
hazheng 44:15de535c4005 290 #endif
hazheng 44:15de535c4005 291 */
hazheng 44:15de535c4005 292 static uint16_t pixel = 0x0000;
hazheng 44:15de535c4005 293 static uint8_t pGreen = 0x00;
hazheng 44:15de535c4005 294
hazheng 44:15de535c4005 295 for (uint8_t j = 0; j < RESOLUTION_WIDTH; ++j)
hazheng 44:15de535c4005 296 {
hazheng 44:15de535c4005 297 pixel = static_cast<uint16_t>(ardu_cam_spi_read_8(SINGLE_FIFO_READ)) << 8;
hazheng 44:15de535c4005 298 pixel = pixel | ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 46:a5eb9bd3bb55 299
hazheng 44:15de535c4005 300 pGreen = static_cast<uint8_t>((pixel >> 3) & 0x00FF);
hazheng 44:15de535c4005 301 if((pGreen < black_calibrate))
hazheng 44:15de535c4005 302 {
hazheng 44:15de535c4005 303 if(j < temp_mid_pos)
hazheng 44:15de535c4005 304 {
hazheng 44:15de535c4005 305 *left = j;
hazheng 46:a5eb9bd3bb55 306 #ifdef CAM_DISP_DEBUG
hazheng 46:a5eb9bd3bb55 307 ardu_utft_write_DATA(0xF8, 0x00);
hazheng 46:a5eb9bd3bb55 308 #endif
hazheng 44:15de535c4005 309 }
hazheng 44:15de535c4005 310 else if(!isRightFound)
hazheng 44:15de535c4005 311 {
hazheng 44:15de535c4005 312 *right = j;
hazheng 44:15de535c4005 313 isRightFound = 1;
hazheng 46:a5eb9bd3bb55 314 #ifdef CAM_DISP_DEBUG
hazheng 46:a5eb9bd3bb55 315 ardu_utft_write_DATA(0xF8, 0x00);
hazheng 46:a5eb9bd3bb55 316 #endif
hazheng 44:15de535c4005 317 }
hazheng 44:15de535c4005 318 }
hazheng 46:a5eb9bd3bb55 319 #ifdef CAM_DISP_DEBUG
hazheng 46:a5eb9bd3bb55 320 else
hazheng 46:a5eb9bd3bb55 321 {
hazheng 46:a5eb9bd3bb55 322 ardu_utft_write_DATA(static_cast<uint8_t>(pixel >> 8), static_cast<uint8_t>(pixel));
hazheng 46:a5eb9bd3bb55 323 }
hazheng 46:a5eb9bd3bb55 324 #elif defined(CAM_DISP_IMG)
hazheng 46:a5eb9bd3bb55 325 ardu_utft_write_DATA(static_cast<uint8_t>(pixel >> 8), static_cast<uint8_t>(pixel));
hazheng 46:a5eb9bd3bb55 326 #endif
hazheng 44:15de535c4005 327 }
hazheng 44:15de535c4005 328 }
hazheng 44:15de535c4005 329
hazheng 44:15de535c4005 330 volatile const uint8_t* ardu_cam_get_center_array()
hazheng 44:15de535c4005 331 {
hazheng 44:15de535c4005 332 return centerLine;
hazheng 44:15de535c4005 333 }
hazheng 44:15de535c4005 334
hazheng 44:15de535c4005 335 void image_processing()
hazheng 44:15de535c4005 336 {
hazheng 44:15de535c4005 337 while(true)
hazheng 44:15de535c4005 338 {
hazheng 44:15de535c4005 339 ardu_cam_start_capture();
hazheng 44:15de535c4005 340
hazheng 44:15de535c4005 341 while (!(ardu_cam_spi_read_8(ARDUCHIP_TRIG) & CAP_DONE_MASK));
hazheng 44:15de535c4005 342
hazheng 44:15de535c4005 343 temp_mid_pos = RESOLUTION_WIDTH / 2;
hazheng 44:15de535c4005 344 //cal_black_calibrate();
hazheng 44:15de535c4005 345 uint8_t leftPos = 0;
hazheng 44:15de535c4005 346 uint8_t rightPos = 0;
hazheng 44:15de535c4005 347 for (uint8_t i = 0; i < CAM_ROI_UPPER_LIMIT; ++i)
hazheng 44:15de535c4005 348 {
hazheng 46:a5eb9bd3bb55 349 #if defined(CAM_DISP_IMG) or defined(CAM_DISP_DEBUG)
hazheng 46:a5eb9bd3bb55 350 ardu_utft_set_camimg_row(CAM_ROI_UPPER_LIMIT - i);
hazheng 46:a5eb9bd3bb55 351 #endif
hazheng 44:15de535c4005 352 get_img_row_info(0, i, &leftPos, &rightPos);
hazheng 44:15de535c4005 353 temp_mid_pos = (leftPos + rightPos) / 2;
hazheng 46:a5eb9bd3bb55 354
hazheng 46:a5eb9bd3bb55 355 #ifdef CAM_DISP_DEBUG_CENTER
hazheng 44:15de535c4005 356 ardu_utft_set_camimg_rowcol(CAM_ROI_UPPER_LIMIT - i, temp_mid_pos);
hazheng 44:15de535c4005 357 ardu_utft_write_DATA(0xF8, 0x00);
hazheng 44:15de535c4005 358 #endif
hazheng 46:a5eb9bd3bb55 359
hazheng 44:15de535c4005 360 centerLine[CAM_ROI_UPPER_LIMIT - i - 1] = temp_mid_pos;
hazheng 44:15de535c4005 361 }
hazheng 44:15de535c4005 362 }
hazheng 44:15de535c4005 363 }
hazheng 46:a5eb9bd3bb55 364
hazheng 46:a5eb9bd3bb55 365
hazheng 43:0d1886f4848a 366 void ardu_cam_display_img_utft()
hazheng 43:0d1886f4848a 367 {
hazheng 43:0d1886f4848a 368 ardu_cam_start_capture();
hazheng 44:15de535c4005 369
hazheng 44:15de535c4005 370 while (!(ardu_cam_spi_read_8(ARDUCHIP_TRIG) & CAP_DONE_MASK));
hazheng 44:15de535c4005 371
hazheng 44:15de535c4005 372 temp_mid_pos = RESOLUTION_WIDTH / 2;
hazheng 46:a5eb9bd3bb55 373
hazheng 44:15de535c4005 374 uint8_t leftPos = 0;
hazheng 44:15de535c4005 375 uint8_t rightPos = 0;
hazheng 44:15de535c4005 376 for (uint8_t i = 0; i < CAM_ROI_UPPER_LIMIT; ++i)
hazheng 43:0d1886f4848a 377 {
hazheng 46:a5eb9bd3bb55 378 ardu_utft_set_camimg_row(CAM_ROI_UPPER_LIMIT - i);
hazheng 46:a5eb9bd3bb55 379 for (uint8_t j = 0; j < RESOLUTION_WIDTH; ++j)
hazheng 46:a5eb9bd3bb55 380 {
hazheng 46:a5eb9bd3bb55 381 uint8_t VH = ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 46:a5eb9bd3bb55 382 uint8_t VL = ardu_cam_spi_read_8(SINGLE_FIFO_READ);
hazheng 46:a5eb9bd3bb55 383
hazheng 46:a5eb9bd3bb55 384 ardu_utft_write_DATA(VH, VL);
hazheng 46:a5eb9bd3bb55 385 }
hazheng 44:15de535c4005 386
hazheng 43:0d1886f4848a 387 }
hazheng 44:15de535c4005 388 }
hazheng 46:a5eb9bd3bb55 389
hazheng 46:a5eb9bd3bb55 390 #ifdef __cplusplus
hazheng 46:a5eb9bd3bb55 391 }
hazheng 46:a5eb9bd3bb55 392 #endif
hazheng 46:a5eb9bd3bb55 393
hazheng 46:a5eb9bd3bb55 394
hazheng 46:a5eb9bd3bb55 395