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