4 * Copyright (C) 2013-06-21 K.Ohta <whatisthis.sowhat ai gmail.com>
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.
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,
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.
31 #include "commondef.h"
34 void toggle_amfm(void)
39 fmfreq_bank[fmband] = fmfreq;
40 // akc6955_set_amband(amband);
41 freq = amfreq_bank[amband];
44 amfreq_bank[amband] = amfreq;
45 // akc6955_set_fmband(fmband);
46 freq = fmfreq_bank[fmband];
48 akc6955_chg_fm(fm, freq);
50 // akc6955_set_freq(freq);
55 void set_stereomode(void)
60 mode.b0 = 1; // Force mono
61 } else if(stereo < 0x80){
62 mode.b1 = 1; // Force stereo
64 akc6955_set_stereomode(mode.byte);
70 if(stereo == 0xff) {// Force Mono
72 } else if(stereo == 0x00) { //Mono->Stereo
74 } else { // Default, Stereo->auto
91 d = akc6955_getvolumemode();
98 print_numeric_nosupress(volume, 2);
102 _PUTCHAR('0' + (prevolume & 3));
104 if(lowboost == 0x00){
110 c = pollkeys(pollkeybuf, 60, 1);
113 switch(pollkeybuf[p]) {
116 if(volume > 63) volume = 63;
120 if(volume < 23) volume = 23;
130 akc6955_setvolumemode(fact);
134 if(prevolume > 3) prevolume = 0;
135 akc6955_set_prevolume(prevolume);
139 if(lowboost == 0x00){
143 akc6955_set_lowboost(lowboost);
156 akc6955_setvolume(volume);
161 void scan_start(void)
171 printstr("Scan F/A/4/6");
173 c = pollkeys(pollkeybuf, 20, 0); // 23*20 = 460ms
174 // idle_time_ms(2000);
177 if(pollkeybuf[0] == charcode_6){
179 akc6955_do_scan(0xff);
180 } else if(pollkeybuf[0] == charcode_4){
183 } else if(pollkeybuf[0] == charcode_a){
185 akc6955_abort_scan();
187 } else if(pollkeybuf[0] == charcode_f){
190 // if((scanflag != 0) && (akc6955_chk_donescan() != 0)) {
198 void setfreq_direct(void)
203 printstr("Set Freq:");
209 val = read_numeric(val, 5, 7, 1);
215 val = read_numeric(val, 5, 7, 1);
218 akc6955_set_freq(val);
221 void setband_direct(void)
227 printstr("Set Band:FM#");
229 fmfreq_bank[fmband] = amfreq;
230 fmband = read_numeric(band, 2, 7, 1);
231 akc6955_set_fmband(fmband);
233 fmfreq = fmfreq_bank[fmband];
234 akc6955_set_freq(fmfreq);
236 printstr("Set Band:AM#");
237 band = amband & 0x1f;
238 amfreq_bank[amband] = amfreq;
239 amband = read_numeric(band, 2, 7, 1);
240 amfreq = amfreq_bank[amband];
241 akc6955_set_amband(amband);
243 akc6955_set_freq(amfreq);
247 void call_userband(unsigned char num)
253 unsigned char mode3k;
257 if(num >= USER_BAND_NUM) return;
259 p = &(am_usrbands[num]);
261 p = &(fm_usrbands[num]);
268 ch = ((freq - 3000) / 5) * 2;
269 fmband = AKC6955_BAND_FMUSER;
272 if(mode3k != 0) q = 3;
274 amband = AKC6955_BAND_AMUSER;
291 akc6955_set_userband(start, end, ch, mode3k);
294 void set_userband(void)
296 unsigned int from,to;
299 unsigned char mode3k;
304 printstr("User ch:");
305 c = pollkey_single();
307 if(c > charcode_0) return;
308 if(c < charcode_1) return;
309 if(c == charcode_0) {
312 c = c - charcode_1 + 1;
314 if(c >= USER_BAND_NUM) return;
316 from = fm_usrbands[c].start * 80 + 3000; // 32*25/10
317 to = fm_usrbands[c].stop * 80 + 3000;
322 print_numeric_nosupress(c, 1);
325 from = read_numeric(from, 5, 7, 1);
328 to = read_numeric(to, 5, 7, 1);
329 fm_usrbands[c].start = (from - 3000) / 80;
330 fm_usrbands[c].stop = (to - 3000) / 80;
331 fm_usrbands[c].freq = from * 80 + 3000;
334 mode3k = am_usrbands[c].mode3k;
336 if(mode3k == 0) p = 160; // 5*32
337 from = am_usrbands[c].start * p;
338 to = am_usrbands[c].stop * p;
342 print_numeric_nosupress(c, 1);
345 printstr("0=3k 1=5k");
346 cc = pollkey_single();
347 if(cc == charcode_0){
350 } else if(cc = charcode_1) {
357 print_numeric_nosupress(c, 1);
360 from = read_numeric(from, 5, 7, 1);
363 to = read_numeric(to, 5, 7, 1);
364 am_usrbands[c].start = from / p;
365 am_usrbands[c].stop = to / p;
366 am_usrbands[c].mode3k = mode3k;
367 am_usrbands[c].freq = from * p;
374 void input_userband(void)
380 printstr("User Band");
383 c = pollkey_single();
385 if((c >= charcode_a) && (c <= charcode_f)){
388 if(c == charcode_0) {
397 c = c - charcode_1 + 1;
398 if(c < USER_BAND_NUM) {
414 void menu_poweroff(void)
417 c = printhelp_2lines("Poweroff", "A=Yes");
418 if(c == charcode_a) {
423 void setup_akc6955(void)
425 // akc6955_chg_fm(fm); // Set to AM
429 0x4c, //REG00 //Modify
444 0x82, //REG15 //Modify
448 akc6955_writecmd(0x00, 0x4c);
449 akc6955_writecmd(0x01, 0b00010000);
450 akc6955_writecmd(0x02, 0b01001010);
451 akc6955_writecmd(0x03, 0xc8);
452 akc6955_writecmd(0x04, 0x19);
453 akc6955_writecmd(0x05, 0x32);
454 akc6955_writecmd(0x06, 0xa1);
455 akc6955_writecmd(0x07, 0b10100001);
456 akc6955_writecmd(0x08, 0b01010000);
457 akc6955_writecmd(0x09, 0b11000111);
458 akc6955_writecmd(0x09, 0b01111111);
459 akc6955_writecmd(0x0b, 0b11100000);
460 akc6955_writecmd(0x0c, 0b00000000);
461 akc6955_writecmd(0x0d, 0b00001100);
462 akc6955_writecmd(0x0e, 0x40);
463 akc6955_writecmd(0x0f, 0x82);
464 akc6955_writecmd(0x10, 0xcc);
465 akc6955_writecmd(0x11, 0xf9);
469 akc6955_writecmd(AKC6955_POWER, 0xc0); // You musto *not* mute, set b2 to '0".
470 akc6955_writecmd(AKC6955_VOLUME, 0xc0); // You must select to radio(b1 = '0).
472 akc6955_set_amband(amband);
473 if(amband == AKC6955_BAND_AMUSER) call_userband(am_userbandnum);
474 amfreq = amfreq_bank[amband];
475 akc6955_chg_fm(0, amfreq); // Set to AM
476 akc6955_set_freq(amfreq);
478 akc6955_set_fmband(fmband);
479 if(fmband == AKC6955_BAND_FMUSER) call_userband(fm_userbandnum);
480 fmfreq = fmfreq_bank[fmband];
481 akc6955_chg_fm(0xff, fmfreq); // Set to AM
482 akc6955_set_freq(fmfreq);
483 }// Dummy, TBS (954KHz)
484 akc6955_set_power(0xff); // Power ON
485 akc6955_setvolume(36); // Temporally
486 akc6955_set_thresh_fmcnr(threshold_fmcnr);
487 akc6955_set_thresh_amcnr(threshold_amcnr);
488 akc6955_set_thresh_width(threshold_width);
489 akc6955_set_thresh_fmstereo(threshold_fmstereo);
490 akc6955_setvolumemode(0);
491 akc6955_set_lowboost(lowboost);
499 c = printhelp_2lines("Save settings", "A=Yes");
500 if(c == charcode_a) {
508 c = printhelp_2lines("Load settings", "A=Yes B=Init");
509 if(c == charcode_a) {
514 c = printhelp_2lines("X) Load Error", "A=Fix");
521 } else if(c == charcode_b){
527 void setup_menu(void)
532 c = printhelp_2lines("Setup F=HELP", "5=Return");
537 printstr("BL Level:");
538 val = read_numeric(backlight_level, 3, 0,1);
539 if(val > 255) val = 255;
540 if(val < 10) val = 15;
541 backlight_level = (unsigned char)val;
546 printstr("FM Bandwidth:");
547 akc6955_get_fmbandwidth(val);
548 val = read_numeric(val, 1, 0, 1) & 3;
549 fmbandwidth = (unsigned char)val;
550 akc6955_set_fmbandwidth(fmbandwidth);
557 printstr("FM-CNR threshold:");
558 val = threshold_fmcnr;
559 val = read_numeric(val, 1, 0, 1);
560 akc6955_set_thresh_fmcnr((unsigned char)val);
565 printstr("AM-CNR threshold:");
566 val = threshold_amcnr;
567 val = read_numeric(val, 1, 0, 1);
568 akc6955_set_thresh_amcnr((unsigned char)val);
573 printstr("Stereo threshold:");
574 val = threshold_fmstereo;
575 val = read_numeric(val, 1, 0, 1);
576 akc6955_set_thresh_fmstereo((unsigned char)val);
593 printstr("BL Long:");
594 val = read_numeric(backlight_long, 3, 0,1);
595 if(val > 999) val = 999;
596 backlight_long = val;
606 * Main Menu : initial-screen -> 'F'.
618 printstr("Menu:F=HELP");
620 printstr("B=CANCEL");
622 n = pollkeys(pollkeybuf, 60, 1);
629 } else if(c == charcode_2){
630 } else if(c == charcode_3){
633 } else if(c == charcode_4){
635 }else if(c == charcode_5){
638 } else if(c == charcode_6){
640 } else if(c == charcode_7){
642 } else if(c == charcode_8){
645 } else if(c == charcode_9){
648 printstr("Sig width:");
649 val = threshold_width;
650 val = read_numeric(val, 1, 0, 1);
651 akc6955_set_thresh_width((unsigned char)val);
653 } else if(c == charcode_0){
656 } else if(c == charcode_a){
658 } else if(c == charcode_b){
660 } else if(c == charcode_c){
663 } else if(c == charcode_d){
666 } else if(c == charcode_e){
669 } else if (c == charcode_f){