summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/eos.c
blob: 6df87009140f58b1192dd2a0ad591d316cad7027 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>

#include "encoding.h"
#include "platform.h"
#include "prci_driver.h"

#include "event.h"
#include "soc/interrupt.h"
#include "soc/timer.h"
#include "soc/pwr.h"
#include "soc/i2s.h"
#include "soc/i2c.h"
#include "soc/uart.h"
#include "soc/spi.h"

#include "dev/flash.h"
#include "dev/spi.h"
#include "dev/net.h"
#include "dev/lcd.h"
#include "dev/sdcard.h"
#include "dev/gt911.h"
#include "dev/bq25895.h"
#include "dev/eve.h"

#include "net/pwr.h"
#include "net/wifi.h"
#include "net/sock.h"
#include "net/cell.h"

#include "eos.h"

uint8_t eos_init(void) {
    uint8_t wakeup_cause;
    int rv;

    PRCI_use_default_clocks();
    PRCI_use_pll(PLL_REFSEL_HFXOSC, 0, 1, 31, 1, -1, -1, -1);

    eos_flash_init();

    wakeup_cause = eos_pwr_wakeup_cause();

    eos_evtq_init(wakeup_cause);
    eos_intr_init(wakeup_cause);
    eos_timer_init(wakeup_cause);
    eos_uart_init(wakeup_cause);

    printf("INIT:%d\n", wakeup_cause);

    rv = eos_pwr_init(wakeup_cause);
    if (rv) printf("PWR INIT ERR:%d\n", rv);
    rv = eos_i2s_init(wakeup_cause);
    if (rv) printf("I2S INIT ERR:%d\n", rv);
    rv = eos_i2c_init(wakeup_cause);
    if (rv) printf("I2C INIT ERR:%d\n", rv);
    rv = eos_spi_init(wakeup_cause);
    if (rv) printf("SPI INIT ERR:%d\n", rv);
    rv = eos_spi_dev_init(wakeup_cause);
    if (rv) printf("SPI DEV INIT ERR:%d\n", rv);

    rv = eos_bq25895_init(wakeup_cause);
    if (rv) printf("BQ25895 INIT ERR:%d\n", rv);

    rv = eos_net_init(wakeup_cause);
    if (rv) printf("NET INIT ERR:%d\n", rv);

    rv = eos_sdc_init(wakeup_cause);
    if (rv) printf("SDC INIT ERR:%d\n", rv);

    rv = eos_eve_init(wakeup_cause);
    if (rv) printf("EVE INIT ERR:%d\n", rv);

    rv = eos_lcd_init(wakeup_cause);
    if (rv) printf("LCD INIT ERR:%d\n", rv);

    rv = eos_eve_run(wakeup_cause);
    if (rv) printf("EVE RUN ERR:%d\n", rv);

    eos_pwr_net_init();
    eos_wifi_init();
    eos_sock_init();
    eos_cell_init();

    return wakeup_cause;
}

void eos_run(uint8_t wakeup_cause) {
    int rv;

    rv = eos_net_run(wakeup_cause);
    if (rv) printf("NET RUN ERR:%d\n", rv);
}

void eos_run_once(void) {
    eos_gt911_cfg_print();
    eos_gt911_configure();
    eos_gt911_cfg_print();

    eos_eve_calibrate();
}