-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArduCAM.cpp
2228 lines (2121 loc) · 58.1 KB
/
ArduCAM.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
ArduCAM.cpp - Arduino library support for CMOS Image Sensor
Copyright (C)2011-2015 ArduCAM.com. All right reserved
Basic functionality of this library are based on the demo-code provided by
ArduCAM.com. You can find the latest version of the library at
http://www.ArduCAM.com
Now supported controllers:
- OV2640
- OV5642
- OV5640
We will add support for many other sensors in next release.
Supported MCU platform
- Theoretically support all Arduino families
- Arduino UNO R3 (Tested)
- Arduino MEGA2560 R3 (Tested)
- Arduino Leonardo R3 (Tested)
- Arduino Nano (Tested)
- Arduino DUE (Tested)
- Arduino Yun (Tested)
- Raspberry Pi (Tested)
- ESP8266-12 (Tested)
If you make any modifications or improvements to the code, I would appreciate
that you share the code with me so that I might include it in the next release.
I can be contacted through http://www.ArduCAM.com
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*------------------------------------
Revision History:
2012/09/20 V1.0.0 by Lee first release
2012/10/23 V1.0.1 by Lee Resolved some timing issue for the Read/Write Register
2012/11/29 V1.1.0 by Lee Add support for MT9D111 sensor
2012/12/13 V1.2.0 by Lee Add support for OV7675 sensor
2012/12/28 V1.3.0 by Lee Add support for OV2640,OV3640,OV5642 sensors
2013/02/26 V2.0.0 by Lee New Rev.B shield hardware, add support for FIFO control
and support Mega1280/2560 boards
2013/05/28 V2.1.0 by Lee Add support all drawing functions derived from UTFT library
2013/08/24 V3.0.0 by Lee Support ArudCAM shield Rev.C hardware, features SPI interface and low power mode.
Support almost all series of Arduino boards including DUE.
2014/02/06 V3.0.1 by Lee Minor change to the library, fixed some bugs, add self test code to the sketches for easy debugging.
2014/03/09 V3.1.0 by Lee Add the more impressive example sketches.
Optimise the OV5642 settings, improve image quality.
Add live preview before JPEG capture.
Add play back photos one by one after BMP capture.
2014/05/01 V3.1.1 by Lee Minor changes to add support Arduino IDE for linux distributions.
2014/09/30 V3.2.0 by Lee Improvement on OV5642 camera dirver.
2014/10/06 V3.3.0 by Lee Add OV7660,OV7725 camera support.
2015/02/27 V3.4.0 by Lee Add the support for Arduino Yun board, update the latest UTFT library for ArduCAM.
2015/06/09 V3.4.1 by Lee Minor changes and add some comments
2015/06/19 V3.4.2 by Lee Add support for MT9M112 camera.
2015/06/20 V3.4.3 by Lee Add support for MT9V111 camera.
2015/06/22 V3.4.4 by Lee Add support for OV5640 camera.
2015/06/22 V3.4.5 by Lee Add support for MT9M001 camera.
2015/08/05 V3.4.6 by Lee Add support for MT9T112 camera.
2015/08/08 V3.4.7 by Lee Add support for MT9D112 camera.
2015/09/20 V3.4.8 by Lee Add support for ESP8266 processor.
2016/02/03 V3.4.9 by Lee Add support for Arduino ZERO board.
2016/06/07 V3.5.0 by Lee Add support for OV5642_CAM_BIT_ROTATION_FIXED.
2016/06/14 V3.5.1 by Lee Add support for ArduCAM-Mini-5MP-Plus OV5640_CAM.
2016/09/29 V3.5.2 by Lee Optimize the OV5642 register settings
2016/10/05 V4.0.0 by Lee Add support for second generation hardware platforms like ArduCAM shield V2, ArduCAM-Mini-5MP-Plus(OV5642/OV5640).
2016/10/28 V4.0.1 by Lee Add support for Raspberry Pi
2017/04/27 V4.1.0 by Lee Add support for OV2640/OV5640/OV5642 functions.
2017/07/07 V4.1.0 by Lee Add support for ArduCAM_ESP32 paltform
2017/07/25 V4.1.1 by Lee Add support for MT9V034
--------------------------------------*/
#include "Arduino.h"
#include "ArduCAM.h"
#include <Wire.h>
#include <SPI.h>
#include "HardwareSerial.h"
ArduCAM::ArduCAM(byte model, int CS)
{
B_CS = CS;
pinMode(CS, OUTPUT);
sbi(P_CS, B_CS);
sensor_model = model;
switch (sensor_model)
{
case OV5640:
case OV5642:
sensor_addr = 0x78;
break;
case OV2640:
sensor_addr = 0x60;
break;
default:
sensor_addr = 0x42;
break;
}
}
void ArduCAM::InitCAM()
{
switch (sensor_model)
{
case OV5642:
{
#if (defined(OV5642_CAM) || defined(OV5642_MINI_5MP) || defined(OV5642_MINI_5MP_BIT_ROTATION_FIXED) || defined(OV5642_MINI_5MP_PLUS))
wrSensorReg16_8(0x3008, 0x80);
if (m_fmt == RAW)
{
// Init and set 640x480;
wrSensorRegs16_8(OV5642_1280x960_RAW);
wrSensorRegs16_8(OV5642_640x480_RAW);
}
else
{
wrSensorRegs16_8(OV5642_QVGA_Preview);
delay(100);
if (m_fmt == JPEG)
{
delay(100);
wrSensorRegs16_8(OV5642_JPEG_Capture_QSXGA);
wrSensorRegs16_8(ov5642_320x240);
delay(100);
wrSensorReg16_8(0x3818, 0xa8);
wrSensorReg16_8(0x3621, 0x10);
wrSensorReg16_8(0x3801, 0xb0);
#if (defined(OV5642_MINI_5MP_PLUS) || (defined ARDUCAM_SHIELD_V2))
wrSensorReg16_8(0x4407, 0x08);
#else
wrSensorReg16_8(0x4407, 0x0C);
#endif
wrSensorReg16_8(0x5888, 0x00);
wrSensorReg16_8(0x5000, 0xFF);
}
else
{
byte reg_val;
wrSensorReg16_8(0x4740, 0x21);
wrSensorReg16_8(0x501e, 0x2a);
wrSensorReg16_8(0x5002, 0xf8);
wrSensorReg16_8(0x501f, 0x01);
wrSensorReg16_8(0x4300, 0x61);
rdSensorReg16_8(0x3818, ®_val);
wrSensorReg16_8(0x3818, (reg_val | 0x60) & 0xff);
rdSensorReg16_8(0x3621, ®_val);
wrSensorReg16_8(0x3621, reg_val & 0xdf);
}
}
#endif
break;
}
case OV5640:
{
#if (defined(OV5640_CAM) || defined(OV5640_MINI_5MP_PLUS))
delay(100);
if (m_fmt == JPEG)
{
wrSensorReg16_8(0x3103, 0x11);
wrSensorReg16_8(0x3008, 0x82);
delay(100);
wrSensorRegs16_8(OV5640YUV_Sensor_Dvp_Init);
delay(500);
wrSensorRegs16_8(OV5640_JPEG_QSXGA);
wrSensorRegs16_8(OV5640_QSXGA2QVGA);
#if (defined(OV5640_MINI_5MP_PLUS) || (defined ARDUCAM_SHIELD_V2))
wrSensorReg16_8(0x4407, 0x04);
#else
wrSensorReg16_8(0x4407, 0x0C);
#endif
}
else
{
wrSensorReg16_8(0x3103, 0x11);
wrSensorReg16_8(0x3008, 0x82);
delay(500);
wrSensorRegs16_8(OV5640YUV_Sensor_Dvp_Init);
wrSensorRegs16_8(OV5640_RGB_QVGA);
}
#endif
break;
}
case OV2640:
{
#if (defined(OV2640_CAM) || defined(OV2640_MINI_2MP) || defined(OV2640_MINI_2MP_PLUS))
wrSensorReg8_8(0xff, 0x01);
wrSensorReg8_8(0x12, 0x80);
delay(100);
if (m_fmt == JPEG)
{
wrSensorRegs8_8(OV2640_JPEG_INIT);
wrSensorRegs8_8(OV2640_YUV422);
wrSensorRegs8_8(OV2640_JPEG);
wrSensorReg8_8(0xff, 0x01);
wrSensorReg8_8(0x15, 0x00);
wrSensorRegs8_8(OV2640_320x240_JPEG);
// wrSensorReg8_8(0xff, 0x00);
// wrSensorReg8_8(0x44, 0x32);
}
else
{
wrSensorRegs8_8(OV2640_QVGA);
}
#endif
break;
}
default:
break;
}
}
void ArduCAM::flush_fifo(void)
{
write_reg(ARDUCHIP_FIFO, FIFO_CLEAR_MASK);
}
void ArduCAM::start_capture(void)
{
write_reg(ARDUCHIP_FIFO, FIFO_START_MASK);
}
void ArduCAM::clear_fifo_flag(void)
{
write_reg(ARDUCHIP_FIFO, FIFO_CLEAR_MASK);
}
uint32_t ArduCAM::read_fifo_length(void)
{
uint32_t len1, len2, len3, length = 0;
len1 = read_reg(FIFO_SIZE1);
len2 = read_reg(FIFO_SIZE2);
len3 = read_reg(FIFO_SIZE3) & 0x7f;
length = ((len3 << 16) | (len2 << 8) | len1) & 0x07fffff;
return length;
}
void ArduCAM::set_fifo_burst()
{
SPI.transfer(BURST_FIFO_READ);
}
void ArduCAM::CS_HIGH(void)
{
sbi(P_CS, B_CS);
}
void ArduCAM::CS_LOW(void)
{
cbi(P_CS, B_CS);
}
uint8_t ArduCAM::read_fifo(void)
{
uint8_t data;
data = bus_read(SINGLE_FIFO_READ);
return data;
}
uint8_t ArduCAM::read_reg(uint8_t addr)
{
uint8_t data;
data = bus_read(addr & 0x7F);
return data;
}
void ArduCAM::write_reg(uint8_t addr, uint8_t data)
{
bus_write(addr | 0x80, data);
}
// Set corresponding bit
void ArduCAM::set_bit(uint8_t addr, uint8_t bit)
{
uint8_t temp;
temp = read_reg(addr);
write_reg(addr, temp | bit);
}
// Clear corresponding bit
void ArduCAM::clear_bit(uint8_t addr, uint8_t bit)
{
uint8_t temp;
temp = read_reg(addr);
write_reg(addr, temp & (~bit));
}
// Get corresponding bit status
uint8_t ArduCAM::get_bit(uint8_t addr, uint8_t bit)
{
uint8_t temp;
temp = read_reg(addr);
temp = temp & bit;
return temp;
}
// Set ArduCAM working mode
// MCU2LCD_MODE: MCU writes the LCD screen GRAM
// CAM2LCD_MODE: Camera takes control of the LCD screen
// LCD2MCU_MODE: MCU read the LCD screen GRAM
void ArduCAM::set_mode(uint8_t mode)
{
switch (mode)
{
case MCU2LCD_MODE:
write_reg(ARDUCHIP_MODE, MCU2LCD_MODE);
break;
case CAM2LCD_MODE:
write_reg(ARDUCHIP_MODE, CAM2LCD_MODE);
break;
case LCD2MCU_MODE:
write_reg(ARDUCHIP_MODE, LCD2MCU_MODE);
break;
default:
write_reg(ARDUCHIP_MODE, MCU2LCD_MODE);
break;
}
}
uint8_t ArduCAM::bus_write(int address, int value)
{
cbi(P_CS, B_CS);
SPI.transfer(address);
SPI.transfer(value);
sbi(P_CS, B_CS);
return 1;
}
uint8_t ArduCAM::bus_read(int address)
{
uint8_t value;
cbi(P_CS, B_CS);
#if (defined(ESP8266) || defined(__arm__) || defined(TEENSYDUINO))
#if defined(OV5642_MINI_5MP)
SPI.transfer(address);
value = SPI.transfer(0x00);
// correction for bit rotation from readback
value = (byte)(value >> 1) | (value << 7);
// take the SS pin high to de-select the chip:
sbi(P_CS, B_CS);
return value;
#else
SPI.transfer(address);
value = SPI.transfer(0x00);
// take the SS pin high to de-select the chip:
sbi(P_CS, B_CS);
return value;
#endif
#else
SPI.transfer(address);
value = SPI.transfer(0x00);
// take the SS pin high to de-select the chip:
sbi(P_CS, B_CS);
return value;
#endif
}
void ArduCAM::OV2640_set_JPEG_size(uint8_t size)
{
#if (defined(OV2640_CAM) || defined(OV2640_MINI_2MP) || defined(OV2640_MINI_2MP_PLUS))
switch (size)
{
case OV2640_160x120:
wrSensorRegs8_8(OV2640_160x120_JPEG);
break;
case OV2640_176x144:
wrSensorRegs8_8(OV2640_176x144_JPEG);
break;
case OV2640_320x240:
wrSensorRegs8_8(OV2640_320x240_JPEG);
break;
case OV2640_352x288:
wrSensorRegs8_8(OV2640_352x288_JPEG);
break;
case OV2640_640x480:
wrSensorRegs8_8(OV2640_640x480_JPEG);
break;
case OV2640_800x600:
wrSensorRegs8_8(OV2640_800x600_JPEG);
break;
case OV2640_1024x768:
wrSensorRegs8_8(OV2640_1024x768_JPEG);
break;
case OV2640_1280x1024:
wrSensorRegs8_8(OV2640_1280x1024_JPEG);
break;
case OV2640_1600x1200:
wrSensorRegs8_8(OV2640_1600x1200_JPEG);
break;
default:
wrSensorRegs8_8(OV2640_320x240_JPEG);
break;
}
#endif
}
void ArduCAM::OV5642_set_RAW_size(uint8_t size)
{
#if defined(OV5642_CAM) || defined(OV5642_CAM_BIT_ROTATION_FIXED) || defined(OV5642_MINI_5MP) || defined(OV5642_MINI_5MP_PLUS)
switch (size)
{
case OV5642_640x480:
wrSensorRegs16_8(OV5642_1280x960_RAW);
wrSensorRegs16_8(OV5642_640x480_RAW);
break;
case OV5642_1280x960:
wrSensorRegs16_8(OV5642_1280x960_RAW);
break;
case OV5642_1920x1080:
wrSensorRegs16_8(ov5642_RAW);
wrSensorRegs16_8(OV5642_1920x1080_RAW);
break;
case OV5642_2592x1944:
wrSensorRegs16_8(ov5642_RAW);
break;
}
#endif
}
void ArduCAM::OV5642_set_JPEG_size(uint8_t size)
{
#if defined(OV5642_CAM) || defined(OV5642_CAM_BIT_ROTATION_FIXED) || defined(OV5642_MINI_5MP) || defined(OV5642_MINI_5MP_PLUS)
uint8_t reg_val;
switch (size)
{
case OV5642_320x240:
wrSensorRegs16_8(ov5642_320x240);
break;
case OV5642_640x480:
wrSensorRegs16_8(ov5642_640x480);
break;
case OV5642_1024x768:
wrSensorRegs16_8(ov5642_1024x768);
break;
case OV5642_1280x960:
wrSensorRegs16_8(ov5642_1280x960);
break;
case OV5642_1600x1200:
wrSensorRegs16_8(ov5642_1600x1200);
break;
case OV5642_2048x1536:
wrSensorRegs16_8(ov5642_2048x1536);
break;
case OV5642_2592x1944:
wrSensorRegs16_8(ov5642_2592x1944);
break;
default:
wrSensorRegs16_8(ov5642_320x240);
break;
}
#endif
}
void ArduCAM::OV5640_set_JPEG_size(uint8_t size)
{
#if (defined(OV5640_CAM) || defined(OV5640_MINI_5MP_PLUS))
switch (size)
{
case OV5640_320x240:
wrSensorRegs16_8(OV5640_QSXGA2QVGA);
break;
case OV5640_352x288:
wrSensorRegs16_8(OV5640_QSXGA2CIF);
break;
case OV5640_640x480:
wrSensorRegs16_8(OV5640_QSXGA2VGA);
break;
case OV5640_800x480:
wrSensorRegs16_8(OV5640_QSXGA2WVGA);
break;
case OV5640_1024x768:
wrSensorRegs16_8(OV5640_QSXGA2XGA);
break;
case OV5640_1280x960:
wrSensorRegs16_8(OV5640_QSXGA2SXGA);
break;
case OV5640_1600x1200:
wrSensorRegs16_8(OV5640_QSXGA2UXGA);
break;
case OV5640_2048x1536:
wrSensorRegs16_8(OV5640_QSXGA2QXGA);
break;
case OV5640_2592x1944:
wrSensorRegs16_8(OV5640_JPEG_QSXGA);
break;
default:
// 320x240
wrSensorRegs16_8(OV5640_QSXGA2QVGA);
break;
}
#endif
}
void ArduCAM::set_format(byte fmt)
{
if (fmt == BMP)
m_fmt = BMP;
else if (fmt == RAW)
m_fmt = RAW;
else
m_fmt = JPEG;
}
void ArduCAM::OV2640_set_Light_Mode(uint8_t Light_Mode)
{
#if (defined(OV2640_CAM) || defined(OV2640_MINI_2MP) || defined(OV2640_MINI_2MP_PLUS))
switch (Light_Mode)
{
case Auto:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0xc7, 0x00); // AWB on
break;
case Sunny:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0xc7, 0x40); // AWB off
wrSensorReg8_8(0xcc, 0x5e);
wrSensorReg8_8(0xcd, 0x41);
wrSensorReg8_8(0xce, 0x54);
break;
case Cloudy:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0xc7, 0x40); // AWB off
wrSensorReg8_8(0xcc, 0x65);
wrSensorReg8_8(0xcd, 0x41);
wrSensorReg8_8(0xce, 0x4f);
break;
case Office:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0xc7, 0x40); // AWB off
wrSensorReg8_8(0xcc, 0x52);
wrSensorReg8_8(0xcd, 0x41);
wrSensorReg8_8(0xce, 0x66);
break;
case Home:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0xc7, 0x40); // AWB off
wrSensorReg8_8(0xcc, 0x42);
wrSensorReg8_8(0xcd, 0x3f);
wrSensorReg8_8(0xce, 0x71);
break;
default:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0xc7, 0x00); // AWB on
break;
}
#endif
}
void ArduCAM::OV5642_set_Light_Mode(uint8_t Light_Mode)
{
#if defined(OV5642_CAM) || defined(OV5642_CAM_BIT_ROTATION_FIXED) || defined(OV5642_MINI_5MP) || defined(OV5642_MINI_5MP_PLUS)
switch (Light_Mode)
{
case Advanced_AWB:
wrSensorReg16_8(0x3406, 0x0);
wrSensorReg16_8(0x5192, 0x04);
wrSensorReg16_8(0x5191, 0xf8);
wrSensorReg16_8(0x518d, 0x26);
wrSensorReg16_8(0x518f, 0x42);
wrSensorReg16_8(0x518e, 0x2b);
wrSensorReg16_8(0x5190, 0x42);
wrSensorReg16_8(0x518b, 0xd0);
wrSensorReg16_8(0x518c, 0xbd);
wrSensorReg16_8(0x5187, 0x18);
wrSensorReg16_8(0x5188, 0x18);
wrSensorReg16_8(0x5189, 0x56);
wrSensorReg16_8(0x518a, 0x5c);
wrSensorReg16_8(0x5186, 0x1c);
wrSensorReg16_8(0x5181, 0x50);
wrSensorReg16_8(0x5184, 0x20);
wrSensorReg16_8(0x5182, 0x11);
wrSensorReg16_8(0x5183, 0x0);
break;
case Simple_AWB:
wrSensorReg16_8(0x3406, 0x00);
wrSensorReg16_8(0x5183, 0x80);
wrSensorReg16_8(0x5191, 0xff);
wrSensorReg16_8(0x5192, 0x00);
break;
case Manual_day:
wrSensorReg16_8(0x3406, 0x1);
wrSensorReg16_8(0x3400, 0x7);
wrSensorReg16_8(0x3401, 0x32);
wrSensorReg16_8(0x3402, 0x4);
wrSensorReg16_8(0x3403, 0x0);
wrSensorReg16_8(0x3404, 0x5);
wrSensorReg16_8(0x3405, 0x36);
break;
case Manual_A:
wrSensorReg16_8(0x3406, 0x1);
wrSensorReg16_8(0x3400, 0x4);
wrSensorReg16_8(0x3401, 0x88);
wrSensorReg16_8(0x3402, 0x4);
wrSensorReg16_8(0x3403, 0x0);
wrSensorReg16_8(0x3404, 0x8);
wrSensorReg16_8(0x3405, 0xb6);
break;
case Manual_cwf:
wrSensorReg16_8(0x3406, 0x1);
wrSensorReg16_8(0x3400, 0x6);
wrSensorReg16_8(0x3401, 0x13);
wrSensorReg16_8(0x3402, 0x4);
wrSensorReg16_8(0x3403, 0x0);
wrSensorReg16_8(0x3404, 0x7);
wrSensorReg16_8(0x3405, 0xe2);
break;
case Manual_cloudy:
wrSensorReg16_8(0x3406, 0x1);
wrSensorReg16_8(0x3400, 0x7);
wrSensorReg16_8(0x3401, 0x88);
wrSensorReg16_8(0x3402, 0x4);
wrSensorReg16_8(0x3403, 0x0);
wrSensorReg16_8(0x3404, 0x5);
wrSensorReg16_8(0x3405, 0x0);
break;
default:
break;
}
#endif
}
void ArduCAM::OV5640_set_Light_Mode(uint8_t Light_Mode)
{
#if (defined(OV5640_CAM) || defined(OV5640_MINI_5MP_PLUS))
switch (Light_Mode)
{
case Auto:
wrSensorReg16_8(0x3212, 0x03); // start group 3
wrSensorReg16_8(0x3406, 0x00);
wrSensorReg16_8(0x3400, 0x04);
wrSensorReg16_8(0x3401, 0x00);
wrSensorReg16_8(0x3402, 0x04);
wrSensorReg16_8(0x3403, 0x00);
wrSensorReg16_8(0x3404, 0x04);
wrSensorReg16_8(0x3405, 0x00);
wrSensorReg16_8(0x3212, 0x13); // end group 3
wrSensorReg16_8(0x3212, 0xa3); // lanuch group 3
wrSensorReg16_8(0x5183, 0x0);
break;
case Sunny:
wrSensorReg16_8(0x3212, 0x03); // start group 3
wrSensorReg16_8(0x3406, 0x01);
wrSensorReg16_8(0x3400, 0x06);
wrSensorReg16_8(0x3401, 0x1c);
wrSensorReg16_8(0x3402, 0x04);
wrSensorReg16_8(0x3403, 0x00);
wrSensorReg16_8(0x3404, 0x04);
wrSensorReg16_8(0x3405, 0xf3);
wrSensorReg16_8(0x3212, 0x13); // end group 3
wrSensorReg16_8(0x3212, 0xa3); // lanuch group 3
break;
case Office:
wrSensorReg16_8(0x3212, 0x03); // start group 3
wrSensorReg16_8(0x3406, 0x01);
wrSensorReg16_8(0x3400, 0x05);
wrSensorReg16_8(0x3401, 0x48);
wrSensorReg16_8(0x3402, 0x04);
wrSensorReg16_8(0x3403, 0x00);
wrSensorReg16_8(0x3404, 0x07);
wrSensorReg16_8(0x3405, 0xcf);
wrSensorReg16_8(0x3212, 0x13); // end group 3
wrSensorReg16_8(0x3212, 0xa3); // lanuch group 3
wrSensorReg16_8(0x3212, 0x03); // start group 3
wrSensorReg16_8(0x3406, 0x01);
wrSensorReg16_8(0x3400, 0x06);
wrSensorReg16_8(0x3401, 0x48);
wrSensorReg16_8(0x3402, 0x04);
wrSensorReg16_8(0x3403, 0x00);
wrSensorReg16_8(0x3404, 0x04);
wrSensorReg16_8(0x3405, 0xd3);
wrSensorReg16_8(0x3212, 0x13); // end group 3
wrSensorReg16_8(0x3212, 0xa3); // lanuch group 3
break;
case Cloudy:
wrSensorReg16_8(0x3212, 0x03); // start group 3
wrSensorReg16_8(0x3406, 0x01);
wrSensorReg16_8(0x3400, 0x06);
wrSensorReg16_8(0x3401, 0x48);
wrSensorReg16_8(0x3402, 0x04);
wrSensorReg16_8(0x3403, 0x00);
wrSensorReg16_8(0x3404, 0x04);
wrSensorReg16_8(0x3405, 0xd3);
wrSensorReg16_8(0x3212, 0x13); // end group 3
wrSensorReg16_8(0x3212, 0xa3); // lanuch group 3
break;
case Home:
wrSensorReg16_8(0x3212, 0x03); // start group 3
wrSensorReg16_8(0x3406, 0x01);
wrSensorReg16_8(0x3400, 0x04);
wrSensorReg16_8(0x3401, 0x10);
wrSensorReg16_8(0x3402, 0x04);
wrSensorReg16_8(0x3403, 0x00);
wrSensorReg16_8(0x3404, 0x08);
wrSensorReg16_8(0x3405, 0x40);
wrSensorReg16_8(0x3212, 0x13); // end group 3
wrSensorReg16_8(0x3212, 0xa3); // lanuch group 3
break;
default:
break;
}
#endif
}
void ArduCAM::OV2640_set_Color_Saturation(uint8_t Color_Saturation)
{
#if (defined(OV2640_CAM) || defined(OV2640_MINI_2MP) || defined(OV2640_MINI_2MP_PLUS))
switch (Color_Saturation)
{
case Saturation2:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0x7c, 0x00);
wrSensorReg8_8(0x7d, 0x02);
wrSensorReg8_8(0x7c, 0x03);
wrSensorReg8_8(0x7d, 0x68);
wrSensorReg8_8(0x7d, 0x68);
break;
case Saturation1:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0x7c, 0x00);
wrSensorReg8_8(0x7d, 0x02);
wrSensorReg8_8(0x7c, 0x03);
wrSensorReg8_8(0x7d, 0x58);
wrSensorReg8_8(0x7d, 0x58);
break;
case Saturation0:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0x7c, 0x00);
wrSensorReg8_8(0x7d, 0x02);
wrSensorReg8_8(0x7c, 0x03);
wrSensorReg8_8(0x7d, 0x48);
wrSensorReg8_8(0x7d, 0x48);
break;
case Saturation_1:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0x7c, 0x00);
wrSensorReg8_8(0x7d, 0x02);
wrSensorReg8_8(0x7c, 0x03);
wrSensorReg8_8(0x7d, 0x38);
wrSensorReg8_8(0x7d, 0x38);
break;
case Saturation_2:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0x7c, 0x00);
wrSensorReg8_8(0x7d, 0x02);
wrSensorReg8_8(0x7c, 0x03);
wrSensorReg8_8(0x7d, 0x28);
wrSensorReg8_8(0x7d, 0x28);
break;
}
#endif
}
void ArduCAM::OV5640_set_Color_Saturation(uint8_t Color_Saturation)
{
#if (defined(OV5640_CAM) || defined(OV5640_MINI_5MP_PLUS))
switch (Color_Saturation)
{
case Saturation3:
wrSensorReg16_8(0x3212, 0x03); // start group 3
wrSensorReg16_8(0x5381, 0x1c);
wrSensorReg16_8(0x5382, 0x5a);
wrSensorReg16_8(0x5383, 0x06);
wrSensorReg16_8(0x5384, 0x2b);
wrSensorReg16_8(0x5385, 0xab);
wrSensorReg16_8(0x5386, 0xd6);
wrSensorReg16_8(0x5387, 0xda);
wrSensorReg16_8(0x5388, 0xd6);
wrSensorReg16_8(0x5389, 0x04);
wrSensorReg16_8(0x538b, 0x98);
wrSensorReg16_8(0x538a, 0x01);
wrSensorReg16_8(0x3212, 0x13); // end group 3
wrSensorReg16_8(0x3212, 0xa3); // launch group 3
break;
case Saturation2:
wrSensorReg16_8(0x3212, 0x03); // start group 3
wrSensorReg16_8(0x5381, 0x1c);
wrSensorReg16_8(0x5382, 0x5a);
wrSensorReg16_8(0x5383, 0x06);
wrSensorReg16_8(0x5384, 0x24);
wrSensorReg16_8(0x5385, 0x8f);
wrSensorReg16_8(0x5386, 0xb3);
wrSensorReg16_8(0x5387, 0xb6);
wrSensorReg16_8(0x5388, 0xb3);
wrSensorReg16_8(0x5389, 0x03);
wrSensorReg16_8(0x538b, 0x98);
wrSensorReg16_8(0x538a, 0x01);
wrSensorReg16_8(0x3212, 0x13); // end group 3
wrSensorReg16_8(0x3212, 0xa3); // launch group 3
break;
case Saturation1:
wrSensorReg16_8(0x3212, 0x03); // start group 3
wrSensorReg16_8(0x5381, 0x1c);
wrSensorReg16_8(0x5382, 0x5a);
wrSensorReg16_8(0x5383, 0x06);
wrSensorReg16_8(0x5384, 0x1f);
wrSensorReg16_8(0x5385, 0x7a);
wrSensorReg16_8(0x5386, 0x9a);
wrSensorReg16_8(0x5387, 0x9c);
wrSensorReg16_8(0x5388, 0x9a);
wrSensorReg16_8(0x5389, 0x02);
wrSensorReg16_8(0x538b, 0x98);
wrSensorReg16_8(0x538a, 0x01);
wrSensorReg16_8(0x3212, 0x13); // end group 3
wrSensorReg16_8(0x3212, 0xa3); // launch group 3
break;
case Saturation0:
wrSensorReg16_8(0x3212, 0x03); // start group 3
wrSensorReg16_8(0x5381, 0x1c);
wrSensorReg16_8(0x5382, 0x5a);
wrSensorReg16_8(0x5383, 0x06);
wrSensorReg16_8(0x5384, 0x1a);
wrSensorReg16_8(0x5385, 0x66);
wrSensorReg16_8(0x5386, 0x80);
wrSensorReg16_8(0x5387, 0x82);
wrSensorReg16_8(0x5388, 0x80);
wrSensorReg16_8(0x5389, 0x02);
wrSensorReg16_8(0x538b, 0x98);
wrSensorReg16_8(0x538a, 0x01);
wrSensorReg16_8(0x3212, 0x13); // end group 3
wrSensorReg16_8(0x3212, 0xa3); // launch group 3
break;
case Saturation_1:
wrSensorReg16_8(0x3212, 0x03); // start group 3
wrSensorReg16_8(0x5381, 0x1c);
wrSensorReg16_8(0x5382, 0x5a);
wrSensorReg16_8(0x5383, 0x06);
wrSensorReg16_8(0x5384, 0x15);
wrSensorReg16_8(0x5385, 0x52);
wrSensorReg16_8(0x5386, 0x66);
wrSensorReg16_8(0x5387, 0x68);
wrSensorReg16_8(0x5388, 0x66);
wrSensorReg16_8(0x5389, 0x02);
wrSensorReg16_8(0x538b, 0x98);
wrSensorReg16_8(0x538a, 0x01);
wrSensorReg16_8(0x3212, 0x13); // end group 3
wrSensorReg16_8(0x3212, 0xa3); // launch group 3
break;
case Saturation_2:
wrSensorReg16_8(0x3212, 0x03); // start group 3
wrSensorReg16_8(0x5381, 0x1c);
wrSensorReg16_8(0x5382, 0x5a);
wrSensorReg16_8(0x5383, 0x06);
wrSensorReg16_8(0x5384, 0x10);
wrSensorReg16_8(0x5385, 0x3d);
wrSensorReg16_8(0x5386, 0x4d);
wrSensorReg16_8(0x5387, 0x4e);
wrSensorReg16_8(0x5388, 0x4d);
wrSensorReg16_8(0x5389, 0x01);
wrSensorReg16_8(0x538b, 0x98);
wrSensorReg16_8(0x538a, 0x01);
wrSensorReg16_8(0x3212, 0x13); // end group 3
wrSensorReg16_8(0x3212, 0xa3); // launch group 3
break;
case Saturation_3:
wrSensorReg16_8(0x3212, 0x03); // start group 3
wrSensorReg16_8(0x5381, 0x1c);
wrSensorReg16_8(0x5382, 0x5a);
wrSensorReg16_8(0x5383, 0x06);
wrSensorReg16_8(0x5384, 0x0c);
wrSensorReg16_8(0x5385, 0x30);
wrSensorReg16_8(0x5386, 0x3d);
wrSensorReg16_8(0x5387, 0x3e);
wrSensorReg16_8(0x5388, 0x3d);
wrSensorReg16_8(0x5389, 0x01);
wrSensorReg16_8(0x538b, 0x98);
wrSensorReg16_8(0x538a, 0x01);
wrSensorReg16_8(0x3212, 0x13); // end group 3
wrSensorReg16_8(0x3212, 0xa3); // launch group 3
break;
}
#endif
}
void ArduCAM::OV5642_set_Color_Saturation(uint8_t Color_Saturation)
{
#if defined(OV5642_CAM) || defined(OV5642_CAM_BIT_ROTATION_FIXED) || defined(OV5642_MINI_5MP) || defined(OV5642_MINI_5MP_PLUS)
switch (Color_Saturation)
{
case Saturation4:
wrSensorReg16_8(0x5001, 0xff);
wrSensorReg16_8(0x5583, 0x80);
wrSensorReg16_8(0x5584, 0x80);
wrSensorReg16_8(0x5580, 0x02);
break;
case Saturation3:
wrSensorReg16_8(0x5001, 0xff);
wrSensorReg16_8(0x5583, 0x70);
wrSensorReg16_8(0x5584, 0x70);
wrSensorReg16_8(0x5580, 0x02);
break;
case Saturation2:
wrSensorReg16_8(0x5001, 0xff);
wrSensorReg16_8(0x5583, 0x60);
wrSensorReg16_8(0x5584, 0x60);
wrSensorReg16_8(0x5580, 0x02);
break;
case Saturation1:
wrSensorReg16_8(0x5001, 0xff);
wrSensorReg16_8(0x5583, 0x50);
wrSensorReg16_8(0x5584, 0x50);
wrSensorReg16_8(0x5580, 0x02);
break;
case Saturation0:
wrSensorReg16_8(0x5001, 0xff);
wrSensorReg16_8(0x5583, 0x40);
wrSensorReg16_8(0x5584, 0x40);
wrSensorReg16_8(0x5580, 0x02);
break;
case Saturation_1:
wrSensorReg16_8(0x5001, 0xff);
wrSensorReg16_8(0x5583, 0x30);
wrSensorReg16_8(0x5584, 0x30);
wrSensorReg16_8(0x5580, 0x02);
break;
case Saturation_2:
wrSensorReg16_8(0x5001, 0xff);
wrSensorReg16_8(0x5583, 0x20);
wrSensorReg16_8(0x5584, 0x20);
wrSensorReg16_8(0x5580, 0x02);
break;
case Saturation_3:
wrSensorReg16_8(0x5001, 0xff);
wrSensorReg16_8(0x5583, 0x10);
wrSensorReg16_8(0x5584, 0x10);
wrSensorReg16_8(0x5580, 0x02);
break;
case Saturation_4:
wrSensorReg16_8(0x5001, 0xff);
wrSensorReg16_8(0x5583, 0x00);
wrSensorReg16_8(0x5584, 0x00);
wrSensorReg16_8(0x5580, 0x02);
break;
}
#endif
}
void ArduCAM::OV2640_set_Brightness(uint8_t Brightness)
{
#if (defined(OV2640_CAM) || defined(OV2640_MINI_2MP) || defined(OV2640_MINI_2MP_PLUS))
switch (Brightness)
{
case Brightness2:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0x7c, 0x00);
wrSensorReg8_8(0x7d, 0x04);
wrSensorReg8_8(0x7c, 0x09);
wrSensorReg8_8(0x7d, 0x40);
wrSensorReg8_8(0x7d, 0x00);
break;
case Brightness1:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0x7c, 0x00);
wrSensorReg8_8(0x7d, 0x04);
wrSensorReg8_8(0x7c, 0x09);
wrSensorReg8_8(0x7d, 0x30);
wrSensorReg8_8(0x7d, 0x00);
break;
case Brightness0:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0x7c, 0x00);
wrSensorReg8_8(0x7d, 0x04);
wrSensorReg8_8(0x7c, 0x09);
wrSensorReg8_8(0x7d, 0x20);
wrSensorReg8_8(0x7d, 0x00);
break;
case Brightness_1:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0x7c, 0x00);
wrSensorReg8_8(0x7d, 0x04);
wrSensorReg8_8(0x7c, 0x09);
wrSensorReg8_8(0x7d, 0x10);
wrSensorReg8_8(0x7d, 0x00);
break;
case Brightness_2:
wrSensorReg8_8(0xff, 0x00);
wrSensorReg8_8(0x7c, 0x00);
wrSensorReg8_8(0x7d, 0x04);