diff options
Diffstat (limited to 'firmware/drivers/fmradio.c')
-rw-r--r-- | firmware/drivers/fmradio.c | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/firmware/drivers/fmradio.c b/firmware/drivers/fmradio.c new file mode 100644 index 0000000000..0d947f4480 --- /dev/null +++ b/firmware/drivers/fmradio.c | |||
@@ -0,0 +1,133 @@ | |||
1 | /*************************************************************************** | ||
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" | ||
24 | |||
25 | #ifdef HAVE_FMRADIO | ||
26 | |||
27 | /* Signals: | ||
28 | DI (Data In) - PB0 (doubles as data pin for the LCD) | ||
29 | CL (Clock) - PB1 (doubles as clock for the LCD) | ||
30 | CE (Chip Enable) - PB3 (also chip select for the LCD, but active low) | ||
31 | DO (Data Out) - PB4 | ||
32 | */ | ||
33 | |||
34 | #define PB0 0x0001 | ||
35 | #define PB1 0x0002 | ||
36 | #define PB3 0x0008 | ||
37 | #define PB4 0x0010 | ||
38 | |||
39 | /* cute little functions */ | ||
40 | #define CE_LO (PBDR &= ~PB3) | ||
41 | #define CE_HI (PBDR |= PB3) | ||
42 | #define CL_LO (PBDR &= ~PB1) | ||
43 | #define CL_HI (PBDR |= PB1) | ||
44 | #define DO (PBDR & PB4) | ||
45 | #define DI_LO (PBDR &= ~PB0) | ||
46 | #define DI_HI (PBDR |= PB0) | ||
47 | |||
48 | #define START (PBDR |= (PB3 | PB1)) | ||
49 | |||
50 | /* delay loop */ | ||
51 | #define DELAY do { int _x; for(_x=0;_x<10;_x++);} while (0) | ||
52 | |||
53 | static struct mutex fmradio_mtx; | ||
54 | |||
55 | void fmradio_begin(void) | ||
56 | { | ||
57 | mutex_lock(&fmradio_mtx); | ||
58 | } | ||
59 | |||
60 | void fmradio_end(void) | ||
61 | { | ||
62 | mutex_unlock(&fmradio_mtx); | ||
63 | } | ||
64 | |||
65 | int fmradio_read(int addr) | ||
66 | { | ||
67 | int i; | ||
68 | int data = 0; | ||
69 | |||
70 | START; | ||
71 | |||
72 | /* First address bit */ | ||
73 | CL_LO; | ||
74 | if(addr & 2) | ||
75 | DI_HI; | ||
76 | else | ||
77 | DI_LO; | ||
78 | DELAY; | ||
79 | CL_HI; | ||
80 | DELAY; | ||
81 | |||
82 | /* Second address bit */ | ||
83 | CL_LO; | ||
84 | if(addr & 1) | ||
85 | DI_HI; | ||
86 | else | ||
87 | DI_LO; | ||
88 | DELAY; | ||
89 | CL_HI; | ||
90 | DELAY; | ||
91 | |||
92 | for(i = 0; i < 21;i++) | ||
93 | { | ||
94 | CL_LO; | ||
95 | DELAY; | ||
96 | data <<= 1; | ||
97 | data |= (DO)?1:0; | ||
98 | CL_HI; | ||
99 | DELAY; | ||
100 | } | ||
101 | |||
102 | CE_LO; | ||
103 | |||
104 | return data; | ||
105 | } | ||
106 | |||
107 | void fmradio_set(int addr, int data) | ||
108 | { | ||
109 | int i; | ||
110 | |||
111 | /* Include the address in the data */ | ||
112 | data |= addr << 21; | ||
113 | |||
114 | START; | ||
115 | |||
116 | for(i = 0; i < 23;i++) | ||
117 | { | ||
118 | CL_LO; | ||
119 | DELAY; | ||
120 | if(data & (1 << 22)) | ||
121 | DI_HI; | ||
122 | else | ||
123 | DI_LO; | ||
124 | |||
125 | data <<= 1; | ||
126 | CL_HI; | ||
127 | DELAY; | ||
128 | } | ||
129 | |||
130 | CE_LO; | ||
131 | } | ||
132 | |||
133 | #endif | ||