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.
32 void toggle_amfm(void)
37 akc6955_set_amband(amband);
38 akc6955_set_freq(amfreq);
42 akc6955_set_fmband(fmband);
43 akc6955_set_freq(fmfreq);
54 printstr("CNR Threshold");
58 printstr("1-4 F=exit");
61 if(c == charcode_f) return;
62 } while((c < charcode_1) && (c>charcode_4));
63 a |= ((c - charcode_1) << 6);
68 if(c == charcode_f) return;
69 } while((c < charcode_1) && (c>charcode_4));
70 a |= ((c - charcode_1) << 4);
75 if(c == charcode_f) return;
76 } while((c < charcode_1) && (c>charcode_4));
77 a |= ((c - charcode_1) << 2);
82 if(c == charcode_f) return;
83 } while((c < charcode_1) && (c>charcode_4));
84 a |= (c - charcode_1);
85 akc6955_writecmd(AKC6955_THRESH, a);
88 void set_stereomode(void)
90 unsigned char mode = 0x00;
93 mode = 0b00000001; // Force mono
99 mode = 0b00000010; // Force stereo
102 akc6955_set_stereomode(mode);
105 void set_stereo(void)
107 if(stereo == 0xff) {// Force Mono
109 } else if(stereo == 0x00) { //Mono->Stereo
111 } else { // Default, Stereo->auto
118 void set_volume(void)
125 d = akc6955_getvolumemode();
137 print_numeric_nosupress(volume, 2);
139 _PUTCHAR('0' + (prevolume & 3));
140 if(lowboost == 0x00){
145 c = pollkeys(pollkeybuf, 60, 1);
148 switch(pollkeybuf[p]) {
151 if(volume > 63) volume = 63;
155 if(volume < 23) volume = 23;
161 akc6955_setvolumemode(0xff);
163 akc6955_setvolumemode(0x00);
168 if(prevolume > 3) prevolume = 0;
169 akc6955_set_prevolume(prevolume);
172 if(lowboost == 0x00){
177 akc6955_set_lowboost(lowboost);
190 akc6955_setvolume(volume);
194 void scan_start(void)
201 printstr("Scan A/U=6/D=4");
203 c = pollkey_single();
207 if((c == charcode_a) || (c == charcode_4) || (c == charcode_6)) {
208 akc6955_abort_scan();
214 akc6955_do_scan(0xff);
215 } else if(c == charcode_4){
217 } else if(c == charcode_a){
225 if(akc6955_chk_donescan() != 0) {
228 printstr("Scan completed");
230 idle_time_ms(ui_idlecount);
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 fmband = read_numeric(band, 2, 7, 1);
268 akc6955_set_fmband(fmband);
271 printstr("Set Band:AM#");
272 band = amband & 0x1f;
273 amband = read_numeric(band, 2, 7, 1);
274 akc6955_set_amband(amband);
279 void call_userband(unsigned char num)
283 if(num >= USER_BAND_NUM) return;
285 freq = fm_usrbands[num].freq;
286 ch = ((freq - 3000) / 25) * 10;
287 akc6955_set_userband(fm_usrbands[num].start, fm_usrbands[num].stop, ch,
288 fm_usrbands[num].mode3k);
289 fmband = AKC6955_BAND_AMUSER;
292 if(am_usrbands[num].mode3k != 0) p = 3;
293 freq = am_usrbands[num].freq;
295 akc6955_set_userband(am_usrbands[num].start, am_usrbands[num].stop, ch,
296 am_usrbands[num].mode3k);
297 amband = AKC6955_BAND_AMUSER;
301 void set_userband(void)
303 unsigned int from,to;
306 unsigned char mode3k;
311 printstr("User ch:");
312 c = pollkey_single();
314 if(c > charcode_0) return;
315 if(c < charcode_1) return;
316 if(c == charcode_0) {
319 c = c - charcode_1 + 1;
321 if(c >= USER_BAND_NUM) return;
323 from = fm_usrbands[c].start * 80 + 3000; // 32*25/10
324 to = fm_usrbands[c].stop * 80 + 3000;
328 print_numeric_nosupress(c, 1);
330 from = read_numeric(from, 5, 7, 1);
333 to = read_numeric(to, 5, 7, 1);
334 fm_usrbands[c].start = (from - 3000) / 80;
335 fm_usrbands[c].stop = (to - 3000) / 80;
336 fm_usrbands[c].freq = from * 80 + 3000;
339 mode3k = am_usrbands[c].mode3k;
341 if(mode3k == 0) p = 160; // 5*32
342 from = am_usrbands[c].start * p;
343 to = am_usrbands[c].stop * p;
347 print_numeric_nosupress(c, 1);
350 printstr("0=3k 1=5k");
351 cc = pollkey_single();
352 if(cc == charcode_0){
355 } else if(cc = charcode_1) {
362 print_numeric_nosupress(c, 1);
364 from = read_numeric(from, 5, 7, 1);
367 to = read_numeric(to, 5, 7, 1);
368 am_usrbands[c].start = from / p;
369 am_usrbands[c].stop = to / p;
370 am_usrbands[c].mode3k = mode3k;
371 am_usrbands[c].freq = from * p;
377 void input_userband(void)
383 printstr("User Band");
386 c = pollkey_single();
388 if((c >= charcode_a) && (c <= charcode_f)){
391 if(c == charcode_0) {
400 c = c - charcode_1 + 1;
401 if(c < USER_BAND_NUM) {
416 unsigned char printhelp_2lines(char *l1, char *l2)
424 return pollkey_single();
427 unsigned char numeric_help(void)
430 c = printhelp_2lines("On numeric input", " ");
431 if(c == charcode_f) return c;
432 c = printhelp_2lines("0-9: Numeric", "f: enter");
433 if(c == charcode_f) return c;
434 c = printhelp_2lines("a: Delete", "b: Reset value");
435 if(c == charcode_f) return c;
436 c = printhelp_2lines("d: Left", "e: Right");
437 if(c == charcode_f) return c;
438 c = printhelp_2lines("Press any key", " to continue.");
442 void mainmenu_help(void)
447 c = printhelp_2lines("Help", "F=exit any=continue");
448 if(c == charcode_f) return;
449 c = printhelp_2lines("0: Setup", "1: Reserve");
450 if(c == charcode_f) return;
451 c = printhelp_2lines("2: Band", "3: Freq");
452 if(c == charcode_f) return;
453 c = printhelp_2lines("4: Reserve", "5: Scan");
454 if(c == charcode_f) return;
455 c = printhelp_2lines("6: Gain", "7: Volume");
456 if(c == charcode_f) return;
457 c = printhelp_2lines("8: FM Wide/Narrow", "9: NF");
458 if(c == charcode_f) return;
459 c = printhelp_2lines("a: PowOFF", "b: Cancel");
460 if(c == charcode_f) return;
461 c = printhelp_2lines("c: Set user", "d: Input user");
462 if(c == charcode_f) return;
463 c = printhelp_2lines("e: AM/FM", "f: (Exit) Help");
464 if(c == charcode_f) return;
466 if(c == charcode_f) return;
471 void updown_help(void)
476 c = printhelp_2lines("Help", "F=exit any=continue");
477 if(c == charcode_f) return;
478 c = printhelp_2lines("5: Menu", " ");
479 if(c == charcode_f) return;
480 c = printhelp_2lines("1: Slow Down", "3: Slow Up");
481 if(c == charcode_f) return;
482 c = printhelp_2lines("4: Down", "6: Up");
483 if(c == charcode_f) return;
484 c = printhelp_2lines("7: Fast Down", "9: Fast Up");
485 if(c == charcode_f) return;
486 c = printhelp_2lines("2: Band Down", "8: Band Up");
487 if(c == charcode_f) return;
488 c = printhelp_2lines("0: Mode3K", " ");
489 if(c == charcode_f) return;
490 c = printhelp_2lines("a: AM/FM", "b: Volume");
491 if(c == charcode_f) return;
492 c = printhelp_2lines("c: Scan", "d: Stereo mode");
493 if(c == charcode_f) return;
494 c = printhelp_2lines("e: Backlight", "f: (Exit) Help");
495 if(c == charcode_f) return;
497 if(c == charcode_f) return;
501 void menu_poweroff(void)
504 c = printhelp_2lines("Poweroff", "A=Yes");
505 if(c == charcode_a) {
510 void setup_akc6955(void)
512 // akc6955_chg_fm(fm); // Set to AM
516 0x4c, //REG00 //Modify
531 0x82, //REG15 //Modify
535 akc6955_writecmd(0x00, 0x4c);
536 akc6955_writecmd(0x01, 0b00010000);
537 akc6955_writecmd(0x02, 0b01001010);
538 akc6955_writecmd(0x03, 0xc8);
539 akc6955_writecmd(0x04, 0x19);
540 akc6955_writecmd(0x05, 0x32);
541 akc6955_writecmd(0x06, 0xa1);
542 akc6955_writecmd(0x07, 0b10100001);
543 akc6955_writecmd(0x08, 0b01010000);
544 akc6955_writecmd(0x09, 0b11000111);
545 akc6955_writecmd(0x09, 0b01111111);
546 akc6955_writecmd(0x0b, 0b11100000);
547 akc6955_writecmd(0x0c, 0b00000000);
548 akc6955_writecmd(0x0d, 0b00001100);
549 akc6955_writecmd(0x0e, 0x40);
550 akc6955_writecmd(0x0f, 0x82);
551 akc6955_writecmd(0x10, 0xcc);
552 akc6955_writecmd(0x11, 0xf9);
556 akc6955_chg_fm(fm); // Set to AM
558 akc6955_set_amband(amband);
559 if(amband == AKC6955_BAND_AMUSER) call_userband(am_userbandnum);
560 amfreq = amfreq_bank[amband];
561 akc6955_set_freq(amfreq);
563 akc6955_set_fmband(fmband);
564 if(fmband == AKC6955_BAND_FMUSER) call_userband(fm_userbandnum);
565 fmfreq = fmfreq_bank[fmband];
566 akc6955_set_freq(fmfreq);
567 }// Dummy, TBS (954KHz)
568 akc6955_set_power(0xff); // Power ON
569 akc6955_setvolume(36); // Temporally
570 akc6955_writecmd(AKC6955_THRESH, threshold);
571 akc6955_set_lowboost(lowboost);
579 c = printhelp_2lines("Save settings", "A=Yes");
580 if(c == charcode_a) {
588 c = printhelp_2lines("Load settings", "A=Yes B=Init");
589 if(c == charcode_a) {
594 c = printhelp_2lines("X) Load Error", "A=Fix");
601 } else if(c == charcode_b){
607 void setup_help(void)
612 c = printhelp_2lines("Help", "F=exit any=continue");
613 if(c == charcode_f) return;
614 c = printhelp_2lines("0: Power OFF", "C: Save status");
615 if(c == charcode_f) return;
616 c = printhelp_2lines("d: Reset default", "E: BL time");
617 if(c == charcode_f) return;
618 c = printhelp_2lines("A: Load", "2: Threshold");
619 if(c == charcode_f) return;
620 c = printhelp_2lines("3: Reserve", "4: Reserve");
621 if(c == charcode_f) return;
622 c = printhelp_2lines("6: Reserve", "7: Reserve");
623 if(c == charcode_f) return;
624 c = printhelp_2lines("8: Reserve", "9: Reserve");
625 if(c == charcode_f) return;
626 c = printhelp_2lines("5: Cancel", "f: (Exit) Help");
627 if(c == charcode_f) return;
629 if(c == charcode_f) return;
633 void setup_menu(void)
637 c = printhelp_2lines("Setup F=HELP", "5=Return");
664 * Main Menu : initial-screen -> 'F'.
674 printstr("Menu:F=HELP");
676 printstr("B=CANCEL");
678 n = pollkeys(pollkeybuf, 60, 1);
685 } else if(c == charcode_b){
687 } else if(c == charcode_1){
689 } else if(c == charcode_2){
692 } else if(c == charcode_3){
695 } else if(c == charcode_a){
697 } else if(c == charcode_5){
700 } else if(c == charcode_6){
702 } else if(c == charcode_4){
704 } else if(c == charcode_7){
707 } else if(c == charcode_8){
710 if(fmbandwidth > 3) fmbandwidth = 0;
711 akc6955_set_fmbandwidth(fmbandwidth);
712 } else if(c == charcode_9){
714 } else if(c == charcode_0){
717 } else if(c == charcode_d){
720 } else if(c == charcode_c){
723 } else if(c == charcode_e){