|
| 1 | +/* mbed Microcontroller Library |
| 2 | + * SPDX-License-Identifier: BSD-3-Clause |
| 3 | + ****************************************************************************** |
| 4 | + * |
| 5 | + * Copyright (c) 2015-2021 STMicroelectronics. |
| 6 | + * All rights reserved. |
| 7 | + * |
| 8 | + * This software component is licensed by ST under BSD 3-Clause license, |
| 9 | + * the "License"; You may not use this file except in compliance with the |
| 10 | + * License. You may obtain a copy of the License at: |
| 11 | + * opensource.org/licenses/BSD-3-Clause |
| 12 | + * |
| 13 | + ****************************************************************************** |
| 14 | + */ |
| 15 | + |
| 16 | +#ifndef MBED_I2C_DEVICE_H |
| 17 | +#define MBED_I2C_DEVICE_H |
| 18 | + |
| 19 | +#include "PeripheralNames.h" |
| 20 | + |
| 21 | +#ifdef __cplusplus |
| 22 | +extern "C" { |
| 23 | +#endif |
| 24 | + |
| 25 | +/* Define I2C Device */ |
| 26 | +#if DEVICE_I2C |
| 27 | + |
| 28 | +/* Define IP version */ |
| 29 | +#define I2C_IP_VERSION_V2 |
| 30 | + |
| 31 | +#define I2C1_EV_IRQn I2C1_IRQn |
| 32 | +#define I2C1_ER_IRQn I2C1_IRQn |
| 33 | +#define I2C2_EV_IRQn I2C2_3_4_IRQn |
| 34 | +#define I2C2_ER_IRQn I2C2_3_4_IRQn |
| 35 | +#define I2C3_EV_IRQn I2C2_3_4_IRQn |
| 36 | +#define I2C3_ER_IRQn I2C2_3_4_IRQn |
| 37 | +#define I2C4_EV_IRQn I2C2_3_4_IRQn |
| 38 | +#define I2C4_ER_IRQn I2C2_3_4_IRQn |
| 39 | + |
| 40 | +// Common settings: I2C clock = 56 MHz, Analog filter = ON, Digital filter coefficient = 0 |
| 41 | +#define TIMING_VAL_56M_CLK_100KHZ 0x20C04963 // Standard mode with Rise Time = 400ns and Fall Time = 100ns |
| 42 | +#define TIMING_VAL_56M_CLK_400KHZ 0x2060091A // Fast mode with Rise Time = 250ns and Fall Time = 100ns |
| 43 | +#define TIMING_VAL_56M_CLK_1MHZ 0x00600A19 // Fast mode Plus with Rise Time = 60ns and Fall Time = 100ns |
| 44 | +#define I2C_PCLK_56M 56000000 // 56 MHz |
| 45 | + |
| 46 | +#define I2C_IT_ALL (I2C_IT_ERRI|I2C_IT_TCI|I2C_IT_STOPI|I2C_IT_NACKI|I2C_IT_ADDRI|I2C_IT_RXI|I2C_IT_TXI) |
| 47 | + |
| 48 | +/* Family specifc settings for clock source */ |
| 49 | +#define I2CAPI_I2C1_CLKSRC RCC_I2C1CLKSOURCE_SYSCLK |
| 50 | +#define I2CAPI_I2C3_CLKSRC RCC_I2C3CLKSOURCE_SYSCLK |
| 51 | + |
| 52 | +uint32_t i2c_get_pclk(I2CName i2c); |
| 53 | +uint32_t i2c_get_timing(I2CName i2c, uint32_t current_timing, int current_hz, int hz); |
| 54 | + |
| 55 | +#if MBED_CONF_TARGET_I2C_TIMING_VALUE_ALGO |
| 56 | +uint32_t i2c_compute_timing(uint32_t clock_src_freq, uint32_t i2c_freq); |
| 57 | +void i2c_compute_presc_scldel_sdadel(uint32_t clock_src_freq, uint32_t I2C_speed); |
| 58 | +uint32_t i2c_compute_scll_sclh(uint32_t clock_src_freq, uint32_t I2C_speed); |
| 59 | +#endif // MBED_CONF_TARGET_I2C_TIMING_VALUE_ALGO |
| 60 | + |
| 61 | +#endif // DEVICE_I2C |
| 62 | + |
| 63 | +#ifdef __cplusplus |
| 64 | +} |
| 65 | +#endif |
| 66 | + |
| 67 | +#endif |
0 commit comments