Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:05

0001 /**
0002  * @file
0003  * @ingroup stm32f4_i2c I2C Support
0004  * @brief I2C-module.
0005  */
0006 
0007 /*
0008  * Copyright (c) 2013 Christian Mauderer.  All rights reserved.
0009  *
0010  * The license and distribution terms for this file may be
0011  * found in the file LICENSE in this distribution or at
0012  * http://www.rtems.org/license/LICENSE.
0013  */
0014 
0015 /* The I2C-module can not run with libi2c. The reason for this is, that libi2c
0016  * needs a possibility to generate a stop condition separately. This controller
0017  * wants to generate the condition automatically when sending or receiving data.
0018  */
0019 
0020 #ifndef LIBBSP_ARM_STM32F4_I2C_H
0021 #define LIBBSP_ARM_STM32F4_I2C_H
0022 
0023 #include <rtems.h>
0024 
0025 #include <bsp/io.h>
0026 #include <bsp/stm32f4.h>
0027 
0028 #ifdef __cplusplus
0029 extern "C" {
0030 #endif /* __cplusplus */
0031 
0032 /**
0033  * @defgroup stm32f4_i2c I2C Support
0034  * @ingroup RTEMSBSPsARMSTM32F4
0035  * @brief I2C Module
0036  * @{
0037  */
0038 
0039 typedef struct {
0040   /**
0041    * @brief The address of the slave without the read write bit.
0042    * A 7-Bit address should be placed in the bits [6..0]
0043    */
0044   uint16_t addr;
0045   /** @brief Read (true) or write (false) data */
0046   bool read;
0047   /** @brief Size of data to read or write */
0048   size_t len;
0049   /** @brief Buffer for data */
0050   uint8_t *buf;
0051 } stm32f4_i2c_message;
0052 
0053 typedef struct {
0054   volatile stm32f4_i2c *regs;
0055   size_t index;
0056   rtems_vector_number vector;
0057   rtems_id mutex;
0058   rtems_id task_id;
0059   uint8_t *data;
0060   uint8_t *last;
0061   size_t len;
0062   bool read;
0063   uint8_t addr_with_rw;
0064 } stm32f4_i2c_bus_entry;
0065 
0066 /** @brief Initialise the i2c module. */
0067 rtems_status_code stm32f4_i2c_init(stm32f4_i2c_bus_entry *e);
0068 
0069 /** @brief Process a i2c message */
0070 rtems_status_code stm32f4_i2c_process_message(
0071   stm32f4_i2c_bus_entry *e,
0072   stm32f4_i2c_message *msg
0073 );
0074 
0075 /** @brief Set another baud rate than the default one */
0076 rtems_status_code stm32f4_i2c_set_bitrate(
0077   stm32f4_i2c_bus_entry *e,
0078   uint32_t br
0079 );
0080 
0081 extern stm32f4_i2c_bus_entry *const stm32f4_i2c1;
0082 extern stm32f4_i2c_bus_entry *const stm32f4_i2c2;
0083 
0084 /** @} */
0085 
0086 #ifdef __cplusplus
0087 }
0088 #endif /* __cplusplus */
0089 
0090 #endif /* LIBBSP_ARM_STM32F4_I2C_H */