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.
Diff: TARGET_EFM32HG_STK3400/TARGET_Silicon_Labs/TARGET_EFM32/emlib/inc/em_i2c.h
- Revision:
- 113:f141b2784e32
- Parent:
- 98:8ab26030e058
- Child:
- 128:9bcdf88f62b0
--- a/TARGET_EFM32HG_STK3400/TARGET_Silicon_Labs/TARGET_EFM32/emlib/inc/em_i2c.h Wed Jan 13 09:48:29 2016 +0000 +++ b/TARGET_EFM32HG_STK3400/TARGET_Silicon_Labs/TARGET_EFM32/emlib/inc/em_i2c.h Tue Feb 02 14:43:35 2016 +0000 @@ -1,10 +1,10 @@ /***************************************************************************//** * @file em_i2c.h * @brief Inter-intergrated circuit (I2C) peripheral API - * @version 3.20.12 + * @version 4.2.1 ******************************************************************************* * @section License - * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b> + * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b> ******************************************************************************* * * Permission is granted to anyone to use this software for any purpose, @@ -30,9 +30,8 @@ * ******************************************************************************/ - -#ifndef __SILICON_LABS_EM_I2C_H_ -#define __SILICON_LABS_EM_I2C_H_ +#ifndef __SILICON_LABS_EM_I2C_H__ +#define __SILICON_LABS_EM_I2C_H__ #include "em_device.h" #if defined(I2C_COUNT) && (I2C_COUNT > 0) @@ -66,8 +65,21 @@ * worst case value of Tlow or Thigh as base. * * 1/(Tlow + Thigh + 1us + 0.3us) = 1/(4.7 + 4.7 + 1.3)us = 93458Hz + * @note + * Due to chip characteristics, the max value is somewhat reduced. */ -#define I2C_FREQ_STANDARD_MAX 93500 +#if defined(_EFM32_GECKO_FAMILY) || defined(_EFM32_TINY_FAMILY) \ + || defined(_EFM32_ZERO_FAMILY) || defined(_EFM32_HAPPY_FAMILY) +#define I2C_FREQ_STANDARD_MAX 93000 +#elif defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY) +#define I2C_FREQ_STANDARD_MAX 92000 +#elif defined(_SILICON_LABS_32B_PLATFORM_2) +// None of the chips on this platform has been characterized on this parameter. +// Use same value as on Wonder until further notice. +#define I2C_FREQ_STANDARD_MAX 92000 +#else +#error "Unknown device family." +#endif /** * @brief @@ -79,7 +91,7 @@ * * 1/(Tlow + Thigh + 0.3us + 0.3us) = 1/(1.3 + 0.65 + 0.6)us = 392157Hz */ -#define I2C_FREQ_FAST_MAX 392500 +#define I2C_FREQ_FAST_MAX 392157 /** @@ -87,12 +99,12 @@ * Fast mode+ max frequency assuming using 11:6 ratio for Nlow:Nhigh. * @details * From I2C specification: Min Tlow = 0.5us, min Thigh = 0.26us, - * max Trise=0.012us, max Tfall=0.12us. Since ratio is 11:6, have to use + * max Trise=0.12us, max Tfall=0.12us. Since ratio is 11:6, have to use * worst case value of Tlow or (11/6)xThigh as base. * * 1/(Tlow + Thigh + 0.12us + 0.12us) = 1/(0.5 + 0.273 + 0.24)us = 987167Hz */ -#define I2C_FREQ_FASTPLUS_MAX 987500 +#define I2C_FREQ_FASTPLUS_MAX 987167 /** @@ -207,14 +219,15 @@ } I2C_Init_TypeDef; /** Suggested default config for I2C init structure. */ -#define I2C_INIT_DEFAULT \ - { true, /* Enable when init done */ \ - true, /* Set to master mode */ \ - 0, /* Use currently configured reference clock */ \ - I2C_FREQ_STANDARD_MAX, /* Set to standard rate assuring being */ \ - /* within I2C spec */ \ - i2cClockHLRStandard /* Set to use 4:4 low/high duty cycle */ \ - } +#define I2C_INIT_DEFAULT \ +{ \ + true, /* Enable when init done */ \ + true, /* Set to master mode */ \ + 0, /* Use currently configured reference clock */ \ + I2C_FREQ_STANDARD_MAX, /* Set to standard rate assuring being */ \ + /* within I2C spec */ \ + i2cClockHLRStandard /* Set to use 4:4 low/high duty cycle */ \ +} /** @@ -273,9 +286,9 @@ uint32_t I2C_BusFreqGet(I2C_TypeDef *i2c); void I2C_BusFreqSet(I2C_TypeDef *i2c, - uint32_t refFreq, - uint32_t freq, - I2C_ClockHLR_TypeDef type); + uint32_t freqRef, + uint32_t freqScl, + I2C_ClockHLR_TypeDef i2cMode); void I2C_Enable(I2C_TypeDef *i2c, bool enable); void I2C_Init(I2C_TypeDef *i2c, const I2C_Init_TypeDef *init); @@ -351,7 +364,33 @@ ******************************************************************************/ __STATIC_INLINE uint32_t I2C_IntGet(I2C_TypeDef *i2c) { - return(i2c->IF); + return i2c->IF; +} + + +/***************************************************************************//** + * @brief + * Get enabled and pending I2C interrupt flags. + * Useful for handling more interrupt sources in the same interrupt handler. + * + * @note + * Interrupt flags are not cleared by the use of this function. + * + * @param[in] i2c + * Pointer to I2C peripheral register block. + * + * @return + * Pending and enabled I2C interrupt sources + * The return value is the bitwise AND of + * - the enabled interrupt sources in I2Cn_IEN and + * - the pending interrupt flags I2Cn_IF + ******************************************************************************/ +__STATIC_INLINE uint32_t I2C_IntGetEnabled(I2C_TypeDef *i2c) +{ + uint32_t ien; + + ien = i2c->IEN; + return i2c->IF & ien; } @@ -392,7 +431,7 @@ ******************************************************************************/ __STATIC_INLINE uint8_t I2C_SlaveAddressGet(I2C_TypeDef *i2c) { - return((uint8_t)(i2c->SADDR)); + return ((uint8_t)(i2c->SADDR)); } @@ -444,7 +483,7 @@ ******************************************************************************/ __STATIC_INLINE uint8_t I2C_SlaveAddressMaskGet(I2C_TypeDef *i2c) { - return((uint8_t)(i2c->SADDRMASK)); + return ((uint8_t)(i2c->SADDRMASK)); } @@ -489,4 +528,4 @@ #endif #endif /* defined(I2C_COUNT) && (I2C_COUNT > 0) */ -#endif /* __SILICON_LABS_EM_I2C_H_ */ +#endif /* __SILICON_LABS_EM_I2C_H__ */