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"
33 const char *updown_helpstr[20] = {
34 "Help", "F=exit any=continue",
36 "1: Slow Down", "3: Slow Up",
38 "7: Fast Down", "9: Fast Up",
39 "2: Band Down", "8: Band Up",
41 "a: AM/FM", "b: Volume",
42 "c: Scan", "d: Stereo mode",
43 "e: Backlight", "f: (Exit) Help",
46 const char *setup_helpstr[16] = {
47 "Help", "F=exit any=continue",
48 "0: Power OFF", "C: Save status",
49 "d: Reset default", "E: BL time",
51 "1: FM CNR", "2: AM CNR"
52 "3: FM STEREO", "4: Reserve"
53 "6: Reserve", "7: Reserve",
54 "8: Reserve", "9: Reserve",
55 "5: Cancel", "f: (Exit) Help",
58 const char *mainmenu_helpstr[18] = {
59 "Help", "F=exit any=continue",
60 "0: Setup", "1: Reserve",
62 "4: Reserve", "5: Scan"
63 "6: Gain", "7: Volume",
64 "8: FM Wide/Narrow", "9: Reserved",
65 "a: PowOFF", "b: Cancel",
66 "c: Set user", "d: Input user",
67 "e: AM/FM", "f: (Exit) Help"
70 const char *numeric_helpstr[10] = {
71 "On numeric input", " ",
72 "0-9: Numeric", "f: enter",
73 "a: Delete", "b: Reset value",
74 "d: Left", "e: Right",
75 "Press any key", " to continue."
78 void toggle_amfm(void)
83 fmfreq_bank[fmband] = fmfreq;
84 // akc6955_set_amband(amband);
85 freq = amfreq_bank[amband];
88 amfreq_bank[amband] = amfreq;
89 // akc6955_set_fmband(fmband);
90 freq = fmfreq_bank[fmband];
92 akc6955_chg_fm(fm, freq);
94 // akc6955_set_freq(freq);
98 void set_thresh_fmstereo(unsigned char a)
102 threshold_fmstereo = a;
103 b = akc6955_readcmd(AKC6955_THRESH) & 0xfc;
104 akc6955_writecmd(AKC6955_THRESH, a | b);
107 void set_thresh_width(unsigned char a)
113 b = akc6955_readcmd(AKC6955_THRESH) & 0xf3;;
114 akc6955_writecmd(AKC6955_THRESH, a | b);
117 void set_thresh_amcnr(unsigned char a)
123 b = akc6955_readcmd(AKC6955_THRESH) & 0xcf;
124 akc6955_writecmd(AKC6955_THRESH, a | b);
127 void set_thresh_fmcnr(unsigned char a)
133 b = akc6955_readcmd(AKC6955_THRESH) & 0x3f;
134 akc6955_writecmd(AKC6955_THRESH, a | b);
137 void set_stereomode(void)
142 mode.b0 = 1; // Force mono
143 } else if(stereo < 0x80){
144 mode.b1 = 1; // Force stereo
146 akc6955_set_stereomode(mode.byte);
149 void set_stereo(void)
151 if(stereo == 0xff) {// Force Mono
153 } else if(stereo == 0x00) { //Mono->Stereo
155 } else { // Default, Stereo->auto
162 void set_volume(void)
172 d = akc6955_getvolumemode();
179 print_numeric_nosupress(volume, 2);
183 _PUTCHAR('0' + (prevolume & 3));
185 if(lowboost == 0x00){
191 c = pollkeys(pollkeybuf, 60, 1);
194 switch(pollkeybuf[p]) {
197 if(volume > 63) volume = 63;
201 if(volume < 23) volume = 23;
210 akc6955_setvolumemode(fact);
214 if(prevolume > 3) prevolume = 0;
215 akc6955_set_prevolume(prevolume);
219 if(lowboost == 0x00){
223 akc6955_set_lowboost(lowboost);
236 akc6955_setvolume(volume);
241 void scan_start(void)
246 printstr("Scan F/A/4/6");
250 c = pollkey_single();
254 akc6955_do_scan(0xff);
255 } else if(c == charcode_4){
258 } else if(c == charcode_a){
260 akc6955_abort_scan();
262 } else if(c == charcode_f){
265 if((scanflag != 0) && (akc6955_chk_donescan() != 0)) {
268 printstr("Scan F/A/4/6");
278 void setfreq_direct(void)
283 printstr("Set Freq:");
289 val = read_numeric(val, 5, 7, 1);
295 val = read_numeric(val, 5, 7, 1);
298 akc6955_set_freq(val);
301 void setband_direct(void)
307 printstr("Set Band:FM#");
309 fmband = read_numeric(band, 2, 7, 1);
310 akc6955_set_fmband(fmband);
313 printstr("Set Band:AM#");
314 band = amband & 0x1f;
315 amband = read_numeric(band, 2, 7, 1);
316 akc6955_set_amband(amband);
321 void call_userband(unsigned char num)
325 if(num >= USER_BAND_NUM) return;
327 freq = fm_usrbands[num].freq;
328 ch = ((freq - 3000) / 25) * 10;
329 akc6955_set_userband(fm_usrbands[num].start, fm_usrbands[num].stop, ch,
330 fm_usrbands[num].mode3k);
331 fmband = AKC6955_BAND_AMUSER;
334 if(am_usrbands[num].mode3k != 0) p = 3;
335 freq = am_usrbands[num].freq;
337 akc6955_set_userband(am_usrbands[num].start, am_usrbands[num].stop, ch,
338 am_usrbands[num].mode3k);
339 amband = AKC6955_BAND_AMUSER;
343 void set_userband(void)
345 unsigned int from,to;
348 unsigned char mode3k;
353 printstr("User ch:");
354 c = pollkey_single();
356 if(c > charcode_0) return;
357 if(c < charcode_1) return;
358 if(c == charcode_0) {
361 c = c - charcode_1 + 1;
363 if(c >= USER_BAND_NUM) return;
365 from = fm_usrbands[c].start * 80 + 3000; // 32*25/10
366 to = fm_usrbands[c].stop * 80 + 3000;
370 print_numeric_nosupress(c, 1);
372 from = read_numeric(from, 5, 7, 1);
375 to = read_numeric(to, 5, 7, 1);
376 fm_usrbands[c].start = (from - 3000) / 80;
377 fm_usrbands[c].stop = (to - 3000) / 80;
378 fm_usrbands[c].freq = from * 80 + 3000;
381 mode3k = am_usrbands[c].mode3k;
383 if(mode3k == 0) p = 160; // 5*32
384 from = am_usrbands[c].start * p;
385 to = am_usrbands[c].stop * p;
389 print_numeric_nosupress(c, 1);
392 printstr("0=3k 1=5k");
393 cc = pollkey_single();
394 if(cc == charcode_0){
397 } else if(cc = charcode_1) {
404 print_numeric_nosupress(c, 1);
406 from = read_numeric(from, 5, 7, 1);
409 to = read_numeric(to, 5, 7, 1);
410 am_usrbands[c].start = from / p;
411 am_usrbands[c].stop = to / p;
412 am_usrbands[c].mode3k = mode3k;
413 am_usrbands[c].freq = from * p;
419 void input_userband(void)
425 printstr("User Band");
428 c = pollkey_single();
430 if((c >= charcode_a) && (c <= charcode_f)){
433 if(c == charcode_0) {
442 c = c - charcode_1 + 1;
443 if(c < USER_BAND_NUM) {
458 unsigned char printhelp_2lines(char *l1, char *l2)
466 return pollkey_single();
469 unsigned char numeric_help(void)
475 c = printhelp_2lines(numeric_helpstr[l], numeric_helpstr[l + 1]);
476 if(c == charcode_f) return charcode_f;
482 void mainmenu_help(void)
489 c = printhelp_2lines(mainmenu_helpstr[l], mainmenu_helpstr[l + 1]);
490 if(c == charcode_f) return;
494 if(c == charcode_f) return;
500 void updown_help(void)
507 c = printhelp_2lines(updown_helpstr[l], updown_helpstr[l + 1]);
508 if(c == charcode_f) return;
512 if(c == charcode_f) return;
518 void menu_poweroff(void)
521 c = printhelp_2lines("Poweroff", "A=Yes");
522 if(c == charcode_a) {
527 void setup_akc6955(void)
529 // akc6955_chg_fm(fm); // Set to AM
533 0x4c, //REG00 //Modify
548 0x82, //REG15 //Modify
552 akc6955_writecmd(0x00, 0x4c);
553 akc6955_writecmd(0x01, 0b00010000);
554 akc6955_writecmd(0x02, 0b01001010);
555 akc6955_writecmd(0x03, 0xc8);
556 akc6955_writecmd(0x04, 0x19);
557 akc6955_writecmd(0x05, 0x32);
558 akc6955_writecmd(0x06, 0xa1);
559 akc6955_writecmd(0x07, 0b10100001);
560 akc6955_writecmd(0x08, 0b01010000);
561 akc6955_writecmd(0x09, 0b11000111);
562 akc6955_writecmd(0x09, 0b01111111);
563 akc6955_writecmd(0x0b, 0b11100000);
564 akc6955_writecmd(0x0c, 0b00000000);
565 akc6955_writecmd(0x0d, 0b00001100);
566 akc6955_writecmd(0x0e, 0x40);
567 akc6955_writecmd(0x0f, 0x82);
568 akc6955_writecmd(0x10, 0xcc);
569 akc6955_writecmd(0x11, 0xf9);
573 akc6955_writecmd(AKC6955_POWER, 0xc0); // You musto *not* mute, set b2 to '0".
574 akc6955_writecmd(AKC6955_VOLUME, 0xc0); // You must select to radio(b1 = '0).
576 akc6955_set_amband(amband);
577 if(amband == AKC6955_BAND_AMUSER) call_userband(am_userbandnum);
578 amfreq = amfreq_bank[amband];
579 akc6955_chg_fm(0, amfreq); // Set to AM
580 akc6955_set_freq(amfreq);
582 akc6955_set_fmband(fmband);
583 if(fmband == AKC6955_BAND_FMUSER) call_userband(fm_userbandnum);
584 fmfreq = fmfreq_bank[fmband];
585 akc6955_chg_fm(0xff, fmfreq); // Set to AM
586 akc6955_set_freq(fmfreq);
587 }// Dummy, TBS (954KHz)
588 akc6955_set_power(0xff); // Power ON
589 akc6955_setvolume(36); // Temporally
590 set_thresh_fmcnr(threshold_fmcnr);
591 set_thresh_amcnr(threshold_amcnr);
592 set_thresh_width(threshold_width);
593 set_thresh_fmstereo(threshold_fmstereo);
594 akc6955_setvolumemode(0);
595 akc6955_set_lowboost(lowboost);
603 c = printhelp_2lines("Save settings", "A=Yes");
604 if(c == charcode_a) {
612 c = printhelp_2lines("Load settings", "A=Yes B=Init");
613 if(c == charcode_a) {
618 c = printhelp_2lines("X) Load Error", "A=Fix");
625 } else if(c == charcode_b){
631 void setup_help(void)
637 c = printhelp_2lines(setup_helpstr[l], setup_helpstr[l + 1]);
638 if(c == charcode_f) return;
642 if(c == charcode_f) return;
648 void setup_menu(void)
653 c = printhelp_2lines("Setup F=HELP", "5=Return");
677 printstr("FM Bandwidth:");
678 akc6955_get_fmbandwidth(val);
679 val = read_numeric(val, 1, 0, 1) & 3;
680 fmbandwidth = (unsigned char)val;
681 akc6955_set_fmbandwidth(fmbandwidth);
686 printstr("FM-CNR threshold:");
687 val = threshold_fmcnr;
688 val = read_numeric(val, 1, 0, 1);
689 set_thresh_fmcnr((unsigned char)val);
694 printstr("AM-CNR threshold:");
695 val = threshold_amcnr;
696 val = read_numeric(val, 1, 0, 1);
697 set_thresh_amcnr((unsigned char)val);
702 printstr("Stereo threshold:");
703 val = threshold_fmstereo;
704 val = read_numeric(val, 1, 0, 1);
705 set_thresh_fmstereo((unsigned char)val);
710 * Main Menu : initial-screen -> 'F'.
722 printstr("Menu:F=HELP");
724 printstr("B=CANCEL");
726 n = pollkeys(pollkeybuf, 60, 1);
733 } else if(c == charcode_b){
735 } else if(c == charcode_1){
737 } else if(c == charcode_2){
740 } else if(c == charcode_3){
743 } else if(c == charcode_a){
745 } else if(c == charcode_5){
748 } else if(c == charcode_6){
750 } else if(c == charcode_4){
752 } else if(c == charcode_7){
755 } else if(c == charcode_8){
757 } else if(c == charcode_9){
760 printstr("Sig width:");
761 val = threshold_width;
762 val = read_numeric(val, 1, 0, 1);
763 set_thresh_width((unsigned char)val);
765 } else if(c == charcode_0){
768 } else if(c == charcode_d){
771 } else if(c == charcode_c){
774 } else if(c == charcode_e){