Skip to content

Commit 1b13590

Browse files
committed
Update to Zephyr best practices as of May 2024
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
1 parent 6c755f3 commit 1b13590

1 file changed

Lines changed: 25 additions & 46 deletions

File tree

slides.tex

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
}{Gerard Marull-Paretas}
4646
}
4747
\institute{Nordic Semiconductor ASA}
48-
\date{7\textsuperscript{th} June 2022}
48+
\date{20\textsuperscript{th} May 2024}
4949

5050
% document ---------------------------------------------------------------------
5151

@@ -173,19 +173,16 @@ \subsection{Devicetree}
173173
soc {
174174
i2c0: i2c@40003000 {
175175
compatible = "nordic,nrf-twim";
176-
label = "I2C0";
177176
reg = <0x40003000 0x1000>;
178177

179178
apds9960@39 {
180179
compatible = "avago,apds9960";
181-
label = "APDS9960";
182180
reg = <0x39>;
183181
};
184182

185183
ti_hdc@43 {
186184
compatible = "ti,hdc",
187185
"ti,hdc1010";
188-
label = "HDC1010";
189186
reg = <0x43>;
190187
};
191188
};
@@ -245,14 +242,12 @@ \subsection{Devicetree}
245242
\texttt{compatible} & %
246243
Name of the \textbf{hardware} a node \textbf{represents}, typically
247244
\texttt{vendor,device}. Used to find the \textbf{bindings} for the node. \\
248-
\texttt{label} & %
249-
\textbf{Name} of the device (unique). \\
250245
\texttt{reg} & %
251246
Information used to \textbf{address} the device (optional). Value
252247
meaning depends on the device. In general, it is a
253248
\textbf{sequence of address-length pairs.} \\
254249
\texttt{status} & %
255-
\textbf{Status} of the device. \texttt{okay} (default if not specified)
250+
\textbf{Status} of the device.\ \texttt{okay} (default if not specified)
256251
or \texttt{disabled}. \\
257252
\bottomrule
258253
\end{tabular}
@@ -298,15 +293,13 @@ \subsection{Devicetree}
298293
/* one instance of 'nordic,nrf-twim' */
299294
i2c0: i2c@40003000 {
300295
compatible = "nordic,nrf-twim";
301-
label = "I2C_0";
302296
reg = <0x40003000 0x1000>;
303297
clock-frequency = <I2C_BITRATE_STANDARD>;
304298
};
305299

306300
/* another instance of 'nordic,nrf-twim' */
307301
i2c1: i2c@40004000 {
308302
compatible = "nordic,nrf-twim"
309-
label = "I2C_1";
310303
reg = <0x40004000 0x1000>;
311304
clock-frequency = <I2C_BITRATE_FAST>;
312305
};
@@ -426,7 +419,7 @@ \subsection{Devicetree}
426419
\item \textbf{Content} of Devicetree, including data types, is
427420
\textbf{described} in \textbf{binding} files
428421
\item Binding files are used by the Devicetree parser to
429-
\textbf{validate content}
422+
\textbf{validate content} (i.e.\ schema)
430423
\item Binding files are written in \textbf{YAML}, structure custom to
431424
Zephyr
432425
\end{itemize}
@@ -452,8 +445,7 @@ \subsection{Devicetree}
452445
/ {
453446
dev0: dev@deadbeef {
454447
?\tikzmark{dtcompat}?compatible = "vnd,dev"
455-
?\tikzmark{dtbaseprop1}?label = "DEV0";
456-
?\tikzmark{dtbaseprop2}?reg = <0xdeadbeef>;
448+
?\tikzmark{dtbaseprop}?reg = <0xdeadbeef>;
457449
?\tikzmark{dtprop}?foo = <7>;
458450
};
459451
};
@@ -465,8 +457,7 @@ \subsection{Devicetree}
465457

466458
\begin{tikzpicture}[overlay,remember picture]
467459
\draw[->] (pic cs:dtcompat) to[out=180,in=0] (pic cs:bindingcompat);
468-
\draw[->] (pic cs:dtbaseprop1) to[out=180,in=0] (pic cs:bindingbaseprop);
469-
\draw[->] (pic cs:dtbaseprop2) to[out=180,in=0] (pic cs:bindingbaseprop);
460+
\draw[->] (pic cs:dtbaseprop) to[out=180,in=0] (pic cs:bindingbaseprop);
470461
\draw[->] (pic cs:dtprop) to[out=180,in=0] (pic cs:bindingprop);
471462
\end{tikzpicture}
472463
\end{frame}
@@ -794,7 +785,7 @@ \subsection{Zephyr devices}
794785
struct device {
795786
const char *name;
796787
const void *config;
797-
void * const data;
788+
void * data;
798789
const void *api;
799790
...
800791
};
@@ -810,14 +801,12 @@ \subsection{Zephyr devices}
810801
Field & Purpose \\
811802
\midrule
812803
\texttt{name} & %
813-
Device name (unique), corresponds to the \textbf{\texttt{label}}
814-
property for Devicetree devices \\
804+
Device name (unique), corresponds to the Devicetree node name \\
815805
\texttt{config} & %
816-
Reference to \textbf{read-only configuration} set at
817-
\textbf{compile time}, tipically used to store Devicetree properties \\
806+
Reference to \textbf{immutable device configuration}, tipically used to
807+
store Devicetree properties \\
818808
\texttt{data} & %
819-
Reference to device \textbf{data} that needs to be modified at
820-
\textbf{runtime}, e.g.\ counter, state, etc. \\
809+
Reference to \textbf{mutable device data}, e.g.\ counter, state, etc.\\
821810
\texttt{api} & %
822811
Reference to the device \textbf{API operations} \\
823812
\bottomrule
@@ -996,7 +985,6 @@ \subsection{Example device driver}
996985
...
997986
accel: sensor@ff {
998987
compatible = "vnd,mysensor";
999-
label = "ACCEL"
1000988
reg = <0xff>;
1001989
int-gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>;
1002990
sample-freq = <1000>;
@@ -1035,7 +1023,7 @@ \subsection{Example device driver}
10351023
const struct device *dev = DEVICE_DT_GET_ONE(vnd_my_sensor);
10361024

10371025
/* get reference to a device at runtime, using name lookup */
1038-
const struct device *dev = device_get_binding("ACCEL");
1026+
const struct device *dev = device_get_binding("sensor@ff");
10391027
\end{minted}
10401028
\caption{Examples on how to obtain device references}
10411029
\end{listing}
@@ -1568,8 +1556,10 @@ \subsection{Coding session: JM-101 driver}
15681556
config JM101
15691557
bool "JM-101 fingerprint sensor"
15701558
default y
1571-
?\tikzmark{depends}?depends on GPIO && SERIAL && UART_INTERRUPT_DRIVEN && \
1572-
DT_HAS_ZEANTEC_JM101_ENABLED?\tikzmark{default}?
1559+
depends on DT_HAS_ZEANTEC_JM101_ENABLED?\tikzmark{default}?
1560+
?\tikzmark{select}?select GPIO
1561+
select SERIAL
1562+
select UART_INTERRUPT_DRIVEN
15731563
help
15741564
JM-101 fingerprint sensor.
15751565

@@ -1584,8 +1574,8 @@ \subsection{Coding session: JM-101 driver}
15841574
\end{listing}
15851575

15861576
\begin{tikzpicture}[overlay,remember picture]
1587-
\draw[->] ($(pic cs:depends) +(-2ex,4.7em)$) to[out=180,in=180] (pic cs:depends);
1588-
\node[anchor=west] at ($(pic cs:depends) +(-2ex,4.7em)$) {Software Dependencies};
1577+
\draw[->] ($(pic cs:select) +(-2ex,6em)$) to[out=180,in=180] (pic cs:select);
1578+
\node[anchor=west] at ($(pic cs:select) +(-2ex,6em)$) {Software Dependencies (selected)};
15891579
\draw[->] ($(pic cs:default) +(5ex,3.5em)$) to[out=270,in=0] (pic cs:default);
15901580
\node[anchor=south] at ($(pic cs:default) +(5ex,3.5em)$) {Depends on being enabled in DT};
15911581
\end{tikzpicture}
@@ -1755,7 +1745,7 @@ \subsection{Coding session: JM-101 driver}
17551745
...
17561746
#ifdef CONFIG_JM101_TRIGGER
17571747
if (config->touch.port != NULL) {
1758-
if (!device_is_ready(config->touch.port)) {
1748+
if (!gpio_is_ready_dt(&config->touch)) {
17591749
LOG_ERR("Touch GPIO controller not ready");
17601750
return -ENODEV;
17611751
}
@@ -1835,18 +1825,12 @@ \subsection{Using the JM-101 driver}
18351825
\item JM-101 sensor driver is enabled when \texttt{CONFIG\_JM101=y}
18361826
\item \texttt{CONFIG\_JM101} is automatically enabled if:
18371827
\begin{itemize}
1838-
\item All its \textbf{dependencies} are \textbf{enabled}, including
1839-
\texttt{CONFIG\_SENSOR}
1828+
\item Its driver class is enabledm i.e.\ \texttt{CONFIG\_SENSOR}
18401829
\item One or more instances are \texttt{okay} in Devicetree
18411830
\end{itemize}
18421831
\end{itemize}
18431832
\begin{listing}[H]
18441833
\begin{minted}[fontsize=\tiny]{kconfig}
1845-
# dependencies required so that JM-101 driver can be enabled
1846-
CONFIG_GPIO=y
1847-
CONFIG_SERIAL=y
1848-
CONFIG_UART_INTERRUPT_DRIVEN=y
1849-
18501834
# enable the sensor driver class
18511835
CONFIG_SENSOR=y
18521836

@@ -2439,7 +2423,9 @@ \subsection{Coding session: servo-driven lock}
24392423
config LOCK_SERVO
24402424
bool "Servo-controlled lock"
24412425
default y
2442-
depends on PWM && ADC && DT_HAS_LOCK_SERVO_ENABLED
2426+
depends on DT_HAS_LOCK_SERVO_ENABLED
2427+
select PWM
2428+
select ADC
24432429
help
24442430
Enables a servo-controlled lock driver.
24452431

@@ -2456,10 +2442,8 @@ \subsection{Coding session: servo-driven lock}
24562442
add_subdirectory(drivers)
24572443

24582444
zephyr_include_directories(include)
2459-
24602445
# optional, only needed for userspace support
2461-
list(APPEND SYSCALL_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)
2462-
set(SYSCALL_INCLUDE_DIRS ${SYSCALL_INCLUDE_DIRS} PARENT_SCOPE)
2446+
zephyr_syscall_include_directories(include)
24632447
\end{minted}
24642448
\caption{\texttt{\$ROOT/CMakeLists.txt}}
24652449
\end{listing}
@@ -2560,7 +2544,7 @@ \subsection{Using the servo-driven lock driver}
25602544
closed-pulse-us = <1250>;
25612545
io-channels = <&adc 0>;
25622546
fb-gain = <(-1765)>;
2563-
fb-offset = <4206250>;
2547+
fb-offset-microvolt = <4206250>;
25642548
max-target-err-us = <50>;
25652549
max-action-time-ms = <2000>;
25662550
};
@@ -2627,17 +2611,12 @@ \subsection{Using the servo-driven lock driver}
26272611
\texttt{CONFIG\_LOCK\_SERVO=y}
26282612
\item \texttt{CONFIG\_LOCK\_SERVO} is automatically enabled if:
26292613
\begin{itemize}
2630-
\item All its \textbf{dependencies} are \textbf{enabled}, including
2631-
\texttt{CONFIG\_LOCK}
2614+
\item Its driver class is enabled, i.e.\ \texttt{CONFIG\_LOCK}
26322615
\item One or more instances are \texttt{okay} in Devicetree
26332616
\end{itemize}
26342617
\end{itemize}
26352618
\begin{listing}[H]
26362619
\begin{minted}[fontsize=\tiny]{kconfig}
2637-
# dependencies required so that servo-driven lock driver can be enabled
2638-
CONFIG_ADC=y
2639-
CONFIG_PWM=y
2640-
26412620
# enable the lock driver class
26422621
CONFIG_LOCK=y
26432622
\end{minted}

0 commit comments

Comments
 (0)