lol

Dependencies:   MMA8451Q

Fork of Application by Mateusz Kowalik

Committer:
danix
Date:
Sun Jan 21 22:28:30 2018 +0000
Revision:
12:3a30cdffa27c
Parent:
10:41552d038a69
Working acelerometer and mouse

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Zaitsev 10:41552d038a69 1 /* mbed Microcontroller Library
Zaitsev 10:41552d038a69 2 * Copyright (c) 2006-2013 ARM Limited
Zaitsev 10:41552d038a69 3 *
Zaitsev 10:41552d038a69 4 * Licensed under the Apache License, Version 2.0 (the "License");
Zaitsev 10:41552d038a69 5 * you may not use this file except in compliance with the License.
Zaitsev 10:41552d038a69 6 * You may obtain a copy of the License at
Zaitsev 10:41552d038a69 7 *
Zaitsev 10:41552d038a69 8 * http://www.apache.org/licenses/LICENSE-2.0
Zaitsev 10:41552d038a69 9 *
Zaitsev 10:41552d038a69 10 * Unless required by applicable law or agreed to in writing, software
Zaitsev 10:41552d038a69 11 * distributed under the License is distributed on an "AS IS" BASIS,
Zaitsev 10:41552d038a69 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Zaitsev 10:41552d038a69 13 * See the License for the specific language governing permissions and
Zaitsev 10:41552d038a69 14 * limitations under the License.
Zaitsev 10:41552d038a69 15 */
Zaitsev 10:41552d038a69 16
Zaitsev 10:41552d038a69 17 /* Orion specific header files */
Zaitsev 10:41552d038a69 18
Zaitsev 10:41552d038a69 19 #include "pad.h"
Zaitsev 10:41552d038a69 20
Zaitsev 10:41552d038a69 21 /* MBED header files */
Zaitsev 10:41552d038a69 22 #include "pinmap.h"
Zaitsev 10:41552d038a69 23
Zaitsev 10:41552d038a69 24 void pin_function(PinName pin, int function)
Zaitsev 10:41552d038a69 25 {
Zaitsev 10:41552d038a69 26 /** - Enable the clock for PAD peripheral device */
Zaitsev 10:41552d038a69 27 CLOCK_ENABLE(CLOCK_CROSSB);
Zaitsev 10:41552d038a69 28
Zaitsev 10:41552d038a69 29 /* Note: GPIO 0,1,2,3 are used for UART 1, GPIO 8,9 are used for UART 2 */
Zaitsev 10:41552d038a69 30 CrossbReg_pt crossBar = (CrossbReg_t *)(CROSSBREG_BASE + (pin * CROSS_REG_ADRS_BYTE_SIZE));
Zaitsev 10:41552d038a69 31 crossBar->DIOCTRL0 = function;
Zaitsev 10:41552d038a69 32
Zaitsev 10:41552d038a69 33 /** - Disable the clock for PAD peripheral device */
Zaitsev 10:41552d038a69 34 CLOCK_DISABLE(CLOCK_CROSSB);
Zaitsev 10:41552d038a69 35 }
Zaitsev 10:41552d038a69 36
Zaitsev 10:41552d038a69 37 void pin_mode(PinName pin, PinMode mode)
Zaitsev 10:41552d038a69 38 {
Zaitsev 10:41552d038a69 39 /** - Get PAD IO register address for the PAD number */
Zaitsev 10:41552d038a69 40 PadReg_t *padRegOffset = (PadReg_t*)(PADREG_BASE + (pin * PAD_REG_ADRS_BYTE_SIZE));
Zaitsev 10:41552d038a69 41
Zaitsev 10:41552d038a69 42 /** - Enable the clock for PAD peripheral device */
Zaitsev 10:41552d038a69 43 CLOCK_ENABLE(CLOCK_PAD);
Zaitsev 10:41552d038a69 44
Zaitsev 10:41552d038a69 45 switch (mode) {
Zaitsev 10:41552d038a69 46 case PushPullPullDown:
Zaitsev 10:41552d038a69 47 padRegOffset->PADIO0.BITS.TYPE = PAD_OUTCFG_PUSHPULL;
Zaitsev 10:41552d038a69 48 padRegOffset->PADIO0.BITS.PULL = PAD_PULL_DOWN;
Zaitsev 10:41552d038a69 49 break;
Zaitsev 10:41552d038a69 50
Zaitsev 10:41552d038a69 51 case PushPullNoPull:
Zaitsev 10:41552d038a69 52 padRegOffset->PADIO0.BITS.TYPE = PAD_OUTCFG_PUSHPULL;
Zaitsev 10:41552d038a69 53 padRegOffset->PADIO0.BITS.PULL = PAD_PULL_NONE;
Zaitsev 10:41552d038a69 54 break;
Zaitsev 10:41552d038a69 55
Zaitsev 10:41552d038a69 56 case PushPullPullUp:
Zaitsev 10:41552d038a69 57 padRegOffset->PADIO0.BITS.TYPE = PAD_OUTCFG_PUSHPULL;
Zaitsev 10:41552d038a69 58 padRegOffset->PADIO0.BITS.PULL = PAD_PULL_UP;
Zaitsev 10:41552d038a69 59 break;
Zaitsev 10:41552d038a69 60
Zaitsev 10:41552d038a69 61 case OpenDrainPullDown:
Zaitsev 10:41552d038a69 62 padRegOffset->PADIO0.BITS.TYPE = PAD_OOUTCFG_OPENDRAIN;
Zaitsev 10:41552d038a69 63 padRegOffset->PADIO0.BITS.PULL = PAD_PULL_DOWN;
Zaitsev 10:41552d038a69 64 break;
Zaitsev 10:41552d038a69 65
Zaitsev 10:41552d038a69 66 case OpenDrainNoPull:
Zaitsev 10:41552d038a69 67 padRegOffset->PADIO0.BITS.TYPE = PAD_OOUTCFG_OPENDRAIN;
Zaitsev 10:41552d038a69 68 padRegOffset->PADIO0.BITS.PULL = PAD_PULL_NONE;
Zaitsev 10:41552d038a69 69 break;
Zaitsev 10:41552d038a69 70
Zaitsev 10:41552d038a69 71 case OpenDrainPullUp:
Zaitsev 10:41552d038a69 72 padRegOffset->PADIO0.BITS.TYPE = PAD_OOUTCFG_OPENDRAIN;
Zaitsev 10:41552d038a69 73 padRegOffset->PADIO0.BITS.PULL = PAD_PULL_UP;
Zaitsev 10:41552d038a69 74 break;
Zaitsev 10:41552d038a69 75
Zaitsev 10:41552d038a69 76 default:
Zaitsev 10:41552d038a69 77 break;
Zaitsev 10:41552d038a69 78 }
Zaitsev 10:41552d038a69 79
Zaitsev 10:41552d038a69 80 /** - Disable the clock for PAD peripheral device */
Zaitsev 10:41552d038a69 81 CLOCK_DISABLE(CLOCK_PAD);
Zaitsev 10:41552d038a69 82
Zaitsev 10:41552d038a69 83 }