Level-Konverter: Leerzeichen am Ende von Optionszeilen trimmen.
[hackover2013-badge-firmware.git] / badge / main.c
1 /**************************************************************************/
2 /*!
3 @file main.c
4 @author K. Townsend (microBuilder.eu)
5
6 @section LICENSE
7
8 Software License Agreement (BSD License)
9
10 Copyright (c) 2011, microBuilder SARL
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 1. Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 2. Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 3. Neither the name of the copyright holders nor the
21 names of its contributors may be used to endorse or promote products
22 derived from this software without specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 /**************************************************************************/
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
39
40 #include "projectconfig.h"
41 #include "sysinit.h"
42
43 #include "core/adc/adc.h"
44 #include "core/cpu/cpu.h"
45 #include "core/pmu/pmu.h"
46 #include "core/wdt/wdt.h"
47 #include "core/gpio/gpio.h"
48 #include "core/ssp/ssp.h"
49 #include "core/systick/systick.h"
50 #include "core/usbhid-rom/usbmsc.h"
51
52 #ifdef CFG_INTERFACE
53 #include "core/cmd/cmd.h"
54 #endif
55
56 #include "init.h"
57 #include "ui/display.h"
58 #include "ui/sprite.h"
59 #include "ui/event.h"
60 #include "ui/font.h"
61 #include "util/util.h"
62 #include "jumpnrun/jumpnrun.h"
63
64 #include "dataflash/at45db041d.h"
65
66 #include "drivers/fatfs/ff.h"
67
68 #include "badge/pinconfig.h"
69 #include <funk/nrf24l01p.h>
70
71 #ifdef R0KET
72
73 #include "r0ketports.h"
74 void rbBacklightInit(void) {
75 /* Enable the clock for CT16B1 */
76 SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT16B1);
77
78 /* Configure PIO1.9 as Timer1_16 MAT0 Output */
79 IOCON_PIO1_9 &= ~IOCON_PIO1_9_FUNC_MASK;
80 IOCON_PIO1_9 |= IOCON_PIO1_9_FUNC_CT16B1_MAT0;
81
82 /* Set default duty cycle (MR1) */
83 TMR_TMR16B1MR0 = 0; //(0xFFFF * (100 - brightness)) / 100;
84
85 /* External Match Register Settings for PWM */
86 TMR_TMR16B1EMR = TMR_TMR16B1EMR_EMC0_TOGGLE | TMR_TMR16B1EMR_EM0;
87
88 /* enable Timer1 */
89 TMR_TMR16B1TCR = TMR_TMR16B1TCR_COUNTERENABLE_ENABLED;
90
91 /* Enable PWM0 */
92 TMR_TMR16B1PWMC = TMR_TMR16B1PWMC_PWM0_ENABLED;
93
94 // Enable Step-UP
95 gpioSetDir(RB_PWR_LCDBL, gpioDirection_Output);
96 gpioSetValue(RB_PWR_LCDBL, 0);
97 }
98
99 void rbInit() {
100 RB_HB0_IO &= ~IOCON_SWDIO_PIO1_3_FUNC_MASK;
101 RB_HB0_IO |= IOCON_SWDIO_PIO1_3_FUNC_GPIO;
102 RB_HB1_IO &= ~IOCON_JTAG_TCK_PIO0_10_FUNC_MASK;
103 RB_HB1_IO |= IOCON_JTAG_TCK_PIO0_10_FUNC_GPIO;
104
105 struct {
106 int port;
107 int pin;
108 uint32_t volatile *reg;
109 gpioPullupMode_t mode;
110 } const input_pins[] = {
111 #ifdef HOB_REV2
112 { RB_BTN0 , &RB_BTN0_IO , gpioPullupMode_PullDown },
113 { RB_BTN1 , &RB_BTN1_IO , gpioPullupMode_PullDown },
114 { RB_BTN2 , &RB_BTN2_IO , gpioPullupMode_PullDown },
115 { RB_BTN3 , &RB_BTN3_IO , gpioPullupMode_PullDown },
116 { RB_BTN4 , &RB_BTN4_IO , gpioPullupMode_PullDown },
117 { RB_HB0 , &RB_HB0_IO , gpioPullupMode_PullDown },
118 { RB_HB1 , &RB_HB1_IO , gpioPullupMode_PullDown },
119 { RB_PWR_CHRG, &RB_PWR_CHRG_IO, gpioPullupMode_PullDown }
120 #else
121 { RB_BTN0 , &RB_BTN0_IO , gpioPullupMode_PullUp },
122 { RB_BTN1 , &RB_BTN1_IO , gpioPullupMode_PullUp },
123 { RB_BTN2 , &RB_BTN2_IO , gpioPullupMode_PullUp },
124 { RB_BTN3 , &RB_BTN3_IO , gpioPullupMode_PullUp },
125 { RB_BTN4 , &RB_BTN4_IO , gpioPullupMode_PullUp },
126 { RB_HB0 , &RB_HB0_IO , gpioPullupMode_PullUp },
127 { RB_HB1 , &RB_HB1_IO , gpioPullupMode_PullUp },
128 { RB_PWR_CHRG, &RB_PWR_CHRG_IO, gpioPullupMode_PullUp }
129 #endif
130 };
131
132 for(int i = 0; i < ARRAY_SIZE(input_pins); ++i) {
133 gpioSetDir(input_pins[i].port, input_pins[i].pin, gpioDirection_Input);
134 gpioSetPullup(input_pins[i].reg, input_pins[i].mode);
135 }
136
137 // LED3 zur Bestimmung der Umgebungshelligkeit.
138 gpioSetDir(RB_LED3, gpioDirection_Input);
139 RB_LED3_IO = (RB_LED3_IO & IOCON_PIO1_11_FUNC_MASK) | IOCON_PIO1_11_FUNC_AD7;
140
141 // prepare LEDs
142 IOCON_JTAG_TDI_PIO0_11 &= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK;
143 IOCON_JTAG_TDI_PIO0_11 |= IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO;
144
145 struct {
146 int port;
147 int pin;
148 int value;
149 } const output_pins[] = {
150 { RB_PWR_GOOD , 0 },
151 { USB_CONNECT , 1 },
152 { RB_LCD_CS , 1 },
153 { RB_SPI_CS_DF, 1 },
154 { RB_SPI_SS2 , 1 },
155 { RB_SPI_SS3 , 1 },
156 { RB_SPI_SS4 , 1 },
157 { RB_SPI_SS5 , 1 },
158 { RB_LED0 , 0 },
159 { RB_LED1 , 0 },
160 { RB_LED2 , 0 },
161 { RB_LCD_BL , 0 },
162 { RB_HB2 , 1 },
163 { RB_HB3 , 1 },
164 { RB_HB4 , 1 },
165 { RB_HB5 , 1 }
166 };
167
168 for(int i = 0; i < ARRAY_SIZE(output_pins); ++i) {
169 gpioSetDir (output_pins[i].port, output_pins[i].pin, gpioDirection_Output);
170 gpioSetValue(output_pins[i].port, output_pins[i].pin, output_pins[i].value);
171 }
172
173 // Set P0.0 to GPIO
174 RB_PWR_LCDBL_IO &= ~RB_PWR_LCDBL_IO_FUNC_MASK;
175 RB_PWR_LCDBL_IO |= RB_PWR_LCDBL_IO_FUNC_GPIO;
176
177 gpioSetDir ( RB_PWR_LCDBL , gpioDirection_Input);
178 gpioSetPullup(&RB_PWR_LCDBL_IO, gpioPullupMode_Inactive);
179
180 rbBacklightInit();
181 badge_display_init();
182 }
183
184 #endif
185
186 void usbmode(void) {
187 badge_framebuffer fb = { { { 0 } } };
188
189 badge_framebuffer_render_text(&fb, 23, 30, "USB-Modus");
190 /*
191 badge_framebuffer_render_number(&fb, 23, 50, sizeof(jumpnrun_tile));
192 badge_framebuffer_render_number(&fb, 33, 50, sizeof(jumpnrun_item));
193 badge_framebuffer_render_number(&fb, 48, 50, sizeof(jumpnrun_enemy));
194 */
195 badge_framebuffer_flush(&fb);
196 usbMSCInit();
197 for(;;);
198 }
199
200 /**************************************************************************/
201 /*!
202 Main program entry point. After reset, normal code execution will
203 begin here.
204 */
205 /**************************************************************************/
206 int main(void)
207 {
208 // Configure cpu and mandatory peripherals
209 //systemInit();
210
211 cpuInit();
212 systickInit(CFG_SYSTICK_DELAY_IN_MS);
213
214 // pmuInit();
215 // adcInit();
216 #ifdef R0KET
217 rbInit();
218 #else
219 badge_init();
220 #endif
221
222 FATFS fs;
223 f_mount(0, &fs);
224
225 if(badge_input_raw() & BADGE_EVENT_KEY_DOWN) {
226 usbmode();
227 }
228
229 badge_event_start();
230 jumpnrun_play();
231
232 return 0;
233 }
This page took 0.055603 seconds and 5 git commands to generate.