Skip to content

Commit 94beeac

Browse files
committed
Add missing docstring comments in drivers
1 parent 72887c7 commit 94beeac

File tree

7 files changed

+93
-8
lines changed

7 files changed

+93
-8
lines changed

cv2_drivers/cameras/dvp_rp2_pio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ def _active(self, active=None):
117117
- True: Activate the DVP interface
118118
- False: Deactivate the DVP interface
119119
- None: Get the current active state
120+
121+
Returns:
122+
bool: Current active state if no argument is provided
120123
"""
121124
# If no argument is provided, return the current active state
122125
if active == None:

cv2_drivers/cameras/hm01b0.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,21 @@ def _set_mode(self, mode):
303303
"""
304304
Sets the operating mode of the HM01B0 sensor.
305305
Args:
306-
mode (int): The mode to set, e.g., MODE_STREAMING.
306+
mode (int): The mode to set, e.g., _HIMAX_MODE_STREAMING.
307307
"""
308308
self._write_register(self._MODE_SELECT, mode)
309309

310310
def _trigger(self):
311+
"""
312+
Triggers the HM01B0 sensor to capture a number of images. See
313+
_set_n_frames().
314+
"""
311315
self._write_register(self._MODE_SELECT, self._HIMAX_MODE_STREAMING_NFRAMES)
312316

313317
def _set_n_frames(self, n_frames):
318+
"""
319+
Sets the number of frames to capture before stopping. See _trigger().
320+
"""
314321
self._write_register(self._PMU_AUTOSLEEP_FRAMECNT, n_frames)
315322

316323
def _send_init(self, num_data_pins):

cv2_drivers/cameras/ov5640.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,9 @@ def _write_list(self, data):
958958
"""
959959
Initializes the OV5640 sensor with default settings.
960960
This includes setting up exposure, gain, and frame timing.
961+
962+
Args:
963+
data (list): List of register-value pairs to write to the sensor.
961964
"""
962965
for i in range(len(data) // 2):
963966
reg = data[i * 2]
@@ -1038,6 +1041,16 @@ def _set_pll(
10381041
) -> None:
10391042
"""
10401043
Sets the PLL (Phase-Locked Loop) configuration for the OV5640 camera.
1044+
1045+
Args:
1046+
bypass (bool): Whether to bypass the PLL.
1047+
multiplier (int): PLL multiplier.
1048+
sys_div (int): System divider.
1049+
pre_div (int): Pre-divider.
1050+
root_2x (bool): Whether to use 2x root clock.
1051+
pclk_root_div (int): PCLK root divider.
1052+
pclk_manual (bool): Whether to use manual PCLK.
1053+
pclk_div (int): PCLK divider.
10411054
"""
10421055
if (
10431056
multiplier > 252
@@ -1125,6 +1138,11 @@ def _set_image_options(self) -> None:
11251138
def _write_addr_reg(self, reg: int, x_value: int, y_value: int) -> None:
11261139
"""
11271140
Writes 2 16-bit values to 4 8-bit registers.
1141+
1142+
Args:
1143+
reg (int): The base register address to write to.
1144+
x_value (int): The first 16-bit value to write.
1145+
y_value (int): The second 16-bit value to write.
11281146
"""
11291147
self._write_register(reg, [
11301148
(x_value >> 8) & 0xFF,
@@ -1136,6 +1154,12 @@ def _write_addr_reg(self, reg: int, x_value: int, y_value: int) -> None:
11361154
def _write_reg_bits(self, reg: int, mask: int, enable: bool) -> None:
11371155
"""
11381156
Writes a bitmask to a register, enabling or disabling specific bits.
1157+
1158+
Args:
1159+
reg (int): The register address to write to.
1160+
mask (int): The bitmask to apply.
1161+
enable (bool): If True, enables the bits in the mask; if False,
1162+
disables them.
11391163
"""
11401164
val = self._read_register(reg)[0]
11411165
if enable:

cv2_drivers/displays/st7789_pio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ def _write(self, command=None, data=None):
173173
def _pio_write(self, data):
174174
"""
175175
Writes data to the display using the PIO.
176+
177+
Args:
178+
data (bytes, bytearray, or ndarray): Data to write to the display
176179
"""
177180
# Configure the DMA transfer count and read address
178181
count = len(data) if isinstance(data, (bytes, bytearray)) else data.size

cv2_drivers/displays/st7789_spi.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ def __init__(
6262
super().__init__(width, height, rotation, bgr_order, reverse_bytes_in_word)
6363

6464
def _write(self, command=None, data=None):
65-
"""SPI write to the device: commands and data."""
65+
"""
66+
Writes commands and data to the display.
67+
68+
Args:
69+
command (bytes, optional): Command to send to the display
70+
data (bytes, optional): Data to send to the display
71+
"""
6672
# Save the current mode and alt of the DC pin in case it's used by
6773
# another device on the same SPI bus
6874
dcMode, dcAlt = self._save_pin_mode_alt(self._dc)

cv2_drivers/touch_screens/cst816.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from .cv2_touch_screen import CV2_Touch_Screen
1717

1818
class CST816(CV2_Touch_Screen):
19+
"""
20+
OpenCV CST816 touch screen driver using an I2C interface.
21+
"""
1922
_I2C_ADDRESS = 0x15
2023
_CHIP_ID = 0xB6
2124

@@ -53,24 +56,42 @@ class CST816(CV2_Touch_Screen):
5356
_REG_IO_CTL = 0xFD
5457
_REG_DIS_AUTO_SLEEP = 0xFE
5558

56-
def __init__(self, i2c, address=_I2C_ADDRESS, width=240, height=320, rotation=1):
59+
def __init__(self, i2c, width=240, height=320, rotation=1, address=_I2C_ADDRESS):
60+
"""
61+
Initializes the CST816 driver.
62+
63+
Args:
64+
i2c (I2C): I2C object for communication
65+
width (int, optional): Touch screen width in pixels.
66+
Default is 240
67+
height (int, optional): Touch screen height in pixels.
68+
Default is 320
69+
rotation (int, optional): Orientation of touch screen
70+
- 0: Portrait (default)
71+
- 1: Landscape
72+
- 2: Inverted portrait
73+
- 3: Inverted landscape
74+
address (int, optional): I2C address of the camera.
75+
Default is 0x15
76+
"""
5777
self.i2c = i2c
5878
self.address = address
5979
self.width = width
6080
self.height = height
6181
self.rotation = rotation
6282

63-
def is_connected(self):
83+
def _is_connected(self):
6484
"""
65-
Check if the CST816 touch screen is connected by reading the chip ID.
85+
Checks if the touch screen is connected by reading the chip ID.
6686
6787
Returns:
68-
bool: True if connected, False otherwise
88+
bool: True if the touch screen is connected and the chip ID is
89+
correct, otherwise False.
6990
"""
7091
try:
7192
# Try to read the chip ID
7293
# If it throws an I/O error - the device isn't connected
73-
chip_id = self.read_register_value(self._REG_CHIP_ID)
94+
chip_id = self._get_chip_id()
7495

7596
# Confirm the chip ID is correct
7697
if chip_id == self._CHIP_ID:
@@ -80,7 +101,13 @@ def is_connected(self):
80101
except:
81102
return False
82103

83-
def getChipID(self):
104+
def _get_chip_id(self):
105+
"""
106+
Reads the chip ID.
107+
108+
Returns:
109+
int: The chip ID of the HM01B0 (should be 0xB6).
110+
"""
84111
return self.read_register_value(self._REG_CHIP_ID)
85112

86113
def is_touched(self):
@@ -97,6 +124,13 @@ def is_touched(self):
97124
return touch_num > 0
98125

99126
def get_touch_xy(self):
127+
"""
128+
Get the X and Y coordinates of the touch point. Will return the last
129+
touch point if no touch is currently detected.
130+
131+
Returns:
132+
tuple: (x, y) coordinates of the touch point
133+
"""
100134
x = self.read_register_value(self._REG_X_POS_H, 2) & 0x0FFF
101135
y = self.read_register_value(self._REG_Y_POS_H, 2) & 0x0FFF
102136

@@ -118,6 +152,8 @@ def read_register_value(self, reg, num_bytes=1):
118152
119153
Args:
120154
reg (int): Register address to read from
155+
num_bytes (int, optional): Number of bytes to read from the register.
156+
Default is 1
121157
122158
Returns:
123159
int: Value read from the register

cv2_drivers/touch_screens/cv2_touch_screen.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
#-------------------------------------------------------------------------------
1010

1111
class CV2_Touch_Screen():
12+
"""
13+
Base class for OpenCV touch screen drivers.
14+
"""
1215
def __init__(self):
16+
"""
17+
Initializes the touch screen.
18+
"""
1319
pass
1420

1521
# TODO: Implement common methods for all touch screens

0 commit comments

Comments
 (0)