PageRenderTime 64ms CodeModel.GetById 36ms RepoModel.GetById 1ms app.codeStats 0ms

/libmaple/stm32f1/include/series/spi.h

https://github.com/torfbolt/libmaple
C Header | 99 lines | 34 code | 14 blank | 51 comment | 1 complexity | 8d70c7d72b46a67029b4555650a0a07b MD5 | raw file
  1. /******************************************************************************
  2. * The MIT License
  3. *
  4. * Copyright (c) 2011, 2012 LeafLabs, LLC.
  5. * Copyright (c) 2010 Perry Hung.
  6. *
  7. * Permission is hereby granted, free of charge, to any person
  8. * obtaining a copy of this software and associated documentation
  9. * files (the "Software"), to deal in the Software without
  10. * restriction, including without limitation the rights to use, copy,
  11. * modify, merge, publish, distribute, sublicense, and/or sell copies
  12. * of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  22. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  23. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  24. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. * SOFTWARE.
  26. *****************************************************************************/
  27. /**
  28. * @file libmaple/stm32f1/include/series/spi.h
  29. * @author Marti Bolivar <mbolivar@leaflabs.com>
  30. * @brief STM32F1 SPI/I2S series header.
  31. */
  32. #ifndef _LIBMAPLE_STM32F1_SPI_H_
  33. #define _LIBMAPLE_STM32F1_SPI_H_
  34. #include <libmaple/libmaple_types.h>
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /*
  39. * Register map base pointers
  40. */
  41. struct spi_reg_map;
  42. #define SPI1_BASE ((struct spi_reg_map*)0x40013000)
  43. #define SPI2_BASE ((struct spi_reg_map*)0x40003800)
  44. #define SPI3_BASE ((struct spi_reg_map*)0x40003C00)
  45. /*
  46. * Device pointers
  47. */
  48. struct spi_dev;
  49. extern struct spi_dev *SPI1;
  50. extern struct spi_dev *SPI2;
  51. #if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY)
  52. extern struct spi_dev *SPI3;
  53. #endif
  54. /*
  55. * Routines
  56. */
  57. /* spi_gpio_cfg(): Backwards compatibility shim to spi_config_gpios() */
  58. struct gpio_dev;
  59. extern void spi_config_gpios(struct spi_dev*, uint8,
  60. struct gpio_dev*, uint8,
  61. struct gpio_dev*, uint8, uint8, uint8);
  62. /**
  63. * @brief Deprecated. Use spi_config_gpios() instead.
  64. * @see spi_config_gpios()
  65. */
  66. static __always_inline void spi_gpio_cfg(uint8 as_master,
  67. struct gpio_dev *nss_dev,
  68. uint8 nss_bit,
  69. struct gpio_dev *comm_dev,
  70. uint8 sck_bit,
  71. uint8 miso_bit,
  72. uint8 mosi_bit) {
  73. /* We switched style globally to foo_config_gpios() and always
  74. * taking a foo_dev* argument (that last bit is the important
  75. * part) after this function was written.
  76. *
  77. * However, spi_config_gpios() just ignores the spi_dev* on F1, so
  78. * we can still keep this around for older code. */
  79. spi_config_gpios(NULL, as_master, nss_dev, nss_bit,
  80. comm_dev, sck_bit, miso_bit, mosi_bit);
  81. }
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif