common_objects.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* mbed Microcontroller Library
  2. *******************************************************************************
  3. * Copyright (c) 2016, STMicroelectronics
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *******************************************************************************
  29. */
  30. #ifndef MBED_COMMON_OBJECTS_H
  31. #define MBED_COMMON_OBJECTS_H
  32. #include "cmsis.h"
  33. #include "PortNames.h"
  34. #include "PeripheralNames.h"
  35. #include "PinNames.h"
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. struct pwmout_s {
  40. PWMName pwm;
  41. PinName pin;
  42. uint32_t prescaler;
  43. uint32_t period;
  44. uint32_t pulse;
  45. uint8_t channel;
  46. uint8_t inverted;
  47. };
  48. struct spi_s {
  49. SPI_HandleTypeDef handle;
  50. IRQn_Type spiIRQ;
  51. SPIName spi;
  52. PinName pin_miso;
  53. PinName pin_mosi;
  54. PinName pin_sclk;
  55. PinName pin_ssel;
  56. #ifdef DEVICE_SPI_ASYNCH
  57. uint32_t event;
  58. uint8_t transfer_type;
  59. #endif
  60. };
  61. struct serial_s {
  62. UARTName uart;
  63. int index; // Used by irq
  64. uint32_t baudrate;
  65. uint32_t databits;
  66. uint32_t stopbits;
  67. uint32_t parity;
  68. PinName pin_tx;
  69. PinName pin_rx;
  70. #if DEVICE_SERIAL_ASYNCH
  71. uint32_t events;
  72. #endif
  73. #if DEVICE_SERIAL_FC
  74. uint32_t hw_flow_ctl;
  75. PinName pin_rts;
  76. PinName pin_cts;
  77. #endif
  78. };
  79. struct i2c_s {
  80. /* The 1st 2 members I2CName i2c
  81. * and I2C_HandleTypeDef handle should
  82. * be kept as the first members of this struct
  83. * to ensure i2c_get_obj to work as expected
  84. */
  85. I2CName i2c;
  86. I2C_HandleTypeDef handle;
  87. uint8_t index;
  88. int hz;
  89. PinName sda;
  90. PinName scl;
  91. IRQn_Type event_i2cIRQ;
  92. IRQn_Type error_i2cIRQ;
  93. uint32_t XferOperation;
  94. volatile uint8_t event;
  95. volatile int pending_start;
  96. #if DEVICE_I2CSLAVE
  97. uint8_t slave;
  98. volatile uint8_t pending_slave_tx_master_rx;
  99. volatile uint8_t pending_slave_rx_maxter_tx;
  100. #endif
  101. #if DEVICE_I2C_ASYNCH
  102. uint32_t address;
  103. uint8_t stop;
  104. uint8_t available_events;
  105. #endif
  106. };
  107. struct flash_s {
  108. /* nothing to be stored for now */
  109. uint32_t dummy;
  110. };
  111. struct analogin_s {
  112. ADC_HandleTypeDef handle;
  113. PinName pin;
  114. uint8_t channel;
  115. };
  116. #include "gpio_object.h"
  117. struct dac_s {
  118. DACName dac;
  119. PinName pin;
  120. uint32_t channel;
  121. DAC_HandleTypeDef handle;
  122. };
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126. #if DEVICE_CAN
  127. struct can_s {
  128. CAN_HandleTypeDef CanHandle;
  129. int index;
  130. int hz;
  131. };
  132. #endif
  133. /* STM32L4 HAL doesn't provide this API called in rtc_api.c */
  134. #define __HAL_RCC_RTC_CLKPRESCALER(__RTCCLKSource__)
  135. #endif