33d048da3944d27953badb4297fac0811b9cc987
[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 INPUT_PIN_CONFIG(HOB_BTN_UP , gpioPullupMode_PullUp);
27 INPUT_PIN_CONFIG(HOB_BTN_RIGHT , gpioPullupMode_PullUp);
28 INPUT_PIN_CONFIG(HOB_BTN_DOWN , gpioPullupMode_PullUp);
29 INPUT_PIN_CONFIG(HOB_BTN_LEFT , gpioPullupMode_PullUp);
30 INPUT_PIN_CONFIG(HOB_BTN_A , gpioPullupMode_PullUp);
31 INPUT_PIN_CONFIG(HOB_BTN_B , gpioPullupMode_PullUp);
32
33 #undef INPUT_PIN_CONFIG
34
35 #define OUTPUT_PIN_CONFIG(spec, value) do { \
36 HOB_SET_PIN_FUNC(spec, GPIO); \
37 gpioSetDir(HOB_PORT(spec), HOB_PIN(spec), gpioDirection_Output); \
38 gpioSetValue(HOB_PORT(spec), HOB_PIN(spec), (value)); \
39 } while(0)
40
41 OUTPUT_PIN_CONFIG(HOB_USB_CONNECT , 1);
42 OUTPUT_PIN_CONFIG(HOB_LCD_CS , 1);
43 OUTPUT_PIN_CONFIG(HOB_LCD_RST , 1);
44 OUTPUT_PIN_CONFIG(HOB_DATAFLASH_CS, 1);
45 OUTPUT_PIN_CONFIG(HOB_LED_LEFT , 0);
46 OUTPUT_PIN_CONFIG(HOB_LED_RIGHT , 0);
47
48 #undef OUTPUT_PIN_CONFIG
49
50 badge_init_backlight();
51 badge_display_init();
52 }
This page took 0.036856 seconds and 3 git commands to generate.