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;
294 if(num >= USER_BAND_NUM) return;
296 freq = fm_usrbands[num].freq;
297 ch = ((freq - 3000) / 5) * 2;
298 start = fm_usrbands[num].start;
299 end = fm_usrbands[num].stop;
300 mode3k = fm_usrbands[num].mode3k;
301 fmband = AKC6955_BAND_FMUSER;
304 if(am_usrbands[num].mode3k != 0) p = 3;
305 freq = am_usrbands[num].freq;
307 start = am_usrbands[num].start;
308 end = am_usrbands[num].stop;
309 mode3k = am_usrbands[num].mode3k;
310 amband = AKC6955_BAND_AMUSER;
327 akc6955_set_userband(start, end, ch, mode3k);
330 void set_userband(void)
332 unsigned int from,to;
335 unsigned char mode3k;
340 printstr("User ch:");
341 c = pollkey_single();
343 if(c > charcode_0) return;
344 if(c < charcode_1) return;
345 if(c == charcode_0) {
348 c = c - charcode_1 + 1;
350 if(c >= USER_BAND_NUM) return;
352 from = fm_usrbands[c].start * 80 + 3000; // 32*25/10
353 to = fm_usrbands[c].stop * 80 + 3000;
358 print_numeric_nosupress(c, 1);
361 from = read_numeric(from, 5, 7, 1);
364 to = read_numeric(to, 5, 7, 1);
365 fm_usrbands[c].start = (from - 3000) / 80;
366 fm_usrbands[c].stop = (to - 3000) / 80;
367 fm_usrbands[c].freq = from * 80 + 3000;
370 mode3k = am_usrbands[c].mode3k;
372 if(mode3k == 0) p = 160; // 5*32
373 from = am_usrbands[c].start * p;
374 to = am_usrbands[c].stop * p;
378 print_numeric_nosupress(c, 1);
381 printstr("0=3k 1=5k");
382 cc = pollkey_single();
383 if(cc == charcode_0){
386 } else if(cc = charcode_1) {
393 print_numeric_nosupress(c, 1);
396 from = read_numeric(from, 5, 7, 1);
399 to = read_numeric(to, 5, 7, 1);
400 am_usrbands[c].start = from / p;
401 am_usrbands[c].stop = to / p;
402 am_usrbands[c].mode3k = mode3k;
403 am_usrbands[c].freq = from * p;
410 void input_userband(void)
416 printstr("User Band");
419 c = pollkey_single();
421 if((c >= charcode_a) && (c <= charcode_f)){
424 if(c == charcode_0) {
433 c = c - charcode_1 + 1;
434 if(c < USER_BAND_NUM) {
450 void menu_poweroff(void)
453 c = printhelp_2lines("Poweroff", "A=Yes");
454 if(c == charcode_a) {
459 void setup_akc6955(void)
461 // akc6955_chg_fm(fm); // Set to AM
465 0x4c, //REG00 //Modify
480 0x82, //REG15 //Modify
484 akc6955_writecmd(0x00, 0x4c);
485 akc6955_writecmd(0x01, 0b00010000);
486 akc6955_writecmd(0x02, 0b01001010);
487 akc6955_writecmd(0x03, 0xc8);
488 akc6955_writecmd(0x04, 0x19);
489 akc6955_writecmd(0x05, 0x32);
490 akc6955_writecmd(0x06, 0xa1);
491 akc6955_writecmd(0x07, 0b10100001);
492 akc6955_writecmd(0x08, 0b01010000);
493 akc6955_writecmd(0x09, 0b11000111);
494 akc6955_writecmd(0x09, 0b01111111);
495 akc6955_writecmd(0x0b, 0b11100000);
496 akc6955_writecmd(0x0c, 0b00000000);
497 akc6955_writecmd(0x0d, 0b00001100);
498 akc6955_writecmd(0x0e, 0x40);
499 akc6955_writecmd(0x0f, 0x82);
500 akc6955_writecmd(0x10, 0xcc);
501 akc6955_writecmd(0x11, 0xf9);
505 akc6955_writecmd(AKC6955_POWER, 0xc0); // You musto *not* mute, set b2 to '0".
506 akc6955_writecmd(AKC6955_VOLUME, 0xc0); // You must select to radio(b1 = '0).
508 akc6955_set_amband(amband);
509 if(amband == AKC6955_BAND_AMUSER) call_userband(am_userbandnum);
510 amfreq = amfreq_bank[amband];
511 akc6955_chg_fm(0, amfreq); // Set to AM
512 akc6955_set_freq(amfreq);
514 akc6955_set_fmband(fmband);
515 if(fmband == AKC6955_BAND_FMUSER) call_userband(fm_userbandnum);
516 fmfreq = fmfreq_bank[fmband];
517 akc6955_chg_fm(0xff, fmfreq); // Set to AM
518 akc6955_set_freq(fmfreq);
519 }// Dummy, TBS (954KHz)
520 akc6955_set_power(0xff); // Power ON
521 akc6955_setvolume(36); // Temporally
522 set_thresh_fmcnr(threshold_fmcnr);
523 set_thresh_amcnr(threshold_amcnr);
524 set_thresh_width(threshold_width);
525 set_thresh_fmstereo(threshold_fmstereo);
526 akc6955_setvolumemode(0);
527 akc6955_set_lowboost(lowboost);
535 c = printhelp_2lines("Save settings", "A=Yes");
536 if(c == charcode_a) {
544 c = printhelp_2lines("Load settings", "A=Yes B=Init");
545 if(c == charcode_a) {
550 c = printhelp_2lines("X) Load Error", "A=Fix");
557 } else if(c == charcode_b){
563 void setup_menu(void)
568 c = printhelp_2lines("Setup F=HELP", "5=Return");
592 printstr("FM Bandwidth:");
593 akc6955_get_fmbandwidth(val);
594 val = read_numeric(val, 1, 0, 1) & 3;
595 fmbandwidth = (unsigned char)val;
596 akc6955_set_fmbandwidth(fmbandwidth);
601 printstr("FM-CNR threshold:");
602 val = threshold_fmcnr;
603 val = read_numeric(val, 1, 0, 1);
604 set_thresh_fmcnr((unsigned char)val);
609 printstr("AM-CNR threshold:");
610 val = threshold_amcnr;
611 val = read_numeric(val, 1, 0, 1);
612 set_thresh_amcnr((unsigned char)val);
617 printstr("Stereo threshold:");
618 val = threshold_fmstereo;
619 val = read_numeric(val, 1, 0, 1);
620 set_thresh_fmstereo((unsigned char)val);
625 * Main Menu : initial-screen -> 'F'.
637 printstr("Menu:F=HELP");
639 printstr("B=CANCEL");
641 n = pollkeys(pollkeybuf, 60, 1);
648 } else if(c == charcode_b){
650 } else if(c == charcode_1){
652 } else if(c == charcode_2){
655 } else if(c == charcode_3){
658 } else if(c == charcode_a){
660 } else if(c == charcode_5){
663 } else if(c == charcode_6){
665 } else if(c == charcode_4){
667 } else if(c == charcode_7){
670 } else if(c == charcode_8){
672 } else if(c == charcode_9){
675 printstr("Sig width:");
676 val = threshold_width;
677 val = read_numeric(val, 1, 0, 1);
678 set_thresh_width((unsigned char)val);
680 } else if(c == charcode_0){
683 } else if(c == charcode_d){
686 } else if(c == charcode_c){
689 } else if(c == charcode_e){