stm32_twi.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #ifndef _STM32_TWI_H_
  2. #define _STM32_TWI_H_
  3. /*
  4. * Copyright (C) 2010 by Ulrich Prinz (uprinz2@netscape.net)
  5. * Copyright (C) 2010 by Rittal GmbH & Co. KG. All rights reserved.
  6. *
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of the copyright holders nor the names of
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  31. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  32. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. * SUCH DAMAGE.
  34. *
  35. * For additional information see http://www.ethernut.de/
  36. */
  37. /*
  38. * \verbatim
  39. * $Id: stm32_twi.h 5070 2013-03-20 14:50:47Z u_bonnes $
  40. * \endverbatim
  41. */
  42. /*!
  43. * \file arch/cm3/dev/stm/stm32_twi.h
  44. * \brief Header file for STM32F I2C bus
  45. */
  46. typedef struct _NUTTWIICB NUTTWIICB;
  47. /*
  48. * Runtime Data container.
  49. * This is installed in heap at initializaton
  50. * of a bus.
  51. */
  52. struct _NUTTWIICB {
  53. /********** Master mode *********/
  54. /*! \brief Bus slave address.
  55. */
  56. volatile uint_fast16_t tw_mm_sla;
  57. /*! \brief Bus current error condition.
  58. */
  59. volatile int_fast8_t tw_mm_err;
  60. /*! \brief Bus last error condition.
  61. */
  62. volatile int_fast8_t tw_mm_error;
  63. /*! \brief Bus nodes internal address register length.
  64. */
  65. uint8_t *tw_mm_iadr;
  66. /*! \brief Bus nodes internal address register.
  67. */
  68. volatile uint_fast8_t tw_mm_iadrlen;
  69. /*! \brief Bus transmission data buffer pointer.
  70. */
  71. const uint8_t *tw_mm_txbuf;
  72. /*! \brief Bus transmission data block length.
  73. */
  74. volatile uint_fast16_t tw_mm_txlen;
  75. /*! \brief Bus transmissinn position.
  76. */
  77. volatile uint_fast16_t tw_mm_txidx;
  78. /*! \brief Bus reception data buffer pointer.
  79. */
  80. uint8_t *tw_mm_rxbuf;
  81. /*! \brief Bus reception data block length.
  82. */
  83. volatile uint_fast16_t tw_mm_rxlen;
  84. /*! \brief Bus reception position.
  85. */
  86. volatile uint_fast16_t tw_mm_rxidx;
  87. /*! \brief Bus data direction.
  88. */
  89. volatile uint_fast8_t tw_mm_dir;
  90. /*! \brief Transmission Ongoing Mutex.
  91. */
  92. HANDLE tw_mm_mtx;
  93. };
  94. extern NUTTWIBUS Stm32TwiBus_1;
  95. extern NUTTWIBUS Stm32TwiBus_2;
  96. #define I2C1_DMA_CHANNEL_TX DMA1_C6
  97. #define I2C1_DMA_CHANNEL_RX DMA1_C7
  98. #define I2C2_DMA_CHANNEL_TX DMA1_C4
  99. #define I2C2_DMA_CHANNEL_RX DMA1_C5
  100. #endif /* _STM32_TWI_H_ */