xref: /aosp_15_r20/external/pigweed/seed/0122.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _seed-0122:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker===================================
4*61c4878aSAndroid Build Coastguard Worker0122: Organize Pigweed code samples
5*61c4878aSAndroid Build Coastguard Worker===================================
6*61c4878aSAndroid Build Coastguard Worker.. seed::
7*61c4878aSAndroid Build Coastguard Worker   :number: 122
8*61c4878aSAndroid Build Coastguard Worker   :name: Organize Pigweed code samples
9*61c4878aSAndroid Build Coastguard Worker   :status: accepted
10*61c4878aSAndroid Build Coastguard Worker   :proposal_date: 2024-01-09
11*61c4878aSAndroid Build Coastguard Worker   :cl: 187121
12*61c4878aSAndroid Build Coastguard Worker   :authors: Ted Pudlik
13*61c4878aSAndroid Build Coastguard Worker   :facilitator: Kayce Basques
14*61c4878aSAndroid Build Coastguard Worker
15*61c4878aSAndroid Build Coastguard Worker-------
16*61c4878aSAndroid Build Coastguard WorkerSummary
17*61c4878aSAndroid Build Coastguard Worker-------
18*61c4878aSAndroid Build Coastguard WorkerThis SEED describes how Pigweed code samples will be organized. Implementation
19*61c4878aSAndroid Build Coastguard Workerbug: https://pwbug.dev//322816792.
20*61c4878aSAndroid Build Coastguard Worker
21*61c4878aSAndroid Build Coastguard Worker----------
22*61c4878aSAndroid Build Coastguard WorkerMotivation
23*61c4878aSAndroid Build Coastguard Worker----------
24*61c4878aSAndroid Build Coastguard WorkerPigweed users need to see code samples that demonstrate Pigweed in action.
25*61c4878aSAndroid Build Coastguard WorkerHowever, there are a few different use cases for such code samples.
26*61c4878aSAndroid Build Coastguard WorkerHistorically, we've not been explicit about what the use cases are, and how
27*61c4878aSAndroid Build Coastguard Workerthey should be served. This SEED will fill this gap.
28*61c4878aSAndroid Build Coastguard Worker
29*61c4878aSAndroid Build Coastguard Worker--------
30*61c4878aSAndroid Build Coastguard WorkerProposal
31*61c4878aSAndroid Build Coastguard Worker--------
32*61c4878aSAndroid Build Coastguard Worker
33*61c4878aSAndroid Build Coastguard WorkerRepositories
34*61c4878aSAndroid Build Coastguard Worker============
35*61c4878aSAndroid Build Coastguard WorkerPigweed will maintain the following types of code sample repositories:
36*61c4878aSAndroid Build Coastguard Worker
37*61c4878aSAndroid Build Coastguard Worker* **Quickstart**: `minimal, complete, reproducible
38*61c4878aSAndroid Build Coastguard Worker  <https://stackoverflow.com/help/minimal-reproducible-example>`_ projects you
39*61c4878aSAndroid Build Coastguard Worker  can clone to understand the basics of Pigweed and start a new `greenfield
40*61c4878aSAndroid Build Coastguard Worker  project <https://en.wikipedia.org/wiki/Greenfield_project>`_.  There will be
41*61c4878aSAndroid Build Coastguard Worker  one Quickstart repository for each build system that Pigweed supports.
42*61c4878aSAndroid Build Coastguard Worker* **Examples**: granular, comprehensive code examples of every Pigweed
43*61c4878aSAndroid Build Coastguard Worker  module's API. The Examples repository can also demonstrate core use cases
44*61c4878aSAndroid Build Coastguard Worker  that require using multiple modules together. There will only be one Examples
45*61c4878aSAndroid Build Coastguard Worker  repository.
46*61c4878aSAndroid Build Coastguard Worker* **Showcase**: Showstopper examples that demonstrate how to use Pigweed
47*61c4878aSAndroid Build Coastguard Worker  to implement complex real-world applications. There will be many Showcase
48*61c4878aSAndroid Build Coastguard Worker  repositories, each demonstrating a different application. These repositories
49*61c4878aSAndroid Build Coastguard Worker  should inspire users, show them how to implement complex integrations, and
50*61c4878aSAndroid Build Coastguard Worker  convince them that Pigweed is the best way to develop embedded projects.
51*61c4878aSAndroid Build Coastguard Worker
52*61c4878aSAndroid Build Coastguard WorkerStandard board
53*61c4878aSAndroid Build Coastguard Worker==============
54*61c4878aSAndroid Build Coastguard WorkerThe Quickstart and Examples repositories will eventually focus on a single
55*61c4878aSAndroid Build Coastguard Worker:ref:`seed-0122-standard-board`. But selecting the standard board is out of the
56*61c4878aSAndroid Build Coastguard Workerscope of this SEED.
57*61c4878aSAndroid Build Coastguard Worker
58*61c4878aSAndroid Build Coastguard Worker---------------
59*61c4878aSAndroid Build Coastguard WorkerDetailed design
60*61c4878aSAndroid Build Coastguard Worker---------------
61*61c4878aSAndroid Build Coastguard Worker
62*61c4878aSAndroid Build Coastguard Worker.. _seed-0122-quickstart:
63*61c4878aSAndroid Build Coastguard Worker
64*61c4878aSAndroid Build Coastguard WorkerQuickstart repository
65*61c4878aSAndroid Build Coastguard Worker=====================
66*61c4878aSAndroid Build Coastguard Worker* **User journeys** these repositories serve:
67*61c4878aSAndroid Build Coastguard Worker
68*61c4878aSAndroid Build Coastguard Worker  * "I want to clone a minimal repository to create my own project from
69*61c4878aSAndroid Build Coastguard Worker    scratch."
70*61c4878aSAndroid Build Coastguard Worker  * "I want to understand the smallest set of steps needed to add Pigweed as a
71*61c4878aSAndroid Build Coastguard Worker    dependency of my own existing project."
72*61c4878aSAndroid Build Coastguard Worker  * "I'm just getting started with Pigweed and want a tutorial that will
73*61c4878aSAndroid Build Coastguard Worker    put *some* code on device".
74*61c4878aSAndroid Build Coastguard Worker
75*61c4878aSAndroid Build Coastguard Worker* **Repository contents**: One repository per build system that demonstrates
76*61c4878aSAndroid Build Coastguard Worker  the minimal set of Pigweed features:
77*61c4878aSAndroid Build Coastguard Worker
78*61c4878aSAndroid Build Coastguard Worker  #.  Bootstrapping (downloading required tools, third-party dependencies, etc).
79*61c4878aSAndroid Build Coastguard Worker  #.  Building the minimal, viable, complete (MVC) application for
80*61c4878aSAndroid Build Coastguard Worker      :ref:`target-host` and for the :ref:`seed-0122-standard-board`.
81*61c4878aSAndroid Build Coastguard Worker  #.  Flashing the application to the board.
82*61c4878aSAndroid Build Coastguard Worker  #.  Communicating with the board via :ref:`module-pw_console`.
83*61c4878aSAndroid Build Coastguard Worker
84*61c4878aSAndroid Build Coastguard Worker  Determining the exact content of the MVC app is out-of-scope for this SEED.
85*61c4878aSAndroid Build Coastguard Worker  This is the subject of `SEED-0106
86*61c4878aSAndroid Build Coastguard Worker  <https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/155430>`_.
87*61c4878aSAndroid Build Coastguard Worker  However, every Quickstart repository will implement the same set of MVC
88*61c4878aSAndroid Build Coastguard Worker  features.
89*61c4878aSAndroid Build Coastguard Worker
90*61c4878aSAndroid Build Coastguard Worker  There will be tutorial documentation associated with each of these
91*61c4878aSAndroid Build Coastguard Worker  repositories, but it will be hosted in pigweed.git. Documentation generation
92*61c4878aSAndroid Build Coastguard Worker  with :ref:`module-pw_docgen` falls outside the scope of Quickstart.
93*61c4878aSAndroid Build Coastguard Worker
94*61c4878aSAndroid Build Coastguard Worker  We may also add separate Quickstart repositories for boards other than the
95*61c4878aSAndroid Build Coastguard Worker  "standard board".
96*61c4878aSAndroid Build Coastguard Worker
97*61c4878aSAndroid Build Coastguard Worker* **Locations**:
98*61c4878aSAndroid Build Coastguard Worker
99*61c4878aSAndroid Build Coastguard Worker  * https://pigweed.googlesource.com/pigweed/quickstart/bazel.git
100*61c4878aSAndroid Build Coastguard Worker  * https://pigweed.googlesource.com/pigweed/quickstart/gn.git
101*61c4878aSAndroid Build Coastguard Worker  * (No CMake quickstart. We offer support for integrating Pigweed into an
102*61c4878aSAndroid Build Coastguard Worker    existing CMake project, but don't recommend CMake for a greenfield Pigweed
103*61c4878aSAndroid Build Coastguard Worker    project and so have no quickstart repository for it.)
104*61c4878aSAndroid Build Coastguard Worker
105*61c4878aSAndroid Build Coastguard Worker.. _seed-0122-examples:
106*61c4878aSAndroid Build Coastguard Worker
107*61c4878aSAndroid Build Coastguard WorkerExamples repository
108*61c4878aSAndroid Build Coastguard Worker===================
109*61c4878aSAndroid Build Coastguard Worker* **User journeys** this repository serves:
110*61c4878aSAndroid Build Coastguard Worker
111*61c4878aSAndroid Build Coastguard Worker  * "I want to see an example of how a module's API is used in the context of a
112*61c4878aSAndroid Build Coastguard Worker    full, building project."
113*61c4878aSAndroid Build Coastguard Worker  * "I want to use tokenized logging, how do I hook this up?"
114*61c4878aSAndroid Build Coastguard Worker  * "I read you can customize the :ref:`module-pw_console`, can I see an example?"
115*61c4878aSAndroid Build Coastguard Worker  * "I want to see how to configure a backend of this module."
116*61c4878aSAndroid Build Coastguard Worker  * "How do I use method X from Pigweed module Y?"
117*61c4878aSAndroid Build Coastguard Worker  * "How do I use Pigweed modules A and B together?"
118*61c4878aSAndroid Build Coastguard Worker
119*61c4878aSAndroid Build Coastguard Worker* **Repository contents**: One repository that contains a bunch of directories.
120*61c4878aSAndroid Build Coastguard Worker  Each directory is meant to be consulted in isolation. Common use cases such
121*61c4878aSAndroid Build Coastguard Worker  as logging over UART or blinking an LED, may get their own directories.
122*61c4878aSAndroid Build Coastguard Worker  Related examples (e.g., examples for an individual module) may be grouped
123*61c4878aSAndroid Build Coastguard Worker  into a directory hierarchy for clarity.
124*61c4878aSAndroid Build Coastguard Worker
125*61c4878aSAndroid Build Coastguard Worker  The individual examples may define their own build targets, but they are not
126*61c4878aSAndroid Build Coastguard Worker  expected to set up independent builds. They're all part of one top-level build.
127*61c4878aSAndroid Build Coastguard Worker
128*61c4878aSAndroid Build Coastguard Worker  In general, it should be possible to build the examples using all of
129*61c4878aSAndroid Build Coastguard Worker  Pigweed's supported build systems (Bazel, CMake, GN). However, if the
130*61c4878aSAndroid Build Coastguard Worker  functionality being exemplified is only supported in some build systems (e.g.
131*61c4878aSAndroid Build Coastguard Worker  :ref:`module-pw_docgen` is only supported in GN as of this writing), then its
132*61c4878aSAndroid Build Coastguard Worker  examples can be restricted to those build systems.
133*61c4878aSAndroid Build Coastguard Worker
134*61c4878aSAndroid Build Coastguard Worker  Unlike Quickstart, this repository is a reference work: the user is not
135*61c4878aSAndroid Build Coastguard Worker  expected to read through it "from beginning to end". Rather, they will come
136*61c4878aSAndroid Build Coastguard Worker  here to view a specific example. We eventually expect to have hundreds or
137*61c4878aSAndroid Build Coastguard Worker  even thousands of examples.
138*61c4878aSAndroid Build Coastguard Worker
139*61c4878aSAndroid Build Coastguard Worker  The documentation for the Examples repo will be hosted at http://pigweed.dev,
140*61c4878aSAndroid Build Coastguard Worker  but will be built from source within the ``examples.git`` repo. Building
141*61c4878aSAndroid Build Coastguard Worker  documentation using :ref:`module-pw_docgen` is one of the things we're
142*61c4878aSAndroid Build Coastguard Worker  exemplifying.
143*61c4878aSAndroid Build Coastguard Worker
144*61c4878aSAndroid Build Coastguard Worker* **Location**: https://pigweed.googlesource.com/pigweed/examples.git
145*61c4878aSAndroid Build Coastguard Worker
146*61c4878aSAndroid Build Coastguard WorkerShowcase repositories
147*61c4878aSAndroid Build Coastguard Worker=====================
148*61c4878aSAndroid Build Coastguard Worker* **User journeys** these repositories serve:
149*61c4878aSAndroid Build Coastguard Worker
150*61c4878aSAndroid Build Coastguard Worker  * "I want to see a cool project built using Pigweed."
151*61c4878aSAndroid Build Coastguard Worker  * "I'm looking for a full-fledged demo of what Pigweed is capable of."
152*61c4878aSAndroid Build Coastguard Worker  * "I'm looking for a Show HN submission."
153*61c4878aSAndroid Build Coastguard Worker  * "I want to convince my team Pigweed is powerful enough for our use case."
154*61c4878aSAndroid Build Coastguard Worker  * "I need proof that Pigweed is a better way to develop embedded projects."
155*61c4878aSAndroid Build Coastguard Worker  * "I need proof that Pigweed is production-ready."
156*61c4878aSAndroid Build Coastguard Worker
157*61c4878aSAndroid Build Coastguard Worker* **Repository contents**: One repository per showcase project. These projects
158*61c4878aSAndroid Build Coastguard Worker  are standalone, with documentation that explains what they do. They're not
159*61c4878aSAndroid Build Coastguard Worker  necessarily easy to stand up yourself, and may require custom hardware that's
160*61c4878aSAndroid Build Coastguard Worker  hard to source. :ref:`Kudzu <docs-blog-01-kudzu>` and `Gonk
161*61c4878aSAndroid Build Coastguard Worker  <https://pigweed.googlesource.com/gonk.git>`_ are examples of showcase
162*61c4878aSAndroid Build Coastguard Worker  projects.
163*61c4878aSAndroid Build Coastguard Worker
164*61c4878aSAndroid Build Coastguard Worker* **Locations**: Showcase projects can be hosted anywhere. Open-source projects
165*61c4878aSAndroid Build Coastguard Worker  created by third parties and not hosted on https://pigweed.googlesource.com
166*61c4878aSAndroid Build Coastguard Worker  can also be showcases.
167*61c4878aSAndroid Build Coastguard Worker
168*61c4878aSAndroid Build Coastguard Worker  We will host a list of Showcase projects, with brief descriptions, at
169*61c4878aSAndroid Build Coastguard Worker  https://pigweed.dev/showcase.
170*61c4878aSAndroid Build Coastguard Worker
171*61c4878aSAndroid Build Coastguard Worker.. _seed-0122-standard-board:
172*61c4878aSAndroid Build Coastguard Worker
173*61c4878aSAndroid Build Coastguard WorkerStandard board
174*61c4878aSAndroid Build Coastguard Worker==============
175*61c4878aSAndroid Build Coastguard WorkerPigweed will select a "standard board" for use in our code samples. Today, the
176*61c4878aSAndroid Build Coastguard Workerde facto standard board is the STM32F429I-DISC1, but we expect to select a
177*61c4878aSAndroid Build Coastguard Workerdifferent standard board in the near future. Standard board selection will be
178*61c4878aSAndroid Build Coastguard Workerdiscussed in a separate followup SEED.
179*61c4878aSAndroid Build Coastguard Worker
180*61c4878aSAndroid Build Coastguard Worker----
181*61c4878aSAndroid Build Coastguard WorkerFAQs
182*61c4878aSAndroid Build Coastguard Worker----
183*61c4878aSAndroid Build Coastguard Worker
184*61c4878aSAndroid Build Coastguard Worker.. _seed-0122-existing-samples:
185*61c4878aSAndroid Build Coastguard Worker
186*61c4878aSAndroid Build Coastguard WorkerHow do existing code samples map to this scheme?
187*61c4878aSAndroid Build Coastguard Worker================================================
188*61c4878aSAndroid Build Coastguard Worker* `example/echo <https://pigweed.googlesource.com/pigweed/example/echo.git>`_
189*61c4878aSAndroid Build Coastguard Worker  will be renamed to become :ref:`seed-0122-quickstart` for Bazel.
190*61c4878aSAndroid Build Coastguard Worker* `sample_project
191*61c4878aSAndroid Build Coastguard Worker  <https://pigweed.googlesource.com/pigweed/sample_project.git>`_ will be
192*61c4878aSAndroid Build Coastguard Worker  renamed and reorganized to become the :ref:`seed-0122-examples`.
193*61c4878aSAndroid Build Coastguard Worker* `Kudzu <https://pigweed.googlesource.com/pigweed/kudzu.git>`_ and `Gonk
194*61c4878aSAndroid Build Coastguard Worker  <https://pigweed.googlesource.com/gonk.git>`_ are Showcase projects.
195*61c4878aSAndroid Build Coastguard Worker
196*61c4878aSAndroid Build Coastguard Worker
197*61c4878aSAndroid Build Coastguard WorkerWhat about inline code samples in the documentation?
198*61c4878aSAndroid Build Coastguard Worker====================================================
199*61c4878aSAndroid Build Coastguard WorkerWe will continue to provide inline code samples in the documentation, and later
200*61c4878aSAndroid Build Coastguard Workerin 2024 may prototype solutions for ensuring they compile and pass assertions.
201*61c4878aSAndroid Build Coastguard WorkerBut this is out of scope for this SEED.
202*61c4878aSAndroid Build Coastguard Worker
203*61c4878aSAndroid Build Coastguard Worker--------------
204*61c4878aSAndroid Build Coastguard WorkerOpen questions
205*61c4878aSAndroid Build Coastguard Worker--------------
206*61c4878aSAndroid Build Coastguard WorkerA followup SEED will discuss the selection of the "standard board" for Pigweed
207*61c4878aSAndroid Build Coastguard WorkerQuickstart and Examples repositories.
208*61c4878aSAndroid Build Coastguard Worker
209*61c4878aSAndroid Build Coastguard WorkerThe exact feature set of the MVC application demonstrated by the Quickstart
210*61c4878aSAndroid Build Coastguard Workerrepos is the subject of `SEED-0106
211*61c4878aSAndroid Build Coastguard Worker<https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/155430>`_.
212