2017-06-23 16:51:27 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 BayLibre, SAS
|
|
|
|
* Copyright (c) 2017 Linaro Ltd
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _STM32_I2C_H_
|
|
|
|
#define _STM32_I2C_H_
|
|
|
|
|
|
|
|
typedef void (*irq_config_func_t)(struct device *port);
|
|
|
|
|
|
|
|
struct i2c_stm32_config {
|
|
|
|
#ifdef CONFIG_I2C_STM32_INTERRUPT
|
|
|
|
irq_config_func_t irq_config_func;
|
|
|
|
#endif
|
|
|
|
struct stm32_pclken pclken;
|
|
|
|
I2C_TypeDef *i2c;
|
2017-08-11 00:59:14 +08:00
|
|
|
u32_t bitrate;
|
2017-06-23 16:51:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct i2c_stm32_data {
|
|
|
|
#ifdef CONFIG_I2C_STM32_INTERRUPT
|
|
|
|
struct k_sem device_sync_sem;
|
|
|
|
#endif
|
2017-09-14 00:31:00 +08:00
|
|
|
u32_t dev_config;
|
2017-06-23 16:51:27 +08:00
|
|
|
#ifdef CONFIG_I2C_STM32_V1
|
|
|
|
u16_t slave_address;
|
|
|
|
#endif
|
|
|
|
struct {
|
|
|
|
#ifdef CONFIG_I2C_STM32_V1
|
|
|
|
unsigned int is_restart;
|
|
|
|
unsigned int flags;
|
|
|
|
#endif
|
|
|
|
unsigned int is_write;
|
2018-03-01 17:53:49 +08:00
|
|
|
unsigned int is_arlo;
|
2017-06-23 16:51:27 +08:00
|
|
|
unsigned int is_nack;
|
|
|
|
unsigned int is_err;
|
|
|
|
struct i2c_msg *msg;
|
|
|
|
unsigned int len;
|
|
|
|
u8_t *buf;
|
|
|
|
} current;
|
2018-03-01 17:53:49 +08:00
|
|
|
#ifdef CONFIG_I2C_SLAVE
|
|
|
|
bool master_active;
|
|
|
|
struct i2c_slave_config *slave_cfg;
|
|
|
|
bool slave_attached;
|
|
|
|
#endif
|
2017-06-23 16:51:27 +08:00
|
|
|
};
|
|
|
|
|
2017-10-22 01:09:47 +08:00
|
|
|
s32_t stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, u8_t *flg,
|
2017-06-23 16:51:27 +08:00
|
|
|
u16_t sadr);
|
2017-10-22 01:09:47 +08:00
|
|
|
s32_t stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, u8_t *flg,
|
2017-06-23 16:51:27 +08:00
|
|
|
u16_t sadr);
|
|
|
|
s32_t stm32_i2c_configure_timing(struct device *dev, u32_t clk);
|
2018-03-01 17:53:49 +08:00
|
|
|
int i2c_stm32_runtime_configure(struct device *dev, u32_t config);
|
2017-06-23 16:51:27 +08:00
|
|
|
|
|
|
|
void stm32_i2c_event_isr(void *arg);
|
|
|
|
void stm32_i2c_error_isr(void *arg);
|
2017-11-30 18:02:38 +08:00
|
|
|
#ifdef CONFIG_I2C_STM32_COMBINED_INTERRUPT
|
|
|
|
void stm32_i2c_combined_isr(void *arg);
|
|
|
|
#endif
|
2017-06-23 16:51:27 +08:00
|
|
|
|
2018-03-01 17:53:49 +08:00
|
|
|
#ifdef CONFIG_I2C_SLAVE
|
|
|
|
int i2c_stm32_slave_register(struct device *dev,
|
|
|
|
struct i2c_slave_config *config);
|
|
|
|
int i2c_stm32_slave_unregister(struct device *dev,
|
|
|
|
struct i2c_slave_config *config);
|
|
|
|
#endif
|
|
|
|
|
2017-06-23 16:51:27 +08:00
|
|
|
#define DEV_DATA(dev) ((struct i2c_stm32_data * const)(dev)->driver_data)
|
|
|
|
#define DEV_CFG(dev) \
|
|
|
|
((const struct i2c_stm32_config * const)(dev)->config->config_info)
|
|
|
|
|
|
|
|
#endif /* _STM32_I2C_H_ */
|