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

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?

UserRevisionLine numberNew contents of line
ssmith73 1:10feea6e63a8 1 /***************************************************************************/ /**
ssmith73 1:10feea6e63a8 2 * @file platform_drivers.h
ssmith73 1:10feea6e63a8 3 * @brief Header file of Generic Platform Drivers.
ssmith73 1:10feea6e63a8 4 * @author DBogdan (dragos.bogdan@analog.com)
ssmith73 1:10feea6e63a8 5 ********************************************************************************
ssmith73 1:10feea6e63a8 6 * Copyright 2017(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 #ifndef PLATFORM_DRIVERS_H_
ssmith73 1:10feea6e63a8 41 #define PLATFORM_DRIVERS_H_
ssmith73 1:10feea6e63a8 42
ssmith73 1:10feea6e63a8 43 // Our platform driver needs to be C-compatible to work with the drivers
ssmith73 1:10feea6e63a8 44 #ifdef __cplusplus
ssmith73 1:10feea6e63a8 45 extern "C"
ssmith73 1:10feea6e63a8 46 {
ssmith73 1:10feea6e63a8 47 #endif
ssmith73 1:10feea6e63a8 48
ssmith73 1:10feea6e63a8 49 #include <stdint.h>
ssmith73 1:10feea6e63a8 50
ssmith73 1:10feea6e63a8 51 /**
ssmith73 1:10feea6e63a8 52 TODO: The use of PinNames introduces a dependency on the MBED library
ssmith73 1:10feea6e63a8 53 Investigate if this dependency can be cleanly removed.
ssmith73 1:10feea6e63a8 54 ***/
ssmith73 1:10feea6e63a8 55 #include "PinNames.h"
ssmith73 1:10feea6e63a8 56
ssmith73 1:10feea6e63a8 57 /******************************************************************************/
ssmith73 1:10feea6e63a8 58 /********************** Macros and Constants Definitions **********************/
ssmith73 1:10feea6e63a8 59 /******************************************************************************/
ssmith73 1:10feea6e63a8 60 #define MBED_ACTIVE
ssmith73 1:10feea6e63a8 61
ssmith73 1:10feea6e63a8 62 #define SUCCESS 0
ssmith73 1:10feea6e63a8 63 #define FAILURE -1
ssmith73 1:10feea6e63a8 64
ssmith73 1:10feea6e63a8 65 #define SPI_CPHA 0x01
ssmith73 1:10feea6e63a8 66 #define SPI_CPOL 0x02
ssmith73 1:10feea6e63a8 67
ssmith73 1:10feea6e63a8 68 #define GPIO_OUT 0x01
ssmith73 1:10feea6e63a8 69 #define GPIO_IN 0x00
ssmith73 1:10feea6e63a8 70
ssmith73 1:10feea6e63a8 71 #define GPIO_HIGH 0x01
ssmith73 1:10feea6e63a8 72 #define GPIO_LOW 0x00
ssmith73 1:10feea6e63a8 73
ssmith73 1:10feea6e63a8 74 #define INTERNAL 1
ssmith73 1:10feea6e63a8 75 #define EXTERNAL 2
ssmith73 1:10feea6e63a8 76
ssmith73 1:10feea6e63a8 77 #define SEND_BYTE 8
ssmith73 1:10feea6e63a8 78
ssmith73 1:10feea6e63a8 79 /**
ssmith73 1:10feea6e63a8 80 There is a naming collision with CMD_OFFSET, in the MBED API. To keep the code
ssmith73 1:10feea6e63a8 81 clean and avoid changes to the noOS layer, it will be undefined here. If
ssmith73 1:10feea6e63a8 82 your code uses this file, this will need to be re-introduce and the the
ssmith73 1:10feea6e63a8 83 name changed in the driver.
ssmith73 1:10feea6e63a8 84 stm32f4xx_ll_sdmmc.h(660)
ssmith73 1:10feea6e63a8 85 **/
ssmith73 1:10feea6e63a8 86 #undef CMD_OFFSET
ssmith73 1:10feea6e63a8 87
ssmith73 1:10feea6e63a8 88 /**
ssmith73 1:10feea6e63a8 89 There is a naming collision withe following functions in the no-OS drivers
ssmith73 1:10feea6e63a8 90 and the mbed API. Functions are redefined here to avoid changes to the
ssmith73 1:10feea6e63a8 91 no-OS driver code.
ssmith73 1:10feea6e63a8 92 **/
ssmith73 1:10feea6e63a8 93 #define spi_init mbed_spi_init
ssmith73 1:10feea6e63a8 94 #define i2c_init mbed_i2c_init
ssmith73 1:10feea6e63a8 95 #define i2c_read mbed_i2c_read
ssmith73 1:10feea6e63a8 96 #define i2c_write mbed_i2c_write
ssmith73 6:38fa8ac6e43b 97 #define MAX_SLAVE_SELECTS 8
ssmith73 1:10feea6e63a8 98
ssmith73 1:10feea6e63a8 99 /******************************************************************************/
ssmith73 1:10feea6e63a8 100 /*************************** Types Declarations *******************************/
ssmith73 1:10feea6e63a8 101 /******************************************************************************/
ssmith73 1:10feea6e63a8 102
ssmith73 1:10feea6e63a8 103 typedef enum i2c_type
ssmith73 1:10feea6e63a8 104 {
ssmith73 1:10feea6e63a8 105 GENERIC_I2C
ssmith73 1:10feea6e63a8 106 } i2c_type;
ssmith73 1:10feea6e63a8 107
ssmith73 1:10feea6e63a8 108 typedef struct i2c_init_param
ssmith73 1:10feea6e63a8 109 {
ssmith73 1:10feea6e63a8 110 enum i2c_type type;
ssmith73 1:10feea6e63a8 111 uint32_t id;
ssmith73 1:10feea6e63a8 112 uint32_t max_speed_hz;
ssmith73 1:10feea6e63a8 113 uint8_t slave_address;
ssmith73 1:10feea6e63a8 114
ssmith73 1:10feea6e63a8 115 } i2c_init_param;
ssmith73 1:10feea6e63a8 116
ssmith73 1:10feea6e63a8 117 typedef struct i2c_desc
ssmith73 1:10feea6e63a8 118 {
ssmith73 1:10feea6e63a8 119 enum i2c_type type;
ssmith73 1:10feea6e63a8 120 uint32_t id;
ssmith73 1:10feea6e63a8 121 uint8_t slave_address;
ssmith73 1:10feea6e63a8 122 } i2c_desc;
ssmith73 1:10feea6e63a8 123
ssmith73 1:10feea6e63a8 124 typedef enum platforms
ssmith73 1:10feea6e63a8 125 {
ssmith73 1:10feea6e63a8 126 ARDUINO,
ssmith73 1:10feea6e63a8 127 MBED,
ssmith73 1:10feea6e63a8 128 }platforms;
ssmith73 1:10feea6e63a8 129
ssmith73 1:10feea6e63a8 130
ssmith73 1:10feea6e63a8 131 typedef enum spi_type
ssmith73 1:10feea6e63a8 132 {
ssmith73 1:10feea6e63a8 133 GENERIC_SPI
ssmith73 1:10feea6e63a8 134 } spi_type;
ssmith73 1:10feea6e63a8 135
ssmith73 1:10feea6e63a8 136 typedef enum spi_mode
ssmith73 1:10feea6e63a8 137 {
ssmith73 1:10feea6e63a8 138 SPI_MODE_0 = (0 | 0),
ssmith73 1:10feea6e63a8 139 SPI_MODE_1 = (0 | SPI_CPHA),
ssmith73 1:10feea6e63a8 140 SPI_MODE_2 = (SPI_CPOL | 0),
ssmith73 1:10feea6e63a8 141 SPI_MODE_3 = (SPI_CPOL | SPI_CPHA)
ssmith73 1:10feea6e63a8 142 } spi_mode;
ssmith73 1:10feea6e63a8 143
ssmith73 1:10feea6e63a8 144 typedef struct spi_init_param
ssmith73 1:10feea6e63a8 145 {
ssmith73 1:10feea6e63a8 146 enum platforms platform;
ssmith73 1:10feea6e63a8 147 enum spi_type type;
ssmith73 1:10feea6e63a8 148 uint32_t id;
ssmith73 1:10feea6e63a8 149 uint32_t max_speed_hz;
ssmith73 1:10feea6e63a8 150 enum spi_mode mode;
ssmith73 1:10feea6e63a8 151 uint8_t chip_select;
ssmith73 1:10feea6e63a8 152 } spi_init_param;
ssmith73 1:10feea6e63a8 153
ssmith73 1:10feea6e63a8 154 typedef struct spi_desc
ssmith73 1:10feea6e63a8 155 {
ssmith73 1:10feea6e63a8 156 enum spi_type type;
ssmith73 1:10feea6e63a8 157 uint32_t id;
ssmith73 1:10feea6e63a8 158 uint32_t max_speed_hz;
ssmith73 1:10feea6e63a8 159 enum spi_mode mode;
ssmith73 1:10feea6e63a8 160 uint8_t chip_select;
ssmith73 1:10feea6e63a8 161 } spi_desc;
ssmith73 1:10feea6e63a8 162
ssmith73 1:10feea6e63a8 163 typedef enum gpio_type
ssmith73 1:10feea6e63a8 164 {
ssmith73 1:10feea6e63a8 165 GENERIC_GPIO
ssmith73 1:10feea6e63a8 166 } gpio_type;
ssmith73 1:10feea6e63a8 167
ssmith73 1:10feea6e63a8 168 typedef struct gpio_desc
ssmith73 1:10feea6e63a8 169 {
ssmith73 1:10feea6e63a8 170 enum gpio_type type;
ssmith73 1:10feea6e63a8 171 uint32_t id;
ssmith73 1:10feea6e63a8 172 uint8_t number;
ssmith73 1:10feea6e63a8 173 PinName pin;
ssmith73 1:10feea6e63a8 174 } gpio_desc;
ssmith73 1:10feea6e63a8 175
ssmith73 1:10feea6e63a8 176 /******************************************************************************/
ssmith73 1:10feea6e63a8 177 /************************ Functions Declarations ******************************/
ssmith73 1:10feea6e63a8 178 /******************************************************************************/
ssmith73 1:10feea6e63a8 179
ssmith73 1:10feea6e63a8 180 /* Initialize the I2C communication peripheral. */
ssmith73 1:10feea6e63a8 181 int32_t mbed_i2c_init(struct i2c_desc **desc,
ssmith73 1:10feea6e63a8 182 const struct i2c_init_param *param);
ssmith73 1:10feea6e63a8 183
ssmith73 1:10feea6e63a8 184 /* Free the resources allocated by i2c_init(). */
ssmith73 1:10feea6e63a8 185 int32_t i2c_remove(struct i2c_desc *desc);
ssmith73 1:10feea6e63a8 186
ssmith73 1:10feea6e63a8 187 /* Write data to a slave device. */
ssmith73 1:10feea6e63a8 188 int32_t mbed_i2c_write(struct i2c_desc *desc,
ssmith73 1:10feea6e63a8 189 uint8_t *data,
ssmith73 1:10feea6e63a8 190 uint8_t bytes_number,
ssmith73 1:10feea6e63a8 191 uint8_t stop_bit);
ssmith73 1:10feea6e63a8 192
ssmith73 1:10feea6e63a8 193 /* Read data from a slave device. */
ssmith73 1:10feea6e63a8 194 int32_t mbed_i2c_read(struct i2c_desc *desc,
ssmith73 1:10feea6e63a8 195 uint8_t *data,
ssmith73 1:10feea6e63a8 196 uint8_t bytes_number,
ssmith73 1:10feea6e63a8 197 uint8_t stop_bit);
ssmith73 1:10feea6e63a8 198
ssmith73 1:10feea6e63a8 199 /* Initialize the SPI communication peripheral. */
ssmith73 1:10feea6e63a8 200 int32_t mbed_spi_init(struct spi_desc **desc,
ssmith73 1:10feea6e63a8 201 const struct spi_init_param *param);
ssmith73 1:10feea6e63a8 202
ssmith73 1:10feea6e63a8 203 /* Free the resources allocated by spi_init() */
ssmith73 1:10feea6e63a8 204 int32_t spi_remove(struct spi_desc *desc);
ssmith73 1:10feea6e63a8 205
ssmith73 1:10feea6e63a8 206 /* Write and read data to/from SPI. */
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 /* Obtain the GPIO decriptor. */
ssmith73 1:10feea6e63a8 212 int32_t gpio_get(struct gpio_desc **desc,
ssmith73 1:10feea6e63a8 213 gpio_desc gpio_number);
ssmith73 1:10feea6e63a8 214 //uint8_t gpio_number);
ssmith73 1:10feea6e63a8 215
ssmith73 1:10feea6e63a8 216 /* Free the resources allocated by gpio_get() */
ssmith73 1:10feea6e63a8 217 int32_t gpio_remove(struct gpio_desc *desc);
ssmith73 1:10feea6e63a8 218
ssmith73 1:10feea6e63a8 219 /* Enable the input direction of the specified GPIO. */
ssmith73 1:10feea6e63a8 220 int32_t gpio_direction_input(struct gpio_desc *desc);
ssmith73 1:10feea6e63a8 221
ssmith73 1:10feea6e63a8 222 /* Enable the output direction of the specified GPIO. */
ssmith73 1:10feea6e63a8 223 int32_t gpio_direction_output(struct gpio_desc *desc,
ssmith73 1:10feea6e63a8 224 uint8_t value);
ssmith73 1:10feea6e63a8 225
ssmith73 1:10feea6e63a8 226 /* Get the direction of the specified GPIO. */
ssmith73 1:10feea6e63a8 227 int32_t gpio_get_direction(struct gpio_desc *desc,
ssmith73 1:10feea6e63a8 228 uint8_t *direction);
ssmith73 1:10feea6e63a8 229
ssmith73 1:10feea6e63a8 230 /* Set the value of the specified GPIO. */
ssmith73 1:10feea6e63a8 231 int32_t gpio_set_value(struct gpio_desc *desc,
ssmith73 1:10feea6e63a8 232 uint8_t value);
ssmith73 1:10feea6e63a8 233
ssmith73 1:10feea6e63a8 234 /* Get the value of the specified GPIO. */
ssmith73 1:10feea6e63a8 235 int32_t gpio_get_value(struct gpio_desc *desc,
ssmith73 1:10feea6e63a8 236 uint8_t *value);
ssmith73 1:10feea6e63a8 237
ssmith73 1:10feea6e63a8 238 /* Generate miliseconds delay. */
ssmith73 1:10feea6e63a8 239 void mdelay(uint32_t msecs);
ssmith73 1:10feea6e63a8 240
ssmith73 1:10feea6e63a8 241
ssmith73 1:10feea6e63a8 242 #ifdef __cplusplus // Closing extern c
ssmith73 1:10feea6e63a8 243 }
ssmith73 1:10feea6e63a8 244 #endif
ssmith73 1:10feea6e63a8 245
ssmith73 1:10feea6e63a8 246 #endif // PLATFORM_DRIVERS_H_