OSDN Git Service

[I2C_ROM] Block Write/Block Read even unaligned address and size.
[openi2cradio/OpenI2CRadio.git] / ui_updown.c
1 /*
2  * OpenI2CRADIO
3  * Up-down UI routine.
4  * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
5  * License: GPL2+LE
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2,
10  *  or (at your option) any later version.
11  *  This library / 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.
14  *  See the 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 library; see the file COPYING. If not, write to the
18  *  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
19  *  MA 02110-1301, USA.
20  *
21  *  As a special exception, if you link this(includeed from sdcc) library
22  *  with other files, some of which are compiled with SDCC,
23  *  to produce an executable, this library does not by itself cause
24  *  the resulting executable to be covered by the GNU General Public License.
25  *  This exception does not however invalidate any other reasons why
26  *  the executable file might be covered by the GNU General Public License.
27  */
28
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #if defined(__SDCC)
34 #include <sdcc-lib.h>
35 #include <pic18fregs.h> /* ONLY FOR PIC18x */
36 #include <delay.h>
37 #else
38 #include <xc.h>
39 #endif
40 #include <signal.h>
41
42 #include "iodef.h"
43 #include "idle.h"
44 #include "i2c_io.h"
45 #include "akc6955.h"
46 #include "lcd_acm1602.h"
47 #include "ui.h"
48 #include "eeprom.h"
49 #include "ioports.h"
50 #include "menu.h"
51 #include "menu_memoryfreq.h"
52 #include "power.h"
53 #include "adc_int.h"
54
55 static void setfreq_updown_amsub(void)
56 {
57     if(setup.amband >= AKC6955_BAND_AMEND) {
58         setup.amband = 0;
59     }
60     akc6955_set_amband(setup.amband);
61     setup.amfreq = setup.amfreq_bank[setup.amband];
62 //    idle_time_62_5ms(); // 62.5ms
63     ClrWdt();
64     akc6955_set_freq(setup.amfreq);
65 }
66
67 static void setfreq_updown_fmsub(void)
68 {
69     if(setup.fmband >= AKC6955_BAND_FMEND) {
70         setup.fmband = 0;
71     }
72     akc6955_set_fmband(setup.fmband);
73     setup.fmfreq = setup.fmfreq_bank[setup.fmband];
74 //    idle_time_62_5ms(); // 62.5ms
75     ClrWdt();
76     akc6955_set_freq(setup.fmfreq);
77 }
78
79 static void setband_updown(unsigned char updown)
80 {
81     unsigned char band;
82     if(setup.fm == 0){  // MW
83         band = setup.amband + 1;
84         if(setup.amband == AKC6955_BAND_AMUSER){
85             setup.am_usrbands[setup.am_userbandnum].freq = setup.amfreq;
86         }
87         setup.amfreq_bank[setup.amband] = setup.amfreq;
88         if(updown == 0) { // down
89             if(band <= 1) {
90                 band = AKC6955_BAND_AMEND - 1;
91             }
92             band -= 2;
93         }
94         setup.amband = band;
95         if(setup.amband == AKC6955_BAND_AMUSER){
96 //            amfreq = am_usrbands[am_userbandnum].freq;
97             call_userband(setup.am_userbandnum);
98         }
99         setfreq_updown_amsub();
100     } else { // FM
101         if(setup.fmband == AKC6955_BAND_FMUSER){
102             setup.fm_usrbands[setup.fm_userbandnum].freq = setup.fmfreq;
103         }
104         band = setup.fmband + 1;
105         setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
106         if(updown == 0) { // down
107             if(band <= 1) {
108                 band = AKC6955_BAND_FMEND - 1;
109             }
110             band -= 2;
111         }
112         setup.fmband = band;
113         if(setup.fmband == AKC6955_BAND_FMUSER){
114    //         setup.fmfreq = fm_usrbands[fm_userbandnum].freq;
115             call_userband(setup.fm_userbandnum);
116         }
117         setfreq_updown_fmsub();
118     }
119 }
120
121 void setfreq_updown(unsigned char ctlword)
122 {
123     unsigned int freq;
124     if((ctlword != charcode_e) && (ctlword >= charcode_1)
125             && (ctlword <= charcode_f)) {
126             backlight_counter = setup.backlight_long;
127             lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
128     } else if(ctlword == charcode_e){
129         if(backlight_counter != 0){
130             backlight_counter = 0;
131         } else {
132             backlight_counter = setup.backlight_long;
133         }
134         return;
135     }
136
137     update_status();
138     switch(ctlword){
139         case charcode_8: // Up band
140             setband_updown(0xff);
141             break;
142         case charcode_2: // Down band
143             setband_updown(0x00);
144             break;
145         case charcode_4: // Down Freq;
146             freq = 9; // 27KHz@3K/9KStep.
147             if(setup.fm != 0) {
148                 freq = 10; // 250KHz
149             } else if(setup.am_mode3k == 0){
150                 freq = 6; // 30KHz
151             }
152             akc6955_down_freq(freq);
153             break;
154         case charcode_6: // Down Freq;
155             freq = 9; // 27KHz@3K/9KStep.
156             if(setup.fm != 0) {
157                 freq = 10; // 250KHz
158             } else if(setup.am_mode3k == 0){
159                 freq = 6; // 30KHz
160             }
161             akc6955_up_freq(freq); // 225 or 27 or 45KHz
162             break;
163         case charcode_9: // Down Fast;
164             freq = 33; // 99KHz@3K/9KStep.
165             if(setup.fm != 0){
166                 freq = 40; // 1MHz
167             } else if(setup.am_mode3k != 0){
168                 freq = 20; // 100KHz
169             }
170             akc6955_up_freq(freq); // 825 or 90 or 165KHz
171             break;
172         case charcode_7: // Down Fast;
173             freq = 33; // 99KHz@3K/9KStep.
174             if(setup.fm != 0){
175                 freq = 40; // 1MHz
176             } else if(setup.am_mode3k != 0){
177                 freq = 20; // 100KHz
178             }
179             akc6955_down_freq(freq); // 825 or 90 or 165KHz
180             break;
181         case charcode_1: // Down Slow;
182             if(setup.fm != 0){
183                 freq = 4; // DOWN 100KHz
184             } else {
185                 freq = 1; // 5KHz or 3KHz
186                 if(setup.amband == AKC6955_BAND_MW2) {
187                     freq = 3; // 9KHz
188                 } else if(setup.amband == AKC6955_BAND_MW3) {
189                     freq = 2; // 10KHz
190                 }
191             }
192             akc6955_down_freq(freq);
193             break;
194         case charcode_3: // Up Slow;
195             if(setup.fm != 0){
196                 freq = 4; // DOWN 100KHz
197             } else {
198                 freq = 1; // 5KHz or 3KHz
199                 if(setup.amband == AKC6955_BAND_MW2) {
200                     freq = 3; // 9KHz
201                 } else if(setup.amband == AKC6955_BAND_MW3) {
202                     freq = 2; // 10KHz
203                 }
204             }
205             akc6955_up_freq(freq);
206             break;
207         case charcode_0: // Step
208             setup.threshold_width++;
209             akc6955_set_thresh_width(setup.threshold_width);
210             akc6955_do_tune();
211             break;
212         case charcode_a: // Toggle FM
213             toggle_amfm();
214             break;
215         case charcode_b:
216 //            set_volume();
217              on_updown_userfreq();
218             break;
219         case charcode_c:
220             // Scan
221             scan_start();
222             break;
223         case charcode_d:
224             // FM Narrow/Wide
225             set_stereo();
226             break;
227         case charcode_5:
228             main_menu();
229             break;
230         case charcode_f:
231             updown_help();
232             _CLS();
233             _LOCATE(0,0);
234             break;
235         default:
236             break;
237     }
238 //    if(fm == 0){
239 //        akc6955_get_amband(amband);
240 //        amfreq = akc6955_get_freq();
241 //        amfreq_bank[amband] = amfreq;
242 //    } else {
243 //        akc6955_get_fmband(fmband);
244 //        fmfreq = akc6955_get_freq();
245 //        fmfreq_bank[fmband] = fmfreq;
246 //    }
247 }