Introduction to mt9d131 driver

Source: Internet
Author: User

Mt9d131 has a general effect. Thanks to haisi's drive, there are still a lot of users.

The drivers of many chips are relatively simple, that is, to assign a value to a register directly, it will be OK. What is the meaning of this Register, and what is the meaning of the value? Just look at datasheet.

 

Mt9d131 is slightly more complex.

Mt9d131 contains many configuration items, so mt9d131 divides the configuration items into three categories.

1. Hardware registers

2. Driver variable

3. MCU memory

 

1. Hardware registers

There is no difference between hardware registers and general chip registers, but because mt9d131 has many registers, it is divided into three pages, page0, page1, page2

Page0 includes some core sensor functions

Control of page1 color Pipelines

Page2 includes JPEG and other processing

Therefore, before assigning values to a register of mt9d131, you must assign values to the page by writing the 0xf0 register.

Write 0 indicates that all subsequent operations are for page0, write 1 indicates that all subsequent operations are for page1, write 2 indicates page2

After determining which page, you can read and write the required registers normally.

 

For example, the following code is used to read the chip ID.

Gpio_i2c_write (i2c_mt9d131, 0xf0, 0x00 );
Gpio_i2c_write (i2c_mt9d131, 0xf1, 0x00 );

The above two rows indicate switching to page0

Note that if the operation target is 16 bits,

If we need to read and write the last eight digits at a time, we need to read and write the 0xf1 register.

 

The following two rows indicate that the r0 registers of page0 are read,

Because a register is 16 bits, you need to read and write 0xf1 each time to complete the data read and write.
Unsigned char regvalue = gpio_i2c_read (I2C_MT9D131, 0x00 );
Int loop1 = gpio_i2c_read (I2C_MT9D131, 0xf1 );
If (regvalue! = 0x15) | (loop1! = 0x19 ))
{
Printk ("read Prodect ID Number MSB is % x \ n", regvalue );
Printk ("read Prodect ID Number LSB is % x \ n", loop1 );
Printk ("check mt9d131 ID error. \ n ");
}

Through datasheet, we know that r0 is read-only and the constant value is 0x1519.

Other reads and writes to registers are similar.

 

2. driver variable

Many functions in mt9d131 are implemented using the driver method. Each driver has an id

All these drivers constitute the mt9d131 firmware, which can run on a 6811 compatible processor (with a math coprocessor.

For example

Sequence Control related to driver id 1

Auto exposure corresponding to driver id 2

Auto White Balance corresponding to driver id 3

And so on.

Each driver has many variables. by assigning values to these variables, you can control the behavior of the corresponding driver.

This is implemented through the 0xC6 and 0xC8 registers.

0xC6 is composed of the driver id and the corresponding variable offset.

0xC8 is the value assigned to the corresponding variable.

Assign a value to 0xC6 Based on Datasheet, which consists of four parts:

8 ~ The 12-bit driver id

0 ~ The 7-bit is the offset of the corresponding variable in the driver.

13 ~ A 14-bit value of 1 indicates a logical operation.

If the value of 15 is 0, it indicates a 16-bit operation. If the value is 1, it indicates an 8-bit operation.

 

For example, the following code sets the output width and height of context A to 800x600.

Gpio_i2c_write (I2C_MT9D131, 0xf0, 0x00 );

Gpio_i2c_write (I2C_MT9D131, 0xf1, 0x01 );

The code above switches to page1

 

According to datasheet, we know that the corresponding driver is 7, and the variable offset is 3 and 5.
Gpio_i2c_write (I2C_MT9D131, 0xC6, 0x27 );

Gpio_i2c_write (i2c_mt9d131, 0xf1, 0x03 );

Gpio_i2c_write (i2c_mt9d131, 0xc8, 0x03 );

Gpio_i2c_write (i2c_mt9d131, 0xf1, 0x20 );

The above code is assigned 0x2703 to 0xc6.

Split by rules.

Driver id = 7

Variable address = 3

16-bit, logical operation

0x0320, that is, 800, assigned to 0xc8

 

Gpio_i2c_write (i2c_mt9d131, 0xc6, 0x27 );

Gpio_i2c_write (i2c_mt9d131, 0xf1, 0x05 );

Gpio_i2c_write (i2c_mt9d131, 0xc8, 0x02 );

Gpio_i2c_write (i2c_mt9d131, 0xf1, 0x58 );

The above code is assigned 0x2705 to 0xc6.

Split by rules.

Driver id = 7

Variable address = 5

16-bit, logical operation

0x0258, that is, 600, assigned to 0xc8

Of course, other operations are required to completely change the image size.

 

3. MCU memory

Omitted

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.