1 /**************************************************************************/
4 @author K. Townsend (microBuilder.eu)
8 Software License Agreement (BSD License)
10 Copyright (c) 2011, microBuilder SARL
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.
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.
35 /**************************************************************************/
40 #include "projectconfig.h"
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"
53 #include "core/cmd/cmd.h"
57 #include "ui/display.h"
58 #include "ui/sprite.h"
60 #include "util/util.h"
61 #include "jumpnrun/jumpnrun.h"
63 #include "dataflash/at45db041d.h"
65 #include "drivers/fatfs/ff.h"
67 #include "badge/pinconfig.h"
68 #include <funk/nrf24l01p.h>
72 #include "r0ketports.h"
73 void rbBacklightInit(void) {
74 /* Enable the clock for CT16B1 */
75 SCB_SYSAHBCLKCTRL
|= (SCB_SYSAHBCLKCTRL_CT16B1
);
77 /* Configure PIO1.9 as Timer1_16 MAT0 Output */
78 IOCON_PIO1_9
&= ~IOCON_PIO1_9_FUNC_MASK
;
79 IOCON_PIO1_9
|= IOCON_PIO1_9_FUNC_CT16B1_MAT0
;
81 /* Set default duty cycle (MR1) */
82 TMR_TMR16B1MR0
= 0; //(0xFFFF * (100 - brightness)) / 100;
84 /* External Match Register Settings for PWM */
85 TMR_TMR16B1EMR
= TMR_TMR16B1EMR_EMC0_TOGGLE
| TMR_TMR16B1EMR_EM0
;
88 TMR_TMR16B1TCR
= TMR_TMR16B1TCR_COUNTERENABLE_ENABLED
;
91 TMR_TMR16B1PWMC
= TMR_TMR16B1PWMC_PWM0_ENABLED
;
94 gpioSetDir(RB_PWR_LCDBL
, gpioDirection_Output
);
95 gpioSetValue(RB_PWR_LCDBL
, 0);
99 RB_HB0_IO
&= ~IOCON_SWDIO_PIO1_3_FUNC_MASK
;
100 RB_HB0_IO
|= IOCON_SWDIO_PIO1_3_FUNC_GPIO
;
101 RB_HB1_IO
&= ~IOCON_JTAG_TCK_PIO0_10_FUNC_MASK
;
102 RB_HB1_IO
|= IOCON_JTAG_TCK_PIO0_10_FUNC_GPIO
;
107 uint32_t volatile *reg
;
108 gpioPullupMode_t mode
;
109 } const input_pins
[] = {
111 { RB_BTN0
, &RB_BTN0_IO
, gpioPullupMode_PullDown
},
112 { RB_BTN1
, &RB_BTN1_IO
, gpioPullupMode_PullDown
},
113 { RB_BTN2
, &RB_BTN2_IO
, gpioPullupMode_PullDown
},
114 { RB_BTN3
, &RB_BTN3_IO
, gpioPullupMode_PullDown
},
115 { RB_BTN4
, &RB_BTN4_IO
, gpioPullupMode_PullDown
},
116 { RB_HB0
, &RB_HB0_IO
, gpioPullupMode_PullDown
},
117 { RB_HB1
, &RB_HB1_IO
, gpioPullupMode_PullDown
},
118 { RB_PWR_CHRG
, &RB_PWR_CHRG_IO
, gpioPullupMode_PullDown
}
120 { RB_BTN0
, &RB_BTN0_IO
, gpioPullupMode_PullUp
},
121 { RB_BTN1
, &RB_BTN1_IO
, gpioPullupMode_PullUp
},
122 { RB_BTN2
, &RB_BTN2_IO
, gpioPullupMode_PullUp
},
123 { RB_BTN3
, &RB_BTN3_IO
, gpioPullupMode_PullUp
},
124 { RB_BTN4
, &RB_BTN4_IO
, gpioPullupMode_PullUp
},
125 { RB_HB0
, &RB_HB0_IO
, gpioPullupMode_PullUp
},
126 { RB_HB1
, &RB_HB1_IO
, gpioPullupMode_PullUp
},
127 { RB_PWR_CHRG
, &RB_PWR_CHRG_IO
, gpioPullupMode_PullUp
}
131 for(int i
= 0; i
< ARRAY_SIZE(input_pins
); ++i
) {
132 gpioSetDir(input_pins
[i
].port
, input_pins
[i
].pin
, gpioDirection_Input
);
133 gpioSetPullup(input_pins
[i
].reg
, input_pins
[i
].mode
);
136 // LED3 zur Bestimmung der Umgebungshelligkeit.
137 gpioSetDir(RB_LED3
, gpioDirection_Input
);
138 RB_LED3_IO
= (RB_LED3_IO
& IOCON_PIO1_11_FUNC_MASK
) | IOCON_PIO1_11_FUNC_AD7
;
141 IOCON_JTAG_TDI_PIO0_11
&= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK
;
142 IOCON_JTAG_TDI_PIO0_11
|= IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO
;
148 } const output_pins
[] = {
167 for(int i
= 0; i
< ARRAY_SIZE(output_pins
); ++i
) {
168 gpioSetDir (output_pins
[i
].port
, output_pins
[i
].pin
, gpioDirection_Output
);
169 gpioSetValue(output_pins
[i
].port
, output_pins
[i
].pin
, output_pins
[i
].value
);
173 RB_PWR_LCDBL_IO
&= ~RB_PWR_LCDBL_IO_FUNC_MASK
;
174 RB_PWR_LCDBL_IO
|= RB_PWR_LCDBL_IO_FUNC_GPIO
;
176 gpioSetDir ( RB_PWR_LCDBL
, gpioDirection_Input
);
177 gpioSetPullup(&RB_PWR_LCDBL_IO
, gpioPullupMode_Inactive
);
180 badge_display_init();
185 /**************************************************************************/
187 Main program entry point. After reset, normal code execution will
190 /**************************************************************************/
193 // Configure cpu and mandatory peripherals
197 systickInit(CFG_SYSTICK_DELAY_IN_MS
);
210 for(uint8_t i = 1; ; ++i) {
211 badge_framebuffer fb = { { { 0 } } };
213 fb.data[2][86] = 0xff;
214 fb.data[3][87] = nrf_read_reg(R_CONFIG);
215 fb.data[4][86] = 0xff;
216 for(uint8_t j = 0; j < i; j += 3) {
217 fb.data[3][j / 3] = 0xff;
220 SCB_CLKOUTCLKDIV = i;
221 badge_framebuffer_flush(&fb);
228 badge_framebuffer fb
;
232 while(FR_OK
!= f_mount(0, &fatvol
)) {
237 if(FR_OK
== (res
= f_open(&fil
, "sshot.dat", FA_OPEN_EXISTING
| FA_READ
))) {
240 if(FR_OK
!= f_read(&fil
, &fb
, sizeof(fb
), &readbytes
)) {
246 badge_framebuffer_flush(&fb
);
249 if(badge_input_raw() & BADGE_EVENT_KEY_DOWN
) {
257 if(JUMPNRUN_ERROR
== jumpnrun_play("smb.lvl")) {
264 for(uint8_t i
= 0; ; ++i
) {
265 badge_event_t event
= badge_event_wait();
267 switch(badge_event_type(event
)) {
268 case BADGE_EVENT_USER_INPUT
: {
269 buttons
= badge_event_current_input_state();
272 case BADGE_EVENT_GAME_TICK
: {
273 badge_sprite
const sp
= { 4, 4, (uint8_t const *) "\xff\xff" };
274 badge_framebuffer fb
= { { { 0x80 } } };
276 if(buttons
& BADGE_EVENT_KEY_UP
) { badge_framebuffer_blt(&fb
, 30, 10, &sp
, 0); }
277 if(buttons
& BADGE_EVENT_KEY_DOWN
) { badge_framebuffer_blt(&fb
, 30, 50, &sp
, 0); }
278 if(buttons
& BADGE_EVENT_KEY_LEFT
) { badge_framebuffer_blt(&fb
, 10, 30, &sp
, 0); }
279 if(buttons
& BADGE_EVENT_KEY_RIGHT
) { badge_framebuffer_blt(&fb
, 50, 30, &sp
, 0); }
280 if(buttons
& BADGE_EVENT_KEY_CENTER
){ badge_framebuffer_blt(&fb
, 30, 30, &sp
, 0); }
281 if(buttons
& BADGE_EVENT_KEY_BTN_A
) { badge_framebuffer_blt(&fb
, 70, 10, &sp
, 0); }
282 if(buttons
& BADGE_EVENT_KEY_BTN_B
) { badge_framebuffer_blt(&fb
, 70, 50, &sp
, 0); }
284 badge_framebuffer_flush(&fb
);