5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
jacobjohnson
Date:
Mon Feb 27 17:45:05 2017 +0000
Revision:
1:f30bdcd2b33b
Parent:
0:098463de4c5d
changed the inputscale from 1 to 7 in analogin_api.c.  This will need to be changed later, and accessed from the main level, but for now this allows the  adc to read a value from 0 to 3.7V, instead of just up to 1V.;

Who changed what in which revision?

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