summaryrefslogtreecommitdiff
path: root/fw/fe310/phone/timer.c
blob: cd6605312c86966461d0cf1f3f23adbf629a94ad (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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <eos.h>
#include <soc/timer.h>
#include <dev/net.h>

#include <eve/eve.h>
#include <eve/eve_kbd.h>
#include <eve/eve_font.h>

#include <eve/screen/window.h>
#include <eve/screen/page.h>
#include <eve/screen/form.h>

#include "app/app.h"

#include "timer.h"

static void timer(unsigned char evt) {
    int rv;

    printf("TIMER\n");
    eos_timer_set(EOS_TIMER_ETYPE_USR, 500);
}

int timer_app(EVEWindow *window, EVEViewStack *stack) {
    EVEFormSpec spec[] = {
        APP_SPACERW(1,1),
    };
    EVEPage *page = eve_form_create(window, stack, spec, APP_SPEC_SIZE(spec), NULL, timer_close);
    if (page == NULL) {
        APP_LOG(APP_LOG_ERR, "OUT OF MEMORY\n");
        return EVE_ERR_NOMEM;
    }
    eos_timer_set_handler(EOS_TIMER_ETYPE_USR, timer);
    eos_timer_set(EOS_TIMER_ETYPE_USR, 500);
    eos_net_acquire_for_evt(EOS_EVT_TIMER | EOS_TIMER_ETYPE_USR, 1);

    return EVE_OK;
}

void timer_close(EVEPage *page) {
    eos_timer_clear(EOS_TIMER_ETYPE_USR);
    eos_timer_set_handler(EOS_TIMER_ETYPE_USR, NULL);
    eos_net_acquire_for_evt(EOS_EVT_TIMER | EOS_TIMER_ETYPE_USR, 0);
    eve_form_destroy(page);
}