/
pin.h
153 lines (136 loc) · 3.58 KB
/
pin.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* @file drivers/pin.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_PIN_H__
#define __DRIVERS_PIN_H__
#include "simba.h"
/**
* Configure the pin as an output pin.
*/
#define PIN_OUTPUT 0
/**
* Configure the pin as an input pin.
*/
#define PIN_INPUT 1
#include "pin_port.h"
extern struct pin_device_t pin_device[PIN_DEVICE_MAX];
/**
* Initialize the pin 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 pin_module_init(void);
/**
* Initialize given driver object with given device and mode.
*
* @param[out] self_p Driver object to be initialized.
* @param[in] dev_p Device to use.
* @param[in] mode Pin mode. One of ``PIN_INPUT`` or ``PIN_OUTPUT``.
*
* @return zero(0) or negative error code.
*/
int pin_init(struct pin_driver_t *self_p,
struct pin_device_t *dev_p,
int mode);
/**
* Write given value to given pin.
*
* @param[in] self_p Driver object.
* @param[in] value ``1`` for high and ``0`` for low output.
*
* @return zero(0) or negative error code.
*/
int pin_write(struct pin_driver_t *self_p, int value);
/**
* Read the current value of given pin.
*
* @param[in] self_p Driver object.
*
* @return ``1`` for high and ``0`` for low input, otherwise negative
* error code.
*/
int pin_read(struct pin_driver_t *self_p);
/**
* Toggle the pin output value (high/low).
*
* @param[in] self_p Driver object.
*
* @return zero(0) or negative error code.
*/
int pin_toggle(struct pin_driver_t *self_p);
/**
* Set the pin mode of given pin.
*
* @param[in] self_p Driver object.
* @param[in] mode New pin mode.
*
* @return zero(0) or negative error code.
*/
int pin_set_mode(struct pin_driver_t *self_p, int mode);
/**
* Pin device mode to set. One of ``PIN_INPUT`` or ``PIN_OUTPUT``.
*
* @param[in] self_p Pin device.
* @param[in] mode New pin mode.
*
* @return zero(0) or negative error code.
*/
static inline int pin_device_set_mode(const struct pin_device_t *dev_p,
int mode)
{
return (pin_port_device_set_mode(dev_p, mode));
}
/**
* Read the value of given pin device.
*
* @param[in] self_p Pin device.
*
* @return ``1`` for high and ``0`` for low input, otherwise negative
* error code.
*/
static inline int pin_device_read(const struct pin_device_t *dev_p)
{
return (pin_port_device_read(dev_p));
}
/**
* Write high to given pin device.
*
* @param[in] self_p Pin device.
*
* @return zero(0) or negative error code.
*/
static inline int pin_device_write_high(const struct pin_device_t *dev_p)
{
return (pin_port_device_write_high(dev_p));
}
/**
* Write low to given pin device.
*
* @param[in] self_p Pin device.
*
* @return zero(0) or negative error code.
*/
static inline int pin_device_write_low(const struct pin_device_t *dev_p)
{
return (pin_port_device_write_low(dev_p));
}
#endif