I2C application (app/i2c-app.c)
===============================

@tableofcontents

I2C application demonstrates how to access/manipulate Always On (AON) I2C from
the SPE/AON processor. There are three I2C instances (2, 8 and 10) in AON
domain, availability of the instance will be based on the Jetson platform being
used.

@note It is required to compile device tree and flash board to have them
updated after making kernel device tree changes as described in following
sections.


## Hardware Configuration

The sample app uses I2C bus 8 and BMI160 sensor module, similar to
https://hackspark.fr/en/electronics/1341-6dof-bosch-6-axis-acceleration-gyro-gravity-sensor-gy-bmi160.html
for the demo purposes.

The I2C app accesses the 40 pin header J30 and expects I2C external module at the pin map
shown below:

- Pin 1  - 3.3V
- Pin 3  - SDA
- Pin 5  - SCL
- Pin 34 - SAO
- Pin 39 - GND

The demo app reads BMI160 sensor ID. If the app successfully retrieves the
correct ID, it prints the following message:

    I2C test successful

@note BMI160 is configured to have the I2C address 0x68 by connecting its SAO pin to
Pin 34.

## Software Configuration

# Jetson AGX Orin and Orin Nano
1. Make sure I2C bus 8 is disabled in linux kernel device tree and no other
processors using it. In case of Orin Nano, it is disabled by default. For AGX Orin, the I2C bus 8 needs to be disabled.
You must run source_sync.sh to get the dtsi file. After running source_sync.sh, the file is located at
Linux_for_Tegra/sources/hardware/nvidia/t23x/nv-public/overlay/tegra234-p3737-0000+p3701-0000.dts.
Disabling device node from the kernel makes that I2C controller and all the client devices
attached to it unaccessible from the kernel.
```
    i2c@c250000 {
            status = "disabled";
    };
```
2. Compile the device tree and copy the dtb file to Linux_for_Tegra/dtb/ directory.
3. Disable firewall setting in bootloader/tegra234-firewall-config-base.dtsi
so that SPE can access I2C registers.
```
        reg@2130 { /* CLK_RST_CONTROLLER_AON_SCR_I2C8_0 */
            exclusion-info = <3>;
            value = <0x30001610>;
        };
```

4. In `soc/t23x/target_specific.mk`, set `ENABLE_I2C_APP := 1` and rebuild the
application. Copy the output to `${L4T}/bootloader/spe_t234.bin`

5. Reflash all the partitions, including new device tree and SPE binaries
generated from the above steps by referencing the instructions in the **Building the Kernel**
section of the Linux Developer Guide.

The demo app reads BMI160 sensor ID. If the app successfully retrieves the
correct ID, it prints the following message:

    I2C test successful

