1 /** 2 * 3 * \file 4 * 5 * \brief WINC Peripherals Application Interface. 6 * 7 * Copyright (c) 2016 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 42 #ifndef _M2M_PERIPH_H_ 43 #define _M2M_PERIPH_H_ 44 45 46 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 47 INCLUDES 48 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 49 50 51 #include "common/include/nm_common.h" 52 #include "driver/include/m2m_types.h" 53 54 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 55 MACROS 56 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 57 58 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 59 DATA TYPES 60 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 61 62 /*! 63 @struct \ 64 tstrPerphInitParam 65 66 @brief 67 Peripheral module initialization parameters. 68 */ 69 typedef struct { 70 void * arg; 71 } tstrPerphInitParam; 72 73 74 /*! 75 @enum \ 76 tenuGpioNum 77 78 @brief 79 A list of GPIO numbers configurable through the m2m_periph module. 80 */ 81 typedef enum { 82 M2M_PERIPH_GPIO3, /*!< GPIO15 pad */ 83 M2M_PERIPH_GPIO4, /*!< GPIO16 pad */ 84 M2M_PERIPH_GPIO5, /*!< GPIO18 pad */ 85 M2M_PERIPH_GPIO6, /*!< GPIO18 pad */ 86 M2M_PERIPH_GPIO15, /*!< GPIO15 pad */ 87 M2M_PERIPH_GPIO16, /*!< GPIO16 pad */ 88 M2M_PERIPH_GPIO18, /*!< GPIO18 pad */ 89 M2M_PERIPH_GPIO_MAX 90 } tenuGpioNum; 91 92 93 /*! 94 @enum \ 95 tenuI2cMasterSclMuxOpt 96 97 @brief 98 Allowed pin multiplexing options for I2C master SCL signal. 99 */ 100 typedef enum { 101 M2M_PERIPH_I2C_MASTER_SCL_MUX_OPT_HOST_WAKEUP, /*!< I2C master SCL is avaiable on HOST_WAKEUP. */ 102 M2M_PERIPH_I2C_MASTER_SCL_MUX_OPT_SD_DAT3, /*!< I2C master SCL is avaiable on SD_DAT3 (GPIO 7). */ 103 M2M_PERIPH_I2C_MASTER_SCL_MUX_OPT_GPIO13, /*!< I2C master SCL is avaiable on GPIO 13. */ 104 M2M_PERIPH_I2C_MASTER_SCL_MUX_OPT_GPIO4, /*!< I2C master SCL is avaiable on GPIO 4.*/ 105 M2M_PERIPH_I2C_MASTER_SCL_MUX_OPT_I2C_SCL, /*!< I2C master SCL is avaiable on I2C slave SCL. */ 106 M2M_PERIPH_I2C_MASTER_SCL_MUX_OPT_NUM 107 } tenuI2cMasterSclMuxOpt; 108 109 /*! 110 @enum \ 111 tenuI2cMasterSdaMuxOpt 112 113 @brief 114 Allowed pin multiplexing options for I2C master SDA signal. 115 */ 116 typedef enum { 117 M2M_PERIPH_I2C_MASTER_SDA_MUX_OPT_RTC_CLK , /*!< I2C master SDA is avaiable on RTC_CLK. */ 118 M2M_PERIPH_I2C_MASTER_SDA_MUX_OPT_SD_CLK, /*!< I2C master SDA is avaiable on SD_CLK (GPIO 8). */ 119 M2M_PERIPH_I2C_MASTER_SDA_MUX_OPT_GPIO14, /*!< I2C master SDA is avaiable on GPIO 14. */ 120 M2M_PERIPH_I2C_MASTER_SDA_MUX_OPT_GPIO6, /*!< I2C master SDA is avaiable on GPIO 6.*/ 121 M2M_PERIPH_I2C_MASTER_SDA_MUX_OPT_I2C_SDA, /*!< I2C master SDA is avaiable on I2C slave SDA. */ 122 M2M_PERIPH_I2C_MASTER_SDA_MUX_OPT_NUM 123 } tenuI2cMasterSdaMuxOpt; 124 125 126 /*! 127 @struct \ 128 tstrI2cMasterInitParam 129 130 @brief 131 I2C master configuration parameters. 132 @sa 133 tenuI2cMasterSclMuxOpt 134 tenuI2cMasterSdaMuxOpt 135 */ 136 typedef struct { 137 uint8 enuSclMuxOpt; /*!< SCL multiplexing option. Allowed value are defined in tenuI2cMasterSclMuxOpt */ 138 uint8 enuSdaMuxOpt; /*!< SDA multiplexing option. Allowed value are defined in tenuI2cMasterSdaMuxOpt */ 139 uint8 u8ClkSpeedKHz; /*!< I2C master clock speed in KHz. */ 140 } tstrI2cMasterInitParam; 141 142 /*! 143 @enum \ 144 tenuI2cMasterFlags 145 146 @brief 147 Bitwise-ORed flags for use in m2m_periph_i2c_master_write and m2m_periph_i2c_master_read 148 @sa 149 m2m_periph_i2c_master_write 150 m2m_periph_i2c_master_read 151 */ 152 typedef enum { 153 I2C_MASTER_NO_FLAGS = 0x00, 154 /*!< No flags. */ 155 I2C_MASTER_NO_STOP = 0x01, 156 /*!< No stop bit after this transaction. Useful for scattered buffer read/write operations. */ 157 I2C_MASTER_NO_START = 0x02, 158 /*!< No start bit at the beginning of this transaction. Useful for scattered buffer read/write operations.*/ 159 } tenuI2cMasterFlags; 160 161 /*! 162 @enum \ 163 tenuPullupMask 164 165 @brief 166 Bitwise-ORed flags for use in m2m_perph_pullup_ctrl. 167 @sa 168 m2m_periph_pullup_ctrl 169 170 */ 171 typedef enum { 172 M2M_PERIPH_PULLUP_DIS_HOST_WAKEUP = (1ul << 0), 173 M2M_PERIPH_PULLUP_DIS_RTC_CLK = (1ul << 1), 174 M2M_PERIPH_PULLUP_DIS_IRQN = (1ul << 2), 175 M2M_PERIPH_PULLUP_DIS_GPIO_3 = (1ul << 3), 176 M2M_PERIPH_PULLUP_DIS_GPIO_4 = (1ul << 4), 177 M2M_PERIPH_PULLUP_DIS_GPIO_5 = (1ul << 5), 178 M2M_PERIPH_PULLUP_DIS_SD_DAT3 = (1ul << 6), 179 M2M_PERIPH_PULLUP_DIS_SD_DAT2_SPI_RXD = (1ul << 7), 180 M2M_PERIPH_PULLUP_DIS_SD_DAT1_SPI_SSN = (1ul << 9), 181 M2M_PERIPH_PULLUP_DIS_SD_CMD_SPI_SCK = (1ul << 10), 182 M2M_PERIPH_PULLUP_DIS_SD_DAT0_SPI_TXD = (1ul << 11), 183 M2M_PERIPH_PULLUP_DIS_GPIO_6 = (1ul << 12), 184 M2M_PERIPH_PULLUP_DIS_SD_CLK = (1ul << 13), 185 M2M_PERIPH_PULLUP_DIS_I2C_SCL = (1ul << 14), 186 M2M_PERIPH_PULLUP_DIS_I2C_SDA = (1ul << 15), 187 M2M_PERIPH_PULLUP_DIS_GPIO_11 = (1ul << 16), 188 M2M_PERIPH_PULLUP_DIS_GPIO_12 = (1ul << 17), 189 M2M_PERIPH_PULLUP_DIS_GPIO_13 = (1ul << 18), 190 M2M_PERIPH_PULLUP_DIS_GPIO_14 = (1ul << 19), 191 M2M_PERIPH_PULLUP_DIS_GPIO_15 = (1ul << 20), 192 M2M_PERIPH_PULLUP_DIS_GPIO_16 = (1ul << 21), 193 M2M_PERIPH_PULLUP_DIS_GPIO_17 = (1ul << 22), 194 M2M_PERIPH_PULLUP_DIS_GPIO_18 = (1ul << 23), 195 M2M_PERIPH_PULLUP_DIS_GPIO_19 = (1ul << 24), 196 M2M_PERIPH_PULLUP_DIS_GPIO_20 = (1ul << 25), 197 M2M_PERIPH_PULLUP_DIS_GPIO_21 = (1ul << 26), 198 M2M_PERIPH_PULLUP_DIS_GPIO_22 = (1ul << 27), 199 M2M_PERIPH_PULLUP_DIS_GPIO_23 = (1ul << 28), 200 M2M_PERIPH_PULLUP_DIS_GPIO_24 = (1ul << 29), 201 } tenuPullupMask; 202 203 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 204 FUNCTION PROTOTYPES 205 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 206 207 208 #ifdef __cplusplus 209 extern "C" { 210 #endif 211 212 /*! 213 @fn \ 214 NMI_API sint8 m2m_periph_init(tstrPerphInitParam * param); 215 216 @brief 217 Initialize the NMC1500 peripheral driver module. 218 219 @param [in] param 220 Peripheral module initialization structure. See members of tstrPerphInitParam. 221 222 @return 223 The function SHALL return 0 for success and a negative value otherwise. 224 225 @sa 226 tstrPerphInitParam 227 */ 228 NMI_API sint8 m2m_periph_init(tstrPerphInitParam * param); 229 230 /*! 231 @fn \ 232 NMI_API sint8 m2m_periph_gpio_set_dir(uint8 u8GpioNum, uint8 u8GpioDir); 233 234 @brief 235 Configure a specific NMC1500 pad as a GPIO and sets its direction (input or output). 236 237 @param [in] u8GpioNum 238 GPIO number. Allowed values are defined in tenuGpioNum. 239 240 @param [in] u8GpioDir 241 GPIO direction: Zero = input. Non-zero = output. 242 243 @return 244 The function SHALL return 0 for success and a negative value otherwise. 245 246 @sa 247 tenuGpioNum 248 */ 249 NMI_API sint8 m2m_periph_gpio_set_dir(uint8 u8GpioNum, uint8 u8GpioDir); 250 251 /*! 252 @fn \ 253 NMI_API sint8 m2m_periph_gpio_set_val(uint8 u8GpioNum, uint8 u8GpioVal); 254 255 @brief 256 Set an NMC1500 GPIO output level high or low. 257 258 @param [in] u8GpioNum 259 GPIO number. Allowed values are defined in tenuGpioNum. 260 261 @param [in] u8GpioVal 262 GPIO output value. Zero = low, non-zero = high. 263 264 @return 265 The function SHALL return 0 for success and a negative value otherwise. 266 267 @sa 268 tenuGpioNum 269 */ 270 NMI_API sint8 m2m_periph_gpio_set_val(uint8 u8GpioNum, uint8 u8GpioVal); 271 272 /*! 273 @fn \ 274 NMI_API sint8 m2m_periph_gpio_get_val(uint8 u8GpioNum, uint8 * pu8GpioVal); 275 276 @brief 277 Read an NMC1500 GPIO input level. 278 279 @param [in] u8GpioNum 280 GPIO number. Allowed values are defined in tenuGpioNum. 281 282 @param [out] pu8GpioVal 283 GPIO input value. Zero = low, non-zero = high. 284 285 @return 286 The function SHALL return 0 for success and a negative value otherwise. 287 288 @sa 289 tenuGpioNum 290 */ 291 NMI_API sint8 m2m_periph_gpio_get_val(uint8 u8GpioNum, uint8 * pu8GpioVal); 292 293 /*! 294 @fn \ 295 NMI_API sint8 m2m_periph_gpio_pullup_ctrl(uint8 u8GpioNum, uint8 u8PullupEn); 296 297 @brief 298 Set an NMC1500 GPIO pullup resisitor enable or disable. 299 300 @param [in] u8GpioNum 301 GPIO number. Allowed values are defined in tenuGpioNum. 302 303 @param [in] u8PullupEn 304 Zero: pullup disabled. Non-zero: pullup enabled. 305 306 @return 307 The function SHALL return 0 for success and a negative value otherwise. 308 309 @sa 310 tenuGpioNum 311 */ 312 NMI_API sint8 m2m_periph_gpio_pullup_ctrl(uint8 u8GpioNum, uint8 u8PullupEn); 313 314 /*! 315 @fn \ 316 NMI_API sint8 m2m_periph_i2c_master_init(tstrI2cMasterInitParam * param); 317 318 @brief 319 Initialize and configure the NMC1500 I2C master peripheral. 320 321 @param [in] param 322 I2C master initialization structure. See members of tstrI2cMasterInitParam. 323 324 @return 325 The function SHALL return 0 for success and a negative value otherwise. 326 327 @sa 328 tstrI2cMasterInitParam 329 */ 330 NMI_API sint8 m2m_periph_i2c_master_init(tstrI2cMasterInitParam * param); 331 332 /*! 333 @fn \ 334 NMI_API sint8 m2m_periph_i2c_master_write(uint8 u8SlaveAddr, uint8 * pu8Buf, uint16 u16BufLen, uint8 flags); 335 336 @brief 337 Write a stream of bytes to the I2C slave device. 338 339 @param [in] u8SlaveAddr 340 7-bit I2C slave address. 341 @param [in] pu8Buf 342 A pointer to an input buffer which contains a stream of bytes. 343 @param [in] u16BufLen 344 Input buffer length in bytes. 345 @param [in] flags 346 Write operation bitwise-ORed flags. See tenuI2cMasterFlags. 347 348 @return 349 The function SHALL return 0 for success and a negative value otherwise. 350 351 @sa 352 tenuI2cMasterFlags 353 */ 354 NMI_API sint8 m2m_periph_i2c_master_write(uint8 u8SlaveAddr, uint8 * pu8Buf, uint16 u16BufLen, uint8 flags); 355 356 357 /*! 358 @fn \ 359 NMI_API sint8 m2m_periph_i2c_master_read(uint8 u8SlaveAddr, uint8 * pu8Buf, uint16 u16BufLen, uint16 * pu16ReadLen, uint8 flags); 360 361 @brief 362 Write a stream of bytes to the I2C slave device. 363 364 @param [in] u8SlaveAddr 365 7-bit I2C slave address. 366 @param [out] pu8Buf 367 A pointer to an output buffer in which a stream of bytes are received. 368 @param [in] u16BufLen 369 Max output buffer length in bytes. 370 @param [out] pu16ReadLen 371 Actual number of bytes received. 372 @param [in] flags 373 Write operation bitwise-ORed flags. See tenuI2cMasterFlags. 374 375 @return 376 The function SHALL return 0 for success and a negative value otherwise. 377 378 @sa 379 tenuI2cMasterFlags 380 */ 381 NMI_API sint8 m2m_periph_i2c_master_read(uint8 u8SlaveAddr, uint8 * pu8Buf, uint16 u16BufLen, uint16 * pu16ReadLen, uint8 flags); 382 383 384 /*! 385 @fn \ 386 NMI_API sint8 m2m_periph_pullup_ctrl(uint32 pinmask, uint8 enable); 387 388 @brief 389 Control the programmable pull-up resistor on the chip pads . 390 391 392 @param [in] pinmask 393 Write operation bitwise-ORed mask for which pads to control. Allowed values are defined in tenuPullupMask. 394 395 @param [in] enable 396 Set to 0 to disable pull-up resistor. Non-zero will enable the pull-up. 397 398 @return 399 The function SHALL return 0 for success and a negative value otherwise. 400 401 @sa 402 tenuPullupMask 403 */ 404 NMI_API sint8 m2m_periph_pullup_ctrl(uint32 pinmask, uint8 enable); 405 406 #ifdef __cplusplus 407 } 408 #endif 409 410 411 #endif /* _M2M_PERIPH_H_ */