bug fix: SS was not declared in the spi_write_and_read(.. function
platform_drivers.cpp@7:efb143ea4191, 2019-09-02 (annotated)
- Committer:
- ssmith73
- Date:
- Mon Sep 02 11:42:58 2019 +0000
- Revision:
- 7:efb143ea4191
- Parent:
- 6:38fa8ac6e43b
Bugfix - SS is undeclared in the spi_write_and_read function
Who changed what in which revision?
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 | 6:38fa8ac6e43b | 50 | PinName slave_selects[8] = { SPI_CS, SPI_CSE }; |
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 | 6:38fa8ac6e43b | 54 | |
ssmith73 | 1:10feea6e63a8 | 55 | extern SPI spi; |
ssmith73 | 1:10feea6e63a8 | 56 | extern I2C i2c; |
ssmith73 | 6:38fa8ac6e43b | 57 | extern PinName slave_selects[MAX_SLAVE_SELECTS]; |
ssmith73 | 1:10feea6e63a8 | 58 | /******************************************************************************/ |
ssmith73 | 1:10feea6e63a8 | 59 | /************************ Functions Definitions *******************************/ |
ssmith73 | 1:10feea6e63a8 | 60 | /******************************************************************************/ |
ssmith73 | 1:10feea6e63a8 | 61 | |
ssmith73 | 1:10feea6e63a8 | 62 | /** |
ssmith73 | 1:10feea6e63a8 | 63 | * @brief Initialize the I2C communication peripheral. |
ssmith73 | 1:10feea6e63a8 | 64 | * @param desc - The I2C descriptor. |
ssmith73 | 1:10feea6e63a8 | 65 | * @param param - The structure that contains the I2C parameters. |
ssmith73 | 1:10feea6e63a8 | 66 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 67 | */ |
ssmith73 | 1:10feea6e63a8 | 68 | int32_t mbed_i2c_init(struct i2c_desc **desc, |
ssmith73 | 1:10feea6e63a8 | 69 | const struct i2c_init_param *param) |
ssmith73 | 1:10feea6e63a8 | 70 | { |
ssmith73 | 1:10feea6e63a8 | 71 | i2c_desc * new_desc = (i2c_desc*) malloc(sizeof(i2c_desc)); |
ssmith73 | 1:10feea6e63a8 | 72 | new_desc->id = param->id; |
ssmith73 | 1:10feea6e63a8 | 73 | new_desc->slave_address = param->slave_address; |
ssmith73 | 1:10feea6e63a8 | 74 | new_desc->type = param->type; |
ssmith73 | 1:10feea6e63a8 | 75 | |
ssmith73 | 1:10feea6e63a8 | 76 | *desc = new_desc; |
ssmith73 | 1:10feea6e63a8 | 77 | |
ssmith73 | 1:10feea6e63a8 | 78 | return SUCCESS; |
ssmith73 | 1:10feea6e63a8 | 79 | } |
ssmith73 | 1:10feea6e63a8 | 80 | |
ssmith73 | 1:10feea6e63a8 | 81 | |
ssmith73 | 1:10feea6e63a8 | 82 | /** |
ssmith73 | 1:10feea6e63a8 | 83 | * @brief Free the resources allocated by i2c_init(). |
ssmith73 | 1:10feea6e63a8 | 84 | * @param desc - The I2C descriptor. |
ssmith73 | 1:10feea6e63a8 | 85 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 86 | */ |
ssmith73 | 1:10feea6e63a8 | 87 | int32_t i2c_remove(struct i2c_desc *desc) |
ssmith73 | 1:10feea6e63a8 | 88 | { |
ssmith73 | 1:10feea6e63a8 | 89 | if (desc) { |
ssmith73 | 1:10feea6e63a8 | 90 | // Unused variable - fix compiler warning |
ssmith73 | 1:10feea6e63a8 | 91 | } |
ssmith73 | 1:10feea6e63a8 | 92 | |
ssmith73 | 1:10feea6e63a8 | 93 | return SUCCESS; |
ssmith73 | 1:10feea6e63a8 | 94 | } |
ssmith73 | 1:10feea6e63a8 | 95 | |
ssmith73 | 1:10feea6e63a8 | 96 | /** |
ssmith73 | 1:10feea6e63a8 | 97 | * @brief Write data to a slave device. |
ssmith73 | 1:10feea6e63a8 | 98 | * @param desc - The I2C descriptor. |
ssmith73 | 1:10feea6e63a8 | 99 | * @param data - Buffer that stores the transmission data. |
ssmith73 | 1:10feea6e63a8 | 100 | * @param bytes_number - Number of bytes to write. |
ssmith73 | 1:10feea6e63a8 | 101 | * @param stop_bit - Stop condition control. |
ssmith73 | 1:10feea6e63a8 | 102 | * Example: 0 - A stop condition will not be generated; |
ssmith73 | 1:10feea6e63a8 | 103 | * 1 - A stop condition will be generated. |
ssmith73 | 1:10feea6e63a8 | 104 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 105 | */ |
ssmith73 | 1:10feea6e63a8 | 106 | |
ssmith73 | 1:10feea6e63a8 | 107 | int32_t mbed_i2c_write(struct i2c_desc *desc, |
ssmith73 | 1:10feea6e63a8 | 108 | uint8_t *data, |
ssmith73 | 1:10feea6e63a8 | 109 | uint8_t bytes_number, |
ssmith73 | 1:10feea6e63a8 | 110 | uint8_t stop_bit) |
ssmith73 | 1:10feea6e63a8 | 111 | { |
ssmith73 | 1:10feea6e63a8 | 112 | /** |
ssmith73 | 1:10feea6e63a8 | 113 | The MBED I2C API is reversed for parameter 4 |
ssmith73 | 1:10feea6e63a8 | 114 | Instead of stop_bit - it has |
ssmith73 | 1:10feea6e63a8 | 115 | @param repeated - Repeated start, true - don't send stop at end default value is false. |
ssmith73 | 1:10feea6e63a8 | 116 | Inverting here to keep the no-OS/platform_drivers API |
ssmith73 | 1:10feea6e63a8 | 117 | */ |
ssmith73 | 2:996b477a1553 | 118 | if(!(i2c.write(desc->slave_address , (char *)data, bytes_number, !stop_bit))) |
ssmith73 | 2:996b477a1553 | 119 | return SUCCESS; |
ssmith73 | 2:996b477a1553 | 120 | else |
ssmith73 | 2:996b477a1553 | 121 | return FAILURE; |
ssmith73 | 1:10feea6e63a8 | 122 | } |
ssmith73 | 1:10feea6e63a8 | 123 | |
ssmith73 | 1:10feea6e63a8 | 124 | /** |
ssmith73 | 1:10feea6e63a8 | 125 | * @brief Read data from a slave device. |
ssmith73 | 1:10feea6e63a8 | 126 | * @param desc - The I2C descriptor. |
ssmith73 | 1:10feea6e63a8 | 127 | * @param data - Buffer that will store the received data. |
ssmith73 | 1:10feea6e63a8 | 128 | * @param bytes_number - Number of bytes to read. |
ssmith73 | 1:10feea6e63a8 | 129 | * @param stop_bit - Stop condition control. |
ssmith73 | 1:10feea6e63a8 | 130 | * Example: 0 - A stop condition will not be generated; |
ssmith73 | 1:10feea6e63a8 | 131 | * 1 - A stop condition will be generated. |
ssmith73 | 1:10feea6e63a8 | 132 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 133 | */ |
ssmith73 | 1:10feea6e63a8 | 134 | int32_t mbed_i2c_read(struct i2c_desc *desc, |
ssmith73 | 1:10feea6e63a8 | 135 | uint8_t *data, |
ssmith73 | 1:10feea6e63a8 | 136 | uint8_t bytes_number, |
ssmith73 | 1:10feea6e63a8 | 137 | uint8_t stop_bit) |
ssmith73 | 1:10feea6e63a8 | 138 | { |
ssmith73 | 1:10feea6e63a8 | 139 | /** |
ssmith73 | 1:10feea6e63a8 | 140 | The MBED I2C API is reversed for parameter 4 |
ssmith73 | 1:10feea6e63a8 | 141 | Instead of stop_bit - it has |
ssmith73 | 1:10feea6e63a8 | 142 | @param repeated - Repeated start, true - don't send stop at end default value is false. |
ssmith73 | 1:10feea6e63a8 | 143 | Inverting here to keep the no-OS/platform_drivers API |
ssmith73 | 1:10feea6e63a8 | 144 | */ |
ssmith73 | 2:996b477a1553 | 145 | if(!(i2c.read(desc->slave_address, (char *)data, bytes_number, !stop_bit))) |
ssmith73 | 2:996b477a1553 | 146 | return SUCCESS; |
ssmith73 | 2:996b477a1553 | 147 | else |
ssmith73 | 2:996b477a1553 | 148 | return FAILURE; |
ssmith73 | 1:10feea6e63a8 | 149 | } |
ssmith73 | 1:10feea6e63a8 | 150 | |
ssmith73 | 1:10feea6e63a8 | 151 | /** |
ssmith73 | 1:10feea6e63a8 | 152 | * @brief Initialize the SPI communication peripheral. |
ssmith73 | 1:10feea6e63a8 | 153 | * @param desc - The SPI descriptor. |
ssmith73 | 1:10feea6e63a8 | 154 | * @param init_param - The structure that contains the SPI parameters. |
ssmith73 | 1:10feea6e63a8 | 155 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 156 | */ |
ssmith73 | 1:10feea6e63a8 | 157 | int32_t mbed_spi_init(struct spi_desc **desc, |
ssmith73 | 1:10feea6e63a8 | 158 | const struct spi_init_param *param) |
ssmith73 | 1:10feea6e63a8 | 159 | { |
ssmith73 | 1:10feea6e63a8 | 160 | |
ssmith73 | 1:10feea6e63a8 | 161 | // Create the spi description object for the device |
ssmith73 | 1:10feea6e63a8 | 162 | spi_desc * new_desc = (spi_desc*) malloc(sizeof(*new_desc)); |
ssmith73 | 1:10feea6e63a8 | 163 | new_desc->chip_select = param->chip_select; |
ssmith73 | 1:10feea6e63a8 | 164 | new_desc->mode = param->mode; |
ssmith73 | 1:10feea6e63a8 | 165 | new_desc->max_speed_hz = param->max_speed_hz; |
ssmith73 | 1:10feea6e63a8 | 166 | *desc = new_desc; |
ssmith73 | 6:38fa8ac6e43b | 167 | //Create the DigitalOut object, based on user-defined chip-select |
ssmith73 | 6:38fa8ac6e43b | 168 | DigitalOut SS(slave_selects[new_desc->chip_select]); |
ssmith73 | 1:10feea6e63a8 | 169 | spi.format(SEND_BYTE, param->mode); //Stick to byte-multiples |
ssmith73 | 1:10feea6e63a8 | 170 | /** |
ssmith73 | 1:10feea6e63a8 | 171 | NOTE: Actual frequency of SPI clk will be somewhat device |
ssmith73 | 1:10feea6e63a8 | 172 | dependent, relating to clock-settings, prescalars etc. If absolute |
ssmith73 | 1:10feea6e63a8 | 173 | SPI frequency is required, consult your device documentation. |
ssmith73 | 1:10feea6e63a8 | 174 | **/ |
ssmith73 | 1:10feea6e63a8 | 175 | spi.frequency(param->max_speed_hz); |
ssmith73 | 1:10feea6e63a8 | 176 | spi.set_default_write_value(0x00); //code to write when reading back |
ssmith73 | 1:10feea6e63a8 | 177 | SS = GPIO_HIGH; //set SS high |
ssmith73 | 1:10feea6e63a8 | 178 | |
ssmith73 | 1:10feea6e63a8 | 179 | return SUCCESS; |
ssmith73 | 1:10feea6e63a8 | 180 | } |
ssmith73 | 1:10feea6e63a8 | 181 | |
ssmith73 | 1:10feea6e63a8 | 182 | /** |
ssmith73 | 1:10feea6e63a8 | 183 | * @brief Free the resources allocated by spi_init(). |
ssmith73 | 1:10feea6e63a8 | 184 | * @param desc - The SPI descriptor. |
ssmith73 | 1:10feea6e63a8 | 185 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 186 | */ |
ssmith73 | 1:10feea6e63a8 | 187 | int32_t spi_remove(struct spi_desc *desc) |
ssmith73 | 1:10feea6e63a8 | 188 | { |
ssmith73 | 1:10feea6e63a8 | 189 | if (desc) { |
ssmith73 | 1:10feea6e63a8 | 190 | // Unused variable - fix compiler warning |
ssmith73 | 1:10feea6e63a8 | 191 | } |
ssmith73 | 1:10feea6e63a8 | 192 | |
ssmith73 | 1:10feea6e63a8 | 193 | return SUCCESS; |
ssmith73 | 1:10feea6e63a8 | 194 | } |
ssmith73 | 1:10feea6e63a8 | 195 | |
ssmith73 | 1:10feea6e63a8 | 196 | |
ssmith73 | 1:10feea6e63a8 | 197 | /** |
ssmith73 | 1:10feea6e63a8 | 198 | * @brief Write and read data to/from SPI. |
ssmith73 | 1:10feea6e63a8 | 199 | * |
ssmith73 | 1:10feea6e63a8 | 200 | * This function will be updated to improve performance |
ssmith73 | 1:10feea6e63a8 | 201 | * |
ssmith73 | 1:10feea6e63a8 | 202 | * @param desc - The SPI descriptor. |
ssmith73 | 1:10feea6e63a8 | 203 | * @param data - The buffer with the transmitted/received data. |
ssmith73 | 1:10feea6e63a8 | 204 | * @param bytes_number - Number of bytes to write/read. |
ssmith73 | 1:10feea6e63a8 | 205 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 206 | */ |
ssmith73 | 1:10feea6e63a8 | 207 | int32_t spi_write_and_read(struct spi_desc *desc, |
ssmith73 | 1:10feea6e63a8 | 208 | uint8_t *data, |
ssmith73 | 1:10feea6e63a8 | 209 | uint8_t bytes_number) |
ssmith73 | 1:10feea6e63a8 | 210 | { |
ssmith73 | 1:10feea6e63a8 | 211 | if (desc) { |
ssmith73 | 1:10feea6e63a8 | 212 | // Unused variable - fix compiler warning |
ssmith73 | 1:10feea6e63a8 | 213 | } |
ssmith73 | 7:efb143ea4191 | 214 | //Create the DigitalOut object, based on user-defined chip-select |
ssmith73 | 7:efb143ea4191 | 215 | DigitalOut SS(slave_selects[desc->chip_select]); |
ssmith73 | 1:10feea6e63a8 | 216 | |
ssmith73 | 1:10feea6e63a8 | 217 | SS = GPIO_LOW; //!select SS |
ssmith73 | 1:10feea6e63a8 | 218 | for(size_t byte = 0 ; byte < bytes_number ; byte++) |
ssmith73 | 1:10feea6e63a8 | 219 | { |
MitchAD | 4:7a997a86e5ea | 220 | data[byte] = spi.write(data[byte]); |
ssmith73 | 1:10feea6e63a8 | 221 | } |
ssmith73 | 1:10feea6e63a8 | 222 | SS = GPIO_HIGH; //!deselect SS |
ssmith73 | 1:10feea6e63a8 | 223 | |
ssmith73 | 1:10feea6e63a8 | 224 | return SUCCESS; |
ssmith73 | 1:10feea6e63a8 | 225 | } |
ssmith73 | 1:10feea6e63a8 | 226 | |
ssmith73 | 1:10feea6e63a8 | 227 | /** |
ssmith73 | 1:10feea6e63a8 | 228 | * @brief Obtain the GPIO decriptor. |
ssmith73 | 1:10feea6e63a8 | 229 | * @param desc - The GPIO descriptor. |
ssmith73 | 1:10feea6e63a8 | 230 | * @param gpio_number - The number of the GPIO. |
ssmith73 | 1:10feea6e63a8 | 231 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 232 | */ |
ssmith73 | 1:10feea6e63a8 | 233 | int32_t gpio_get(struct gpio_desc **desc, |
ssmith73 | 1:10feea6e63a8 | 234 | gpio_desc init_values) |
ssmith73 | 1:10feea6e63a8 | 235 | { |
ssmith73 | 1:10feea6e63a8 | 236 | gpio_desc * new_gpio = new gpio_desc; |
ssmith73 | 1:10feea6e63a8 | 237 | new_gpio->id = init_values.id; |
ssmith73 | 1:10feea6e63a8 | 238 | new_gpio->number = init_values.number; |
ssmith73 | 1:10feea6e63a8 | 239 | new_gpio->pin = init_values.pin; |
ssmith73 | 1:10feea6e63a8 | 240 | new_gpio->type = init_values.type; |
ssmith73 | 1:10feea6e63a8 | 241 | |
ssmith73 | 1:10feea6e63a8 | 242 | *desc = new_gpio; |
ssmith73 | 1:10feea6e63a8 | 243 | |
ssmith73 | 1:10feea6e63a8 | 244 | return SUCCESS; |
ssmith73 | 1:10feea6e63a8 | 245 | } |
ssmith73 | 1:10feea6e63a8 | 246 | |
ssmith73 | 1:10feea6e63a8 | 247 | /** |
ssmith73 | 1:10feea6e63a8 | 248 | * @brief Free the resources allocated by gpio_get(). |
ssmith73 | 1:10feea6e63a8 | 249 | * @param desc - The SPI descriptor. |
ssmith73 | 1:10feea6e63a8 | 250 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 251 | */ |
ssmith73 | 1:10feea6e63a8 | 252 | int32_t gpio_remove(struct gpio_desc *desc) |
ssmith73 | 1:10feea6e63a8 | 253 | { |
ssmith73 | 1:10feea6e63a8 | 254 | if (desc) { |
ssmith73 | 1:10feea6e63a8 | 255 | // Unused variable - fix compiler warning |
ssmith73 | 1:10feea6e63a8 | 256 | } |
ssmith73 | 1:10feea6e63a8 | 257 | |
ssmith73 | 1:10feea6e63a8 | 258 | return SUCCESS; |
ssmith73 | 1:10feea6e63a8 | 259 | } |
ssmith73 | 1:10feea6e63a8 | 260 | |
ssmith73 | 1:10feea6e63a8 | 261 | /** |
ssmith73 | 1:10feea6e63a8 | 262 | * @brief Enable the input direction of the specified GPIO. |
ssmith73 | 1:10feea6e63a8 | 263 | * @param desc - The GPIO descriptor. |
ssmith73 | 1:10feea6e63a8 | 264 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 265 | */ |
ssmith73 | 1:10feea6e63a8 | 266 | int32_t gpio_direction_input(struct gpio_desc *desc) |
ssmith73 | 1:10feea6e63a8 | 267 | { |
ssmith73 | 1:10feea6e63a8 | 268 | //unnessary for MBED |
ssmith73 | 1:10feea6e63a8 | 269 | if(desc) { } |
ssmith73 | 1:10feea6e63a8 | 270 | // Unused variable - fix compiler warning |
ssmith73 | 1:10feea6e63a8 | 271 | |
ssmith73 | 1:10feea6e63a8 | 272 | return 0; |
ssmith73 | 1:10feea6e63a8 | 273 | } |
ssmith73 | 1:10feea6e63a8 | 274 | |
ssmith73 | 1:10feea6e63a8 | 275 | /** |
ssmith73 | 1:10feea6e63a8 | 276 | * @brief Enable the output direction of the specified GPIO. |
ssmith73 | 1:10feea6e63a8 | 277 | * @param desc - The GPIO descriptor. |
ssmith73 | 1:10feea6e63a8 | 278 | * @param value - The value. |
ssmith73 | 1:10feea6e63a8 | 279 | * Example: GPIO_HIGH |
ssmith73 | 1:10feea6e63a8 | 280 | * GPIO_LOW |
ssmith73 | 1:10feea6e63a8 | 281 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 282 | */ |
ssmith73 | 1:10feea6e63a8 | 283 | int32_t gpio_direction_output(struct gpio_desc *desc, |
ssmith73 | 1:10feea6e63a8 | 284 | uint8_t value) |
ssmith73 | 1:10feea6e63a8 | 285 | { |
ssmith73 | 1:10feea6e63a8 | 286 | //unnessary for MBED ? |
ssmith73 | 1:10feea6e63a8 | 287 | if(desc) { } |
ssmith73 | 1:10feea6e63a8 | 288 | // Unused variable - fix compiler warning |
ssmith73 | 1:10feea6e63a8 | 289 | |
ssmith73 | 1:10feea6e63a8 | 290 | return SUCCESS; |
ssmith73 | 1:10feea6e63a8 | 291 | } |
ssmith73 | 1:10feea6e63a8 | 292 | |
ssmith73 | 1:10feea6e63a8 | 293 | /** |
ssmith73 | 1:10feea6e63a8 | 294 | * @brief Get the direction of the specified GPIO. |
ssmith73 | 1:10feea6e63a8 | 295 | * @param desc - The GPIO descriptor. |
ssmith73 | 1:10feea6e63a8 | 296 | * @param direction - The direction. |
ssmith73 | 1:10feea6e63a8 | 297 | * Example: GPIO_OUT |
ssmith73 | 1:10feea6e63a8 | 298 | * GPIO_IN |
ssmith73 | 1:10feea6e63a8 | 299 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 300 | */ |
ssmith73 | 1:10feea6e63a8 | 301 | int32_t gpio_get_direction(struct gpio_desc *desc, |
ssmith73 | 1:10feea6e63a8 | 302 | uint8_t *direction) |
ssmith73 | 1:10feea6e63a8 | 303 | { |
ssmith73 | 1:10feea6e63a8 | 304 | if (desc) { |
ssmith73 | 1:10feea6e63a8 | 305 | // Unused variable - fix compiler warning |
ssmith73 | 1:10feea6e63a8 | 306 | } |
ssmith73 | 1:10feea6e63a8 | 307 | |
ssmith73 | 1:10feea6e63a8 | 308 | if (direction) { |
ssmith73 | 1:10feea6e63a8 | 309 | // Unused variable - fix compiler warning |
ssmith73 | 1:10feea6e63a8 | 310 | } |
ssmith73 | 1:10feea6e63a8 | 311 | |
ssmith73 | 1:10feea6e63a8 | 312 | return SUCCESS; |
ssmith73 | 1:10feea6e63a8 | 313 | } |
ssmith73 | 1:10feea6e63a8 | 314 | |
ssmith73 | 1:10feea6e63a8 | 315 | /** |
ssmith73 | 1:10feea6e63a8 | 316 | * @brief Set the value of the specified GPIO. |
ssmith73 | 1:10feea6e63a8 | 317 | * @param desc - The GPIO descriptor. |
ssmith73 | 1:10feea6e63a8 | 318 | * @param value - The value. |
ssmith73 | 1:10feea6e63a8 | 319 | * Example: GPIO_HIGH |
ssmith73 | 1:10feea6e63a8 | 320 | * GPIO_LOW |
ssmith73 | 1:10feea6e63a8 | 321 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 322 | */ |
ssmith73 | 1:10feea6e63a8 | 323 | int32_t gpio_set_value(struct gpio_desc *desc, |
ssmith73 | 1:10feea6e63a8 | 324 | uint8_t value) |
ssmith73 | 1:10feea6e63a8 | 325 | { |
ssmith73 | 1:10feea6e63a8 | 326 | if (desc) |
ssmith73 | 1:10feea6e63a8 | 327 | DigitalOut(desc->pin, value); |
ssmith73 | 1:10feea6e63a8 | 328 | else |
ssmith73 | 1:10feea6e63a8 | 329 | return FAILURE; |
ssmith73 | 1:10feea6e63a8 | 330 | |
ssmith73 | 1:10feea6e63a8 | 331 | return SUCCESS; |
ssmith73 | 1:10feea6e63a8 | 332 | } |
ssmith73 | 1:10feea6e63a8 | 333 | |
ssmith73 | 1:10feea6e63a8 | 334 | /** |
ssmith73 | 1:10feea6e63a8 | 335 | * @brief Get the value of the specified GPIO. |
ssmith73 | 1:10feea6e63a8 | 336 | * @param desc - The GPIO descriptor. |
ssmith73 | 1:10feea6e63a8 | 337 | * @param value - The value. |
ssmith73 | 1:10feea6e63a8 | 338 | * Example: GPIO_HIGH |
ssmith73 | 1:10feea6e63a8 | 339 | * GPIO_LOW |
ssmith73 | 1:10feea6e63a8 | 340 | * @return SUCCESS in case of success, FAILURE otherwise. |
ssmith73 | 1:10feea6e63a8 | 341 | */ |
ssmith73 | 1:10feea6e63a8 | 342 | int32_t gpio_get_value(struct gpio_desc *desc, uint8_t *value) |
ssmith73 | 1:10feea6e63a8 | 343 | { |
ssmith73 | 1:10feea6e63a8 | 344 | uint8_t returnVal = FAILURE; |
ssmith73 | 1:10feea6e63a8 | 345 | if (desc) { |
ssmith73 | 1:10feea6e63a8 | 346 | { |
ssmith73 | 1:10feea6e63a8 | 347 | DigitalIn gpio(desc->pin); |
ssmith73 | 1:10feea6e63a8 | 348 | *value = (uint8_t)gpio.read(); |
ssmith73 | 1:10feea6e63a8 | 349 | *value = gpio; |
ssmith73 | 1:10feea6e63a8 | 350 | returnVal = gpio.is_connected() ? SUCCESS : FAILURE; |
ssmith73 | 1:10feea6e63a8 | 351 | } |
ssmith73 | 1:10feea6e63a8 | 352 | |
ssmith73 | 1:10feea6e63a8 | 353 | return returnVal; |
ssmith73 | 1:10feea6e63a8 | 354 | } |
ssmith73 | 1:10feea6e63a8 | 355 | return FAILURE; |
ssmith73 | 1:10feea6e63a8 | 356 | } |
ssmith73 | 1:10feea6e63a8 | 357 | |
ssmith73 | 1:10feea6e63a8 | 358 | /** |
ssmith73 | 1:10feea6e63a8 | 359 | * @brief Generate miliseconds delay. |
ssmith73 | 1:10feea6e63a8 | 360 | * @param msecs - Delay in miliseconds. |
ssmith73 | 1:10feea6e63a8 | 361 | * @return None. |
ssmith73 | 1:10feea6e63a8 | 362 | */ |
ssmith73 | 1:10feea6e63a8 | 363 | void mdelay(uint32_t msecs) |
ssmith73 | 1:10feea6e63a8 | 364 | { |
ssmith73 | 1:10feea6e63a8 | 365 | if (msecs) |
ssmith73 | 1:10feea6e63a8 | 366 | { |
ssmith73 | 1:10feea6e63a8 | 367 | //unused variable - fix compiler warning |
ssmith73 | 1:10feea6e63a8 | 368 | } |
ssmith73 | 1:10feea6e63a8 | 369 | } |