Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1 /* mbed Microcontroller Library
switches 0:5c4d7b2438d3 2 * Copyright (c) 2006-2013 ARM Limited
switches 0:5c4d7b2438d3 3 *
switches 0:5c4d7b2438d3 4 * Licensed under the Apache License, Version 2.0 (the "License");
switches 0:5c4d7b2438d3 5 * you may not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 6 * You may obtain a copy of the License at
switches 0:5c4d7b2438d3 7 *
switches 0:5c4d7b2438d3 8 * http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 9 *
switches 0:5c4d7b2438d3 10 * Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 11 * distributed under the License is distributed on an "AS IS" BASIS,
switches 0:5c4d7b2438d3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 13 * See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 14 * limitations under the License.
switches 0:5c4d7b2438d3 15 */
switches 0:5c4d7b2438d3 16 #ifndef MBED_SERIALBASE_H
switches 0:5c4d7b2438d3 17 #define MBED_SERIALBASE_H
switches 0:5c4d7b2438d3 18
switches 0:5c4d7b2438d3 19 #include "platform/platform.h"
switches 0:5c4d7b2438d3 20
switches 0:5c4d7b2438d3 21 #if DEVICE_SERIAL
switches 0:5c4d7b2438d3 22
switches 0:5c4d7b2438d3 23 #include "Stream.h"
switches 0:5c4d7b2438d3 24 #include "Callback.h"
switches 0:5c4d7b2438d3 25 #include "serial_api.h"
switches 0:5c4d7b2438d3 26 #include "toolchain.h"
switches 0:5c4d7b2438d3 27
switches 0:5c4d7b2438d3 28 #if DEVICE_SERIAL_ASYNCH
switches 0:5c4d7b2438d3 29 #include "CThunk.h"
switches 0:5c4d7b2438d3 30 #include "dma_api.h"
switches 0:5c4d7b2438d3 31 #endif
switches 0:5c4d7b2438d3 32
switches 0:5c4d7b2438d3 33 namespace mbed {
switches 0:5c4d7b2438d3 34 /** \addtogroup drivers */
switches 0:5c4d7b2438d3 35 /** @{*/
switches 0:5c4d7b2438d3 36
switches 0:5c4d7b2438d3 37 /** A base class for serial port implementations
switches 0:5c4d7b2438d3 38 * Can't be instantiated directly (use Serial or RawSerial)
switches 0:5c4d7b2438d3 39 *
switches 0:5c4d7b2438d3 40 * @Note Synchronization level: Set by subclass
switches 0:5c4d7b2438d3 41 */
switches 0:5c4d7b2438d3 42 class SerialBase {
switches 0:5c4d7b2438d3 43
switches 0:5c4d7b2438d3 44 public:
switches 0:5c4d7b2438d3 45 /** Set the baud rate of the serial port
switches 0:5c4d7b2438d3 46 *
switches 0:5c4d7b2438d3 47 * @param baudrate The baudrate of the serial port (default = 9600).
switches 0:5c4d7b2438d3 48 */
switches 0:5c4d7b2438d3 49 void baud(int baudrate);
switches 0:5c4d7b2438d3 50
switches 0:5c4d7b2438d3 51 enum Parity {
switches 0:5c4d7b2438d3 52 None = 0,
switches 0:5c4d7b2438d3 53 Odd,
switches 0:5c4d7b2438d3 54 Even,
switches 0:5c4d7b2438d3 55 Forced1,
switches 0:5c4d7b2438d3 56 Forced0
switches 0:5c4d7b2438d3 57 };
switches 0:5c4d7b2438d3 58
switches 0:5c4d7b2438d3 59 enum IrqType {
switches 0:5c4d7b2438d3 60 RxIrq = 0,
switches 0:5c4d7b2438d3 61 TxIrq,
switches 0:5c4d7b2438d3 62
switches 0:5c4d7b2438d3 63 IrqCnt
switches 0:5c4d7b2438d3 64 };
switches 0:5c4d7b2438d3 65
switches 0:5c4d7b2438d3 66 enum Flow {
switches 0:5c4d7b2438d3 67 Disabled = 0,
switches 0:5c4d7b2438d3 68 RTS,
switches 0:5c4d7b2438d3 69 CTS,
switches 0:5c4d7b2438d3 70 RTSCTS
switches 0:5c4d7b2438d3 71 };
switches 0:5c4d7b2438d3 72
switches 0:5c4d7b2438d3 73 /** Set the transmission format used by the serial port
switches 0:5c4d7b2438d3 74 *
switches 0:5c4d7b2438d3 75 * @param bits The number of bits in a word (5-8; default = 8)
switches 0:5c4d7b2438d3 76 * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
switches 0:5c4d7b2438d3 77 * @param stop The number of stop bits (1 or 2; default = 1)
switches 0:5c4d7b2438d3 78 */
switches 0:5c4d7b2438d3 79 void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1);
switches 0:5c4d7b2438d3 80
switches 0:5c4d7b2438d3 81 /** Determine if there is a character available to read
switches 0:5c4d7b2438d3 82 *
switches 0:5c4d7b2438d3 83 * @returns
switches 0:5c4d7b2438d3 84 * 1 if there is a character available to read,
switches 0:5c4d7b2438d3 85 * 0 otherwise
switches 0:5c4d7b2438d3 86 */
switches 0:5c4d7b2438d3 87 int readable();
switches 0:5c4d7b2438d3 88
switches 0:5c4d7b2438d3 89 /** Determine if there is space available to write a character
switches 0:5c4d7b2438d3 90 *
switches 0:5c4d7b2438d3 91 * @returns
switches 0:5c4d7b2438d3 92 * 1 if there is space to write a character,
switches 0:5c4d7b2438d3 93 * 0 otherwise
switches 0:5c4d7b2438d3 94 */
switches 0:5c4d7b2438d3 95 int writeable();
switches 0:5c4d7b2438d3 96
switches 0:5c4d7b2438d3 97 /** Attach a function to call whenever a serial interrupt is generated
switches 0:5c4d7b2438d3 98 *
switches 0:5c4d7b2438d3 99 * @param func A pointer to a void function, or 0 to set as none
switches 0:5c4d7b2438d3 100 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
switches 0:5c4d7b2438d3 101 */
switches 0:5c4d7b2438d3 102 void attach(Callback<void()> func, IrqType type=RxIrq);
switches 0:5c4d7b2438d3 103
switches 0:5c4d7b2438d3 104 /** Attach a member function to call whenever a serial interrupt is generated
switches 0:5c4d7b2438d3 105 *
switches 0:5c4d7b2438d3 106 * @param obj pointer to the object to call the member function on
switches 0:5c4d7b2438d3 107 * @param method pointer to the member function to be called
switches 0:5c4d7b2438d3 108 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
switches 0:5c4d7b2438d3 109 * @deprecated
switches 0:5c4d7b2438d3 110 * The attach function does not support cv-qualifiers. Replaced by
switches 0:5c4d7b2438d3 111 * attach(callback(obj, method), type).
switches 0:5c4d7b2438d3 112 */
switches 0:5c4d7b2438d3 113 template<typename T>
switches 0:5c4d7b2438d3 114 MBED_DEPRECATED_SINCE("mbed-os-5.1",
switches 0:5c4d7b2438d3 115 "The attach function does not support cv-qualifiers. Replaced by "
switches 0:5c4d7b2438d3 116 "attach(callback(obj, method), type).")
switches 0:5c4d7b2438d3 117 void attach(T *obj, void (T::*method)(), IrqType type=RxIrq) {
switches 0:5c4d7b2438d3 118 attach(callback(obj, method), type);
switches 0:5c4d7b2438d3 119 }
switches 0:5c4d7b2438d3 120
switches 0:5c4d7b2438d3 121 /** Attach a member function to call whenever a serial interrupt is generated
switches 0:5c4d7b2438d3 122 *
switches 0:5c4d7b2438d3 123 * @param obj pointer to the object to call the member function on
switches 0:5c4d7b2438d3 124 * @param method pointer to the member function to be called
switches 0:5c4d7b2438d3 125 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
switches 0:5c4d7b2438d3 126 * @deprecated
switches 0:5c4d7b2438d3 127 * The attach function does not support cv-qualifiers. Replaced by
switches 0:5c4d7b2438d3 128 * attach(callback(obj, method), type).
switches 0:5c4d7b2438d3 129 */
switches 0:5c4d7b2438d3 130 template<typename T>
switches 0:5c4d7b2438d3 131 MBED_DEPRECATED_SINCE("mbed-os-5.1",
switches 0:5c4d7b2438d3 132 "The attach function does not support cv-qualifiers. Replaced by "
switches 0:5c4d7b2438d3 133 "attach(callback(obj, method), type).")
switches 0:5c4d7b2438d3 134 void attach(T *obj, void (*method)(T*), IrqType type=RxIrq) {
switches 0:5c4d7b2438d3 135 attach(callback(obj, method), type);
switches 0:5c4d7b2438d3 136 }
switches 0:5c4d7b2438d3 137
switches 0:5c4d7b2438d3 138 /** Generate a break condition on the serial line
switches 0:5c4d7b2438d3 139 */
switches 0:5c4d7b2438d3 140 void send_break();
switches 0:5c4d7b2438d3 141
switches 0:5c4d7b2438d3 142 protected:
switches 0:5c4d7b2438d3 143
switches 0:5c4d7b2438d3 144 /** Acquire exclusive access to this serial port
switches 0:5c4d7b2438d3 145 */
switches 0:5c4d7b2438d3 146 virtual void lock(void);
switches 0:5c4d7b2438d3 147
switches 0:5c4d7b2438d3 148 /** Release exclusive access to this serial port
switches 0:5c4d7b2438d3 149 */
switches 0:5c4d7b2438d3 150 virtual void unlock(void);
switches 0:5c4d7b2438d3 151
switches 0:5c4d7b2438d3 152 public:
switches 0:5c4d7b2438d3 153
switches 0:5c4d7b2438d3 154 #if DEVICE_SERIAL_FC
switches 0:5c4d7b2438d3 155 /** Set the flow control type on the serial port
switches 0:5c4d7b2438d3 156 *
switches 0:5c4d7b2438d3 157 * @param type the flow control type (Disabled, RTS, CTS, RTSCTS)
switches 0:5c4d7b2438d3 158 * @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
switches 0:5c4d7b2438d3 159 * @param flow2 the second flow control pin (CTS for RTSCTS)
switches 0:5c4d7b2438d3 160 */
switches 0:5c4d7b2438d3 161 void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC);
switches 0:5c4d7b2438d3 162 #endif
switches 0:5c4d7b2438d3 163
switches 0:5c4d7b2438d3 164 static void _irq_handler(uint32_t id, SerialIrq irq_type);
switches 0:5c4d7b2438d3 165
switches 0:5c4d7b2438d3 166 #if DEVICE_SERIAL_ASYNCH
switches 0:5c4d7b2438d3 167
switches 0:5c4d7b2438d3 168 /** Begin asynchronous write using 8bit buffer. The completition invokes registered TX event callback
switches 0:5c4d7b2438d3 169 *
switches 0:5c4d7b2438d3 170 * @param buffer The buffer where received data will be stored
switches 0:5c4d7b2438d3 171 * @param length The buffer length in bytes
switches 0:5c4d7b2438d3 172 * @param callback The event callback function
switches 0:5c4d7b2438d3 173 * @param event The logical OR of TX events
switches 0:5c4d7b2438d3 174 */
switches 0:5c4d7b2438d3 175 int write(const uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
switches 0:5c4d7b2438d3 176
switches 0:5c4d7b2438d3 177 /** Begin asynchronous write using 16bit buffer. The completition invokes registered TX event callback
switches 0:5c4d7b2438d3 178 *
switches 0:5c4d7b2438d3 179 * @param buffer The buffer where received data will be stored
switches 0:5c4d7b2438d3 180 * @param length The buffer length in bytes
switches 0:5c4d7b2438d3 181 * @param callback The event callback function
switches 0:5c4d7b2438d3 182 * @param event The logical OR of TX events
switches 0:5c4d7b2438d3 183 */
switches 0:5c4d7b2438d3 184 int write(const uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
switches 0:5c4d7b2438d3 185
switches 0:5c4d7b2438d3 186 /** Abort the on-going write transfer
switches 0:5c4d7b2438d3 187 */
switches 0:5c4d7b2438d3 188 void abort_write();
switches 0:5c4d7b2438d3 189
switches 0:5c4d7b2438d3 190 /** Begin asynchronous reading using 8bit buffer. The completition invokes registred RX event callback.
switches 0:5c4d7b2438d3 191 *
switches 0:5c4d7b2438d3 192 * @param buffer The buffer where received data will be stored
switches 0:5c4d7b2438d3 193 * @param length The buffer length in bytes
switches 0:5c4d7b2438d3 194 * @param callback The event callback function
switches 0:5c4d7b2438d3 195 * @param event The logical OR of RX events
switches 0:5c4d7b2438d3 196 * @param char_match The matching character
switches 0:5c4d7b2438d3 197 */
switches 0:5c4d7b2438d3 198 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);
switches 0:5c4d7b2438d3 199
switches 0:5c4d7b2438d3 200 /** Begin asynchronous reading using 16bit buffer. The completition invokes registred RX event callback.
switches 0:5c4d7b2438d3 201 *
switches 0:5c4d7b2438d3 202 * @param buffer The buffer where received data will be stored
switches 0:5c4d7b2438d3 203 * @param length The buffer length in bytes
switches 0:5c4d7b2438d3 204 * @param callback The event callback function
switches 0:5c4d7b2438d3 205 * @param event The logical OR of RX events
switches 0:5c4d7b2438d3 206 * @param char_match The matching character
switches 0:5c4d7b2438d3 207 */
switches 0:5c4d7b2438d3 208 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);
switches 0:5c4d7b2438d3 209
switches 0:5c4d7b2438d3 210 /** Abort the on-going read transfer
switches 0:5c4d7b2438d3 211 */
switches 0:5c4d7b2438d3 212 void abort_read();
switches 0:5c4d7b2438d3 213
switches 0:5c4d7b2438d3 214 /** Configure DMA usage suggestion for non-blocking TX transfers
switches 0:5c4d7b2438d3 215 *
switches 0:5c4d7b2438d3 216 * @param usage The usage DMA hint for peripheral
switches 0:5c4d7b2438d3 217 * @return Zero if the usage was set, -1 if a transaction is on-going
switches 0:5c4d7b2438d3 218 */
switches 0:5c4d7b2438d3 219 int set_dma_usage_tx(DMAUsage usage);
switches 0:5c4d7b2438d3 220
switches 0:5c4d7b2438d3 221 /** Configure DMA usage suggestion for non-blocking RX transfers
switches 0:5c4d7b2438d3 222 *
switches 0:5c4d7b2438d3 223 * @param usage The usage DMA hint for peripheral
switches 0:5c4d7b2438d3 224 * @return Zero if the usage was set, -1 if a transaction is on-going
switches 0:5c4d7b2438d3 225 */
switches 0:5c4d7b2438d3 226 int set_dma_usage_rx(DMAUsage usage);
switches 0:5c4d7b2438d3 227
switches 0:5c4d7b2438d3 228 protected:
switches 0:5c4d7b2438d3 229 void start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event, unsigned char char_match);
switches 0:5c4d7b2438d3 230 void start_write(const void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event);
switches 0:5c4d7b2438d3 231 void interrupt_handler_asynch(void);
switches 0:5c4d7b2438d3 232 #endif
switches 0:5c4d7b2438d3 233
switches 0:5c4d7b2438d3 234 protected:
switches 0:5c4d7b2438d3 235 SerialBase(PinName tx, PinName rx, int baud);
switches 0:5c4d7b2438d3 236 virtual ~SerialBase() {
switches 0:5c4d7b2438d3 237 }
switches 0:5c4d7b2438d3 238
switches 0:5c4d7b2438d3 239 int _base_getc();
switches 0:5c4d7b2438d3 240 int _base_putc(int c);
switches 0:5c4d7b2438d3 241
switches 0:5c4d7b2438d3 242 #if DEVICE_SERIAL_ASYNCH
switches 0:5c4d7b2438d3 243 CThunk<SerialBase> _thunk_irq;
switches 0:5c4d7b2438d3 244 event_callback_t _tx_callback;
switches 0:5c4d7b2438d3 245 event_callback_t _rx_callback;
switches 0:5c4d7b2438d3 246 DMAUsage _tx_usage;
switches 0:5c4d7b2438d3 247 DMAUsage _rx_usage;
switches 0:5c4d7b2438d3 248 #endif
switches 0:5c4d7b2438d3 249
switches 0:5c4d7b2438d3 250 serial_t _serial;
switches 0:5c4d7b2438d3 251 Callback<void()> _irq[IrqCnt];
switches 0:5c4d7b2438d3 252 int _baud;
switches 0:5c4d7b2438d3 253
switches 0:5c4d7b2438d3 254 };
switches 0:5c4d7b2438d3 255
switches 0:5c4d7b2438d3 256 } // namespace mbed
switches 0:5c4d7b2438d3 257
switches 0:5c4d7b2438d3 258 #endif
switches 0:5c4d7b2438d3 259
switches 0:5c4d7b2438d3 260 #endif
switches 0:5c4d7b2438d3 261
switches 0:5c4d7b2438d3 262 /** @}*/