bug fix: SS was not declared in the spi_write_and_read(.. function

Committer:
ssmith73
Date:
Tue Aug 27 09:38:19 2019 +0000
Revision:
5:52f39fdbcd67
Parent:
4:7a997a86e5ea
Child:
6:38fa8ac6e43b
Removed unused rxData variable

Who changed what in which revision?

UserRevisionLine numberNew 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 2:996b477a1553 117 if(!(i2c.write(desc->slave_address , (char *)data, bytes_number, !stop_bit)))
ssmith73 2:996b477a1553 118 return SUCCESS;
ssmith73 2:996b477a1553 119 else
ssmith73 2:996b477a1553 120 return FAILURE;
ssmith73 1:10feea6e63a8 121 }
ssmith73 1:10feea6e63a8 122
ssmith73 1:10feea6e63a8 123 /**
ssmith73 1:10feea6e63a8 124 * @brief Read data from a slave device.
ssmith73 1:10feea6e63a8 125 * @param desc - The I2C descriptor.
ssmith73 1:10feea6e63a8 126 * @param data - Buffer that will store the received data.
ssmith73 1:10feea6e63a8 127 * @param bytes_number - Number of bytes to read.
ssmith73 1:10feea6e63a8 128 * @param stop_bit - Stop condition control.
ssmith73 1:10feea6e63a8 129 * Example: 0 - A stop condition will not be generated;
ssmith73 1:10feea6e63a8 130 * 1 - A stop condition will be generated.
ssmith73 1:10feea6e63a8 131 * @return SUCCESS in case of success, FAILURE otherwise.
ssmith73 1:10feea6e63a8 132 */
ssmith73 1:10feea6e63a8 133 int32_t mbed_i2c_read(struct i2c_desc *desc,
ssmith73 1:10feea6e63a8 134 uint8_t *data,
ssmith73 1:10feea6e63a8 135 uint8_t bytes_number,
ssmith73 1:10feea6e63a8 136 uint8_t stop_bit)
ssmith73 1:10feea6e63a8 137 {
ssmith73 1:10feea6e63a8 138 /**
ssmith73 1:10feea6e63a8 139 The MBED I2C API is reversed for parameter 4
ssmith73 1:10feea6e63a8 140 Instead of stop_bit - it has
ssmith73 1:10feea6e63a8 141 @param repeated - Repeated start, true - don't send stop at end default value is false.
ssmith73 1:10feea6e63a8 142 Inverting here to keep the no-OS/platform_drivers API
ssmith73 1:10feea6e63a8 143 */
ssmith73 2:996b477a1553 144 if(!(i2c.read(desc->slave_address, (char *)data, bytes_number, !stop_bit)))
ssmith73 2:996b477a1553 145 return SUCCESS;
ssmith73 2:996b477a1553 146 else
ssmith73 2:996b477a1553 147 return FAILURE;
ssmith73 1:10feea6e63a8 148 }
ssmith73 1:10feea6e63a8 149
ssmith73 1:10feea6e63a8 150 /**
ssmith73 1:10feea6e63a8 151 * @brief Initialize the SPI communication peripheral.
ssmith73 1:10feea6e63a8 152 * @param desc - The SPI descriptor.
ssmith73 1:10feea6e63a8 153 * @param init_param - The structure that contains the SPI parameters.
ssmith73 1:10feea6e63a8 154 * @return SUCCESS in case of success, FAILURE otherwise.
ssmith73 1:10feea6e63a8 155 */
ssmith73 1:10feea6e63a8 156 int32_t mbed_spi_init(struct spi_desc **desc,
ssmith73 1:10feea6e63a8 157 const struct spi_init_param *param)
ssmith73 1:10feea6e63a8 158 {
ssmith73 1:10feea6e63a8 159
ssmith73 1:10feea6e63a8 160 // Create the spi description object for the device
ssmith73 1:10feea6e63a8 161 spi_desc * new_desc = (spi_desc*) malloc(sizeof(*new_desc));
ssmith73 1:10feea6e63a8 162 new_desc->chip_select = param->chip_select;
ssmith73 1:10feea6e63a8 163 new_desc->mode = param->mode;
ssmith73 1:10feea6e63a8 164 new_desc->max_speed_hz = param->max_speed_hz;
ssmith73 1:10feea6e63a8 165 *desc = new_desc;
ssmith73 1:10feea6e63a8 166
ssmith73 1:10feea6e63a8 167 spi.format(SEND_BYTE, param->mode); //Stick to byte-multiples
ssmith73 1:10feea6e63a8 168 /**
ssmith73 1:10feea6e63a8 169 NOTE: Actual frequency of SPI clk will be somewhat device
ssmith73 1:10feea6e63a8 170 dependent, relating to clock-settings, prescalars etc. If absolute
ssmith73 1:10feea6e63a8 171 SPI frequency is required, consult your device documentation.
ssmith73 1:10feea6e63a8 172 **/
ssmith73 1:10feea6e63a8 173 spi.frequency(param->max_speed_hz);
ssmith73 1:10feea6e63a8 174 spi.set_default_write_value(0x00); //code to write when reading back
ssmith73 1:10feea6e63a8 175 SS = GPIO_HIGH; //set SS high
ssmith73 1:10feea6e63a8 176
ssmith73 1:10feea6e63a8 177 return SUCCESS;
ssmith73 1:10feea6e63a8 178 }
ssmith73 1:10feea6e63a8 179
ssmith73 1:10feea6e63a8 180 /**
ssmith73 1:10feea6e63a8 181 * @brief Free the resources allocated by spi_init().
ssmith73 1:10feea6e63a8 182 * @param desc - The SPI descriptor.
ssmith73 1:10feea6e63a8 183 * @return SUCCESS in case of success, FAILURE otherwise.
ssmith73 1:10feea6e63a8 184 */
ssmith73 1:10feea6e63a8 185 int32_t spi_remove(struct spi_desc *desc)
ssmith73 1:10feea6e63a8 186 {
ssmith73 1:10feea6e63a8 187 if (desc) {
ssmith73 1:10feea6e63a8 188 // Unused variable - fix compiler warning
ssmith73 1:10feea6e63a8 189 }
ssmith73 1:10feea6e63a8 190
ssmith73 1:10feea6e63a8 191 return SUCCESS;
ssmith73 1:10feea6e63a8 192 }
ssmith73 1:10feea6e63a8 193
ssmith73 1:10feea6e63a8 194
ssmith73 1:10feea6e63a8 195 /**
ssmith73 1:10feea6e63a8 196 * @brief Write and read data to/from SPI.
ssmith73 1:10feea6e63a8 197 *
ssmith73 1:10feea6e63a8 198 * This function will be updated to improve performance
ssmith73 1:10feea6e63a8 199 *
ssmith73 1:10feea6e63a8 200 * @param desc - The SPI descriptor.
ssmith73 1:10feea6e63a8 201 * @param data - The buffer with the transmitted/received data.
ssmith73 1:10feea6e63a8 202 * @param bytes_number - Number of bytes to write/read.
ssmith73 1:10feea6e63a8 203 * @return SUCCESS in case of success, FAILURE otherwise.
ssmith73 1:10feea6e63a8 204 */
ssmith73 1:10feea6e63a8 205 int32_t spi_write_and_read(struct spi_desc *desc,
ssmith73 1:10feea6e63a8 206 uint8_t *data,
ssmith73 1:10feea6e63a8 207 uint8_t bytes_number)
ssmith73 1:10feea6e63a8 208 {
ssmith73 1:10feea6e63a8 209 if (desc) {
ssmith73 1:10feea6e63a8 210 // Unused variable - fix compiler warning
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 {
MitchAD 4:7a997a86e5ea 216 data[byte] = spi.write(data[byte]);
ssmith73 1:10feea6e63a8 217 }
ssmith73 1:10feea6e63a8 218 SS = GPIO_HIGH; //!deselect SS
ssmith73 1:10feea6e63a8 219
ssmith73 1:10feea6e63a8 220 return SUCCESS;
ssmith73 1:10feea6e63a8 221 }
ssmith73 1:10feea6e63a8 222
ssmith73 1:10feea6e63a8 223 /**
ssmith73 1:10feea6e63a8 224 * @brief Obtain the GPIO decriptor.
ssmith73 1:10feea6e63a8 225 * @param desc - The GPIO descriptor.
ssmith73 1:10feea6e63a8 226 * @param gpio_number - The number of the GPIO.
ssmith73 1:10feea6e63a8 227 * @return SUCCESS in case of success, FAILURE otherwise.
ssmith73 1:10feea6e63a8 228 */
ssmith73 1:10feea6e63a8 229 int32_t gpio_get(struct gpio_desc **desc,
ssmith73 1:10feea6e63a8 230 gpio_desc init_values)
ssmith73 1:10feea6e63a8 231 {
ssmith73 1:10feea6e63a8 232 gpio_desc * new_gpio = new gpio_desc;
ssmith73 1:10feea6e63a8 233 new_gpio->id = init_values.id;
ssmith73 1:10feea6e63a8 234 new_gpio->number = init_values.number;
ssmith73 1:10feea6e63a8 235 new_gpio->pin = init_values.pin;
ssmith73 1:10feea6e63a8 236 new_gpio->type = init_values.type;
ssmith73 1:10feea6e63a8 237
ssmith73 1:10feea6e63a8 238 *desc = new_gpio;
ssmith73 1:10feea6e63a8 239
ssmith73 1:10feea6e63a8 240 return SUCCESS;
ssmith73 1:10feea6e63a8 241 }
ssmith73 1:10feea6e63a8 242
ssmith73 1:10feea6e63a8 243 /**
ssmith73 1:10feea6e63a8 244 * @brief Free the resources allocated by gpio_get().
ssmith73 1:10feea6e63a8 245 * @param desc - The SPI descriptor.
ssmith73 1:10feea6e63a8 246 * @return SUCCESS in case of success, FAILURE otherwise.
ssmith73 1:10feea6e63a8 247 */
ssmith73 1:10feea6e63a8 248 int32_t gpio_remove(struct gpio_desc *desc)
ssmith73 1:10feea6e63a8 249 {
ssmith73 1:10feea6e63a8 250 if (desc) {
ssmith73 1:10feea6e63a8 251 // Unused variable - fix compiler warning
ssmith73 1:10feea6e63a8 252 }
ssmith73 1:10feea6e63a8 253
ssmith73 1:10feea6e63a8 254 return SUCCESS;
ssmith73 1:10feea6e63a8 255 }
ssmith73 1:10feea6e63a8 256
ssmith73 1:10feea6e63a8 257 /**
ssmith73 1:10feea6e63a8 258 * @brief Enable the input direction of the specified GPIO.
ssmith73 1:10feea6e63a8 259 * @param desc - The GPIO descriptor.
ssmith73 1:10feea6e63a8 260 * @return SUCCESS in case of success, FAILURE otherwise.
ssmith73 1:10feea6e63a8 261 */
ssmith73 1:10feea6e63a8 262 int32_t gpio_direction_input(struct gpio_desc *desc)
ssmith73 1:10feea6e63a8 263 {
ssmith73 1:10feea6e63a8 264 //unnessary for MBED
ssmith73 1:10feea6e63a8 265 if(desc) { }
ssmith73 1:10feea6e63a8 266 // Unused variable - fix compiler warning
ssmith73 1:10feea6e63a8 267
ssmith73 1:10feea6e63a8 268 return 0;
ssmith73 1:10feea6e63a8 269 }
ssmith73 1:10feea6e63a8 270
ssmith73 1:10feea6e63a8 271 /**
ssmith73 1:10feea6e63a8 272 * @brief Enable the output direction of the specified GPIO.
ssmith73 1:10feea6e63a8 273 * @param desc - The GPIO descriptor.
ssmith73 1:10feea6e63a8 274 * @param value - The value.
ssmith73 1:10feea6e63a8 275 * Example: GPIO_HIGH
ssmith73 1:10feea6e63a8 276 * GPIO_LOW
ssmith73 1:10feea6e63a8 277 * @return SUCCESS in case of success, FAILURE otherwise.
ssmith73 1:10feea6e63a8 278 */
ssmith73 1:10feea6e63a8 279 int32_t gpio_direction_output(struct gpio_desc *desc,
ssmith73 1:10feea6e63a8 280 uint8_t value)
ssmith73 1:10feea6e63a8 281 {
ssmith73 1:10feea6e63a8 282 //unnessary for MBED ?
ssmith73 1:10feea6e63a8 283 if(desc) { }
ssmith73 1:10feea6e63a8 284 // Unused variable - fix compiler warning
ssmith73 1:10feea6e63a8 285
ssmith73 1:10feea6e63a8 286 return SUCCESS;
ssmith73 1:10feea6e63a8 287 }
ssmith73 1:10feea6e63a8 288
ssmith73 1:10feea6e63a8 289 /**
ssmith73 1:10feea6e63a8 290 * @brief Get the direction of the specified GPIO.
ssmith73 1:10feea6e63a8 291 * @param desc - The GPIO descriptor.
ssmith73 1:10feea6e63a8 292 * @param direction - The direction.
ssmith73 1:10feea6e63a8 293 * Example: GPIO_OUT
ssmith73 1:10feea6e63a8 294 * GPIO_IN
ssmith73 1:10feea6e63a8 295 * @return SUCCESS in case of success, FAILURE otherwise.
ssmith73 1:10feea6e63a8 296 */
ssmith73 1:10feea6e63a8 297 int32_t gpio_get_direction(struct gpio_desc *desc,
ssmith73 1:10feea6e63a8 298 uint8_t *direction)
ssmith73 1:10feea6e63a8 299 {
ssmith73 1:10feea6e63a8 300 if (desc) {
ssmith73 1:10feea6e63a8 301 // Unused variable - fix compiler warning
ssmith73 1:10feea6e63a8 302 }
ssmith73 1:10feea6e63a8 303
ssmith73 1:10feea6e63a8 304 if (direction) {
ssmith73 1:10feea6e63a8 305 // Unused variable - fix compiler warning
ssmith73 1:10feea6e63a8 306 }
ssmith73 1:10feea6e63a8 307
ssmith73 1:10feea6e63a8 308 return SUCCESS;
ssmith73 1:10feea6e63a8 309 }
ssmith73 1:10feea6e63a8 310
ssmith73 1:10feea6e63a8 311 /**
ssmith73 1:10feea6e63a8 312 * @brief Set the value of the specified GPIO.
ssmith73 1:10feea6e63a8 313 * @param desc - The GPIO descriptor.
ssmith73 1:10feea6e63a8 314 * @param value - The value.
ssmith73 1:10feea6e63a8 315 * Example: GPIO_HIGH
ssmith73 1:10feea6e63a8 316 * GPIO_LOW
ssmith73 1:10feea6e63a8 317 * @return SUCCESS in case of success, FAILURE otherwise.
ssmith73 1:10feea6e63a8 318 */
ssmith73 1:10feea6e63a8 319 int32_t gpio_set_value(struct gpio_desc *desc,
ssmith73 1:10feea6e63a8 320 uint8_t value)
ssmith73 1:10feea6e63a8 321 {
ssmith73 1:10feea6e63a8 322 if (desc)
ssmith73 1:10feea6e63a8 323 DigitalOut(desc->pin, value);
ssmith73 1:10feea6e63a8 324 else
ssmith73 1:10feea6e63a8 325 return FAILURE;
ssmith73 1:10feea6e63a8 326
ssmith73 1:10feea6e63a8 327 return SUCCESS;
ssmith73 1:10feea6e63a8 328 }
ssmith73 1:10feea6e63a8 329
ssmith73 1:10feea6e63a8 330 /**
ssmith73 1:10feea6e63a8 331 * @brief Get the value of the specified GPIO.
ssmith73 1:10feea6e63a8 332 * @param desc - The GPIO descriptor.
ssmith73 1:10feea6e63a8 333 * @param value - The value.
ssmith73 1:10feea6e63a8 334 * Example: GPIO_HIGH
ssmith73 1:10feea6e63a8 335 * GPIO_LOW
ssmith73 1:10feea6e63a8 336 * @return SUCCESS in case of success, FAILURE otherwise.
ssmith73 1:10feea6e63a8 337 */
ssmith73 1:10feea6e63a8 338 int32_t gpio_get_value(struct gpio_desc *desc, uint8_t *value)
ssmith73 1:10feea6e63a8 339 {
ssmith73 1:10feea6e63a8 340 uint8_t returnVal = FAILURE;
ssmith73 1:10feea6e63a8 341 if (desc) {
ssmith73 1:10feea6e63a8 342 {
ssmith73 1:10feea6e63a8 343 DigitalIn gpio(desc->pin);
ssmith73 1:10feea6e63a8 344 *value = (uint8_t)gpio.read();
ssmith73 1:10feea6e63a8 345 *value = gpio;
ssmith73 1:10feea6e63a8 346 returnVal = gpio.is_connected() ? SUCCESS : FAILURE;
ssmith73 1:10feea6e63a8 347 }
ssmith73 1:10feea6e63a8 348
ssmith73 1:10feea6e63a8 349 return returnVal;
ssmith73 1:10feea6e63a8 350 }
ssmith73 1:10feea6e63a8 351 return FAILURE;
ssmith73 1:10feea6e63a8 352 }
ssmith73 1:10feea6e63a8 353
ssmith73 1:10feea6e63a8 354 /**
ssmith73 1:10feea6e63a8 355 * @brief Generate miliseconds delay.
ssmith73 1:10feea6e63a8 356 * @param msecs - Delay in miliseconds.
ssmith73 1:10feea6e63a8 357 * @return None.
ssmith73 1:10feea6e63a8 358 */
ssmith73 1:10feea6e63a8 359 void mdelay(uint32_t msecs)
ssmith73 1:10feea6e63a8 360 {
ssmith73 1:10feea6e63a8 361 if (msecs)
ssmith73 1:10feea6e63a8 362 {
ssmith73 1:10feea6e63a8 363 //unused variable - fix compiler warning
ssmith73 1:10feea6e63a8 364 }
ssmith73 1:10feea6e63a8 365 }