Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1 /* mbed Microcontroller Library
switches 0:5c4d7b2438d3 2 * Copyright (c) 2006-2013 ARM Limited
switches 0:5c4d7b2438d3 3 *
switches 0:5c4d7b2438d3 4 * Licensed under the Apache License, Version 2.0 (the "License");
switches 0:5c4d7b2438d3 5 * you may not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 6 * You may obtain a copy of the License at
switches 0:5c4d7b2438d3 7 *
switches 0:5c4d7b2438d3 8 * http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 9 *
switches 0:5c4d7b2438d3 10 * Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 11 * distributed under the License is distributed on an "AS IS" BASIS,
switches 0:5c4d7b2438d3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 13 * See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 14 * limitations under the License.
switches 0:5c4d7b2438d3 15 */
switches 0:5c4d7b2438d3 16 #include "drivers/InterruptIn.h"
switches 0:5c4d7b2438d3 17
switches 0:5c4d7b2438d3 18 #if DEVICE_INTERRUPTIN
switches 0:5c4d7b2438d3 19
switches 0:5c4d7b2438d3 20 namespace mbed {
switches 0:5c4d7b2438d3 21
switches 0:5c4d7b2438d3 22 static void donothing() {}
switches 0:5c4d7b2438d3 23
switches 0:5c4d7b2438d3 24 InterruptIn::InterruptIn(PinName pin) : gpio(),
switches 0:5c4d7b2438d3 25 gpio_irq(),
switches 0:5c4d7b2438d3 26 _rise(),
switches 0:5c4d7b2438d3 27 _fall() {
switches 0:5c4d7b2438d3 28 // No lock needed in the constructor
switches 0:5c4d7b2438d3 29
switches 0:5c4d7b2438d3 30 _rise.attach(donothing);
switches 0:5c4d7b2438d3 31 _fall.attach(donothing);
switches 0:5c4d7b2438d3 32
switches 0:5c4d7b2438d3 33 gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
switches 0:5c4d7b2438d3 34 gpio_init_in(&gpio, pin);
switches 0:5c4d7b2438d3 35 }
switches 0:5c4d7b2438d3 36
switches 0:5c4d7b2438d3 37 InterruptIn::~InterruptIn() {
switches 0:5c4d7b2438d3 38 // No lock needed in the destructor
switches 0:5c4d7b2438d3 39 gpio_irq_free(&gpio_irq);
switches 0:5c4d7b2438d3 40 }
switches 0:5c4d7b2438d3 41
switches 0:5c4d7b2438d3 42 int InterruptIn::read() {
switches 0:5c4d7b2438d3 43 // Read only
switches 0:5c4d7b2438d3 44 return gpio_read(&gpio);
switches 0:5c4d7b2438d3 45 }
switches 0:5c4d7b2438d3 46
switches 0:5c4d7b2438d3 47 void InterruptIn::mode(PinMode pull) {
switches 0:5c4d7b2438d3 48 core_util_critical_section_enter();
switches 0:5c4d7b2438d3 49 gpio_mode(&gpio, pull);
switches 0:5c4d7b2438d3 50 core_util_critical_section_exit();
switches 0:5c4d7b2438d3 51 }
switches 0:5c4d7b2438d3 52
switches 0:5c4d7b2438d3 53 void InterruptIn::rise(Callback<void()> func) {
switches 0:5c4d7b2438d3 54 core_util_critical_section_enter();
switches 0:5c4d7b2438d3 55 if (func) {
switches 0:5c4d7b2438d3 56 _rise.attach(func);
switches 0:5c4d7b2438d3 57 gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
switches 0:5c4d7b2438d3 58 } else {
switches 0:5c4d7b2438d3 59 _rise.attach(donothing);
switches 0:5c4d7b2438d3 60 gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
switches 0:5c4d7b2438d3 61 }
switches 0:5c4d7b2438d3 62 core_util_critical_section_exit();
switches 0:5c4d7b2438d3 63 }
switches 0:5c4d7b2438d3 64
switches 0:5c4d7b2438d3 65 void InterruptIn::fall(Callback<void()> func) {
switches 0:5c4d7b2438d3 66 core_util_critical_section_enter();
switches 0:5c4d7b2438d3 67 if (func) {
switches 0:5c4d7b2438d3 68 _fall.attach(func);
switches 0:5c4d7b2438d3 69 gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
switches 0:5c4d7b2438d3 70 } else {
switches 0:5c4d7b2438d3 71 _fall.attach(donothing);
switches 0:5c4d7b2438d3 72 gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
switches 0:5c4d7b2438d3 73 }
switches 0:5c4d7b2438d3 74 core_util_critical_section_exit();
switches 0:5c4d7b2438d3 75 }
switches 0:5c4d7b2438d3 76
switches 0:5c4d7b2438d3 77 void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
switches 0:5c4d7b2438d3 78 InterruptIn *handler = (InterruptIn*)id;
switches 0:5c4d7b2438d3 79 switch (event) {
switches 0:5c4d7b2438d3 80 case IRQ_RISE: handler->_rise.call(); break;
switches 0:5c4d7b2438d3 81 case IRQ_FALL: handler->_fall.call(); break;
switches 0:5c4d7b2438d3 82 case IRQ_NONE: break;
switches 0:5c4d7b2438d3 83 }
switches 0:5c4d7b2438d3 84 }
switches 0:5c4d7b2438d3 85
switches 0:5c4d7b2438d3 86 void InterruptIn::enable_irq() {
switches 0:5c4d7b2438d3 87 core_util_critical_section_enter();
switches 0:5c4d7b2438d3 88 gpio_irq_enable(&gpio_irq);
switches 0:5c4d7b2438d3 89 core_util_critical_section_exit();
switches 0:5c4d7b2438d3 90 }
switches 0:5c4d7b2438d3 91
switches 0:5c4d7b2438d3 92 void InterruptIn::disable_irq() {
switches 0:5c4d7b2438d3 93 core_util_critical_section_enter();
switches 0:5c4d7b2438d3 94 gpio_irq_disable(&gpio_irq);
switches 0:5c4d7b2438d3 95 core_util_critical_section_exit();
switches 0:5c4d7b2438d3 96 }
switches 0:5c4d7b2438d3 97
switches 0:5c4d7b2438d3 98 InterruptIn::operator int() {
switches 0:5c4d7b2438d3 99 // Underlying call is atomic
switches 0:5c4d7b2438d3 100 return read();
switches 0:5c4d7b2438d3 101 }
switches 0:5c4d7b2438d3 102
switches 0:5c4d7b2438d3 103 } // namespace mbed
switches 0:5c4d7b2438d3 104
switches 0:5c4d7b2438d3 105 #endif