/
exti.h
104 lines (90 loc) · 2.72 KB
/
exti.h
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
101
102
103
104
/**
* @file drivers/exti.h
*
* @section License
* Copyright (C) 2014-2016, Erik Moqvist
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* This file is part of the Simba project.
*/
#ifndef __DRIVERS_EXTI_H__
#define __DRIVERS_EXTI_H__
#include "simba.h"
struct exti_driver_t;
#include "exti_port.h"
/**
* Trigger an interrupt on both rising and falling edges.
*/
#define EXTI_TRIGGER_BOTH_EDGES EXTI_PORT_TRIGGER_BOTH_EDGES
/**
* Trigger an interrupt on falling edges.
*/
#define EXTI_TRIGGER_FALLING_EDGE EXTI_PORT_TRIGGER_FALLING_EDGE
/**
* Trigger an interrupt on both rising edges.
*/
#define EXTI_TRIGGER_RISING_EDGE EXTI_PORT_TRIGGER_RISING_EDGE
extern struct exti_device_t exti_device[EXTI_DEVICE_MAX];
/**
* Initialize the external interrupt (EXTI) module. This function must
* be called before calling any other function in this module.
*
* The module will only be initialized once even if this function is
* called multiple times.
*
* @return zero(0) or negative error code.
*/
int exti_module_init(void);
/**
* Initialize given driver object.
*
* @param[in] self_p Driver object to be initialized.
* @param[in] dev_p Device to use.
* @param[in] trigger One of ``EXTI_TRIGGER_BOTH_EDGES``,
* ``EXTI_TRIGGER_FALLING_EDGE`` or
* ``EXTI_TRIGGER_RISING_EDGE``.
* @param[in] on_interrupt Function callback called when an interrupt
* occurs.
* @param[in] arg_p Fucntion callback argument.
*
* @return zero(0) or negative error code.
*/
int exti_init(struct exti_driver_t *self_p,
struct exti_device_t *dev_p,
int trigger,
void (*on_interrupt)(void *arg_p),
void *arg_p);
/**
* Starts the EXTI device using given driver object.
*
* @param[in] self_p Driver object.
*
* @return zero(0) or negative error code.
*/
int exti_start(struct exti_driver_t *self_p);
/**
* Stops the EXTI device referenced by given driver object.
*
* @param[in] self_p Driver object.
*
* @return zero(0) or negative error code.
*/
int exti_stop(struct exti_driver_t *self_p);
/**
* Clear the interrupt flag.
*
* @param[in] self_p Driver object.
*
* @return zero(0) or negative error code.
*/
int exti_clear(struct exti_driver_t *self_p);
#endif