Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 18:6a4db94011d3 1 /****************************************************************************//**
sahilmgandhi 18:6a4db94011d3 2 * @file i2c.h
sahilmgandhi 18:6a4db94011d3 3 * @version V1.00
sahilmgandhi 18:6a4db94011d3 4 * $Revision: 12 $
sahilmgandhi 18:6a4db94011d3 5 * $Date: 14/09/30 1:12p $
sahilmgandhi 18:6a4db94011d3 6 * @brief NUC472/NUC442 I2C driver header file
sahilmgandhi 18:6a4db94011d3 7 *
sahilmgandhi 18:6a4db94011d3 8 * @note
sahilmgandhi 18:6a4db94011d3 9 * Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved.
sahilmgandhi 18:6a4db94011d3 10 *****************************************************************************/
sahilmgandhi 18:6a4db94011d3 11 #ifndef __I2C_H__
sahilmgandhi 18:6a4db94011d3 12 #define __I2C_H__
sahilmgandhi 18:6a4db94011d3 13
sahilmgandhi 18:6a4db94011d3 14 #ifdef __cplusplus
sahilmgandhi 18:6a4db94011d3 15 extern "C"
sahilmgandhi 18:6a4db94011d3 16 {
sahilmgandhi 18:6a4db94011d3 17 #endif
sahilmgandhi 18:6a4db94011d3 18
sahilmgandhi 18:6a4db94011d3 19
sahilmgandhi 18:6a4db94011d3 20 /** @addtogroup NUC472_442_Device_Driver NUC472/NUC442 Device Driver
sahilmgandhi 18:6a4db94011d3 21 @{
sahilmgandhi 18:6a4db94011d3 22 */
sahilmgandhi 18:6a4db94011d3 23
sahilmgandhi 18:6a4db94011d3 24 /** @addtogroup NUC472_442_I2C_Driver I2C Driver
sahilmgandhi 18:6a4db94011d3 25 @{
sahilmgandhi 18:6a4db94011d3 26 */
sahilmgandhi 18:6a4db94011d3 27
sahilmgandhi 18:6a4db94011d3 28 /** @addtogroup NUC472_442_I2C_EXPORTED_CONSTANTS I2C Exported Constants
sahilmgandhi 18:6a4db94011d3 29 @{
sahilmgandhi 18:6a4db94011d3 30 */
sahilmgandhi 18:6a4db94011d3 31
sahilmgandhi 18:6a4db94011d3 32 #define I2C_STA 0x20 /*!< I2C START bit value \hideinitializer */
sahilmgandhi 18:6a4db94011d3 33 #define I2C_STO 0x10 /*!< I2C STOP bit value \hideinitializer */
sahilmgandhi 18:6a4db94011d3 34 #define I2C_SI 0x08 /*!< I2C SI bit value \hideinitializer */
sahilmgandhi 18:6a4db94011d3 35 #define I2C_AA 0x04 /*!< I2C ACK bit value \hideinitializer */
sahilmgandhi 18:6a4db94011d3 36
sahilmgandhi 18:6a4db94011d3 37 #define I2C_GCMODE_ENABLE 1 /*!< Enable I2C GC Mode \hideinitializer */
sahilmgandhi 18:6a4db94011d3 38 #define I2C_GCMODE_DISABLE 0 /*!< Disable I2C GC Mode \hideinitializer */
sahilmgandhi 18:6a4db94011d3 39
sahilmgandhi 18:6a4db94011d3 40 /*@}*/ /* end of group NUC472_442_I2C_EXPORTED_CONSTANTS */
sahilmgandhi 18:6a4db94011d3 41
sahilmgandhi 18:6a4db94011d3 42
sahilmgandhi 18:6a4db94011d3 43 /** @addtogroup NUC472_442_I2C_EXPORTED_FUNCTIONS I2C Exported Functions
sahilmgandhi 18:6a4db94011d3 44 @{
sahilmgandhi 18:6a4db94011d3 45 */
sahilmgandhi 18:6a4db94011d3 46
sahilmgandhi 18:6a4db94011d3 47 /**
sahilmgandhi 18:6a4db94011d3 48 * @brief This macro sets the I2C control register at one time.
sahilmgandhi 18:6a4db94011d3 49 * @param[in] i2c is the base address of I2C module.
sahilmgandhi 18:6a4db94011d3 50 * @param[in] u8Ctrl is the register value of I2C control register.
sahilmgandhi 18:6a4db94011d3 51 * @return none
sahilmgandhi 18:6a4db94011d3 52 * \hideinitializer
sahilmgandhi 18:6a4db94011d3 53 */
sahilmgandhi 18:6a4db94011d3 54 #define I2C_SET_CONTROL_REG(i2c, u8Ctrl) ( (i2c)->CTL = ((i2c)->CTL & ~0x3c) | u8Ctrl )
sahilmgandhi 18:6a4db94011d3 55
sahilmgandhi 18:6a4db94011d3 56 /**
sahilmgandhi 18:6a4db94011d3 57 * @brief This macro only set START bit to the control register of I2C module.
sahilmgandhi 18:6a4db94011d3 58 * @param[in] i2c is the base address of I2C module.
sahilmgandhi 18:6a4db94011d3 59 * @return none
sahilmgandhi 18:6a4db94011d3 60 * \hideinitializer
sahilmgandhi 18:6a4db94011d3 61 */
sahilmgandhi 18:6a4db94011d3 62 #define I2C_START(i2c) ( (i2c)->CTL = ((i2c)->CTL & ~I2C_CTL_SI_Msk) | I2C_CTL_STA_Msk )
sahilmgandhi 18:6a4db94011d3 63
sahilmgandhi 18:6a4db94011d3 64 /**
sahilmgandhi 18:6a4db94011d3 65 * @brief This macro only set STOP bit to the control register of I2C module.
sahilmgandhi 18:6a4db94011d3 66 * @param[in] i2c is the base address of I2C module.
sahilmgandhi 18:6a4db94011d3 67 * @return none
sahilmgandhi 18:6a4db94011d3 68 * \hideinitializer
sahilmgandhi 18:6a4db94011d3 69 */
sahilmgandhi 18:6a4db94011d3 70 #define I2C_STOP(i2c) ( (i2c)->CTL = ((i2c)->CTL & ~0x3c) | I2C_CTL_SI_Msk | I2C_CTL_STO_Msk )
sahilmgandhi 18:6a4db94011d3 71
sahilmgandhi 18:6a4db94011d3 72 /**
sahilmgandhi 18:6a4db94011d3 73 * @brief This macro will return when I2C module is ready.
sahilmgandhi 18:6a4db94011d3 74 * @param[in] i2c is the base address of I2C module.
sahilmgandhi 18:6a4db94011d3 75 * @return none
sahilmgandhi 18:6a4db94011d3 76 * \hideinitializer
sahilmgandhi 18:6a4db94011d3 77 */
sahilmgandhi 18:6a4db94011d3 78 #define I2C_WAIT_READY(i2c) while(!((i2c)->CTL & I2C_CTL_SI_Msk))
sahilmgandhi 18:6a4db94011d3 79
sahilmgandhi 18:6a4db94011d3 80 /**
sahilmgandhi 18:6a4db94011d3 81 * @brief This macro returns the data stored in data register of I2C module.
sahilmgandhi 18:6a4db94011d3 82 * @param[in] i2c is the base address of I2C module.
sahilmgandhi 18:6a4db94011d3 83 * @return Data.
sahilmgandhi 18:6a4db94011d3 84 * \hideinitializer
sahilmgandhi 18:6a4db94011d3 85 */
sahilmgandhi 18:6a4db94011d3 86 #define I2C_GET_DATA(i2c) ( (i2c)->DAT )
sahilmgandhi 18:6a4db94011d3 87
sahilmgandhi 18:6a4db94011d3 88 /**
sahilmgandhi 18:6a4db94011d3 89 * @brief This macro writes the data to data register of I2C module.
sahilmgandhi 18:6a4db94011d3 90 * @param[in] i2c is the base address of I2C module.
sahilmgandhi 18:6a4db94011d3 91 * @param[in] u8Data is the data which will be write to data register of I2C module.
sahilmgandhi 18:6a4db94011d3 92 * @return none
sahilmgandhi 18:6a4db94011d3 93 * \hideinitializer
sahilmgandhi 18:6a4db94011d3 94 */
sahilmgandhi 18:6a4db94011d3 95 #define I2C_SET_DATA(i2c, u8Data) ( (i2c)->DAT = u8Data )
sahilmgandhi 18:6a4db94011d3 96
sahilmgandhi 18:6a4db94011d3 97 /**
sahilmgandhi 18:6a4db94011d3 98 * @brief This macro returns the status of I2C module.
sahilmgandhi 18:6a4db94011d3 99 * @param[in] i2c is the base address of I2C module.
sahilmgandhi 18:6a4db94011d3 100 * @return Status.
sahilmgandhi 18:6a4db94011d3 101 * \hideinitializer
sahilmgandhi 18:6a4db94011d3 102 */
sahilmgandhi 18:6a4db94011d3 103 #define I2C_GET_STATUS(i2c) ( (i2c)->STATUS )
sahilmgandhi 18:6a4db94011d3 104
sahilmgandhi 18:6a4db94011d3 105 /**
sahilmgandhi 18:6a4db94011d3 106 * @brief This macro returns time-out flag.
sahilmgandhi 18:6a4db94011d3 107 * @param[in] i2c is the base address of I2C module.
sahilmgandhi 18:6a4db94011d3 108 * @return Status.
sahilmgandhi 18:6a4db94011d3 109 * @retval 0 Flag is not set.
sahilmgandhi 18:6a4db94011d3 110 * @retval 1 Flag is set.
sahilmgandhi 18:6a4db94011d3 111 * \hideinitializer
sahilmgandhi 18:6a4db94011d3 112 */
sahilmgandhi 18:6a4db94011d3 113 #define I2C_GET_TIMEOUT_FLAG(i2c) ( ((i2c)->TOCTL & I2C_TOCTL_TOIF_Msk) == I2C_TOCTL_TOIF_Msk ? 1:0 )
sahilmgandhi 18:6a4db94011d3 114
sahilmgandhi 18:6a4db94011d3 115 /**
sahilmgandhi 18:6a4db94011d3 116 * @brief This macro returns wakeup flag.
sahilmgandhi 18:6a4db94011d3 117 * @param[in] i2c is the base address of I2C module.
sahilmgandhi 18:6a4db94011d3 118 * @return Status.
sahilmgandhi 18:6a4db94011d3 119 * @retval 0 Flag is not set.
sahilmgandhi 18:6a4db94011d3 120 * @retval 1 Flag is set.
sahilmgandhi 18:6a4db94011d3 121 * \hideinitializer
sahilmgandhi 18:6a4db94011d3 122 */
sahilmgandhi 18:6a4db94011d3 123 #define I2C_GET_WAKEUP_FLAG(i2c) ( ((i2c)->WKSTS & I2C_WKSTS_WKIF_Msk) == I2C_WKSTS_WKIF_Msk ? 1:0 )
sahilmgandhi 18:6a4db94011d3 124
sahilmgandhi 18:6a4db94011d3 125 uint32_t I2C_Open(I2C_T *i2c, uint32_t u32BusClock);
sahilmgandhi 18:6a4db94011d3 126 void I2C_Close(I2C_T *i2c);
sahilmgandhi 18:6a4db94011d3 127 void I2C_ClearTimeoutFlag(I2C_T *i2c);
sahilmgandhi 18:6a4db94011d3 128 void I2C_Trigger(I2C_T *i2c, uint8_t u8Start, uint8_t u8Stop, uint8_t u8Si, uint8_t u8Ack);
sahilmgandhi 18:6a4db94011d3 129 void I2C_DisableInt(I2C_T *i2c);
sahilmgandhi 18:6a4db94011d3 130 void I2C_EnableInt(I2C_T *i2c);
sahilmgandhi 18:6a4db94011d3 131 uint32_t I2C_GetBusClockFreq(I2C_T *i2c);
sahilmgandhi 18:6a4db94011d3 132 uint32_t I2C_SetBusClockFreq(I2C_T *i2c, uint32_t u32BusClock);
sahilmgandhi 18:6a4db94011d3 133 uint32_t I2C_GetIntFlag(I2C_T *i2c);
sahilmgandhi 18:6a4db94011d3 134 uint32_t I2C_GetStatus(I2C_T *i2c);
sahilmgandhi 18:6a4db94011d3 135 uint32_t I2C_GetData(I2C_T *i2c);
sahilmgandhi 18:6a4db94011d3 136 void I2C_SetData(I2C_T *i2c, uint8_t u8Data);
sahilmgandhi 18:6a4db94011d3 137 void I2C_SetSlaveAddr(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddr, uint8_t u8GCMode);
sahilmgandhi 18:6a4db94011d3 138 void I2C_SetSlaveAddrMask(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddrMask);
sahilmgandhi 18:6a4db94011d3 139 void I2C_EnableTimeout(I2C_T *i2c, uint8_t u8LongTimeout);
sahilmgandhi 18:6a4db94011d3 140 void I2C_DisableTimeout(I2C_T *i2c);
sahilmgandhi 18:6a4db94011d3 141 void I2C_EnableWakeup(I2C_T *i2c);
sahilmgandhi 18:6a4db94011d3 142 void I2C_DisableWakeup(I2C_T *i2c);
sahilmgandhi 18:6a4db94011d3 143
sahilmgandhi 18:6a4db94011d3 144 /*@}*/ /* end of group NUC472_442_I2C_EXPORTED_FUNCTIONS */
sahilmgandhi 18:6a4db94011d3 145
sahilmgandhi 18:6a4db94011d3 146 /*@}*/ /* end of group NUC472_442_I2C_Driver */
sahilmgandhi 18:6a4db94011d3 147
sahilmgandhi 18:6a4db94011d3 148 /*@}*/ /* end of group NUC472_442_Device_Driver */
sahilmgandhi 18:6a4db94011d3 149
sahilmgandhi 18:6a4db94011d3 150 #ifdef __cplusplus
sahilmgandhi 18:6a4db94011d3 151 }
sahilmgandhi 18:6a4db94011d3 152 #endif
sahilmgandhi 18:6a4db94011d3 153
sahilmgandhi 18:6a4db94011d3 154 #endif //__I2C_H__
sahilmgandhi 18:6a4db94011d3 155
sahilmgandhi 18:6a4db94011d3 156 /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/