9b5880903589225998016b05e208f9990e5b9216
[fw/altos] / src / cc1111 / ao_lcd_port.c
1 /*
2  * Copyright © 2011 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #include "ao.h"
20
21 static void
22 ao_lcd_port_delay(void)
23 {
24         uint8_t i;
25
26         for (i = 0; i < 100; i++)
27                 ao_arch_nop();
28 }
29
30 void
31 ao_lcd_port_put_nibble(uint8_t rs, uint8_t nibble)
32 {
33         P0 = (P0 & 0xf0) | (nibble & 0x0f);
34         P1_1 = rs;
35         P1_0 = 1;
36         ao_lcd_port_delay();
37         P1_0 = 0;
38         ao_lcd_port_delay();
39 }
40
41 void
42 ao_lcd_port_init(void)
43 {
44         /* LCD_E and LCD_RS are GPIO outputs */
45         P1DIR |= 0x03;
46         P1SEL &= ~0x03;
47
48         /* LCD D4-D7 are GPIO outputs */
49         P0DIR |= 0x0f;
50         P0SEL &= ~0x0f;
51 }