]> hackdaworld.org Git - my-code/arm.git/blob - betty.c
3b29d2e2207c5a2e2659ea68771c6384a5f0889f
[my-code/arm.git] / betty.c
1 /*
2  * betty.c - alternative firmware for the betty tv ;)
3  *
4  * author: hackbard@hackdaworld.org
5  *
6  */
7
8 /* includes */
9 #include "betty.h"
10
11 /*
12  * global variables
13  */
14
15 const char announce[]="betty - live from flash at 0x80000000! ;)\r\n";
16 const char d1_txt[]="betty";
17 const char d2_txt[]="- alphablend -";
18 u8 contrast;
19 t_button button;
20 int sample_count;
21
22 /*
23  * functions
24  */
25
26 #define cc1100_init     spi1_init(8,SPI_MASTER,8)
27
28 void display_string_page(u8 x,u8 p,u8 *s,u8 f,u8 o,u8 sp) {
29
30         while(*(s)) {
31                 if(x==DISPLAY_DIMX) {
32                         p+=1;
33                         x=o;
34                 }
35                 display_font_page(x,p,(u8 *)default_font+(*(s)<<3),f);
36                 x+=sp;
37                 s++;
38         }
39 }
40
41 void __attribute__ ((interrupt("IRQ"))) set_sample(void) {
42
43         uart0_send_byte('S');
44         pwm_update_match(PWM_CHAN2,PWM_SINGLE_EDGE,sinus[sample_count++],0);
45         if(sample_count==0xff)
46                 sample_count=0;
47         interrupt_ack();
48         interrupt_tc_ir_set(INTERRUPT_TC0,INTERRUPT_M0);
49 }
50
51 void __attribute__ ((interrupt("IRQ"))) input_event(void) {
52
53         u8 noret,tries;
54
55         /* button scan */
56         if(button_get_event(&button)) {
57                 switch(button.key[0]) {
58                         case BUTTON_POWER:
59                                 display_logo((u8 *)default_logo);
60                                 break;
61                         case BUTTON_DOWN:
62                                 if(contrast>0x00)
63                                         contrast-=1;
64                                 DISPLAY_SET_CONTRAST(contrast);
65                                 break;
66                         case BUTTON_UP:
67                                 if(contrast<0x3f)
68                                         contrast+=1;
69                                 DISPLAY_SET_CONTRAST(contrast);
70                                 break;
71                         case BUTTON_A:
72                                 display_fill_screen(DISPLAY_FILL_W);
73                                 break;
74                         case BUTTON_B:
75                                 display_fill_screen(DISPLAY_FILL_LG);
76                                 break;
77                         case BUTTON_C:
78                                 display_fill_screen(DISPLAY_FILL_DG);
79                                 break;
80                         case BUTTON_D:
81                                 display_fill_screen(DISPLAY_FILL_B);
82                                 break;
83                         case BUTTON_1:
84                                 display_rectangle_page(4,2,60,5,
85                                                        DISPLAY_FILL_B,0xff);
86                                 break;
87                         case BUTTON_2:
88                                 display_rectangle_page(40,5,50,5,
89                                                        DISPLAY_FILL_LG,0x7f);
90                                 break;
91                         case BUTTON_3:
92                                 break;
93                         case BUTTON_4:
94                                 display_font_page(42,18,
95                                                   (u8 *)default_font+(0x34<<3),
96                                                   DISPLAY_FILL_B);
97                                 break;
98                         case BUTTON_5:
99                                 display_font_page(50,18,
100                                                   (u8 *)default_font+(0x35<<3),
101                                                   DISPLAY_FILL_DG);
102                                 break;
103                         case BUTTON_6:
104                                 display_font_page(58,18,
105                                                   (u8 *)default_font+(0x36<<3),
106                                                   DISPLAY_FILL_W);
107                                 break;
108                         case BUTTON_7:
109                                 break;
110                         case BUTTON_8:
111                                 break;
112                         case BUTTON_BETTY:
113                                 display_string_page(50,13,(u8 *)d1_txt,
114                                                     DISPLAY_FILL_B,0,8);
115                                 break;
116                         case BUTTON_EXIT:
117                                 display_string_page(10,8,(u8 *)d2_txt,
118                                                     DISPLAY_FILL_B,0,8);
119                                 break;
120                         default:
121                                 display_clear_screen();
122                                 break;
123                 }
124         }
125
126         /* resume the interrupt at button release */
127         noret=1;
128         while(noret) {
129                 tries=0xff;
130                 noret=1;
131                 while(tries--) {
132                         noret=IOPIN0&(1<<30)?0:1;
133                         if(noret)
134                                 break;
135                 }
136         }
137         interrupt_ack();
138         interrupt_ext_ir_set(INTERRUPT_EXT3);
139 }
140
141 /*
142  * main function
143  */
144
145 int main() {
146
147         /* variables */
148
149         /* init */
150         sample_count=0;
151
152         /* system init */
153         pll_init();
154         pin_init();
155         ext_mem_init();
156
157         /* memory mapping - dirty! */
158         if((void *)announce<(void *)FLASH_BANK0)
159                 mmap_init(MEMTYPE_RAM);
160         else
161                 mmap_init(MEMTYPE_EXT);
162         
163         /* uart init */
164         uart0_init();
165
166         /* display init */
167         display_bl_init();
168
169         /* button init */
170         button.mode=BUTTON_INT;
171         button_init(&button);
172         button_set_retries(&button,30);
173
174         /* flash init */
175         flash_init();
176
177         /* display init */
178         display_init();
179         contrast=0x38;
180
181         /* interrupt init */
182         interrupt_init();
183
184         // ext interrupt
185         interrupt_ext_ir_config(INTERRUPT_EXT3,INTERRUPT_EXT_NOWAKE,
186                                 INTERRUPT_EXT_MODE_EDGE,
187                                 INTERRUPT_EXT_POLAR_LOW);
188         interrupt_ext_ir_set(INTERRUPT_EXT3);
189         interrupt_enable(INTERRUPT_EINT3,INTERRUPT_MODE_VIRQ,
190                          0,(u32)&input_event);
191
192         // timer interrupt
193         interrupt_tc_config(INTERRUPT_TC0,INTERRUPT_TC_MODE_T,0,0);
194         interrupt_tc_match_config(INTERRUPT_TC0,INTERRUPT_M0,120,
195                                   INTERRUPT_TC_MATCH_IR|INTERRUPT_TC_MATCH_RESET);
196         interrupt_tc_ir_set(INTERRUPT_TC0,INTERRUPT_M0);
197         interrupt_enable(INTERRUPT_PWM,INTERRUPT_MODE_VIRQ,1,(u32)&set_sample);
198
199         /* pwm init */
200         pwm_set_rate_and_prescaler(0xff,0);
201         pwm_config(PWM_CHAN2,PWM_SINGLE_EDGE,0,0);
202         pwm_match_ctrl_config(PWM_CHAN2,0);
203         interrupt_pwm_ir_set(PWM_CHAN2);
204         pwm_enable;
205         
206
207         /*
208          * start it ...
209          */
210
211         /* toggle the display back light */
212         display_bl_toggle();
213
214         /* announce */
215         uart0_send_string((char *)announce);
216
217         
218         while(1) {
219                 pause(0xffffff);
220                 uart0_send_string((char *)announce);
221         }
222
223         return 0;
224 }