Update examples.
[bertos.git] / examples / lm3s1968 / hw / hw_rit128x96.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \brief LM3S1986: OLED-RIT-128x96 (P14201) low-level hardware macros
34  *
35  * \author Andrea Righi <arighi@develer.com>
36  */
37
38 #ifndef HW_RIT128x96_H
39 #define HW_RIT128x96_H
40
41 #include "cfg/macros.h"   /* BV() */
42 #include "cfg/debug.h"
43
44 #include <cpu/attr.h>
45 #include <cpu/irq.h>
46 #include <cpu/types.h>
47
48 #include <drv/clock_lm3s.h>
49 #include <drv/ssi_lm3s.h>
50 #include <drv/gpio_lm3s.h>
51
52 /**
53  * \name LCD I/O pins/ports
54  * @{
55  */
56 /* OLED Data/Command control pin */
57 #define GPIO_OLEDDC_PIN             BV(2)
58
59 /* OLED enable pin */
60 #define GPIO_OLEDEN_PIN             BV(3)
61 /*@}*/
62
63 /**
64  * \name LCD bus control macros
65  * @{
66  */
67 /* Enter command mode */
68 #define LCD_SET_COMMAND() \
69         lm3s_gpioPinWrite(GPIO_PORTH_BASE, GPIO_OLEDDC_PIN, 0)
70
71 /* Enter data mode */
72 #define LCD_SET_DATA() \
73         lm3s_gpioPinWrite(GPIO_PORTH_BASE, GPIO_OLEDDC_PIN, GPIO_OLEDDC_PIN)
74
75 /* Send data to the display */
76 #define LCD_WRITE(x)                                                    \
77         {                                                               \
78                 uint32_t _x;                                            \
79                 while (!lm3s_ssiWriteFrameNonBlocking(SSI0_BASE, x));   \
80                 /* Dummy read to drain the FIFO */                      \
81                 while (!lm3s_ssiReadFrameNonBlocking(SSI0_BASE, &_x));  \
82         }
83 /*@}*/
84
85 INLINE void lcd_rit128x96_hw_bus_init(void)
86 {
87         uint32_t dummy;
88
89         /* Enable the peripheral clock */
90         SYSCTL_RCGC1_R |= SYSCTL_RCGC1_SSI0;
91         SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOA;
92         SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOH;
93         lm3s_busyWait(512);
94
95         /* Configure the SSI0CLK and SSIOTX pins for SSI operation. */
96         lm3s_gpioPinConfig(GPIO_PORTA_BASE, BV(2) | BV(3) | BV(5),
97                 GPIO_DIR_MODE_HW, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU);
98         /*
99          * Configure the GPIO port pin used as a D/C# signal (data/command
100          * control) for OLED device, and the port pin used to enable power to
101          * the OLED panel.
102          */
103         lm3s_gpioPinConfig(GPIO_PORTH_BASE, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN,
104                 GPIO_DIR_MODE_OUT, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
105         lm3s_gpioPinWrite(GPIO_PORTH_BASE, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN,
106                         GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN);
107
108         /* Configure the SSI0 port for master mode */
109         lm3s_ssiOpen(SSI0_BASE, SSI_FRF_MOTO_MODE_2,
110                         SSI_MODE_MASTER, CPU_FREQ / 2, 8);
111         /*
112          * Configure the GPIO port pin used as a D/Cn signal for OLED device,
113          * and the port pin used to enable power to the OLED panel.
114          */
115         lm3s_gpioPinConfig(GPIO_PORTA_BASE, GPIO_OLEDEN_PIN,
116                 GPIO_DIR_MODE_HW, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU);
117
118         /* Drain the SSI RX FIFO */
119         while (lm3s_ssiReadFrameNonBlocking(SSI0_BASE, &dummy));
120 }
121
122 #endif /* HW_RIT128x96_H */