Schrift fest in Firmware eingebacken, damit die auch funktioniert, wenn auf dem
[hackover2013-badge-firmware.git] / badge / init.c
1 #include "init.h"
2 #include "pinconfig.h"
3 #include "util/util.h"
4 #include "ui/display.h"
5
6 #include <core/wdt/wdt.h>
7 #include <core/gpio/gpio.h>
8
9 static void badge_init_backlight(void) {
10 HOB_SET_PIN_FUNC(HOB_LCD_BACKLIGHT, CLKOUT);
11
12 wdtInit(false);
13 SCB_CLKOUTCLKSEL = SCB_MAINCLKSEL_SOURCE_WDTOSC;
14 SCB_CLKOUTCLKUEN = SCB_CLKOUTCLKUEN_DISABLE;
15 SCB_CLKOUTCLKUEN = SCB_CLKOUTCLKUEN_UPDATE;
16 SCB_CLKOUTCLKDIV = 75;
17 }
18
19 void badge_init(void) {
20 #define INPUT_PIN_CONFIG(spec, mode) do { \
21 HOB_SET_PIN_FUNC(spec, GPIO); \
22 gpioSetDir(HOB_PORT(spec), HOB_PIN(spec), gpioDirection_Input); \
23 gpioSetPullup(&HOB_IOCON(spec), (mode)); \
24 } while(0)
25
26 #ifdef HOB_REV2
27 INPUT_PIN_CONFIG(HOB_BTN_UP , gpioPullupMode_PullUp);
28 INPUT_PIN_CONFIG(HOB_BTN_RIGHT , gpioPullupMode_PullUp);
29 INPUT_PIN_CONFIG(HOB_BTN_DOWN , gpioPullupMode_PullUp);
30 INPUT_PIN_CONFIG(HOB_BTN_LEFT , gpioPullupMode_PullUp);
31 INPUT_PIN_CONFIG(HOB_BTN_A , gpioPullupMode_PullUp);
32 INPUT_PIN_CONFIG(HOB_BTN_B , gpioPullupMode_PullUp);
33 #else
34 INPUT_PIN_CONFIG(HOB_BTN_UP , gpioPullupMode_PullDown);
35 INPUT_PIN_CONFIG(HOB_BTN_RIGHT , gpioPullupMode_PullDown);
36 INPUT_PIN_CONFIG(HOB_BTN_DOWN , gpioPullupMode_PullDown);
37 INPUT_PIN_CONFIG(HOB_BTN_LEFT , gpioPullupMode_PullDown);
38 INPUT_PIN_CONFIG(HOB_BTN_CENTER, gpioPullupMode_PullDown);
39 INPUT_PIN_CONFIG(HOB_BTN_A , gpioPullupMode_PullDown);
40 INPUT_PIN_CONFIG(HOB_BTN_B , gpioPullupMode_PullDown);
41 #endif
42
43 #undef INPUT_PIN_CONFIG
44
45 #define OUTPUT_PIN_CONFIG(spec, value) do { \
46 HOB_SET_PIN_FUNC(spec, GPIO); \
47 gpioSetDir(HOB_PORT(spec), HOB_PIN(spec), gpioDirection_Output); \
48 gpioSetValue(HOB_PORT(spec), HOB_PIN(spec), (value)); \
49 } while(0)
50
51 OUTPUT_PIN_CONFIG(HOB_USB_CONNECT , 1);
52 OUTPUT_PIN_CONFIG(HOB_LCD_CS , 1);
53 OUTPUT_PIN_CONFIG(HOB_LCD_RST , 1);
54 OUTPUT_PIN_CONFIG(HOB_DATAFLASH_CS, 1);
55
56 #ifdef HOB_REV2
57 OUTPUT_PIN_CONFIG(HOB_LED_LEFT , 0);
58 OUTPUT_PIN_CONFIG(HOB_LED_RIGHT , 0);
59 #endif
60
61 #undef OUTPUT_PIN_CONFIG
62
63 badge_init_backlight();
64 badge_display_init();
65 }
This page took 0.050011 seconds and 5 git commands to generate.