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 #ifndef MBED_TICKER_H
switches 0:5c4d7b2438d3 17 #define MBED_TICKER_H
switches 0:5c4d7b2438d3 18
switches 0:5c4d7b2438d3 19 #include "drivers/TimerEvent.h"
switches 0:5c4d7b2438d3 20 #include "platform/Callback.h"
switches 0:5c4d7b2438d3 21 #include "platform/toolchain.h"
switches 0:5c4d7b2438d3 22
switches 0:5c4d7b2438d3 23 namespace mbed {
switches 0:5c4d7b2438d3 24 /** \addtogroup drivers */
switches 0:5c4d7b2438d3 25 /** @{*/
switches 0:5c4d7b2438d3 26
switches 0:5c4d7b2438d3 27 /** A Ticker is used to call a function at a recurring interval
switches 0:5c4d7b2438d3 28 *
switches 0:5c4d7b2438d3 29 * You can use as many seperate Ticker objects as you require.
switches 0:5c4d7b2438d3 30 *
switches 0:5c4d7b2438d3 31 * @Note Synchronization level: Interrupt safe
switches 0:5c4d7b2438d3 32 *
switches 0:5c4d7b2438d3 33 * Example:
switches 0:5c4d7b2438d3 34 * @code
switches 0:5c4d7b2438d3 35 * // Toggle the blinking led after 5 seconds
switches 0:5c4d7b2438d3 36 *
switches 0:5c4d7b2438d3 37 * #include "mbed.h"
switches 0:5c4d7b2438d3 38 *
switches 0:5c4d7b2438d3 39 * Ticker timer;
switches 0:5c4d7b2438d3 40 * DigitalOut led1(LED1);
switches 0:5c4d7b2438d3 41 * DigitalOut led2(LED2);
switches 0:5c4d7b2438d3 42 *
switches 0:5c4d7b2438d3 43 * int flip = 0;
switches 0:5c4d7b2438d3 44 *
switches 0:5c4d7b2438d3 45 * void attime() {
switches 0:5c4d7b2438d3 46 * flip = !flip;
switches 0:5c4d7b2438d3 47 * }
switches 0:5c4d7b2438d3 48 *
switches 0:5c4d7b2438d3 49 * int main() {
switches 0:5c4d7b2438d3 50 * timer.attach(&attime, 5);
switches 0:5c4d7b2438d3 51 * while(1) {
switches 0:5c4d7b2438d3 52 * if(flip == 0) {
switches 0:5c4d7b2438d3 53 * led1 = !led1;
switches 0:5c4d7b2438d3 54 * } else {
switches 0:5c4d7b2438d3 55 * led2 = !led2;
switches 0:5c4d7b2438d3 56 * }
switches 0:5c4d7b2438d3 57 * wait(0.2);
switches 0:5c4d7b2438d3 58 * }
switches 0:5c4d7b2438d3 59 * }
switches 0:5c4d7b2438d3 60 * @endcode
switches 0:5c4d7b2438d3 61 */
switches 0:5c4d7b2438d3 62 class Ticker : public TimerEvent {
switches 0:5c4d7b2438d3 63
switches 0:5c4d7b2438d3 64 public:
switches 0:5c4d7b2438d3 65 Ticker() : TimerEvent() {
switches 0:5c4d7b2438d3 66 }
switches 0:5c4d7b2438d3 67
switches 0:5c4d7b2438d3 68 Ticker(const ticker_data_t *data) : TimerEvent(data) {
switches 0:5c4d7b2438d3 69 data->interface->init();
switches 0:5c4d7b2438d3 70 }
switches 0:5c4d7b2438d3 71
switches 0:5c4d7b2438d3 72 /** Attach a function to be called by the Ticker, specifiying the interval in seconds
switches 0:5c4d7b2438d3 73 *
switches 0:5c4d7b2438d3 74 * @param func pointer to the function to be called
switches 0:5c4d7b2438d3 75 * @param t the time between calls in seconds
switches 0:5c4d7b2438d3 76 */
switches 0:5c4d7b2438d3 77 void attach(Callback<void()> func, float t) {
switches 0:5c4d7b2438d3 78 attach_us(func, t * 1000000.0f);
switches 0:5c4d7b2438d3 79 }
switches 0:5c4d7b2438d3 80
switches 0:5c4d7b2438d3 81 /** Attach a member function to be called by the Ticker, specifiying the interval in seconds
switches 0:5c4d7b2438d3 82 *
switches 0:5c4d7b2438d3 83 * @param obj pointer to the object to call the member function on
switches 0:5c4d7b2438d3 84 * @param method pointer to the member function to be called
switches 0:5c4d7b2438d3 85 * @param t the time between calls in seconds
switches 0:5c4d7b2438d3 86 * @deprecated
switches 0:5c4d7b2438d3 87 * The attach function does not support cv-qualifiers. Replaced by
switches 0:5c4d7b2438d3 88 * attach(callback(obj, method), t).
switches 0:5c4d7b2438d3 89 */
switches 0:5c4d7b2438d3 90 template<typename T, typename M>
switches 0:5c4d7b2438d3 91 MBED_DEPRECATED_SINCE("mbed-os-5.1",
switches 0:5c4d7b2438d3 92 "The attach function does not support cv-qualifiers. Replaced by "
switches 0:5c4d7b2438d3 93 "attach(callback(obj, method), t).")
switches 0:5c4d7b2438d3 94 void attach(T *obj, M method, float t) {
switches 0:5c4d7b2438d3 95 attach(callback(obj, method), t);
switches 0:5c4d7b2438d3 96 }
switches 0:5c4d7b2438d3 97
switches 0:5c4d7b2438d3 98 /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
switches 0:5c4d7b2438d3 99 *
switches 0:5c4d7b2438d3 100 * @param fptr pointer to the function to be called
switches 0:5c4d7b2438d3 101 * @param t the time between calls in micro-seconds
switches 0:5c4d7b2438d3 102 */
switches 0:5c4d7b2438d3 103 void attach_us(Callback<void()> func, timestamp_t t) {
switches 0:5c4d7b2438d3 104 _function.attach(func);
switches 0:5c4d7b2438d3 105 setup(t);
switches 0:5c4d7b2438d3 106 }
switches 0:5c4d7b2438d3 107
switches 0:5c4d7b2438d3 108 /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
switches 0:5c4d7b2438d3 109 *
switches 0:5c4d7b2438d3 110 * @param tptr pointer to the object to call the member function on
switches 0:5c4d7b2438d3 111 * @param mptr pointer to the member function to be called
switches 0:5c4d7b2438d3 112 * @param t the time between calls in micro-seconds
switches 0:5c4d7b2438d3 113 * @deprecated
switches 0:5c4d7b2438d3 114 * The attach_us function does not support cv-qualifiers. Replaced by
switches 0:5c4d7b2438d3 115 * attach_us(callback(obj, method), t).
switches 0:5c4d7b2438d3 116 */
switches 0:5c4d7b2438d3 117 template<typename T, typename M>
switches 0:5c4d7b2438d3 118 MBED_DEPRECATED_SINCE("mbed-os-5.1",
switches 0:5c4d7b2438d3 119 "The attach_us function does not support cv-qualifiers. Replaced by "
switches 0:5c4d7b2438d3 120 "attach_us(callback(obj, method), t).")
switches 0:5c4d7b2438d3 121 void attach_us(T *obj, M method, timestamp_t t) {
switches 0:5c4d7b2438d3 122 attach_us(Callback<void()>(obj, method), t);
switches 0:5c4d7b2438d3 123 }
switches 0:5c4d7b2438d3 124
switches 0:5c4d7b2438d3 125 virtual ~Ticker() {
switches 0:5c4d7b2438d3 126 detach();
switches 0:5c4d7b2438d3 127 }
switches 0:5c4d7b2438d3 128
switches 0:5c4d7b2438d3 129 /** Detach the function
switches 0:5c4d7b2438d3 130 */
switches 0:5c4d7b2438d3 131 void detach();
switches 0:5c4d7b2438d3 132
switches 0:5c4d7b2438d3 133 protected:
switches 0:5c4d7b2438d3 134 void setup(timestamp_t t);
switches 0:5c4d7b2438d3 135 virtual void handler();
switches 0:5c4d7b2438d3 136
switches 0:5c4d7b2438d3 137 protected:
switches 0:5c4d7b2438d3 138 timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */
switches 0:5c4d7b2438d3 139 Callback<void()> _function; /**< Callback. */
switches 0:5c4d7b2438d3 140 };
switches 0:5c4d7b2438d3 141
switches 0:5c4d7b2438d3 142 } // namespace mbed
switches 0:5c4d7b2438d3 143
switches 0:5c4d7b2438d3 144 #endif
switches 0:5c4d7b2438d3 145
switches 0:5c4d7b2438d3 146 /** @}*/