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/gpio/gpio.h"
47 #include "core/systick/systick.h"
48 #include "core/usbhid-rom/usbmsc.h"
51 #include "core/cmd/cmd.h"
54 #include "lcd/display.h"
56 #include "r0ketports.h"
58 uint8_t getInputRaw(void) {
59 uint8_t result
= BTN_NONE
;
61 if (gpioGetValue(RB_BTN3
)==0) {
65 if (gpioGetValue(RB_BTN2
)==0) {
69 if (gpioGetValue(RB_BTN4
)==0) {
73 if (gpioGetValue(RB_BTN0
)==0) {
77 if (gpioGetValue(RB_BTN1
)==0) {
84 void backlightInit(void) {
85 /* Enable the clock for CT16B1 */
86 SCB_SYSAHBCLKCTRL
|= (SCB_SYSAHBCLKCTRL_CT16B1
);
88 /* Configure PIO1.9 as Timer1_16 MAT0 Output */
89 IOCON_PIO1_9
&= ~IOCON_PIO1_9_FUNC_MASK
;
90 IOCON_PIO1_9
|= IOCON_PIO1_9_FUNC_CT16B1_MAT0
;
92 /* Set default duty cycle (MR1) */
93 TMR_TMR16B1MR0
= 0; //(0xFFFF * (100 - brightness)) / 100;
95 /* External Match Register Settings for PWM */
96 TMR_TMR16B1EMR
= TMR_TMR16B1EMR_EMC0_TOGGLE
| TMR_TMR16B1EMR_EM0
;
99 TMR_TMR16B1TCR
= TMR_TMR16B1TCR_COUNTERENABLE_ENABLED
;
102 TMR_TMR16B1PWMC
= TMR_TMR16B1PWMC_PWM0_ENABLED
;
105 gpioSetDir(RB_PWR_LCDBL
, gpioDirection_Output
);
106 gpioSetValue(RB_PWR_LCDBL
, 0);
112 // TODO FIXME special port disable ? LEDs BTNs ?
115 // TODO FIXME more power init needed ? chrg + volt input ?
116 // enable external vcc
117 gpioSetDir(RB_PWR_GOOD
, gpioDirection_Output
);
118 gpioSetValue (RB_PWR_GOOD
, 0);
120 // Disable USB Connect (we don't want USB by default)
121 gpioSetDir(USB_CONNECT
, gpioDirection_Output
);
122 gpioSetValue(USB_CONNECT
, 1);
124 static uint8_t ports
[] = { RB_BTN0
, RB_BTN1
, RB_BTN2
, RB_BTN3
, RB_BTN4
,
125 RB_LED0
, RB_LED1
, RB_LED2
,
126 RB_SPI_SS0
, RB_SPI_SS1
, RB_SPI_SS2
,
127 RB_SPI_SS3
, RB_SPI_SS4
, RB_SPI_SS5
,
128 RB_HB0
, RB_HB1
, RB_HB2
,
129 RB_HB3
, RB_HB4
, RB_HB5
};
131 volatile uint32_t * regs
[] = {&RB_BTN0_IO
, &RB_BTN1_IO
, &RB_BTN2_IO
,
132 &RB_BTN3_IO
, &RB_BTN4_IO
};
136 gpioSetDir(ports
[i
], ports
[i
+1], gpioDirection_Input
);
137 gpioSetPullup(regs
[i
/2], gpioPullupMode_PullUp
);
142 gpioSetDir(RB_PWR_CHRG
, gpioDirection_Input
);
143 gpioSetPullup (&RB_PWR_CHRG_IO
, gpioPullupMode_PullUp
);
145 gpioSetDir(RB_LED3
, gpioDirection_Input
);
146 IOCON_PIO1_11
= 0x41;
149 IOCON_JTAG_TDI_PIO0_11
&= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK
;
150 IOCON_JTAG_TDI_PIO0_11
|= IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO
;
153 gpioSetDir(ports
[i
],ports
[i
+1], gpioDirection_Output
);
154 gpioSetValue (ports
[i
], ports
[i
+1], 0);
159 IOCON_PIO1_11
= 0x41;
162 // TODO FIXME more init needed ?
163 gpioSetDir(RB_LCD_BL
, gpioDirection_Output
);
164 gpioSetValue (RB_LCD_BL
, 0);
167 RB_PWR_LCDBL_IO
&= ~RB_PWR_LCDBL_IO_FUNC_MASK
;
168 RB_PWR_LCDBL_IO
|= RB_PWR_LCDBL_IO_FUNC_GPIO
;
169 gpioSetDir(RB_PWR_LCDBL
, gpioDirection_Input
);
170 gpioSetPullup(&RB_PWR_LCDBL_IO
, gpioPullupMode_Inactive
);
173 // TODO FIXME init miso/mosi/sck somehow ?
175 while(i
<sizeof(ports
)){
176 gpioSetDir(ports
[i
],ports
[i
+1], gpioDirection_Output
);
177 gpioSetValue (ports
[i
], ports
[i
+1], 1);
186 /**************************************************************************/
188 Main program entry point. After reset, normal code execution will
191 /**************************************************************************/
194 // Configure cpu and mandatory peripherals
198 systickInit(CFG_SYSTICK_DELAY_IN_MS
);
204 badge_display_init();
205 gpioSetDir(0, 11, gpioDirection_Output
);
208 badge_framebuffer fb
= {
211 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
212 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
213 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
214 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
215 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
217 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
218 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
219 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
220 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
221 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
223 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
224 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
225 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
226 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
227 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
229 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
230 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
231 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
232 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
233 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
235 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
236 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
237 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
238 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
239 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
241 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
242 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
243 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
244 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
245 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
247 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
248 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
249 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
250 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
251 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
253 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
254 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
255 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
256 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
257 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
259 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
260 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
261 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
262 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
263 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
268 badge_framebuffer_flush(&fb
);
273 for(uint8_t i
= 0; ; ++i
) {
274 gpioSetValue(0, 11, i
& 1);