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 #include "I2C.h"
MikamiUitOpen 16:cbb726ac20d8 17
MikamiUitOpen 16:cbb726ac20d8 18 #if DEVICE_I2C
MikamiUitOpen 16:cbb726ac20d8 19
MikamiUitOpen 16:cbb726ac20d8 20 namespace mbed {
MikamiUitOpen 16:cbb726ac20d8 21
MikamiUitOpen 16:cbb726ac20d8 22 I2C *I2C::_owner = NULL;
MikamiUitOpen 16:cbb726ac20d8 23
MikamiUitOpen 16:cbb726ac20d8 24 I2C::I2C(PinName sda, PinName scl) :
MikamiUitOpen 16:cbb726ac20d8 25 #if DEVICE_I2C_ASYNCH
MikamiUitOpen 16:cbb726ac20d8 26 _irq(this), _usage(DMA_USAGE_NEVER),
MikamiUitOpen 16:cbb726ac20d8 27 #endif
MikamiUitOpen 16:cbb726ac20d8 28 _i2c(), _hz(100000) {
MikamiUitOpen 16:cbb726ac20d8 29 // The init function also set the frequency to 100000
MikamiUitOpen 16:cbb726ac20d8 30 i2c_init(&_i2c, sda, scl);
MikamiUitOpen 16:cbb726ac20d8 31
MikamiUitOpen 16:cbb726ac20d8 32 // Used to avoid unnecessary frequency updates
MikamiUitOpen 16:cbb726ac20d8 33 _owner = this;
MikamiUitOpen 16:cbb726ac20d8 34 }
MikamiUitOpen 16:cbb726ac20d8 35
MikamiUitOpen 16:cbb726ac20d8 36 void I2C::frequency(int hz) {
MikamiUitOpen 16:cbb726ac20d8 37 _hz = hz;
MikamiUitOpen 16:cbb726ac20d8 38
MikamiUitOpen 16:cbb726ac20d8 39 // We want to update the frequency even if we are already the bus owners
MikamiUitOpen 16:cbb726ac20d8 40 i2c_frequency(&_i2c, _hz);
MikamiUitOpen 16:cbb726ac20d8 41
MikamiUitOpen 16:cbb726ac20d8 42 // Updating the frequency of the bus we become the owners of it
MikamiUitOpen 16:cbb726ac20d8 43 _owner = this;
MikamiUitOpen 16:cbb726ac20d8 44 }
MikamiUitOpen 16:cbb726ac20d8 45
MikamiUitOpen 16:cbb726ac20d8 46 void I2C::aquire() {
MikamiUitOpen 16:cbb726ac20d8 47 if (_owner != this) {
MikamiUitOpen 16:cbb726ac20d8 48 i2c_frequency(&_i2c, _hz);
MikamiUitOpen 16:cbb726ac20d8 49 _owner = this;
MikamiUitOpen 16:cbb726ac20d8 50 }
MikamiUitOpen 16:cbb726ac20d8 51 }
MikamiUitOpen 16:cbb726ac20d8 52
MikamiUitOpen 16:cbb726ac20d8 53 // write - Master Transmitter Mode
MikamiUitOpen 16:cbb726ac20d8 54 int I2C::write(int address, const char* data, int length, bool repeated) {
MikamiUitOpen 16:cbb726ac20d8 55 aquire();
MikamiUitOpen 16:cbb726ac20d8 56
MikamiUitOpen 16:cbb726ac20d8 57 int stop = (repeated) ? 0 : 1;
MikamiUitOpen 16:cbb726ac20d8 58 int written = i2c_write(&_i2c, address, data, length, stop);
MikamiUitOpen 16:cbb726ac20d8 59
MikamiUitOpen 16:cbb726ac20d8 60 return length != written;
MikamiUitOpen 16:cbb726ac20d8 61 }
MikamiUitOpen 16:cbb726ac20d8 62
MikamiUitOpen 16:cbb726ac20d8 63 int I2C::write(int data) {
MikamiUitOpen 16:cbb726ac20d8 64 return i2c_byte_write(&_i2c, data);
MikamiUitOpen 16:cbb726ac20d8 65 }
MikamiUitOpen 16:cbb726ac20d8 66
MikamiUitOpen 16:cbb726ac20d8 67 // read - Master Reciever Mode
MikamiUitOpen 16:cbb726ac20d8 68 int I2C::read(int address, char* data, int length, bool repeated) {
MikamiUitOpen 16:cbb726ac20d8 69 aquire();
MikamiUitOpen 16:cbb726ac20d8 70
MikamiUitOpen 16:cbb726ac20d8 71 int stop = (repeated) ? 0 : 1;
MikamiUitOpen 16:cbb726ac20d8 72 int read = i2c_read(&_i2c, address, data, length, stop);
MikamiUitOpen 16:cbb726ac20d8 73
MikamiUitOpen 16:cbb726ac20d8 74 return length != read;
MikamiUitOpen 16:cbb726ac20d8 75 }
MikamiUitOpen 16:cbb726ac20d8 76
MikamiUitOpen 16:cbb726ac20d8 77 int I2C::read(int ack) {
MikamiUitOpen 16:cbb726ac20d8 78 if (ack) {
MikamiUitOpen 16:cbb726ac20d8 79 return i2c_byte_read(&_i2c, 0);
MikamiUitOpen 16:cbb726ac20d8 80 } else {
MikamiUitOpen 16:cbb726ac20d8 81 return i2c_byte_read(&_i2c, 1);
MikamiUitOpen 16:cbb726ac20d8 82 }
MikamiUitOpen 16:cbb726ac20d8 83 }
MikamiUitOpen 16:cbb726ac20d8 84
MikamiUitOpen 16:cbb726ac20d8 85 void I2C::start(void) {
MikamiUitOpen 16:cbb726ac20d8 86 i2c_start(&_i2c);
MikamiUitOpen 16:cbb726ac20d8 87 }
MikamiUitOpen 16:cbb726ac20d8 88
MikamiUitOpen 16:cbb726ac20d8 89 void I2C::stop(void) {
MikamiUitOpen 16:cbb726ac20d8 90 i2c_stop(&_i2c);
MikamiUitOpen 16:cbb726ac20d8 91 }
MikamiUitOpen 16:cbb726ac20d8 92
MikamiUitOpen 16:cbb726ac20d8 93 #if DEVICE_I2C_ASYNCH
MikamiUitOpen 16:cbb726ac20d8 94
MikamiUitOpen 16:cbb726ac20d8 95 int I2C::transfer(int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t& callback, int event, bool repeated)
MikamiUitOpen 16:cbb726ac20d8 96 {
MikamiUitOpen 16:cbb726ac20d8 97 if (i2c_active(&_i2c)) {
MikamiUitOpen 16:cbb726ac20d8 98 return -1; // transaction ongoing
MikamiUitOpen 16:cbb726ac20d8 99 }
MikamiUitOpen 16:cbb726ac20d8 100 aquire();
MikamiUitOpen 16:cbb726ac20d8 101
MikamiUitOpen 16:cbb726ac20d8 102 _callback = callback;
MikamiUitOpen 16:cbb726ac20d8 103 int stop = (repeated) ? 0 : 1;
MikamiUitOpen 16:cbb726ac20d8 104 _irq.callback(&I2C::irq_handler_asynch);
MikamiUitOpen 16:cbb726ac20d8 105 i2c_transfer_asynch(&_i2c, (void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length, address, stop, _irq.entry(), event, _usage);
MikamiUitOpen 16:cbb726ac20d8 106 return 0;
MikamiUitOpen 16:cbb726ac20d8 107 }
MikamiUitOpen 16:cbb726ac20d8 108
MikamiUitOpen 16:cbb726ac20d8 109 void I2C::abort_transfer(void)
MikamiUitOpen 16:cbb726ac20d8 110 {
MikamiUitOpen 16:cbb726ac20d8 111 i2c_abort_asynch(&_i2c);
MikamiUitOpen 16:cbb726ac20d8 112 }
MikamiUitOpen 16:cbb726ac20d8 113
MikamiUitOpen 16:cbb726ac20d8 114 void I2C::irq_handler_asynch(void)
MikamiUitOpen 16:cbb726ac20d8 115 {
MikamiUitOpen 16:cbb726ac20d8 116 int event = i2c_irq_handler_asynch(&_i2c);
MikamiUitOpen 16:cbb726ac20d8 117 if (_callback && event) {
MikamiUitOpen 16:cbb726ac20d8 118 _callback.call(event);
MikamiUitOpen 16:cbb726ac20d8 119 }
MikamiUitOpen 16:cbb726ac20d8 120
MikamiUitOpen 16:cbb726ac20d8 121 }
MikamiUitOpen 16:cbb726ac20d8 122
MikamiUitOpen 16:cbb726ac20d8 123
MikamiUitOpen 16:cbb726ac20d8 124 #endif
MikamiUitOpen 16:cbb726ac20d8 125
MikamiUitOpen 16:cbb726ac20d8 126 } // namespace mbed
MikamiUitOpen 16:cbb726ac20d8 127
MikamiUitOpen 16:cbb726ac20d8 128 #endif