# Software adaption

### Example devicetree&#x20;

The following implements Devicetree nodes are implementing the P140 functionallity for the tca6408 and pca9685 component.&#x20;

{% hint style="info" %}
The following devicetree snippet is only an example. The I²C controller depends on your hardware setup.&#x20;
{% endhint %}

{% code title="" lineNumbers="true" %}

```c
/*
 * Copyright (c) 2023, AUVIDEA. All rights reserved.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or any
 * later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 */

/ {
    i2c@c240000 {
        p140_control_tca6408: p140_tca6408@21 {
            compatible = "ti,tca6408";
            reg = <0x21>;
	    vcc-supply = <&battery_reg>;
            gpio-controller;
            #gpio-cells = <2>;
            gpio-line-names = "", "", "RESET_POE", "/INT", "EN_PCA", "PGOOD_48V", "EN_48V", ""; 
            
            // this is required for the PCA to be enabled
            en_pca { 
		gpio-hog;
		gpios = <4 0>;
		output-low;
		line-name = "EN_PCA";
	    };
        };

        p140_control_pca9685: p140_pca9685@54 {
            compatible = "nxp,pca9685-pwm";
            #pwm-cells = <2>;
            reg = <0x54>;
	    gpio-line-names = "", "LED4_G", "LED4_R", "LED4_B", "LED3_G", "LED3_R", "LED3_B",
                                "LED2_G", "LED2_R", "LED2_B", "LED1_G", "LED1_R", "LED1_B",
                                "LED0_G", "LED0_R", "LED0_B", "CTL_ALL";
        };
    };
};
```

{% endcode %}

### Bash Script

#### Ethernet Switch (KSZ9896C)

{% file src="/files/sCgmOA1jUIUFjOZTHq9L" %}

This code is meant to initializing the board correctly. Because the settings will reset every time you reboot the board, it is necessary to run this script on every start of the board. The script can take some time to show some response, so wait some time and set the script run until it prints “Done!” in the console.

#### GPIO Control

{% file src="/files/b5p2PJemUzU1hzpJXIFO" %}

This script is made to control specific GPIO Ports which are connected to preset outputs/inputs to check there status or set them to a specific state

**All action**

<table><thead><tr><th width="247.33333333333331">Option</th><th>Suboption 1</th><th>Description</th></tr></thead><tbody><tr><td>-h (--help)</td><td></td><td>Shows help menu</td></tr><tr><td>-en48V (--enable48V)</td><td>0|1</td><td>Enable/Disable 48V</td></tr><tr><td>-enPCA (--enablePCA)</td><td>0|1</td><td>Enable/Disable PCA</td></tr><tr><td>-rPoE (--resetPoE)</td><td></td><td>Reset PoE</td></tr><tr><td>-c48V (--check48V)</td><td></td><td>Check 48V Status</td></tr></tbody></table>

**Example**

| Action                        | Command                            |
| ----------------------------- | ---------------------------------- |
| Show help menu and enable 48V | `./gpio_control.sh -h -en48V 1`    |
| Disable PCA and check 48V     | `./gpio_control.sh -enPCA 0 -c48V` |

#### PWM Controller (PCA9685)

{% file src="/files/x1L5ytc8gGdtLEPD4VJV" %}

This script is made to control the PWM Controller, to turn on/off specific/all LEDs on the board

**All action**

<table><thead><tr><th width="130">Option</th><th width="153">Value 1</th><th>Value 2</th><th>Description</th></tr></thead><tbody><tr><td>-h (--help)</td><td></td><td></td><td>Shows help menu</td></tr><tr><td>-led0</td><td>red|blue|green</td><td>on|off</td><td>Turn on/off LED0 color</td></tr><tr><td>-led1</td><td>red|blue|green</td><td>on|off</td><td>Turn on/off LED1 color</td></tr><tr><td>-led2</td><td>red|blue|green</td><td>on|off</td><td>Turn on/off LED2 color</td></tr><tr><td>-led3</td><td>red|blue|green</td><td>on|off</td><td>Turn on/off LED3 color</td></tr><tr><td>-led4</td><td>red|blue|green</td><td>on|off</td><td>Turn on/off LED4 color</td></tr><tr><td>-o (--off)</td><td></td><td></td><td>Turn all LEDs off</td></tr></tbody></table>

**Example**

| Action                                                         | Command                                                 |
| -------------------------------------------------------------- | ------------------------------------------------------- |
| Shows help menu and turns color red on led0 on                 | `./PWM_LED_controller.sh -h -led0 red on`               |
| Turns color blue on led1 on and turns color green on led 2 off | `./PWM_LED_controller.sh -led1 blue on -led2 green off` |

#### PoE Power Controller (TPS23861)

{% file src="/files/ylSBZR8HdR6bKNOWsm5U" %}

This script is made to control the PoE Controller on the board. It is possible to set specific ports to on, off or change there mode or turn them off completely&#x20;

**All action**

<table><thead><tr><th width="191.33333333333331">argument</th><th>Description</th></tr></thead><tbody><tr><td>-h (--help)</td><td>Shows help menu</td></tr><tr><td>-b (--bus)</td><td>Set bus</td></tr><tr><td>-a (-address)</td><td>Set chip address</td></tr><tr><td>-s (--status)</td><td>Checks status</td></tr><tr><td>-on[PORT|a]</td><td>Turn all or specific port(s) on</td></tr><tr><td>-off[PORT|a]</td><td>Turn all or specific port(s) off</td></tr><tr><td>-dis[PORT|a]</td><td>Disable all or specific port(s)</td></tr><tr><td>-man[PORT|a]</td><td>Set all or specific port(s) to manual mode</td></tr><tr><td>-sauto[PORT|a]</td><td>Set all or specific port(s) to semi auto mode</td></tr><tr><td>-auto[PORT|a]</td><td>Set all or specific port(s) to auto mode</td></tr></tbody></table>

**Example**

| Action                                                                                  | Command                                       |
| --------------------------------------------------------------------------------------- | --------------------------------------------- |
| Set all ports to manual mode and turn on all ports and checks status                    | `./TPS23861_PoE.sh -mana -ona -s`             |
| Set bus to 1, set port 3 to manual, set port 2 to auto, turn on port 3 and check status | `./TPS23861_PoE.sh -b 1 -man3 -auto2 -on3 -s` |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://auvidea.gitbook.io/p140/manual/software-adaption.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
