forked from CoreElectronics/CE-Arducam-MicroPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.py
More file actions
646 lines (497 loc) · 20.1 KB
/
Copy pathcamera.py
File metadata and controls
646 lines (497 loc) · 20.1 KB
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
from utime import sleep_ms
import utime
import uos
import ujson
'''
Start this alongside the camera module to save photos in a folder with a filename i.e. image-<counter>.jpg
* appends '_' after a word, the next number and the file format
'''
class FileManager:
def __init__(self, file_manager_name='filemanager.log'):
self.FILE_MANAGER_LOG_NAME = file_manager_name
self.last_request_filename = None
self.suffix = None
count = 0
file_dict = {}
# Ensure file is present
if self.FILE_MANAGER_LOG_NAME not in uos.listdir():
with open(self.FILE_MANAGER_LOG_NAME, 'w') as f:
f.write(ujson.dumps(file_dict))
# Check if the filename already exists in the storage
with open(self.FILE_MANAGER_LOG_NAME, 'r') as f:
self.file_dict = ujson.loads(f.read())
def new_jpg_fn(self, requested_filename=None):
return (self.new_filename(requested_filename) + '.jpg')
# def new_fn_custom(self, suffix, requested_filename=None, suffix):
# return (self.new_filename(requested_filename) + suffix)
def new_filename(self, requested_filename):
count = 0
self.last_request_filename = requested_filename
if requested_filename == None and self.last_request_filename == None:
raise Exception('Please enter a filename for the first use of the function')
if requested_filename in self.file_dict:
count = self.file_dict[requested_filename] + 1
self.file_dict[requested_filename] = count
self.save_manager_file()
new_filename = f"{requested_filename}_{count}" if count > 0 else f"{requested_filename}"
return new_filename
def save_manager_file(self):
# Save the updated list back to the storage
with open(self.FILE_MANAGER_LOG_NAME, 'w') as f:
f.write(ujson.dumps(self.file_dict))
class Camera:
# Required imports
### Register definitions
## For camera Reset
CAM_REG_SENSOR_RESET = 0x07
CAM_SENSOR_RESET_ENABLE = 0x40
## For get_sensor_config
CAM_REG_SENSOR_ID = 0x40
SENSOR_5MP_1 = 0x81
SENSOR_3MP_1 = 0x82
SENSOR_5MP_2 = 0x83
SENSOR_3MP_2 = 0x84
## Camera effect control
# Set Colour Effect
CAM_REG_COLOR_EFFECT_CONTROL = 0x27
SPECIAL_NORMAL = 0x00
SPECIAL_COOL = 1
SPECIAL_WARM = 2
SPECIAL_BW = 0x04
SPECIAL_YELLOWING = 4
SPECIAL_REVERSE = 5
SPECIAL_GREENISH = 6
SPECIAL_LIGHT_YELLOW = 9 # 3MP Only
# Set Brightness
CAM_REG_BRIGHTNESS_CONTROL = 0X22
BRIGHTNESS_MINUS_4 = 8
BRIGHTNESS_MINUS_3 = 6
BRIGHTNESS_MINUS_2 = 4
BRIGHTNESS_MINUS_1 = 2
BRIGHTNESS_DEFAULT = 0
BRIGHTNESS_PLUS_1 = 1
BRIGHTNESS_PLUS_2 = 3
BRIGHTNESS_PLUS_3 = 5
BRIGHTNESS_PLUS_4 = 7
# Set Contrast
CAM_REG_CONTRAST_CONTROL = 0X23
CONTRAST_MINUS_3 = 6
CONTRAST_MINUS_2 = 4
CONTRAST_MINUS_1 = 2
CONTRAST_DEFAULT = 0
CONTRAST_PLUS_1 = 1
CONTRAST_PLUS_2 = 3
CONTRAST_PLUS_3 = 5
# Set Saturation
CAM_REG_SATURATION_CONTROL = 0X24
SATURATION_MINUS_3 = 6
SATURATION_MINUS_2 = 4
SATURATION_MINUS_1 = 2
SATURATION_DEFAULT = 0
SATURATION_PLUS_1 = 1
SATURATION_PLUS_2 = 3
SATURATION_PLUS_3 = 5
# Set Exposure Value
CAM_REG_EXPOSURE_CONTROL = 0X25
EXPOSURE_MINUS_3 = 6
EXPOSURE_MINUS_2 = 4
EXPOSURE_MINUS_1 = 2
EXPOSURE_DEFAULT = 0
EXPOSURE_PLUS_1 = 1
EXPOSURE_PLUS_2 = 3
EXPOSURE_PLUS_3 = 5
# Set Whitebalance
CAM_REG_WB_MODE_CONTROL = 0X26
WB_MODE_AUTO = 0
WB_MODE_SUNNY = 1
WB_MODE_OFFICE = 2
WB_MODE_CLOUDY = 3
WB_MODE_HOME = 4
# Set Sharpness
CAM_REG_SHARPNESS_CONTROL = 0X28 #3MP only
SHARPNESS_NORMAL = 0
SHARPNESS_1 = 1
SHARPNESS_2 = 2
SHARPNESS_3 = 3
SHARPNESS_4 = 4
SHARPNESS_5 = 5
SHARPNESS_6 = 6
SHARPNESS_7 = 7
SHARPNESS_8 = 8
# Set Autofocus
CAM_REG_AUTO_FOCUS_CONTROL = 0X29 #5MP only
# Set Image quality
CAM_REG_IMAGE_QUALITY = 0x2A
IMAGE_QUALITY_HIGH = 0
IMAGE_QUALITY_MEDI = 1
IMAGE_QUALITY_LOW = 2
# Manual gain, and exposure are explored in the datasheet - https://www.arducam.com/downloads/datasheet/Arducam_MEGA_SPI_Camera_Application_Note.pdf
# Device addressing
CAM_REG_DEBUG_DEVICE_ADDRESS = 0x0A
deviceAddress = 0x78
# For Waiting
CAM_REG_SENSOR_STATE = 0x44
CAM_REG_SENSOR_STATE_IDLE = 0x01
# Setup for capturing photos
CAM_REG_FORMAT = 0x20
CAM_IMAGE_PIX_FMT_JPG = 0x01
CAM_IMAGE_PIX_FMT_RGB565 = 0x02
CAM_IMAGE_PIX_FMT_YUV = 0x03
# Resolution settings
CAM_REG_CAPTURE_RESOLUTION = 0x21
# Some resolutions are not available - refer to datasheet https://www.arducam.com/downloads/datasheet/Arducam_MEGA_SPI_Camera_Application_Note.pdf
# RESOLUTION_160X120 = 0X00
RESOLUTION_320X240 = 0X01
RESOLUTION_640X480 = 0X02
# RESOLUTION_800X600 = 0X03
RESOLUTION_1280X720 = 0X04
# RESOLUTION_1280X960 = 0X05
RESOLUTION_1600X1200 = 0X06
RESOLUTION_1920X1080 = 0X07
RESOLUTION_2048X1536 = 0X08 # 3MP only
RESOLUTION_2592X1944 = 0X09 # 5MP only
RESOLUTION_96X96 = 0X0a
RESOLUTION_128X128 = 0X0b
RESOLUTION_320X320 = 0X0c
valid_3mp_resolutions = {
'320x240': RESOLUTION_320X240,
'640x480': RESOLUTION_640X480,
'1280x720': RESOLUTION_1280X720,
'1600x1200': RESOLUTION_1600X1200,
'1920x1080': RESOLUTION_1920X1080,
'2048x1536': RESOLUTION_2048X1536,
'96X96': RESOLUTION_96X96,
'128X128': RESOLUTION_128X128,
'320X320': RESOLUTION_320X320
}
valid_5mp_resolutions = {
'320x240': RESOLUTION_320X240,
'640x480': RESOLUTION_640X480,
'1280x720': RESOLUTION_1280X720,
'1600x1200': RESOLUTION_1600X1200,
'1920x1080': RESOLUTION_1920X1080,
'2592x1944': RESOLUTION_2592X1944,
'96X96': RESOLUTION_96X96,
'128X128': RESOLUTION_128X128,
'320X320': RESOLUTION_320X320
}
# FIFO and State setting registers
ARDUCHIP_FIFO = 0x04
FIFO_CLEAR_ID_MASK = 0x01
FIFO_START_MASK = 0x02
ARDUCHIP_TRIG = 0x44
CAP_DONE_MASK = 0x04
FIFO_SIZE1 = 0x45
FIFO_SIZE2 = 0x46
FIFO_SIZE3 = 0x47
SINGLE_FIFO_READ = 0x3D
BURST_FIFO_READ = 0X3C
# Size of image_buffer (Burst reading)
BUFFER_MAX_LENGTH = 255
# For 5MP startup routine
WHITE_BALANCE_WAIT_TIME_MS = 500
# User callable functions
## Main functions
## Setting functions
# Internal functions
## High level internal functions
## Low level
##################### Callable FUNCTIONS #####################
########### CORE PHOTO FUNCTIONS ###########
def __init__(self, spi_bus, cs, skip_sleep=False, debug_information=False):
self.cs = cs
self.spi_bus = spi_bus
self._write_reg(self.CAM_REG_SENSOR_RESET, self.CAM_SENSOR_RESET_ENABLE) # Reset camera
self._wait_idle()
self._get_sensor_config() # Get camera sensor information
self._wait_idle()
self._write_reg(self.CAM_REG_DEBUG_DEVICE_ADDRESS, self.deviceAddress)
self._wait_idle()
self.run_start_up_config = True
# Set default format and resolution
self.current_pixel_format = self.CAM_IMAGE_PIX_FMT_JPG
self.old_pixel_format = self.current_pixel_format
self.current_resolution_setting = self.RESOLUTION_640X480 # ArduCam driver defines this as mode
self.old_resolution = self.current_resolution_setting
self.set_filter(self.SPECIAL_NORMAL)
self.received_length = 0
self.total_length = 0
# Burst setup
self.first_burst_run = False
self.image_buffer = bytearray(self.BUFFER_MAX_LENGTH)
self.valid_image_buffer = 0
self.camera_idx = 'NOT DETECTED'
# Tracks the AWB warmup time
self.start_time = utime.ticks_ms()
if debug_information:
print('Camera version =', self.camera_idx)
if self.camera_idx == '3MP':
self.startup_routine_3MP()
if self.camera_idx == '5MP' and skip_sleep == False:
utime.sleep_ms(self.WHITE_BALANCE_WAIT_TIME_MS)
def startup_routine_3MP(self):
# Leave the shutter open for some time seconds (i.e. take a few photos without saving)
print('Running 3MP startup routine')
self.capture_jpg()
self.saveJPG('dummy_image.jpg')
uos.remove('dummy_image.jpg')
print('complete')
'''
Issue warning if the filepath doesnt end in .jpg (Blank) and append
Issue error if the filetype is NOT .jpg
'''
def capture_jpg(self):
if (utime.ticks_diff(utime.ticks_ms(), self.start_time) <= self.WHITE_BALANCE_WAIT_TIME_MS) and self.camera_idx == '5MP':
print('Please add a ', self.WHITE_BALANCE_WAIT_TIME_MS, 'ms delay to allow for white balance to run')
else:
# print('Starting capture JPG')
# JPG, bmp ect
# TODO: PROPERTIES TO CONFIGURE THE PIXEL FORMAT
if (self.old_pixel_format != self.current_pixel_format) or self.run_start_up_config:
self.old_pixel_format = self.current_pixel_format
self._write_reg(self.CAM_REG_FORMAT, self.current_pixel_format) # Set to capture a jpg
self._wait_idle()
# print('old',self.old_resolution,'new',self.current_resolution_setting)
# TODO: PROPERTIES TO CONFIGURE THE RESOLUTION
if (self.old_resolution != self.current_resolution_setting) or self.run_start_up_config:
self.old_resolution = self.current_resolution_setting
self._write_reg(self.CAM_REG_CAPTURE_RESOLUTION, self.current_resolution_setting)
# print('setting res', self.current_resolution_setting)
self._wait_idle()
self.run_start_up_config = False
# Start capturing the photo
self._set_capture()
# print('capture jpg complete')
# TODO: After reading the camera data clear the FIFO and reset the camera (so that the first time read can be used)
def saveJPG(self,filename):
headflag = 0
print('Saving image, please dont remove power')
# print('rec len:', self.received_length)
image_data = 0x00
image_data_next = 0x00
image_data_int = 0x00
image_data_next_int = 0x00
print(self.received_length)
while(self.received_length):
image_data = image_data_next
image_data_int = image_data_next_int
image_data_next = self._read_byte()
image_data_next_int = int.from_bytes(image_data_next, 1) # TODO: CHANGE TO READ n BYTES
if headflag == 1:
jpg_to_write.write(image_data_next)
if (image_data_int == 0xff) and (image_data_next_int == 0xd8):
# TODO: Save file to filename
# print('start of file')
headflag = 1
jpg_to_write = open(filename,'ab')
jpg_to_write.write(image_data)
jpg_to_write.write(image_data_next)
if (image_data_int == 0xff) and (image_data_next_int == 0xd9):
# print('TODO: Save and close file?')
headflag = 0
jpg_to_write.write(image_data_next)
jpg_to_write.close()
def save_JPG_burst(self):
headflag = 0
print('Saving image, please dont remove power')
image_data = 0x00
image_data_next = 0x00
image_data_int = 0x00
image_data_next_int = 0x00
print(self.received_length)
while(self.received_length):
self._burst_read_FIFO()
start_bytes = self.image_buffer[0]
end_bytes = self.image_buffer[self.valid_image_buffer-1]
# def _read_byte(self):
# self.cs.off()
# self.spi_bus.write(bytes([self.SINGLE_FIFO_READ]))
# data = self.spi_bus.read(1)
# data = self.spi_bus.read(1)
# self.cs.on()
# self.received_length -= 1
# return data
def _burst_read_FIFO(self):
#compute how many bytes to read
burst_read_length = self.BUFFER_MAX_LENGTH # Default to max length
if self.received_length < self.BUFFER_MAX_LENGTH:
burst_read_length = self.received_length
current_buffer_byte = 0
self.cs.off()
self.spi_bus.write(bytes([self.BURST_FIFO_READ]))
data = self.spi_bus.read(1)
# Throw away first byte on first read
if self.first_burst_fifo == True:
self.image_buffer[current_buffer_byte] = data
current_buffer_byte += 1
burst_read_length -= 1
print('first burst read')
while burst_read_length:
data = self.spi_bus.read(1) # Read from camera
self.image_buffer[current_buffer_byte] = data # write to buffer
current_buffer_byte += 1
burst_read_length -= 1
self.cs.on()
self.received_length -= burst_read_length
self.valid_image_buffer = burst_read_length
@property
def resolution(self):
return self.current_resolution_setting
@resolution.setter
def resolution(self, new_resolution):
input_string_lower = new_resolution.lower()
if self.camera_idx == '3MP':
if input_string_lower in self.valid_3mp_resolutions:
self.current_resolution_setting = self.valid_5mp_resolutions[input_string_lower]
else:
raise ValueError("Invalid resolution provided for {}, please select from {}".format(self.camera_idx, list(self.valid_3mp_resolutions.keys())))
elif self.camera_idx == '5MP':
if input_string_lower in self.valid_5mp_resolutions:
self.current_resolution_setting = self.valid_5mp_resolutions[input_string_lower]
else:
raise ValueError("Invalid resolution provided for {}, please select from {}".format(self.camera_idx, list(self.valid_5mp_resolutions.keys())))
def set_pixel_format(self, new_pixel_format):
self.current_pixel_format = new_pixel_format
########### ACCSESSORY FUNCTIONS ###########
# TODO: Complete for other camera settings
# Make these setters - https://github.com/CoreElectronics/CE-PiicoDev-Accelerometer-LIS3DH-MicroPython-Module/blob/abcb4337020434af010f2325b061e694b808316d/PiicoDev_LIS3DH.py#L118C1-L118C1
# # Set Brightness
# CAM_REG_BRIGHTNESS_CONTROL = 0X22
#
# BRIGHTNESS_MINUS_4 = 8
# BRIGHTNESS_MINUS_3 = 6
# BRIGHTNESS_MINUS_2 = 4
# BRIGHTNESS_MINUS_1 = 2
# BRIGHTNESS_DEFAULT = 0
# BRIGHTNESS_PLUS_1 = 1
# BRIGHTNESS_PLUS_2 = 3
# BRIGHTNESS_PLUS_3 = 5
# BRIGHTNESS_PLUS_4 = 7
def set_brightness_level(self, brightness):
self._write_reg(self.CAM_REG_BRIGHTNESS_CONTROL, brightness)
self._wait_idle()
def set_filter(self, effect):
self._write_reg(self.CAM_REG_COLOR_EFFECT_CONTROL, effect)
self._wait_idle()
# # Set Saturation
# CAM_REG_SATURATION_CONTROL = 0X24
#
# SATURATION_MINUS_3 = 6
# SATURATION_MINUS_2 = 4
# SATURATION_MINUS_1 = 2
# SATURATION_DEFAULT = 0
# SATURATION_PLUS_1 = 1
# SATURATION_PLUS_2 = 3
# SATURATION_PLUS_3 = 5
def set_saturation_control(self, saturation_value):
self._write_reg(self.CAM_REG_SATURATION_CONTROL, saturation_value)
self._wait_idle()
# # Set Exposure Value
# CAM_REG_EXPOSURE_CONTROL = 0X25
#
# EXPOSURE_MINUS_3 = 6
# EXPOSURE_MINUS_2 = 4
# EXPOSURE_MINUS_1 = 2
# EXPOSURE_DEFAULT = 0
# EXPOSURE_PLUS_1 = 1
# EXPOSURE_PLUS_2 = 3
# EXPOSURE_PLUS_3 = 5
# # Set Contrast
# CAM_REG_CONTRAST_CONTROL = 0X23
#
# CONTRAST_MINUS_3 = 6
# CONTRAST_MINUS_2 = 4
# CONTRAST_MINUS_1 = 2
# CONTRAST_DEFAULT = 0
# CONTRAST_PLUS_1 = 1
# CONTRAST_PLUS_2 = 3
# CONTRAST_PLUS_3 = 5
def set_contrast(self, contrast):
self._write_reg(self.CAM_REG_CONTRAST_CONTROL, contrast)
self._wait_idle()
def set_white_balance(self, environment):
register_value = self.WB_MODE_AUTO
if environment == 'sunny':
register_value = self.WB_MODE_SUNNY
elif environment == 'office':
register_value = self.WB_MODE_OFFICE
elif environment == 'cloudy':
register_value = self.WB_MODE_CLOUDY
elif environment == 'home':
register_value = self.WB_MODE_HOME
elif self.camera_idx == '3MP':
print('TODO UPDATE: For best results set a White Balance setting')
self.white_balance_mode = register_value
self._write_reg(self.CAM_REG_WB_MODE_CONTROL, register_value)
self._wait_idle()
##################### INTERNAL FUNCTIONS - HIGH LEVEL #####################
########### CORE PHOTO FUNCTIONS ###########
def _clear_fifo_flag(self):
self._write_reg(self.ARDUCHIP_FIFO, self.FIFO_CLEAR_ID_MASK)
def _start_capture(self):
self._write_reg(self.ARDUCHIP_FIFO, self.FIFO_START_MASK)
def _set_capture(self):
# print('a1')
self._clear_fifo_flag()
self._wait_idle()
self._start_capture()
# print('a2')
while (int(self._get_bit(self.ARDUCHIP_TRIG, self.CAP_DONE_MASK)) == 0):
# print(self._get_bit(self.ARDUCHIP_TRIG, self.CAP_DONE_MASK))
sleep_ms(200)
# print('a3')
self.received_length = self._read_fifo_length()
self.total_length = self.received_length
self.burst_first_flag = False
# print('a4')
def _read_fifo_length(self): # TODO: CONFIRM AND SWAP TO A 3 BYTE READ
len1 = int.from_bytes(self._read_reg(self.FIFO_SIZE1),1)
len2 = int.from_bytes(self._read_reg(self.FIFO_SIZE2),1)
len3 = int.from_bytes(self._read_reg(self.FIFO_SIZE3),1)
# print(len1,len2,len3)
return ((len3 << 16) | (len2 << 8) | len1) & 0xffffff
def _get_sensor_config(self):
camera_id = self._read_reg(self.CAM_REG_SENSOR_ID);
self._wait_idle()
if (int.from_bytes(camera_id, 1) == self.SENSOR_3MP_1) or (int.from_bytes(camera_id, 1) == self.SENSOR_3MP_2):
self.camera_idx = '3MP'
if (int.from_bytes(camera_id, 1) == self.SENSOR_5MP_1) or (int.from_bytes(camera_id, 1) == self.SENSOR_5MP_2):
self.camera_idx = '5MP'
##################### INTERNAL FUNCTIONS - LOW LEVEL #####################
def _read_buffer(self):
print('COMPLETE')
def _bus_write(self, addr, val):
self.cs.off()
self.spi_bus.write(bytes([addr]))
self.spi_bus.write(bytes([val])) # FixMe only works with single bytes
self.cs.on()
sleep_ms(1) # From the Arducam Library
return 1
def _bus_read(self, addr):
self.cs.off()
self.spi_bus.write(bytes([addr]))
data = self.spi_bus.read(1) # Only read second set of data
data = self.spi_bus.read(1)
self.cs.on()
return data
def _write_reg(self, addr, val):
self._bus_write(addr | 0x80, val)
def _read_reg(self, addr):
data = self._bus_read(addr & 0x7F)
return data # TODO: Check that this should return raw bytes or int (int.from_bytes(data, 1))
def _read_byte(self):
self.cs.off()
self.spi_bus.write(bytes([self.SINGLE_FIFO_READ]))
data = self.spi_bus.read(1)
data = self.spi_bus.read(1)
self.cs.on()
self.received_length -= 1
return data
def _wait_idle(self):
data = self._read_reg(self.CAM_REG_SENSOR_STATE)
while ((int.from_bytes(data, 1) & 0x03) == self.CAM_REG_SENSOR_STATE_IDLE):
data = self._read_reg(self.CAM_REG_SENSOR_STATE)
sleep_ms(2)
def _get_bit(self, addr, bit):
data = self._read_reg(addr);
return int.from_bytes(data, 1) & bit;