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