xref: /aosp_15_r20/external/pigweed/pw_i2c_mcuxpresso/docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1.. _module-pw_i2c_mcuxpresso:
2
3=================
4pw_i2c_mcuxpresso
5=================
6.. pigweed-module::
7   :name: pw_i2c_mcuxpresso
8
9``pw_i2c_mcuxpresso`` implements the ``pw_i2c`` interface using the
10NXP MCUXpresso SDK.
11
12The implementation is based on the i2c driver in SDK. I2C transfers use
13non-blocking driver API.
14
15``I3cMcuxpressoInitiator`` implements the ``pw_i2c`` initiator interface using
16the MCUXpresso I3C driver. It exposes a few I3C specific API's for setting up
17the bus, allowing normal I2C API's to work after setup.
18
19-----
20Setup
21-----
22This module requires following setup:
23
241. Use ``pw_build_mcuxpresso`` to create a ``pw_source_set`` for an
25   MCUXpresso SDK.
262. Include the i2c driver component in this SDK definition.
273. Specify the ``pw_third_party_mcuxpresso_SDK`` GN global variable to specify
28   the name of this source set.
294. Use ``pw::i2c::McuxpressoInitiator`` implementation of
30   ``pw::i2c::Initiator`` while creating ``pw::i2c::Device`` or
31   ``pw::i2c::RegisterDevice`` interface to access the I2C devices connected to
32   target.
33
34-----
35Usage
36-----
37.. code-block:: cpp
38
39   constexpr uint32_t kI2CBaudRate = 100000;
40   constexpr McuxpressoInitiator::Config kConfig = {
41       .flexcomm_address = I2C11_BASE,
42       .clock_name = kCLOCK_Flexcomm11Clk,
43       .baud_rate_bps = kI2CBaudRate,
44   };
45   McuxpressoInitiator initiator{kConfig};
46   initiator.Enable();
47
48``I3cMcuxpressoInitiator`` example usage.
49
50.. code-block:: cpp
51
52   constexpr I3cMcuxpressoInitiator::Config kI3c0Config = {
53    .base_address = I3C0_BASE,
54    .i2c_baud_rate = kI3cI2cBaudRate,
55    .i3c_open_drain_baud_rate = kI3cOpenDrainBaudRate,
56    .i3c_push_pull_baud_rate = kI3cPushPullBaudRate,
57    .enable_open_drain_stop = false,  // NXP default
58    .enable_open_drain_high = true,   // necessary to allow bus to operate in
59                                      // mixed mode
60   };
61
62   I3cMcuxpressoInitiator i3c_0_initiator{kI3c0Config};
63
64   const std::array dynamic_address_list = {kDynamicAddress};
65   PW_TRY(i3c_initiator.SetDynamicAddressList(dynamic_address_list));
66   PW_TRY(i3c_initiator.Initialize());
67