Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

405 wiersze
12 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief WINC Peripherals Application Interface.
  6. *
  7. * Copyright (c) 2015 Atmel Corporation. All rights reserved.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. *
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. *
  23. * 3. The name of Atmel may not be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  27. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  29. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  30. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  34. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  35. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * \asf_license_stop
  39. *
  40. */
  41. #ifndef _M2M_PERIPH_H_
  42. #define _M2M_PERIPH_H_
  43. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  44. INCLUDES
  45. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  46. #include "common/include/nm_common.h"
  47. #include "driver/include/m2m_types.h"
  48. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  49. MACROS
  50. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  51. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  52. DATA TYPES
  53. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  54. /*!
  55. @struct \
  56. tstrPerphInitParam
  57. @brief
  58. Peripheral module initialization parameters.
  59. */
  60. typedef struct {
  61. void *arg;
  62. } tstrPerphInitParam;
  63. /*!
  64. @enum \
  65. tenuGpioNum
  66. @brief
  67. A list of GPIO numbers configurable through the m2m_periph module.
  68. */
  69. typedef enum {
  70. M2M_PERIPH_GPIO3, /*!< GPIO15 pad */
  71. M2M_PERIPH_GPIO4, /*!< GPIO16 pad */
  72. M2M_PERIPH_GPIO5, /*!< GPIO18 pad */
  73. M2M_PERIPH_GPIO6, /*!< GPIO18 pad */
  74. M2M_PERIPH_GPIO15, /*!< GPIO15 pad */
  75. M2M_PERIPH_GPIO16, /*!< GPIO16 pad */
  76. M2M_PERIPH_GPIO18, /*!< GPIO18 pad */
  77. M2M_PERIPH_GPIO_MAX
  78. } tenuGpioNum;
  79. /*!
  80. @enum \
  81. tenuI2cMasterSclMuxOpt
  82. @brief
  83. Allowed pin multiplexing options for I2C master SCL signal.
  84. */
  85. typedef enum {
  86. M2M_PERIPH_I2C_MASTER_SCL_MUX_OPT_HOST_WAKEUP, /*!< I2C master SCL is avaiable on HOST_WAKEUP. */
  87. M2M_PERIPH_I2C_MASTER_SCL_MUX_OPT_SD_DAT3, /*!< I2C master SCL is avaiable on SD_DAT3 (GPIO 7). */
  88. M2M_PERIPH_I2C_MASTER_SCL_MUX_OPT_GPIO13, /*!< I2C master SCL is avaiable on GPIO 13. */
  89. M2M_PERIPH_I2C_MASTER_SCL_MUX_OPT_GPIO4, /*!< I2C master SCL is avaiable on GPIO 4.*/
  90. M2M_PERIPH_I2C_MASTER_SCL_MUX_OPT_I2C_SCL, /*!< I2C master SCL is avaiable on I2C slave SCL. */
  91. M2M_PERIPH_I2C_MASTER_SCL_MUX_OPT_NUM
  92. } tenuI2cMasterSclMuxOpt;
  93. /*!
  94. @enum \
  95. tenuI2cMasterSdaMuxOpt
  96. @brief
  97. Allowed pin multiplexing options for I2C master SDA signal.
  98. */
  99. typedef enum {
  100. M2M_PERIPH_I2C_MASTER_SDA_MUX_OPT_RTC_CLK, /*!< I2C master SDA is avaiable on RTC_CLK. */
  101. M2M_PERIPH_I2C_MASTER_SDA_MUX_OPT_SD_CLK, /*!< I2C master SDA is avaiable on SD_CLK (GPIO 8). */
  102. M2M_PERIPH_I2C_MASTER_SDA_MUX_OPT_GPIO14, /*!< I2C master SDA is avaiable on GPIO 14. */
  103. M2M_PERIPH_I2C_MASTER_SDA_MUX_OPT_GPIO6, /*!< I2C master SDA is avaiable on GPIO 6.*/
  104. M2M_PERIPH_I2C_MASTER_SDA_MUX_OPT_I2C_SDA, /*!< I2C master SDA is avaiable on I2C slave SDA. */
  105. M2M_PERIPH_I2C_MASTER_SDA_MUX_OPT_NUM
  106. } tenuI2cMasterSdaMuxOpt;
  107. /*!
  108. @struct \
  109. tstrI2cMasterInitParam
  110. @brief
  111. I2C master configuration parameters.
  112. @sa
  113. tenuI2cMasterSclMuxOpt
  114. tenuI2cMasterSdaMuxOpt
  115. */
  116. typedef struct {
  117. uint8 enuSclMuxOpt; /*!< SCL multiplexing option. Allowed value are defined in tenuI2cMasterSclMuxOpt */
  118. uint8 enuSdaMuxOpt; /*!< SDA multiplexing option. Allowed value are defined in tenuI2cMasterSdaMuxOpt */
  119. uint8 u8ClkSpeedKHz; /*!< I2C master clock speed in KHz. */
  120. } tstrI2cMasterInitParam;
  121. /*!
  122. @enum \
  123. tenuI2cMasterFlags
  124. @brief
  125. Bitwise-ORed flags for use in m2m_periph_i2c_master_write and m2m_periph_i2c_master_read
  126. @sa
  127. m2m_periph_i2c_master_write
  128. m2m_periph_i2c_master_read
  129. */
  130. typedef enum {
  131. I2C_MASTER_NO_FLAGS = 0x00,
  132. /*!< No flags. */
  133. I2C_MASTER_NO_STOP = 0x01,
  134. /*!< No stop bit after this transaction. Useful for scattered buffer read/write operations. */
  135. I2C_MASTER_NO_START = 0x02,
  136. /*!< No start bit at the beginning of this transaction. Useful for scattered buffer read/write operations.*/
  137. } tenuI2cMasterFlags;
  138. /*!
  139. @enum \
  140. tenuPullupMask
  141. @brief
  142. Bitwise-ORed flags for use in m2m_perph_pullup_ctrl.
  143. @sa
  144. m2m_periph_pullup_ctrl
  145. */
  146. typedef enum {
  147. M2M_PERIPH_PULLUP_DIS_HOST_WAKEUP = (1ul << 0),
  148. M2M_PERIPH_PULLUP_DIS_RTC_CLK = (1ul << 1),
  149. M2M_PERIPH_PULLUP_DIS_IRQN = (1ul << 2),
  150. M2M_PERIPH_PULLUP_DIS_GPIO_3 = (1ul << 3),
  151. M2M_PERIPH_PULLUP_DIS_GPIO_4 = (1ul << 4),
  152. M2M_PERIPH_PULLUP_DIS_GPIO_5 = (1ul << 5),
  153. M2M_PERIPH_PULLUP_DIS_SD_DAT3 = (1ul << 6),
  154. M2M_PERIPH_PULLUP_DIS_SD_DAT2_SPI_RXD = (1ul << 7),
  155. M2M_PERIPH_PULLUP_DIS_SD_DAT1_SPI_SSN = (1ul << 9),
  156. M2M_PERIPH_PULLUP_DIS_SD_CMD_SPI_SCK = (1ul << 10),
  157. M2M_PERIPH_PULLUP_DIS_SD_DAT0_SPI_TXD = (1ul << 11),
  158. M2M_PERIPH_PULLUP_DIS_GPIO_6 = (1ul << 12),
  159. M2M_PERIPH_PULLUP_DIS_SD_CLK = (1ul << 13),
  160. M2M_PERIPH_PULLUP_DIS_I2C_SCL = (1ul << 14),
  161. M2M_PERIPH_PULLUP_DIS_I2C_SDA = (1ul << 15),
  162. M2M_PERIPH_PULLUP_DIS_GPIO_11 = (1ul << 16),
  163. M2M_PERIPH_PULLUP_DIS_GPIO_12 = (1ul << 17),
  164. M2M_PERIPH_PULLUP_DIS_GPIO_13 = (1ul << 18),
  165. M2M_PERIPH_PULLUP_DIS_GPIO_14 = (1ul << 19),
  166. M2M_PERIPH_PULLUP_DIS_GPIO_15 = (1ul << 20),
  167. M2M_PERIPH_PULLUP_DIS_GPIO_16 = (1ul << 21),
  168. M2M_PERIPH_PULLUP_DIS_GPIO_17 = (1ul << 22),
  169. M2M_PERIPH_PULLUP_DIS_GPIO_18 = (1ul << 23),
  170. M2M_PERIPH_PULLUP_DIS_GPIO_19 = (1ul << 24),
  171. M2M_PERIPH_PULLUP_DIS_GPIO_20 = (1ul << 25),
  172. M2M_PERIPH_PULLUP_DIS_GPIO_21 = (1ul << 26),
  173. M2M_PERIPH_PULLUP_DIS_GPIO_22 = (1ul << 27),
  174. M2M_PERIPH_PULLUP_DIS_GPIO_23 = (1ul << 28),
  175. M2M_PERIPH_PULLUP_DIS_GPIO_24 = (1ul << 29),
  176. } tenuPullupMask;
  177. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  178. FUNCTION PROTOTYPES
  179. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  180. #ifdef __cplusplus
  181. extern "C" {
  182. #endif
  183. /*!
  184. @fn \
  185. NMI_API sint8 m2m_periph_init(tstrPerphInitParam * param);
  186. @brief
  187. Initialize the NMC1500 peripheral driver module.
  188. @param [in] param
  189. Peripheral module initialization structure. See members of tstrPerphInitParam.
  190. @return
  191. The function SHALL return 0 for success and a negative value otherwise.
  192. @sa
  193. tstrPerphInitParam
  194. */
  195. NMI_API sint8 m2m_periph_init(tstrPerphInitParam *param);
  196. /*!
  197. @fn \
  198. NMI_API sint8 m2m_periph_gpio_set_dir(uint8 u8GpioNum, uint8 u8GpioDir);
  199. @brief
  200. Configure a specific NMC1500 pad as a GPIO and sets its direction (input or output).
  201. @param [in] u8GpioNum
  202. GPIO number. Allowed values are defined in tenuGpioNum.
  203. @param [in] u8GpioDir
  204. GPIO direction: Zero = input. Non-zero = output.
  205. @return
  206. The function SHALL return 0 for success and a negative value otherwise.
  207. @sa
  208. tenuGpioNum
  209. */
  210. NMI_API sint8 m2m_periph_gpio_set_dir(uint8 u8GpioNum, uint8 u8GpioDir);
  211. /*!
  212. @fn \
  213. NMI_API sint8 m2m_periph_gpio_set_val(uint8 u8GpioNum, uint8 u8GpioVal);
  214. @brief
  215. Set an NMC1500 GPIO output level high or low.
  216. @param [in] u8GpioNum
  217. GPIO number. Allowed values are defined in tenuGpioNum.
  218. @param [in] u8GpioVal
  219. GPIO output value. Zero = low, non-zero = high.
  220. @return
  221. The function SHALL return 0 for success and a negative value otherwise.
  222. @sa
  223. tenuGpioNum
  224. */
  225. NMI_API sint8 m2m_periph_gpio_set_val(uint8 u8GpioNum, uint8 u8GpioVal);
  226. /*!
  227. @fn \
  228. NMI_API sint8 m2m_periph_gpio_get_val(uint8 u8GpioNum, uint8 * pu8GpioVal);
  229. @brief
  230. Read an NMC1500 GPIO input level.
  231. @param [in] u8GpioNum
  232. GPIO number. Allowed values are defined in tenuGpioNum.
  233. @param [out] pu8GpioVal
  234. GPIO input value. Zero = low, non-zero = high.
  235. @return
  236. The function SHALL return 0 for success and a negative value otherwise.
  237. @sa
  238. tenuGpioNum
  239. */
  240. NMI_API sint8 m2m_periph_gpio_get_val(uint8 u8GpioNum, uint8 *pu8GpioVal);
  241. /*!
  242. @fn \
  243. NMI_API sint8 m2m_periph_gpio_pullup_ctrl(uint8 u8GpioNum, uint8 u8PullupEn);
  244. @brief
  245. Set an NMC1500 GPIO pullup resisitor enable or disable.
  246. @param [in] u8GpioNum
  247. GPIO number. Allowed values are defined in tenuGpioNum.
  248. @param [in] u8PullupEn
  249. Zero: pullup disabled. Non-zero: pullup enabled.
  250. @return
  251. The function SHALL return 0 for success and a negative value otherwise.
  252. @sa
  253. tenuGpioNum
  254. */
  255. NMI_API sint8 m2m_periph_gpio_pullup_ctrl(uint8 u8GpioNum, uint8 u8PullupEn);
  256. /*!
  257. @fn \
  258. NMI_API sint8 m2m_periph_i2c_master_init(tstrI2cMasterInitParam * param);
  259. @brief
  260. Initialize and configure the NMC1500 I2C master peripheral.
  261. @param [in] param
  262. I2C master initialization structure. See members of tstrI2cMasterInitParam.
  263. @return
  264. The function SHALL return 0 for success and a negative value otherwise.
  265. @sa
  266. tstrI2cMasterInitParam
  267. */
  268. NMI_API sint8 m2m_periph_i2c_master_init(tstrI2cMasterInitParam *param);
  269. /*!
  270. @fn \
  271. NMI_API sint8 m2m_periph_i2c_master_write(uint8 u8SlaveAddr, uint8 * pu8Buf, uint16 u16BufLen, uint8 flags);
  272. @brief
  273. Write a stream of bytes to the I2C slave device.
  274. @param [in] u8SlaveAddr
  275. 7-bit I2C slave address.
  276. @param [in] pu8Buf
  277. A pointer to an input buffer which contains a stream of bytes.
  278. @param [in] u16BufLen
  279. Input buffer length in bytes.
  280. @param [in] flags
  281. Write operation bitwise-ORed flags. See tenuI2cMasterFlags.
  282. @return
  283. The function SHALL return 0 for success and a negative value otherwise.
  284. @sa
  285. tenuI2cMasterFlags
  286. */
  287. NMI_API sint8 m2m_periph_i2c_master_write(uint8 u8SlaveAddr, uint8 *pu8Buf, uint16 u16BufLen, uint8 flags);
  288. /*!
  289. @fn \
  290. NMI_API sint8 m2m_periph_i2c_master_read(uint8 u8SlaveAddr, uint8 * pu8Buf, uint16 u16BufLen, uint16 * pu16ReadLen,
  291. uint8 flags);
  292. @brief
  293. Write a stream of bytes to the I2C slave device.
  294. @param [in] u8SlaveAddr
  295. 7-bit I2C slave address.
  296. @param [out] pu8Buf
  297. A pointer to an output buffer in which a stream of bytes are received.
  298. @param [in] u16BufLen
  299. Max output buffer length in bytes.
  300. @param [out] pu16ReadLen
  301. Actual number of bytes received.
  302. @param [in] flags
  303. Write operation bitwise-ORed flags. See tenuI2cMasterFlags.
  304. @return
  305. The function SHALL return 0 for success and a negative value otherwise.
  306. @sa
  307. tenuI2cMasterFlags
  308. */
  309. NMI_API sint8 m2m_periph_i2c_master_read(uint8 u8SlaveAddr, uint8 *pu8Buf, uint16 u16BufLen, uint16 *pu16ReadLen,
  310. uint8 flags);
  311. /*!
  312. @fn \
  313. NMI_API sint8 m2m_periph_pullup_ctrl(uint32 pinmask, uint8 enable);
  314. @brief
  315. Control the programmable pull-up resistor on the chip pads .
  316. @param [in] pinmask
  317. Write operation bitwise-ORed mask for which pads to control. Allowed values are defined in
  318. tenuPullupMask.
  319. @param [in] enable
  320. Set to 0 to disable pull-up resistor. Non-zero will enable the pull-up.
  321. @return
  322. The function SHALL return 0 for success and a negative value otherwise.
  323. @sa
  324. tenuPullupMask
  325. */
  326. NMI_API sint8 m2m_periph_pullup_ctrl(uint32 pinmask, uint8 enable);
  327. #ifdef __cplusplus
  328. }
  329. #endif
  330. #endif /* _M2M_PERIPH_H_ */