PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Dependents:   Sensitive

Fork of PokittoLib by Jonne Valola

Committer:
spinal
Date:
Wed Oct 18 14:47:54 2017 +0000
Revision:
15:0bbe8f6fae32
Parent:
6:ea7377f3d1af
direct lcd stuff used by sensitive

Who changed what in which revision?

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