The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
<>
Date:
Thu Oct 27 16:45:56 2016 +0100
Revision:
128:9bcdf88f62b0
Child:
132:9baf128c2fab
Release 128 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

2966: Add kw24 support https://github.com/ARMmbed/mbed-os/pull/2966
3068: MultiTech mDot - clean up PeripheralPins.c and add new pin names https://github.com/ARMmbed/mbed-os/pull/3068
3089: Kinetis HAL: Remove clock initialization code from serial and ticker https://github.com/ARMmbed/mbed-os/pull/3089
2943: [NRF5] NVIC_SetVector functionality https://github.com/ARMmbed/mbed-os/pull/2943
2938: InterruptIn changes in NCS36510 HAL. https://github.com/ARMmbed/mbed-os/pull/2938
3108: Fix sleep function for NRF52. https://github.com/ARMmbed/mbed-os/pull/3108
3076: STM32F1: Correct timer master value reading https://github.com/ARMmbed/mbed-os/pull/3076
3085: Add LOWPOWERTIMER capability for NUCLEO_F303ZE https://github.com/ARMmbed/mbed-os/pull/3085
3046: [BEETLE] Update BLE stack on Beetle board https://github.com/ARMmbed/mbed-os/pull/3046
3122: [Silicon Labs] Update of Silicon Labs HAL https://github.com/ARMmbed/mbed-os/pull/3122
3022: OnSemi RAM usage fix https://github.com/ARMmbed/mbed-os/pull/3022
3121: STM32F3: Correct UART4 and UART5 defines when using DEVICE_SERIAL_ASYNCH https://github.com/ARMmbed/mbed-os/pull/3121
3142: Targets- NUMAKER_PFM_NUC47216 remove mbed 2 https://github.com/ARMmbed/mbed-os/pull/3142

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 128:9bcdf88f62b0 1
<> 128:9bcdf88f62b0 2 /** \addtogroup hal */
<> 128:9bcdf88f62b0 3 /** @{*/
<> 128:9bcdf88f62b0 4 /* mbed Microcontroller Library
<> 128:9bcdf88f62b0 5 * Copyright (c) 2006-2015 ARM Limited
<> 128:9bcdf88f62b0 6 *
<> 128:9bcdf88f62b0 7 * Licensed under the Apache License, Version 2.0 (the "License");
<> 128:9bcdf88f62b0 8 * you may not use this file except in compliance with the License.
<> 128:9bcdf88f62b0 9 * You may obtain a copy of the License at
<> 128:9bcdf88f62b0 10 *
<> 128:9bcdf88f62b0 11 * http://www.apache.org/licenses/LICENSE-2.0
<> 128:9bcdf88f62b0 12 *
<> 128:9bcdf88f62b0 13 * Unless required by applicable law or agreed to in writing, software
<> 128:9bcdf88f62b0 14 * distributed under the License is distributed on an "AS IS" BASIS,
<> 128:9bcdf88f62b0 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 128:9bcdf88f62b0 16 * See the License for the specific language governing permissions and
<> 128:9bcdf88f62b0 17 * limitations under the License.
<> 128:9bcdf88f62b0 18 */
<> 128:9bcdf88f62b0 19 #ifndef MBED_I2C_API_H
<> 128:9bcdf88f62b0 20 #define MBED_I2C_API_H
<> 128:9bcdf88f62b0 21
<> 128:9bcdf88f62b0 22 #include "device.h"
<> 128:9bcdf88f62b0 23 #include "hal/buffer.h"
<> 128:9bcdf88f62b0 24
<> 128:9bcdf88f62b0 25 #if DEVICE_I2C_ASYNCH
<> 128:9bcdf88f62b0 26 #include "hal/dma_api.h"
<> 128:9bcdf88f62b0 27 #endif
<> 128:9bcdf88f62b0 28
<> 128:9bcdf88f62b0 29 #if DEVICE_I2C
<> 128:9bcdf88f62b0 30
<> 128:9bcdf88f62b0 31 /**
<> 128:9bcdf88f62b0 32 * @defgroup hal_I2CEvents I2C Events Macros
<> 128:9bcdf88f62b0 33 *
<> 128:9bcdf88f62b0 34 * @{
<> 128:9bcdf88f62b0 35 */
<> 128:9bcdf88f62b0 36 #define I2C_EVENT_ERROR (1 << 1)
<> 128:9bcdf88f62b0 37 #define I2C_EVENT_ERROR_NO_SLAVE (1 << 2)
<> 128:9bcdf88f62b0 38 #define I2C_EVENT_TRANSFER_COMPLETE (1 << 3)
<> 128:9bcdf88f62b0 39 #define I2C_EVENT_TRANSFER_EARLY_NACK (1 << 4)
<> 128:9bcdf88f62b0 40 #define I2C_EVENT_ALL (I2C_EVENT_ERROR | I2C_EVENT_TRANSFER_COMPLETE | I2C_EVENT_ERROR_NO_SLAVE | I2C_EVENT_TRANSFER_EARLY_NACK)
<> 128:9bcdf88f62b0 41
<> 128:9bcdf88f62b0 42 /**@}*/
<> 128:9bcdf88f62b0 43
<> 128:9bcdf88f62b0 44 #if DEVICE_I2C_ASYNCH
<> 128:9bcdf88f62b0 45 /** Asynch I2C HAL structure
<> 128:9bcdf88f62b0 46 */
<> 128:9bcdf88f62b0 47 typedef struct {
<> 128:9bcdf88f62b0 48 struct i2c_s i2c; /**< Target specific I2C structure */
<> 128:9bcdf88f62b0 49 struct buffer_s tx_buff; /**< Tx buffer */
<> 128:9bcdf88f62b0 50 struct buffer_s rx_buff; /**< Rx buffer */
<> 128:9bcdf88f62b0 51 } i2c_t;
<> 128:9bcdf88f62b0 52
<> 128:9bcdf88f62b0 53 #else
<> 128:9bcdf88f62b0 54 /** Non-asynch I2C HAL structure
<> 128:9bcdf88f62b0 55 */
<> 128:9bcdf88f62b0 56 typedef struct i2c_s i2c_t;
<> 128:9bcdf88f62b0 57
<> 128:9bcdf88f62b0 58 #endif
<> 128:9bcdf88f62b0 59
<> 128:9bcdf88f62b0 60 enum {
<> 128:9bcdf88f62b0 61 I2C_ERROR_NO_SLAVE = -1,
<> 128:9bcdf88f62b0 62 I2C_ERROR_BUS_BUSY = -2
<> 128:9bcdf88f62b0 63 };
<> 128:9bcdf88f62b0 64
<> 128:9bcdf88f62b0 65 #ifdef __cplusplus
<> 128:9bcdf88f62b0 66 extern "C" {
<> 128:9bcdf88f62b0 67 #endif
<> 128:9bcdf88f62b0 68
<> 128:9bcdf88f62b0 69 /**
<> 128:9bcdf88f62b0 70 * \defgroup hal_GeneralI2C I2C Configuration Functions
<> 128:9bcdf88f62b0 71 * @{
<> 128:9bcdf88f62b0 72 */
<> 128:9bcdf88f62b0 73
<> 128:9bcdf88f62b0 74 /** Initialize the I2C peripheral. It sets the default parameters for I2C
<> 128:9bcdf88f62b0 75 * peripheral, and configures its specifieds pins.
<> 128:9bcdf88f62b0 76 *
<> 128:9bcdf88f62b0 77 * @param obj The I2C object
<> 128:9bcdf88f62b0 78 * @param sda The sda pin
<> 128:9bcdf88f62b0 79 * @param scl The scl pin
<> 128:9bcdf88f62b0 80 */
<> 128:9bcdf88f62b0 81 void i2c_init(i2c_t *obj, PinName sda, PinName scl);
<> 128:9bcdf88f62b0 82
<> 128:9bcdf88f62b0 83 /** Configure the I2C frequency
<> 128:9bcdf88f62b0 84 *
<> 128:9bcdf88f62b0 85 * @param obj The I2C object
<> 128:9bcdf88f62b0 86 * @param hz Frequency in Hz
<> 128:9bcdf88f62b0 87 */
<> 128:9bcdf88f62b0 88 void i2c_frequency(i2c_t *obj, int hz);
<> 128:9bcdf88f62b0 89
<> 128:9bcdf88f62b0 90 /** Send START command
<> 128:9bcdf88f62b0 91 *
<> 128:9bcdf88f62b0 92 * @param obj The I2C object
<> 128:9bcdf88f62b0 93 */
<> 128:9bcdf88f62b0 94 int i2c_start(i2c_t *obj);
<> 128:9bcdf88f62b0 95
<> 128:9bcdf88f62b0 96 /** Send STOP command
<> 128:9bcdf88f62b0 97 *
<> 128:9bcdf88f62b0 98 * @param obj The I2C object
<> 128:9bcdf88f62b0 99 */
<> 128:9bcdf88f62b0 100 int i2c_stop(i2c_t *obj);
<> 128:9bcdf88f62b0 101
<> 128:9bcdf88f62b0 102 /** Blocking reading data
<> 128:9bcdf88f62b0 103 *
<> 128:9bcdf88f62b0 104 * @param obj The I2C object
<> 128:9bcdf88f62b0 105 * @param address 7-bit address (last bit is 1)
<> 128:9bcdf88f62b0 106 * @param data The buffer for receiving
<> 128:9bcdf88f62b0 107 * @param length Number of bytes to read
<> 128:9bcdf88f62b0 108 * @param stop Stop to be generated after the transfer is done
<> 128:9bcdf88f62b0 109 * @return Number of read bytes
<> 128:9bcdf88f62b0 110 */
<> 128:9bcdf88f62b0 111 int i2c_read(i2c_t *obj, int address, char *data, int length, int stop);
<> 128:9bcdf88f62b0 112
<> 128:9bcdf88f62b0 113 /** Blocking sending data
<> 128:9bcdf88f62b0 114 *
<> 128:9bcdf88f62b0 115 * @param obj The I2C object
<> 128:9bcdf88f62b0 116 * @param address 7-bit address (last bit is 0)
<> 128:9bcdf88f62b0 117 * @param data The buffer for sending
<> 128:9bcdf88f62b0 118 * @param length Number of bytes to write
<> 128:9bcdf88f62b0 119 * @param stop Stop to be generated after the transfer is done
<> 128:9bcdf88f62b0 120 * @return Number of written bytes
<> 128:9bcdf88f62b0 121 */
<> 128:9bcdf88f62b0 122 int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop);
<> 128:9bcdf88f62b0 123
<> 128:9bcdf88f62b0 124 /** Reset I2C peripheral. TODO: The action here. Most of the implementation sends stop()
<> 128:9bcdf88f62b0 125 *
<> 128:9bcdf88f62b0 126 * @param obj The I2C object
<> 128:9bcdf88f62b0 127 */
<> 128:9bcdf88f62b0 128 void i2c_reset(i2c_t *obj);
<> 128:9bcdf88f62b0 129
<> 128:9bcdf88f62b0 130 /** Read one byte
<> 128:9bcdf88f62b0 131 *
<> 128:9bcdf88f62b0 132 * @param obj The I2C object
<> 128:9bcdf88f62b0 133 * @param last Acknoledge
<> 128:9bcdf88f62b0 134 * @return The read byte
<> 128:9bcdf88f62b0 135 */
<> 128:9bcdf88f62b0 136 int i2c_byte_read(i2c_t *obj, int last);
<> 128:9bcdf88f62b0 137
<> 128:9bcdf88f62b0 138 /** Write one byte
<> 128:9bcdf88f62b0 139 *
<> 128:9bcdf88f62b0 140 * @param obj The I2C object
<> 128:9bcdf88f62b0 141 * @param data Byte to be written
<> 128:9bcdf88f62b0 142 * @return 0 if NAK was received, 1 if ACK was received, 2 for timeout.
<> 128:9bcdf88f62b0 143 */
<> 128:9bcdf88f62b0 144 int i2c_byte_write(i2c_t *obj, int data);
<> 128:9bcdf88f62b0 145
<> 128:9bcdf88f62b0 146 /**@}*/
<> 128:9bcdf88f62b0 147
<> 128:9bcdf88f62b0 148 #if DEVICE_I2CSLAVE
<> 128:9bcdf88f62b0 149
<> 128:9bcdf88f62b0 150 /**
<> 128:9bcdf88f62b0 151 * \defgroup SynchI2C Synchronous I2C Hardware Abstraction Layer for slave
<> 128:9bcdf88f62b0 152 * @{
<> 128:9bcdf88f62b0 153 */
<> 128:9bcdf88f62b0 154
<> 128:9bcdf88f62b0 155 /** Configure I2C as slave or master.
<> 128:9bcdf88f62b0 156 * @param obj The I2C object
<> 128:9bcdf88f62b0 157 * @return non-zero if a value is available
<> 128:9bcdf88f62b0 158 */
<> 128:9bcdf88f62b0 159 void i2c_slave_mode(i2c_t *obj, int enable_slave);
<> 128:9bcdf88f62b0 160
<> 128:9bcdf88f62b0 161 /** Check to see if the I2C slave has been addressed.
<> 128:9bcdf88f62b0 162 * @param obj The I2C object
<> 128:9bcdf88f62b0 163 * @return The status - 1 - read addresses, 2 - write to all slaves,
<> 128:9bcdf88f62b0 164 * 3 write addressed, 0 - the slave has not been addressed
<> 128:9bcdf88f62b0 165 */
<> 128:9bcdf88f62b0 166 int i2c_slave_receive(i2c_t *obj);
<> 128:9bcdf88f62b0 167
<> 128:9bcdf88f62b0 168 /** Configure I2C as slave or master.
<> 128:9bcdf88f62b0 169 * @param obj The I2C object
<> 128:9bcdf88f62b0 170 * @return non-zero if a value is available
<> 128:9bcdf88f62b0 171 */
<> 128:9bcdf88f62b0 172 int i2c_slave_read(i2c_t *obj, char *data, int length);
<> 128:9bcdf88f62b0 173
<> 128:9bcdf88f62b0 174 /** Configure I2C as slave or master.
<> 128:9bcdf88f62b0 175 * @param obj The I2C object
<> 128:9bcdf88f62b0 176 * @return non-zero if a value is available
<> 128:9bcdf88f62b0 177 */
<> 128:9bcdf88f62b0 178 int i2c_slave_write(i2c_t *obj, const char *data, int length);
<> 128:9bcdf88f62b0 179
<> 128:9bcdf88f62b0 180 /** Configure I2C address.
<> 128:9bcdf88f62b0 181 * @param obj The I2C object
<> 128:9bcdf88f62b0 182 * @param idx Currently not used
<> 128:9bcdf88f62b0 183 * @param address The address to be set
<> 128:9bcdf88f62b0 184 * @param mask Currently not used
<> 128:9bcdf88f62b0 185 */
<> 128:9bcdf88f62b0 186 void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask);
<> 128:9bcdf88f62b0 187
<> 128:9bcdf88f62b0 188 #endif
<> 128:9bcdf88f62b0 189
<> 128:9bcdf88f62b0 190 /**@}*/
<> 128:9bcdf88f62b0 191
<> 128:9bcdf88f62b0 192 #if DEVICE_I2C_ASYNCH
<> 128:9bcdf88f62b0 193
<> 128:9bcdf88f62b0 194 /**
<> 128:9bcdf88f62b0 195 * \defgroup hal_AsynchI2C Asynchronous I2C Hardware Abstraction Layer
<> 128:9bcdf88f62b0 196 * @{
<> 128:9bcdf88f62b0 197 */
<> 128:9bcdf88f62b0 198
<> 128:9bcdf88f62b0 199 /** Start I2C asynchronous transfer
<> 128:9bcdf88f62b0 200 *
<> 128:9bcdf88f62b0 201 * @param obj The I2C object
<> 128:9bcdf88f62b0 202 * @param tx The transmit buffer
<> 128:9bcdf88f62b0 203 * @param tx_length The number of bytes to transmit
<> 128:9bcdf88f62b0 204 * @param rx The receive buffer
<> 128:9bcdf88f62b0 205 * @param rx_length The number of bytes to receive
<> 128:9bcdf88f62b0 206 * @param address The address to be set - 7bit or 9bit
<> 128:9bcdf88f62b0 207 * @param stop If true, stop will be generated after the transfer is done
<> 128:9bcdf88f62b0 208 * @param handler The I2C IRQ handler to be set
<> 128:9bcdf88f62b0 209 * @param hint DMA hint usage
<> 128:9bcdf88f62b0 210 */
<> 128:9bcdf88f62b0 211 void i2c_transfer_asynch(i2c_t *obj, const void *tx, size_t tx_length, void *rx, size_t rx_length, uint32_t address, uint32_t stop, uint32_t handler, uint32_t event, DMAUsage hint);
<> 128:9bcdf88f62b0 212
<> 128:9bcdf88f62b0 213 /** The asynchronous IRQ handler
<> 128:9bcdf88f62b0 214 *
<> 128:9bcdf88f62b0 215 * @param obj The I2C object which holds the transfer information
<> 128:9bcdf88f62b0 216 * @return Event flags if a transfer termination condition was met, otherwise return 0.
<> 128:9bcdf88f62b0 217 */
<> 128:9bcdf88f62b0 218 uint32_t i2c_irq_handler_asynch(i2c_t *obj);
<> 128:9bcdf88f62b0 219
<> 128:9bcdf88f62b0 220 /** Attempts to determine if the I2C peripheral is already in use
<> 128:9bcdf88f62b0 221 *
<> 128:9bcdf88f62b0 222 * @param obj The I2C object
<> 128:9bcdf88f62b0 223 * @return Non-zero if the I2C module is active or zero if it is not
<> 128:9bcdf88f62b0 224 */
<> 128:9bcdf88f62b0 225 uint8_t i2c_active(i2c_t *obj);
<> 128:9bcdf88f62b0 226
<> 128:9bcdf88f62b0 227 /** Abort asynchronous transfer
<> 128:9bcdf88f62b0 228 *
<> 128:9bcdf88f62b0 229 * This function does not perform any check - that should happen in upper layers.
<> 128:9bcdf88f62b0 230 * @param obj The I2C object
<> 128:9bcdf88f62b0 231 */
<> 128:9bcdf88f62b0 232 void i2c_abort_asynch(i2c_t *obj);
<> 128:9bcdf88f62b0 233
<> 128:9bcdf88f62b0 234 #endif
<> 128:9bcdf88f62b0 235
<> 128:9bcdf88f62b0 236 /**@}*/
<> 128:9bcdf88f62b0 237
<> 128:9bcdf88f62b0 238 #ifdef __cplusplus
<> 128:9bcdf88f62b0 239 }
<> 128:9bcdf88f62b0 240 #endif
<> 128:9bcdf88f62b0 241
<> 128:9bcdf88f62b0 242 #endif
<> 128:9bcdf88f62b0 243
<> 128:9bcdf88f62b0 244 #endif
<> 128:9bcdf88f62b0 245
<> 128:9bcdf88f62b0 246 /** @}*/