\section{kernel/lcd.c File Reference}
\label{lcd_8c}\index{kernel/lcd.c@{kernel/lcd.c}}
Implementation: wrapper for ROM LCD number display functions. 

{\tt \#include $<$config.h$>$}\par
{\tt \#include $<$dlcd.h$>$}\par
{\tt \#include $<$conio.h$>$}\par
{\tt \#include $<$string.h$>$}\par
{\tt \#include $<$sys/h8.h$>$}\par
{\tt \#include $<$sys/lcd.h$>$}\par
{\tt \#include $<$rom/registers.h$>$}\par
{\tt \#include $<$lnp/sys/irq.h$>$}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define {\bf set}(b)\ \_\-\_\-asm\_\-\_\- \_\-\_\-volatile\_\-\_\-(\char`\"{}bset \%0,@0xbb:8\char`\"{} : : \char`\"{}i\char`\"{}(b));
\begin{CompactList}\small\item\em set single bit convenience macro \item\end{CompactList}\item 
\#define {\bf clr}(b)\ \_\-\_\-asm\_\-\_\- \_\-\_\-volatile\_\-\_\-(\char`\"{}bclr \%0,@0xbb:8\char`\"{} : : \char`\"{}i\char`\"{}(b));
\begin{CompactList}\small\item\em clear single bit convenience macro \item\end{CompactList}\item 
\#define {\bf slowdown}()
\begin{CompactList}\small\item\em generate the necessary delay for the i2c bus. \item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void {\bf lcd\_\-number} (int i, {\bf lcd\_\-number\_\-style} n, {\bf lcd\_\-comma\_\-style} c)
\begin{CompactList}\small\item\em show number on LCD display \item\end{CompactList}\item 
{\bf \_\-\_\-asm\_\-\_\-} (\char`\"{}$\backslash$n$\backslash$
.text$\backslash$n$\backslash$
.align 1$\backslash$n$\backslash$
.globl \_\-lcd\_\-number$\backslash$n$\backslash$
\_\-lcd\_\-number:$\backslash$n$\backslash$
        push r6         ; save r6$\backslash$n$\backslash$
    $\backslash$n$\backslash$
        push r2         ; comma\_\-style   $\rightarrow$  stack$\backslash$n$\backslash$
        push r0         ; number        $\rightarrow$  stack$\backslash$n$\backslash$
    $\backslash$n$\backslash$
        mov.w r1,r6     ; number\_\-style  $\rightarrow$  r6$\backslash$n$\backslash$
    $\backslash$n$\backslash$
        jsr @lcd\_\-number ; call ROM$\backslash$n$\backslash$
    $\backslash$n$\backslash$
        adds \#0x02,sp   ; clear stack$\backslash$n$\backslash$
        adds \#0x02,sp$\backslash$n$\backslash$
        $\backslash$n$\backslash$
        pop r6          ; restore r6$\backslash$n$\backslash$
        rts$\backslash$n$\backslash$
        $\backslash$n$\backslash$
       \char`\"{})
\item 
\_\-\_\-inline\_\-\_\- void {\bf i2c\_\-start} (void)
\begin{CompactList}\small\item\em generate an i2c start condition. \item\end{CompactList}\item 
\_\-\_\-inline\_\-\_\- void {\bf i2c\_\-stop} (void)
\begin{CompactList}\small\item\em generate an i2c stop condition. \item\end{CompactList}\item 
\_\-\_\-inline\_\-\_\- void {\bf i2c\_\-read\_\-ack} (void)
\begin{CompactList}\small\item\em read the acknoledge from the i2c bus. \item\end{CompactList}\item 
\_\-\_\-inline\_\-\_\- void {\bf i2c\_\-write} (unsigned char val)
\begin{CompactList}\small\item\em write one byte to the i2c bus. \item\end{CompactList}\item 
void {\bf lcd\_\-write\_\-data} (unsigned char $\ast$data, unsigned char len)
\begin{CompactList}\small\item\em write an array of bytes to the i2c bus. \item\end{CompactList}\item 
void {\bf lcd\_\-refresh} (void)
\begin{CompactList}\small\item\em show LCD display contents to the world \item\end{CompactList}\item 
void {\bf lcd\_\-power\_\-on} (void)
\begin{CompactList}\small\item\em power on LCD display, also called from {\bf lcd\_\-init()}{\rm (p.\,\pageref{sys_2lcd_8h_a13})} \item\end{CompactList}\item 
void {\bf lcd\_\-power\_\-off} (void)
\begin{CompactList}\small\item\em power off LCD display \item\end{CompactList}\item 
void {\bf lcd\_\-init} (void)
\begin{CompactList}\small\item\em initialize LCD driver \item\end{CompactList}\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
unsigned char {\bf lcd\_\-shadow} [LCD\_\-DATA\_\-OFFSET+LCD\_\-DATA\_\-SIZE]
\begin{CompactList}\small\item\em lcd\_\-shadow buffer: \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Implementation: wrapper for ROM LCD number display functions. 

\begin{Desc}
\item[Author:]Markus L. Noga $<${\tt markus@noga.de}$>$\end{Desc}


Definition in file {\bf lcd.c}.

\subsection{Define Documentation}
\index{lcd.c@{lcd.c}!clr@{clr}}
\index{clr@{clr}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define clr(b)\ \_\-\_\-asm\_\-\_\- \_\-\_\-volatile\_\-\_\-(\char`\"{}bclr \%0,@0xbb:8\char`\"{} : : \char`\"{}i\char`\"{}(b));}\label{lcd_8c_a1}


clear single bit convenience macro 



Definition at line 113 of file lcd.c.

Referenced by i2c\_\-read\_\-ack(), i2c\_\-start(), i2c\_\-stop(), i2c\_\-write(), lcd\_\-init(), and lcd\_\-power\_\-off().\index{lcd.c@{lcd.c}!set@{set}}
\index{set@{set}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define set(b)\ \_\-\_\-asm\_\-\_\- \_\-\_\-volatile\_\-\_\-(\char`\"{}bset \%0,@0xbb:8\char`\"{} : : \char`\"{}i\char`\"{}(b));}\label{lcd_8c_a0}


set single bit convenience macro 



Definition at line 111 of file lcd.c.

Referenced by i2c\_\-read\_\-ack(), i2c\_\-start(), i2c\_\-stop(), and i2c\_\-write().\index{lcd.c@{lcd.c}!slowdown@{slowdown}}
\index{slowdown@{slowdown}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define slowdown()}\label{lcd_8c_a2}


generate the necessary delay for the i2c bus. 

the h8/300 at 16 MHz is slow enough to run without delay, when running this code from RAM. There might be some delay necessary when running from ROM. 

Definition at line 121 of file lcd.c.

Referenced by i2c\_\-read\_\-ack(), i2c\_\-start(), i2c\_\-stop(), and i2c\_\-write().

\subsection{Function Documentation}
\index{lcd.c@{lcd.c}!__asm__@{\_\-\_\-asm\_\-\_\-}}
\index{__asm__@{\_\-\_\-asm\_\-\_\-}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\_\-\_\-asm\_\-\_\- (\char`\"{}$\backslash$n$\backslash$.text$\backslash$n$\backslash$.align 1$\backslash$n$\backslash$.globl \_\-lcd\_\-number$\backslash$n$\backslash$\_\-lcd\_\-number:$\backslash$n$\backslash$ push r6 ; save r6$\backslash$n$\backslash$ $\backslash$n$\backslash$ push r2 ; comma\_\-style  $\rightarrow$  stack$\backslash$n$\backslash$ push r0 ; number  $\rightarrow$  stack$\backslash$n$\backslash$ $\backslash$n$\backslash$ mov.w  {\em r1}, r6;number\_\-style $\rightarrow$  r6$\backslash$n$\backslash$$\backslash$n$\backslash$jsr @lcd\_\-number;call ROM$\backslash$n$\backslash$$\backslash$n$\backslash$adds\# {\em 0x02}, sp;clear stack$\backslash$n$\backslash$adds\# {\em 0x02}, sp$\backslash$n$\backslash$$\backslash$n$\backslash$pop r6;restore r6$\backslash$n$\backslash$rts$\backslash$n$\backslash$$\backslash$n$\backslash$\char`\"{})}\label{lcd_8c_a5}




Referenced by dbutton(), disable\_\-irqs(), enable\_\-irqs(), lcd\_\-clear(), lcd\_\-hide(), lcd\_\-show(), memcpy(), memset(), power\_\-init(), power\_\-off(), sound\_\-playing(), and sound\_\-system().\index{lcd.c@{lcd.c}!i2c_read_ack@{i2c\_\-read\_\-ack}}
\index{i2c_read_ack@{i2c\_\-read\_\-ack}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\_\-\_\-inline\_\-\_\- void i2c\_\-read\_\-ack (void)\hspace{0.3cm}{\tt  [static]}}\label{lcd_8c_a8}


read the acknoledge from the i2c bus. 

Warning: the value of the acknoledge is ignored. We can't do much on errors anyway. 

Definition at line 153 of file lcd.c.

References clr, PORT6\_\-DDR, rom\_\-port6\_\-ddr, SCL, set, and slowdown.

Referenced by lcd\_\-write\_\-data().\index{lcd.c@{lcd.c}!i2c_start@{i2c\_\-start}}
\index{i2c_start@{i2c\_\-start}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\_\-\_\-inline\_\-\_\- void i2c\_\-start (void)\hspace{0.3cm}{\tt  [static]}}\label{lcd_8c_a6}


generate an i2c start condition. 



Definition at line 124 of file lcd.c.

References clr, SCL, SDA, set, and slowdown.

Referenced by lcd\_\-write\_\-data().\index{lcd.c@{lcd.c}!i2c_stop@{i2c\_\-stop}}
\index{i2c_stop@{i2c\_\-stop}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\_\-\_\-inline\_\-\_\- void i2c\_\-stop (void)\hspace{0.3cm}{\tt  [static]}}\label{lcd_8c_a7}


generate an i2c stop condition. 



Definition at line 136 of file lcd.c.

References clr, SCL, SDA, set, and slowdown.

Referenced by lcd\_\-write\_\-data().\index{lcd.c@{lcd.c}!i2c_write@{i2c\_\-write}}
\index{i2c_write@{i2c\_\-write}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\_\-\_\-inline\_\-\_\- void i2c\_\-write (unsigned char {\em val})\hspace{0.3cm}{\tt  [static]}}\label{lcd_8c_a9}


write one byte to the i2c bus. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em val}]byte to write to the i2c bus \end{description}
\end{Desc}


Definition at line 169 of file lcd.c.

References clr, SCL, SDA, set, and slowdown.

Referenced by lcd\_\-write\_\-data().\index{lcd.c@{lcd.c}!lcd_init@{lcd\_\-init}}
\index{lcd_init@{lcd\_\-init}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void lcd\_\-init (void)}\label{lcd_8c_a14}


initialize LCD driver 

output drivers are configured as outputs. the lcd\_\-shadow buffer is cleared and initialized. the LCD controller is enabled. 

Definition at line 295 of file lcd.c.

References clr, LCD\_\-DEV\_\-ID, lcd\_\-power\_\-on(), lcd\_\-shadow, memset(), PORT6\_\-DDR, rom\_\-port6\_\-ddr, SCL, and SDA.

Referenced by kmain().\index{lcd.c@{lcd.c}!lcd_number@{lcd\_\-number}}
\index{lcd_number@{lcd\_\-number}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void lcd\_\-number (int {\em i}, {\bf lcd\_\-number\_\-style} {\em n}, {\bf lcd\_\-comma\_\-style} {\em c})}\label{lcd_8c_a4}


show number on LCD display 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em i}]the number \item[{\em n}]a number style \item[{\em c}]a comma style \end{description}
\end{Desc}
\index{lcd.c@{lcd.c}!lcd_power_off@{lcd\_\-power\_\-off}}
\index{lcd_power_off@{lcd\_\-power\_\-off}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void lcd\_\-power\_\-off (void)}\label{lcd_8c_a13}


power off LCD display 

the LCD controller is put in low power mode and output drivers to the LCD controller are disabled.

Note: without disabling the output drivers the CPU will not save power in sleep mode. 

Definition at line 279 of file lcd.c.

References clr, LCD\_\-MODE\_\-SET, lcd\_\-refresh(), lcd\_\-shadow, LCD\_\-SHORT\_\-CMD, lcd\_\-write\_\-data(), SCL, and SDA.

Referenced by kmain().\index{lcd.c@{lcd.c}!lcd_power_on@{lcd\_\-power\_\-on}}
\index{lcd_power_on@{lcd\_\-power\_\-on}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void lcd\_\-power\_\-on (void)}\label{lcd_8c_a12}


power on LCD display, also called from {\bf lcd\_\-init()}{\rm (p.\,\pageref{sys_2lcd_8h_a13})} 

the LCD controller is enabled. 

Definition at line 266 of file lcd.c.

References LCD\_\-MODE\_\-SET, lcd\_\-shadow, LCD\_\-SHORT\_\-CMD, and lcd\_\-write\_\-data().

Referenced by lcd\_\-init().\index{lcd.c@{lcd.c}!lcd_refresh@{lcd\_\-refresh}}
\index{lcd_refresh@{lcd\_\-refresh}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void lcd\_\-refresh (void)}\label{lcd_8c_a11}


show LCD display contents to the world 

the entire 9 bytes of display\_\-memory are written to the LCD controller unconditionally. lcd\_\-shadow is updated to the new values. 

Definition at line 254 of file lcd.c.

References display\_\-memory, LCD\_\-LONG\_\-CMD, lcd\_\-shadow, and lcd\_\-write\_\-data().

Referenced by kmain(), lcd\_\-power\_\-off(), show\_\-off(), and show\_\-on().\index{lcd.c@{lcd.c}!lcd_write_data@{lcd\_\-write\_\-data}}
\index{lcd_write_data@{lcd\_\-write\_\-data}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void lcd\_\-write\_\-data (unsigned char $\ast$ {\em data}, unsigned char {\em len})\hspace{0.3cm}{\tt  [static]}}\label{lcd_8c_a10}


write an array of bytes to the i2c bus. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em data}]array of bytes to write to the i2c bus \item[{\em len}]number of bytes to write\end{description}
\end{Desc}
len bytes are written to the i2c bus, including initial start condition and final stop condition. The first byte must contain a device address and the r/w flag. 

Definition at line 195 of file lcd.c.

References i2c\_\-read\_\-ack(), i2c\_\-start(), i2c\_\-stop(), and i2c\_\-write().

Referenced by lcd\_\-power\_\-off(), lcd\_\-power\_\-on(), and lcd\_\-refresh().

\subsection{Variable Documentation}
\index{lcd.c@{lcd.c}!lcd_shadow@{lcd\_\-shadow}}
\index{lcd_shadow@{lcd\_\-shadow}!lcd.c@{lcd.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}unsigned char {\bf lcd\_\-shadow}[LCD\_\-DATA\_\-OFFSET+LCD\_\-DATA\_\-SIZE]\hspace{0.3cm}{\tt  [static]}}\label{lcd_8c_a3}


lcd\_\-shadow buffer: 

contains the last display\_\-memory bytes written to the LCD controller at position LCD\_\-DATA\_\-OFFSET.

lcd\_\-shadow also contains the buffer for the i2c commands written to the LCD controller.

At offset LCD\_\-SHORT\_\-CMD a small piece of memory is reserved for direct commands to the LCD controller. This is used for power on/off, and for single byte updates.

At offset LCD\_\-LONG\_\-CMD a small piece of memory is reserved for the i2c command header to do a full LCD update. The display data directly follows this header.

The entire buffer in memory looks like this:

0 1 2 3 4 5 +------+------+------+------+------+--- ---+ $|$ Addr $|$ Cmd $|$ Data $|$ Addr $|$ 0x00 $|$ display data (9 bytes) $|$ +------+------+------+------+------+--- ---+ / / LCD\_\-SHORT\_\-CMD LCD\_\-LONG\_\-CMD with display data 

Definition at line 72 of file lcd.c.

Referenced by lcd\_\-init(), lcd\_\-power\_\-off(), lcd\_\-power\_\-on(), and lcd\_\-refresh().