Mouse code for the MacroRat
mbed-dev/targets/TARGET_RENESAS/TARGET_RZ_A1H/port_api.c@18:6a4db94011d3, 2017-05-14 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sun May 14 23:18:57 2017 +0000
- Revision:
- 18:6a4db94011d3
Publishing again
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /* mbed Microcontroller Library |
sahilmgandhi | 18:6a4db94011d3 | 2 | * Copyright (c) 2006-2013 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 | |
sahilmgandhi | 18:6a4db94011d3 | 20 | PinName port_pin(PortName port, int pin_n) { |
sahilmgandhi | 18:6a4db94011d3 | 21 | return (PinName)(0); |
sahilmgandhi | 18:6a4db94011d3 | 22 | } |
sahilmgandhi | 18:6a4db94011d3 | 23 | |
sahilmgandhi | 18:6a4db94011d3 | 24 | void port_init(port_t *obj, PortName port, int mask, PinDirection dir) { |
sahilmgandhi | 18:6a4db94011d3 | 25 | obj->port = port; |
sahilmgandhi | 18:6a4db94011d3 | 26 | obj->mask = mask; |
sahilmgandhi | 18:6a4db94011d3 | 27 | |
sahilmgandhi | 18:6a4db94011d3 | 28 | // Do not use masking, because it prevents the use of the unmasked pins |
sahilmgandhi | 18:6a4db94011d3 | 29 | // port_reg->FIOMASK = ~mask; |
sahilmgandhi | 18:6a4db94011d3 | 30 | |
sahilmgandhi | 18:6a4db94011d3 | 31 | uint32_t i; |
sahilmgandhi | 18:6a4db94011d3 | 32 | // The function is set per pin: reuse gpio logic |
sahilmgandhi | 18:6a4db94011d3 | 33 | for (i=0; i<32; i++) { |
sahilmgandhi | 18:6a4db94011d3 | 34 | if (obj->mask & (1<<i)) { |
sahilmgandhi | 18:6a4db94011d3 | 35 | gpio_set(port_pin(obj->port, i)); |
sahilmgandhi | 18:6a4db94011d3 | 36 | } |
sahilmgandhi | 18:6a4db94011d3 | 37 | } |
sahilmgandhi | 18:6a4db94011d3 | 38 | |
sahilmgandhi | 18:6a4db94011d3 | 39 | port_dir(obj, dir); |
sahilmgandhi | 18:6a4db94011d3 | 40 | } |
sahilmgandhi | 18:6a4db94011d3 | 41 | |
sahilmgandhi | 18:6a4db94011d3 | 42 | void port_mode(port_t *obj, PinMode mode) { |
sahilmgandhi | 18:6a4db94011d3 | 43 | uint32_t i; |
sahilmgandhi | 18:6a4db94011d3 | 44 | // The mode is set per pin: reuse pinmap logic |
sahilmgandhi | 18:6a4db94011d3 | 45 | for (i=0; i<32; i++) { |
sahilmgandhi | 18:6a4db94011d3 | 46 | if (obj->mask & (1<<i)) { |
sahilmgandhi | 18:6a4db94011d3 | 47 | pin_mode(port_pin(obj->port, i), mode); |
sahilmgandhi | 18:6a4db94011d3 | 48 | } |
sahilmgandhi | 18:6a4db94011d3 | 49 | } |
sahilmgandhi | 18:6a4db94011d3 | 50 | } |
sahilmgandhi | 18:6a4db94011d3 | 51 | |
sahilmgandhi | 18:6a4db94011d3 | 52 | void port_dir(port_t *obj, PinDirection dir) { |
sahilmgandhi | 18:6a4db94011d3 | 53 | switch (dir) { |
sahilmgandhi | 18:6a4db94011d3 | 54 | case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; |
sahilmgandhi | 18:6a4db94011d3 | 55 | case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; |
sahilmgandhi | 18:6a4db94011d3 | 56 | } |
sahilmgandhi | 18:6a4db94011d3 | 57 | } |
sahilmgandhi | 18:6a4db94011d3 | 58 | |
sahilmgandhi | 18:6a4db94011d3 | 59 | void port_write(port_t *obj, int value) { |
sahilmgandhi | 18:6a4db94011d3 | 60 | *obj->reg_out = (*obj->reg_in & ~obj->mask) | (value & obj->mask); |
sahilmgandhi | 18:6a4db94011d3 | 61 | } |
sahilmgandhi | 18:6a4db94011d3 | 62 | |
sahilmgandhi | 18:6a4db94011d3 | 63 | int port_read(port_t *obj) { |
sahilmgandhi | 18:6a4db94011d3 | 64 | return (*obj->reg_in & obj->mask); |
sahilmgandhi | 18:6a4db94011d3 | 65 | } |