lm3s1968: use the generic OLED-RIT-128x96 (P14201) driver in the example.
[bertos.git] / examples / lm3s1968 / hw / hw_lcd.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_LCD_H
39 #define HW_LCD_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 #include <drv/lcd_rit128x96.h>
53
54 /**
55  * \name LCD I/O pins/ports
56  * @{
57  */
58 /* OLED Data/Command control pin */
59 #define GPIO_OLEDDC_PIN             BV(2)
60
61 /* OLED enable pin */
62 #define GPIO_OLEDEN_PIN             BV(3)
63 /*@}*/
64
65 /**
66  * \name LCD bus control macros
67  * @{
68  */
69 /* Enter command mode */
70 #define LCD_SET_COMMAND() \
71         lm3s_gpio_pin_write(GPIO_PORTH_BASE, GPIO_OLEDDC_PIN, 0)
72
73 /* Enter data mode */
74 #define LCD_SET_DATA() \
75         lm3s_gpio_pin_write(GPIO_PORTH_BASE, GPIO_OLEDDC_PIN, GPIO_OLEDDC_PIN)
76
77 /* Send data to the display */
78 #define LCD_WRITE(x)    lm3s_ssiWriteFrame(SSI0_BASE, x)
79
80 /* Read data from the display */
81 #define LCD_READ()                                      \
82         ({                                              \
83                 uint32_t frame;                         \
84                 lm3s_ssiReadFrame(SSI0_BASE, &frame);   \
85                 frame;                                  \
86         })
87 /*@}*/
88
89 INLINE void lcd_bus_init(void)
90 {
91         cpu_flags_t flags;
92         uint32_t dummy;
93
94         IRQ_SAVE_DISABLE(flags);
95
96         /* Enable the peripheral clock */
97         SYSCTL_RCGC1_R |= SYSCTL_RCGC1_SSI0;
98         SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOA;
99         SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOH;
100         __delay(512);
101
102         /* Configure the SSI0CLK and SSIOTX pins for SSI operation. */
103         lm3s_gpio_pin_config(GPIO_PORTA_BASE, BV(2) | BV(3) | BV(5),
104                 GPIO_DIR_MODE_HW, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU);
105         /*
106          * Configure the GPIO port pin used as a D/C# signal (data/command
107          * control) for OLED device, and the port pin used to enable power to
108          * the OLED panel.
109          */
110         lm3s_gpio_pin_config(GPIO_PORTH_BASE, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN,
111                 GPIO_DIR_MODE_OUT, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
112         lm3s_gpio_pin_write(GPIO_PORTH_BASE, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN,
113                         GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN);
114
115         /* Configure the SSI0 port for master mode */
116         lm3s_ssiOpen(SSI0_BASE, SSI_FRF_MOTO_MODE_2,
117                         SSI_MODE_MASTER, CPU_FREQ / 2, 8);
118         /*
119          * Configure the GPIO port pin used as a D/Cn signal for OLED device,
120          * and the port pin used to enable power to the OLED panel.
121          */
122         lm3s_gpio_pin_config(GPIO_PORTA_BASE, GPIO_OLEDEN_PIN,
123                 GPIO_DIR_MODE_HW, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU);
124
125         /* Drain the SSI RX FIFO */
126         while (lm3s_ssiReadFrameNonBlocking(SSI0_BASE, &dummy));
127
128         IRQ_RESTORE(flags);
129 }
130
131 #endif /* HW_LCD_H */