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-2013 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 "SerialBase.h"
MikamiUitOpen 16:cbb726ac20d8 17 #include "wait_api.h"
MikamiUitOpen 16:cbb726ac20d8 18
MikamiUitOpen 16:cbb726ac20d8 19 #if DEVICE_SERIAL
MikamiUitOpen 16:cbb726ac20d8 20
MikamiUitOpen 16:cbb726ac20d8 21 namespace mbed {
MikamiUitOpen 16:cbb726ac20d8 22
MikamiUitOpen 16:cbb726ac20d8 23 SerialBase::SerialBase(PinName tx, PinName rx) :
MikamiUitOpen 16:cbb726ac20d8 24 #if DEVICE_SERIAL_ASYNCH
MikamiUitOpen 16:cbb726ac20d8 25 _thunk_irq(this), _tx_usage(DMA_USAGE_NEVER),
MikamiUitOpen 16:cbb726ac20d8 26 _rx_usage(DMA_USAGE_NEVER),
MikamiUitOpen 16:cbb726ac20d8 27 #endif
MikamiUitOpen 16:cbb726ac20d8 28 _serial(), _baud(9600) {
MikamiUitOpen 16:cbb726ac20d8 29 serial_init(&_serial, tx, rx);
MikamiUitOpen 16:cbb726ac20d8 30 serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this);
MikamiUitOpen 16:cbb726ac20d8 31 }
MikamiUitOpen 16:cbb726ac20d8 32
MikamiUitOpen 16:cbb726ac20d8 33 void SerialBase::baud(int baudrate) {
MikamiUitOpen 16:cbb726ac20d8 34 serial_baud(&_serial, baudrate);
MikamiUitOpen 16:cbb726ac20d8 35 _baud = baudrate;
MikamiUitOpen 16:cbb726ac20d8 36 }
MikamiUitOpen 16:cbb726ac20d8 37
MikamiUitOpen 16:cbb726ac20d8 38 void SerialBase::format(int bits, Parity parity, int stop_bits) {
MikamiUitOpen 16:cbb726ac20d8 39 serial_format(&_serial, bits, (SerialParity)parity, stop_bits);
MikamiUitOpen 16:cbb726ac20d8 40 }
MikamiUitOpen 16:cbb726ac20d8 41
MikamiUitOpen 16:cbb726ac20d8 42 int SerialBase::readable() {
MikamiUitOpen 16:cbb726ac20d8 43 return serial_readable(&_serial);
MikamiUitOpen 16:cbb726ac20d8 44 }
MikamiUitOpen 16:cbb726ac20d8 45
MikamiUitOpen 16:cbb726ac20d8 46
MikamiUitOpen 16:cbb726ac20d8 47 int SerialBase::writeable() {
MikamiUitOpen 16:cbb726ac20d8 48 return serial_writable(&_serial);
MikamiUitOpen 16:cbb726ac20d8 49 }
MikamiUitOpen 16:cbb726ac20d8 50
MikamiUitOpen 16:cbb726ac20d8 51 void SerialBase::attach(void (*fptr)(void), IrqType type) {
MikamiUitOpen 16:cbb726ac20d8 52 if (fptr) {
MikamiUitOpen 16:cbb726ac20d8 53 _irq[type].attach(fptr);
MikamiUitOpen 16:cbb726ac20d8 54 serial_irq_set(&_serial, (SerialIrq)type, 1);
MikamiUitOpen 16:cbb726ac20d8 55 } else {
MikamiUitOpen 16:cbb726ac20d8 56 serial_irq_set(&_serial, (SerialIrq)type, 0);
MikamiUitOpen 16:cbb726ac20d8 57 }
MikamiUitOpen 16:cbb726ac20d8 58 }
MikamiUitOpen 16:cbb726ac20d8 59
MikamiUitOpen 16:cbb726ac20d8 60 void SerialBase::_irq_handler(uint32_t id, SerialIrq irq_type) {
MikamiUitOpen 16:cbb726ac20d8 61 SerialBase *handler = (SerialBase*)id;
MikamiUitOpen 16:cbb726ac20d8 62 handler->_irq[irq_type].call();
MikamiUitOpen 16:cbb726ac20d8 63 }
MikamiUitOpen 16:cbb726ac20d8 64
MikamiUitOpen 16:cbb726ac20d8 65 int SerialBase::_base_getc() {
MikamiUitOpen 16:cbb726ac20d8 66 return serial_getc(&_serial);
MikamiUitOpen 16:cbb726ac20d8 67 }
MikamiUitOpen 16:cbb726ac20d8 68
MikamiUitOpen 16:cbb726ac20d8 69 int SerialBase::_base_putc(int c) {
MikamiUitOpen 16:cbb726ac20d8 70 serial_putc(&_serial, c);
MikamiUitOpen 16:cbb726ac20d8 71 return c;
MikamiUitOpen 16:cbb726ac20d8 72 }
MikamiUitOpen 16:cbb726ac20d8 73
MikamiUitOpen 16:cbb726ac20d8 74 void SerialBase::send_break() {
MikamiUitOpen 16:cbb726ac20d8 75 // Wait for 1.5 frames before clearing the break condition
MikamiUitOpen 16:cbb726ac20d8 76 // This will have different effects on our platforms, but should
MikamiUitOpen 16:cbb726ac20d8 77 // ensure that we keep the break active for at least one frame.
MikamiUitOpen 16:cbb726ac20d8 78 // We consider a full frame (1 start bit + 8 data bits bits +
MikamiUitOpen 16:cbb726ac20d8 79 // 1 parity bit + 2 stop bits = 12 bits) for computation.
MikamiUitOpen 16:cbb726ac20d8 80 // One bit time (in us) = 1000000/_baud
MikamiUitOpen 16:cbb726ac20d8 81 // Twelve bits: 12000000/baud delay
MikamiUitOpen 16:cbb726ac20d8 82 // 1.5 frames: 18000000/baud delay
MikamiUitOpen 16:cbb726ac20d8 83 serial_break_set(&_serial);
MikamiUitOpen 16:cbb726ac20d8 84 wait_us(18000000/_baud);
MikamiUitOpen 16:cbb726ac20d8 85 serial_break_clear(&_serial);
MikamiUitOpen 16:cbb726ac20d8 86 }
MikamiUitOpen 16:cbb726ac20d8 87
MikamiUitOpen 16:cbb726ac20d8 88 #if DEVICE_SERIAL_FC
MikamiUitOpen 16:cbb726ac20d8 89 void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2) {
MikamiUitOpen 16:cbb726ac20d8 90 FlowControl flow_type = (FlowControl)type;
MikamiUitOpen 16:cbb726ac20d8 91 switch(type) {
MikamiUitOpen 16:cbb726ac20d8 92 case RTS:
MikamiUitOpen 16:cbb726ac20d8 93 serial_set_flow_control(&_serial, flow_type, flow1, NC);
MikamiUitOpen 16:cbb726ac20d8 94 break;
MikamiUitOpen 16:cbb726ac20d8 95
MikamiUitOpen 16:cbb726ac20d8 96 case CTS:
MikamiUitOpen 16:cbb726ac20d8 97 serial_set_flow_control(&_serial, flow_type, NC, flow1);
MikamiUitOpen 16:cbb726ac20d8 98 break;
MikamiUitOpen 16:cbb726ac20d8 99
MikamiUitOpen 16:cbb726ac20d8 100 case RTSCTS:
MikamiUitOpen 16:cbb726ac20d8 101 case Disabled:
MikamiUitOpen 16:cbb726ac20d8 102 serial_set_flow_control(&_serial, flow_type, flow1, flow2);
MikamiUitOpen 16:cbb726ac20d8 103 break;
MikamiUitOpen 16:cbb726ac20d8 104
MikamiUitOpen 16:cbb726ac20d8 105 default:
MikamiUitOpen 16:cbb726ac20d8 106 break;
MikamiUitOpen 16:cbb726ac20d8 107 }
MikamiUitOpen 16:cbb726ac20d8 108 }
MikamiUitOpen 16:cbb726ac20d8 109 #endif
MikamiUitOpen 16:cbb726ac20d8 110
MikamiUitOpen 16:cbb726ac20d8 111 #if DEVICE_SERIAL_ASYNCH
MikamiUitOpen 16:cbb726ac20d8 112
MikamiUitOpen 16:cbb726ac20d8 113 int SerialBase::write(const uint8_t *buffer, int length, const event_callback_t& callback, int event)
MikamiUitOpen 16:cbb726ac20d8 114 {
MikamiUitOpen 16:cbb726ac20d8 115 if (serial_tx_active(&_serial)) {
MikamiUitOpen 16:cbb726ac20d8 116 return -1; // transaction ongoing
MikamiUitOpen 16:cbb726ac20d8 117 }
MikamiUitOpen 16:cbb726ac20d8 118 start_write((void *)buffer, length, 8, callback, event);
MikamiUitOpen 16:cbb726ac20d8 119 return 0;
MikamiUitOpen 16:cbb726ac20d8 120 }
MikamiUitOpen 16:cbb726ac20d8 121
MikamiUitOpen 16:cbb726ac20d8 122 int SerialBase::write(const uint16_t *buffer, int length, const event_callback_t& callback, int event)
MikamiUitOpen 16:cbb726ac20d8 123 {
MikamiUitOpen 16:cbb726ac20d8 124 if (serial_tx_active(&_serial)) {
MikamiUitOpen 16:cbb726ac20d8 125 return -1; // transaction ongoing
MikamiUitOpen 16:cbb726ac20d8 126 }
MikamiUitOpen 16:cbb726ac20d8 127 start_write((void *)buffer, length, 16, callback, event);
MikamiUitOpen 16:cbb726ac20d8 128 return 0;
MikamiUitOpen 16:cbb726ac20d8 129 }
MikamiUitOpen 16:cbb726ac20d8 130
MikamiUitOpen 16:cbb726ac20d8 131 void SerialBase::start_write(const void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event)
MikamiUitOpen 16:cbb726ac20d8 132 {
MikamiUitOpen 16:cbb726ac20d8 133 _tx_callback = callback;
MikamiUitOpen 16:cbb726ac20d8 134
MikamiUitOpen 16:cbb726ac20d8 135 _thunk_irq.callback(&SerialBase::interrupt_handler_asynch);
MikamiUitOpen 16:cbb726ac20d8 136 serial_tx_asynch(&_serial, buffer, buffer_size, buffer_width, _thunk_irq.entry(), event, _tx_usage);
MikamiUitOpen 16:cbb726ac20d8 137 }
MikamiUitOpen 16:cbb726ac20d8 138
MikamiUitOpen 16:cbb726ac20d8 139 void SerialBase::abort_write(void)
MikamiUitOpen 16:cbb726ac20d8 140 {
MikamiUitOpen 16:cbb726ac20d8 141 serial_tx_abort_asynch(&_serial);
MikamiUitOpen 16:cbb726ac20d8 142 }
MikamiUitOpen 16:cbb726ac20d8 143
MikamiUitOpen 16:cbb726ac20d8 144 void SerialBase::abort_read(void)
MikamiUitOpen 16:cbb726ac20d8 145 {
MikamiUitOpen 16:cbb726ac20d8 146 serial_rx_abort_asynch(&_serial);
MikamiUitOpen 16:cbb726ac20d8 147 }
MikamiUitOpen 16:cbb726ac20d8 148
MikamiUitOpen 16:cbb726ac20d8 149 int SerialBase::set_dma_usage_tx(DMAUsage usage)
MikamiUitOpen 16:cbb726ac20d8 150 {
MikamiUitOpen 16:cbb726ac20d8 151 if (serial_tx_active(&_serial)) {
MikamiUitOpen 16:cbb726ac20d8 152 return -1;
MikamiUitOpen 16:cbb726ac20d8 153 }
MikamiUitOpen 16:cbb726ac20d8 154 _tx_usage = usage;
MikamiUitOpen 16:cbb726ac20d8 155 return 0;
MikamiUitOpen 16:cbb726ac20d8 156 }
MikamiUitOpen 16:cbb726ac20d8 157
MikamiUitOpen 16:cbb726ac20d8 158 int SerialBase::set_dma_usage_rx(DMAUsage usage)
MikamiUitOpen 16:cbb726ac20d8 159 {
MikamiUitOpen 16:cbb726ac20d8 160 if (serial_tx_active(&_serial)) {
MikamiUitOpen 16:cbb726ac20d8 161 return -1;
MikamiUitOpen 16:cbb726ac20d8 162 }
MikamiUitOpen 16:cbb726ac20d8 163 _rx_usage = usage;
MikamiUitOpen 16:cbb726ac20d8 164 return 0;
MikamiUitOpen 16:cbb726ac20d8 165 }
MikamiUitOpen 16:cbb726ac20d8 166
MikamiUitOpen 16:cbb726ac20d8 167 int SerialBase::read(uint8_t *buffer, int length, const event_callback_t& callback, int event, unsigned char char_match)
MikamiUitOpen 16:cbb726ac20d8 168 {
MikamiUitOpen 16:cbb726ac20d8 169 if (serial_rx_active(&_serial)) {
MikamiUitOpen 16:cbb726ac20d8 170 return -1; // transaction ongoing
MikamiUitOpen 16:cbb726ac20d8 171 }
MikamiUitOpen 16:cbb726ac20d8 172 start_read((void*)buffer, length, 8, callback, event, char_match);
MikamiUitOpen 16:cbb726ac20d8 173 return 0;
MikamiUitOpen 16:cbb726ac20d8 174 }
MikamiUitOpen 16:cbb726ac20d8 175
MikamiUitOpen 16:cbb726ac20d8 176
MikamiUitOpen 16:cbb726ac20d8 177 int SerialBase::read(uint16_t *buffer, int length, const event_callback_t& callback, int event, unsigned char char_match)
MikamiUitOpen 16:cbb726ac20d8 178 {
MikamiUitOpen 16:cbb726ac20d8 179 if (serial_rx_active(&_serial)) {
MikamiUitOpen 16:cbb726ac20d8 180 return -1; // transaction ongoing
MikamiUitOpen 16:cbb726ac20d8 181 }
MikamiUitOpen 16:cbb726ac20d8 182 start_read((void*)buffer, length, 16, callback, event, char_match);
MikamiUitOpen 16:cbb726ac20d8 183 return 0;
MikamiUitOpen 16:cbb726ac20d8 184 }
MikamiUitOpen 16:cbb726ac20d8 185
MikamiUitOpen 16:cbb726ac20d8 186
MikamiUitOpen 16:cbb726ac20d8 187 void SerialBase::start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event, unsigned char char_match)
MikamiUitOpen 16:cbb726ac20d8 188 {
MikamiUitOpen 16:cbb726ac20d8 189 _rx_callback = callback;
MikamiUitOpen 16:cbb726ac20d8 190 _thunk_irq.callback(&SerialBase::interrupt_handler_asynch);
MikamiUitOpen 16:cbb726ac20d8 191 serial_rx_asynch(&_serial, buffer, buffer_size, buffer_width, _thunk_irq.entry(), event, char_match, _rx_usage);
MikamiUitOpen 16:cbb726ac20d8 192 }
MikamiUitOpen 16:cbb726ac20d8 193
MikamiUitOpen 16:cbb726ac20d8 194 void SerialBase::interrupt_handler_asynch(void)
MikamiUitOpen 16:cbb726ac20d8 195 {
MikamiUitOpen 16:cbb726ac20d8 196 int event = serial_irq_handler_asynch(&_serial);
MikamiUitOpen 16:cbb726ac20d8 197 int rx_event = event & SERIAL_EVENT_RX_MASK;
MikamiUitOpen 16:cbb726ac20d8 198 if (_rx_callback && rx_event) {
MikamiUitOpen 16:cbb726ac20d8 199 _rx_callback.call(rx_event);
MikamiUitOpen 16:cbb726ac20d8 200 }
MikamiUitOpen 16:cbb726ac20d8 201
MikamiUitOpen 16:cbb726ac20d8 202 int tx_event = event & SERIAL_EVENT_TX_MASK;
MikamiUitOpen 16:cbb726ac20d8 203 if (_tx_callback && tx_event) {
MikamiUitOpen 16:cbb726ac20d8 204 _tx_callback.call(tx_event);
MikamiUitOpen 16:cbb726ac20d8 205 }
MikamiUitOpen 16:cbb726ac20d8 206 }
MikamiUitOpen 16:cbb726ac20d8 207
MikamiUitOpen 16:cbb726ac20d8 208 #endif
MikamiUitOpen 16:cbb726ac20d8 209
MikamiUitOpen 16:cbb726ac20d8 210 } // namespace mbed
MikamiUitOpen 16:cbb726ac20d8 211
MikamiUitOpen 16:cbb726ac20d8 212 #endif