blob: 4b496b7e1c0d1681d0557453a28be105564c9494 [file] [log] [blame]
Linus Nielsen Feltzing331c7d92003-05-03 02:40:09 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "lcd.h"
20#include "sh7034.h"
21#include "kernel.h"
22#include "thread.h"
23#include "debug.h"
Jörg Hohensohn75bab492003-11-06 01:34:50 +000024#include "system.h"
Linus Nielsen Feltzing331c7d92003-05-03 02:40:09 +000025
26#ifdef HAVE_FMRADIO
27
28/* Signals:
29 DI (Data In) - PB0 (doubles as data pin for the LCD)
30 CL (Clock) - PB1 (doubles as clock for the LCD)
31 CE (Chip Enable) - PB3 (also chip select for the LCD, but active low)
32 DO (Data Out) - PB4
33*/
34
35#define PB0 0x0001
36#define PB1 0x0002
37#define PB3 0x0008
38#define PB4 0x0010
39
40/* cute little functions */
Jörg Hohensohn75bab492003-11-06 01:34:50 +000041#define CE_LO __clear_bit_constant(3, PBDRL_ADDR)
42#define CE_HI __set_bit_constant(3, PBDRL_ADDR)
43#define CL_LO __clear_bit_constant(1, PBDRL_ADDR)
44#define CL_HI __set_bit_constant(1, PBDRL_ADDR)
Linus Nielsen Feltzing331c7d92003-05-03 02:40:09 +000045#define DO (PBDR & PB4)
Jörg Hohensohn75bab492003-11-06 01:34:50 +000046#define DI_LO __clear_bit_constant(0, PBDRL_ADDR)
47#define DI_HI __set_bit_constant(0, PBDRL_ADDR)
Linus Nielsen Feltzing331c7d92003-05-03 02:40:09 +000048
Jörg Hohensohn75bab492003-11-06 01:34:50 +000049#define START __set_mask_constant((PB3 | PB1), PBDRL_ADDR)
Linus Nielsen Feltzing331c7d92003-05-03 02:40:09 +000050
51/* delay loop */
52#define DELAY do { int _x; for(_x=0;_x<10;_x++);} while (0)
53
Linus Nielsen Feltzing23b0fda2003-05-03 15:39:40 +000054static int fmstatus = 0;
Linus Nielsen Feltzing331c7d92003-05-03 02:40:09 +000055
56int fmradio_read(int addr)
57{
58 int i;
59 int data = 0;
60
61 START;
62
63 /* First address bit */
64 CL_LO;
65 if(addr & 2)
66 DI_HI;
67 else
68 DI_LO;
69 DELAY;
70 CL_HI;
71 DELAY;
72
73 /* Second address bit */
74 CL_LO;
75 if(addr & 1)
76 DI_HI;
77 else
78 DI_LO;
79 DELAY;
80 CL_HI;
81 DELAY;
82
83 for(i = 0; i < 21;i++)
84 {
85 CL_LO;
86 DELAY;
87 data <<= 1;
88 data |= (DO)?1:0;
89 CL_HI;
90 DELAY;
91 }
92
93 CE_LO;
94
95 return data;
96}
97
98void fmradio_set(int addr, int data)
99{
100 int i;
101
102 /* Include the address in the data */
103 data |= addr << 21;
104
105 START;
106
107 for(i = 0; i < 23;i++)
108 {
109 CL_LO;
110 DELAY;
111 if(data & (1 << 22))
112 DI_HI;
113 else
114 DI_LO;
115
116 data <<= 1;
117 CL_HI;
118 DELAY;
119 }
120
121 CE_LO;
122}
123
Linus Nielsen Feltzing23b0fda2003-05-03 15:39:40 +0000124void fmradio_set_status(int status)
125{
126 fmstatus = status;
127}
128
129int fmradio_get_status(void)
130{
131 return fmstatus;
132}
133
Linus Nielsen Feltzing331c7d92003-05-03 02:40:09 +0000134#endif