Output the audio signal with filtering by graphic equalizer in the *.wav file on the SD card using onboard CODEC. SD カードの *.wav ファイルのオーディオ信号をグラフィック・イコライザを通して,ボードに搭載されているCODEC で出力する.

Dependencies:   F746_GUI F746_SAI_IO SD_PlayerSkeleton FrequencyResponseDrawer

Committer:
MikamiUitOpen
Date:
Sun Oct 02 06:33:59 2016 +0000
Revision:
16:cbb726ac20d8
17

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 16:cbb726ac20d8 1 /* mbed Microcontroller Library
MikamiUitOpen 16:cbb726ac20d8 2 * Copyright (c) 2006-2015 ARM Limited
MikamiUitOpen 16:cbb726ac20d8 3 *
MikamiUitOpen 16:cbb726ac20d8 4 * Licensed under the Apache License, Version 2.0 (the "License");
MikamiUitOpen 16:cbb726ac20d8 5 * you may not use this file except in compliance with the License.
MikamiUitOpen 16:cbb726ac20d8 6 * You may obtain a copy of the License at
MikamiUitOpen 16:cbb726ac20d8 7 *
MikamiUitOpen 16:cbb726ac20d8 8 * http://www.apache.org/licenses/LICENSE-2.0
MikamiUitOpen 16:cbb726ac20d8 9 *
MikamiUitOpen 16:cbb726ac20d8 10 * Unless required by applicable law or agreed to in writing, software
MikamiUitOpen 16:cbb726ac20d8 11 * distributed under the License is distributed on an "AS IS" BASIS,
MikamiUitOpen 16:cbb726ac20d8 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MikamiUitOpen 16:cbb726ac20d8 13 * See the License for the specific language governing permissions and
MikamiUitOpen 16:cbb726ac20d8 14 * limitations under the License.
MikamiUitOpen 16:cbb726ac20d8 15 */
MikamiUitOpen 16:cbb726ac20d8 16 #ifndef MBED_SPI_H
MikamiUitOpen 16:cbb726ac20d8 17 #define MBED_SPI_H
MikamiUitOpen 16:cbb726ac20d8 18
MikamiUitOpen 16:cbb726ac20d8 19 #include "platform.h"
MikamiUitOpen 16:cbb726ac20d8 20
MikamiUitOpen 16:cbb726ac20d8 21 #if DEVICE_SPI
MikamiUitOpen 16:cbb726ac20d8 22
MikamiUitOpen 16:cbb726ac20d8 23 #include "spi_api.h"
MikamiUitOpen 16:cbb726ac20d8 24
MikamiUitOpen 16:cbb726ac20d8 25 #if DEVICE_SPI_ASYNCH
MikamiUitOpen 16:cbb726ac20d8 26 #include "CThunk.h"
MikamiUitOpen 16:cbb726ac20d8 27 #include "dma_api.h"
MikamiUitOpen 16:cbb726ac20d8 28 #include "CircularBuffer.h"
MikamiUitOpen 16:cbb726ac20d8 29 #include "FunctionPointer.h"
MikamiUitOpen 16:cbb726ac20d8 30 #include "Transaction.h"
MikamiUitOpen 16:cbb726ac20d8 31 #endif
MikamiUitOpen 16:cbb726ac20d8 32
MikamiUitOpen 16:cbb726ac20d8 33 namespace mbed {
MikamiUitOpen 16:cbb726ac20d8 34
MikamiUitOpen 16:cbb726ac20d8 35 /** A SPI Master, used for communicating with SPI slave devices
MikamiUitOpen 16:cbb726ac20d8 36 *
MikamiUitOpen 16:cbb726ac20d8 37 * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
MikamiUitOpen 16:cbb726ac20d8 38 *
MikamiUitOpen 16:cbb726ac20d8 39 * Most SPI devices will also require Chip Select and Reset signals. These
MikamiUitOpen 16:cbb726ac20d8 40 * can be controlled using <DigitalOut> pins
MikamiUitOpen 16:cbb726ac20d8 41 *
MikamiUitOpen 16:cbb726ac20d8 42 * Example:
MikamiUitOpen 16:cbb726ac20d8 43 * @code
MikamiUitOpen 16:cbb726ac20d8 44 * // Send a byte to a SPI slave, and record the response
MikamiUitOpen 16:cbb726ac20d8 45 *
MikamiUitOpen 16:cbb726ac20d8 46 * #include "mbed.h"
MikamiUitOpen 16:cbb726ac20d8 47 *
MikamiUitOpen 16:cbb726ac20d8 48 * // hardware ssel (where applicable)
MikamiUitOpen 16:cbb726ac20d8 49 * //SPI device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
MikamiUitOpen 16:cbb726ac20d8 50 *
MikamiUitOpen 16:cbb726ac20d8 51 * // software ssel
MikamiUitOpen 16:cbb726ac20d8 52 * SPI device(p5, p6, p7); // mosi, miso, sclk
MikamiUitOpen 16:cbb726ac20d8 53 * DigitalOut cs(p8); // ssel
MikamiUitOpen 16:cbb726ac20d8 54 *
MikamiUitOpen 16:cbb726ac20d8 55 * int main() {
MikamiUitOpen 16:cbb726ac20d8 56 * // hardware ssel (where applicable)
MikamiUitOpen 16:cbb726ac20d8 57 * //int response = device.write(0xFF);
MikamiUitOpen 16:cbb726ac20d8 58 *
MikamiUitOpen 16:cbb726ac20d8 59 * // software ssel
MikamiUitOpen 16:cbb726ac20d8 60 * cs = 0;
MikamiUitOpen 16:cbb726ac20d8 61 * int response = device.write(0xFF);
MikamiUitOpen 16:cbb726ac20d8 62 * cs = 1;
MikamiUitOpen 16:cbb726ac20d8 63 * }
MikamiUitOpen 16:cbb726ac20d8 64 * @endcode
MikamiUitOpen 16:cbb726ac20d8 65 */
MikamiUitOpen 16:cbb726ac20d8 66 class SPI {
MikamiUitOpen 16:cbb726ac20d8 67
MikamiUitOpen 16:cbb726ac20d8 68 public:
MikamiUitOpen 16:cbb726ac20d8 69
MikamiUitOpen 16:cbb726ac20d8 70 /** Create a SPI master connected to the specified pins
MikamiUitOpen 16:cbb726ac20d8 71 *
MikamiUitOpen 16:cbb726ac20d8 72 * mosi or miso can be specfied as NC if not used
MikamiUitOpen 16:cbb726ac20d8 73 *
MikamiUitOpen 16:cbb726ac20d8 74 * @param mosi SPI Master Out, Slave In pin
MikamiUitOpen 16:cbb726ac20d8 75 * @param miso SPI Master In, Slave Out pin
MikamiUitOpen 16:cbb726ac20d8 76 * @param sclk SPI Clock pin
MikamiUitOpen 16:cbb726ac20d8 77 * @param ssel SPI chip select pin
MikamiUitOpen 16:cbb726ac20d8 78 */
MikamiUitOpen 16:cbb726ac20d8 79 SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel=NC);
MikamiUitOpen 16:cbb726ac20d8 80
MikamiUitOpen 16:cbb726ac20d8 81 /** Configure the data transmission format
MikamiUitOpen 16:cbb726ac20d8 82 *
MikamiUitOpen 16:cbb726ac20d8 83 * @param bits Number of bits per SPI frame (4 - 16)
MikamiUitOpen 16:cbb726ac20d8 84 * @param mode Clock polarity and phase mode (0 - 3)
MikamiUitOpen 16:cbb726ac20d8 85 *
MikamiUitOpen 16:cbb726ac20d8 86 * @code
MikamiUitOpen 16:cbb726ac20d8 87 * mode | POL PHA
MikamiUitOpen 16:cbb726ac20d8 88 * -----+--------
MikamiUitOpen 16:cbb726ac20d8 89 * 0 | 0 0
MikamiUitOpen 16:cbb726ac20d8 90 * 1 | 0 1
MikamiUitOpen 16:cbb726ac20d8 91 * 2 | 1 0
MikamiUitOpen 16:cbb726ac20d8 92 * 3 | 1 1
MikamiUitOpen 16:cbb726ac20d8 93 * @endcode
MikamiUitOpen 16:cbb726ac20d8 94 */
MikamiUitOpen 16:cbb726ac20d8 95 void format(int bits, int mode = 0);
MikamiUitOpen 16:cbb726ac20d8 96
MikamiUitOpen 16:cbb726ac20d8 97 /** Set the spi bus clock frequency
MikamiUitOpen 16:cbb726ac20d8 98 *
MikamiUitOpen 16:cbb726ac20d8 99 * @param hz SCLK frequency in hz (default = 1MHz)
MikamiUitOpen 16:cbb726ac20d8 100 */
MikamiUitOpen 16:cbb726ac20d8 101 void frequency(int hz = 1000000);
MikamiUitOpen 16:cbb726ac20d8 102
MikamiUitOpen 16:cbb726ac20d8 103 /** Write to the SPI Slave and return the response
MikamiUitOpen 16:cbb726ac20d8 104 *
MikamiUitOpen 16:cbb726ac20d8 105 * @param value Data to be sent to the SPI slave
MikamiUitOpen 16:cbb726ac20d8 106 *
MikamiUitOpen 16:cbb726ac20d8 107 * @returns
MikamiUitOpen 16:cbb726ac20d8 108 * Response from the SPI slave
MikamiUitOpen 16:cbb726ac20d8 109 */
MikamiUitOpen 16:cbb726ac20d8 110 virtual int write(int value);
MikamiUitOpen 16:cbb726ac20d8 111
MikamiUitOpen 16:cbb726ac20d8 112 #if DEVICE_SPI_ASYNCH
MikamiUitOpen 16:cbb726ac20d8 113
MikamiUitOpen 16:cbb726ac20d8 114 /** Start non-blocking SPI transfer using 8bit buffers.
MikamiUitOpen 16:cbb726ac20d8 115 *
MikamiUitOpen 16:cbb726ac20d8 116 * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
MikamiUitOpen 16:cbb726ac20d8 117 * the default SPI value is sent
MikamiUitOpen 16:cbb726ac20d8 118 * @param tx_length The length of TX buffer in bytes
MikamiUitOpen 16:cbb726ac20d8 119 * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
MikamiUitOpen 16:cbb726ac20d8 120 * received data are ignored
MikamiUitOpen 16:cbb726ac20d8 121 * @param rx_length The length of RX buffer in bytes
MikamiUitOpen 16:cbb726ac20d8 122 * @param callback The event callback function
MikamiUitOpen 16:cbb726ac20d8 123 * @param event The logical OR of events to modify. Look at spi hal header file for SPI events.
MikamiUitOpen 16:cbb726ac20d8 124 * @return Zero if the transfer has started, or -1 if SPI peripheral is busy
MikamiUitOpen 16:cbb726ac20d8 125 */
MikamiUitOpen 16:cbb726ac20d8 126 template<typename Type>
MikamiUitOpen 16:cbb726ac20d8 127 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) {
MikamiUitOpen 16:cbb726ac20d8 128 if (spi_active(&_spi)) {
MikamiUitOpen 16:cbb726ac20d8 129 return queue_transfer(tx_buffer, tx_length, rx_buffer, rx_length, sizeof(Type)*8, callback, event);
MikamiUitOpen 16:cbb726ac20d8 130 }
MikamiUitOpen 16:cbb726ac20d8 131 start_transfer(tx_buffer, tx_length, rx_buffer, rx_length, sizeof(Type)*8, callback, event);
MikamiUitOpen 16:cbb726ac20d8 132 return 0;
MikamiUitOpen 16:cbb726ac20d8 133 }
MikamiUitOpen 16:cbb726ac20d8 134
MikamiUitOpen 16:cbb726ac20d8 135 /** Abort the on-going SPI transfer, and continue with transfer's in the queue if any.
MikamiUitOpen 16:cbb726ac20d8 136 */
MikamiUitOpen 16:cbb726ac20d8 137 void abort_transfer();
MikamiUitOpen 16:cbb726ac20d8 138
MikamiUitOpen 16:cbb726ac20d8 139 /** Clear the transaction buffer
MikamiUitOpen 16:cbb726ac20d8 140 */
MikamiUitOpen 16:cbb726ac20d8 141 void clear_transfer_buffer();
MikamiUitOpen 16:cbb726ac20d8 142
MikamiUitOpen 16:cbb726ac20d8 143 /** Clear the transaction buffer and abort on-going transfer.
MikamiUitOpen 16:cbb726ac20d8 144 */
MikamiUitOpen 16:cbb726ac20d8 145 void abort_all_transfers();
MikamiUitOpen 16:cbb726ac20d8 146
MikamiUitOpen 16:cbb726ac20d8 147 /** Configure DMA usage suggestion for non-blocking transfers
MikamiUitOpen 16:cbb726ac20d8 148 *
MikamiUitOpen 16:cbb726ac20d8 149 * @param usage The usage DMA hint for peripheral
MikamiUitOpen 16:cbb726ac20d8 150 * @return Zero if the usage was set, -1 if a transaction is on-going
MikamiUitOpen 16:cbb726ac20d8 151 */
MikamiUitOpen 16:cbb726ac20d8 152 int set_dma_usage(DMAUsage usage);
MikamiUitOpen 16:cbb726ac20d8 153
MikamiUitOpen 16:cbb726ac20d8 154 protected:
MikamiUitOpen 16:cbb726ac20d8 155 /** SPI IRQ handler
MikamiUitOpen 16:cbb726ac20d8 156 *
MikamiUitOpen 16:cbb726ac20d8 157 */
MikamiUitOpen 16:cbb726ac20d8 158 void irq_handler_asynch(void);
MikamiUitOpen 16:cbb726ac20d8 159
MikamiUitOpen 16:cbb726ac20d8 160 /** Common transfer method
MikamiUitOpen 16:cbb726ac20d8 161 *
MikamiUitOpen 16:cbb726ac20d8 162 * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
MikamiUitOpen 16:cbb726ac20d8 163 * the default SPI value is sent
MikamiUitOpen 16:cbb726ac20d8 164 * @param tx_length The length of TX buffer in bytes
MikamiUitOpen 16:cbb726ac20d8 165 * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
MikamiUitOpen 16:cbb726ac20d8 166 * received data are ignored
MikamiUitOpen 16:cbb726ac20d8 167 * @param rx_length The length of RX buffer in bytes
MikamiUitOpen 16:cbb726ac20d8 168 * @param bit_width The buffers element width
MikamiUitOpen 16:cbb726ac20d8 169 * @param callback The event callback function
MikamiUitOpen 16:cbb726ac20d8 170 * @param event The logical OR of events to modify
MikamiUitOpen 16:cbb726ac20d8 171 * @return Zero if the transfer has started or was added to the queue, or -1 if SPI peripheral is busy/buffer is full
MikamiUitOpen 16:cbb726ac20d8 172 */
MikamiUitOpen 16:cbb726ac20d8 173 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);
MikamiUitOpen 16:cbb726ac20d8 174
MikamiUitOpen 16:cbb726ac20d8 175 /**
MikamiUitOpen 16:cbb726ac20d8 176 *
MikamiUitOpen 16:cbb726ac20d8 177 * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
MikamiUitOpen 16:cbb726ac20d8 178 * the default SPI value is sent
MikamiUitOpen 16:cbb726ac20d8 179 * @param tx_length The length of TX buffer in bytes
MikamiUitOpen 16:cbb726ac20d8 180 * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
MikamiUitOpen 16:cbb726ac20d8 181 * received data are ignored
MikamiUitOpen 16:cbb726ac20d8 182 * @param rx_length The length of RX buffer in bytes
MikamiUitOpen 16:cbb726ac20d8 183 * @param bit_width The buffers element width
MikamiUitOpen 16:cbb726ac20d8 184 * @param callback The event callback function
MikamiUitOpen 16:cbb726ac20d8 185 * @param event The logical OR of events to modify
MikamiUitOpen 16:cbb726ac20d8 186 * @return Zero if a transfer was added to the queue, or -1 if the queue is full
MikamiUitOpen 16:cbb726ac20d8 187 */
MikamiUitOpen 16:cbb726ac20d8 188 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);
MikamiUitOpen 16:cbb726ac20d8 189
MikamiUitOpen 16:cbb726ac20d8 190 /** Configures a callback, spi peripheral and initiate a new transfer
MikamiUitOpen 16:cbb726ac20d8 191 *
MikamiUitOpen 16:cbb726ac20d8 192 * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
MikamiUitOpen 16:cbb726ac20d8 193 * the default SPI value is sent
MikamiUitOpen 16:cbb726ac20d8 194 * @param tx_length The length of TX buffer in bytes
MikamiUitOpen 16:cbb726ac20d8 195 * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
MikamiUitOpen 16:cbb726ac20d8 196 * received data are ignored
MikamiUitOpen 16:cbb726ac20d8 197 * @param rx_length The length of RX buffer in bytes
MikamiUitOpen 16:cbb726ac20d8 198 * @param bit_width The buffers element width
MikamiUitOpen 16:cbb726ac20d8 199 * @param callback The event callback function
MikamiUitOpen 16:cbb726ac20d8 200 * @param event The logical OR of events to modify
MikamiUitOpen 16:cbb726ac20d8 201 */
MikamiUitOpen 16:cbb726ac20d8 202 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);
MikamiUitOpen 16:cbb726ac20d8 203
MikamiUitOpen 16:cbb726ac20d8 204 #if TRANSACTION_QUEUE_SIZE_SPI
MikamiUitOpen 16:cbb726ac20d8 205
MikamiUitOpen 16:cbb726ac20d8 206 /** Start a new transaction
MikamiUitOpen 16:cbb726ac20d8 207 *
MikamiUitOpen 16:cbb726ac20d8 208 * @param data Transaction data
MikamiUitOpen 16:cbb726ac20d8 209 */
MikamiUitOpen 16:cbb726ac20d8 210 void start_transaction(transaction_t *data);
MikamiUitOpen 16:cbb726ac20d8 211
MikamiUitOpen 16:cbb726ac20d8 212 /** Dequeue a transaction
MikamiUitOpen 16:cbb726ac20d8 213 *
MikamiUitOpen 16:cbb726ac20d8 214 */
MikamiUitOpen 16:cbb726ac20d8 215 void dequeue_transaction();
MikamiUitOpen 16:cbb726ac20d8 216 static CircularBuffer<Transaction<SPI>, TRANSACTION_QUEUE_SIZE_SPI> _transaction_buffer;
MikamiUitOpen 16:cbb726ac20d8 217 #endif
MikamiUitOpen 16:cbb726ac20d8 218
MikamiUitOpen 16:cbb726ac20d8 219 #endif
MikamiUitOpen 16:cbb726ac20d8 220
MikamiUitOpen 16:cbb726ac20d8 221 public:
MikamiUitOpen 16:cbb726ac20d8 222 virtual ~SPI() {
MikamiUitOpen 16:cbb726ac20d8 223 }
MikamiUitOpen 16:cbb726ac20d8 224
MikamiUitOpen 16:cbb726ac20d8 225 protected:
MikamiUitOpen 16:cbb726ac20d8 226 spi_t _spi;
MikamiUitOpen 16:cbb726ac20d8 227
MikamiUitOpen 16:cbb726ac20d8 228 #if DEVICE_SPI_ASYNCH
MikamiUitOpen 16:cbb726ac20d8 229 CThunk<SPI> _irq;
MikamiUitOpen 16:cbb726ac20d8 230 event_callback_t _callback;
MikamiUitOpen 16:cbb726ac20d8 231 DMAUsage _usage;
MikamiUitOpen 16:cbb726ac20d8 232 #endif
MikamiUitOpen 16:cbb726ac20d8 233
MikamiUitOpen 16:cbb726ac20d8 234 void aquire(void);
MikamiUitOpen 16:cbb726ac20d8 235 static SPI *_owner;
MikamiUitOpen 16:cbb726ac20d8 236 int _bits;
MikamiUitOpen 16:cbb726ac20d8 237 int _mode;
MikamiUitOpen 16:cbb726ac20d8 238 int _hz;
MikamiUitOpen 16:cbb726ac20d8 239 };
MikamiUitOpen 16:cbb726ac20d8 240
MikamiUitOpen 16:cbb726ac20d8 241 } // namespace mbed
MikamiUitOpen 16:cbb726ac20d8 242
MikamiUitOpen 16:cbb726ac20d8 243 #endif
MikamiUitOpen 16:cbb726ac20d8 244
MikamiUitOpen 16:cbb726ac20d8 245 #endif