User | Revision | Line number | New contents of line |
ssmith73 |
1:10feea6e63a8
|
1
|
/***************************************************************************//**
|
ssmith73 |
1:10feea6e63a8
|
2
|
* @file platform_drivers.cpp
|
ssmith73 |
1:10feea6e63a8
|
3
|
* @brief Implementation of Generic Platform Drivers.
|
ssmith73 |
1:10feea6e63a8
|
4
|
* @author DBogdan (dragos.bogdan@analog.com)
|
ssmith73 |
1:10feea6e63a8
|
5
|
********************************************************************************
|
ssmith73 |
1:10feea6e63a8
|
6
|
* Copyright 2017,2019(c) Analog Devices, Inc.
|
ssmith73 |
1:10feea6e63a8
|
7
|
*
|
ssmith73 |
1:10feea6e63a8
|
8
|
* All rights reserved.
|
ssmith73 |
1:10feea6e63a8
|
9
|
*
|
ssmith73 |
1:10feea6e63a8
|
10
|
* Redistribution and use in source and binary forms, with or without
|
ssmith73 |
1:10feea6e63a8
|
11
|
* modification, are permitted provided that the following conditions are met:
|
ssmith73 |
1:10feea6e63a8
|
12
|
* - Redistributions of source code must retain the above copyright
|
ssmith73 |
1:10feea6e63a8
|
13
|
* notice, this list of conditions and the following disclaimer.
|
ssmith73 |
1:10feea6e63a8
|
14
|
* - Redistributions in binary form must reproduce the above copyright
|
ssmith73 |
1:10feea6e63a8
|
15
|
* notice, this list of conditions and the following disclaimer in
|
ssmith73 |
1:10feea6e63a8
|
16
|
* the documentation and/or other materials provided with the
|
ssmith73 |
1:10feea6e63a8
|
17
|
* distribution.
|
ssmith73 |
1:10feea6e63a8
|
18
|
* - Neither the name of Analog Devices, Inc. nor the names of its
|
ssmith73 |
1:10feea6e63a8
|
19
|
* contributors may be used to endorse or promote products derived
|
ssmith73 |
1:10feea6e63a8
|
20
|
* from this software without specific prior written permission.
|
ssmith73 |
1:10feea6e63a8
|
21
|
* - The use of this software may or may not infringe the patent rights
|
ssmith73 |
1:10feea6e63a8
|
22
|
* of one or more patent holders. This license does not release you
|
ssmith73 |
1:10feea6e63a8
|
23
|
* from the requirement that you obtain separate licenses from these
|
ssmith73 |
1:10feea6e63a8
|
24
|
* patent holders to use this software.
|
ssmith73 |
1:10feea6e63a8
|
25
|
* - Use of the software either in source or binary form, must be run
|
ssmith73 |
1:10feea6e63a8
|
26
|
* on or directly connected to an Analog Devices Inc. component.
|
ssmith73 |
1:10feea6e63a8
|
27
|
*
|
ssmith73 |
1:10feea6e63a8
|
28
|
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
|
ssmith73 |
1:10feea6e63a8
|
29
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
|
ssmith73 |
1:10feea6e63a8
|
30
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
ssmith73 |
1:10feea6e63a8
|
31
|
* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
|
ssmith73 |
1:10feea6e63a8
|
32
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
ssmith73 |
1:10feea6e63a8
|
33
|
* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
|
ssmith73 |
1:10feea6e63a8
|
34
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
ssmith73 |
1:10feea6e63a8
|
35
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
ssmith73 |
1:10feea6e63a8
|
36
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
ssmith73 |
1:10feea6e63a8
|
37
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
ssmith73 |
1:10feea6e63a8
|
38
|
*******************************************************************************/
|
ssmith73 |
1:10feea6e63a8
|
39
|
|
ssmith73 |
1:10feea6e63a8
|
40
|
/******************************************************************************/
|
ssmith73 |
1:10feea6e63a8
|
41
|
/***************************** Include Files **********************************/
|
ssmith73 |
1:10feea6e63a8
|
42
|
/******************************************************************************/
|
ssmith73 |
1:10feea6e63a8
|
43
|
#include <stdint.h>
|
ssmith73 |
1:10feea6e63a8
|
44
|
#include <mbed.h>
|
ssmith73 |
1:10feea6e63a8
|
45
|
#include "platform_drivers.h"
|
ssmith73 |
1:10feea6e63a8
|
46
|
|
ssmith73 |
1:10feea6e63a8
|
47
|
/**
|
ssmith73 |
1:10feea6e63a8
|
48
|
Provide implementations for the following extern functions.
|
ssmith73 |
1:10feea6e63a8
|
49
|
For Example - in main.cpp
|
ssmith73 |
1:10feea6e63a8
|
50
|
DigitalOut SS(SPI_CS);
|
ssmith73 |
1:10feea6e63a8
|
51
|
mbed::SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK);
|
ssmith73 |
1:10feea6e63a8
|
52
|
mbed::I2C i2c(I2C_SDA, I2C_SCL);
|
ssmith73 |
1:10feea6e63a8
|
53
|
**/
|
ssmith73 |
1:10feea6e63a8
|
54
|
extern DigitalOut SS;
|
ssmith73 |
1:10feea6e63a8
|
55
|
extern SPI spi;
|
ssmith73 |
1:10feea6e63a8
|
56
|
extern I2C i2c;
|
ssmith73 |
1:10feea6e63a8
|
57
|
/******************************************************************************/
|
ssmith73 |
1:10feea6e63a8
|
58
|
/************************ Functions Definitions *******************************/
|
ssmith73 |
1:10feea6e63a8
|
59
|
/******************************************************************************/
|
ssmith73 |
1:10feea6e63a8
|
60
|
|
ssmith73 |
1:10feea6e63a8
|
61
|
/**
|
ssmith73 |
1:10feea6e63a8
|
62
|
* @brief Initialize the I2C communication peripheral.
|
ssmith73 |
1:10feea6e63a8
|
63
|
* @param desc - The I2C descriptor.
|
ssmith73 |
1:10feea6e63a8
|
64
|
* @param param - The structure that contains the I2C parameters.
|
ssmith73 |
1:10feea6e63a8
|
65
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
66
|
*/
|
ssmith73 |
1:10feea6e63a8
|
67
|
int32_t mbed_i2c_init(struct i2c_desc **desc,
|
ssmith73 |
1:10feea6e63a8
|
68
|
const struct i2c_init_param *param)
|
ssmith73 |
1:10feea6e63a8
|
69
|
{
|
ssmith73 |
1:10feea6e63a8
|
70
|
i2c_desc * new_desc = (i2c_desc*) malloc(sizeof(i2c_desc));
|
ssmith73 |
1:10feea6e63a8
|
71
|
new_desc->id = param->id;
|
ssmith73 |
1:10feea6e63a8
|
72
|
new_desc->slave_address = param->slave_address;
|
ssmith73 |
1:10feea6e63a8
|
73
|
new_desc->type = param->type;
|
ssmith73 |
1:10feea6e63a8
|
74
|
|
ssmith73 |
1:10feea6e63a8
|
75
|
*desc = new_desc;
|
ssmith73 |
1:10feea6e63a8
|
76
|
|
ssmith73 |
1:10feea6e63a8
|
77
|
return SUCCESS;
|
ssmith73 |
1:10feea6e63a8
|
78
|
}
|
ssmith73 |
1:10feea6e63a8
|
79
|
|
ssmith73 |
1:10feea6e63a8
|
80
|
|
ssmith73 |
1:10feea6e63a8
|
81
|
/**
|
ssmith73 |
1:10feea6e63a8
|
82
|
* @brief Free the resources allocated by i2c_init().
|
ssmith73 |
1:10feea6e63a8
|
83
|
* @param desc - The I2C descriptor.
|
ssmith73 |
1:10feea6e63a8
|
84
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
85
|
*/
|
ssmith73 |
1:10feea6e63a8
|
86
|
int32_t i2c_remove(struct i2c_desc *desc)
|
ssmith73 |
1:10feea6e63a8
|
87
|
{
|
ssmith73 |
1:10feea6e63a8
|
88
|
if (desc) {
|
ssmith73 |
1:10feea6e63a8
|
89
|
// Unused variable - fix compiler warning
|
ssmith73 |
1:10feea6e63a8
|
90
|
}
|
ssmith73 |
1:10feea6e63a8
|
91
|
|
ssmith73 |
1:10feea6e63a8
|
92
|
return SUCCESS;
|
ssmith73 |
1:10feea6e63a8
|
93
|
}
|
ssmith73 |
1:10feea6e63a8
|
94
|
|
ssmith73 |
1:10feea6e63a8
|
95
|
/**
|
ssmith73 |
1:10feea6e63a8
|
96
|
* @brief Write data to a slave device.
|
ssmith73 |
1:10feea6e63a8
|
97
|
* @param desc - The I2C descriptor.
|
ssmith73 |
1:10feea6e63a8
|
98
|
* @param data - Buffer that stores the transmission data.
|
ssmith73 |
1:10feea6e63a8
|
99
|
* @param bytes_number - Number of bytes to write.
|
ssmith73 |
1:10feea6e63a8
|
100
|
* @param stop_bit - Stop condition control.
|
ssmith73 |
1:10feea6e63a8
|
101
|
* Example: 0 - A stop condition will not be generated;
|
ssmith73 |
1:10feea6e63a8
|
102
|
* 1 - A stop condition will be generated.
|
ssmith73 |
1:10feea6e63a8
|
103
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
104
|
*/
|
ssmith73 |
1:10feea6e63a8
|
105
|
|
ssmith73 |
1:10feea6e63a8
|
106
|
int32_t mbed_i2c_write(struct i2c_desc *desc,
|
ssmith73 |
1:10feea6e63a8
|
107
|
uint8_t *data,
|
ssmith73 |
1:10feea6e63a8
|
108
|
uint8_t bytes_number,
|
ssmith73 |
1:10feea6e63a8
|
109
|
uint8_t stop_bit)
|
ssmith73 |
1:10feea6e63a8
|
110
|
{
|
ssmith73 |
1:10feea6e63a8
|
111
|
/**
|
ssmith73 |
1:10feea6e63a8
|
112
|
The MBED I2C API is reversed for parameter 4
|
ssmith73 |
1:10feea6e63a8
|
113
|
Instead of stop_bit - it has
|
ssmith73 |
1:10feea6e63a8
|
114
|
@param repeated - Repeated start, true - don't send stop at end default value is false.
|
ssmith73 |
1:10feea6e63a8
|
115
|
Inverting here to keep the no-OS/platform_drivers API
|
ssmith73 |
1:10feea6e63a8
|
116
|
*/
|
ssmith73 |
1:10feea6e63a8
|
117
|
i2c.write(desc->slave_address , (char *)data, bytes_number, !stop_bit);
|
ssmith73 |
1:10feea6e63a8
|
118
|
return SUCCESS;
|
ssmith73 |
1:10feea6e63a8
|
119
|
}
|
ssmith73 |
1:10feea6e63a8
|
120
|
|
ssmith73 |
1:10feea6e63a8
|
121
|
/**
|
ssmith73 |
1:10feea6e63a8
|
122
|
* @brief Read data from a slave device.
|
ssmith73 |
1:10feea6e63a8
|
123
|
* @param desc - The I2C descriptor.
|
ssmith73 |
1:10feea6e63a8
|
124
|
* @param data - Buffer that will store the received data.
|
ssmith73 |
1:10feea6e63a8
|
125
|
* @param bytes_number - Number of bytes to read.
|
ssmith73 |
1:10feea6e63a8
|
126
|
* @param stop_bit - Stop condition control.
|
ssmith73 |
1:10feea6e63a8
|
127
|
* Example: 0 - A stop condition will not be generated;
|
ssmith73 |
1:10feea6e63a8
|
128
|
* 1 - A stop condition will be generated.
|
ssmith73 |
1:10feea6e63a8
|
129
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
130
|
*/
|
ssmith73 |
1:10feea6e63a8
|
131
|
int32_t mbed_i2c_read(struct i2c_desc *desc,
|
ssmith73 |
1:10feea6e63a8
|
132
|
uint8_t *data,
|
ssmith73 |
1:10feea6e63a8
|
133
|
uint8_t bytes_number,
|
ssmith73 |
1:10feea6e63a8
|
134
|
uint8_t stop_bit)
|
ssmith73 |
1:10feea6e63a8
|
135
|
{
|
ssmith73 |
1:10feea6e63a8
|
136
|
/**
|
ssmith73 |
1:10feea6e63a8
|
137
|
The MBED I2C API is reversed for parameter 4
|
ssmith73 |
1:10feea6e63a8
|
138
|
Instead of stop_bit - it has
|
ssmith73 |
1:10feea6e63a8
|
139
|
@param repeated - Repeated start, true - don't send stop at end default value is false.
|
ssmith73 |
1:10feea6e63a8
|
140
|
Inverting here to keep the no-OS/platform_drivers API
|
ssmith73 |
1:10feea6e63a8
|
141
|
*/
|
ssmith73 |
1:10feea6e63a8
|
142
|
i2c.read(desc->slave_address, (char *)data, bytes_number, !stop_bit);
|
ssmith73 |
1:10feea6e63a8
|
143
|
|
ssmith73 |
1:10feea6e63a8
|
144
|
return SUCCESS;
|
ssmith73 |
1:10feea6e63a8
|
145
|
}
|
ssmith73 |
1:10feea6e63a8
|
146
|
|
ssmith73 |
1:10feea6e63a8
|
147
|
/**
|
ssmith73 |
1:10feea6e63a8
|
148
|
* @brief Initialize the SPI communication peripheral.
|
ssmith73 |
1:10feea6e63a8
|
149
|
* @param desc - The SPI descriptor.
|
ssmith73 |
1:10feea6e63a8
|
150
|
* @param init_param - The structure that contains the SPI parameters.
|
ssmith73 |
1:10feea6e63a8
|
151
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
152
|
*/
|
ssmith73 |
1:10feea6e63a8
|
153
|
int32_t mbed_spi_init(struct spi_desc **desc,
|
ssmith73 |
1:10feea6e63a8
|
154
|
const struct spi_init_param *param)
|
ssmith73 |
1:10feea6e63a8
|
155
|
{
|
ssmith73 |
1:10feea6e63a8
|
156
|
|
ssmith73 |
1:10feea6e63a8
|
157
|
// Create the spi description object for the device
|
ssmith73 |
1:10feea6e63a8
|
158
|
spi_desc * new_desc = (spi_desc*) malloc(sizeof(*new_desc));
|
ssmith73 |
1:10feea6e63a8
|
159
|
new_desc->chip_select = param->chip_select;
|
ssmith73 |
1:10feea6e63a8
|
160
|
new_desc->mode = param->mode;
|
ssmith73 |
1:10feea6e63a8
|
161
|
new_desc->max_speed_hz = param->max_speed_hz;
|
ssmith73 |
1:10feea6e63a8
|
162
|
*desc = new_desc;
|
ssmith73 |
1:10feea6e63a8
|
163
|
|
ssmith73 |
1:10feea6e63a8
|
164
|
spi.format(SEND_BYTE, param->mode); //Stick to byte-multiples
|
ssmith73 |
1:10feea6e63a8
|
165
|
/**
|
ssmith73 |
1:10feea6e63a8
|
166
|
NOTE: Actual frequency of SPI clk will be somewhat device
|
ssmith73 |
1:10feea6e63a8
|
167
|
dependent, relating to clock-settings, prescalars etc. If absolute
|
ssmith73 |
1:10feea6e63a8
|
168
|
SPI frequency is required, consult your device documentation.
|
ssmith73 |
1:10feea6e63a8
|
169
|
**/
|
ssmith73 |
1:10feea6e63a8
|
170
|
spi.frequency(param->max_speed_hz);
|
ssmith73 |
1:10feea6e63a8
|
171
|
spi.set_default_write_value(0x00); //code to write when reading back
|
ssmith73 |
1:10feea6e63a8
|
172
|
SS = GPIO_HIGH; //set SS high
|
ssmith73 |
1:10feea6e63a8
|
173
|
|
ssmith73 |
1:10feea6e63a8
|
174
|
return SUCCESS;
|
ssmith73 |
1:10feea6e63a8
|
175
|
}
|
ssmith73 |
1:10feea6e63a8
|
176
|
|
ssmith73 |
1:10feea6e63a8
|
177
|
/**
|
ssmith73 |
1:10feea6e63a8
|
178
|
* @brief Free the resources allocated by spi_init().
|
ssmith73 |
1:10feea6e63a8
|
179
|
* @param desc - The SPI descriptor.
|
ssmith73 |
1:10feea6e63a8
|
180
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
181
|
*/
|
ssmith73 |
1:10feea6e63a8
|
182
|
int32_t spi_remove(struct spi_desc *desc)
|
ssmith73 |
1:10feea6e63a8
|
183
|
{
|
ssmith73 |
1:10feea6e63a8
|
184
|
if (desc) {
|
ssmith73 |
1:10feea6e63a8
|
185
|
// Unused variable - fix compiler warning
|
ssmith73 |
1:10feea6e63a8
|
186
|
}
|
ssmith73 |
1:10feea6e63a8
|
187
|
|
ssmith73 |
1:10feea6e63a8
|
188
|
return SUCCESS;
|
ssmith73 |
1:10feea6e63a8
|
189
|
}
|
ssmith73 |
1:10feea6e63a8
|
190
|
|
ssmith73 |
1:10feea6e63a8
|
191
|
|
ssmith73 |
1:10feea6e63a8
|
192
|
/**
|
ssmith73 |
1:10feea6e63a8
|
193
|
* @brief Write and read data to/from SPI.
|
ssmith73 |
1:10feea6e63a8
|
194
|
*
|
ssmith73 |
1:10feea6e63a8
|
195
|
* This function will be updated to improve performance
|
ssmith73 |
1:10feea6e63a8
|
196
|
*
|
ssmith73 |
1:10feea6e63a8
|
197
|
* @param desc - The SPI descriptor.
|
ssmith73 |
1:10feea6e63a8
|
198
|
* @param data - The buffer with the transmitted/received data.
|
ssmith73 |
1:10feea6e63a8
|
199
|
* @param bytes_number - Number of bytes to write/read.
|
ssmith73 |
1:10feea6e63a8
|
200
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
201
|
*/
|
ssmith73 |
1:10feea6e63a8
|
202
|
int32_t spi_write_and_read(struct spi_desc *desc,
|
ssmith73 |
1:10feea6e63a8
|
203
|
uint8_t *data,
|
ssmith73 |
1:10feea6e63a8
|
204
|
uint8_t bytes_number)
|
ssmith73 |
1:10feea6e63a8
|
205
|
{
|
ssmith73 |
1:10feea6e63a8
|
206
|
if (desc) {
|
ssmith73 |
1:10feea6e63a8
|
207
|
// Unused variable - fix compiler warning
|
ssmith73 |
1:10feea6e63a8
|
208
|
}
|
ssmith73 |
1:10feea6e63a8
|
209
|
|
ssmith73 |
1:10feea6e63a8
|
210
|
volatile uint8_t rxData[3];
|
ssmith73 |
1:10feea6e63a8
|
211
|
|
ssmith73 |
1:10feea6e63a8
|
212
|
|
ssmith73 |
1:10feea6e63a8
|
213
|
SS = GPIO_LOW; //!select SS
|
ssmith73 |
1:10feea6e63a8
|
214
|
for(size_t byte = 0 ; byte < bytes_number ; byte++)
|
ssmith73 |
1:10feea6e63a8
|
215
|
{
|
ssmith73 |
1:10feea6e63a8
|
216
|
rxData[byte ] = spi.write(data[byte]);
|
ssmith73 |
1:10feea6e63a8
|
217
|
data[byte] = rxData[byte];
|
ssmith73 |
1:10feea6e63a8
|
218
|
}
|
ssmith73 |
1:10feea6e63a8
|
219
|
SS = GPIO_HIGH; //!deselect SS
|
ssmith73 |
1:10feea6e63a8
|
220
|
|
ssmith73 |
1:10feea6e63a8
|
221
|
return SUCCESS;
|
ssmith73 |
1:10feea6e63a8
|
222
|
}
|
ssmith73 |
1:10feea6e63a8
|
223
|
|
ssmith73 |
1:10feea6e63a8
|
224
|
/**
|
ssmith73 |
1:10feea6e63a8
|
225
|
* @brief Obtain the GPIO decriptor.
|
ssmith73 |
1:10feea6e63a8
|
226
|
* @param desc - The GPIO descriptor.
|
ssmith73 |
1:10feea6e63a8
|
227
|
* @param gpio_number - The number of the GPIO.
|
ssmith73 |
1:10feea6e63a8
|
228
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
229
|
*/
|
ssmith73 |
1:10feea6e63a8
|
230
|
int32_t gpio_get(struct gpio_desc **desc,
|
ssmith73 |
1:10feea6e63a8
|
231
|
gpio_desc init_values)
|
ssmith73 |
1:10feea6e63a8
|
232
|
{
|
ssmith73 |
1:10feea6e63a8
|
233
|
gpio_desc * new_gpio = new gpio_desc;
|
ssmith73 |
1:10feea6e63a8
|
234
|
new_gpio->id = init_values.id;
|
ssmith73 |
1:10feea6e63a8
|
235
|
new_gpio->number = init_values.number;
|
ssmith73 |
1:10feea6e63a8
|
236
|
new_gpio->pin = init_values.pin;
|
ssmith73 |
1:10feea6e63a8
|
237
|
new_gpio->type = init_values.type;
|
ssmith73 |
1:10feea6e63a8
|
238
|
|
ssmith73 |
1:10feea6e63a8
|
239
|
*desc = new_gpio;
|
ssmith73 |
1:10feea6e63a8
|
240
|
|
ssmith73 |
1:10feea6e63a8
|
241
|
return SUCCESS;
|
ssmith73 |
1:10feea6e63a8
|
242
|
}
|
ssmith73 |
1:10feea6e63a8
|
243
|
|
ssmith73 |
1:10feea6e63a8
|
244
|
/**
|
ssmith73 |
1:10feea6e63a8
|
245
|
* @brief Free the resources allocated by gpio_get().
|
ssmith73 |
1:10feea6e63a8
|
246
|
* @param desc - The SPI descriptor.
|
ssmith73 |
1:10feea6e63a8
|
247
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
248
|
*/
|
ssmith73 |
1:10feea6e63a8
|
249
|
int32_t gpio_remove(struct gpio_desc *desc)
|
ssmith73 |
1:10feea6e63a8
|
250
|
{
|
ssmith73 |
1:10feea6e63a8
|
251
|
if (desc) {
|
ssmith73 |
1:10feea6e63a8
|
252
|
// Unused variable - fix compiler warning
|
ssmith73 |
1:10feea6e63a8
|
253
|
}
|
ssmith73 |
1:10feea6e63a8
|
254
|
|
ssmith73 |
1:10feea6e63a8
|
255
|
return SUCCESS;
|
ssmith73 |
1:10feea6e63a8
|
256
|
}
|
ssmith73 |
1:10feea6e63a8
|
257
|
|
ssmith73 |
1:10feea6e63a8
|
258
|
/**
|
ssmith73 |
1:10feea6e63a8
|
259
|
* @brief Enable the input direction of the specified GPIO.
|
ssmith73 |
1:10feea6e63a8
|
260
|
* @param desc - The GPIO descriptor.
|
ssmith73 |
1:10feea6e63a8
|
261
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
262
|
*/
|
ssmith73 |
1:10feea6e63a8
|
263
|
int32_t gpio_direction_input(struct gpio_desc *desc)
|
ssmith73 |
1:10feea6e63a8
|
264
|
{
|
ssmith73 |
1:10feea6e63a8
|
265
|
//unnessary for MBED
|
ssmith73 |
1:10feea6e63a8
|
266
|
if(desc) { }
|
ssmith73 |
1:10feea6e63a8
|
267
|
// Unused variable - fix compiler warning
|
ssmith73 |
1:10feea6e63a8
|
268
|
|
ssmith73 |
1:10feea6e63a8
|
269
|
return 0;
|
ssmith73 |
1:10feea6e63a8
|
270
|
}
|
ssmith73 |
1:10feea6e63a8
|
271
|
|
ssmith73 |
1:10feea6e63a8
|
272
|
/**
|
ssmith73 |
1:10feea6e63a8
|
273
|
* @brief Enable the output direction of the specified GPIO.
|
ssmith73 |
1:10feea6e63a8
|
274
|
* @param desc - The GPIO descriptor.
|
ssmith73 |
1:10feea6e63a8
|
275
|
* @param value - The value.
|
ssmith73 |
1:10feea6e63a8
|
276
|
* Example: GPIO_HIGH
|
ssmith73 |
1:10feea6e63a8
|
277
|
* GPIO_LOW
|
ssmith73 |
1:10feea6e63a8
|
278
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
279
|
*/
|
ssmith73 |
1:10feea6e63a8
|
280
|
int32_t gpio_direction_output(struct gpio_desc *desc,
|
ssmith73 |
1:10feea6e63a8
|
281
|
uint8_t value)
|
ssmith73 |
1:10feea6e63a8
|
282
|
{
|
ssmith73 |
1:10feea6e63a8
|
283
|
//unnessary for MBED ?
|
ssmith73 |
1:10feea6e63a8
|
284
|
if(desc) { }
|
ssmith73 |
1:10feea6e63a8
|
285
|
// Unused variable - fix compiler warning
|
ssmith73 |
1:10feea6e63a8
|
286
|
|
ssmith73 |
1:10feea6e63a8
|
287
|
return SUCCESS;
|
ssmith73 |
1:10feea6e63a8
|
288
|
}
|
ssmith73 |
1:10feea6e63a8
|
289
|
|
ssmith73 |
1:10feea6e63a8
|
290
|
/**
|
ssmith73 |
1:10feea6e63a8
|
291
|
* @brief Get the direction of the specified GPIO.
|
ssmith73 |
1:10feea6e63a8
|
292
|
* @param desc - The GPIO descriptor.
|
ssmith73 |
1:10feea6e63a8
|
293
|
* @param direction - The direction.
|
ssmith73 |
1:10feea6e63a8
|
294
|
* Example: GPIO_OUT
|
ssmith73 |
1:10feea6e63a8
|
295
|
* GPIO_IN
|
ssmith73 |
1:10feea6e63a8
|
296
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
297
|
*/
|
ssmith73 |
1:10feea6e63a8
|
298
|
int32_t gpio_get_direction(struct gpio_desc *desc,
|
ssmith73 |
1:10feea6e63a8
|
299
|
uint8_t *direction)
|
ssmith73 |
1:10feea6e63a8
|
300
|
{
|
ssmith73 |
1:10feea6e63a8
|
301
|
if (desc) {
|
ssmith73 |
1:10feea6e63a8
|
302
|
// Unused variable - fix compiler warning
|
ssmith73 |
1:10feea6e63a8
|
303
|
}
|
ssmith73 |
1:10feea6e63a8
|
304
|
|
ssmith73 |
1:10feea6e63a8
|
305
|
if (direction) {
|
ssmith73 |
1:10feea6e63a8
|
306
|
// Unused variable - fix compiler warning
|
ssmith73 |
1:10feea6e63a8
|
307
|
}
|
ssmith73 |
1:10feea6e63a8
|
308
|
|
ssmith73 |
1:10feea6e63a8
|
309
|
return SUCCESS;
|
ssmith73 |
1:10feea6e63a8
|
310
|
}
|
ssmith73 |
1:10feea6e63a8
|
311
|
|
ssmith73 |
1:10feea6e63a8
|
312
|
/**
|
ssmith73 |
1:10feea6e63a8
|
313
|
* @brief Set the value of the specified GPIO.
|
ssmith73 |
1:10feea6e63a8
|
314
|
* @param desc - The GPIO descriptor.
|
ssmith73 |
1:10feea6e63a8
|
315
|
* @param value - The value.
|
ssmith73 |
1:10feea6e63a8
|
316
|
* Example: GPIO_HIGH
|
ssmith73 |
1:10feea6e63a8
|
317
|
* GPIO_LOW
|
ssmith73 |
1:10feea6e63a8
|
318
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
319
|
*/
|
ssmith73 |
1:10feea6e63a8
|
320
|
int32_t gpio_set_value(struct gpio_desc *desc,
|
ssmith73 |
1:10feea6e63a8
|
321
|
uint8_t value)
|
ssmith73 |
1:10feea6e63a8
|
322
|
{
|
ssmith73 |
1:10feea6e63a8
|
323
|
if (desc)
|
ssmith73 |
1:10feea6e63a8
|
324
|
DigitalOut(desc->pin, value);
|
ssmith73 |
1:10feea6e63a8
|
325
|
else
|
ssmith73 |
1:10feea6e63a8
|
326
|
return FAILURE;
|
ssmith73 |
1:10feea6e63a8
|
327
|
|
ssmith73 |
1:10feea6e63a8
|
328
|
return SUCCESS;
|
ssmith73 |
1:10feea6e63a8
|
329
|
}
|
ssmith73 |
1:10feea6e63a8
|
330
|
|
ssmith73 |
1:10feea6e63a8
|
331
|
/**
|
ssmith73 |
1:10feea6e63a8
|
332
|
* @brief Get the value of the specified GPIO.
|
ssmith73 |
1:10feea6e63a8
|
333
|
* @param desc - The GPIO descriptor.
|
ssmith73 |
1:10feea6e63a8
|
334
|
* @param value - The value.
|
ssmith73 |
1:10feea6e63a8
|
335
|
* Example: GPIO_HIGH
|
ssmith73 |
1:10feea6e63a8
|
336
|
* GPIO_LOW
|
ssmith73 |
1:10feea6e63a8
|
337
|
* @return SUCCESS in case of success, FAILURE otherwise.
|
ssmith73 |
1:10feea6e63a8
|
338
|
*/
|
ssmith73 |
1:10feea6e63a8
|
339
|
int32_t gpio_get_value(struct gpio_desc *desc, uint8_t *value)
|
ssmith73 |
1:10feea6e63a8
|
340
|
{
|
ssmith73 |
1:10feea6e63a8
|
341
|
uint8_t returnVal = FAILURE;
|
ssmith73 |
1:10feea6e63a8
|
342
|
if (desc) {
|
ssmith73 |
1:10feea6e63a8
|
343
|
{
|
ssmith73 |
1:10feea6e63a8
|
344
|
DigitalIn gpio(desc->pin);
|
ssmith73 |
1:10feea6e63a8
|
345
|
*value = (uint8_t)gpio.read();
|
ssmith73 |
1:10feea6e63a8
|
346
|
*value = gpio;
|
ssmith73 |
1:10feea6e63a8
|
347
|
returnVal = gpio.is_connected() ? SUCCESS : FAILURE;
|
ssmith73 |
1:10feea6e63a8
|
348
|
}
|
ssmith73 |
1:10feea6e63a8
|
349
|
|
ssmith73 |
1:10feea6e63a8
|
350
|
return returnVal;
|
ssmith73 |
1:10feea6e63a8
|
351
|
}
|
ssmith73 |
1:10feea6e63a8
|
352
|
return FAILURE;
|
ssmith73 |
1:10feea6e63a8
|
353
|
}
|
ssmith73 |
1:10feea6e63a8
|
354
|
|
ssmith73 |
1:10feea6e63a8
|
355
|
/**
|
ssmith73 |
1:10feea6e63a8
|
356
|
* @brief Generate miliseconds delay.
|
ssmith73 |
1:10feea6e63a8
|
357
|
* @param msecs - Delay in miliseconds.
|
ssmith73 |
1:10feea6e63a8
|
358
|
* @return None.
|
ssmith73 |
1:10feea6e63a8
|
359
|
*/
|
ssmith73 |
1:10feea6e63a8
|
360
|
void mdelay(uint32_t msecs)
|
ssmith73 |
1:10feea6e63a8
|
361
|
{
|
ssmith73 |
1:10feea6e63a8
|
362
|
if (msecs)
|
ssmith73 |
1:10feea6e63a8
|
363
|
{
|
ssmith73 |
1:10feea6e63a8
|
364
|
//unused variable - fix compiler warning
|
ssmith73 |
1:10feea6e63a8
|
365
|
}
|
ssmith73 |
1:10feea6e63a8
|
366
|
}
|