|
| 1 | +.. zephyr:code-sample:: mfd_charger |
| 2 | + :name: Multi-Function Device (MFD) with Charger, Fuel Gauge, and Regulators |
| 3 | + :relevant-api: charger_interface fuel_gauge_interface regulator_interface mfd_interfaces |
| 4 | + |
| 5 | + Demonstrate a multi-function device using charger, fuel gauge, and regulator subsystems. |
| 6 | + |
| 7 | +Overview |
| 8 | +******** |
| 9 | + |
| 10 | +This sample demonstrates how to use a multi-function power management device (MFD) |
| 11 | +with Zephyr's driver subsystems. The sample is designed to work with any MFD that |
| 12 | +provides charger, fuel gauge, and regulator functionality through the standard |
| 13 | +Zephyr driver interfaces. |
| 14 | + |
| 15 | +The sample shows how to: |
| 16 | + |
| 17 | +* Initialize and configure an MFD (Multi-Function Device) driver |
| 18 | +* Monitor battery charging status and health using the :ref:`Charger API <charger_api>` |
| 19 | +* Read battery voltage, state of charge, and cycle count using the :ref:`Fuel Gauge API <fuel_gauge_api>` |
| 20 | +* Control and monitor voltage regulators using the :ref:`Regulator API <regulator_api>` |
| 21 | +* Handle interrupts, power-good signals, and reset signals from the device |
| 22 | + |
| 23 | +The application continuously polls the charger and fuel gauge to display real-time |
| 24 | +battery and charging information, including: |
| 25 | + |
| 26 | +* Charger configuration (current limits, charge currents, voltages) |
| 27 | +* Charging status (online, present, charging state, health) |
| 28 | +* Battery fuel gauge data (voltage, state of charge, cycle count) |
| 29 | +* Regulator output voltages |
| 30 | + |
| 31 | +Requirements |
| 32 | +************ |
| 33 | + |
| 34 | +The sample requires a board with an MFD device that supports charger, fuel gauge, |
| 35 | +and regulator functionality. The MFD device must be defined in the devicetree with |
| 36 | +appropriate labels so that the sample code can access the individual subsystems. |
| 37 | + |
| 38 | +The devicetree must include: |
| 39 | + |
| 40 | +* A node with the label ``charger`` for the charger interface |
| 41 | +* A node with the label ``fuelgauge`` for the fuel gauge interface |
| 42 | +* A node with the label ``buck`` for the buck regulator (or similar) |
| 43 | +* A node with the label ``buckboost`` for the buck-boost regulator (or similar) |
| 44 | + |
| 45 | +An example MFD device overlay is provided showing how to configure these labels |
| 46 | +for a specific board and MFD chip. Refer to the overlay file for your board to |
| 47 | +understand how to adapt it for other MFD devices. |
| 48 | + |
| 49 | +Hardware Setup |
| 50 | +============== |
| 51 | + |
| 52 | +The specific hardware connections depend on the MFD device being used. Refer to the |
| 53 | +device datasheet and the overlay file for your board for detailed connection |
| 54 | +instructions. |
| 55 | + |
| 56 | +At minimum, the MFD requires: |
| 57 | + |
| 58 | +* A communications bus |
| 59 | +* Power supply |
| 60 | +* A battery connected to the charger and fuel gauge subsystems for proper operation |
| 61 | + |
| 62 | +Building and Running |
| 63 | +******************** |
| 64 | + |
| 65 | +The code can be found in :zephyr_file:`samples/drivers/mfd_charger`. |
| 66 | + |
| 67 | +To build and flash the application for your board: |
| 68 | + |
| 69 | +.. zephyr-app-commands:: |
| 70 | + :zephyr-app: samples/drivers/mfd_charger |
| 71 | + :board: <board> |
| 72 | + :goals: build flash |
| 73 | + :compact: |
| 74 | + |
| 75 | +Replace ``<board>`` with your target board name. |
| 76 | + |
| 77 | +If your board does not have an MFD overlay, you will need to create one. Create a file |
| 78 | +in the ``boards/`` subdirectory named ``<board>.overlay`` with the appropriate devicetree |
| 79 | +configuration for your MFD device. See the board-specific documentation for examples. |
| 80 | + |
| 81 | +Sample Output |
| 82 | +============= |
| 83 | + |
| 84 | +The sample output will vary based on the specific MFD device and configuration. |
| 85 | +A typical output showing battery charging and monitoring information might look like: |
| 86 | + |
| 87 | +.. code-block:: console |
| 88 | +
|
| 89 | + [0:00:00.003]: Found device "charger", getting charger data |
| 90 | + [0:00:00.006]: Current (Fast Charge): 20000 uA |
| 91 | + [0:00:00.009]: Input Regulation Voltage: 3800000 uV |
| 92 | + [0:00:00.012]: Current (Termination): 5000 uA |
| 93 | + [0:00:03.021]: Fuel gauge Battery Capacity: 1000 |
| 94 | + [0:00:03.024]: Buck Output Voltage: 1300000 |
| 95 | + [0:00:03.027]: Buck Boost Output Voltage: 3300000 |
| 96 | + [0:00:03.030]: Online: Charger is active. |
| 97 | + [0:00:03.033]: Present: Battery is Present. |
| 98 | + [0:00:03.036]: Status: Charger is Charging. |
| 99 | + [0:00:03.039]: Mode: Charger is in Fast Mode (CC). |
| 100 | + [0:00:03.042]: Health: Battery is Cool. |
| 101 | + [0:00:03.045]: Fuel gauge Voltage: 3950000 |
| 102 | + [0:00:03.048]: Fuel gauge Status 0x0 |
| 103 | + [0:00:03.051]: Fuel gauge SoC: 75 |
| 104 | +
|
| 105 | +.. note:: The values shown above will vary depending on the actual MFD device used, |
| 106 | + the battery state of charge, and the device configuration. |
0 commit comments