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 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 3 * @file pad.c
sahilmgandhi 18:6a4db94011d3 4 * @brief PAD management support code
sahilmgandhi 18:6a4db94011d3 5 * @internal
sahilmgandhi 18:6a4db94011d3 6 * @author ON Semiconductor
sahilmgandhi 18:6a4db94011d3 7 * $Rev: 2848 $
sahilmgandhi 18:6a4db94011d3 8 * $Date: 2014-04-01 22:48:18 +0530 (Tue, 01 Apr 2014) $
sahilmgandhi 18:6a4db94011d3 9 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 10 * Copyright 2016 Semiconductor Components Industries LLC (d/b/a “ON Semiconductor”).
sahilmgandhi 18:6a4db94011d3 11 * All rights reserved. This software and/or documentation is licensed by ON Semiconductor
sahilmgandhi 18:6a4db94011d3 12 * under limited terms and conditions. The terms and conditions pertaining to the software
sahilmgandhi 18:6a4db94011d3 13 * and/or documentation are available at http://www.onsemi.com/site/pdf/ONSEMI_T&C.pdf
sahilmgandhi 18:6a4db94011d3 14 * (“ON Semiconductor Standard Terms and Conditions of Sale, Section 8 Software”) and
sahilmgandhi 18:6a4db94011d3 15 * if applicable the software license agreement. Do not use this software and/or
sahilmgandhi 18:6a4db94011d3 16 * documentation unless you have carefully read and you agree to the limited terms and
sahilmgandhi 18:6a4db94011d3 17 * conditions. By using this software and/or documentation, you agree to the limited
sahilmgandhi 18:6a4db94011d3 18 * terms and conditions.
sahilmgandhi 18:6a4db94011d3 19 *
sahilmgandhi 18:6a4db94011d3 20 * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
sahilmgandhi 18:6a4db94011d3 21 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
sahilmgandhi 18:6a4db94011d3 22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
sahilmgandhi 18:6a4db94011d3 23 * ON SEMICONDUCTOR SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL,
sahilmgandhi 18:6a4db94011d3 24 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
sahilmgandhi 18:6a4db94011d3 25 * @endinternal
sahilmgandhi 18:6a4db94011d3 26 *
sahilmgandhi 18:6a4db94011d3 27 * @ingroup pad
sahilmgandhi 18:6a4db94011d3 28 *
sahilmgandhi 18:6a4db94011d3 29 * @details
sahilmgandhi 18:6a4db94011d3 30 */
sahilmgandhi 18:6a4db94011d3 31
sahilmgandhi 18:6a4db94011d3 32 /*************************************************************************************************
sahilmgandhi 18:6a4db94011d3 33 * *
sahilmgandhi 18:6a4db94011d3 34 * Header files *
sahilmgandhi 18:6a4db94011d3 35 * *
sahilmgandhi 18:6a4db94011d3 36 *************************************************************************************************/
sahilmgandhi 18:6a4db94011d3 37
sahilmgandhi 18:6a4db94011d3 38 #include "memory_map.h"
sahilmgandhi 18:6a4db94011d3 39 #include "pad_map.h"
sahilmgandhi 18:6a4db94011d3 40 #include "clock.h"
sahilmgandhi 18:6a4db94011d3 41
sahilmgandhi 18:6a4db94011d3 42 /*************************************************************************************************
sahilmgandhi 18:6a4db94011d3 43 * *
sahilmgandhi 18:6a4db94011d3 44 * Symbolic Constants *
sahilmgandhi 18:6a4db94011d3 45 * *
sahilmgandhi 18:6a4db94011d3 46 *************************************************************************************************/
sahilmgandhi 18:6a4db94011d3 47 #define PAD_CTRL_OP_DRIVE_STRENGTH_MASK (uint32_t)0x1C
sahilmgandhi 18:6a4db94011d3 48 #define PAD_NUM_OF_IO 17
sahilmgandhi 18:6a4db94011d3 49 #define PAD_OP_DRIVE_STRGTH_MAX 7
sahilmgandhi 18:6a4db94011d3 50 #define PAD_OP_DRIVE_TYPE_MAX 1
sahilmgandhi 18:6a4db94011d3 51 #define PAD_OP_PULL_TYPE_MAX 3
sahilmgandhi 18:6a4db94011d3 52
sahilmgandhi 18:6a4db94011d3 53 #define PAD_REG_ADRS_BYTE_SIZE 4
sahilmgandhi 18:6a4db94011d3 54
sahilmgandhi 18:6a4db94011d3 55 #define PAD_OP_DRIVE_STRGTH_BIT_POS 2
sahilmgandhi 18:6a4db94011d3 56 #define PAD_OP_DRIVE_TYPE_BIT_POS 5
sahilmgandhi 18:6a4db94011d3 57 #define PAD_OP_PULL_TYPE_BIT_POS 0
sahilmgandhi 18:6a4db94011d3 58
sahilmgandhi 18:6a4db94011d3 59 /*************************************************************************************************
sahilmgandhi 18:6a4db94011d3 60 * *
sahilmgandhi 18:6a4db94011d3 61 * Global variables *
sahilmgandhi 18:6a4db94011d3 62 * *
sahilmgandhi 18:6a4db94011d3 63 *************************************************************************************************/
sahilmgandhi 18:6a4db94011d3 64
sahilmgandhi 18:6a4db94011d3 65 /* Peripheral PAD register mutex */
sahilmgandhi 18:6a4db94011d3 66 /* sem_pt GlobMutexPadReg; */
sahilmgandhi 18:6a4db94011d3 67
sahilmgandhi 18:6a4db94011d3 68 /*************************************************************************************************
sahilmgandhi 18:6a4db94011d3 69 * *
sahilmgandhi 18:6a4db94011d3 70 * Functions *
sahilmgandhi 18:6a4db94011d3 71 * *
sahilmgandhi 18:6a4db94011d3 72 *************************************************************************************************/
sahilmgandhi 18:6a4db94011d3 73
sahilmgandhi 18:6a4db94011d3 74 /** Find description at pad.h */
sahilmgandhi 18:6a4db94011d3 75 void fPadInit()
sahilmgandhi 18:6a4db94011d3 76 {
sahilmgandhi 18:6a4db94011d3 77 /** - Enable the clock for PAD peripheral device */
sahilmgandhi 18:6a4db94011d3 78 CLOCK_ENABLE(CLOCK_PAD);
sahilmgandhi 18:6a4db94011d3 79
sahilmgandhi 18:6a4db94011d3 80 /** - Set pad parameters, output drive strength, pull piece control, output drive type */
sahilmgandhi 18:6a4db94011d3 81 PADREG->PADIO0.WORD = PAD_OUTPUT_PN_L1_OD; /* UART1 TXD */
sahilmgandhi 18:6a4db94011d3 82 PADREG->PADIO1.WORD = PAD_INPUT_PD_L1_PP; /* UART1 RXD */
sahilmgandhi 18:6a4db94011d3 83 PADREG->PADIO2.WORD = PAD_INPUT_PD_L1_PP; /* UART1 CTS */
sahilmgandhi 18:6a4db94011d3 84 PADREG->PADIO3.WORD = PAD_OUTPUT_PN_L1_OD; /* UART1 RTS */
sahilmgandhi 18:6a4db94011d3 85 PADREG->PADIO4.WORD = PAD_UNUSED_PD_L1_PP;
sahilmgandhi 18:6a4db94011d3 86 PADREG->PADIO5.WORD = PAD_UNUSED_PD_L1_PP;
sahilmgandhi 18:6a4db94011d3 87 PADREG->PADIO6.WORD = PAD_UNUSED_PD_L1_PP;
sahilmgandhi 18:6a4db94011d3 88 PADREG->PADIO7.WORD = PAD_UNUSED_PD_L1_PP;
sahilmgandhi 18:6a4db94011d3 89 PADREG->PADIO8.WORD = PAD_OUTPUT_PN_L1_OD; /* UART2 TXD */
sahilmgandhi 18:6a4db94011d3 90 PADREG->PADIO9.WORD = PAD_INPUT_PD_L1_PP; /* UART2 RXD */
sahilmgandhi 18:6a4db94011d3 91 PADREG->PADIO10.WORD = PAD_UNUSED_PD_L1_PP;
sahilmgandhi 18:6a4db94011d3 92 PADREG->PADIO11.WORD = PAD_INPUT_PD_L1_PP; /* SWO */
sahilmgandhi 18:6a4db94011d3 93 PADREG->PADIO12.WORD = PAD_INPUT_PD_L1_PP; /* SWCLK */
sahilmgandhi 18:6a4db94011d3 94 PADREG->PADIO13.WORD = PAD_INPUT_PD_L1_PP; /* SWDIO */
sahilmgandhi 18:6a4db94011d3 95 PADREG->PADIO14.WORD = PAD_INPUT_PD_L1_PP;
sahilmgandhi 18:6a4db94011d3 96 PADREG->PADIO15.WORD = PAD_UNUSED_PD_L1_PP;
sahilmgandhi 18:6a4db94011d3 97 PADREG->PADIO16.WORD = PAD_UNUSED_PD_L1_PP;
sahilmgandhi 18:6a4db94011d3 98 PADREG->PADIO17.WORD = PAD_UNUSED_PD_L1_PP;
sahilmgandhi 18:6a4db94011d3 99
sahilmgandhi 18:6a4db94011d3 100 /** - Disable the clock for PAD peripheral device */
sahilmgandhi 18:6a4db94011d3 101 CLOCK_DISABLE(CLOCK_PAD);
sahilmgandhi 18:6a4db94011d3 102
sahilmgandhi 18:6a4db94011d3 103 }
sahilmgandhi 18:6a4db94011d3 104
sahilmgandhi 18:6a4db94011d3 105 /** Find description at pad.h */
sahilmgandhi 18:6a4db94011d3 106 boolean fPadIOCtrl(uint8_t PadNum, uint8_t OutputDriveStrength, uint8_t OutputDriveType, uint8_t PullType)
sahilmgandhi 18:6a4db94011d3 107 {
sahilmgandhi 18:6a4db94011d3 108 PadReg_t *PadRegOffset;
sahilmgandhi 18:6a4db94011d3 109 /** \verbatim
sahilmgandhi 18:6a4db94011d3 110 Table: O/p drive strength
sahilmgandhi 18:6a4db94011d3 111
sahilmgandhi 18:6a4db94011d3 112 Drive strength 3.3V (min/typ/max) 1V (min/typ/max)
sahilmgandhi 18:6a4db94011d3 113 000 1/1.4/2.1 mA 0.043/0.07/0.11 mA
sahilmgandhi 18:6a4db94011d3 114 001 2/2.7/4.1 mA 0.086/0.15/0.215 mA
sahilmgandhi 18:6a4db94011d3 115 010 4.1/5.3/7.8 mA 0.188/0.3/0.4 mA
sahilmgandhi 18:6a4db94011d3 116 011 8.1/10.4/15 8 mA 0.4/0.6/0.81 mA
sahilmgandhi 18:6a4db94011d3 117 100 20.8/26/37 mA* 1/1.6/2.2 mA
sahilmgandhi 18:6a4db94011d3 118 101 40.5/50/70 mA* 2/3/4.3 mA
sahilmgandhi 18:6a4db94011d3 119 11x 57/73/102 mA* 3/4.6/6.2 mA
sahilmgandhi 18:6a4db94011d3 120
sahilmgandhi 18:6a4db94011d3 121 *Values are only accessible when CDBGPWRUPREQ is high. This limits the maximum output current in functional mode. \endverbatim */
sahilmgandhi 18:6a4db94011d3 122
sahilmgandhi 18:6a4db94011d3 123
sahilmgandhi 18:6a4db94011d3 124 if((PadNum <= PAD_NUM_OF_IO) &&
sahilmgandhi 18:6a4db94011d3 125 (OutputDriveStrength <= PAD_OP_DRIVE_STRGTH_MAX) &&
sahilmgandhi 18:6a4db94011d3 126 (OutputDriveType <= PAD_OP_DRIVE_TYPE_MAX) && (PullType <= PAD_OP_PULL_TYPE_MAX)) {
sahilmgandhi 18:6a4db94011d3 127 /** - Get PAD IO register address for the PAD number */
sahilmgandhi 18:6a4db94011d3 128 PadRegOffset = (PadReg_t*)(PADREG_BASE + (PadNum * PAD_REG_ADRS_BYTE_SIZE));
sahilmgandhi 18:6a4db94011d3 129
sahilmgandhi 18:6a4db94011d3 130 /** - Enable the clock for PAD peripheral device */
sahilmgandhi 18:6a4db94011d3 131 CLOCK_ENABLE(CLOCK_PAD);
sahilmgandhi 18:6a4db94011d3 132
sahilmgandhi 18:6a4db94011d3 133 /** - Set drive type, pulltype & drive strength */
sahilmgandhi 18:6a4db94011d3 134 PadRegOffset->PADIO0.WORD = (uint32_t)((PullType << PAD_OP_PULL_TYPE_BIT_POS) |
sahilmgandhi 18:6a4db94011d3 135 (OutputDriveStrength << PAD_OP_DRIVE_STRGTH_BIT_POS) |
sahilmgandhi 18:6a4db94011d3 136 (OutputDriveType << PAD_OP_DRIVE_TYPE_BIT_POS));
sahilmgandhi 18:6a4db94011d3 137
sahilmgandhi 18:6a4db94011d3 138 /** - Disable the clock for PAD peripheral device */
sahilmgandhi 18:6a4db94011d3 139 CLOCK_DISABLE(CLOCK_PAD);
sahilmgandhi 18:6a4db94011d3 140 return True;
sahilmgandhi 18:6a4db94011d3 141 }
sahilmgandhi 18:6a4db94011d3 142 /* Invalid parameter/s */
sahilmgandhi 18:6a4db94011d3 143 return False;
sahilmgandhi 18:6a4db94011d3 144 }