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

Committer:
ssmith73
Date:
Thu Jun 13 15:29:24 2019 +0000
Revision:
1:10feea6e63a8
Parent:
0:5d706fbbc200
Child:
6:38fa8ac6e43b
Initial Commit

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 1:10feea6e63a8 97
ssmith73 1:10feea6e63a8 98 /******************************************************************************/
ssmith73 1:10feea6e63a8 99 /*************************** Types Declarations *******************************/
ssmith73 1:10feea6e63a8 100 /******************************************************************************/
ssmith73 1:10feea6e63a8 101
ssmith73 1:10feea6e63a8 102 typedef enum i2c_type
ssmith73 1:10feea6e63a8 103 {
ssmith73 1:10feea6e63a8 104 GENERIC_I2C
ssmith73 1:10feea6e63a8 105 } i2c_type;
ssmith73 1:10feea6e63a8 106
ssmith73 1:10feea6e63a8 107 typedef struct i2c_init_param
ssmith73 1:10feea6e63a8 108 {
ssmith73 1:10feea6e63a8 109 enum i2c_type type;
ssmith73 1:10feea6e63a8 110 uint32_t id;
ssmith73 1:10feea6e63a8 111 uint32_t max_speed_hz;
ssmith73 1:10feea6e63a8 112 uint8_t slave_address;
ssmith73 1:10feea6e63a8 113
ssmith73 1:10feea6e63a8 114 } i2c_init_param;
ssmith73 1:10feea6e63a8 115
ssmith73 1:10feea6e63a8 116 typedef struct i2c_desc
ssmith73 1:10feea6e63a8 117 {
ssmith73 1:10feea6e63a8 118 enum i2c_type type;
ssmith73 1:10feea6e63a8 119 uint32_t id;
ssmith73 1:10feea6e63a8 120 uint8_t slave_address;
ssmith73 1:10feea6e63a8 121 } i2c_desc;
ssmith73 1:10feea6e63a8 122
ssmith73 1:10feea6e63a8 123 typedef enum platforms
ssmith73 1:10feea6e63a8 124 {
ssmith73 1:10feea6e63a8 125 ARDUINO,
ssmith73 1:10feea6e63a8 126 MBED,
ssmith73 1:10feea6e63a8 127 }platforms;
ssmith73 1:10feea6e63a8 128
ssmith73 1:10feea6e63a8 129
ssmith73 1:10feea6e63a8 130 typedef enum spi_type
ssmith73 1:10feea6e63a8 131 {
ssmith73 1:10feea6e63a8 132 GENERIC_SPI
ssmith73 1:10feea6e63a8 133 } spi_type;
ssmith73 1:10feea6e63a8 134
ssmith73 1:10feea6e63a8 135 typedef enum spi_mode
ssmith73 1:10feea6e63a8 136 {
ssmith73 1:10feea6e63a8 137 SPI_MODE_0 = (0 | 0),
ssmith73 1:10feea6e63a8 138 SPI_MODE_1 = (0 | SPI_CPHA),
ssmith73 1:10feea6e63a8 139 SPI_MODE_2 = (SPI_CPOL | 0),
ssmith73 1:10feea6e63a8 140 SPI_MODE_3 = (SPI_CPOL | SPI_CPHA)
ssmith73 1:10feea6e63a8 141 } spi_mode;
ssmith73 1:10feea6e63a8 142
ssmith73 1:10feea6e63a8 143 typedef struct spi_init_param
ssmith73 1:10feea6e63a8 144 {
ssmith73 1:10feea6e63a8 145 enum platforms platform;
ssmith73 1:10feea6e63a8 146 enum spi_type type;
ssmith73 1:10feea6e63a8 147 uint32_t id;
ssmith73 1:10feea6e63a8 148 uint32_t max_speed_hz;
ssmith73 1:10feea6e63a8 149 enum spi_mode mode;
ssmith73 1:10feea6e63a8 150 uint8_t chip_select;
ssmith73 1:10feea6e63a8 151 } spi_init_param;
ssmith73 1:10feea6e63a8 152
ssmith73 1:10feea6e63a8 153 typedef struct spi_desc
ssmith73 1:10feea6e63a8 154 {
ssmith73 1:10feea6e63a8 155 enum spi_type type;
ssmith73 1:10feea6e63a8 156 uint32_t id;
ssmith73 1:10feea6e63a8 157 uint32_t max_speed_hz;
ssmith73 1:10feea6e63a8 158 enum spi_mode mode;
ssmith73 1:10feea6e63a8 159 uint8_t chip_select;
ssmith73 1:10feea6e63a8 160 } spi_desc;
ssmith73 1:10feea6e63a8 161
ssmith73 1:10feea6e63a8 162 typedef enum gpio_type
ssmith73 1:10feea6e63a8 163 {
ssmith73 1:10feea6e63a8 164 GENERIC_GPIO
ssmith73 1:10feea6e63a8 165 } gpio_type;
ssmith73 1:10feea6e63a8 166
ssmith73 1:10feea6e63a8 167 typedef struct gpio_desc
ssmith73 1:10feea6e63a8 168 {
ssmith73 1:10feea6e63a8 169 enum gpio_type type;
ssmith73 1:10feea6e63a8 170 uint32_t id;
ssmith73 1:10feea6e63a8 171 uint8_t number;
ssmith73 1:10feea6e63a8 172 PinName pin;
ssmith73 1:10feea6e63a8 173 } gpio_desc;
ssmith73 1:10feea6e63a8 174
ssmith73 1:10feea6e63a8 175 /******************************************************************************/
ssmith73 1:10feea6e63a8 176 /************************ Functions Declarations ******************************/
ssmith73 1:10feea6e63a8 177 /******************************************************************************/
ssmith73 1:10feea6e63a8 178
ssmith73 1:10feea6e63a8 179 /* Initialize the I2C communication peripheral. */
ssmith73 1:10feea6e63a8 180 int32_t mbed_i2c_init(struct i2c_desc **desc,
ssmith73 1:10feea6e63a8 181 const struct i2c_init_param *param);
ssmith73 1:10feea6e63a8 182
ssmith73 1:10feea6e63a8 183 /* Free the resources allocated by i2c_init(). */
ssmith73 1:10feea6e63a8 184 int32_t i2c_remove(struct i2c_desc *desc);
ssmith73 1:10feea6e63a8 185
ssmith73 1:10feea6e63a8 186 /* Write data to a slave device. */
ssmith73 1:10feea6e63a8 187 int32_t mbed_i2c_write(struct i2c_desc *desc,
ssmith73 1:10feea6e63a8 188 uint8_t *data,
ssmith73 1:10feea6e63a8 189 uint8_t bytes_number,
ssmith73 1:10feea6e63a8 190 uint8_t stop_bit);
ssmith73 1:10feea6e63a8 191
ssmith73 1:10feea6e63a8 192 /* Read data from a slave device. */
ssmith73 1:10feea6e63a8 193 int32_t mbed_i2c_read(struct i2c_desc *desc,
ssmith73 1:10feea6e63a8 194 uint8_t *data,
ssmith73 1:10feea6e63a8 195 uint8_t bytes_number,
ssmith73 1:10feea6e63a8 196 uint8_t stop_bit);
ssmith73 1:10feea6e63a8 197
ssmith73 1:10feea6e63a8 198 /* Initialize the SPI communication peripheral. */
ssmith73 1:10feea6e63a8 199 int32_t mbed_spi_init(struct spi_desc **desc,
ssmith73 1:10feea6e63a8 200 const struct spi_init_param *param);
ssmith73 1:10feea6e63a8 201
ssmith73 1:10feea6e63a8 202 /* Free the resources allocated by spi_init() */
ssmith73 1:10feea6e63a8 203 int32_t spi_remove(struct spi_desc *desc);
ssmith73 1:10feea6e63a8 204
ssmith73 1:10feea6e63a8 205 /* Write and read data to/from SPI. */
ssmith73 1:10feea6e63a8 206 int32_t spi_write_and_read(struct spi_desc *desc,
ssmith73 1:10feea6e63a8 207 uint8_t *data,
ssmith73 1:10feea6e63a8 208 uint8_t bytes_number);
ssmith73 1:10feea6e63a8 209
ssmith73 1:10feea6e63a8 210 /* Obtain the GPIO decriptor. */
ssmith73 1:10feea6e63a8 211 int32_t gpio_get(struct gpio_desc **desc,
ssmith73 1:10feea6e63a8 212 gpio_desc gpio_number);
ssmith73 1:10feea6e63a8 213 //uint8_t gpio_number);
ssmith73 1:10feea6e63a8 214
ssmith73 1:10feea6e63a8 215 /* Free the resources allocated by gpio_get() */
ssmith73 1:10feea6e63a8 216 int32_t gpio_remove(struct gpio_desc *desc);
ssmith73 1:10feea6e63a8 217
ssmith73 1:10feea6e63a8 218 /* Enable the input direction of the specified GPIO. */
ssmith73 1:10feea6e63a8 219 int32_t gpio_direction_input(struct gpio_desc *desc);
ssmith73 1:10feea6e63a8 220
ssmith73 1:10feea6e63a8 221 /* Enable the output direction of the specified GPIO. */
ssmith73 1:10feea6e63a8 222 int32_t gpio_direction_output(struct gpio_desc *desc,
ssmith73 1:10feea6e63a8 223 uint8_t value);
ssmith73 1:10feea6e63a8 224
ssmith73 1:10feea6e63a8 225 /* Get the direction of the specified GPIO. */
ssmith73 1:10feea6e63a8 226 int32_t gpio_get_direction(struct gpio_desc *desc,
ssmith73 1:10feea6e63a8 227 uint8_t *direction);
ssmith73 1:10feea6e63a8 228
ssmith73 1:10feea6e63a8 229 /* Set the value of the specified GPIO. */
ssmith73 1:10feea6e63a8 230 int32_t gpio_set_value(struct gpio_desc *desc,
ssmith73 1:10feea6e63a8 231 uint8_t value);
ssmith73 1:10feea6e63a8 232
ssmith73 1:10feea6e63a8 233 /* Get the value of the specified GPIO. */
ssmith73 1:10feea6e63a8 234 int32_t gpio_get_value(struct gpio_desc *desc,
ssmith73 1:10feea6e63a8 235 uint8_t *value);
ssmith73 1:10feea6e63a8 236
ssmith73 1:10feea6e63a8 237 /* Generate miliseconds delay. */
ssmith73 1:10feea6e63a8 238 void mdelay(uint32_t msecs);
ssmith73 1:10feea6e63a8 239
ssmith73 1:10feea6e63a8 240
ssmith73 1:10feea6e63a8 241 #ifdef __cplusplus // Closing extern c
ssmith73 1:10feea6e63a8 242 }
ssmith73 1:10feea6e63a8 243 #endif
ssmith73 1:10feea6e63a8 244
ssmith73 1:10feea6e63a8 245 #endif // PLATFORM_DRIVERS_H_