ads1115 only

Fork of mbed by mbed official

Committer:
<>
Date:
Tue Dec 20 15:36:52 2016 +0000
Revision:
132:9baf128c2fab
Parent:
128:9bcdf88f62b0
Release 132 of the mbed library

Ports for Upcoming Targets

3241: Add support for FRDM-KW41 https://github.com/ARMmbed/mbed-os/pull/3241
3291: Adding mbed enabled Maker board with NINA-B1 and EVA-M8Q https://github.com/ARMmbed/mbed-os/pull/3291

Fixes and Changes

3062: TARGET_STM :USB device FS https://github.com/ARMmbed/mbed-os/pull/3062
3213: STM32: Refactor us_ticker.c + hal_tick.c files https://github.com/ARMmbed/mbed-os/pull/3213
3288: Dev spi asynch l0l1 https://github.com/ARMmbed/mbed-os/pull/3288
3289: Bug fix of initial value of interrupt edge in "gpio_irq_init" function. https://github.com/ARMmbed/mbed-os/pull/3289
3302: STM32F4 AnalogIn - Clear VBATE and TSVREFE bits before configuring ADC channels https://github.com/ARMmbed/mbed-os/pull/3302
3320: STM32 - Add ADC_VREF label https://github.com/ARMmbed/mbed-os/pull/3320
3321: no HSE available by default for NUCLEO_L432KC https://github.com/ARMmbed/mbed-os/pull/3321
3352: ublox eva nina - fix line endings https://github.com/ARMmbed/mbed-os/pull/3352
3322: DISCO_L053C8 doesn't support LSE https://github.com/ARMmbed/mbed-os/pull/3322
3345: STM32 - Remove TIM_IT_UPDATE flag in HAL_Suspend/ResumeTick functions https://github.com/ARMmbed/mbed-os/pull/3345
3309: [NUC472/M453] Fix CI failed tests https://github.com/ARMmbed/mbed-os/pull/3309
3157: [Silicon Labs] Adding support for EFR32MG1 wireless SoC https://github.com/ARMmbed/mbed-os/pull/3157
3301: I2C - correct return values for write functions (docs) - part 1 https://github.com/ARMmbed/mbed-os/pull/3301
3303: Fix #2956 #2939 #2957 #2959 #2960: Add HAL_DeInit function in gpio_irq destructor https://github.com/ARMmbed/mbed-os/pull/3303
3304: STM32L476: no HSE is present in NUCLEO and DISCO boards https://github.com/ARMmbed/mbed-os/pull/3304
3318: Register map changes for RevG https://github.com/ARMmbed/mbed-os/pull/3318
3317: NUCLEO_F429ZI has integrated LSE https://github.com/ARMmbed/mbed-os/pull/3317
3312: K64F: SPI Asynch API implementation https://github.com/ARMmbed/mbed-os/pull/3312
3324: Dev i2c common code https://github.com/ARMmbed/mbed-os/pull/3324
3369: Add CAN2 missing pins for connector CN12 https://github.com/ARMmbed/mbed-os/pull/3369
3377: STM32 NUCLEO-L152RE Update system core clock to 32MHz https://github.com/ARMmbed/mbed-os/pull/3377
3378: K66F: Enable LWIP feature https://github.com/ARMmbed/mbed-os/pull/3378
3382: [MAX32620] Fixing serial readable function. https://github.com/ARMmbed/mbed-os/pull/3382
3399: NUCLEO_F103RB - Add SERIAL_FC feature https://github.com/ARMmbed/mbed-os/pull/3399
3409: STM32L1 : map ST HAL assert into MBED assert https://github.com/ARMmbed/mbed-os/pull/3409
3416: Renames i2c_api.c for STM32F1 targets to fix IAR exporter https://github.com/ARMmbed/mbed-os/pull/3416
3348: Fix frequency function of CAN driver. https://github.com/ARMmbed/mbed-os/pull/3348
3366: NUCLEO_F412ZG - Add new platform https://github.com/ARMmbed/mbed-os/pull/3366
3379: STM32F0 : map ST HAL assert into MBED assert https://github.com/ARMmbed/mbed-os/pull/3379
3393: ISR register never re-evaluated in HAL_DMA_PollForTransfer for STM32F4 https://github.com/ARMmbed/mbed-os/pull/3393
3408: STM32F7 : map ST HAL assert into MBED assert https://github.com/ARMmbed/mbed-os/pull/3408
3411: STM32L0 : map ST HAL assert into MBED assert https://github.com/ARMmbed/mbed-os/pull/3411
3424: STM32F4 - FIX to add the update of hdma->State variable https://github.com/ARMmbed/mbed-os/pull/3424
3427: Fix stm i2c slave https://github.com/ARMmbed/mbed-os/pull/3427
3429: Fix stm i2c fix init https://github.com/ARMmbed/mbed-os/pull/3429
3434: [NUC472/M453] Fix stuck in lp_ticker_init and other updates https://github.com/ARMmbed/mbed-os/pull/3434

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
<> 132:9baf128c2fab 120 * @return
<> 132:9baf128c2fab 121 * zero or non-zero - Number of written bytes
<> 132:9baf128c2fab 122 * negative - I2C_ERROR_XXX status
<> 128:9bcdf88f62b0 123 */
<> 128:9bcdf88f62b0 124 int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop);
<> 128:9bcdf88f62b0 125
<> 128:9bcdf88f62b0 126 /** Reset I2C peripheral. TODO: The action here. Most of the implementation sends stop()
<> 128:9bcdf88f62b0 127 *
<> 128:9bcdf88f62b0 128 * @param obj The I2C object
<> 128:9bcdf88f62b0 129 */
<> 128:9bcdf88f62b0 130 void i2c_reset(i2c_t *obj);
<> 128:9bcdf88f62b0 131
<> 128:9bcdf88f62b0 132 /** Read one byte
<> 128:9bcdf88f62b0 133 *
<> 128:9bcdf88f62b0 134 * @param obj The I2C object
<> 128:9bcdf88f62b0 135 * @param last Acknoledge
<> 128:9bcdf88f62b0 136 * @return The read byte
<> 128:9bcdf88f62b0 137 */
<> 128:9bcdf88f62b0 138 int i2c_byte_read(i2c_t *obj, int last);
<> 128:9bcdf88f62b0 139
<> 128:9bcdf88f62b0 140 /** Write one byte
<> 128:9bcdf88f62b0 141 *
<> 128:9bcdf88f62b0 142 * @param obj The I2C object
<> 128:9bcdf88f62b0 143 * @param data Byte to be written
<> 128:9bcdf88f62b0 144 * @return 0 if NAK was received, 1 if ACK was received, 2 for timeout.
<> 128:9bcdf88f62b0 145 */
<> 128:9bcdf88f62b0 146 int i2c_byte_write(i2c_t *obj, int data);
<> 128:9bcdf88f62b0 147
<> 128:9bcdf88f62b0 148 /**@}*/
<> 128:9bcdf88f62b0 149
<> 128:9bcdf88f62b0 150 #if DEVICE_I2CSLAVE
<> 128:9bcdf88f62b0 151
<> 128:9bcdf88f62b0 152 /**
<> 128:9bcdf88f62b0 153 * \defgroup SynchI2C Synchronous I2C Hardware Abstraction Layer for slave
<> 128:9bcdf88f62b0 154 * @{
<> 128:9bcdf88f62b0 155 */
<> 128:9bcdf88f62b0 156
<> 128:9bcdf88f62b0 157 /** Configure I2C as slave or master.
<> 128:9bcdf88f62b0 158 * @param obj The I2C object
<> 128:9bcdf88f62b0 159 * @return non-zero if a value is available
<> 128:9bcdf88f62b0 160 */
<> 128:9bcdf88f62b0 161 void i2c_slave_mode(i2c_t *obj, int enable_slave);
<> 128:9bcdf88f62b0 162
<> 128:9bcdf88f62b0 163 /** Check to see if the I2C slave has been addressed.
<> 128:9bcdf88f62b0 164 * @param obj The I2C object
<> 128:9bcdf88f62b0 165 * @return The status - 1 - read addresses, 2 - write to all slaves,
<> 128:9bcdf88f62b0 166 * 3 write addressed, 0 - the slave has not been addressed
<> 128:9bcdf88f62b0 167 */
<> 128:9bcdf88f62b0 168 int i2c_slave_receive(i2c_t *obj);
<> 128:9bcdf88f62b0 169
<> 128:9bcdf88f62b0 170 /** Configure I2C as slave or master.
<> 128:9bcdf88f62b0 171 * @param obj The I2C object
<> 128:9bcdf88f62b0 172 * @return non-zero if a value is available
<> 128:9bcdf88f62b0 173 */
<> 128:9bcdf88f62b0 174 int i2c_slave_read(i2c_t *obj, char *data, int length);
<> 128:9bcdf88f62b0 175
<> 128:9bcdf88f62b0 176 /** Configure I2C as slave or master.
<> 128:9bcdf88f62b0 177 * @param obj The I2C object
<> 128:9bcdf88f62b0 178 * @return non-zero if a value is available
<> 128:9bcdf88f62b0 179 */
<> 128:9bcdf88f62b0 180 int i2c_slave_write(i2c_t *obj, const char *data, int length);
<> 128:9bcdf88f62b0 181
<> 128:9bcdf88f62b0 182 /** Configure I2C address.
<> 128:9bcdf88f62b0 183 * @param obj The I2C object
<> 128:9bcdf88f62b0 184 * @param idx Currently not used
<> 128:9bcdf88f62b0 185 * @param address The address to be set
<> 128:9bcdf88f62b0 186 * @param mask Currently not used
<> 128:9bcdf88f62b0 187 */
<> 128:9bcdf88f62b0 188 void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask);
<> 128:9bcdf88f62b0 189
<> 128:9bcdf88f62b0 190 #endif
<> 128:9bcdf88f62b0 191
<> 128:9bcdf88f62b0 192 /**@}*/
<> 128:9bcdf88f62b0 193
<> 128:9bcdf88f62b0 194 #if DEVICE_I2C_ASYNCH
<> 128:9bcdf88f62b0 195
<> 128:9bcdf88f62b0 196 /**
<> 128:9bcdf88f62b0 197 * \defgroup hal_AsynchI2C Asynchronous I2C Hardware Abstraction Layer
<> 128:9bcdf88f62b0 198 * @{
<> 128:9bcdf88f62b0 199 */
<> 128:9bcdf88f62b0 200
<> 128:9bcdf88f62b0 201 /** Start I2C asynchronous transfer
<> 128:9bcdf88f62b0 202 *
<> 128:9bcdf88f62b0 203 * @param obj The I2C object
<> 128:9bcdf88f62b0 204 * @param tx The transmit buffer
<> 128:9bcdf88f62b0 205 * @param tx_length The number of bytes to transmit
<> 128:9bcdf88f62b0 206 * @param rx The receive buffer
<> 128:9bcdf88f62b0 207 * @param rx_length The number of bytes to receive
<> 128:9bcdf88f62b0 208 * @param address The address to be set - 7bit or 9bit
<> 128:9bcdf88f62b0 209 * @param stop If true, stop will be generated after the transfer is done
<> 128:9bcdf88f62b0 210 * @param handler The I2C IRQ handler to be set
<> 128:9bcdf88f62b0 211 * @param hint DMA hint usage
<> 128:9bcdf88f62b0 212 */
<> 128:9bcdf88f62b0 213 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 214
<> 128:9bcdf88f62b0 215 /** The asynchronous IRQ handler
<> 128:9bcdf88f62b0 216 *
<> 128:9bcdf88f62b0 217 * @param obj The I2C object which holds the transfer information
<> 128:9bcdf88f62b0 218 * @return Event flags if a transfer termination condition was met, otherwise return 0.
<> 128:9bcdf88f62b0 219 */
<> 128:9bcdf88f62b0 220 uint32_t i2c_irq_handler_asynch(i2c_t *obj);
<> 128:9bcdf88f62b0 221
<> 128:9bcdf88f62b0 222 /** Attempts to determine if the I2C peripheral is already in use
<> 128:9bcdf88f62b0 223 *
<> 128:9bcdf88f62b0 224 * @param obj The I2C object
<> 128:9bcdf88f62b0 225 * @return Non-zero if the I2C module is active or zero if it is not
<> 128:9bcdf88f62b0 226 */
<> 128:9bcdf88f62b0 227 uint8_t i2c_active(i2c_t *obj);
<> 128:9bcdf88f62b0 228
<> 128:9bcdf88f62b0 229 /** Abort asynchronous transfer
<> 128:9bcdf88f62b0 230 *
<> 128:9bcdf88f62b0 231 * This function does not perform any check - that should happen in upper layers.
<> 128:9bcdf88f62b0 232 * @param obj The I2C object
<> 128:9bcdf88f62b0 233 */
<> 128:9bcdf88f62b0 234 void i2c_abort_asynch(i2c_t *obj);
<> 128:9bcdf88f62b0 235
<> 128:9bcdf88f62b0 236 #endif
<> 128:9bcdf88f62b0 237
<> 128:9bcdf88f62b0 238 /**@}*/
<> 128:9bcdf88f62b0 239
<> 128:9bcdf88f62b0 240 #ifdef __cplusplus
<> 128:9bcdf88f62b0 241 }
<> 128:9bcdf88f62b0 242 #endif
<> 128:9bcdf88f62b0 243
<> 128:9bcdf88f62b0 244 #endif
<> 128:9bcdf88f62b0 245
<> 128:9bcdf88f62b0 246 #endif
<> 128:9bcdf88f62b0 247
<> 128:9bcdf88f62b0 248 /** @}*/