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
switches 0:5c4d7b2438d3 2 /** \addtogroup hal */
switches 0:5c4d7b2438d3 3 /** @{*/
switches 0:5c4d7b2438d3 4 /* mbed Microcontroller Library
switches 0:5c4d7b2438d3 5 * Copyright (c) 2006-2013 ARM Limited
switches 0:5c4d7b2438d3 6 *
switches 0:5c4d7b2438d3 7 * Licensed under the Apache License, Version 2.0 (the "License");
switches 0:5c4d7b2438d3 8 * you may not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 9 * You may obtain a copy of the License at
switches 0:5c4d7b2438d3 10 *
switches 0:5c4d7b2438d3 11 * http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 12 *
switches 0:5c4d7b2438d3 13 * Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 14 * distributed under the License is distributed on an "AS IS" BASIS,
switches 0:5c4d7b2438d3 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 16 * See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 17 * limitations under the License.
switches 0:5c4d7b2438d3 18 */
switches 0:5c4d7b2438d3 19 #ifndef MBED_SERIAL_API_H
switches 0:5c4d7b2438d3 20 #define MBED_SERIAL_API_H
switches 0:5c4d7b2438d3 21
switches 0:5c4d7b2438d3 22 #include "device.h"
switches 0:5c4d7b2438d3 23 #include "hal/buffer.h"
switches 0:5c4d7b2438d3 24 #include "hal/dma_api.h"
switches 0:5c4d7b2438d3 25
switches 0:5c4d7b2438d3 26 #if DEVICE_SERIAL
switches 0:5c4d7b2438d3 27
switches 0:5c4d7b2438d3 28 #define SERIAL_EVENT_TX_SHIFT (2)
switches 0:5c4d7b2438d3 29 #define SERIAL_EVENT_RX_SHIFT (8)
switches 0:5c4d7b2438d3 30
switches 0:5c4d7b2438d3 31 #define SERIAL_EVENT_TX_MASK (0x00FC)
switches 0:5c4d7b2438d3 32 #define SERIAL_EVENT_RX_MASK (0x3F00)
switches 0:5c4d7b2438d3 33
switches 0:5c4d7b2438d3 34 #define SERIAL_EVENT_ERROR (1 << 1)
switches 0:5c4d7b2438d3 35
switches 0:5c4d7b2438d3 36 /**
switches 0:5c4d7b2438d3 37 * @defgroup SerialTXEvents Serial TX Events Macros
switches 0:5c4d7b2438d3 38 *
switches 0:5c4d7b2438d3 39 * @{
switches 0:5c4d7b2438d3 40 */
switches 0:5c4d7b2438d3 41 #define SERIAL_EVENT_TX_COMPLETE (1 << (SERIAL_EVENT_TX_SHIFT + 0))
switches 0:5c4d7b2438d3 42 #define SERIAL_EVENT_TX_ALL (SERIAL_EVENT_TX_COMPLETE)
switches 0:5c4d7b2438d3 43 /**@}*/
switches 0:5c4d7b2438d3 44
switches 0:5c4d7b2438d3 45 /**
switches 0:5c4d7b2438d3 46 * @defgroup SerialRXEvents Serial RX Events Macros
switches 0:5c4d7b2438d3 47 *
switches 0:5c4d7b2438d3 48 * @{
switches 0:5c4d7b2438d3 49 */
switches 0:5c4d7b2438d3 50 #define SERIAL_EVENT_RX_COMPLETE (1 << (SERIAL_EVENT_RX_SHIFT + 0))
switches 0:5c4d7b2438d3 51 #define SERIAL_EVENT_RX_OVERRUN_ERROR (1 << (SERIAL_EVENT_RX_SHIFT + 1))
switches 0:5c4d7b2438d3 52 #define SERIAL_EVENT_RX_FRAMING_ERROR (1 << (SERIAL_EVENT_RX_SHIFT + 2))
switches 0:5c4d7b2438d3 53 #define SERIAL_EVENT_RX_PARITY_ERROR (1 << (SERIAL_EVENT_RX_SHIFT + 3))
switches 0:5c4d7b2438d3 54 #define SERIAL_EVENT_RX_OVERFLOW (1 << (SERIAL_EVENT_RX_SHIFT + 4))
switches 0:5c4d7b2438d3 55 #define SERIAL_EVENT_RX_CHARACTER_MATCH (1 << (SERIAL_EVENT_RX_SHIFT + 5))
switches 0:5c4d7b2438d3 56 #define SERIAL_EVENT_RX_ALL (SERIAL_EVENT_RX_OVERFLOW | SERIAL_EVENT_RX_PARITY_ERROR | \
switches 0:5c4d7b2438d3 57 SERIAL_EVENT_RX_FRAMING_ERROR | SERIAL_EVENT_RX_OVERRUN_ERROR | \
switches 0:5c4d7b2438d3 58 SERIAL_EVENT_RX_COMPLETE | SERIAL_EVENT_RX_CHARACTER_MATCH)
switches 0:5c4d7b2438d3 59 /**@}*/
switches 0:5c4d7b2438d3 60
switches 0:5c4d7b2438d3 61 #define SERIAL_RESERVED_CHAR_MATCH (255)
switches 0:5c4d7b2438d3 62
switches 0:5c4d7b2438d3 63 typedef enum {
switches 0:5c4d7b2438d3 64 ParityNone = 0,
switches 0:5c4d7b2438d3 65 ParityOdd = 1,
switches 0:5c4d7b2438d3 66 ParityEven = 2,
switches 0:5c4d7b2438d3 67 ParityForced1 = 3,
switches 0:5c4d7b2438d3 68 ParityForced0 = 4
switches 0:5c4d7b2438d3 69 } SerialParity;
switches 0:5c4d7b2438d3 70
switches 0:5c4d7b2438d3 71 typedef enum {
switches 0:5c4d7b2438d3 72 RxIrq,
switches 0:5c4d7b2438d3 73 TxIrq
switches 0:5c4d7b2438d3 74 } SerialIrq;
switches 0:5c4d7b2438d3 75
switches 0:5c4d7b2438d3 76 typedef enum {
switches 0:5c4d7b2438d3 77 FlowControlNone,
switches 0:5c4d7b2438d3 78 FlowControlRTS,
switches 0:5c4d7b2438d3 79 FlowControlCTS,
switches 0:5c4d7b2438d3 80 FlowControlRTSCTS
switches 0:5c4d7b2438d3 81 } FlowControl;
switches 0:5c4d7b2438d3 82
switches 0:5c4d7b2438d3 83 typedef void (*uart_irq_handler)(uint32_t id, SerialIrq event);
switches 0:5c4d7b2438d3 84
switches 0:5c4d7b2438d3 85 #if DEVICE_SERIAL_ASYNCH
switches 0:5c4d7b2438d3 86 /** Asynch serial HAL structure
switches 0:5c4d7b2438d3 87 */
switches 0:5c4d7b2438d3 88 typedef struct {
switches 0:5c4d7b2438d3 89 struct serial_s serial; /**< Target specific serial structure */
switches 0:5c4d7b2438d3 90 struct buffer_s tx_buff; /**< TX buffer */
switches 0:5c4d7b2438d3 91 struct buffer_s rx_buff; /**< RX buffer */
switches 0:5c4d7b2438d3 92 uint8_t char_match; /**< Character to be matched */
switches 0:5c4d7b2438d3 93 uint8_t char_found; /**< State of the matched character */
switches 0:5c4d7b2438d3 94 } serial_t;
switches 0:5c4d7b2438d3 95
switches 0:5c4d7b2438d3 96 #else
switches 0:5c4d7b2438d3 97 /** Non-asynch serial HAL structure
switches 0:5c4d7b2438d3 98 */
switches 0:5c4d7b2438d3 99 typedef struct serial_s serial_t;
switches 0:5c4d7b2438d3 100
switches 0:5c4d7b2438d3 101 #endif
switches 0:5c4d7b2438d3 102
switches 0:5c4d7b2438d3 103 #ifdef __cplusplus
switches 0:5c4d7b2438d3 104 extern "C" {
switches 0:5c4d7b2438d3 105 #endif
switches 0:5c4d7b2438d3 106
switches 0:5c4d7b2438d3 107 /**
switches 0:5c4d7b2438d3 108 * \defgroup hal_GeneralSerial Serial Configuration Functions
switches 0:5c4d7b2438d3 109 * @{
switches 0:5c4d7b2438d3 110 */
switches 0:5c4d7b2438d3 111
switches 0:5c4d7b2438d3 112 /** Initialize the serial peripheral. It sets the default parameters for serial
switches 0:5c4d7b2438d3 113 * peripheral, and configures its specifieds pins.
switches 0:5c4d7b2438d3 114 *
switches 0:5c4d7b2438d3 115 * @param obj The serial object
switches 0:5c4d7b2438d3 116 * @param tx The TX pin name
switches 0:5c4d7b2438d3 117 * @param rx The RX pin name
switches 0:5c4d7b2438d3 118 */
switches 0:5c4d7b2438d3 119 void serial_init(serial_t *obj, PinName tx, PinName rx);
switches 0:5c4d7b2438d3 120
switches 0:5c4d7b2438d3 121 /** Release the serial peripheral, not currently invoked. It requires further
switches 0:5c4d7b2438d3 122 * resource management.
switches 0:5c4d7b2438d3 123 *
switches 0:5c4d7b2438d3 124 * @param obj The serial object
switches 0:5c4d7b2438d3 125 */
switches 0:5c4d7b2438d3 126 void serial_free(serial_t *obj);
switches 0:5c4d7b2438d3 127
switches 0:5c4d7b2438d3 128 /** Configure the baud rate
switches 0:5c4d7b2438d3 129 *
switches 0:5c4d7b2438d3 130 * @param obj The serial object
switches 0:5c4d7b2438d3 131 * @param baudrate The baud rate to be configured
switches 0:5c4d7b2438d3 132 */
switches 0:5c4d7b2438d3 133 void serial_baud(serial_t *obj, int baudrate);
switches 0:5c4d7b2438d3 134
switches 0:5c4d7b2438d3 135 /** Configure the format. Set the number of bits, parity and the number of stop bits
switches 0:5c4d7b2438d3 136 *
switches 0:5c4d7b2438d3 137 * @param obj The serial object
switches 0:5c4d7b2438d3 138 * @param data_bits The number of data bits
switches 0:5c4d7b2438d3 139 * @param parity The parity
switches 0:5c4d7b2438d3 140 * @param stop_bits The number of stop bits
switches 0:5c4d7b2438d3 141 */
switches 0:5c4d7b2438d3 142 void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits);
switches 0:5c4d7b2438d3 143
switches 0:5c4d7b2438d3 144 /** The serial interrupt handler registration
switches 0:5c4d7b2438d3 145 *
switches 0:5c4d7b2438d3 146 * @param obj The serial object
switches 0:5c4d7b2438d3 147 * @param handler The interrupt handler which will be invoked when the interrupt fires
switches 0:5c4d7b2438d3 148 * @param id The SerialBase object
switches 0:5c4d7b2438d3 149 */
switches 0:5c4d7b2438d3 150 void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id);
switches 0:5c4d7b2438d3 151
switches 0:5c4d7b2438d3 152 /** Configure serial interrupt. This function is used for word-approach
switches 0:5c4d7b2438d3 153 *
switches 0:5c4d7b2438d3 154 * @param obj The serial object
switches 0:5c4d7b2438d3 155 * @param irq The serial IRQ type (RX or TX)
switches 0:5c4d7b2438d3 156 * @param enable Set to non-zero to enable events, or zero to disable them
switches 0:5c4d7b2438d3 157 */
switches 0:5c4d7b2438d3 158 void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable);
switches 0:5c4d7b2438d3 159
switches 0:5c4d7b2438d3 160 /** Get character. This is a blocking call, waiting for a character
switches 0:5c4d7b2438d3 161 *
switches 0:5c4d7b2438d3 162 * @param obj The serial object
switches 0:5c4d7b2438d3 163 */
switches 0:5c4d7b2438d3 164 int serial_getc(serial_t *obj);
switches 0:5c4d7b2438d3 165
switches 0:5c4d7b2438d3 166 /** Send a character. This is a blocking call, waiting for a peripheral to be available
switches 0:5c4d7b2438d3 167 * for writing
switches 0:5c4d7b2438d3 168 *
switches 0:5c4d7b2438d3 169 * @param obj The serial object
switches 0:5c4d7b2438d3 170 * @param c The character to be sent
switches 0:5c4d7b2438d3 171 */
switches 0:5c4d7b2438d3 172 void serial_putc(serial_t *obj, int c);
switches 0:5c4d7b2438d3 173
switches 0:5c4d7b2438d3 174 /** Check if the serial peripheral is readable
switches 0:5c4d7b2438d3 175 *
switches 0:5c4d7b2438d3 176 * @param obj The serial object
switches 0:5c4d7b2438d3 177 * @return Non-zero value if a character can be read, 0 if nothing to read
switches 0:5c4d7b2438d3 178 */
switches 0:5c4d7b2438d3 179 int serial_readable(serial_t *obj);
switches 0:5c4d7b2438d3 180
switches 0:5c4d7b2438d3 181 /** Check if the serial peripheral is writable
switches 0:5c4d7b2438d3 182 *
switches 0:5c4d7b2438d3 183 * @param obj The serial object
switches 0:5c4d7b2438d3 184 * @return Non-zero value if a character can be written, 0 otherwise.
switches 0:5c4d7b2438d3 185 */
switches 0:5c4d7b2438d3 186 int serial_writable(serial_t *obj);
switches 0:5c4d7b2438d3 187
switches 0:5c4d7b2438d3 188 /** Clear the serial peripheral
switches 0:5c4d7b2438d3 189 *
switches 0:5c4d7b2438d3 190 * @param obj The serial object
switches 0:5c4d7b2438d3 191 */
switches 0:5c4d7b2438d3 192 void serial_clear(serial_t *obj);
switches 0:5c4d7b2438d3 193
switches 0:5c4d7b2438d3 194 /** Set the break
switches 0:5c4d7b2438d3 195 *
switches 0:5c4d7b2438d3 196 * @param obj The serial object
switches 0:5c4d7b2438d3 197 */
switches 0:5c4d7b2438d3 198 void serial_break_set(serial_t *obj);
switches 0:5c4d7b2438d3 199
switches 0:5c4d7b2438d3 200 /** Clear the break
switches 0:5c4d7b2438d3 201 *
switches 0:5c4d7b2438d3 202 * @param obj The serial object
switches 0:5c4d7b2438d3 203 */
switches 0:5c4d7b2438d3 204 void serial_break_clear(serial_t *obj);
switches 0:5c4d7b2438d3 205
switches 0:5c4d7b2438d3 206 /** Configure the TX pin for UART function.
switches 0:5c4d7b2438d3 207 *
switches 0:5c4d7b2438d3 208 * @param tx The pin name used for TX
switches 0:5c4d7b2438d3 209 */
switches 0:5c4d7b2438d3 210 void serial_pinout_tx(PinName tx);
switches 0:5c4d7b2438d3 211
switches 0:5c4d7b2438d3 212 /** Configure the serial for the flow control. It sets flow control in the hardware
switches 0:5c4d7b2438d3 213 * if a serial peripheral supports it, otherwise software emulation is used.
switches 0:5c4d7b2438d3 214 *
switches 0:5c4d7b2438d3 215 * @param obj The serial object
switches 0:5c4d7b2438d3 216 * @param type The type of the flow control. Look at the available FlowControl types.
switches 0:5c4d7b2438d3 217 * @param rxflow The TX pin name
switches 0:5c4d7b2438d3 218 * @param txflow The RX pin name
switches 0:5c4d7b2438d3 219 */
switches 0:5c4d7b2438d3 220 void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow);
switches 0:5c4d7b2438d3 221
switches 0:5c4d7b2438d3 222 #if DEVICE_SERIAL_ASYNCH
switches 0:5c4d7b2438d3 223
switches 0:5c4d7b2438d3 224 /**@}*/
switches 0:5c4d7b2438d3 225
switches 0:5c4d7b2438d3 226 /**
switches 0:5c4d7b2438d3 227 * \defgroup hal_AsynchSerial Asynchronous Serial Hardware Abstraction Layer
switches 0:5c4d7b2438d3 228 * @{
switches 0:5c4d7b2438d3 229 */
switches 0:5c4d7b2438d3 230
switches 0:5c4d7b2438d3 231 /** Begin asynchronous TX transfer. The used buffer is specified in the serial object,
switches 0:5c4d7b2438d3 232 * tx_buff
switches 0:5c4d7b2438d3 233 *
switches 0:5c4d7b2438d3 234 * @param obj The serial object
switches 0:5c4d7b2438d3 235 * @param tx The transmit buffer
switches 0:5c4d7b2438d3 236 * @param tx_length The number of bytes to transmit
switches 0:5c4d7b2438d3 237 * @param tx_width Deprecated argument
switches 0:5c4d7b2438d3 238 * @param handler The serial handler
switches 0:5c4d7b2438d3 239 * @param event The logical OR of events to be registered
switches 0:5c4d7b2438d3 240 * @param hint A suggestion for how to use DMA with this transfer
switches 0:5c4d7b2438d3 241 * @return Returns number of data transfered, otherwise returns 0
switches 0:5c4d7b2438d3 242 */
switches 0:5c4d7b2438d3 243 int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint);
switches 0:5c4d7b2438d3 244
switches 0:5c4d7b2438d3 245 /** Begin asynchronous RX transfer (enable interrupt for data collecting)
switches 0:5c4d7b2438d3 246 * The used buffer is specified in the serial object - rx_buff
switches 0:5c4d7b2438d3 247 *
switches 0:5c4d7b2438d3 248 * @param obj The serial object
switches 0:5c4d7b2438d3 249 * @param rx The receive buffer
switches 0:5c4d7b2438d3 250 * @param rx_length The number of bytes to receive
switches 0:5c4d7b2438d3 251 * @param rx_width Deprecated argument
switches 0:5c4d7b2438d3 252 * @param handler The serial handler
switches 0:5c4d7b2438d3 253 * @param event The logical OR of events to be registered
switches 0:5c4d7b2438d3 254 * @param handler The serial handler
switches 0:5c4d7b2438d3 255 * @param char_match A character in range 0-254 to be matched
switches 0:5c4d7b2438d3 256 * @param hint A suggestion for how to use DMA with this transfer
switches 0:5c4d7b2438d3 257 */
switches 0:5c4d7b2438d3 258 void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_width, uint32_t handler, uint32_t event, uint8_t char_match, DMAUsage hint);
switches 0:5c4d7b2438d3 259
switches 0:5c4d7b2438d3 260 /** Attempts to determine if the serial peripheral is already in use for TX
switches 0:5c4d7b2438d3 261 *
switches 0:5c4d7b2438d3 262 * @param obj The serial object
switches 0:5c4d7b2438d3 263 * @return Non-zero if the RX transaction is ongoing, 0 otherwise
switches 0:5c4d7b2438d3 264 */
switches 0:5c4d7b2438d3 265 uint8_t serial_tx_active(serial_t *obj);
switches 0:5c4d7b2438d3 266
switches 0:5c4d7b2438d3 267 /** Attempts to determine if the serial peripheral is already in use for RX
switches 0:5c4d7b2438d3 268 *
switches 0:5c4d7b2438d3 269 * @param obj The serial object
switches 0:5c4d7b2438d3 270 * @return Non-zero if the RX transaction is ongoing, 0 otherwise
switches 0:5c4d7b2438d3 271 */
switches 0:5c4d7b2438d3 272 uint8_t serial_rx_active(serial_t *obj);
switches 0:5c4d7b2438d3 273
switches 0:5c4d7b2438d3 274 /** The asynchronous TX and RX handler.
switches 0:5c4d7b2438d3 275 *
switches 0:5c4d7b2438d3 276 * @param obj The serial object
switches 0:5c4d7b2438d3 277 * @return Returns event flags if an RX transfer termination condition was met; otherwise returns 0
switches 0:5c4d7b2438d3 278 */
switches 0:5c4d7b2438d3 279 int serial_irq_handler_asynch(serial_t *obj);
switches 0:5c4d7b2438d3 280
switches 0:5c4d7b2438d3 281 /** Abort the ongoing TX transaction. It disables the enabled interupt for TX and
switches 0:5c4d7b2438d3 282 * flushes the TX hardware buffer if TX FIFO is used
switches 0:5c4d7b2438d3 283 *
switches 0:5c4d7b2438d3 284 * @param obj The serial object
switches 0:5c4d7b2438d3 285 */
switches 0:5c4d7b2438d3 286 void serial_tx_abort_asynch(serial_t *obj);
switches 0:5c4d7b2438d3 287
switches 0:5c4d7b2438d3 288 /** Abort the ongoing RX transaction. It disables the enabled interrupt for RX and
switches 0:5c4d7b2438d3 289 * flushes the RX hardware buffer if RX FIFO is used
switches 0:5c4d7b2438d3 290 *
switches 0:5c4d7b2438d3 291 * @param obj The serial object
switches 0:5c4d7b2438d3 292 */
switches 0:5c4d7b2438d3 293 void serial_rx_abort_asynch(serial_t *obj);
switches 0:5c4d7b2438d3 294
switches 0:5c4d7b2438d3 295 /**@}*/
switches 0:5c4d7b2438d3 296
switches 0:5c4d7b2438d3 297 #endif
switches 0:5c4d7b2438d3 298
switches 0:5c4d7b2438d3 299 #ifdef __cplusplus
switches 0:5c4d7b2438d3 300 }
switches 0:5c4d7b2438d3 301 #endif
switches 0:5c4d7b2438d3 302
switches 0:5c4d7b2438d3 303 #endif
switches 0:5c4d7b2438d3 304
switches 0:5c4d7b2438d3 305 #endif
switches 0:5c4d7b2438d3 306
switches 0:5c4d7b2438d3 307 /** @}*/