Realtime spectrogram for DISCO-F746NG. On-board MEMS microphone is used for input sound signal. リアルタイムスペクトログラム.入力:MEMSマイク
Dependencies: F746_GUI F746_SAI_IO UIT_FFT_Real
mbed_src_STM32F7/api/SerialBase.h@4:c1beacfc42c7, 2016-10-02 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sun Oct 02 10:51:10 2016 +0000
- Revision:
- 4:c1beacfc42c7
5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 4:c1beacfc42c7 | 1 | /* mbed Microcontroller Library |
MikamiUitOpen | 4:c1beacfc42c7 | 2 | * Copyright (c) 2006-2013 ARM Limited |
MikamiUitOpen | 4:c1beacfc42c7 | 3 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
MikamiUitOpen | 4:c1beacfc42c7 | 5 | * you may not use this file except in compliance with the License. |
MikamiUitOpen | 4:c1beacfc42c7 | 6 | * You may obtain a copy of the License at |
MikamiUitOpen | 4:c1beacfc42c7 | 7 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
MikamiUitOpen | 4:c1beacfc42c7 | 9 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 10 | * Unless required by applicable law or agreed to in writing, software |
MikamiUitOpen | 4:c1beacfc42c7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
MikamiUitOpen | 4:c1beacfc42c7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
MikamiUitOpen | 4:c1beacfc42c7 | 13 | * See the License for the specific language governing permissions and |
MikamiUitOpen | 4:c1beacfc42c7 | 14 | * limitations under the License. |
MikamiUitOpen | 4:c1beacfc42c7 | 15 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 16 | #ifndef MBED_SERIALBASE_H |
MikamiUitOpen | 4:c1beacfc42c7 | 17 | #define MBED_SERIALBASE_H |
MikamiUitOpen | 4:c1beacfc42c7 | 18 | |
MikamiUitOpen | 4:c1beacfc42c7 | 19 | #include "platform.h" |
MikamiUitOpen | 4:c1beacfc42c7 | 20 | |
MikamiUitOpen | 4:c1beacfc42c7 | 21 | #if DEVICE_SERIAL |
MikamiUitOpen | 4:c1beacfc42c7 | 22 | |
MikamiUitOpen | 4:c1beacfc42c7 | 23 | #include "Stream.h" |
MikamiUitOpen | 4:c1beacfc42c7 | 24 | #include "FunctionPointer.h" |
MikamiUitOpen | 4:c1beacfc42c7 | 25 | #include "serial_api.h" |
MikamiUitOpen | 4:c1beacfc42c7 | 26 | |
MikamiUitOpen | 4:c1beacfc42c7 | 27 | #if DEVICE_SERIAL_ASYNCH |
MikamiUitOpen | 4:c1beacfc42c7 | 28 | #include "CThunk.h" |
MikamiUitOpen | 4:c1beacfc42c7 | 29 | #include "dma_api.h" |
MikamiUitOpen | 4:c1beacfc42c7 | 30 | #endif |
MikamiUitOpen | 4:c1beacfc42c7 | 31 | |
MikamiUitOpen | 4:c1beacfc42c7 | 32 | namespace mbed { |
MikamiUitOpen | 4:c1beacfc42c7 | 33 | |
MikamiUitOpen | 4:c1beacfc42c7 | 34 | /** A base class for serial port implementations |
MikamiUitOpen | 4:c1beacfc42c7 | 35 | * Can't be instantiated directly (use Serial or RawSerial) |
MikamiUitOpen | 4:c1beacfc42c7 | 36 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 37 | class SerialBase { |
MikamiUitOpen | 4:c1beacfc42c7 | 38 | |
MikamiUitOpen | 4:c1beacfc42c7 | 39 | public: |
MikamiUitOpen | 4:c1beacfc42c7 | 40 | /** Set the baud rate of the serial port |
MikamiUitOpen | 4:c1beacfc42c7 | 41 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 42 | * @param baudrate The baudrate of the serial port (default = 9600). |
MikamiUitOpen | 4:c1beacfc42c7 | 43 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 44 | void baud(int baudrate); |
MikamiUitOpen | 4:c1beacfc42c7 | 45 | |
MikamiUitOpen | 4:c1beacfc42c7 | 46 | enum Parity { |
MikamiUitOpen | 4:c1beacfc42c7 | 47 | None = 0, |
MikamiUitOpen | 4:c1beacfc42c7 | 48 | Odd, |
MikamiUitOpen | 4:c1beacfc42c7 | 49 | Even, |
MikamiUitOpen | 4:c1beacfc42c7 | 50 | Forced1, |
MikamiUitOpen | 4:c1beacfc42c7 | 51 | Forced0 |
MikamiUitOpen | 4:c1beacfc42c7 | 52 | }; |
MikamiUitOpen | 4:c1beacfc42c7 | 53 | |
MikamiUitOpen | 4:c1beacfc42c7 | 54 | enum IrqType { |
MikamiUitOpen | 4:c1beacfc42c7 | 55 | RxIrq = 0, |
MikamiUitOpen | 4:c1beacfc42c7 | 56 | TxIrq |
MikamiUitOpen | 4:c1beacfc42c7 | 57 | }; |
MikamiUitOpen | 4:c1beacfc42c7 | 58 | |
MikamiUitOpen | 4:c1beacfc42c7 | 59 | enum Flow { |
MikamiUitOpen | 4:c1beacfc42c7 | 60 | Disabled = 0, |
MikamiUitOpen | 4:c1beacfc42c7 | 61 | RTS, |
MikamiUitOpen | 4:c1beacfc42c7 | 62 | CTS, |
MikamiUitOpen | 4:c1beacfc42c7 | 63 | RTSCTS |
MikamiUitOpen | 4:c1beacfc42c7 | 64 | }; |
MikamiUitOpen | 4:c1beacfc42c7 | 65 | |
MikamiUitOpen | 4:c1beacfc42c7 | 66 | /** Set the transmission format used by the serial port |
MikamiUitOpen | 4:c1beacfc42c7 | 67 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 68 | * @param bits The number of bits in a word (5-8; default = 8) |
MikamiUitOpen | 4:c1beacfc42c7 | 69 | * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None) |
MikamiUitOpen | 4:c1beacfc42c7 | 70 | * @param stop The number of stop bits (1 or 2; default = 1) |
MikamiUitOpen | 4:c1beacfc42c7 | 71 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 72 | void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1); |
MikamiUitOpen | 4:c1beacfc42c7 | 73 | |
MikamiUitOpen | 4:c1beacfc42c7 | 74 | /** Determine if there is a character available to read |
MikamiUitOpen | 4:c1beacfc42c7 | 75 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 76 | * @returns |
MikamiUitOpen | 4:c1beacfc42c7 | 77 | * 1 if there is a character available to read, |
MikamiUitOpen | 4:c1beacfc42c7 | 78 | * 0 otherwise |
MikamiUitOpen | 4:c1beacfc42c7 | 79 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 80 | int readable(); |
MikamiUitOpen | 4:c1beacfc42c7 | 81 | |
MikamiUitOpen | 4:c1beacfc42c7 | 82 | /** Determine if there is space available to write a character |
MikamiUitOpen | 4:c1beacfc42c7 | 83 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 84 | * @returns |
MikamiUitOpen | 4:c1beacfc42c7 | 85 | * 1 if there is space to write a character, |
MikamiUitOpen | 4:c1beacfc42c7 | 86 | * 0 otherwise |
MikamiUitOpen | 4:c1beacfc42c7 | 87 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 88 | int writeable(); |
MikamiUitOpen | 4:c1beacfc42c7 | 89 | |
MikamiUitOpen | 4:c1beacfc42c7 | 90 | /** Attach a function to call whenever a serial interrupt is generated |
MikamiUitOpen | 4:c1beacfc42c7 | 91 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 92 | * @param fptr A pointer to a void function, or 0 to set as none |
MikamiUitOpen | 4:c1beacfc42c7 | 93 | * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) |
MikamiUitOpen | 4:c1beacfc42c7 | 94 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 95 | void attach(void (*fptr)(void), IrqType type=RxIrq); |
MikamiUitOpen | 4:c1beacfc42c7 | 96 | |
MikamiUitOpen | 4:c1beacfc42c7 | 97 | /** Attach a member function to call whenever a serial interrupt is generated |
MikamiUitOpen | 4:c1beacfc42c7 | 98 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 99 | * @param tptr pointer to the object to call the member function on |
MikamiUitOpen | 4:c1beacfc42c7 | 100 | * @param mptr pointer to the member function to be called |
MikamiUitOpen | 4:c1beacfc42c7 | 101 | * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) |
MikamiUitOpen | 4:c1beacfc42c7 | 102 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 103 | template<typename T> |
MikamiUitOpen | 4:c1beacfc42c7 | 104 | void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) { |
MikamiUitOpen | 4:c1beacfc42c7 | 105 | if((mptr != NULL) && (tptr != NULL)) { |
MikamiUitOpen | 4:c1beacfc42c7 | 106 | _irq[type].attach(tptr, mptr); |
MikamiUitOpen | 4:c1beacfc42c7 | 107 | serial_irq_set(&_serial, (SerialIrq)type, 1); |
MikamiUitOpen | 4:c1beacfc42c7 | 108 | } else { |
MikamiUitOpen | 4:c1beacfc42c7 | 109 | serial_irq_set(&_serial, (SerialIrq)type, 0); |
MikamiUitOpen | 4:c1beacfc42c7 | 110 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 111 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 112 | |
MikamiUitOpen | 4:c1beacfc42c7 | 113 | /** Generate a break condition on the serial line |
MikamiUitOpen | 4:c1beacfc42c7 | 114 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 115 | void send_break(); |
MikamiUitOpen | 4:c1beacfc42c7 | 116 | |
MikamiUitOpen | 4:c1beacfc42c7 | 117 | #if DEVICE_SERIAL_FC |
MikamiUitOpen | 4:c1beacfc42c7 | 118 | /** Set the flow control type on the serial port |
MikamiUitOpen | 4:c1beacfc42c7 | 119 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 120 | * @param type the flow control type (Disabled, RTS, CTS, RTSCTS) |
MikamiUitOpen | 4:c1beacfc42c7 | 121 | * @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS) |
MikamiUitOpen | 4:c1beacfc42c7 | 122 | * @param flow2 the second flow control pin (CTS for RTSCTS) |
MikamiUitOpen | 4:c1beacfc42c7 | 123 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 124 | void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC); |
MikamiUitOpen | 4:c1beacfc42c7 | 125 | #endif |
MikamiUitOpen | 4:c1beacfc42c7 | 126 | |
MikamiUitOpen | 4:c1beacfc42c7 | 127 | static void _irq_handler(uint32_t id, SerialIrq irq_type); |
MikamiUitOpen | 4:c1beacfc42c7 | 128 | |
MikamiUitOpen | 4:c1beacfc42c7 | 129 | #if DEVICE_SERIAL_ASYNCH |
MikamiUitOpen | 4:c1beacfc42c7 | 130 | |
MikamiUitOpen | 4:c1beacfc42c7 | 131 | /** Begin asynchronous write using 8bit buffer. The completition invokes registered TX event callback |
MikamiUitOpen | 4:c1beacfc42c7 | 132 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 133 | * @param buffer The buffer where received data will be stored |
MikamiUitOpen | 4:c1beacfc42c7 | 134 | * @param length The buffer length in bytes |
MikamiUitOpen | 4:c1beacfc42c7 | 135 | * @param callback The event callback function |
MikamiUitOpen | 4:c1beacfc42c7 | 136 | * @param event The logical OR of TX events |
MikamiUitOpen | 4:c1beacfc42c7 | 137 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 138 | int write(const uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE); |
MikamiUitOpen | 4:c1beacfc42c7 | 139 | |
MikamiUitOpen | 4:c1beacfc42c7 | 140 | /** Begin asynchronous write using 16bit buffer. The completition invokes registered TX event callback |
MikamiUitOpen | 4:c1beacfc42c7 | 141 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 142 | * @param buffer The buffer where received data will be stored |
MikamiUitOpen | 4:c1beacfc42c7 | 143 | * @param length The buffer length in bytes |
MikamiUitOpen | 4:c1beacfc42c7 | 144 | * @param callback The event callback function |
MikamiUitOpen | 4:c1beacfc42c7 | 145 | * @param event The logical OR of TX events |
MikamiUitOpen | 4:c1beacfc42c7 | 146 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 147 | int write(const uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE); |
MikamiUitOpen | 4:c1beacfc42c7 | 148 | |
MikamiUitOpen | 4:c1beacfc42c7 | 149 | /** Abort the on-going write transfer |
MikamiUitOpen | 4:c1beacfc42c7 | 150 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 151 | void abort_write(); |
MikamiUitOpen | 4:c1beacfc42c7 | 152 | |
MikamiUitOpen | 4:c1beacfc42c7 | 153 | /** Begin asynchronous reading using 8bit buffer. The completition invokes registred RX event callback. |
MikamiUitOpen | 4:c1beacfc42c7 | 154 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 155 | * @param buffer The buffer where received data will be stored |
MikamiUitOpen | 4:c1beacfc42c7 | 156 | * @param length The buffer length in bytes |
MikamiUitOpen | 4:c1beacfc42c7 | 157 | * @param callback The event callback function |
MikamiUitOpen | 4:c1beacfc42c7 | 158 | * @param event The logical OR of RX events |
MikamiUitOpen | 4:c1beacfc42c7 | 159 | * @param char_match The matching character |
MikamiUitOpen | 4:c1beacfc42c7 | 160 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 161 | int read(uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_RX_COMPLETE, unsigned char char_match = SERIAL_RESERVED_CHAR_MATCH); |
MikamiUitOpen | 4:c1beacfc42c7 | 162 | |
MikamiUitOpen | 4:c1beacfc42c7 | 163 | /** Begin asynchronous reading using 16bit buffer. The completition invokes registred RX event callback. |
MikamiUitOpen | 4:c1beacfc42c7 | 164 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 165 | * @param buffer The buffer where received data will be stored |
MikamiUitOpen | 4:c1beacfc42c7 | 166 | * @param length The buffer length in bytes |
MikamiUitOpen | 4:c1beacfc42c7 | 167 | * @param callback The event callback function |
MikamiUitOpen | 4:c1beacfc42c7 | 168 | * @param event The logical OR of RX events |
MikamiUitOpen | 4:c1beacfc42c7 | 169 | * @param char_match The matching character |
MikamiUitOpen | 4:c1beacfc42c7 | 170 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 171 | int read(uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_RX_COMPLETE, unsigned char char_match = SERIAL_RESERVED_CHAR_MATCH); |
MikamiUitOpen | 4:c1beacfc42c7 | 172 | |
MikamiUitOpen | 4:c1beacfc42c7 | 173 | /** Abort the on-going read transfer |
MikamiUitOpen | 4:c1beacfc42c7 | 174 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 175 | void abort_read(); |
MikamiUitOpen | 4:c1beacfc42c7 | 176 | |
MikamiUitOpen | 4:c1beacfc42c7 | 177 | /** Configure DMA usage suggestion for non-blocking TX transfers |
MikamiUitOpen | 4:c1beacfc42c7 | 178 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 179 | * @param usage The usage DMA hint for peripheral |
MikamiUitOpen | 4:c1beacfc42c7 | 180 | * @return Zero if the usage was set, -1 if a transaction is on-going |
MikamiUitOpen | 4:c1beacfc42c7 | 181 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 182 | int set_dma_usage_tx(DMAUsage usage); |
MikamiUitOpen | 4:c1beacfc42c7 | 183 | |
MikamiUitOpen | 4:c1beacfc42c7 | 184 | /** Configure DMA usage suggestion for non-blocking RX transfers |
MikamiUitOpen | 4:c1beacfc42c7 | 185 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 186 | * @param usage The usage DMA hint for peripheral |
MikamiUitOpen | 4:c1beacfc42c7 | 187 | * @return Zero if the usage was set, -1 if a transaction is on-going |
MikamiUitOpen | 4:c1beacfc42c7 | 188 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 189 | int set_dma_usage_rx(DMAUsage usage); |
MikamiUitOpen | 4:c1beacfc42c7 | 190 | |
MikamiUitOpen | 4:c1beacfc42c7 | 191 | protected: |
MikamiUitOpen | 4:c1beacfc42c7 | 192 | void start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event, unsigned char char_match); |
MikamiUitOpen | 4:c1beacfc42c7 | 193 | void start_write(const void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event); |
MikamiUitOpen | 4:c1beacfc42c7 | 194 | void interrupt_handler_asynch(void); |
MikamiUitOpen | 4:c1beacfc42c7 | 195 | #endif |
MikamiUitOpen | 4:c1beacfc42c7 | 196 | |
MikamiUitOpen | 4:c1beacfc42c7 | 197 | protected: |
MikamiUitOpen | 4:c1beacfc42c7 | 198 | SerialBase(PinName tx, PinName rx); |
MikamiUitOpen | 4:c1beacfc42c7 | 199 | virtual ~SerialBase() { |
MikamiUitOpen | 4:c1beacfc42c7 | 200 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 201 | |
MikamiUitOpen | 4:c1beacfc42c7 | 202 | int _base_getc(); |
MikamiUitOpen | 4:c1beacfc42c7 | 203 | int _base_putc(int c); |
MikamiUitOpen | 4:c1beacfc42c7 | 204 | |
MikamiUitOpen | 4:c1beacfc42c7 | 205 | #if DEVICE_SERIAL_ASYNCH |
MikamiUitOpen | 4:c1beacfc42c7 | 206 | CThunk<SerialBase> _thunk_irq; |
MikamiUitOpen | 4:c1beacfc42c7 | 207 | event_callback_t _tx_callback; |
MikamiUitOpen | 4:c1beacfc42c7 | 208 | event_callback_t _rx_callback; |
MikamiUitOpen | 4:c1beacfc42c7 | 209 | DMAUsage _tx_usage; |
MikamiUitOpen | 4:c1beacfc42c7 | 210 | DMAUsage _rx_usage; |
MikamiUitOpen | 4:c1beacfc42c7 | 211 | #endif |
MikamiUitOpen | 4:c1beacfc42c7 | 212 | |
MikamiUitOpen | 4:c1beacfc42c7 | 213 | serial_t _serial; |
MikamiUitOpen | 4:c1beacfc42c7 | 214 | FunctionPointer _irq[2]; |
MikamiUitOpen | 4:c1beacfc42c7 | 215 | int _baud; |
MikamiUitOpen | 4:c1beacfc42c7 | 216 | |
MikamiUitOpen | 4:c1beacfc42c7 | 217 | }; |
MikamiUitOpen | 4:c1beacfc42c7 | 218 | |
MikamiUitOpen | 4:c1beacfc42c7 | 219 | } // namespace mbed |
MikamiUitOpen | 4:c1beacfc42c7 | 220 | |
MikamiUitOpen | 4:c1beacfc42c7 | 221 | #endif |
MikamiUitOpen | 4:c1beacfc42c7 | 222 | |
MikamiUitOpen | 4:c1beacfc42c7 | 223 | #endif |