-
Notifications
You must be signed in to change notification settings - Fork 0
/
display_extcomin.c
80 lines (68 loc) · 1.66 KB
/
display_extcomin.c
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
#include "app_error.h"
#include "nrfx_gpiote.h"
#include "nrfx_ppi.h"
#include "nrfx_rtc.h"
#include "./display_extcomin.h"
#include "./display.h"
#include "./app_rtc.h"
static bool enabled = false;
static bool pin_in_use = false;
static void gpiote_task_init()
{
uint32_t compare_evt_addr;
uint32_t gpiote_task_addr;
nrf_ppi_channel_t ppi_channel;
ret_code_t err_code;
nrfx_gpiote_out_config_t config = NRFX_GPIOTE_CONFIG_OUT_TASK_TOGGLE(false);
if (pin_in_use)
{
nrfx_gpiote_out_uninit(DISPLAY_EXTCOMIN);
}
err_code = nrfx_gpiote_out_init(DISPLAY_EXTCOMIN, &config);
pin_in_use = true;
APP_ERROR_CHECK(err_code);
err_code = nrfx_ppi_channel_alloc(&ppi_channel);
APP_ERROR_CHECK(err_code);
compare_evt_addr = nrfx_rtc_event_address_get(app_rtc_get_instance(), NRF_RTC_EVENT_COMPARE_0);
gpiote_task_addr = nrfx_gpiote_out_task_addr_get(DISPLAY_EXTCOMIN);
err_code = nrfx_ppi_channel_assign(ppi_channel, compare_evt_addr, gpiote_task_addr);
APP_ERROR_CHECK(err_code);
err_code = nrfx_ppi_channel_enable(ppi_channel);
APP_ERROR_CHECK(err_code);
}
void extcomin_setup()
{
if (!nrfx_gpiote_is_init())
{
APP_ERROR_CHECK(nrfx_gpiote_init());
}
app_rtc_request();
}
void extcomin_enable()
{
if (!enabled)
{
enabled = true;
gpiote_task_init();
nrfx_gpiote_out_task_enable(DISPLAY_EXTCOMIN);
}
}
void extcomin_disable()
{
if (enabled)
{
enabled = false;
if (pin_in_use)
{
nrfx_gpiote_out_uninit(DISPLAY_EXTCOMIN);
}
nrfx_gpiote_out_config_t config = NRFX_GPIOTE_CONFIG_OUT_SIMPLE(false);
APP_ERROR_CHECK(nrfx_gpiote_out_init(DISPLAY_EXTCOMIN, &config));
pin_in_use = true;
}
}
void extcomin_uninit()
{
extcomin_disable();
app_rtc_release();
}