PokittoLib with changes to lcd refresh etc.

Dependents:   Pokittris

Fork of Pokitto by Pokitto Community Team

This is a fork by user @Spinal, and is used in Pokittris for testing. Do not import this to your own program.

Committer:
Pokitto
Date:
Sat Oct 07 21:31:12 2017 +0000
Revision:
5:7e5c566b1760
mbed-pokitto integrated

Who changed what in which revision?

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