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 /* mbed Microcontroller Library
sahilmgandhi 18:6a4db94011d3 2 * Copyright (c) 2006-2015 ARM Limited
sahilmgandhi 18:6a4db94011d3 3 *
sahilmgandhi 18:6a4db94011d3 4 * Licensed under the Apache License, Version 2.0 (the "License");
sahilmgandhi 18:6a4db94011d3 5 * you may not use this file except in compliance with the License.
sahilmgandhi 18:6a4db94011d3 6 * You may obtain a copy of the License at
sahilmgandhi 18:6a4db94011d3 7 *
sahilmgandhi 18:6a4db94011d3 8 * http://www.apache.org/licenses/LICENSE-2.0
sahilmgandhi 18:6a4db94011d3 9 *
sahilmgandhi 18:6a4db94011d3 10 * Unless required by applicable law or agreed to in writing, software
sahilmgandhi 18:6a4db94011d3 11 * distributed under the License is distributed on an "AS IS" BASIS,
sahilmgandhi 18:6a4db94011d3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sahilmgandhi 18:6a4db94011d3 13 * See the License for the specific language governing permissions and
sahilmgandhi 18:6a4db94011d3 14 * limitations under the License.
sahilmgandhi 18:6a4db94011d3 15 */
sahilmgandhi 18:6a4db94011d3 16 #include "port_api.h"
sahilmgandhi 18:6a4db94011d3 17 #include "pinmap.h"
sahilmgandhi 18:6a4db94011d3 18 #include "gpio_api.h"
sahilmgandhi 18:6a4db94011d3 19 #include "ioport.h"
sahilmgandhi 18:6a4db94011d3 20
sahilmgandhi 18:6a4db94011d3 21 extern uint8_t g_sys_init;
sahilmgandhi 18:6a4db94011d3 22
sahilmgandhi 18:6a4db94011d3 23 void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
sahilmgandhi 18:6a4db94011d3 24 {
sahilmgandhi 18:6a4db94011d3 25 MBED_ASSERT(obj);
sahilmgandhi 18:6a4db94011d3 26 if (g_sys_init == 0) {
sahilmgandhi 18:6a4db94011d3 27 sysclk_init();
sahilmgandhi 18:6a4db94011d3 28 system_board_init();
sahilmgandhi 18:6a4db94011d3 29 g_sys_init = 1;
sahilmgandhi 18:6a4db94011d3 30 }
sahilmgandhi 18:6a4db94011d3 31 obj->port = port;
sahilmgandhi 18:6a4db94011d3 32 obj->mask = mask;
sahilmgandhi 18:6a4db94011d3 33
sahilmgandhi 18:6a4db94011d3 34 switch (dir) {
sahilmgandhi 18:6a4db94011d3 35 case PIN_INPUT :
sahilmgandhi 18:6a4db94011d3 36 ioport_set_port_dir(port, mask, IOPORT_DIR_INPUT);
sahilmgandhi 18:6a4db94011d3 37 break;
sahilmgandhi 18:6a4db94011d3 38 case PIN_OUTPUT:
sahilmgandhi 18:6a4db94011d3 39 ioport_set_port_dir(port, mask, IOPORT_DIR_OUTPUT);
sahilmgandhi 18:6a4db94011d3 40 break;
sahilmgandhi 18:6a4db94011d3 41 case PIN_INPUT_OUTPUT:
sahilmgandhi 18:6a4db94011d3 42 ioport_set_port_dir(port, mask, IOPORT_DIR_OUTPUT);
sahilmgandhi 18:6a4db94011d3 43 break;
sahilmgandhi 18:6a4db94011d3 44 }
sahilmgandhi 18:6a4db94011d3 45 ioport_set_port_mode(port, mask, IOPORT_MODE_PULLUP);
sahilmgandhi 18:6a4db94011d3 46 }
sahilmgandhi 18:6a4db94011d3 47
sahilmgandhi 18:6a4db94011d3 48 void port_mode(port_t *obj, PinMode mode)
sahilmgandhi 18:6a4db94011d3 49 {
sahilmgandhi 18:6a4db94011d3 50 MBED_ASSERT(obj);
sahilmgandhi 18:6a4db94011d3 51 obj->mode = mode;
sahilmgandhi 18:6a4db94011d3 52 switch (mode) {
sahilmgandhi 18:6a4db94011d3 53 case PullNone :
sahilmgandhi 18:6a4db94011d3 54 ioport_set_port_mode(obj->port, obj->mask, IOPORT_MODE_OPEN_DRAIN);
sahilmgandhi 18:6a4db94011d3 55 break;
sahilmgandhi 18:6a4db94011d3 56 case PullUp:
sahilmgandhi 18:6a4db94011d3 57 ioport_set_port_mode(obj->port, obj->mask, IOPORT_MODE_PULLUP);
sahilmgandhi 18:6a4db94011d3 58 break;
sahilmgandhi 18:6a4db94011d3 59 case PullDown:
sahilmgandhi 18:6a4db94011d3 60 ioport_set_port_mode(obj->port, obj->mask, IOPORT_MODE_PULLDOWN);
sahilmgandhi 18:6a4db94011d3 61 break;
sahilmgandhi 18:6a4db94011d3 62 }
sahilmgandhi 18:6a4db94011d3 63 }
sahilmgandhi 18:6a4db94011d3 64
sahilmgandhi 18:6a4db94011d3 65 void port_dir(port_t *obj, PinDirection dir)
sahilmgandhi 18:6a4db94011d3 66 {
sahilmgandhi 18:6a4db94011d3 67 MBED_ASSERT(obj);
sahilmgandhi 18:6a4db94011d3 68 obj->direction = dir;
sahilmgandhi 18:6a4db94011d3 69 switch (dir) {
sahilmgandhi 18:6a4db94011d3 70 case PIN_INPUT :
sahilmgandhi 18:6a4db94011d3 71 ioport_set_port_dir(obj->port, obj->mask, IOPORT_DIR_INPUT);
sahilmgandhi 18:6a4db94011d3 72 break;
sahilmgandhi 18:6a4db94011d3 73 case PIN_OUTPUT:
sahilmgandhi 18:6a4db94011d3 74 ioport_set_port_dir(obj->port, obj->mask, IOPORT_DIR_OUTPUT);
sahilmgandhi 18:6a4db94011d3 75 break;
sahilmgandhi 18:6a4db94011d3 76 case PIN_INPUT_OUTPUT:
sahilmgandhi 18:6a4db94011d3 77 ioport_set_port_dir(obj->port, obj->mask, IOPORT_DIR_OUTPUT);
sahilmgandhi 18:6a4db94011d3 78 break;
sahilmgandhi 18:6a4db94011d3 79 }
sahilmgandhi 18:6a4db94011d3 80 }
sahilmgandhi 18:6a4db94011d3 81
sahilmgandhi 18:6a4db94011d3 82 void port_write(port_t *obj, int value)
sahilmgandhi 18:6a4db94011d3 83 {
sahilmgandhi 18:6a4db94011d3 84 MBED_ASSERT(obj);
sahilmgandhi 18:6a4db94011d3 85 ioport_set_port_level(obj->port, obj->mask, value);
sahilmgandhi 18:6a4db94011d3 86 }
sahilmgandhi 18:6a4db94011d3 87
sahilmgandhi 18:6a4db94011d3 88 int port_read(port_t *obj)
sahilmgandhi 18:6a4db94011d3 89 {
sahilmgandhi 18:6a4db94011d3 90 MBED_ASSERT(obj);
sahilmgandhi 18:6a4db94011d3 91 return ioport_get_port_level(obj->port, obj->mask);
sahilmgandhi 18:6a4db94011d3 92 }