shinichi nakazawa / mbed-src

Dependents:   Nucleo_blink_led

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Tue Mar 24 09:00:08 2015 +0000
Revision:
496:543871686697
Parent:
targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/spi_api.c@414:4ec4c5b614b0
Synchronized with git revision ea01d61fa18430564b78226045b196bb6bf6b66a

Full URL: https://github.com/mbedmicro/mbed/commit/ea01d61fa18430564b78226045b196bb6bf6b66a/

NUCLEO_L152RE - reorg hal

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 76:aeb1df146756 1 /* mbed Microcontroller Library
mbed_official 76:aeb1df146756 2 *******************************************************************************
mbed_official 76:aeb1df146756 3 * Copyright (c) 2014, STMicroelectronics
mbed_official 76:aeb1df146756 4 * All rights reserved.
mbed_official 76:aeb1df146756 5 *
mbed_official 76:aeb1df146756 6 * Redistribution and use in source and binary forms, with or without
mbed_official 76:aeb1df146756 7 * modification, are permitted provided that the following conditions are met:
mbed_official 76:aeb1df146756 8 *
mbed_official 76:aeb1df146756 9 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 76:aeb1df146756 10 * this list of conditions and the following disclaimer.
mbed_official 76:aeb1df146756 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 76:aeb1df146756 12 * this list of conditions and the following disclaimer in the documentation
mbed_official 76:aeb1df146756 13 * and/or other materials provided with the distribution.
mbed_official 76:aeb1df146756 14 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 76:aeb1df146756 15 * may be used to endorse or promote products derived from this software
mbed_official 76:aeb1df146756 16 * without specific prior written permission.
mbed_official 76:aeb1df146756 17 *
mbed_official 76:aeb1df146756 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 76:aeb1df146756 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 76:aeb1df146756 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 76:aeb1df146756 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 76:aeb1df146756 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 76:aeb1df146756 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 76:aeb1df146756 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 76:aeb1df146756 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 76:aeb1df146756 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 76:aeb1df146756 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 76:aeb1df146756 28 *******************************************************************************
mbed_official 76:aeb1df146756 29 */
mbed_official 227:7bd0639b8911 30 #include "mbed_assert.h"
mbed_official 76:aeb1df146756 31 #include "spi_api.h"
mbed_official 76:aeb1df146756 32
mbed_official 76:aeb1df146756 33 #if DEVICE_SPI
mbed_official 76:aeb1df146756 34
mbed_official 76:aeb1df146756 35 #include <math.h>
mbed_official 76:aeb1df146756 36 #include "cmsis.h"
mbed_official 76:aeb1df146756 37 #include "pinmap.h"
mbed_official 414:4ec4c5b614b0 38 #include "PeripheralPins.h"
mbed_official 76:aeb1df146756 39
mbed_official 354:e67efb2aab0e 40 static SPI_HandleTypeDef SpiHandle;
mbed_official 76:aeb1df146756 41
mbed_official 354:e67efb2aab0e 42 static void init_spi(spi_t *obj)
mbed_official 354:e67efb2aab0e 43 {
mbed_official 354:e67efb2aab0e 44 SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
mbed_official 354:e67efb2aab0e 45
mbed_official 354:e67efb2aab0e 46 __HAL_SPI_DISABLE(&SpiHandle);
mbed_official 76:aeb1df146756 47
mbed_official 354:e67efb2aab0e 48 SpiHandle.Init.Mode = obj->mode;
mbed_official 354:e67efb2aab0e 49 SpiHandle.Init.BaudRatePrescaler = obj->br_presc;
mbed_official 354:e67efb2aab0e 50 SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
mbed_official 354:e67efb2aab0e 51 SpiHandle.Init.CLKPhase = obj->cpha;
mbed_official 354:e67efb2aab0e 52 SpiHandle.Init.CLKPolarity = obj->cpol;
mbed_official 354:e67efb2aab0e 53 SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
mbed_official 354:e67efb2aab0e 54 SpiHandle.Init.CRCPolynomial = 7;
mbed_official 354:e67efb2aab0e 55 SpiHandle.Init.DataSize = obj->bits;
mbed_official 354:e67efb2aab0e 56 SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
mbed_official 354:e67efb2aab0e 57 SpiHandle.Init.NSS = obj->nss;
mbed_official 354:e67efb2aab0e 58 SpiHandle.Init.TIMode = SPI_TIMODE_DISABLED;
mbed_official 76:aeb1df146756 59
mbed_official 354:e67efb2aab0e 60 HAL_SPI_Init(&SpiHandle);
mbed_official 354:e67efb2aab0e 61
mbed_official 354:e67efb2aab0e 62 __HAL_SPI_ENABLE(&SpiHandle);
mbed_official 76:aeb1df146756 63 }
mbed_official 76:aeb1df146756 64
mbed_official 354:e67efb2aab0e 65 void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
mbed_official 354:e67efb2aab0e 66 {
mbed_official 76:aeb1df146756 67 // Determine the SPI to use
mbed_official 76:aeb1df146756 68 SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
mbed_official 76:aeb1df146756 69 SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
mbed_official 76:aeb1df146756 70 SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK);
mbed_official 76:aeb1df146756 71 SPIName spi_ssel = (SPIName)pinmap_peripheral(ssel, PinMap_SPI_SSEL);
mbed_official 174:8bb9f3a33240 72
mbed_official 76:aeb1df146756 73 SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
mbed_official 76:aeb1df146756 74 SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
mbed_official 174:8bb9f3a33240 75
mbed_official 76:aeb1df146756 76 obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
mbed_official 227:7bd0639b8911 77 MBED_ASSERT(obj->spi != (SPIName)NC);
mbed_official 174:8bb9f3a33240 78
mbed_official 76:aeb1df146756 79 // Enable SPI clock
mbed_official 76:aeb1df146756 80 if (obj->spi == SPI_1) {
mbed_official 354:e67efb2aab0e 81 __SPI1_CLK_ENABLE();
mbed_official 76:aeb1df146756 82 }
mbed_official 76:aeb1df146756 83 if (obj->spi == SPI_2) {
mbed_official 354:e67efb2aab0e 84 __SPI2_CLK_ENABLE();
mbed_official 76:aeb1df146756 85 }
mbed_official 118:b44c45162f28 86 if (obj->spi == SPI_3) {
mbed_official 354:e67efb2aab0e 87 __SPI3_CLK_ENABLE();
mbed_official 118:b44c45162f28 88 }
mbed_official 174:8bb9f3a33240 89
mbed_official 76:aeb1df146756 90 // Configure the SPI pins
mbed_official 76:aeb1df146756 91 pinmap_pinout(mosi, PinMap_SPI_MOSI);
mbed_official 76:aeb1df146756 92 pinmap_pinout(miso, PinMap_SPI_MISO);
mbed_official 76:aeb1df146756 93 pinmap_pinout(sclk, PinMap_SPI_SCLK);
mbed_official 174:8bb9f3a33240 94
mbed_official 76:aeb1df146756 95 // Save new values
mbed_official 354:e67efb2aab0e 96 obj->bits = SPI_DATASIZE_8BIT;
mbed_official 354:e67efb2aab0e 97 obj->cpol = SPI_POLARITY_LOW;
mbed_official 354:e67efb2aab0e 98 obj->cpha = SPI_PHASE_1EDGE;
mbed_official 354:e67efb2aab0e 99 obj->br_presc = SPI_BAUDRATEPRESCALER_256;
mbed_official 174:8bb9f3a33240 100
mbed_official 215:83cf97a28428 101 obj->pin_miso = miso;
mbed_official 215:83cf97a28428 102 obj->pin_mosi = mosi;
mbed_official 215:83cf97a28428 103 obj->pin_sclk = sclk;
mbed_official 215:83cf97a28428 104 obj->pin_ssel = ssel;
mbed_official 215:83cf97a28428 105
mbed_official 354:e67efb2aab0e 106 if (ssel == NC) { // SW NSS Master mode
mbed_official 354:e67efb2aab0e 107 obj->mode = SPI_MODE_MASTER;
mbed_official 354:e67efb2aab0e 108 obj->nss = SPI_NSS_SOFT;
mbed_official 174:8bb9f3a33240 109 } else { // Slave
mbed_official 76:aeb1df146756 110 pinmap_pinout(ssel, PinMap_SPI_SSEL);
mbed_official 354:e67efb2aab0e 111 obj->mode = SPI_MODE_SLAVE;
mbed_official 354:e67efb2aab0e 112 obj->nss = SPI_NSS_HARD_INPUT;
mbed_official 76:aeb1df146756 113 }
mbed_official 76:aeb1df146756 114
mbed_official 76:aeb1df146756 115 init_spi(obj);
mbed_official 76:aeb1df146756 116 }
mbed_official 76:aeb1df146756 117
mbed_official 354:e67efb2aab0e 118 void spi_free(spi_t *obj)
mbed_official 354:e67efb2aab0e 119 {
mbed_official 215:83cf97a28428 120 // Reset SPI and disable clock
mbed_official 215:83cf97a28428 121 if (obj->spi == SPI_1) {
mbed_official 354:e67efb2aab0e 122 __SPI1_FORCE_RESET();
mbed_official 354:e67efb2aab0e 123 __SPI1_RELEASE_RESET();
mbed_official 354:e67efb2aab0e 124 __SPI1_CLK_DISABLE();
mbed_official 215:83cf97a28428 125 }
mbed_official 215:83cf97a28428 126
mbed_official 215:83cf97a28428 127 if (obj->spi == SPI_2) {
mbed_official 354:e67efb2aab0e 128 __SPI2_FORCE_RESET();
mbed_official 354:e67efb2aab0e 129 __SPI2_RELEASE_RESET();
mbed_official 354:e67efb2aab0e 130 __SPI2_CLK_DISABLE();
mbed_official 215:83cf97a28428 131 }
mbed_official 215:83cf97a28428 132
mbed_official 215:83cf97a28428 133 if (obj->spi == SPI_3) {
mbed_official 354:e67efb2aab0e 134 __SPI3_FORCE_RESET();
mbed_official 354:e67efb2aab0e 135 __SPI3_RELEASE_RESET();
mbed_official 354:e67efb2aab0e 136 __SPI3_CLK_DISABLE();
mbed_official 215:83cf97a28428 137 }
mbed_official 215:83cf97a28428 138
mbed_official 354:e67efb2aab0e 139 // Configure GPIO
mbed_official 354:e67efb2aab0e 140 pin_function(obj->pin_miso, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
mbed_official 354:e67efb2aab0e 141 pin_function(obj->pin_mosi, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
mbed_official 354:e67efb2aab0e 142 pin_function(obj->pin_sclk, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
mbed_official 354:e67efb2aab0e 143 pin_function(obj->pin_ssel, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
mbed_official 76:aeb1df146756 144 }
mbed_official 76:aeb1df146756 145
mbed_official 354:e67efb2aab0e 146 void spi_format(spi_t *obj, int bits, int mode, int slave)
mbed_official 354:e67efb2aab0e 147 {
mbed_official 76:aeb1df146756 148 // Save new values
mbed_official 233:1bbc1451db33 149 if (bits == 16) {
mbed_official 354:e67efb2aab0e 150 obj->bits = SPI_DATASIZE_16BIT;
mbed_official 233:1bbc1451db33 151 } else {
mbed_official 354:e67efb2aab0e 152 obj->bits = SPI_DATASIZE_8BIT;
mbed_official 76:aeb1df146756 153 }
mbed_official 174:8bb9f3a33240 154
mbed_official 76:aeb1df146756 155 switch (mode) {
mbed_official 76:aeb1df146756 156 case 0:
mbed_official 354:e67efb2aab0e 157 obj->cpol = SPI_POLARITY_LOW;
mbed_official 354:e67efb2aab0e 158 obj->cpha = SPI_PHASE_1EDGE;
mbed_official 174:8bb9f3a33240 159 break;
mbed_official 76:aeb1df146756 160 case 1:
mbed_official 354:e67efb2aab0e 161 obj->cpol = SPI_POLARITY_LOW;
mbed_official 354:e67efb2aab0e 162 obj->cpha = SPI_PHASE_2EDGE;
mbed_official 174:8bb9f3a33240 163 break;
mbed_official 76:aeb1df146756 164 case 2:
mbed_official 354:e67efb2aab0e 165 obj->cpol = SPI_POLARITY_HIGH;
mbed_official 354:e67efb2aab0e 166 obj->cpha = SPI_PHASE_1EDGE;
mbed_official 174:8bb9f3a33240 167 break;
mbed_official 76:aeb1df146756 168 default:
mbed_official 354:e67efb2aab0e 169 obj->cpol = SPI_POLARITY_HIGH;
mbed_official 354:e67efb2aab0e 170 obj->cpha = SPI_PHASE_2EDGE;
mbed_official 174:8bb9f3a33240 171 break;
mbed_official 76:aeb1df146756 172 }
mbed_official 174:8bb9f3a33240 173
mbed_official 76:aeb1df146756 174 if (slave == 0) {
mbed_official 354:e67efb2aab0e 175 obj->mode = SPI_MODE_MASTER;
mbed_official 354:e67efb2aab0e 176 obj->nss = SPI_NSS_SOFT;
mbed_official 174:8bb9f3a33240 177 } else {
mbed_official 354:e67efb2aab0e 178 obj->mode = SPI_MODE_SLAVE;
mbed_official 354:e67efb2aab0e 179 obj->nss = SPI_NSS_HARD_INPUT;
mbed_official 76:aeb1df146756 180 }
mbed_official 174:8bb9f3a33240 181
mbed_official 76:aeb1df146756 182 init_spi(obj);
mbed_official 76:aeb1df146756 183 }
mbed_official 76:aeb1df146756 184
mbed_official 354:e67efb2aab0e 185 void spi_frequency(spi_t *obj, int hz)
mbed_official 354:e67efb2aab0e 186 {
mbed_official 139:e3413eddde57 187 // Values depend of PCLK1 and PCLK2: 32 MHz if HSI is used, 24 MHz if HSE is used
mbed_official 139:e3413eddde57 188 if (SystemCoreClock == 32000000) { // HSI
mbed_official 139:e3413eddde57 189 if (hz < 250000) {
mbed_official 354:e67efb2aab0e 190 obj->br_presc = SPI_BAUDRATEPRESCALER_256; // 125 kHz
mbed_official 174:8bb9f3a33240 191 } else if ((hz >= 250000) && (hz < 500000)) {
mbed_official 354:e67efb2aab0e 192 obj->br_presc = SPI_BAUDRATEPRESCALER_128; // 250 kHz
mbed_official 174:8bb9f3a33240 193 } else if ((hz >= 500000) && (hz < 1000000)) {
mbed_official 354:e67efb2aab0e 194 obj->br_presc = SPI_BAUDRATEPRESCALER_64; // 500 kHz
mbed_official 174:8bb9f3a33240 195 } else if ((hz >= 1000000) && (hz < 2000000)) {
mbed_official 354:e67efb2aab0e 196 obj->br_presc = SPI_BAUDRATEPRESCALER_32; // 1 MHz
mbed_official 174:8bb9f3a33240 197 } else if ((hz >= 2000000) && (hz < 4000000)) {
mbed_official 354:e67efb2aab0e 198 obj->br_presc = SPI_BAUDRATEPRESCALER_16; // 2 MHz
mbed_official 174:8bb9f3a33240 199 } else if ((hz >= 4000000) && (hz < 8000000)) {
mbed_official 354:e67efb2aab0e 200 obj->br_presc = SPI_BAUDRATEPRESCALER_8; // 4 MHz
mbed_official 174:8bb9f3a33240 201 } else if ((hz >= 8000000) && (hz < 16000000)) {
mbed_official 354:e67efb2aab0e 202 obj->br_presc = SPI_BAUDRATEPRESCALER_4; // 8 MHz
mbed_official 174:8bb9f3a33240 203 } else { // >= 16000000
mbed_official 354:e67efb2aab0e 204 obj->br_presc = SPI_BAUDRATEPRESCALER_2; // 16 MHz
mbed_official 139:e3413eddde57 205 }
mbed_official 174:8bb9f3a33240 206 } else { // 24 MHz - HSE
mbed_official 139:e3413eddde57 207 if (hz < 180000) {
mbed_official 354:e67efb2aab0e 208 obj->br_presc = SPI_BAUDRATEPRESCALER_256; // 94 kHz
mbed_official 174:8bb9f3a33240 209 } else if ((hz >= 180000) && (hz < 350000)) {
mbed_official 354:e67efb2aab0e 210 obj->br_presc = SPI_BAUDRATEPRESCALER_128; // 188 kHz
mbed_official 174:8bb9f3a33240 211 } else if ((hz >= 350000) && (hz < 750000)) {
mbed_official 354:e67efb2aab0e 212 obj->br_presc = SPI_BAUDRATEPRESCALER_64; // 375 kHz
mbed_official 174:8bb9f3a33240 213 } else if ((hz >= 750000) && (hz < 1000000)) {
mbed_official 354:e67efb2aab0e 214 obj->br_presc = SPI_BAUDRATEPRESCALER_32; // 750 kHz
mbed_official 174:8bb9f3a33240 215 } else if ((hz >= 1000000) && (hz < 3000000)) {
mbed_official 354:e67efb2aab0e 216 obj->br_presc = SPI_BAUDRATEPRESCALER_16; // 1.5 MHz
mbed_official 174:8bb9f3a33240 217 } else if ((hz >= 3000000) && (hz < 6000000)) {
mbed_official 354:e67efb2aab0e 218 obj->br_presc = SPI_BAUDRATEPRESCALER_8; // 3 MHz
mbed_official 174:8bb9f3a33240 219 } else if ((hz >= 6000000) && (hz < 12000000)) {
mbed_official 354:e67efb2aab0e 220 obj->br_presc = SPI_BAUDRATEPRESCALER_4; // 6 MHz
mbed_official 174:8bb9f3a33240 221 } else { // >= 12000000
mbed_official 354:e67efb2aab0e 222 obj->br_presc = SPI_BAUDRATEPRESCALER_2; // 12 MHz
mbed_official 139:e3413eddde57 223 }
mbed_official 129:0182c99221bc 224 }
mbed_official 76:aeb1df146756 225 init_spi(obj);
mbed_official 76:aeb1df146756 226 }
mbed_official 76:aeb1df146756 227
mbed_official 354:e67efb2aab0e 228 static inline int ssp_readable(spi_t *obj)
mbed_official 354:e67efb2aab0e 229 {
mbed_official 76:aeb1df146756 230 int status;
mbed_official 354:e67efb2aab0e 231 SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
mbed_official 76:aeb1df146756 232 // Check if data is received
mbed_official 354:e67efb2aab0e 233 status = ((__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_RXNE) != RESET) ? 1 : 0);
mbed_official 174:8bb9f3a33240 234 return status;
mbed_official 76:aeb1df146756 235 }
mbed_official 76:aeb1df146756 236
mbed_official 354:e67efb2aab0e 237 static inline int ssp_writeable(spi_t *obj)
mbed_official 354:e67efb2aab0e 238 {
mbed_official 76:aeb1df146756 239 int status;
mbed_official 354:e67efb2aab0e 240 SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
mbed_official 76:aeb1df146756 241 // Check if data is transmitted
mbed_official 354:e67efb2aab0e 242 status = ((__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_TXE) != RESET) ? 1 : 0);
mbed_official 76:aeb1df146756 243 return status;
mbed_official 76:aeb1df146756 244 }
mbed_official 76:aeb1df146756 245
mbed_official 354:e67efb2aab0e 246 static inline void ssp_write(spi_t *obj, int value)
mbed_official 354:e67efb2aab0e 247 {
mbed_official 174:8bb9f3a33240 248 SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
mbed_official 76:aeb1df146756 249 while (!ssp_writeable(obj));
mbed_official 354:e67efb2aab0e 250 spi->DR = (uint16_t)value;
mbed_official 76:aeb1df146756 251 }
mbed_official 76:aeb1df146756 252
mbed_official 354:e67efb2aab0e 253 static inline int ssp_read(spi_t *obj)
mbed_official 354:e67efb2aab0e 254 {
mbed_official 174:8bb9f3a33240 255 SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
mbed_official 76:aeb1df146756 256 while (!ssp_readable(obj));
mbed_official 354:e67efb2aab0e 257 return (int)spi->DR;
mbed_official 76:aeb1df146756 258 }
mbed_official 76:aeb1df146756 259
mbed_official 354:e67efb2aab0e 260 static inline int ssp_busy(spi_t *obj)
mbed_official 354:e67efb2aab0e 261 {
mbed_official 76:aeb1df146756 262 int status;
mbed_official 354:e67efb2aab0e 263 SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
mbed_official 354:e67efb2aab0e 264 status = ((__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_BSY) != RESET) ? 1 : 0);
mbed_official 76:aeb1df146756 265 return status;
mbed_official 76:aeb1df146756 266 }
mbed_official 76:aeb1df146756 267
mbed_official 354:e67efb2aab0e 268 int spi_master_write(spi_t *obj, int value)
mbed_official 354:e67efb2aab0e 269 {
mbed_official 76:aeb1df146756 270 ssp_write(obj, value);
mbed_official 76:aeb1df146756 271 return ssp_read(obj);
mbed_official 76:aeb1df146756 272 }
mbed_official 76:aeb1df146756 273
mbed_official 354:e67efb2aab0e 274 int spi_slave_receive(spi_t *obj)
mbed_official 354:e67efb2aab0e 275 {
mbed_official 233:1bbc1451db33 276 return (ssp_readable(obj) ? 1 : 0);
mbed_official 76:aeb1df146756 277 };
mbed_official 76:aeb1df146756 278
mbed_official 354:e67efb2aab0e 279 int spi_slave_read(spi_t *obj)
mbed_official 354:e67efb2aab0e 280 {
mbed_official 76:aeb1df146756 281 SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
mbed_official 354:e67efb2aab0e 282 while (!ssp_readable(obj));
mbed_official 354:e67efb2aab0e 283 return (int)spi->DR;
mbed_official 76:aeb1df146756 284 }
mbed_official 76:aeb1df146756 285
mbed_official 354:e67efb2aab0e 286 void spi_slave_write(spi_t *obj, int value)
mbed_official 354:e67efb2aab0e 287 {
mbed_official 174:8bb9f3a33240 288 SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
mbed_official 174:8bb9f3a33240 289 while (!ssp_writeable(obj));
mbed_official 354:e67efb2aab0e 290 spi->DR = (uint16_t)value;
mbed_official 76:aeb1df146756 291 }
mbed_official 76:aeb1df146756 292
mbed_official 354:e67efb2aab0e 293 int spi_busy(spi_t *obj)
mbed_official 354:e67efb2aab0e 294 {
mbed_official 76:aeb1df146756 295 return ssp_busy(obj);
mbed_official 76:aeb1df146756 296 }
mbed_official 76:aeb1df146756 297
mbed_official 76:aeb1df146756 298 #endif