altos/test: Adjust CRC error rate after FEC fix
[fw/altos] / src / avr / 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 #define LCD_PORT        PORTB
22 #define LCD_DDR         DDRB
23
24 #define PIN_RS          4
25 #define PIN_E           5
26 #define PIN_RW          6
27
28 static void
29 ao_lcd_port_set_bits(uint8_t bits)
30 {
31 #if 0
32         printf("\tLCD data %x RS %d R/W %d E %d\n",
33                bits & 0xf,
34                (bits & (1 << PIN_RS)) ? 1 : 0,
35                (bits & (1 << PIN_RW)) ? 1 : 0,
36                (bits & (1 << PIN_E)) ? 1 : 0);
37 #endif
38         LCD_PORT = bits;
39 #if 0
40         ao_delay(1);
41         if (bits & (1 << PIN_RW))
42                 printf("\tLCD input %x\n", PINB);
43 #endif
44 }
45
46 uint8_t
47 ao_lcd_port_get_nibble(uint8_t rs)
48 {
49         uint8_t data = (rs ? (1 << PIN_RS) : 0) | (1 << PIN_RW);
50         uint8_t n;
51
52         DDRB = (1 << PIN_RS) | (1 << PIN_E) | (1 << PIN_RW);
53         ao_lcd_port_set_bits(data);
54         ao_lcd_port_set_bits(data | (1 << PIN_E));
55         n = PINB & 0xf;
56         ao_lcd_port_set_bits(data);
57         return n;
58 }
59
60 void
61 ao_lcd_port_put_nibble(uint8_t rs, uint8_t data)
62 {
63         data = (data & 0xf) | (rs ? (1 << PIN_RS) : 0);
64         DDRB = (0xf) | (1 << PIN_RS) | (1 << PIN_E) | (1 << PIN_RW);
65         ao_lcd_port_set_bits(data);
66         ao_lcd_port_set_bits(data | (1 << PIN_E));
67         ao_lcd_port_set_bits(data);
68 }
69
70 void
71 ao_lcd_port_init(void)
72 {
73         DDRB = (1 << PIN_RS) | (1 << PIN_E) | (1 << PIN_RW);
74         PORTB = 0;
75 }