diff --git a/ch.unit.1wire.tex b/ch.unit.1wire.tex index 1a1da42..cfc9cdd 100644 --- a/ch.unit.1wire.tex +++ b/ch.unit.1wire.tex @@ -1,6 +1,6 @@ \section{1-Wire Unit} -The 1-Wire unit implements the Dallas Semiconductor's 1-Wire protocol, most commonly used to interface smart thermometers (DS18x20). The protocol is explained in section \ref{sec:theory-1wire}. +The 1-Wire unit implements the Dallas Semiconductor's 1-Wire protocol, most commonly used to interface smart thermometers (DS18x20). The protocol is explained in section \ref{sec:theory-1wire}. This unit implements the ROM Search algorithm that is used to find the unique IDs of all 1-Wire devices connected to the bus. The algorithm can find up to 32 devices in one run; More devices can be found by issuing the SEARCH\_CONTINUE command. @@ -22,73 +22,69 @@ This unit generates no events. \subsection{1-Wire Commands} -\begin{tabularx}{\textwidth}{p{\fldwcode}Xp{\fldwpld}} - \toprule - \textbf{Code} & \textbf{Function} & \textbf{Payload} \\ - \midrule - - 0 & \flname{CHECK\_PRESENCE} +\begin{cmdlist} + + 0 & \cname{CHECK\_PRESENCE} Test if there are any devices attached to the bus. - & \makecell[tl]{ - \fldresp - \fld{u8} presence detected (0, 1) - } \\ - - 1 & \flname{SEARCH\_ADDR} + & \begin{cmdresp} + \cfield{u8} presence detected (0, 1) + \end{cmdresp} \\ + + 1 & \cname{SEARCH\_ADDR} Start the search algorithm. - & \makecell[tl]{ - \fldresp - \fld{u8} should continue (0, 1) \\ - \fld{u64[]} device addresses - } \\ + & \begin{cmdresp} + \cfield{u8} should continue (0, 1) + \cfield{u64[]} device addresses + \end{cmdresp} \\ - 2 & \flname{SEARCH\_ALARM} + 2 & \cname{SEARCH\_ALARM} Start the search algorithm, finding only devices in an alarm state. - & \makecell[tl]{ - \fldresp - \fld{u8} should continue (0, 1) \\ - \fld{u64[]} device addresses - } \\ + & \begin{cmdresp} + \cfield{u8} should continue (0, 1) + \cfield{u64[]} device addresses + \end{cmdresp} \\ - 3 & \flname{SEARCH\_CONTINUE} + 3 & \cname{SEARCH\_CONTINUE} Continue a previously started search - & \makecell[tl]{ - \fldresp - \fld{u8} should continue (0, 1) \\ - \fld{u64[]} device addresses - } \\ + & \begin{cmdresp} + \cfield{u8} should continue (0, 1) + \cfield{u64[]} device addresses + \end{cmdresp} \\ - 4 & \flname{READ\_ADDR} + 4 & \cname{READ\_ADDR} Read a device address (single device only) - & \makecell[tl]{ - \fldresp - \fld{u64} device address - } \\ - - 10 & \flname{WRITE} + & \begin{cmdresp} + \cfield{u64} device address + \end{cmdresp} \\ + + 10 & \cname{WRITE} Write bytes to a device. - & \makecell[tl]{ - \fldreq - \fld{u64} device address \\ - \fld{u8[]} bytes to write - } \\ - - 11 & \flname{READ} + & \begin{cmdreq} + \cfield{u64} device address + \cfield{u8[]} bytes to write + \end{cmdreq} \\ + + 11 & \cname{READ} Write a request and read response. - & \makecell[tl]{ - \fldreq - \fld{u64} device address \\ - \fld{u16} read length \\ - \fld{u8} verify checksum (0, 1) \\ - \fld{u8[]} request bytes - } \\ - - 20 & \flname{POLL\_FOR\_1} - Wait for a READY status, used by DS18x20. - Not available in parasitic mode. + & + \begin{cmdreq} + \cfield{u64} device address + \cfield{u16} read length + \cfield{u8} verify checksum (0, 1) + \cfield{u8[]} request bytes + \end{cmdreq} + \cjoin + \begin{cmdresp} + \cfield{u8[]} read bytes + \end{cmdresp} + \\ + + 20 & \cname{POLL\_FOR\_1} + Wait for a READY status, used by DS18x20. + Not available in parasitic mode. Responds with SUCCESS after all devices are ready. - & \\ - \bottomrule -\end{tabularx} + & \\ + +\end{cmdlist} diff --git a/ch.unit.adc.tex b/ch.unit.adc.tex index d165071..31ccc78 100644 --- a/ch.unit.adc.tex +++ b/ch.unit.adc.tex @@ -75,7 +75,7 @@ avg_factor=500 Get the last raw sample from enabled channels. & \begin{cmdresp} - \cfield{u16[]} raw values 0-4095 + \cfield{u16[]} raw values 0--4095 \end{cmdresp} \\ @@ -83,7 +83,7 @@ avg_factor=500 Get the averaged values from enabled channels. Not available for high sample rates and when disabled. & \begin{cmdresp} - \cfield{float32[]} smoothed values 0-4095 + \cfield{float32[]} smoothed values 0--4095 \end{cmdresp} \\ diff --git a/document_config.tex b/document_config.tex index 6512652..874ad95 100755 --- a/document_config.tex +++ b/document_config.tex @@ -41,17 +41,26 @@ \newcommand{\fldresp}{\textit{Response}\newline} \newcommand\flname[1]{\textbf{#1}\newline} -\newcommand{\cfield}[1]{\item \texttt{#1:}} +\usepackage{mytabto} % customized tabto that does not break to a new line + +\newcommand{\cfield}[1]{\item \texttt{#1}\tabto{.8cm}} \newcommand{\cname}[1]{\textbf{#1}\newline} +\usepackage{ragged2e} + % https://tex.stackexchange.com/questions/157389/how-to-center-column-values-in-a-table % P will be a centered column that can have width \newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}} +% this is put before a response that follows a request +% this is needed because the request has a negative gap after itself +\newcommand*{\cjoin}{\null\vspace*{-2pt}} + % This is a table of commands of events \newenvironment{cmdlist} { - \tabulinesep=3pt +% \tabulinesep=3pt + \tabulinesep=7pt \begin{longtabu} to \textwidth {P{\fldwcode} X[3] X[3,l]} \toprule @@ -71,43 +80,54 @@ { %topsep=0pt,partopsep=0pt, \begin{itemize}[ - leftmargin=.5cm, + leftmargin=.7cm, nosep, - after = \vspace{-.7\baselineskip} % remove the weird newline after the list + %after = \vspace{-\baselineskip} ] } { \end{itemize} } + +% a list of request fields, with a caption +\newenvironment{cmditemlistenv}[1] +{ + \begin{minipage}[t]{\linewidth} +% \begin{flushleft} % fix weird spacing in wrapped lines + \textit{#1} \begin{cmdpldlist} +} +{ + \end{cmdpldlist} +% \end{flushleft} + \end{minipage} +} + % a list of request fields, with a caption \newenvironment{cmdreq} { - \textit{Request:} - \begin{cmdpldlist} + \begin{cmditemlistenv}{Request:} } { - \end{cmdpldlist} + \end{cmditemlistenv} } % a list of request fields, with a caption \newenvironment{cmdresp} { - \textit{Response:} - \begin{cmdpldlist} + \begin{cmditemlistenv}{Response:} } { - \end{cmdpldlist} + \end{cmditemlistenv} } % a list of payload fields, with a caption \newenvironment{cmdpld} { - \textit{Payload:} - \begin{cmdpldlist} + \begin{cmditemlistenv}{Payload:} } { - \end{cmdpldlist} + \end{cmditemlistenv} } diff --git a/mytabto.sty b/mytabto.sty new file mode 100644 index 0000000..ca431fc --- /dev/null +++ b/mytabto.sty @@ -0,0 +1,204 @@ +% tabto.sty +% +% version 1.3 (Mar 2013) +% +% Tabbing to fixed positions in a paragraph. +% +% Copyright 2006,2009,2012,2013 by +% Donald Arseneau, Vancouver, Canada (asnd@triumf.ca) +% Permission to use, distribute and modify this software is granted +% under the conditions of the LaTeX Project Public License, either +% version 1.3 or (at your option) any later version. The license is +% found at http://www.latex-project.org/lppl.txt, and is part of all +% recent distributions of LaTeX. +% +% This work has the LPPL maintenance status `maintained' (by author). +% +% Two new text positioning commands are defined: \tabto and \tab. +% +% \tabto{} +% Tab to a position relative to the left margin in a paragraph (any +% indentation due to a list or \leftskip is part of the `margin' in +% this context). If the text on the line already goes past the desired +% position, the tab starts a new line and moves to the requested +% horizontal position. +% +% \tabto*{} +% Similar to \tabto, except it will perform backspacing, and over- +% print previous text on the line whenever that text is already +% longer than the specified length (i.e., no linebreak is produced). +% Line-breaks are suppressed immediately after \tabto or \tabto*. +% +% The length register "\CurrentLineWidth" will report the width +% of the existing text on the line, and it may be used in the +% argument (using calc.sty, for example). Also, there +% is "\TabPrevPos" which gives the "\CurrentLineWidth" from the +% previous tab command, and can be used to return to that position +% if no line breaks have occurred in between. +% +% \tab +% Tab to the next tab-stop chosen from a list of tab positions, in +% the traditional style of typewriters. A \tab will always move +% to the next tab stop (or the next line), even if it is already +% exactly at a tab stop. Thus, "\tab" at the beginning of a line, +% or "\tab\tab" elsewhere skips a position. A linebreak is permitted +% immediately following a \tab, in case the ensuing text does not +% fit well in the remaining space. +% +% If you do not want to skip positions, use "\tabto{\NextTabStop}" +% instead of "\tab". This is particularly useful when you want to +% use \tab in some other command, but do not want to skip a column +% for the first item. +% +% The tab-stop positions are declared using either \TabPositions +% or \NumTabs: +% +% \TabPositions{, ,...} +% Declares the tab stops as a comma-separated list of positions +% relative to the left margin. A tab-stop at 0pt is implicit, and +% need not be listed. +% +% \NumTabs{} +% Declares a list of equally-spaced tabs, starting at the +% left margin and spanning \linewidth. For example \NumTabs{2} +% declares tab-stops at 0pt and 0.5\linewidth, the same as +% \TabPositions{0pt, 0.5\linewidth} or \TabPositions{0.5\linewidth} +% +% After these declarations, the list of tab positions is saved in +% \TabStopList, and the next tab position, relative to the current +% position, is given by \NextTabStop. You do not normally need +% to access them, but they are available. +% +% Problems: +% +% Tall objects after a tab stop may overlap the line above, rather +% than forcing a greater separation between lines. + +\ProvidesPackage{tabto}[2013/03/25 \space v 1.3 \space + Another tabbing mechanism]\relax + +\newdimen\CurrentLineWidth +\let\TabPrevPos\z@ + +\newcommand\tabto[1]{% + \leavevmode + \begingroup + \def\@tempa{*}\def\@tempb{#1}% + \ifx\@tempa\@tempb % \tab* + \endgroup + \TTo@overlaptrue % ... set a flag and re-issue \tabto to get argument + \expandafter\tabto + \else + \ifinner % in a \hbox, so ignore + \else % unrestricted horizontal mode + \null% \predisplaysize will tell the position of this box (must be box) + \parfillskip\fill + \everydisplay{}\everymath{}% + \predisplaypenalty\@M \postdisplaypenalty\@M + $$% math display so we can test \predisplaysize + \lineskiplimit=-999pt % so we get pure \baselineskip + \abovedisplayskip=-\baselineskip \abovedisplayshortskip=-\baselineskip + \belowdisplayskip\z@skip \belowdisplayshortskip\z@skip + \halign{##\cr\noalign{% + % get the width of the line above + \ifdim\predisplaysize=\maxdimen %\message{Mixed R and L, so say the line is full. }% + \CurrentLineWidth\linewidth + \else + \ifdim\predisplaysize=-\maxdimen + % \message{Not in a paragraph, so call the line empty. }% + \CurrentLineWidth\z@ + \else + \ifnum\TTo@Direction<\z@ + \CurrentLineWidth\linewidth \advance\CurrentLineWidth\predisplaysize + \else + \CurrentLineWidth\predisplaysize + \fi + % Correct the 2em offset + \advance\CurrentLineWidth -2em + \advance\CurrentLineWidth -\displayindent + \advance\CurrentLineWidth -\leftskip + \fi\fi + \ifdim\CurrentLineWidth<\z@ \CurrentLineWidth\z@\fi + % Enshrine the tab-to position; #1 might reference \CurrentLineWidth + \@tempdimb=#1\relax + %\message{*** Tab to \the\@tempdimb, previous width is \the\CurrentLineWidth. ***}% + % Save width for possible return use + \xdef\TabPrevPos{\the\CurrentLineWidth}% + % Build the action to perform + \protected@xdef\TTo@action{% + \vrule\@width\z@\@depth\the\prevdepth + \ifdim\CurrentLineWidth>\@tempdimb + \protect\hskip\the\CurrentLineWidth\hskip5pt\relax + \else + \protect\nobreak + \protect\hskip\the\@tempdimb\relax + \fi + }% + %\message{\string\TTo@action: \meaning \TTo@action. }% + % get back to the baseline, regardless of its depth. + \vskip-\prevdepth + \prevdepth-99\p@ + \vskip\prevdepth + }}% + $$ + % Don't count the display as lines in the paragraph + \count@\prevgraf \advance\count@-4 \prevgraf\count@ + \TTo@action + %% \penalty\@m % to allow a penalized line break + \fi + \endgroup + \TTo@overlapfalse + \ignorespaces + \fi +} + +% \tab -- to the next position +% \hskip so \tab\tab moves two positions +% Allow a (penalized but flexible) line-break right after the tab. +% +\newcommand\tab{\leavevmode\hskip2sp\tabto{\NextTabStop}% + \nobreak\hskip\z@\@plus 30\p@\penalty4000\hskip\z@\@plus-30\p@\relax} + + +% Expandable macro to select the next tab position from the list + +\newcommand\NextTabStop{% + \expandafter \TTo@nexttabstop \TabStopList,\maxdimen,>% +} + +\def\TTo@nexttabstop #1,{% + \ifdim#1<\CurrentLineWidth + \expandafter\TTo@nexttabstop + \else + \ifdim#1<0.9999\linewidth#1\else\z@\fi + \expandafter\strip@prefix + \fi +} +\def\TTo@foundtabstop#1>{} + +\newcommand\TabPositions[1]{\def\TabStopList{\z@,#1}} + +\newcommand\NumTabs[1]{% + \def\TabStopList{}% + \@tempdimb\linewidth + \divide\@tempdimb by#1\relax + \advance\@tempdimb 1sp % counteract rounding-down by \divide + \CurrentLineWidth\z@ + \@whiledim\CurrentLineWidth<\linewidth\do {% + \edef\TabStopList{\TabStopList\the\CurrentLineWidth,}% + \advance\CurrentLineWidth\@tempdimb + }% + \edef\TabStopList{\TabStopList\linewidth}% +} + +% default setting of tab positions: +\TabPositions{\parindent,.5\linewidth} + +\newif\ifTTo@overlap \TTo@overlapfalse + +\@ifundefined{predisplaydirection}{ + \let\TTo@Direction\predisplaysize + \let\predisplaydirection\@undefined +}{ + \let\TTo@Direction\predisplaydirection +} diff --git a/thesis.pdf b/thesis.pdf index 6db9c19..6fd9d47 100644 Binary files a/thesis.pdf and b/thesis.pdf differ