takashi kadono
/
Nucleo446_SSD1331
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/drivers/SPI.h@3:f3764f852aa8, 2018-10-11 (annotated)
- Committer:
- kadonotakashi
- Date:
- Thu Oct 11 02:27:46 2018 +0000
- Revision:
- 3:f3764f852aa8
- Parent:
- 0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | /* mbed Microcontroller Library |
kadonotakashi | 0:8fdf9a60065b | 2 | * Copyright (c) 2006-2015 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 3 | * |
kadonotakashi | 0:8fdf9a60065b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 5 | * you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 6 | * You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 7 | * |
kadonotakashi | 0:8fdf9a60065b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 9 | * |
kadonotakashi | 0:8fdf9a60065b | 10 | * Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 13 | * See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 14 | * limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 15 | */ |
kadonotakashi | 0:8fdf9a60065b | 16 | #ifndef MBED_SPI_H |
kadonotakashi | 0:8fdf9a60065b | 17 | #define MBED_SPI_H |
kadonotakashi | 0:8fdf9a60065b | 18 | |
kadonotakashi | 0:8fdf9a60065b | 19 | #include "platform/platform.h" |
kadonotakashi | 0:8fdf9a60065b | 20 | |
kadonotakashi | 0:8fdf9a60065b | 21 | #if defined (DEVICE_SPI) || defined(DOXYGEN_ONLY) |
kadonotakashi | 0:8fdf9a60065b | 22 | |
kadonotakashi | 0:8fdf9a60065b | 23 | #include "platform/PlatformMutex.h" |
kadonotakashi | 0:8fdf9a60065b | 24 | #include "hal/spi_api.h" |
kadonotakashi | 0:8fdf9a60065b | 25 | #include "platform/SingletonPtr.h" |
kadonotakashi | 0:8fdf9a60065b | 26 | #include "platform/NonCopyable.h" |
kadonotakashi | 0:8fdf9a60065b | 27 | |
kadonotakashi | 0:8fdf9a60065b | 28 | #if DEVICE_SPI_ASYNCH |
kadonotakashi | 0:8fdf9a60065b | 29 | #include "platform/CThunk.h" |
kadonotakashi | 0:8fdf9a60065b | 30 | #include "hal/dma_api.h" |
kadonotakashi | 0:8fdf9a60065b | 31 | #include "platform/CircularBuffer.h" |
kadonotakashi | 0:8fdf9a60065b | 32 | #include "platform/FunctionPointer.h" |
kadonotakashi | 0:8fdf9a60065b | 33 | #include "platform/Transaction.h" |
kadonotakashi | 0:8fdf9a60065b | 34 | #endif |
kadonotakashi | 0:8fdf9a60065b | 35 | |
kadonotakashi | 0:8fdf9a60065b | 36 | namespace mbed { |
kadonotakashi | 0:8fdf9a60065b | 37 | /** \addtogroup drivers */ |
kadonotakashi | 0:8fdf9a60065b | 38 | |
kadonotakashi | 0:8fdf9a60065b | 39 | /** A SPI Master, used for communicating with SPI slave devices |
kadonotakashi | 0:8fdf9a60065b | 40 | * |
kadonotakashi | 0:8fdf9a60065b | 41 | * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz |
kadonotakashi | 0:8fdf9a60065b | 42 | * |
kadonotakashi | 0:8fdf9a60065b | 43 | * Most SPI devices will also require Chip Select and Reset signals. These |
kadonotakashi | 0:8fdf9a60065b | 44 | * can be controlled using DigitalOut pins |
kadonotakashi | 0:8fdf9a60065b | 45 | * |
kadonotakashi | 0:8fdf9a60065b | 46 | * @note Synchronization level: Thread safe |
kadonotakashi | 0:8fdf9a60065b | 47 | * |
kadonotakashi | 0:8fdf9a60065b | 48 | * Example: |
kadonotakashi | 0:8fdf9a60065b | 49 | * @code |
kadonotakashi | 0:8fdf9a60065b | 50 | * // Send a byte to a SPI slave, and record the response |
kadonotakashi | 0:8fdf9a60065b | 51 | * |
kadonotakashi | 0:8fdf9a60065b | 52 | * #include "mbed.h" |
kadonotakashi | 0:8fdf9a60065b | 53 | * |
kadonotakashi | 0:8fdf9a60065b | 54 | * // hardware ssel (where applicable) |
kadonotakashi | 0:8fdf9a60065b | 55 | * //SPI device(p5, p6, p7, p8); // mosi, miso, sclk, ssel |
kadonotakashi | 0:8fdf9a60065b | 56 | * |
kadonotakashi | 0:8fdf9a60065b | 57 | * // software ssel |
kadonotakashi | 0:8fdf9a60065b | 58 | * SPI device(p5, p6, p7); // mosi, miso, sclk |
kadonotakashi | 0:8fdf9a60065b | 59 | * DigitalOut cs(p8); // ssel |
kadonotakashi | 0:8fdf9a60065b | 60 | * |
kadonotakashi | 0:8fdf9a60065b | 61 | * int main() { |
kadonotakashi | 0:8fdf9a60065b | 62 | * // hardware ssel (where applicable) |
kadonotakashi | 0:8fdf9a60065b | 63 | * //int response = device.write(0xFF); |
kadonotakashi | 0:8fdf9a60065b | 64 | * |
kadonotakashi | 0:8fdf9a60065b | 65 | * device.lock(); |
kadonotakashi | 0:8fdf9a60065b | 66 | * // software ssel |
kadonotakashi | 0:8fdf9a60065b | 67 | * cs = 0; |
kadonotakashi | 0:8fdf9a60065b | 68 | * int response = device.write(0xFF); |
kadonotakashi | 0:8fdf9a60065b | 69 | * cs = 1; |
kadonotakashi | 0:8fdf9a60065b | 70 | * device.unlock(); |
kadonotakashi | 0:8fdf9a60065b | 71 | * |
kadonotakashi | 0:8fdf9a60065b | 72 | * } |
kadonotakashi | 0:8fdf9a60065b | 73 | * @endcode |
kadonotakashi | 0:8fdf9a60065b | 74 | * @ingroup drivers |
kadonotakashi | 0:8fdf9a60065b | 75 | */ |
kadonotakashi | 0:8fdf9a60065b | 76 | class SPI : private NonCopyable<SPI> { |
kadonotakashi | 0:8fdf9a60065b | 77 | |
kadonotakashi | 0:8fdf9a60065b | 78 | public: |
kadonotakashi | 0:8fdf9a60065b | 79 | |
kadonotakashi | 0:8fdf9a60065b | 80 | /** Create a SPI master connected to the specified pins |
kadonotakashi | 0:8fdf9a60065b | 81 | * |
kadonotakashi | 0:8fdf9a60065b | 82 | * mosi or miso can be specified as NC if not used |
kadonotakashi | 0:8fdf9a60065b | 83 | * |
kadonotakashi | 0:8fdf9a60065b | 84 | * @param mosi SPI Master Out, Slave In pin |
kadonotakashi | 0:8fdf9a60065b | 85 | * @param miso SPI Master In, Slave Out pin |
kadonotakashi | 0:8fdf9a60065b | 86 | * @param sclk SPI Clock pin |
kadonotakashi | 0:8fdf9a60065b | 87 | * @param ssel SPI chip select pin |
kadonotakashi | 0:8fdf9a60065b | 88 | */ |
kadonotakashi | 0:8fdf9a60065b | 89 | SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel = NC); |
kadonotakashi | 0:8fdf9a60065b | 90 | virtual ~SPI(); |
kadonotakashi | 0:8fdf9a60065b | 91 | |
kadonotakashi | 0:8fdf9a60065b | 92 | /** Configure the data transmission format |
kadonotakashi | 0:8fdf9a60065b | 93 | * |
kadonotakashi | 0:8fdf9a60065b | 94 | * @param bits Number of bits per SPI frame (4 - 16) |
kadonotakashi | 0:8fdf9a60065b | 95 | * @param mode Clock polarity and phase mode (0 - 3) |
kadonotakashi | 0:8fdf9a60065b | 96 | * |
kadonotakashi | 0:8fdf9a60065b | 97 | * @code |
kadonotakashi | 0:8fdf9a60065b | 98 | * mode | POL PHA |
kadonotakashi | 0:8fdf9a60065b | 99 | * -----+-------- |
kadonotakashi | 0:8fdf9a60065b | 100 | * 0 | 0 0 |
kadonotakashi | 0:8fdf9a60065b | 101 | * 1 | 0 1 |
kadonotakashi | 0:8fdf9a60065b | 102 | * 2 | 1 0 |
kadonotakashi | 0:8fdf9a60065b | 103 | * 3 | 1 1 |
kadonotakashi | 0:8fdf9a60065b | 104 | * @endcode |
kadonotakashi | 0:8fdf9a60065b | 105 | */ |
kadonotakashi | 0:8fdf9a60065b | 106 | void format(int bits, int mode = 0); |
kadonotakashi | 0:8fdf9a60065b | 107 | |
kadonotakashi | 0:8fdf9a60065b | 108 | /** Set the spi bus clock frequency |
kadonotakashi | 0:8fdf9a60065b | 109 | * |
kadonotakashi | 0:8fdf9a60065b | 110 | * @param hz SCLK frequency in hz (default = 1MHz) |
kadonotakashi | 0:8fdf9a60065b | 111 | */ |
kadonotakashi | 0:8fdf9a60065b | 112 | void frequency(int hz = 1000000); |
kadonotakashi | 0:8fdf9a60065b | 113 | |
kadonotakashi | 0:8fdf9a60065b | 114 | /** Write to the SPI Slave and return the response |
kadonotakashi | 0:8fdf9a60065b | 115 | * |
kadonotakashi | 0:8fdf9a60065b | 116 | * @param value Data to be sent to the SPI slave |
kadonotakashi | 0:8fdf9a60065b | 117 | * |
kadonotakashi | 0:8fdf9a60065b | 118 | * @returns |
kadonotakashi | 0:8fdf9a60065b | 119 | * Response from the SPI slave |
kadonotakashi | 0:8fdf9a60065b | 120 | */ |
kadonotakashi | 0:8fdf9a60065b | 121 | virtual int write(int value); |
kadonotakashi | 0:8fdf9a60065b | 122 | |
kadonotakashi | 0:8fdf9a60065b | 123 | /** Write to the SPI Slave and obtain the response |
kadonotakashi | 0:8fdf9a60065b | 124 | * |
kadonotakashi | 0:8fdf9a60065b | 125 | * The total number of bytes sent and received will be the maximum of |
kadonotakashi | 0:8fdf9a60065b | 126 | * tx_length and rx_length. The bytes written will be padded with the |
kadonotakashi | 0:8fdf9a60065b | 127 | * value 0xff. |
kadonotakashi | 0:8fdf9a60065b | 128 | * |
kadonotakashi | 0:8fdf9a60065b | 129 | * @param tx_buffer Pointer to the byte-array of data to write to the device |
kadonotakashi | 0:8fdf9a60065b | 130 | * @param tx_length Number of bytes to write, may be zero |
kadonotakashi | 0:8fdf9a60065b | 131 | * @param rx_buffer Pointer to the byte-array of data to read from the device |
kadonotakashi | 0:8fdf9a60065b | 132 | * @param rx_length Number of bytes to read, may be zero |
kadonotakashi | 0:8fdf9a60065b | 133 | * @returns |
kadonotakashi | 0:8fdf9a60065b | 134 | * The number of bytes written and read from the device. This is |
kadonotakashi | 0:8fdf9a60065b | 135 | * maximum of tx_length and rx_length. |
kadonotakashi | 0:8fdf9a60065b | 136 | */ |
kadonotakashi | 0:8fdf9a60065b | 137 | virtual int write(const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length); |
kadonotakashi | 0:8fdf9a60065b | 138 | |
kadonotakashi | 0:8fdf9a60065b | 139 | /** Acquire exclusive access to this SPI bus |
kadonotakashi | 0:8fdf9a60065b | 140 | */ |
kadonotakashi | 0:8fdf9a60065b | 141 | virtual void lock(void); |
kadonotakashi | 0:8fdf9a60065b | 142 | |
kadonotakashi | 0:8fdf9a60065b | 143 | /** Release exclusive access to this SPI bus |
kadonotakashi | 0:8fdf9a60065b | 144 | */ |
kadonotakashi | 0:8fdf9a60065b | 145 | virtual void unlock(void); |
kadonotakashi | 0:8fdf9a60065b | 146 | |
kadonotakashi | 0:8fdf9a60065b | 147 | /** Set default write data |
kadonotakashi | 0:8fdf9a60065b | 148 | * SPI requires the master to send some data during a read operation. |
kadonotakashi | 0:8fdf9a60065b | 149 | * Different devices may require different default byte values. |
kadonotakashi | 0:8fdf9a60065b | 150 | * For example: A SD Card requires default bytes to be 0xFF. |
kadonotakashi | 0:8fdf9a60065b | 151 | * |
kadonotakashi | 0:8fdf9a60065b | 152 | * @param data Default character to be transmitted while read operation |
kadonotakashi | 0:8fdf9a60065b | 153 | */ |
kadonotakashi | 0:8fdf9a60065b | 154 | void set_default_write_value(char data); |
kadonotakashi | 0:8fdf9a60065b | 155 | |
kadonotakashi | 0:8fdf9a60065b | 156 | #if DEVICE_SPI_ASYNCH |
kadonotakashi | 0:8fdf9a60065b | 157 | |
kadonotakashi | 0:8fdf9a60065b | 158 | /** Start non-blocking SPI transfer using 8bit buffers. |
kadonotakashi | 0:8fdf9a60065b | 159 | * |
kadonotakashi | 0:8fdf9a60065b | 160 | * This function locks the deep sleep until any event has occurred |
kadonotakashi | 0:8fdf9a60065b | 161 | * |
kadonotakashi | 0:8fdf9a60065b | 162 | * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed, |
kadonotakashi | 0:8fdf9a60065b | 163 | * the default SPI value is sent |
kadonotakashi | 0:8fdf9a60065b | 164 | * @param tx_length The length of TX buffer in bytes |
kadonotakashi | 0:8fdf9a60065b | 165 | * @param rx_buffer The RX buffer which is used for received data. If NULL is passed, |
kadonotakashi | 0:8fdf9a60065b | 166 | * received data are ignored |
kadonotakashi | 0:8fdf9a60065b | 167 | * @param rx_length The length of RX buffer in bytes |
kadonotakashi | 0:8fdf9a60065b | 168 | * @param callback The event callback function |
kadonotakashi | 0:8fdf9a60065b | 169 | * @param event The logical OR of events to modify. Look at spi hal header file for SPI events. |
kadonotakashi | 0:8fdf9a60065b | 170 | * @return Zero if the transfer has started, or -1 if SPI peripheral is busy |
kadonotakashi | 0:8fdf9a60065b | 171 | */ |
kadonotakashi | 0:8fdf9a60065b | 172 | template<typename Type> |
kadonotakashi | 0:8fdf9a60065b | 173 | int transfer(const Type *tx_buffer, int tx_length, Type *rx_buffer, int rx_length, const event_callback_t &callback, int event = SPI_EVENT_COMPLETE) |
kadonotakashi | 0:8fdf9a60065b | 174 | { |
kadonotakashi | 0:8fdf9a60065b | 175 | if (spi_active(&_spi)) { |
kadonotakashi | 0:8fdf9a60065b | 176 | return queue_transfer(tx_buffer, tx_length, rx_buffer, rx_length, sizeof(Type) * 8, callback, event); |
kadonotakashi | 0:8fdf9a60065b | 177 | } |
kadonotakashi | 0:8fdf9a60065b | 178 | start_transfer(tx_buffer, tx_length, rx_buffer, rx_length, sizeof(Type) * 8, callback, event); |
kadonotakashi | 0:8fdf9a60065b | 179 | return 0; |
kadonotakashi | 0:8fdf9a60065b | 180 | } |
kadonotakashi | 0:8fdf9a60065b | 181 | |
kadonotakashi | 0:8fdf9a60065b | 182 | /** Abort the on-going SPI transfer, and continue with transfer's in the queue if any. |
kadonotakashi | 0:8fdf9a60065b | 183 | */ |
kadonotakashi | 0:8fdf9a60065b | 184 | void abort_transfer(); |
kadonotakashi | 0:8fdf9a60065b | 185 | |
kadonotakashi | 0:8fdf9a60065b | 186 | /** Clear the transaction buffer |
kadonotakashi | 0:8fdf9a60065b | 187 | */ |
kadonotakashi | 0:8fdf9a60065b | 188 | void clear_transfer_buffer(); |
kadonotakashi | 0:8fdf9a60065b | 189 | |
kadonotakashi | 0:8fdf9a60065b | 190 | /** Clear the transaction buffer and abort on-going transfer. |
kadonotakashi | 0:8fdf9a60065b | 191 | */ |
kadonotakashi | 0:8fdf9a60065b | 192 | void abort_all_transfers(); |
kadonotakashi | 0:8fdf9a60065b | 193 | |
kadonotakashi | 0:8fdf9a60065b | 194 | /** Configure DMA usage suggestion for non-blocking transfers |
kadonotakashi | 0:8fdf9a60065b | 195 | * |
kadonotakashi | 0:8fdf9a60065b | 196 | * @param usage The usage DMA hint for peripheral |
kadonotakashi | 0:8fdf9a60065b | 197 | * @return Zero if the usage was set, -1 if a transaction is on-going |
kadonotakashi | 0:8fdf9a60065b | 198 | */ |
kadonotakashi | 0:8fdf9a60065b | 199 | int set_dma_usage(DMAUsage usage); |
kadonotakashi | 0:8fdf9a60065b | 200 | |
kadonotakashi | 0:8fdf9a60065b | 201 | protected: |
kadonotakashi | 0:8fdf9a60065b | 202 | /** SPI IRQ handler |
kadonotakashi | 0:8fdf9a60065b | 203 | * |
kadonotakashi | 0:8fdf9a60065b | 204 | */ |
kadonotakashi | 0:8fdf9a60065b | 205 | void irq_handler_asynch(void); |
kadonotakashi | 0:8fdf9a60065b | 206 | |
kadonotakashi | 0:8fdf9a60065b | 207 | /** Common transfer method |
kadonotakashi | 0:8fdf9a60065b | 208 | * |
kadonotakashi | 0:8fdf9a60065b | 209 | * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed, |
kadonotakashi | 0:8fdf9a60065b | 210 | * the default SPI value is sent |
kadonotakashi | 0:8fdf9a60065b | 211 | * @param tx_length The length of TX buffer in bytes |
kadonotakashi | 0:8fdf9a60065b | 212 | * @param rx_buffer The RX buffer which is used for received data. If NULL is passed, |
kadonotakashi | 0:8fdf9a60065b | 213 | * received data are ignored |
kadonotakashi | 0:8fdf9a60065b | 214 | * @param rx_length The length of RX buffer in bytes |
kadonotakashi | 0:8fdf9a60065b | 215 | * @param bit_width The buffers element width |
kadonotakashi | 0:8fdf9a60065b | 216 | * @param callback The event callback function |
kadonotakashi | 0:8fdf9a60065b | 217 | * @param event The logical OR of events to modify |
kadonotakashi | 0:8fdf9a60065b | 218 | * @return Zero if the transfer has started or was added to the queue, or -1 if SPI peripheral is busy/buffer is full |
kadonotakashi | 0:8fdf9a60065b | 219 | */ |
kadonotakashi | 0:8fdf9a60065b | 220 | int transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t &callback, int event); |
kadonotakashi | 0:8fdf9a60065b | 221 | |
kadonotakashi | 0:8fdf9a60065b | 222 | /** |
kadonotakashi | 0:8fdf9a60065b | 223 | * |
kadonotakashi | 0:8fdf9a60065b | 224 | * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed, |
kadonotakashi | 0:8fdf9a60065b | 225 | * the default SPI value is sent |
kadonotakashi | 0:8fdf9a60065b | 226 | * @param tx_length The length of TX buffer in bytes |
kadonotakashi | 0:8fdf9a60065b | 227 | * @param rx_buffer The RX buffer which is used for received data. If NULL is passed, |
kadonotakashi | 0:8fdf9a60065b | 228 | * received data are ignored |
kadonotakashi | 0:8fdf9a60065b | 229 | * @param rx_length The length of RX buffer in bytes |
kadonotakashi | 0:8fdf9a60065b | 230 | * @param bit_width The buffers element width |
kadonotakashi | 0:8fdf9a60065b | 231 | * @param callback The event callback function |
kadonotakashi | 0:8fdf9a60065b | 232 | * @param event The logical OR of events to modify |
kadonotakashi | 0:8fdf9a60065b | 233 | * @return Zero if a transfer was added to the queue, or -1 if the queue is full |
kadonotakashi | 0:8fdf9a60065b | 234 | */ |
kadonotakashi | 0:8fdf9a60065b | 235 | int queue_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t &callback, int event); |
kadonotakashi | 0:8fdf9a60065b | 236 | |
kadonotakashi | 0:8fdf9a60065b | 237 | /** Configures a callback, spi peripheral and initiate a new transfer |
kadonotakashi | 0:8fdf9a60065b | 238 | * |
kadonotakashi | 0:8fdf9a60065b | 239 | * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed, |
kadonotakashi | 0:8fdf9a60065b | 240 | * the default SPI value is sent |
kadonotakashi | 0:8fdf9a60065b | 241 | * @param tx_length The length of TX buffer in bytes |
kadonotakashi | 0:8fdf9a60065b | 242 | * @param rx_buffer The RX buffer which is used for received data. If NULL is passed, |
kadonotakashi | 0:8fdf9a60065b | 243 | * received data are ignored |
kadonotakashi | 0:8fdf9a60065b | 244 | * @param rx_length The length of RX buffer in bytes |
kadonotakashi | 0:8fdf9a60065b | 245 | * @param bit_width The buffers element width |
kadonotakashi | 0:8fdf9a60065b | 246 | * @param callback The event callback function |
kadonotakashi | 0:8fdf9a60065b | 247 | * @param event The logical OR of events to modify |
kadonotakashi | 0:8fdf9a60065b | 248 | */ |
kadonotakashi | 0:8fdf9a60065b | 249 | void start_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t &callback, int event); |
kadonotakashi | 0:8fdf9a60065b | 250 | |
kadonotakashi | 0:8fdf9a60065b | 251 | private: |
kadonotakashi | 0:8fdf9a60065b | 252 | /** Lock deep sleep only if it is not yet locked */ |
kadonotakashi | 0:8fdf9a60065b | 253 | void lock_deep_sleep(); |
kadonotakashi | 0:8fdf9a60065b | 254 | |
kadonotakashi | 0:8fdf9a60065b | 255 | /** Unlock deep sleep in case it is locked */ |
kadonotakashi | 0:8fdf9a60065b | 256 | void unlock_deep_sleep(); |
kadonotakashi | 0:8fdf9a60065b | 257 | |
kadonotakashi | 0:8fdf9a60065b | 258 | |
kadonotakashi | 0:8fdf9a60065b | 259 | #if TRANSACTION_QUEUE_SIZE_SPI |
kadonotakashi | 0:8fdf9a60065b | 260 | |
kadonotakashi | 0:8fdf9a60065b | 261 | /** Start a new transaction |
kadonotakashi | 0:8fdf9a60065b | 262 | * |
kadonotakashi | 0:8fdf9a60065b | 263 | * @param data Transaction data |
kadonotakashi | 0:8fdf9a60065b | 264 | */ |
kadonotakashi | 0:8fdf9a60065b | 265 | void start_transaction(transaction_t *data); |
kadonotakashi | 0:8fdf9a60065b | 266 | |
kadonotakashi | 0:8fdf9a60065b | 267 | /** Dequeue a transaction |
kadonotakashi | 0:8fdf9a60065b | 268 | * |
kadonotakashi | 0:8fdf9a60065b | 269 | */ |
kadonotakashi | 0:8fdf9a60065b | 270 | void dequeue_transaction(); |
kadonotakashi | 0:8fdf9a60065b | 271 | static CircularBuffer<Transaction<SPI>, TRANSACTION_QUEUE_SIZE_SPI> _transaction_buffer; |
kadonotakashi | 0:8fdf9a60065b | 272 | #endif |
kadonotakashi | 0:8fdf9a60065b | 273 | |
kadonotakashi | 0:8fdf9a60065b | 274 | #endif |
kadonotakashi | 0:8fdf9a60065b | 275 | |
kadonotakashi | 0:8fdf9a60065b | 276 | protected: |
kadonotakashi | 0:8fdf9a60065b | 277 | spi_t _spi; |
kadonotakashi | 0:8fdf9a60065b | 278 | |
kadonotakashi | 0:8fdf9a60065b | 279 | #if DEVICE_SPI_ASYNCH |
kadonotakashi | 0:8fdf9a60065b | 280 | CThunk<SPI> _irq; |
kadonotakashi | 0:8fdf9a60065b | 281 | event_callback_t _callback; |
kadonotakashi | 0:8fdf9a60065b | 282 | DMAUsage _usage; |
kadonotakashi | 0:8fdf9a60065b | 283 | bool _deep_sleep_locked; |
kadonotakashi | 0:8fdf9a60065b | 284 | #endif |
kadonotakashi | 0:8fdf9a60065b | 285 | |
kadonotakashi | 0:8fdf9a60065b | 286 | void aquire(void); |
kadonotakashi | 0:8fdf9a60065b | 287 | static SPI *_owner; |
kadonotakashi | 0:8fdf9a60065b | 288 | static SingletonPtr<PlatformMutex> _mutex; |
kadonotakashi | 0:8fdf9a60065b | 289 | int _bits; |
kadonotakashi | 0:8fdf9a60065b | 290 | int _mode; |
kadonotakashi | 0:8fdf9a60065b | 291 | int _hz; |
kadonotakashi | 0:8fdf9a60065b | 292 | char _write_fill; |
kadonotakashi | 0:8fdf9a60065b | 293 | |
kadonotakashi | 0:8fdf9a60065b | 294 | private: |
kadonotakashi | 0:8fdf9a60065b | 295 | /* Private acquire function without locking/unlocking |
kadonotakashi | 0:8fdf9a60065b | 296 | * Implemented in order to avoid duplicate locking and boost performance |
kadonotakashi | 0:8fdf9a60065b | 297 | */ |
kadonotakashi | 0:8fdf9a60065b | 298 | void _acquire(void); |
kadonotakashi | 0:8fdf9a60065b | 299 | }; |
kadonotakashi | 0:8fdf9a60065b | 300 | |
kadonotakashi | 0:8fdf9a60065b | 301 | } // namespace mbed |
kadonotakashi | 0:8fdf9a60065b | 302 | |
kadonotakashi | 0:8fdf9a60065b | 303 | #endif |
kadonotakashi | 0:8fdf9a60065b | 304 | |
kadonotakashi | 0:8fdf9a60065b | 305 | #endif |