Ini File Equivalents
This section lists ini file commands with the Python code that does the same or similar thing. It will illustrate how to do common operations.
On the left are example ini file commands, and the equivalent Python is on the right. Keep in mind that Python is much more flexible than the ini commands. Where an ini command required a numerical constant, Python will allow any expression. Python has much more flow control, functions with parameters, user-defined classes and so on.
FIELD_WR= OUTPUT_FORMAT_TEST, 256 |
reg.OUTPUT_FORMAT_TEST = 256 |
This is the recommended way to write a register, variable or bitfield. |
 |
FIELD_WR=CAM1_AWB_CCM_L_0, 0x0180 |
reg. CAM1_AWB_CCM_L_0 = 1.5 |
If the data type is defined, you can use floating point values and Python will translate to the right value accordingly. This example has fixed8 (signed with 8 fraction bits) CCM settings. |
 |
REG= 0x3084, 0x2409 (no register page) |
reg.reg(0x3084).value = 0x2409 |
On older sensors that have multiple pages of 8-bit addressed registers and an ADDR_SPACE_SEL register, the reg.reg() method takes two parameters. On newer sensors with a 16-bit register address space reg.reg() takes one parameter. It is an error to use the wrong number of parameters. |
 |
BITFIELD= 0x001A, 0x0200, 1 |
reg.reg(0x001A).bitfield(0x0200).value = 1 |
Same as REG= but use the bitfield() method to construct a Bitfield object. |
 |
VAR= 18, 0x126, 1 |
reg.var(18, 0x126).value = 1 |
Note that the size of the variable is determined by the sensor data file. If the variable is not defined then an optional size in bits can be passed as the third argument. It defaults to 16 bits wide. |
 |
VAR8=15, 0x0C, 0 |
reg.var(15, 0x0C, 8).value = 0 |
VAR8 forces an 8-bit data transaction. The Python is not quite equivalent because if the variable is defined in the sensor data file, Python will use the data size in the sensor data file and ignore the data size parameter. |
 |
SFR= 0x1078, 0xFFFF |
reg.sfr(0x1078).value = 0xFFFF |
This writes to MCU memory using the physical, rather than logical, addressing. SFR8 is analogous to VAR8. If the SOC supports multiple physical regions, then the physical region must be the first parameter. After the address you can specify an optional size in bits. The default is 16 bits. |
 |
REG_BURST= 0x990, 0x3C3C, 0x3C3C, 0x3C5F, 0x4F30, 0xED08, 0xBD61, 0xD5CE, 0x4CD |
reg.reg(0x990).value = [0x3C3C, 0x3C3C, 0x3C5F, 0x4F30, 0xED08, 0xBD61, 0xD5CE, 0x4CD] |
If you set a register to a list of values Python does a burst write. This only works for simple registers and SFR (physically addressed) memory. |
 |
SERIAL_REG= 0x64, 0x25, 0x18, 8:16 |
midlib.Register(ship_addr=0x64, addr=0x25, addr_size=8, data_size=16).value = 0x18 |
The SERIAL_REG command is for I2C write to any arbitrary device address with specified register address size and data size. There is equivalent Python syntax by explicitly calling the midlib.Register constructor, but there may be a better way. |
 |
DELAY= 50 |
midlib.delay(50) |
Delay in milliseconds. |
 |
STATE= Display Zoom Percent, 50 |
devware.setstate('Display Zoom Percent', 50) |
Set a DevWare internal variable. You can also set so-called DevWare Option variables with devware.setoption(). |
 |
LOAD= AWB Settings |
devware.load_preset('AWB Settings') |
If no filename is given, the devware.load_preset() method will load from the currently executing ini file, or if that can't be determined, the main ini file. Also consider defining a function entirely in Python instead of using an ini preset. |
 |
POLL_FIELD= SEQ_CMD, !=0, DELAY=10, TIMEOUT=50 |
timeout = 0 |
Python, of course, has looping and flow control constructs far beyond what you can do in an ini file. If you do a lot of similar POLLs, you could write a function to make your code more compact. |
 |
POLL_REG= 0x3F, 0xFFFF, >8, DELAY=50, TIMEOUT=5 |
timeout = 0 |
POLL_VAR similarly, but with reg.var(). |
 |
IF_FIELD= SHUTTER_WIDTH_LIM_AE, >0x100, LOAD=Night mode, ELSELOAD=Day mode |
if (reg.SHUTTER_WIDTH_LIM_AE.value > 0x100): |
The ini file syntax required the if and else blocks to be in presets. In Python they can be inline, or in functions. Also there is much more flexibility in expressing the condition in Python. |
 |
IF_REG= 2, 0x37, 0xFFFF,== 0x100, LOAD=Night mode, ELSELOAD=Day mode |
if (reg.reg(2, 0x37).value == 0x100): |
 |
 |
ERROR_IF= COMMAND_REGISTER, HOST_COMMAND, !=0, "Command failed" |
assert reg.COMMAND_REGISTER. HOST_COMMAND.value == 0, 'Command failed' |
The error message will go to the Python Console window. |
 |
FAR1= 0, 0x3044, 0x0020, 1 |
midlib.Register(addr_type='FAR1', addr=0x3044).bitfield(0x0020).value = 1 |
Similarly for FAR2. |
 |
DATATYPE= HUE_ANGLE, signed, RANGE=-22:22 |
reg.HUE_ANGLE.datatype = signed |
Datatypes are defined in the sensor data file now, but you can also set or change datatype, minimum, and maximum within Python if needed. |
 |
LOG= "// White balance settings" |
devware.log('// White balance settings') |
This works exactly the same as the ini command. |
 |
ICON= blue star |
#icon = blue star |
This is only interpreted by the User Toolbar to set a button icon. In Python use the same syntax but in a comment. There must be no space between # and icon. |
 |
IMAGE= 640, 480, YCBCR |
devware.image(640, 480, 'YCBCR') |
This works exactly the same as the ini command. |
 |
LOAD_PROM= 0xA8, PGA |
midlib.Camera(0).load_prom(0xA8, 'PGA') |
Midlib load_prom() cannot load software settings (SWCCM, SWSTEREO, etc.). |
 |
SAVE_IMAGE= capture.raw |
ret, img = midlib.Camera(0).grab_frame() |
SAVE_IMAGE by default saves in the DevWare image capture directory. The example code above shows how to get the directory using getoption_str(). |
 |
SAVE_REGS= regdump.txt |
savedir = devware.getoption_str('Capture File') |
SAVE_REGS by default saves in the DevWare image capture directory. The example code above shows how to get the directory using getoption_str(). SAVE_REGS also writes the data as ini file commands. In Python you could of course use any format you want. |
 |
SAVE_REGS= regdump.txt, AWB |
savename = os.path.join(savedir,'regdump.txt') |
This example uses a wildcard to save only registers with AWB in the name somewhere. Any criterion can be used. |
 |
XMCLK= 24000000 |
midlib.Camera(0).MI_OUTPUT_CLOCK_FREQ = 24000000 |
All midlib mi_modes defined in midlib2.h are exposed as attributes on a Camera object. Some others are MI_ALLOW_FAR_ACCESS, MI_PIXCLK_POLARITY, MI_SENSOR_POWER, MI_SENSOR_RESET, MI_SHIP_SPEED, MI_DIRECT_VAR_ACCESS. |
 |