mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Fri Sep 11 09:30:09 2015 +0100
Revision:
621:9c82b0f79f3d
Parent:
552:a1b9575155a3
Synchronized with git revision 6c1d63e069ab9bd86de92e8296ca783681257538

Full URL: https://github.com/mbedmicro/mbed/commit/6c1d63e069ab9bd86de92e8296ca783681257538/

ignore target files not supported by the yotta module

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 155:8435094ec241 1 /* mbed Microcontroller Library
mbed_official 155:8435094ec241 2 *******************************************************************************
mbed_official 155:8435094ec241 3 * Copyright (c) 2014, STMicroelectronics
mbed_official 155:8435094ec241 4 * All rights reserved.
mbed_official 155:8435094ec241 5 *
mbed_official 155:8435094ec241 6 * Redistribution and use in source and binary forms, with or without
mbed_official 155:8435094ec241 7 * modification, are permitted provided that the following conditions are met:
mbed_official 155:8435094ec241 8 *
mbed_official 155:8435094ec241 9 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 155:8435094ec241 10 * this list of conditions and the following disclaimer.
mbed_official 155:8435094ec241 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 155:8435094ec241 12 * this list of conditions and the following disclaimer in the documentation
mbed_official 155:8435094ec241 13 * and/or other materials provided with the distribution.
mbed_official 155:8435094ec241 14 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 155:8435094ec241 15 * may be used to endorse or promote products derived from this software
mbed_official 155:8435094ec241 16 * without specific prior written permission.
mbed_official 155:8435094ec241 17 *
mbed_official 155:8435094ec241 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 155:8435094ec241 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 155:8435094ec241 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 155:8435094ec241 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 155:8435094ec241 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 155:8435094ec241 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 155:8435094ec241 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 155:8435094ec241 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 155:8435094ec241 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 155:8435094ec241 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 155:8435094ec241 28 *******************************************************************************
mbed_official 155:8435094ec241 29 */
mbed_official 227:7bd0639b8911 30 #include "mbed_assert.h"
mbed_official 155:8435094ec241 31 #include "spi_api.h"
mbed_official 155:8435094ec241 32
mbed_official 155:8435094ec241 33 #if DEVICE_SPI
mbed_official 155:8435094ec241 34
mbed_official 155:8435094ec241 35 #include <math.h>
mbed_official 155:8435094ec241 36 #include "cmsis.h"
mbed_official 155:8435094ec241 37 #include "pinmap.h"
mbed_official 155:8435094ec241 38
mbed_official 155:8435094ec241 39 static const PinMap PinMap_SPI_MOSI[] = {
mbed_official 155:8435094ec241 40 {PA_11, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
mbed_official 155:8435094ec241 41 {PB_5, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_6)},
mbed_official 155:8435094ec241 42 {PB_15, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
mbed_official 155:8435094ec241 43 {PC_12, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_6)},
mbed_official 155:8435094ec241 44 {NC, NC, 0}
mbed_official 155:8435094ec241 45 };
mbed_official 155:8435094ec241 46
mbed_official 155:8435094ec241 47 static const PinMap PinMap_SPI_MISO[] = {
mbed_official 155:8435094ec241 48 {PA_10, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
mbed_official 155:8435094ec241 49 {PB_4, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_6)},
mbed_official 155:8435094ec241 50 {PB_14, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
mbed_official 155:8435094ec241 51 {PC_11, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_6)},
mbed_official 155:8435094ec241 52 {NC, NC, 0}
mbed_official 155:8435094ec241 53 };
mbed_official 155:8435094ec241 54
mbed_official 155:8435094ec241 55 static const PinMap PinMap_SPI_SCLK[] = {
mbed_official 155:8435094ec241 56 {PB_3, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_6)},
mbed_official 155:8435094ec241 57 {PB_13, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
mbed_official 155:8435094ec241 58 {PC_10, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_6)},
mbed_official 155:8435094ec241 59 {PF_1, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
mbed_official 155:8435094ec241 60 {NC, NC, 0}
mbed_official 155:8435094ec241 61 };
mbed_official 155:8435094ec241 62
mbed_official 155:8435094ec241 63 static const PinMap PinMap_SPI_SSEL[] = {
mbed_official 155:8435094ec241 64 {PA_4, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_6)},
mbed_official 155:8435094ec241 65 {PA_15, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_6)},
mbed_official 155:8435094ec241 66 {PB_12, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
mbed_official 155:8435094ec241 67 {PF_0, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
mbed_official 155:8435094ec241 68 {NC, NC, 0}
mbed_official 155:8435094ec241 69 };
mbed_official 155:8435094ec241 70
mbed_official 155:8435094ec241 71 static void init_spi(spi_t *obj) {
mbed_official 155:8435094ec241 72 SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
mbed_official 155:8435094ec241 73 SPI_InitTypeDef SPI_InitStructure;
mbed_official 155:8435094ec241 74
mbed_official 155:8435094ec241 75 SPI_Cmd(spi, DISABLE);
mbed_official 155:8435094ec241 76
mbed_official 155:8435094ec241 77 SPI_InitStructure.SPI_Mode = obj->mode;
mbed_official 155:8435094ec241 78 SPI_InitStructure.SPI_NSS = obj->nss;
mbed_official 155:8435094ec241 79 SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
mbed_official 155:8435094ec241 80 SPI_InitStructure.SPI_DataSize = obj->bits;
mbed_official 155:8435094ec241 81 SPI_InitStructure.SPI_CPOL = obj->cpol;
mbed_official 155:8435094ec241 82 SPI_InitStructure.SPI_CPHA = obj->cpha;
mbed_official 155:8435094ec241 83 SPI_InitStructure.SPI_BaudRatePrescaler = obj->br_presc;
mbed_official 155:8435094ec241 84 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
mbed_official 155:8435094ec241 85 SPI_InitStructure.SPI_CRCPolynomial = 7;
mbed_official 155:8435094ec241 86 SPI_Init(spi, &SPI_InitStructure);
mbed_official 155:8435094ec241 87
mbed_official 155:8435094ec241 88 SPI_RxFIFOThresholdConfig(spi, SPI_RxFIFOThreshold_QF);
mbed_official 155:8435094ec241 89
mbed_official 155:8435094ec241 90 SPI_Cmd(spi, ENABLE);
mbed_official 155:8435094ec241 91 }
mbed_official 155:8435094ec241 92
mbed_official 155:8435094ec241 93 void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) {
mbed_official 155:8435094ec241 94 // Determine the SPI to use
mbed_official 155:8435094ec241 95 SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
mbed_official 155:8435094ec241 96 SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
mbed_official 155:8435094ec241 97 SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK);
mbed_official 155:8435094ec241 98 SPIName spi_ssel = (SPIName)pinmap_peripheral(ssel, PinMap_SPI_SSEL);
mbed_official 155:8435094ec241 99
mbed_official 155:8435094ec241 100 SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
mbed_official 155:8435094ec241 101 SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
mbed_official 155:8435094ec241 102
mbed_official 155:8435094ec241 103 obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
mbed_official 155:8435094ec241 104
mbed_official 227:7bd0639b8911 105 MBED_ASSERT(obj->spi != (SPIName)NC);
mbed_official 155:8435094ec241 106
mbed_official 155:8435094ec241 107 // Enable SPI clock
mbed_official 155:8435094ec241 108 if (obj->spi == SPI_2) {
mbed_official 155:8435094ec241 109 RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
mbed_official 155:8435094ec241 110 }
mbed_official 155:8435094ec241 111 if (obj->spi == SPI_3) {
mbed_official 155:8435094ec241 112 RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
mbed_official 155:8435094ec241 113 }
mbed_official 155:8435094ec241 114
mbed_official 155:8435094ec241 115 // Configure the SPI pins
mbed_official 155:8435094ec241 116 pinmap_pinout(mosi, PinMap_SPI_MOSI);
mbed_official 155:8435094ec241 117 pinmap_pinout(miso, PinMap_SPI_MISO);
mbed_official 155:8435094ec241 118 pinmap_pinout(sclk, PinMap_SPI_SCLK);
mbed_official 155:8435094ec241 119
mbed_official 155:8435094ec241 120 // Save new values
mbed_official 155:8435094ec241 121 obj->bits = SPI_DataSize_8b;
mbed_official 155:8435094ec241 122 obj->cpol = SPI_CPOL_Low;
mbed_official 155:8435094ec241 123 obj->cpha = SPI_CPHA_1Edge;
mbed_official 155:8435094ec241 124 obj->br_presc = SPI_BaudRatePrescaler_256;
mbed_official 155:8435094ec241 125
mbed_official 552:a1b9575155a3 126 if (ssel != NC) {
mbed_official 155:8435094ec241 127 pinmap_pinout(ssel, PinMap_SPI_SSEL);
mbed_official 552:a1b9575155a3 128 } else {
mbed_official 552:a1b9575155a3 129 obj->nss = SPI_NSS_SOFT;
mbed_official 155:8435094ec241 130 }
mbed_official 155:8435094ec241 131
mbed_official 155:8435094ec241 132 init_spi(obj);
mbed_official 155:8435094ec241 133 }
mbed_official 155:8435094ec241 134
mbed_official 155:8435094ec241 135 void spi_free(spi_t *obj) {
mbed_official 155:8435094ec241 136 SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
mbed_official 155:8435094ec241 137 SPI_I2S_DeInit(spi);
mbed_official 155:8435094ec241 138 }
mbed_official 155:8435094ec241 139
mbed_official 155:8435094ec241 140 void spi_format(spi_t *obj, int bits, int mode, int slave) {
mbed_official 155:8435094ec241 141 // Save new values
mbed_official 155:8435094ec241 142 if (bits == 8) {
mbed_official 155:8435094ec241 143 obj->bits = SPI_DataSize_8b;
mbed_official 155:8435094ec241 144 } else {
mbed_official 155:8435094ec241 145 obj->bits = SPI_DataSize_16b;
mbed_official 155:8435094ec241 146 }
mbed_official 155:8435094ec241 147
mbed_official 155:8435094ec241 148 switch (mode) {
mbed_official 155:8435094ec241 149 case 0:
mbed_official 155:8435094ec241 150 obj->cpol = SPI_CPOL_Low;
mbed_official 155:8435094ec241 151 obj->cpha = SPI_CPHA_1Edge;
mbed_official 155:8435094ec241 152 break;
mbed_official 155:8435094ec241 153 case 1:
mbed_official 155:8435094ec241 154 obj->cpol = SPI_CPOL_Low;
mbed_official 155:8435094ec241 155 obj->cpha = SPI_CPHA_2Edge;
mbed_official 155:8435094ec241 156 break;
mbed_official 155:8435094ec241 157 case 2:
mbed_official 155:8435094ec241 158 obj->cpol = SPI_CPOL_High;
mbed_official 155:8435094ec241 159 obj->cpha = SPI_CPHA_1Edge;
mbed_official 155:8435094ec241 160 break;
mbed_official 155:8435094ec241 161 default:
mbed_official 155:8435094ec241 162 obj->cpol = SPI_CPOL_High;
mbed_official 155:8435094ec241 163 obj->cpha = SPI_CPHA_2Edge;
mbed_official 155:8435094ec241 164 break;
mbed_official 155:8435094ec241 165 }
mbed_official 155:8435094ec241 166
mbed_official 552:a1b9575155a3 167 if (obj->nss != SPI_NSS_SOFT) {
mbed_official 552:a1b9575155a3 168 obj->nss = (slave) ? SPI_NSS_HARD_INPUT : SPI_NSS_HARD_OUTPUT;
mbed_official 155:8435094ec241 169 }
mbed_official 155:8435094ec241 170
mbed_official 552:a1b9575155a3 171 obj->mode = (slave) ? SPI_MODE_SLAVE : SPI_MODE_MASTER;
mbed_official 552:a1b9575155a3 172
mbed_official 155:8435094ec241 173 init_spi(obj);
mbed_official 155:8435094ec241 174 }
mbed_official 155:8435094ec241 175
mbed_official 155:8435094ec241 176 void spi_frequency(spi_t *obj, int hz) {
mbed_official 155:8435094ec241 177 // Values depend of PCLK1: 32 MHz if HSI is used, 36 MHz if HSE is used
mbed_official 155:8435094ec241 178 if (hz < 250000) {
mbed_official 155:8435094ec241 179 obj->br_presc = SPI_BaudRatePrescaler_256; // 125 kHz - 141 kHz
mbed_official 155:8435094ec241 180 } else if ((hz >= 250000) && (hz < 500000)) {
mbed_official 155:8435094ec241 181 obj->br_presc = SPI_BaudRatePrescaler_128; // 250 kHz - 280 kHz
mbed_official 155:8435094ec241 182 } else if ((hz >= 500000) && (hz < 1000000)) {
mbed_official 155:8435094ec241 183 obj->br_presc = SPI_BaudRatePrescaler_64; // 500 kHz - 560 kHz
mbed_official 155:8435094ec241 184 } else if ((hz >= 1000000) && (hz < 2000000)) {
mbed_official 155:8435094ec241 185 obj->br_presc = SPI_BaudRatePrescaler_32; // 1 MHz - 1.13 MHz
mbed_official 155:8435094ec241 186 } else if ((hz >= 2000000) && (hz < 4000000)) {
mbed_official 155:8435094ec241 187 obj->br_presc = SPI_BaudRatePrescaler_16; // 2 MHz - 2.25 MHz
mbed_official 155:8435094ec241 188 } else if ((hz >= 4000000) && (hz < 8000000)) {
mbed_official 155:8435094ec241 189 obj->br_presc = SPI_BaudRatePrescaler_8; // 4 MHz - 4.5 MHz
mbed_official 155:8435094ec241 190 } else if ((hz >= 8000000) && (hz < 16000000)) {
mbed_official 155:8435094ec241 191 obj->br_presc = SPI_BaudRatePrescaler_4; // 8 MHz - 9 MHz
mbed_official 155:8435094ec241 192 } else { // >= 16000000
mbed_official 155:8435094ec241 193 obj->br_presc = SPI_BaudRatePrescaler_2; // 16 MHz - 18 MHz
mbed_official 155:8435094ec241 194 }
mbed_official 155:8435094ec241 195 init_spi(obj);
mbed_official 155:8435094ec241 196 }
mbed_official 155:8435094ec241 197
mbed_official 155:8435094ec241 198 static inline int ssp_readable(spi_t *obj) {
mbed_official 155:8435094ec241 199 int status;
mbed_official 155:8435094ec241 200 SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
mbed_official 155:8435094ec241 201 // Check if data is received
mbed_official 155:8435094ec241 202 status = ((SPI_I2S_GetFlagStatus(spi, SPI_I2S_FLAG_RXNE) != RESET) ? 1 : 0);
mbed_official 155:8435094ec241 203 return status;
mbed_official 155:8435094ec241 204 }
mbed_official 155:8435094ec241 205
mbed_official 155:8435094ec241 206 static inline int ssp_writeable(spi_t *obj) {
mbed_official 155:8435094ec241 207 int status;
mbed_official 155:8435094ec241 208 SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
mbed_official 155:8435094ec241 209 // Check if data is transmitted
mbed_official 155:8435094ec241 210 status = ((SPI_I2S_GetFlagStatus(spi, SPI_I2S_FLAG_TXE) != RESET) ? 1 : 0);
mbed_official 155:8435094ec241 211 return status;
mbed_official 155:8435094ec241 212 }
mbed_official 155:8435094ec241 213
mbed_official 155:8435094ec241 214 static inline void ssp_write(spi_t *obj, int value) {
mbed_official 155:8435094ec241 215 SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
mbed_official 155:8435094ec241 216 while (!ssp_writeable(obj));
mbed_official 155:8435094ec241 217 if (obj->bits == SPI_DataSize_8b) {
mbed_official 155:8435094ec241 218 SPI_SendData8(spi, (uint8_t)value);
mbed_official 155:8435094ec241 219 } else {
mbed_official 155:8435094ec241 220 SPI_I2S_SendData16(spi, (uint16_t)value);
mbed_official 155:8435094ec241 221 }
mbed_official 155:8435094ec241 222 }
mbed_official 155:8435094ec241 223
mbed_official 155:8435094ec241 224 static inline int ssp_read(spi_t *obj) {
mbed_official 155:8435094ec241 225 SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
mbed_official 155:8435094ec241 226 while (!ssp_readable(obj));
mbed_official 155:8435094ec241 227 if (obj->bits == SPI_DataSize_8b) {
mbed_official 155:8435094ec241 228 return (int)SPI_ReceiveData8(spi);
mbed_official 155:8435094ec241 229 } else {
mbed_official 155:8435094ec241 230 return (int)SPI_I2S_ReceiveData16(spi);
mbed_official 155:8435094ec241 231 }
mbed_official 155:8435094ec241 232 }
mbed_official 155:8435094ec241 233
mbed_official 155:8435094ec241 234 static inline int ssp_busy(spi_t *obj) {
mbed_official 155:8435094ec241 235 int status;
mbed_official 155:8435094ec241 236 SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
mbed_official 155:8435094ec241 237 status = ((SPI_I2S_GetFlagStatus(spi, SPI_I2S_FLAG_BSY) != RESET) ? 1 : 0);
mbed_official 155:8435094ec241 238 return status;
mbed_official 155:8435094ec241 239 }
mbed_official 155:8435094ec241 240
mbed_official 155:8435094ec241 241 int spi_master_write(spi_t *obj, int value) {
mbed_official 155:8435094ec241 242 ssp_write(obj, value);
mbed_official 155:8435094ec241 243 return ssp_read(obj);
mbed_official 155:8435094ec241 244 }
mbed_official 155:8435094ec241 245
mbed_official 155:8435094ec241 246 int spi_slave_receive(spi_t *obj) {
mbed_official 155:8435094ec241 247 return (ssp_readable(obj) && !ssp_busy(obj)) ? (1) : (0);
mbed_official 155:8435094ec241 248 };
mbed_official 155:8435094ec241 249
mbed_official 155:8435094ec241 250 int spi_slave_read(spi_t *obj) {
mbed_official 155:8435094ec241 251 SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
mbed_official 155:8435094ec241 252 if (obj->bits == SPI_DataSize_8b) {
mbed_official 155:8435094ec241 253 return (int)SPI_ReceiveData8(spi);
mbed_official 155:8435094ec241 254 } else {
mbed_official 155:8435094ec241 255 return (int)SPI_I2S_ReceiveData16(spi);
mbed_official 155:8435094ec241 256 }
mbed_official 155:8435094ec241 257 }
mbed_official 155:8435094ec241 258
mbed_official 155:8435094ec241 259 void spi_slave_write(spi_t *obj, int value) {
mbed_official 155:8435094ec241 260 SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
mbed_official 155:8435094ec241 261 while (!ssp_writeable(obj));
mbed_official 155:8435094ec241 262 if (obj->bits == SPI_DataSize_8b) {
mbed_official 155:8435094ec241 263 SPI_SendData8(spi, (uint8_t)value);
mbed_official 155:8435094ec241 264 } else {
mbed_official 155:8435094ec241 265 SPI_I2S_SendData16(spi, (uint16_t)value);
mbed_official 155:8435094ec241 266 }
mbed_official 155:8435094ec241 267 }
mbed_official 155:8435094ec241 268
mbed_official 155:8435094ec241 269 int spi_busy(spi_t *obj) {
mbed_official 155:8435094ec241 270 return ssp_busy(obj);
mbed_official 155:8435094ec241 271 }
mbed_official 155:8435094ec241 272
mbed_official 155:8435094ec241 273 #endif