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 void toggle_amfm(void)
39 akc6955_set_amband(amband);
40 freq = amfreq_bank[amband];
44 akc6955_set_fmband(fmband);
45 freq = fmfreq_bank[fmband];
47 akc6955_set_freq(freq);
50 static unsigned char poll_1to4(void)
55 if(c == charcode_f) return 0xff;
56 } while((c < charcode_1) && (c>charcode_4));
57 return (c - charcode_1);
70 printstr("1-4 F=exit");
95 akc6955_writecmd(AKC6955_THRESH, a);
98 void set_stereomode(void)
103 mode.b0 = 1; // Force mono
104 } else if(stereo < 0x80){
105 mode.b1 = 1; // Force stereo
107 akc6955_set_stereomode(mode.byte);
110 void set_stereo(void)
112 if(stereo == 0xff) {// Force Mono
114 } else if(stereo == 0x00) { //Mono->Stereo
116 } else { // Default, Stereo->auto
123 void set_volume(void)
132 d = akc6955_getvolumemode();
139 print_numeric_nosupress(volume, 2);
143 _PUTCHAR('0' + (prevolume & 3));
145 if(lowboost == 0x00){
151 c = pollkeys(pollkeybuf, 60, 1);
154 switch(pollkeybuf[p]) {
157 if(volume > 63) volume = 63;
161 if(volume < 23) volume = 23;
167 akc6955_setvolumemode(0xff);
169 akc6955_setvolumemode(0x00);
174 if(prevolume > 3) prevolume = 0;
175 akc6955_set_prevolume(prevolume);
178 if(lowboost == 0x00){
183 akc6955_set_lowboost(lowboost);
196 akc6955_setvolume(volume);
201 void scan_start(void)
208 printstr("Scan A/U=6/D=4");
210 c = pollkey_single();
214 if((c == charcode_a) || (c == charcode_4) || (c == charcode_6)) {
215 akc6955_abort_scan();
221 akc6955_do_scan(0xff);
222 } else if(c == charcode_4){
224 } else if(c == charcode_a){
232 if(akc6955_chk_donescan() != 0) {
235 printstr("Scan completed");
237 idle_time_ms(ui_idlecount);
243 void setfreq_direct(void)
248 printstr("Set Freq:");
254 val = read_numeric(val, 5, 7, 1);
260 val = read_numeric(val, 5, 7, 1);
263 akc6955_set_freq(val);
266 void setband_direct(void)
272 printstr("Set Band:FM#");
274 fmband = read_numeric(band, 2, 7, 1);
275 akc6955_set_fmband(fmband);
278 printstr("Set Band:AM#");
279 band = amband & 0x1f;
280 amband = read_numeric(band, 2, 7, 1);
281 akc6955_set_amband(amband);
286 void call_userband(unsigned char num)
290 if(num >= USER_BAND_NUM) return;
292 freq = fm_usrbands[num].freq;
293 ch = ((freq - 3000) / 25) * 10;
294 akc6955_set_userband(fm_usrbands[num].start, fm_usrbands[num].stop, ch,
295 fm_usrbands[num].mode3k);
296 fmband = AKC6955_BAND_AMUSER;
299 if(am_usrbands[num].mode3k != 0) p = 3;
300 freq = am_usrbands[num].freq;
302 akc6955_set_userband(am_usrbands[num].start, am_usrbands[num].stop, ch,
303 am_usrbands[num].mode3k);
304 amband = AKC6955_BAND_AMUSER;
308 void set_userband(void)
310 unsigned int from,to;
313 unsigned char mode3k;
318 printstr("User ch:");
319 c = pollkey_single();
321 if(c > charcode_0) return;
322 if(c < charcode_1) return;
323 if(c == charcode_0) {
326 c = c - charcode_1 + 1;
328 if(c >= USER_BAND_NUM) return;
330 from = fm_usrbands[c].start * 80 + 3000; // 32*25/10
331 to = fm_usrbands[c].stop * 80 + 3000;
335 print_numeric_nosupress(c, 1);
337 from = read_numeric(from, 5, 7, 1);
340 to = read_numeric(to, 5, 7, 1);
341 fm_usrbands[c].start = (from - 3000) / 80;
342 fm_usrbands[c].stop = (to - 3000) / 80;
343 fm_usrbands[c].freq = from * 80 + 3000;
346 mode3k = am_usrbands[c].mode3k;
348 if(mode3k == 0) p = 160; // 5*32
349 from = am_usrbands[c].start * p;
350 to = am_usrbands[c].stop * p;
354 print_numeric_nosupress(c, 1);
357 printstr("0=3k 1=5k");
358 cc = pollkey_single();
359 if(cc == charcode_0){
362 } else if(cc = charcode_1) {
369 print_numeric_nosupress(c, 1);
371 from = read_numeric(from, 5, 7, 1);
374 to = read_numeric(to, 5, 7, 1);
375 am_usrbands[c].start = from / p;
376 am_usrbands[c].stop = to / p;
377 am_usrbands[c].mode3k = mode3k;
378 am_usrbands[c].freq = from * p;
384 void input_userband(void)
390 printstr("User Band");
393 c = pollkey_single();
395 if((c >= charcode_a) && (c <= charcode_f)){
398 if(c == charcode_0) {
407 c = c - charcode_1 + 1;
408 if(c < USER_BAND_NUM) {
423 unsigned char printhelp_2lines(char *l1, char *l2)
431 return pollkey_single();
434 unsigned char numeric_help(void)
437 c = printhelp_2lines("On numeric input", " ");
438 if(c == charcode_f) return c;
439 c = printhelp_2lines("0-9: Numeric", "f: enter");
440 if(c == charcode_f) return c;
441 c = printhelp_2lines("a: Delete", "b: Reset value");
442 if(c == charcode_f) return c;
443 c = printhelp_2lines("d: Left", "e: Right");
444 if(c == charcode_f) return c;
445 c = printhelp_2lines("Press any key", " to continue.");
449 void mainmenu_help(void)
454 c = printhelp_2lines("Help", "F=exit any=continue");
455 if(c == charcode_f) return;
456 c = printhelp_2lines("0: Setup", "1: Reserve");
457 if(c == charcode_f) return;
458 c = printhelp_2lines("2: Band", "3: Freq");
459 if(c == charcode_f) return;
460 c = printhelp_2lines("4: Reserve", "5: Scan");
461 if(c == charcode_f) return;
462 c = printhelp_2lines("6: Gain", "7: Volume");
463 if(c == charcode_f) return;
464 c = printhelp_2lines("8: FM Wide/Narrow", "9: NF");
465 if(c == charcode_f) return;
466 c = printhelp_2lines("a: PowOFF", "b: Cancel");
467 if(c == charcode_f) return;
468 c = printhelp_2lines("c: Set user", "d: Input user");
469 if(c == charcode_f) return;
470 c = printhelp_2lines("e: AM/FM", "f: (Exit) Help");
471 if(c == charcode_f) return;
473 if(c == charcode_f) return;
478 void updown_help(void)
483 c = printhelp_2lines("Help", "F=exit any=continue");
484 if(c == charcode_f) return;
485 c = printhelp_2lines("5: Menu", " ");
486 if(c == charcode_f) return;
487 c = printhelp_2lines("1: Slow Down", "3: Slow Up");
488 if(c == charcode_f) return;
489 c = printhelp_2lines("4: Down", "6: Up");
490 if(c == charcode_f) return;
491 c = printhelp_2lines("7: Fast Down", "9: Fast Up");
492 if(c == charcode_f) return;
493 c = printhelp_2lines("2: Band Down", "8: Band Up");
494 if(c == charcode_f) return;
495 c = printhelp_2lines("0: Mode3K", " ");
496 if(c == charcode_f) return;
497 c = printhelp_2lines("a: AM/FM", "b: Volume");
498 if(c == charcode_f) return;
499 c = printhelp_2lines("c: Scan", "d: Stereo mode");
500 if(c == charcode_f) return;
501 c = printhelp_2lines("e: Backlight", "f: (Exit) Help");
502 if(c == charcode_f) return;
504 if(c == charcode_f) return;
508 void menu_poweroff(void)
511 c = printhelp_2lines("Poweroff", "A=Yes");
512 if(c == charcode_a) {
517 void setup_akc6955(void)
519 // akc6955_chg_fm(fm); // Set to AM
523 0x4c, //REG00 //Modify
538 0x82, //REG15 //Modify
542 akc6955_writecmd(0x00, 0x4c);
543 akc6955_writecmd(0x01, 0b00010000);
544 akc6955_writecmd(0x02, 0b01001010);
545 akc6955_writecmd(0x03, 0xc8);
546 akc6955_writecmd(0x04, 0x19);
547 akc6955_writecmd(0x05, 0x32);
548 akc6955_writecmd(0x06, 0xa1);
549 akc6955_writecmd(0x07, 0b10100001);
550 akc6955_writecmd(0x08, 0b01010000);
551 akc6955_writecmd(0x09, 0b11000111);
552 akc6955_writecmd(0x09, 0b01111111);
553 akc6955_writecmd(0x0b, 0b11100000);
554 akc6955_writecmd(0x0c, 0b00000000);
555 akc6955_writecmd(0x0d, 0b00001100);
556 akc6955_writecmd(0x0e, 0x40);
557 akc6955_writecmd(0x0f, 0x82);
558 akc6955_writecmd(0x10, 0xcc);
559 akc6955_writecmd(0x11, 0xf9);
563 akc6955_writecmd(AKC6955_POWER, 0xc0); // You musto *not* mute, set b2 to '0".
564 akc6955_writecmd(AKC6955_VOLUME, 0xc0); // You must select to radio(b1 = '0).
565 akc6955_chg_fm(fm); // Set to AM
567 akc6955_set_amband(amband);
568 if(amband == AKC6955_BAND_AMUSER) call_userband(am_userbandnum);
569 amfreq = amfreq_bank[amband];
570 akc6955_set_freq(amfreq);
572 akc6955_set_fmband(fmband);
573 if(fmband == AKC6955_BAND_FMUSER) call_userband(fm_userbandnum);
574 fmfreq = fmfreq_bank[fmband];
575 akc6955_set_freq(fmfreq);
576 }// Dummy, TBS (954KHz)
577 akc6955_set_power(0xff); // Power ON
578 akc6955_setvolume(36); // Temporally
579 akc6955_writecmd(AKC6955_THRESH, threshold);
580 akc6955_setvolumemode(0);
581 akc6955_set_lowboost(lowboost);
589 c = printhelp_2lines("Save settings", "A=Yes");
590 if(c == charcode_a) {
598 c = printhelp_2lines("Load settings", "A=Yes B=Init");
599 if(c == charcode_a) {
604 c = printhelp_2lines("X) Load Error", "A=Fix");
611 } else if(c == charcode_b){
617 void setup_help(void)
622 c = printhelp_2lines("Help", "F=exit any=continue");
623 if(c == charcode_f) return;
624 c = printhelp_2lines("0: Power OFF", "C: Save status");
625 if(c == charcode_f) return;
626 c = printhelp_2lines("d: Reset default", "E: BL time");
627 if(c == charcode_f) return;
628 c = printhelp_2lines("A: Load", "2: Threshold");
629 if(c == charcode_f) return;
630 c = printhelp_2lines("3: Reserve", "4: Reserve");
631 if(c == charcode_f) return;
632 c = printhelp_2lines("6: Reserve", "7: Reserve");
633 if(c == charcode_f) return;
634 c = printhelp_2lines("8: Reserve", "9: Reserve");
635 if(c == charcode_f) return;
636 c = printhelp_2lines("5: Cancel", "f: (Exit) Help");
637 if(c == charcode_f) return;
639 if(c == charcode_f) return;
643 void setup_menu(void)
647 c = printhelp_2lines("Setup F=HELP", "5=Return");
674 * Main Menu : initial-screen -> 'F'.
684 printstr("Menu:F=HELP");
686 printstr("B=CANCEL");
688 n = pollkeys(pollkeybuf, 60, 1);
695 } else if(c == charcode_b){
697 } else if(c == charcode_1){
699 } else if(c == charcode_2){
702 } else if(c == charcode_3){
705 } else if(c == charcode_a){
707 } else if(c == charcode_5){
710 } else if(c == charcode_6){
712 } else if(c == charcode_4){
714 } else if(c == charcode_7){
717 } else if(c == charcode_8){
720 // if(fmbandwidth > 3) fmbandwidth = 0;
722 akc6955_set_fmbandwidth(fmbandwidth);
723 } else if(c == charcode_9){
725 } else if(c == charcode_0){
728 } else if(c == charcode_d){
731 } else if(c == charcode_c){
734 } else if(c == charcode_e){