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);
54 void set_thresh_fmstereo(unsigned char a)
58 threshold_fmstereo = a;
59 b = akc6955_readcmd(AKC6955_THRESH) & 0xfc;
60 akc6955_writecmd(AKC6955_THRESH, a | b);
63 void set_thresh_width(unsigned char a)
69 b = akc6955_readcmd(AKC6955_THRESH) & 0xf3;;
70 akc6955_writecmd(AKC6955_THRESH, a | b);
73 void set_thresh_amcnr(unsigned char a)
79 b = akc6955_readcmd(AKC6955_THRESH) & 0xcf;
80 akc6955_writecmd(AKC6955_THRESH, a | b);
83 void set_thresh_fmcnr(unsigned char a)
89 b = akc6955_readcmd(AKC6955_THRESH) & 0x3f;
90 akc6955_writecmd(AKC6955_THRESH, a | b);
93 void set_stereomode(void)
98 mode.b0 = 1; // Force mono
99 } else if(stereo < 0x80){
100 mode.b1 = 1; // Force stereo
102 akc6955_set_stereomode(mode.byte);
105 void set_stereo(void)
108 if(stereo == 0xff) {// Force Mono
110 } else if(stereo == 0x00) { //Mono->Stereo
112 } else { // Default, Stereo->auto
119 void set_volume(void)
129 d = akc6955_getvolumemode();
136 print_numeric_nosupress(volume, 2);
140 _PUTCHAR('0' + (prevolume & 3));
142 if(lowboost == 0x00){
148 c = pollkeys(pollkeybuf, 60, 1);
151 switch(pollkeybuf[p]) {
154 if(volume > 63) volume = 63;
158 if(volume < 23) volume = 23;
168 akc6955_setvolumemode(fact);
172 if(prevolume > 3) prevolume = 0;
173 akc6955_set_prevolume(prevolume);
177 if(lowboost == 0x00){
181 akc6955_set_lowboost(lowboost);
194 akc6955_setvolume(volume);
199 void scan_start(void)
204 printstr("Scan F/A/4/6");
208 c = pollkey_single();
212 akc6955_do_scan(0xff);
213 } else if(c == charcode_4){
216 } else if(c == charcode_a){
218 akc6955_abort_scan();
220 } else if(c == charcode_f){
223 if((scanflag != 0) && (akc6955_chk_donescan() != 0)) {
226 printstr("Scan F/A/4/6");
236 void setfreq_direct(void)
241 printstr("Set Freq:");
247 val = read_numeric(val, 5, 7, 1);
253 val = read_numeric(val, 5, 7, 1);
256 akc6955_set_freq(val);
259 void setband_direct(void)
265 printstr("Set Band:FM#");
267 fmfreq_bank[fmband] = amfreq;
268 fmband = read_numeric(band, 2, 7, 1);
269 akc6955_set_fmband(fmband);
271 fmfreq = fmfreq_bank[fmband];
272 akc6955_set_freq(fmfreq);
274 printstr("Set Band:AM#");
275 band = amband & 0x1f;
276 amfreq_bank[amband] = amfreq;
277 amband = read_numeric(band, 2, 7, 1);
278 amfreq = amfreq_bank[amband];
279 akc6955_set_amband(amband);
281 akc6955_set_freq(amfreq);
285 void call_userband(unsigned char num)
291 unsigned char mode3k;
295 if(num >= USER_BAND_NUM) return;
297 p = &(am_usrbands[num]);
299 p = &(fm_usrbands[num]);
306 ch = ((freq - 3000) / 5) * 2;
307 fmband = AKC6955_BAND_FMUSER;
310 if(mode3k != 0) q = 3;
312 amband = AKC6955_BAND_AMUSER;
329 akc6955_set_userband(start, end, ch, mode3k);
332 void set_userband(void)
334 unsigned int from,to;
337 unsigned char mode3k;
342 printstr("User ch:");
343 c = pollkey_single();
345 if(c > charcode_0) return;
346 if(c < charcode_1) return;
347 if(c == charcode_0) {
350 c = c - charcode_1 + 1;
352 if(c >= USER_BAND_NUM) return;
354 from = fm_usrbands[c].start * 80 + 3000; // 32*25/10
355 to = fm_usrbands[c].stop * 80 + 3000;
360 print_numeric_nosupress(c, 1);
363 from = read_numeric(from, 5, 7, 1);
366 to = read_numeric(to, 5, 7, 1);
367 fm_usrbands[c].start = (from - 3000) / 80;
368 fm_usrbands[c].stop = (to - 3000) / 80;
369 fm_usrbands[c].freq = from * 80 + 3000;
372 mode3k = am_usrbands[c].mode3k;
374 if(mode3k == 0) p = 160; // 5*32
375 from = am_usrbands[c].start * p;
376 to = am_usrbands[c].stop * p;
380 print_numeric_nosupress(c, 1);
383 printstr("0=3k 1=5k");
384 cc = pollkey_single();
385 if(cc == charcode_0){
388 } else if(cc = charcode_1) {
395 print_numeric_nosupress(c, 1);
398 from = read_numeric(from, 5, 7, 1);
401 to = read_numeric(to, 5, 7, 1);
402 am_usrbands[c].start = from / p;
403 am_usrbands[c].stop = to / p;
404 am_usrbands[c].mode3k = mode3k;
405 am_usrbands[c].freq = from * p;
412 void input_userband(void)
418 printstr("User Band");
421 c = pollkey_single();
423 if((c >= charcode_a) && (c <= charcode_f)){
426 if(c == charcode_0) {
435 c = c - charcode_1 + 1;
436 if(c < USER_BAND_NUM) {
452 void menu_poweroff(void)
455 c = printhelp_2lines("Poweroff", "A=Yes");
456 if(c == charcode_a) {
461 void setup_akc6955(void)
463 // akc6955_chg_fm(fm); // Set to AM
467 0x4c, //REG00 //Modify
482 0x82, //REG15 //Modify
486 akc6955_writecmd(0x00, 0x4c);
487 akc6955_writecmd(0x01, 0b00010000);
488 akc6955_writecmd(0x02, 0b01001010);
489 akc6955_writecmd(0x03, 0xc8);
490 akc6955_writecmd(0x04, 0x19);
491 akc6955_writecmd(0x05, 0x32);
492 akc6955_writecmd(0x06, 0xa1);
493 akc6955_writecmd(0x07, 0b10100001);
494 akc6955_writecmd(0x08, 0b01010000);
495 akc6955_writecmd(0x09, 0b11000111);
496 akc6955_writecmd(0x09, 0b01111111);
497 akc6955_writecmd(0x0b, 0b11100000);
498 akc6955_writecmd(0x0c, 0b00000000);
499 akc6955_writecmd(0x0d, 0b00001100);
500 akc6955_writecmd(0x0e, 0x40);
501 akc6955_writecmd(0x0f, 0x82);
502 akc6955_writecmd(0x10, 0xcc);
503 akc6955_writecmd(0x11, 0xf9);
507 akc6955_writecmd(AKC6955_POWER, 0xc0); // You musto *not* mute, set b2 to '0".
508 akc6955_writecmd(AKC6955_VOLUME, 0xc0); // You must select to radio(b1 = '0).
510 akc6955_set_amband(amband);
511 if(amband == AKC6955_BAND_AMUSER) call_userband(am_userbandnum);
512 amfreq = amfreq_bank[amband];
513 akc6955_chg_fm(0, amfreq); // Set to AM
514 akc6955_set_freq(amfreq);
516 akc6955_set_fmband(fmband);
517 if(fmband == AKC6955_BAND_FMUSER) call_userband(fm_userbandnum);
518 fmfreq = fmfreq_bank[fmband];
519 akc6955_chg_fm(0xff, fmfreq); // Set to AM
520 akc6955_set_freq(fmfreq);
521 }// Dummy, TBS (954KHz)
522 akc6955_set_power(0xff); // Power ON
523 akc6955_setvolume(36); // Temporally
524 set_thresh_fmcnr(threshold_fmcnr);
525 set_thresh_amcnr(threshold_amcnr);
526 set_thresh_width(threshold_width);
527 set_thresh_fmstereo(threshold_fmstereo);
528 akc6955_setvolumemode(0);
529 akc6955_set_lowboost(lowboost);
537 c = printhelp_2lines("Save settings", "A=Yes");
538 if(c == charcode_a) {
546 c = printhelp_2lines("Load settings", "A=Yes B=Init");
547 if(c == charcode_a) {
552 c = printhelp_2lines("X) Load Error", "A=Fix");
559 } else if(c == charcode_b){
565 void setup_menu(void)
570 c = printhelp_2lines("Setup F=HELP", "5=Return");
575 printstr("BL Level:");
576 val = read_numeric(backlight_level, 3, 0,1);
577 if(val > 255) val = 255;
578 if(val < 10) val = 15;
579 backlight_level = (unsigned char)val;
584 printstr("FM Bandwidth:");
585 akc6955_get_fmbandwidth(val);
586 val = read_numeric(val, 1, 0, 1) & 3;
587 fmbandwidth = (unsigned char)val;
588 akc6955_set_fmbandwidth(fmbandwidth);
595 printstr("FM-CNR threshold:");
596 val = threshold_fmcnr;
597 val = read_numeric(val, 1, 0, 1);
598 set_thresh_fmcnr((unsigned char)val);
603 printstr("AM-CNR threshold:");
604 val = threshold_amcnr;
605 val = read_numeric(val, 1, 0, 1);
606 set_thresh_amcnr((unsigned char)val);
611 printstr("Stereo threshold:");
612 val = threshold_fmstereo;
613 val = read_numeric(val, 1, 0, 1);
614 set_thresh_fmstereo((unsigned char)val);
634 printstr("BL Long:");
635 val = read_numeric(backlight_long, 3, 0,1);
636 if(val > 999) val = 999;
637 backlight_long = val;
644 * Main Menu : initial-screen -> 'F'.
656 printstr("Menu:F=HELP");
658 printstr("B=CANCEL");
660 n = pollkeys(pollkeybuf, 60, 1);
667 } else if(c == charcode_2){
668 } else if(c == charcode_3){
671 } else if(c == charcode_4){
673 }else if(c == charcode_5){
676 } else if(c == charcode_6){
678 } else if(c == charcode_7){
680 } else if(c == charcode_8){
683 } else if(c == charcode_9){
686 printstr("Sig width:");
687 val = threshold_width;
688 val = read_numeric(val, 1, 0, 1);
689 set_thresh_width((unsigned char)val);
691 } else if(c == charcode_0){
694 } else if(c == charcode_a){
696 } else if(c == charcode_b){
698 } else if(c == charcode_c){
701 } else if(c == charcode_d){
704 } else if(c == charcode_e){
707 } else if (c == charcode_f){