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:
Kojto
Date:
Tue Feb 14 11:24:20 2017 +0000
Revision:
136:ef9c61f8c49f
Parent:
128:9bcdf88f62b0
Child:
139:856d2700e60b
Release 136 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

3432: Target STM USBHOST support https://github.com/ARMmbed/mbed-os/pull/3432
3181: NUCLEO_F207ZG extending PeripheralPins.c: all available alternate functions can be used now https://github.com/ARMmbed/mbed-os/pull/3181
3626: NUCLEO_F412ZG : Add USB Device +Host https://github.com/ARMmbed/mbed-os/pull/3626
3628: Fix warnings https://github.com/ARMmbed/mbed-os/pull/3628
3629: STM32: L0 LL layer https://github.com/ARMmbed/mbed-os/pull/3629
3632: IDE Export support for platform VK_RZ_A1H https://github.com/ARMmbed/mbed-os/pull/3632
3642: Missing IRQ pin fix for platform VK_RZ_A1H https://github.com/ARMmbed/mbed-os/pull/3642
3664: Fix ncs36510 sleep definitions https://github.com/ARMmbed/mbed-os/pull/3664
3655: [STM32F4] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3655
3657: [STM32L4] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3657
3658: [STM32F3] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3658
3685: STM32: I2C: reset state machine https://github.com/ARMmbed/mbed-os/pull/3685
3692: uVisor: Standardize available legacy heap and stack https://github.com/ARMmbed/mbed-os/pull/3692
3621: Fix for #2884, LPC824: export to LPCXpresso, target running with wron https://github.com/ARMmbed/mbed-os/pull/3621
3649: [STM32F7] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3649
3695: Enforce device_name is valid in targets.json https://github.com/ARMmbed/mbed-os/pull/3695
3723: NCS36510: spi_format function bug fix https://github.com/ARMmbed/mbed-os/pull/3723

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 98:8ab26030e058 1 /***************************************************************************//**
Kojto 98:8ab26030e058 2 * @file em_i2c.h
Kojto 98:8ab26030e058 3 * @brief Inter-intergrated circuit (I2C) peripheral API
<> 128:9bcdf88f62b0 4 * @version 5.0.0
Kojto 98:8ab26030e058 5 *******************************************************************************
Kojto 98:8ab26030e058 6 * @section License
<> 128:9bcdf88f62b0 7 * <b>Copyright 2016 Silicon Laboratories, Inc. http://www.silabs.com</b>
Kojto 98:8ab26030e058 8 *******************************************************************************
Kojto 98:8ab26030e058 9 *
Kojto 98:8ab26030e058 10 * Permission is granted to anyone to use this software for any purpose,
Kojto 98:8ab26030e058 11 * including commercial applications, and to alter it and redistribute it
Kojto 98:8ab26030e058 12 * freely, subject to the following restrictions:
Kojto 98:8ab26030e058 13 *
Kojto 98:8ab26030e058 14 * 1. The origin of this software must not be misrepresented; you must not
Kojto 98:8ab26030e058 15 * claim that you wrote the original software.
Kojto 98:8ab26030e058 16 * 2. Altered source versions must be plainly marked as such, and must not be
Kojto 98:8ab26030e058 17 * misrepresented as being the original software.
Kojto 98:8ab26030e058 18 * 3. This notice may not be removed or altered from any source distribution.
Kojto 98:8ab26030e058 19 *
Kojto 98:8ab26030e058 20 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
Kojto 98:8ab26030e058 21 * obligation to support this Software. Silicon Labs is providing the
Kojto 98:8ab26030e058 22 * Software "AS IS", with no express or implied warranties of any kind,
Kojto 98:8ab26030e058 23 * including, but not limited to, any implied warranties of merchantability
Kojto 98:8ab26030e058 24 * or fitness for any particular purpose or warranties against infringement
Kojto 98:8ab26030e058 25 * of any proprietary rights of a third party.
Kojto 98:8ab26030e058 26 *
Kojto 98:8ab26030e058 27 * Silicon Labs will not be liable for any consequential, incidental, or
Kojto 98:8ab26030e058 28 * special damages, or any other relief, or for any claim by any third party,
Kojto 98:8ab26030e058 29 * arising from your use of this Software.
Kojto 98:8ab26030e058 30 *
Kojto 98:8ab26030e058 31 ******************************************************************************/
Kojto 98:8ab26030e058 32
<> 128:9bcdf88f62b0 33 #ifndef EM_I2C_H
<> 128:9bcdf88f62b0 34 #define EM_I2C_H
Kojto 98:8ab26030e058 35
Kojto 98:8ab26030e058 36 #include "em_device.h"
Kojto 98:8ab26030e058 37 #if defined(I2C_COUNT) && (I2C_COUNT > 0)
Kojto 98:8ab26030e058 38
Kojto 98:8ab26030e058 39 #include <stdbool.h>
Kojto 98:8ab26030e058 40
Kojto 98:8ab26030e058 41 #ifdef __cplusplus
Kojto 98:8ab26030e058 42 extern "C" {
Kojto 98:8ab26030e058 43 #endif
Kojto 98:8ab26030e058 44
Kojto 98:8ab26030e058 45 /***************************************************************************//**
<> 128:9bcdf88f62b0 46 * @addtogroup emlib
Kojto 98:8ab26030e058 47 * @{
Kojto 98:8ab26030e058 48 ******************************************************************************/
Kojto 98:8ab26030e058 49
Kojto 98:8ab26030e058 50 /***************************************************************************//**
Kojto 98:8ab26030e058 51 * @addtogroup I2C
Kojto 98:8ab26030e058 52 * @{
Kojto 98:8ab26030e058 53 ******************************************************************************/
Kojto 98:8ab26030e058 54
Kojto 98:8ab26030e058 55 /*******************************************************************************
Kojto 98:8ab26030e058 56 ******************************* DEFINES ***********************************
Kojto 98:8ab26030e058 57 ******************************************************************************/
Kojto 98:8ab26030e058 58
Kojto 98:8ab26030e058 59 /**
Kojto 98:8ab26030e058 60 * @brief
Kojto 98:8ab26030e058 61 * Standard mode max frequency assuming using 4:4 ratio for Nlow:Nhigh.
Kojto 98:8ab26030e058 62 * @details
Kojto 98:8ab26030e058 63 * From I2C specification: Min Tlow = 4.7us, min Thigh = 4.0us,
Kojto 98:8ab26030e058 64 * max Trise=1.0us, max Tfall=0.3us. Since ratio is 4:4, have to use
Kojto 98:8ab26030e058 65 * worst case value of Tlow or Thigh as base.
Kojto 98:8ab26030e058 66 *
Kojto 98:8ab26030e058 67 * 1/(Tlow + Thigh + 1us + 0.3us) = 1/(4.7 + 4.7 + 1.3)us = 93458Hz
Kojto 113:f141b2784e32 68 * @note
Kojto 113:f141b2784e32 69 * Due to chip characteristics, the max value is somewhat reduced.
Kojto 98:8ab26030e058 70 */
Kojto 113:f141b2784e32 71 #if defined(_EFM32_GECKO_FAMILY) || defined(_EFM32_TINY_FAMILY) \
Kojto 113:f141b2784e32 72 || defined(_EFM32_ZERO_FAMILY) || defined(_EFM32_HAPPY_FAMILY)
Kojto 113:f141b2784e32 73 #define I2C_FREQ_STANDARD_MAX 93000
Kojto 113:f141b2784e32 74 #elif defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
Kojto 113:f141b2784e32 75 #define I2C_FREQ_STANDARD_MAX 92000
Kojto 113:f141b2784e32 76 #elif defined(_SILICON_LABS_32B_PLATFORM_2)
Kojto 113:f141b2784e32 77 // None of the chips on this platform has been characterized on this parameter.
Kojto 113:f141b2784e32 78 // Use same value as on Wonder until further notice.
Kojto 113:f141b2784e32 79 #define I2C_FREQ_STANDARD_MAX 92000
Kojto 113:f141b2784e32 80 #else
Kojto 113:f141b2784e32 81 #error "Unknown device family."
Kojto 113:f141b2784e32 82 #endif
Kojto 98:8ab26030e058 83
Kojto 98:8ab26030e058 84 /**
Kojto 98:8ab26030e058 85 * @brief
Kojto 98:8ab26030e058 86 * Fast mode max frequency assuming using 6:3 ratio for Nlow:Nhigh.
Kojto 98:8ab26030e058 87 * @details
Kojto 98:8ab26030e058 88 * From I2C specification: Min Tlow = 1.3us, min Thigh = 0.6us,
Kojto 98:8ab26030e058 89 * max Trise=0.3us, max Tfall=0.3us. Since ratio is 6:3, have to use
Kojto 98:8ab26030e058 90 * worst case value of Tlow or 2xThigh as base.
Kojto 98:8ab26030e058 91 *
Kojto 98:8ab26030e058 92 * 1/(Tlow + Thigh + 0.3us + 0.3us) = 1/(1.3 + 0.65 + 0.6)us = 392157Hz
Kojto 98:8ab26030e058 93 */
Kojto 113:f141b2784e32 94 #define I2C_FREQ_FAST_MAX 392157
Kojto 98:8ab26030e058 95
Kojto 98:8ab26030e058 96
Kojto 98:8ab26030e058 97 /**
Kojto 98:8ab26030e058 98 * @brief
Kojto 98:8ab26030e058 99 * Fast mode+ max frequency assuming using 11:6 ratio for Nlow:Nhigh.
Kojto 98:8ab26030e058 100 * @details
Kojto 98:8ab26030e058 101 * From I2C specification: Min Tlow = 0.5us, min Thigh = 0.26us,
Kojto 113:f141b2784e32 102 * max Trise=0.12us, max Tfall=0.12us. Since ratio is 11:6, have to use
Kojto 98:8ab26030e058 103 * worst case value of Tlow or (11/6)xThigh as base.
Kojto 98:8ab26030e058 104 *
Kojto 98:8ab26030e058 105 * 1/(Tlow + Thigh + 0.12us + 0.12us) = 1/(0.5 + 0.273 + 0.24)us = 987167Hz
Kojto 98:8ab26030e058 106 */
Kojto 113:f141b2784e32 107 #define I2C_FREQ_FASTPLUS_MAX 987167
Kojto 98:8ab26030e058 108
Kojto 98:8ab26030e058 109
Kojto 98:8ab26030e058 110 /**
Kojto 98:8ab26030e058 111 * @brief
Kojto 98:8ab26030e058 112 * Indicate plain write sequence: S+ADDR(W)+DATA0+P.
Kojto 98:8ab26030e058 113 * @details
Kojto 98:8ab26030e058 114 * @li S - Start
Kojto 98:8ab26030e058 115 * @li ADDR(W) - address with W/R bit cleared
Kojto 98:8ab26030e058 116 * @li DATA0 - Data taken from buffer with index 0
Kojto 98:8ab26030e058 117 * @li P - Stop
Kojto 98:8ab26030e058 118 */
Kojto 98:8ab26030e058 119 #define I2C_FLAG_WRITE 0x0001
Kojto 98:8ab26030e058 120
Kojto 98:8ab26030e058 121 /**
Kojto 98:8ab26030e058 122 * @brief
Kojto 98:8ab26030e058 123 * Indicate plain read sequence: S+ADDR(R)+DATA0+P.
Kojto 98:8ab26030e058 124 * @details
Kojto 98:8ab26030e058 125 * @li S - Start
Kojto 98:8ab26030e058 126 * @li ADDR(R) - address with W/R bit set
Kojto 98:8ab26030e058 127 * @li DATA0 - Data read into buffer with index 0
Kojto 98:8ab26030e058 128 * @li P - Stop
Kojto 98:8ab26030e058 129 */
Kojto 98:8ab26030e058 130 #define I2C_FLAG_READ 0x0002
Kojto 98:8ab26030e058 131
Kojto 98:8ab26030e058 132 /**
Kojto 98:8ab26030e058 133 * @brief
Kojto 98:8ab26030e058 134 * Indicate combined write/read sequence: S+ADDR(W)+DATA0+Sr+ADDR(R)+DATA1+P.
Kojto 98:8ab26030e058 135 * @details
Kojto 98:8ab26030e058 136 * @li S - Start
Kojto 98:8ab26030e058 137 * @li Sr - Repeated start
Kojto 98:8ab26030e058 138 * @li ADDR(W) - address with W/R bit cleared
Kojto 98:8ab26030e058 139 * @li ADDR(R) - address with W/R bit set
Kojto 98:8ab26030e058 140 * @li DATAn - Data written from/read into buffer with index n
Kojto 98:8ab26030e058 141 * @li P - Stop
Kojto 98:8ab26030e058 142 */
Kojto 98:8ab26030e058 143 #define I2C_FLAG_WRITE_READ 0x0004
Kojto 98:8ab26030e058 144
Kojto 98:8ab26030e058 145 /**
Kojto 98:8ab26030e058 146 * @brief
Kojto 98:8ab26030e058 147 * Indicate write sequence using two buffers: S+ADDR(W)+DATA0+DATA1+P.
Kojto 98:8ab26030e058 148 * @details
Kojto 98:8ab26030e058 149 * @li S - Start
Kojto 98:8ab26030e058 150 * @li ADDR(W) - address with W/R bit cleared
Kojto 98:8ab26030e058 151 * @li DATAn - Data written from buffer with index n
Kojto 98:8ab26030e058 152 * @li P - Stop
Kojto 98:8ab26030e058 153 */
Kojto 98:8ab26030e058 154 #define I2C_FLAG_WRITE_WRITE 0x0008
Kojto 98:8ab26030e058 155
Kojto 98:8ab26030e058 156 /** Use 10 bit address. */
Kojto 98:8ab26030e058 157 #define I2C_FLAG_10BIT_ADDR 0x0010
Kojto 98:8ab26030e058 158
Kojto 98:8ab26030e058 159
Kojto 98:8ab26030e058 160 /*******************************************************************************
Kojto 98:8ab26030e058 161 ******************************** ENUMS ************************************
Kojto 98:8ab26030e058 162 ******************************************************************************/
Kojto 98:8ab26030e058 163
Kojto 98:8ab26030e058 164 /** Clock low to high ratio settings. */
Kojto 98:8ab26030e058 165 typedef enum
Kojto 98:8ab26030e058 166 {
Kojto 98:8ab26030e058 167 i2cClockHLRStandard = _I2C_CTRL_CLHR_STANDARD, /**< Ratio is 4:4 */
Kojto 98:8ab26030e058 168 i2cClockHLRAsymetric = _I2C_CTRL_CLHR_ASYMMETRIC, /**< Ratio is 6:3 */
Kojto 98:8ab26030e058 169 i2cClockHLRFast = _I2C_CTRL_CLHR_FAST /**< Ratio is 11:3 */
Kojto 98:8ab26030e058 170 } I2C_ClockHLR_TypeDef;
Kojto 98:8ab26030e058 171
Kojto 98:8ab26030e058 172
Kojto 98:8ab26030e058 173 /** Return codes for single master mode transfer function. */
Kojto 98:8ab26030e058 174 typedef enum
Kojto 98:8ab26030e058 175 {
Kojto 98:8ab26030e058 176 /* In progress code (>0) */
Kojto 98:8ab26030e058 177 i2cTransferInProgress = 1, /**< Transfer in progress. */
Kojto 98:8ab26030e058 178
Kojto 98:8ab26030e058 179 /* Complete code (=0) */
Kojto 98:8ab26030e058 180 i2cTransferDone = 0, /**< Transfer completed successfully. */
Kojto 98:8ab26030e058 181
Kojto 98:8ab26030e058 182 /* Transfer error codes (<0) */
Kojto 98:8ab26030e058 183 i2cTransferNack = -1, /**< NACK received during transfer. */
Kojto 98:8ab26030e058 184 i2cTransferBusErr = -2, /**< Bus error during transfer (misplaced START/STOP). */
Kojto 98:8ab26030e058 185 i2cTransferArbLost = -3, /**< Arbitration lost during transfer. */
Kojto 98:8ab26030e058 186 i2cTransferUsageFault = -4, /**< Usage fault. */
Kojto 98:8ab26030e058 187 i2cTransferSwFault = -5 /**< SW fault. */
Kojto 98:8ab26030e058 188 } I2C_TransferReturn_TypeDef;
Kojto 98:8ab26030e058 189
Kojto 98:8ab26030e058 190
Kojto 98:8ab26030e058 191 /*******************************************************************************
Kojto 98:8ab26030e058 192 ******************************* STRUCTS ***********************************
Kojto 98:8ab26030e058 193 ******************************************************************************/
Kojto 98:8ab26030e058 194
Kojto 98:8ab26030e058 195 /** I2C initialization structure. */
Kojto 98:8ab26030e058 196 typedef struct
Kojto 98:8ab26030e058 197 {
Kojto 98:8ab26030e058 198 /** Enable I2C peripheral when init completed. */
Kojto 98:8ab26030e058 199 bool enable;
Kojto 98:8ab26030e058 200
Kojto 98:8ab26030e058 201 /** Set to master (true) or slave (false) mode */
Kojto 98:8ab26030e058 202 bool master;
Kojto 98:8ab26030e058 203
Kojto 98:8ab26030e058 204 /**
Kojto 98:8ab26030e058 205 * I2C reference clock assumed when configuring bus frequency setup.
Kojto 98:8ab26030e058 206 * Set it to 0 if currently configurated reference clock shall be used
Kojto 98:8ab26030e058 207 * This parameter is only applicable if operating in master mode.
Kojto 98:8ab26030e058 208 */
Kojto 98:8ab26030e058 209 uint32_t refFreq;
Kojto 98:8ab26030e058 210
Kojto 98:8ab26030e058 211 /**
Kojto 98:8ab26030e058 212 * (Max) I2C bus frequency to use. This parameter is only applicable
Kojto 98:8ab26030e058 213 * if operating in master mode.
Kojto 98:8ab26030e058 214 */
Kojto 98:8ab26030e058 215 uint32_t freq;
Kojto 98:8ab26030e058 216
Kojto 98:8ab26030e058 217 /** Clock low/high ratio control. */
Kojto 98:8ab26030e058 218 I2C_ClockHLR_TypeDef clhr;
Kojto 98:8ab26030e058 219 } I2C_Init_TypeDef;
Kojto 98:8ab26030e058 220
Kojto 98:8ab26030e058 221 /** Suggested default config for I2C init structure. */
Kojto 113:f141b2784e32 222 #define I2C_INIT_DEFAULT \
Kojto 113:f141b2784e32 223 { \
Kojto 113:f141b2784e32 224 true, /* Enable when init done */ \
Kojto 113:f141b2784e32 225 true, /* Set to master mode */ \
Kojto 113:f141b2784e32 226 0, /* Use currently configured reference clock */ \
Kojto 113:f141b2784e32 227 I2C_FREQ_STANDARD_MAX, /* Set to standard rate assuring being */ \
Kojto 113:f141b2784e32 228 /* within I2C spec */ \
Kojto 113:f141b2784e32 229 i2cClockHLRStandard /* Set to use 4:4 low/high duty cycle */ \
Kojto 113:f141b2784e32 230 }
Kojto 98:8ab26030e058 231
Kojto 98:8ab26030e058 232
Kojto 98:8ab26030e058 233 /**
Kojto 98:8ab26030e058 234 * @brief
Kojto 98:8ab26030e058 235 * Master mode transfer message structure used to define a complete
Kojto 98:8ab26030e058 236 * I2C transfer sequence (from start to stop).
Kojto 98:8ab26030e058 237 * @details
Kojto 98:8ab26030e058 238 * The structure allows for defining the following types of sequences,
Kojto 98:8ab26030e058 239 * please refer to defines for sequence details.
Kojto 98:8ab26030e058 240 * @li #I2C_FLAG_READ - data read into buf[0].data
Kojto 98:8ab26030e058 241 * @li #I2C_FLAG_WRITE - data written from buf[0].data
Kojto 98:8ab26030e058 242 * @li #I2C_FLAG_WRITE_READ - data written from buf[0].data and read
Kojto 98:8ab26030e058 243 * into buf[1].data
Kojto 98:8ab26030e058 244 * @li #I2C_FLAG_WRITE_WRITE - data written from buf[0].data and
Kojto 98:8ab26030e058 245 * buf[1].data
Kojto 98:8ab26030e058 246 */
Kojto 98:8ab26030e058 247 typedef struct
Kojto 98:8ab26030e058 248 {
Kojto 98:8ab26030e058 249 /**
Kojto 98:8ab26030e058 250 * @brief
Kojto 98:8ab26030e058 251 * Address to use after (repeated) start.
Kojto 98:8ab26030e058 252 * @details
Kojto 98:8ab26030e058 253 * Layout details, A = address bit, X = don't care bit (set to 0):
Kojto 98:8ab26030e058 254 * @li 7 bit address - use format AAAA AAAX.
Kojto 98:8ab26030e058 255 * @li 10 bit address - use format XXXX XAAX AAAA AAAA
Kojto 98:8ab26030e058 256 */
Kojto 98:8ab26030e058 257 uint16_t addr;
Kojto 98:8ab26030e058 258
Kojto 98:8ab26030e058 259 /** Flags defining sequence type and details, see I2C_FLAG_... defines. */
Kojto 98:8ab26030e058 260 uint16_t flags;
Kojto 98:8ab26030e058 261
Kojto 98:8ab26030e058 262 /**
Kojto 98:8ab26030e058 263 * Buffers used to hold data to send from or receive into depending
Kojto 98:8ab26030e058 264 * on sequence type.
Kojto 98:8ab26030e058 265 */
Kojto 98:8ab26030e058 266 struct
Kojto 98:8ab26030e058 267 {
Kojto 98:8ab26030e058 268 /** Buffer used for data to transmit/receive, must be @p len long. */
Kojto 98:8ab26030e058 269 uint8_t *data;
Kojto 98:8ab26030e058 270
Kojto 98:8ab26030e058 271 /**
Kojto 98:8ab26030e058 272 * Number of bytes in @p data to send or receive. Notice that when
Kojto 98:8ab26030e058 273 * receiving data to this buffer, at least 1 byte must be received.
Kojto 98:8ab26030e058 274 * Setting @p len to 0 in the receive case is considered a usage fault.
Kojto 98:8ab26030e058 275 * Transmitting 0 bytes is legal, in which case only the address
Kojto 98:8ab26030e058 276 * is transmitted after the start condition.
Kojto 98:8ab26030e058 277 */
Kojto 98:8ab26030e058 278 uint16_t len;
Kojto 98:8ab26030e058 279 } buf[2];
Kojto 98:8ab26030e058 280 } I2C_TransferSeq_TypeDef;
Kojto 98:8ab26030e058 281
Kojto 98:8ab26030e058 282
Kojto 98:8ab26030e058 283 /*******************************************************************************
Kojto 98:8ab26030e058 284 ***************************** PROTOTYPES **********************************
Kojto 98:8ab26030e058 285 ******************************************************************************/
Kojto 98:8ab26030e058 286
Kojto 98:8ab26030e058 287 uint32_t I2C_BusFreqGet(I2C_TypeDef *i2c);
Kojto 98:8ab26030e058 288 void I2C_BusFreqSet(I2C_TypeDef *i2c,
Kojto 113:f141b2784e32 289 uint32_t freqRef,
Kojto 113:f141b2784e32 290 uint32_t freqScl,
Kojto 113:f141b2784e32 291 I2C_ClockHLR_TypeDef i2cMode);
Kojto 98:8ab26030e058 292 void I2C_Enable(I2C_TypeDef *i2c, bool enable);
Kojto 98:8ab26030e058 293 void I2C_Init(I2C_TypeDef *i2c, const I2C_Init_TypeDef *init);
Kojto 98:8ab26030e058 294
Kojto 98:8ab26030e058 295 /***************************************************************************//**
Kojto 98:8ab26030e058 296 * @brief
Kojto 98:8ab26030e058 297 * Clear one or more pending I2C interrupts.
Kojto 98:8ab26030e058 298 *
Kojto 98:8ab26030e058 299 * @param[in] i2c
Kojto 98:8ab26030e058 300 * Pointer to I2C peripheral register block.
Kojto 98:8ab26030e058 301 *
Kojto 98:8ab26030e058 302 * @param[in] flags
Kojto 98:8ab26030e058 303 * Pending I2C interrupt source to clear. Use a bitwse logic OR combination of
Kojto 98:8ab26030e058 304 * valid interrupt flags for the I2C module (I2C_IF_nnn).
Kojto 98:8ab26030e058 305 ******************************************************************************/
Kojto 98:8ab26030e058 306 __STATIC_INLINE void I2C_IntClear(I2C_TypeDef *i2c, uint32_t flags)
Kojto 98:8ab26030e058 307 {
Kojto 98:8ab26030e058 308 i2c->IFC = flags;
Kojto 98:8ab26030e058 309 }
Kojto 98:8ab26030e058 310
Kojto 98:8ab26030e058 311
Kojto 98:8ab26030e058 312 /***************************************************************************//**
Kojto 98:8ab26030e058 313 * @brief
Kojto 98:8ab26030e058 314 * Disable one or more I2C interrupts.
Kojto 98:8ab26030e058 315 *
Kojto 98:8ab26030e058 316 * @param[in] i2c
Kojto 98:8ab26030e058 317 * Pointer to I2C peripheral register block.
Kojto 98:8ab26030e058 318 *
Kojto 98:8ab26030e058 319 * @param[in] flags
Kojto 98:8ab26030e058 320 * I2C interrupt sources to disable. Use a bitwise logic OR combination of
Kojto 98:8ab26030e058 321 * valid interrupt flags for the I2C module (I2C_IF_nnn).
Kojto 98:8ab26030e058 322 ******************************************************************************/
Kojto 98:8ab26030e058 323 __STATIC_INLINE void I2C_IntDisable(I2C_TypeDef *i2c, uint32_t flags)
Kojto 98:8ab26030e058 324 {
Kojto 98:8ab26030e058 325 i2c->IEN &= ~(flags);
Kojto 98:8ab26030e058 326 }
Kojto 98:8ab26030e058 327
Kojto 98:8ab26030e058 328
Kojto 98:8ab26030e058 329 /***************************************************************************//**
Kojto 98:8ab26030e058 330 * @brief
Kojto 98:8ab26030e058 331 * Enable one or more I2C interrupts.
Kojto 98:8ab26030e058 332 *
Kojto 98:8ab26030e058 333 * @note
Kojto 98:8ab26030e058 334 * Depending on the use, a pending interrupt may already be set prior to
Kojto 98:8ab26030e058 335 * enabling the interrupt. Consider using I2C_IntClear() prior to enabling
Kojto 98:8ab26030e058 336 * if such a pending interrupt should be ignored.
Kojto 98:8ab26030e058 337 *
Kojto 98:8ab26030e058 338 * @param[in] i2c
Kojto 98:8ab26030e058 339 * Pointer to I2C peripheral register block.
Kojto 98:8ab26030e058 340 *
Kojto 98:8ab26030e058 341 * @param[in] flags
Kojto 98:8ab26030e058 342 * I2C interrupt sources to enable. Use a bitwise logic OR combination of
Kojto 98:8ab26030e058 343 * valid interrupt flags for the I2C module (I2C_IF_nnn).
Kojto 98:8ab26030e058 344 ******************************************************************************/
Kojto 98:8ab26030e058 345 __STATIC_INLINE void I2C_IntEnable(I2C_TypeDef *i2c, uint32_t flags)
Kojto 98:8ab26030e058 346 {
Kojto 98:8ab26030e058 347 i2c->IEN |= flags;
Kojto 98:8ab26030e058 348 }
Kojto 98:8ab26030e058 349
Kojto 98:8ab26030e058 350
Kojto 98:8ab26030e058 351 /***************************************************************************//**
Kojto 98:8ab26030e058 352 * @brief
Kojto 98:8ab26030e058 353 * Get pending I2C interrupt flags.
Kojto 98:8ab26030e058 354 *
Kojto 98:8ab26030e058 355 * @note
Kojto 98:8ab26030e058 356 * The event bits are not cleared by the use of this function.
Kojto 98:8ab26030e058 357 *
Kojto 98:8ab26030e058 358 * @param[in] i2c
Kojto 98:8ab26030e058 359 * Pointer to I2C peripheral register block.
Kojto 98:8ab26030e058 360 *
Kojto 98:8ab26030e058 361 * @return
Kojto 98:8ab26030e058 362 * I2C interrupt sources pending. A bitwise logic OR combination of valid
Kojto 98:8ab26030e058 363 * interrupt flags for the I2C module (I2C_IF_nnn).
Kojto 98:8ab26030e058 364 ******************************************************************************/
Kojto 98:8ab26030e058 365 __STATIC_INLINE uint32_t I2C_IntGet(I2C_TypeDef *i2c)
Kojto 98:8ab26030e058 366 {
Kojto 113:f141b2784e32 367 return i2c->IF;
Kojto 113:f141b2784e32 368 }
Kojto 113:f141b2784e32 369
Kojto 113:f141b2784e32 370
Kojto 113:f141b2784e32 371 /***************************************************************************//**
Kojto 113:f141b2784e32 372 * @brief
Kojto 113:f141b2784e32 373 * Get enabled and pending I2C interrupt flags.
Kojto 113:f141b2784e32 374 * Useful for handling more interrupt sources in the same interrupt handler.
Kojto 113:f141b2784e32 375 *
Kojto 113:f141b2784e32 376 * @note
Kojto 113:f141b2784e32 377 * Interrupt flags are not cleared by the use of this function.
Kojto 113:f141b2784e32 378 *
Kojto 113:f141b2784e32 379 * @param[in] i2c
Kojto 113:f141b2784e32 380 * Pointer to I2C peripheral register block.
Kojto 113:f141b2784e32 381 *
Kojto 113:f141b2784e32 382 * @return
Kojto 113:f141b2784e32 383 * Pending and enabled I2C interrupt sources
Kojto 113:f141b2784e32 384 * The return value is the bitwise AND of
Kojto 113:f141b2784e32 385 * - the enabled interrupt sources in I2Cn_IEN and
Kojto 113:f141b2784e32 386 * - the pending interrupt flags I2Cn_IF
Kojto 113:f141b2784e32 387 ******************************************************************************/
Kojto 113:f141b2784e32 388 __STATIC_INLINE uint32_t I2C_IntGetEnabled(I2C_TypeDef *i2c)
Kojto 113:f141b2784e32 389 {
Kojto 113:f141b2784e32 390 uint32_t ien;
Kojto 113:f141b2784e32 391
Kojto 113:f141b2784e32 392 ien = i2c->IEN;
Kojto 113:f141b2784e32 393 return i2c->IF & ien;
Kojto 98:8ab26030e058 394 }
Kojto 98:8ab26030e058 395
Kojto 98:8ab26030e058 396
Kojto 98:8ab26030e058 397 /***************************************************************************//**
Kojto 98:8ab26030e058 398 * @brief
Kojto 98:8ab26030e058 399 * Set one or more pending I2C interrupts from SW.
Kojto 98:8ab26030e058 400 *
Kojto 98:8ab26030e058 401 * @param[in] i2c
Kojto 98:8ab26030e058 402 * Pointer to I2C peripheral register block.
Kojto 98:8ab26030e058 403 *
Kojto 98:8ab26030e058 404 * @param[in] flags
Kojto 98:8ab26030e058 405 * I2C interrupt sources to set to pending. Use a bitwise logic OR combination
Kojto 98:8ab26030e058 406 * of valid interrupt flags for the I2C module (I2C_IF_nnn).
Kojto 98:8ab26030e058 407 ******************************************************************************/
Kojto 98:8ab26030e058 408 __STATIC_INLINE void I2C_IntSet(I2C_TypeDef *i2c, uint32_t flags)
Kojto 98:8ab26030e058 409 {
Kojto 98:8ab26030e058 410 i2c->IFS = flags;
Kojto 98:8ab26030e058 411 }
Kojto 98:8ab26030e058 412
Kojto 98:8ab26030e058 413 void I2C_Reset(I2C_TypeDef *i2c);
Kojto 98:8ab26030e058 414
Kojto 98:8ab26030e058 415 /***************************************************************************//**
Kojto 98:8ab26030e058 416 * @brief
Kojto 98:8ab26030e058 417 * Get slave address used for I2C peripheral (when operating in slave mode).
Kojto 98:8ab26030e058 418 *
Kojto 98:8ab26030e058 419 * @details
Kojto 98:8ab26030e058 420 * For 10 bit addressing mode, the address is split in two bytes, and only
Kojto 98:8ab26030e058 421 * the first byte setting is fetched, effectively only controlling the 2 most
Kojto 98:8ab26030e058 422 * significant bits of the 10 bit address. Full handling of 10 bit addressing
Kojto 98:8ab26030e058 423 * in slave mode requires additional SW handling.
Kojto 98:8ab26030e058 424 *
Kojto 98:8ab26030e058 425 * @param[in] i2c
Kojto 98:8ab26030e058 426 * Pointer to I2C peripheral register block.
Kojto 98:8ab26030e058 427 *
Kojto 98:8ab26030e058 428 * @return
Kojto 98:8ab26030e058 429 * I2C slave address in use. The 7 most significant bits define the actual
Kojto 98:8ab26030e058 430 * address, the least significant bit is reserved and always returned as 0.
Kojto 98:8ab26030e058 431 ******************************************************************************/
Kojto 98:8ab26030e058 432 __STATIC_INLINE uint8_t I2C_SlaveAddressGet(I2C_TypeDef *i2c)
Kojto 98:8ab26030e058 433 {
Kojto 113:f141b2784e32 434 return ((uint8_t)(i2c->SADDR));
Kojto 98:8ab26030e058 435 }
Kojto 98:8ab26030e058 436
Kojto 98:8ab26030e058 437
Kojto 98:8ab26030e058 438 /***************************************************************************//**
Kojto 98:8ab26030e058 439 * @brief
Kojto 98:8ab26030e058 440 * Set slave address to use for I2C peripheral (when operating in slave mode).
Kojto 98:8ab26030e058 441 *
Kojto 98:8ab26030e058 442 * @details
Kojto 98:8ab26030e058 443 * For 10 bit addressing mode, the address is split in two bytes, and only
Kojto 98:8ab26030e058 444 * the first byte is set, effectively only controlling the 2 most significant
Kojto 98:8ab26030e058 445 * bits of the 10 bit address. Full handling of 10 bit addressing in slave
Kojto 98:8ab26030e058 446 * mode requires additional SW handling.
Kojto 98:8ab26030e058 447 *
Kojto 98:8ab26030e058 448 * @param[in] i2c
Kojto 98:8ab26030e058 449 * Pointer to I2C peripheral register block.
Kojto 98:8ab26030e058 450 *
Kojto 98:8ab26030e058 451 * @param[in] addr
Kojto 98:8ab26030e058 452 * I2C slave address to use. The 7 most significant bits define the actual
Kojto 98:8ab26030e058 453 * address, the least significant bit is reserved and always set to 0.
Kojto 98:8ab26030e058 454 ******************************************************************************/
Kojto 98:8ab26030e058 455 __STATIC_INLINE void I2C_SlaveAddressSet(I2C_TypeDef *i2c, uint8_t addr)
Kojto 98:8ab26030e058 456 {
Kojto 98:8ab26030e058 457 i2c->SADDR = (uint32_t)addr & 0xfe;
Kojto 98:8ab26030e058 458 }
Kojto 98:8ab26030e058 459
Kojto 98:8ab26030e058 460
Kojto 98:8ab26030e058 461 /***************************************************************************//**
Kojto 98:8ab26030e058 462 * @brief
Kojto 98:8ab26030e058 463 * Get slave address mask used for I2C peripheral (when operating in slave
Kojto 98:8ab26030e058 464 * mode).
Kojto 98:8ab26030e058 465 *
Kojto 98:8ab26030e058 466 * @details
Kojto 98:8ab26030e058 467 * The address mask defines how the comparator works. A bit position with
Kojto 98:8ab26030e058 468 * value 0 means that the corresponding slave address bit is ignored during
Kojto 98:8ab26030e058 469 * comparison (don't care). A bit position with value 1 means that the
Kojto 98:8ab26030e058 470 * corresponding slave address bit must match.
Kojto 98:8ab26030e058 471 *
Kojto 98:8ab26030e058 472 * For 10 bit addressing mode, the address is split in two bytes, and only
Kojto 98:8ab26030e058 473 * the mask for the first address byte is fetched, effectively only
Kojto 98:8ab26030e058 474 * controlling the 2 most significant bits of the 10 bit address.
Kojto 98:8ab26030e058 475 *
Kojto 98:8ab26030e058 476 * @param[in] i2c
Kojto 98:8ab26030e058 477 * Pointer to I2C peripheral register block.
Kojto 98:8ab26030e058 478 *
Kojto 98:8ab26030e058 479 * @return
Kojto 98:8ab26030e058 480 * I2C slave address mask in use. The 7 most significant bits define the
Kojto 98:8ab26030e058 481 * actual address mask, the least significant bit is reserved and always
Kojto 98:8ab26030e058 482 * returned as 0.
Kojto 98:8ab26030e058 483 ******************************************************************************/
Kojto 98:8ab26030e058 484 __STATIC_INLINE uint8_t I2C_SlaveAddressMaskGet(I2C_TypeDef *i2c)
Kojto 98:8ab26030e058 485 {
Kojto 113:f141b2784e32 486 return ((uint8_t)(i2c->SADDRMASK));
Kojto 98:8ab26030e058 487 }
Kojto 98:8ab26030e058 488
Kojto 98:8ab26030e058 489
Kojto 98:8ab26030e058 490 /***************************************************************************//**
Kojto 98:8ab26030e058 491 * @brief
Kojto 98:8ab26030e058 492 * Set slave address mask used for I2C peripheral (when operating in slave
Kojto 98:8ab26030e058 493 * mode).
Kojto 98:8ab26030e058 494 *
Kojto 98:8ab26030e058 495 * @details
Kojto 98:8ab26030e058 496 * The address mask defines how the comparator works. A bit position with
Kojto 98:8ab26030e058 497 * value 0 means that the corresponding slave address bit is ignored during
Kojto 98:8ab26030e058 498 * comparison (don't care). A bit position with value 1 means that the
Kojto 98:8ab26030e058 499 * corresponding slave address bit must match.
Kojto 98:8ab26030e058 500 *
Kojto 98:8ab26030e058 501 * For 10 bit addressing mode, the address is split in two bytes, and only
Kojto 98:8ab26030e058 502 * the mask for the first address byte is set, effectively only controlling
Kojto 98:8ab26030e058 503 * the 2 most significant bits of the 10 bit address.
Kojto 98:8ab26030e058 504 *
Kojto 98:8ab26030e058 505 * @param[in] i2c
Kojto 98:8ab26030e058 506 * Pointer to I2C peripheral register block.
Kojto 98:8ab26030e058 507 *
Kojto 98:8ab26030e058 508 * @param[in] mask
Kojto 98:8ab26030e058 509 * I2C slave address mask to use. The 7 most significant bits define the
Kojto 98:8ab26030e058 510 * actual address mask, the least significant bit is reserved and should
Kojto 98:8ab26030e058 511 * be 0.
Kojto 98:8ab26030e058 512 ******************************************************************************/
Kojto 98:8ab26030e058 513 __STATIC_INLINE void I2C_SlaveAddressMaskSet(I2C_TypeDef *i2c, uint8_t mask)
Kojto 98:8ab26030e058 514 {
Kojto 98:8ab26030e058 515 i2c->SADDRMASK = (uint32_t)mask & 0xfe;
Kojto 98:8ab26030e058 516 }
Kojto 98:8ab26030e058 517
Kojto 98:8ab26030e058 518
Kojto 98:8ab26030e058 519 I2C_TransferReturn_TypeDef I2C_Transfer(I2C_TypeDef *i2c);
Kojto 98:8ab26030e058 520 I2C_TransferReturn_TypeDef I2C_TransferInit(I2C_TypeDef *i2c,
Kojto 98:8ab26030e058 521 I2C_TransferSeq_TypeDef *seq);
Kojto 98:8ab26030e058 522
Kojto 98:8ab26030e058 523 /** @} (end addtogroup I2C) */
<> 128:9bcdf88f62b0 524 /** @} (end addtogroup emlib) */
Kojto 98:8ab26030e058 525
Kojto 98:8ab26030e058 526 #ifdef __cplusplus
Kojto 98:8ab26030e058 527 }
Kojto 98:8ab26030e058 528 #endif
Kojto 98:8ab26030e058 529
Kojto 98:8ab26030e058 530 #endif /* defined(I2C_COUNT) && (I2C_COUNT > 0) */
<> 128:9bcdf88f62b0 531 #endif /* EM_I2C_H */