Mouse code for the MacroRat
mbed-dev/targets/TARGET_NUVOTON/TARGET_NUC472/device/StdDriver/nuc472_ps2.h@46:b156ef445742, 2017-06-03 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 2 | * @file PS2.h |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @version V0.10 |
sahilmgandhi | 18:6a4db94011d3 | 4 | * $Revision: 6 $ |
sahilmgandhi | 18:6a4db94011d3 | 5 | * $Date: 14/10/06 1:58p $ |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @brief NUC472/NUC442 PS2 Driver Header File |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 9 | * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 10 | ******************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 11 | #ifndef __PS2_H__ |
sahilmgandhi | 18:6a4db94011d3 | 12 | #define __PS2_H__ |
sahilmgandhi | 18:6a4db94011d3 | 13 | |
sahilmgandhi | 18:6a4db94011d3 | 14 | /*---------------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 15 | /* Include related headers */ |
sahilmgandhi | 18:6a4db94011d3 | 16 | /*---------------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 17 | #include "NUC472_442.h" |
sahilmgandhi | 18:6a4db94011d3 | 18 | |
sahilmgandhi | 18:6a4db94011d3 | 19 | #ifdef __cplusplus |
sahilmgandhi | 18:6a4db94011d3 | 20 | extern "C" |
sahilmgandhi | 18:6a4db94011d3 | 21 | { |
sahilmgandhi | 18:6a4db94011d3 | 22 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 23 | |
sahilmgandhi | 18:6a4db94011d3 | 24 | |
sahilmgandhi | 18:6a4db94011d3 | 25 | /** @addtogroup NUC472_442_Device_Driver NUC472/NUC442 Device Driver |
sahilmgandhi | 18:6a4db94011d3 | 26 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 27 | */ |
sahilmgandhi | 18:6a4db94011d3 | 28 | |
sahilmgandhi | 18:6a4db94011d3 | 29 | /** @addtogroup NUC472_442_PS2_Driver PS2 Driver |
sahilmgandhi | 18:6a4db94011d3 | 30 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 31 | */ |
sahilmgandhi | 18:6a4db94011d3 | 32 | |
sahilmgandhi | 18:6a4db94011d3 | 33 | |
sahilmgandhi | 18:6a4db94011d3 | 34 | /** @addtogroup NUC472_442_PS2_EXPORTED_FUNCTIONS PS2 Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 35 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 36 | */ |
sahilmgandhi | 18:6a4db94011d3 | 37 | |
sahilmgandhi | 18:6a4db94011d3 | 38 | |
sahilmgandhi | 18:6a4db94011d3 | 39 | /** |
sahilmgandhi | 18:6a4db94011d3 | 40 | * @brief This function use to set TX FIFO length. |
sahilmgandhi | 18:6a4db94011d3 | 41 | * |
sahilmgandhi | 18:6a4db94011d3 | 42 | * @param[in] u32Count TX FIFO length |
sahilmgandhi | 18:6a4db94011d3 | 43 | * |
sahilmgandhi | 18:6a4db94011d3 | 44 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 45 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 46 | */ |
sahilmgandhi | 18:6a4db94011d3 | 47 | #define PS2_SET_TX_BYTE_CNT(u32Count) (PS2->CTL = (PS2->CTL & ~PS2_CTL_TXFDEPTH_Msk) \ |
sahilmgandhi | 18:6a4db94011d3 | 48 | | ((u32Count-1) << PS2_CTL_TXFDEPTH_Pos)) |
sahilmgandhi | 18:6a4db94011d3 | 49 | |
sahilmgandhi | 18:6a4db94011d3 | 50 | /** |
sahilmgandhi | 18:6a4db94011d3 | 51 | * @brief This function use to get PS2 status. |
sahilmgandhi | 18:6a4db94011d3 | 52 | * |
sahilmgandhi | 18:6a4db94011d3 | 53 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 54 | * |
sahilmgandhi | 18:6a4db94011d3 | 55 | * @return PS2 status |
sahilmgandhi | 18:6a4db94011d3 | 56 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 57 | */ |
sahilmgandhi | 18:6a4db94011d3 | 58 | #define PS2_GET_STATUS() (PS2->STATUS) |
sahilmgandhi | 18:6a4db94011d3 | 59 | |
sahilmgandhi | 18:6a4db94011d3 | 60 | /** |
sahilmgandhi | 18:6a4db94011d3 | 61 | * @brief This function use to clear PS2 status. |
sahilmgandhi | 18:6a4db94011d3 | 62 | * |
sahilmgandhi | 18:6a4db94011d3 | 63 | * @param[in] u32Mask Clear the specified status of Ps2 module: |
sahilmgandhi | 18:6a4db94011d3 | 64 | * \ref PS2_STATUS_FRAMEERR_Msk , \ref PS2_STATUS_RXOV_Msk |
sahilmgandhi | 18:6a4db94011d3 | 65 | * |
sahilmgandhi | 18:6a4db94011d3 | 66 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 67 | */ |
sahilmgandhi | 18:6a4db94011d3 | 68 | #define PS2_CLR_STATUS(u32Mask) (PS2D->PS2STATUS = u32Mask) |
sahilmgandhi | 18:6a4db94011d3 | 69 | |
sahilmgandhi | 18:6a4db94011d3 | 70 | /** |
sahilmgandhi | 18:6a4db94011d3 | 71 | * @brief This function use to clear PS2 Tx FIFO. |
sahilmgandhi | 18:6a4db94011d3 | 72 | * |
sahilmgandhi | 18:6a4db94011d3 | 73 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 74 | * |
sahilmgandhi | 18:6a4db94011d3 | 75 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 76 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 77 | */ |
sahilmgandhi | 18:6a4db94011d3 | 78 | __STATIC_INLINE void PS2_CLEAR_TX_FIFO(void) |
sahilmgandhi | 18:6a4db94011d3 | 79 | { |
sahilmgandhi | 18:6a4db94011d3 | 80 | PS2->CTL |= PS2_CTL_CLRFIFO_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 81 | PS2->CTL &= ~PS2_CTL_CLRFIFO_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 82 | } |
sahilmgandhi | 18:6a4db94011d3 | 83 | |
sahilmgandhi | 18:6a4db94011d3 | 84 | /** |
sahilmgandhi | 18:6a4db94011d3 | 85 | * @brief This function use to clear PS2 Rx interrupt. |
sahilmgandhi | 18:6a4db94011d3 | 86 | * |
sahilmgandhi | 18:6a4db94011d3 | 87 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 88 | * |
sahilmgandhi | 18:6a4db94011d3 | 89 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 90 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 91 | */ |
sahilmgandhi | 18:6a4db94011d3 | 92 | #define PS2_CLR_RX_INT_FLAG() (PS2->INTSTS = PS2_INTSTS_RXIF_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 93 | |
sahilmgandhi | 18:6a4db94011d3 | 94 | /** |
sahilmgandhi | 18:6a4db94011d3 | 95 | * @brief This function use to clear PS2 Tx interrupt. |
sahilmgandhi | 18:6a4db94011d3 | 96 | * |
sahilmgandhi | 18:6a4db94011d3 | 97 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 98 | * |
sahilmgandhi | 18:6a4db94011d3 | 99 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 100 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 101 | */ |
sahilmgandhi | 18:6a4db94011d3 | 102 | #define PS2_CLR_TX_INT_FLAG() (PS2->INTSTS = PS2_INTSTS_TXIF_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 103 | |
sahilmgandhi | 18:6a4db94011d3 | 104 | /** |
sahilmgandhi | 18:6a4db94011d3 | 105 | * @brief This function use to get PS2 interrupt. |
sahilmgandhi | 18:6a4db94011d3 | 106 | * |
sahilmgandhi | 18:6a4db94011d3 | 107 | * @param[in] u32IntFlag interrupt flag: \ref PS2_INTSTS_TXIF_Msk , \ref PS2_INTSTS_RXIF_Msk |
sahilmgandhi | 18:6a4db94011d3 | 108 | * |
sahilmgandhi | 18:6a4db94011d3 | 109 | * @return 1: interrupt occurs |
sahilmgandhi | 18:6a4db94011d3 | 110 | * 0: interrupt not occurs |
sahilmgandhi | 18:6a4db94011d3 | 111 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 112 | */ |
sahilmgandhi | 18:6a4db94011d3 | 113 | #define PS2_GET_INT_FLAG(u32IntFlag) ((PS2->INTSTS & u32IntFlag)?1:0) |
sahilmgandhi | 18:6a4db94011d3 | 114 | |
sahilmgandhi | 18:6a4db94011d3 | 115 | /** |
sahilmgandhi | 18:6a4db94011d3 | 116 | * @brief This function use to set PS2CLK and PS2DATA pins are controlled by hardware. |
sahilmgandhi | 18:6a4db94011d3 | 117 | * |
sahilmgandhi | 18:6a4db94011d3 | 118 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 119 | * |
sahilmgandhi | 18:6a4db94011d3 | 120 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 121 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 122 | */ |
sahilmgandhi | 18:6a4db94011d3 | 123 | #define PS2_DISABLE_OVERRIDE() (PS2->CTL &= ~PS2_CTL_PS2EN_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 124 | |
sahilmgandhi | 18:6a4db94011d3 | 125 | /** |
sahilmgandhi | 18:6a4db94011d3 | 126 | * @brief This function use to set PS2CLK and PS2DATA pins are controlled by software. |
sahilmgandhi | 18:6a4db94011d3 | 127 | * |
sahilmgandhi | 18:6a4db94011d3 | 128 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 129 | * |
sahilmgandhi | 18:6a4db94011d3 | 130 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 131 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 132 | */ |
sahilmgandhi | 18:6a4db94011d3 | 133 | #define PS2_ENABLE_OVERRIDE() (PS2->CTL |= PS2_CTL_PS2EN_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 134 | |
sahilmgandhi | 18:6a4db94011d3 | 135 | /** |
sahilmgandhi | 18:6a4db94011d3 | 136 | * @brief This function use to get indicates which data byte in transmit data shift register. |
sahilmgandhi | 18:6a4db94011d3 | 137 | * |
sahilmgandhi | 18:6a4db94011d3 | 138 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 139 | * |
sahilmgandhi | 18:6a4db94011d3 | 140 | * @return The indicates which data byte in transmit data shift register. |
sahilmgandhi | 18:6a4db94011d3 | 141 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 142 | */ |
sahilmgandhi | 18:6a4db94011d3 | 143 | #define PS2_GET_TX_BYTE_INDEX() ((PS2->STATUS & PS2_STATUS_BYTEIDX_Msk) >> PS2_STATUS_BYTEIDX_Pos) |
sahilmgandhi | 18:6a4db94011d3 | 144 | |
sahilmgandhi | 18:6a4db94011d3 | 145 | /** |
sahilmgandhi | 18:6a4db94011d3 | 146 | * @brief This function use to set PS2DATA Pin low. |
sahilmgandhi | 18:6a4db94011d3 | 147 | * |
sahilmgandhi | 18:6a4db94011d3 | 148 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 149 | * |
sahilmgandhi | 18:6a4db94011d3 | 150 | * @return None. |
sahilmgandhi | 18:6a4db94011d3 | 151 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 152 | */ |
sahilmgandhi | 18:6a4db94011d3 | 153 | #define PS2_SET_DATA_LOW() (PS2->CTL &= ~PS2_CTL_FPS2DAT_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 154 | |
sahilmgandhi | 18:6a4db94011d3 | 155 | /** |
sahilmgandhi | 18:6a4db94011d3 | 156 | * @brief This function use to set PS2DATA Pin high. |
sahilmgandhi | 18:6a4db94011d3 | 157 | * |
sahilmgandhi | 18:6a4db94011d3 | 158 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 159 | * |
sahilmgandhi | 18:6a4db94011d3 | 160 | * @return None. |
sahilmgandhi | 18:6a4db94011d3 | 161 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 162 | */ |
sahilmgandhi | 18:6a4db94011d3 | 163 | #define PS2_SET_DATA_HIGH() (PS2->CTL |= PS2_CTL_FPS2DAT_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 164 | |
sahilmgandhi | 18:6a4db94011d3 | 165 | /** |
sahilmgandhi | 18:6a4db94011d3 | 166 | * @brief This function use to set PS2CLK Pin low. |
sahilmgandhi | 18:6a4db94011d3 | 167 | * |
sahilmgandhi | 18:6a4db94011d3 | 168 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 169 | * |
sahilmgandhi | 18:6a4db94011d3 | 170 | * @return None. |
sahilmgandhi | 18:6a4db94011d3 | 171 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 172 | */ |
sahilmgandhi | 18:6a4db94011d3 | 173 | #define PS2_SET_CLK_LOW() (PS2->CTL &= ~PS2_CTL_FPS2CLK_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 174 | |
sahilmgandhi | 18:6a4db94011d3 | 175 | /** |
sahilmgandhi | 18:6a4db94011d3 | 176 | * @brief This function use to set PS2CLK Pin high. |
sahilmgandhi | 18:6a4db94011d3 | 177 | * |
sahilmgandhi | 18:6a4db94011d3 | 178 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 179 | * |
sahilmgandhi | 18:6a4db94011d3 | 180 | * @return None. |
sahilmgandhi | 18:6a4db94011d3 | 181 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 182 | */ |
sahilmgandhi | 18:6a4db94011d3 | 183 | #define PS2_SET_CLK_HIGH() (PS2->CTL |= PS2_CTL_FPS2CLK_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 184 | |
sahilmgandhi | 18:6a4db94011d3 | 185 | /** |
sahilmgandhi | 18:6a4db94011d3 | 186 | * @brief If Parity error or Stop bit is Not Received Correctly, Acknowledge will Not be Sent to host at 12th clock. |
sahilmgandhi | 18:6a4db94011d3 | 187 | * |
sahilmgandhi | 18:6a4db94011d3 | 188 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 189 | * |
sahilmgandhi | 18:6a4db94011d3 | 190 | * @return None. |
sahilmgandhi | 18:6a4db94011d3 | 191 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 192 | */ |
sahilmgandhi | 18:6a4db94011d3 | 193 | #define PS2_DISABLE_ACK_ALWAYS() (PS2->CTL |= PS2_CTL_ACK_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 194 | |
sahilmgandhi | 18:6a4db94011d3 | 195 | /** |
sahilmgandhi | 18:6a4db94011d3 | 196 | * @brief Always sends acknowledge to host at 12th clock for host to device communication. |
sahilmgandhi | 18:6a4db94011d3 | 197 | * |
sahilmgandhi | 18:6a4db94011d3 | 198 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 199 | * |
sahilmgandhi | 18:6a4db94011d3 | 200 | * @return None. |
sahilmgandhi | 18:6a4db94011d3 | 201 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 202 | */ |
sahilmgandhi | 18:6a4db94011d3 | 203 | #define PS2_ENABLE_ACK_ALWAYS() (PS2->CTL &= ~PS2_CTL_ACK_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 204 | |
sahilmgandhi | 18:6a4db94011d3 | 205 | |
sahilmgandhi | 18:6a4db94011d3 | 206 | /*---------------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 207 | /* Define Function Prototypes */ |
sahilmgandhi | 18:6a4db94011d3 | 208 | /*---------------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 209 | |
sahilmgandhi | 18:6a4db94011d3 | 210 | void PS2_Open(void); |
sahilmgandhi | 18:6a4db94011d3 | 211 | void PS2_Close(void); |
sahilmgandhi | 18:6a4db94011d3 | 212 | uint8_t PS2_Read(void); |
sahilmgandhi | 18:6a4db94011d3 | 213 | int32_t PS2_Write(uint32_t *pu32Buf, uint32_t u32ByteCount); |
sahilmgandhi | 18:6a4db94011d3 | 214 | void PS2_EnableInt(uint32_t u32Mask); |
sahilmgandhi | 18:6a4db94011d3 | 215 | void PS2_DisableInt(uint32_t u32Mask); |
sahilmgandhi | 18:6a4db94011d3 | 216 | |
sahilmgandhi | 18:6a4db94011d3 | 217 | |
sahilmgandhi | 18:6a4db94011d3 | 218 | /*@}*/ /* end of group NUC472_442_PS2_EXPORTED_FUNCTIONS */ |
sahilmgandhi | 18:6a4db94011d3 | 219 | |
sahilmgandhi | 18:6a4db94011d3 | 220 | /*@}*/ /* end of group NUC472_442_PS2_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 221 | |
sahilmgandhi | 18:6a4db94011d3 | 222 | /*@}*/ /* end of group NUC472_442_Device_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 223 | |
sahilmgandhi | 18:6a4db94011d3 | 224 | #ifdef __cplusplus |
sahilmgandhi | 18:6a4db94011d3 | 225 | } |
sahilmgandhi | 18:6a4db94011d3 | 226 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 227 | |
sahilmgandhi | 18:6a4db94011d3 | 228 | #endif //__PS2_H__ |
sahilmgandhi | 18:6a4db94011d3 | 229 | |
sahilmgandhi | 18:6a4db94011d3 | 230 | /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/ |
sahilmgandhi | 18:6a4db94011d3 | 231 |