fw/apps: Remove manual gain control with keyboard
[osmocom-bb.git] / src / target / firmware / apps / layer1 / main.c
1 /* main program of Free Software for Calypso Phone */
2
3 /* (C) 2010 by Harald Welte <laforge@gnumonks.org>
4  *
5  * All Rights Reserved
6  *
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 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22
23 #include <stdint.h>
24 #include <stdio.h>
25
26 #include <debug.h>
27 #include <memory.h>
28 #include <delay.h>
29 #include <rffe.h>
30 #include <keypad.h>
31 #include <board.h>
32
33 #include <abb/twl3025.h>
34 #include <display.h>
35 #include <rf/trf6151.h>
36
37 #include <comm/sercomm.h>
38 #include <comm/timer.h>
39
40 #include <calypso/clock.h>
41 #include <calypso/tpu.h>
42 #include <calypso/tsp.h>
43 #include <calypso/irq.h>
44 #include <calypso/misc.h>
45
46 #include <layer1/sync.h>
47 #include <layer1/tpu_window.h>
48
49 const char *hr = "======================================================================\n";
50
51 /* MAIN program **************************************************************/
52
53 static void key_handler(enum key_codes code, enum key_states state);
54
55 int main(void)
56 {
57         board_init();
58
59         puts("\n\nOSMOCOM Layer 1 (revision " GIT_REVISION ")\n");
60         puts(hr);
61
62         /* Dump device identification */
63         dump_dev_id();
64         puts(hr);
65
66         keypad_set_handler(&key_handler);
67
68         /* Dump clock config after PLL set */
69         calypso_clk_dump();
70         puts(hr);
71
72         display_puts("layer1.bin");
73
74         layer1_init();
75
76         display_unset_attr(DISP_ATTR_INVERT);
77
78         tpu_frame_irq_en(1, 1);
79
80         while (1) {
81                 l1a_compl_execute();
82                 update_timers();
83         }
84
85         /* NOT REACHED */
86
87         twl3025_power_off();
88 }
89
90 static int afcout = 0;
91
92 static void tspact_toggle(uint8_t num)
93 {
94         printf("TSPACT%u toggle\n", num);
95         tsp_act_toggle((1 << num));
96         tpu_enq_sleep();
97         tpu_enable(1);
98         tpu_wait_idle();
99 }
100
101 static void key_handler(enum key_codes code, enum key_states state)
102 {
103         if (state != PRESSED)
104                 return;
105
106         switch (code) {
107         case KEY_4:
108                 tspact_toggle(6);       /* TRENA (RFFE) */
109                 break;
110         case KEY_5:
111                 tspact_toggle(8);       /* GSM_TXEN (RFFE) */
112                 break;
113         case KEY_6:
114                 tspact_toggle(1);       /* PAENA (RFFE) */
115                 break;
116         case KEY_7:                     /* decrement AFC OUT */
117                 afcout -= 100;
118                 if (afcout < -4096)
119                         afcout = -4096;
120                 twl3025_afc_set(afcout);
121                 printf("AFC OUT: %u\n", twl3025_afcout_get());
122                 break;
123         case KEY_9:                     /* increase AFC OUT */
124                 afcout += 100;
125                 if (afcout > 4095)
126                         afcout = 4095;
127                 twl3025_afc_set(afcout);
128                 printf("AFC OUT: %u\n", twl3025_afcout_get());
129                 break;
130         default:
131                 break;
132         }
133 }
134
135