mirror of https://github.com/ARMmbed/mbed-os.git
Changed line endings to LF, removed non-ASCII chars from sources
parent
3f703f1bf0
commit
3b465de3aa
|
@ -1,94 +1,94 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_FUNCTIONPOINTER_H
|
||||
#define MBED_FUNCTIONPOINTER_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
namespace mbed {
|
||||
|
||||
typedef void (*pvoidf_t)(void);
|
||||
|
||||
/** A class for storing and calling a pointer to a static or member void function
|
||||
*/
|
||||
class FunctionPointer {
|
||||
public:
|
||||
|
||||
/** Create a FunctionPointer, attaching a static function
|
||||
*
|
||||
* @param function The void static function to attach (default is none)
|
||||
*/
|
||||
FunctionPointer(void (*function)(void) = 0);
|
||||
|
||||
/** Create a FunctionPointer, attaching a member function
|
||||
*
|
||||
* @param object The object pointer to invoke the member function on (i.e. the this pointer)
|
||||
* @param function The address of the void member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
FunctionPointer(T *object, void (T::*member)(void)) {
|
||||
attach(object, member);
|
||||
}
|
||||
|
||||
/** Attach a static function
|
||||
*
|
||||
* @param function The void static function to attach (default is none)
|
||||
*/
|
||||
void attach(void (*function)(void) = 0);
|
||||
|
||||
/** Attach a member function
|
||||
*
|
||||
* @param object The object pointer to invoke the member function on (i.e. the this pointer)
|
||||
* @param function The address of the void member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
void attach(T *object, void (T::*member)(void)) {
|
||||
_object = static_cast<void*>(object);
|
||||
memcpy(_member, (char*)&member, sizeof(member));
|
||||
_membercaller = &FunctionPointer::membercaller<T>;
|
||||
_function = 0;
|
||||
}
|
||||
|
||||
/** Call the attached static or member function
|
||||
*/
|
||||
void call();
|
||||
|
||||
pvoidf_t get_function() const {
|
||||
return (pvoidf_t)_function;
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
void operator ()(void);
|
||||
#endif
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
static void membercaller(void *object, char *member) {
|
||||
T* o = static_cast<T*>(object);
|
||||
void (T::*m)(void);
|
||||
memcpy((char*)&m, member, sizeof(m));
|
||||
(o->*m)();
|
||||
}
|
||||
|
||||
void (*_function)(void); // static function pointer - 0 if none attached
|
||||
void *_object; // object this pointer - 0 if none attached
|
||||
char _member[16]; // raw member function pointer storage - converted back by registered _membercaller
|
||||
void (*_membercaller)(void*, char*); // registered membercaller function to convert back and call _member on _object
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_FUNCTIONPOINTER_H
|
||||
#define MBED_FUNCTIONPOINTER_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
namespace mbed {
|
||||
|
||||
typedef void (*pvoidf_t)(void);
|
||||
|
||||
/** A class for storing and calling a pointer to a static or member void function
|
||||
*/
|
||||
class FunctionPointer {
|
||||
public:
|
||||
|
||||
/** Create a FunctionPointer, attaching a static function
|
||||
*
|
||||
* @param function The void static function to attach (default is none)
|
||||
*/
|
||||
FunctionPointer(void (*function)(void) = 0);
|
||||
|
||||
/** Create a FunctionPointer, attaching a member function
|
||||
*
|
||||
* @param object The object pointer to invoke the member function on (i.e. the this pointer)
|
||||
* @param function The address of the void member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
FunctionPointer(T *object, void (T::*member)(void)) {
|
||||
attach(object, member);
|
||||
}
|
||||
|
||||
/** Attach a static function
|
||||
*
|
||||
* @param function The void static function to attach (default is none)
|
||||
*/
|
||||
void attach(void (*function)(void) = 0);
|
||||
|
||||
/** Attach a member function
|
||||
*
|
||||
* @param object The object pointer to invoke the member function on (i.e. the this pointer)
|
||||
* @param function The address of the void member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
void attach(T *object, void (T::*member)(void)) {
|
||||
_object = static_cast<void*>(object);
|
||||
memcpy(_member, (char*)&member, sizeof(member));
|
||||
_membercaller = &FunctionPointer::membercaller<T>;
|
||||
_function = 0;
|
||||
}
|
||||
|
||||
/** Call the attached static or member function
|
||||
*/
|
||||
void call();
|
||||
|
||||
pvoidf_t get_function() const {
|
||||
return (pvoidf_t)_function;
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
void operator ()(void);
|
||||
#endif
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
static void membercaller(void *object, char *member) {
|
||||
T* o = static_cast<T*>(object);
|
||||
void (T::*m)(void);
|
||||
memcpy((char*)&m, member, sizeof(m));
|
||||
(o->*m)();
|
||||
}
|
||||
|
||||
void (*_function)(void); // static function pointer - 0 if none attached
|
||||
void *_object; // object this pointer - 0 if none attached
|
||||
char _member[16]; // raw member function pointer storage - converted back by registered _membercaller
|
||||
void (*_membercaller)(void*, char*); // registered membercaller function to convert back and call _member on _object
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,273 +1,273 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_INTERRUPTIN_H
|
||||
#define MBED_INTERRUPTIN_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_INTERRUPTIN
|
||||
|
||||
#include "gpio_api.h"
|
||||
#include "gpio_irq_api.h"
|
||||
|
||||
#include "FunctionPointer.h"
|
||||
#include "CallChain.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A digital interrupt input, used to call a function on a rising or falling edge
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Flash an LED while waiting for events
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* InterruptIn event(p16);
|
||||
* DigitalOut led(LED1);
|
||||
*
|
||||
* void trigger() {
|
||||
* printf("triggered!\n");
|
||||
* }
|
||||
*
|
||||
* int main() {
|
||||
* event.rise(&trigger);
|
||||
* while(1) {
|
||||
* led = !led;
|
||||
* wait(0.25);
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class InterruptIn {
|
||||
|
||||
public:
|
||||
|
||||
/** Create an InterruptIn connected to the specified pin
|
||||
*
|
||||
* @param pin InterruptIn pin to connect to
|
||||
* @param name (optional) A string to identify the object
|
||||
*/
|
||||
InterruptIn(PinName pin);
|
||||
virtual ~InterruptIn();
|
||||
|
||||
int read();
|
||||
#ifdef MBED_OPERATORS
|
||||
operator int();
|
||||
|
||||
#endif
|
||||
|
||||
/** Attach a function to call when a rising edge occurs on the input
|
||||
*
|
||||
* @param fptr A pointer to a void function, or 0 to set as none
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t rise(void (*fptr)(void));
|
||||
|
||||
/** Add a function to be called when a rising edge occurs at the end of the call chain
|
||||
*
|
||||
* @param fptr the function to add
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t rise_add(void (*fptr)(void)) {
|
||||
return rise_add_common(fptr);
|
||||
}
|
||||
|
||||
/** Add a function to be called when a rising edge occurs at the beginning of the call chain
|
||||
*
|
||||
* @param fptr the function to add
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t rise_add_front(void (*fptr)(void)) {
|
||||
return rise_add_common(fptr, true);
|
||||
}
|
||||
|
||||
/** Attach a member function to call when a rising edge occurs on the input
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t rise(T* tptr, void (T::*mptr)(void)) {
|
||||
_rise.clear();
|
||||
pFunctionPointer_t pf = _rise.add(tptr, mptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
|
||||
return pf;
|
||||
}
|
||||
|
||||
/** Add a function to be called when a rising edge occurs at the end of the call chain
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t rise_add(T* tptr, void (T::*mptr)(void)) {
|
||||
return rise_add_common(tptr, mptr);
|
||||
}
|
||||
|
||||
/** Add a function to be called when a rising edge occurs at the beginning of the call chain
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t rise_add_front(T* tptr, void (T::*mptr)(void)) {
|
||||
return rise_add_common(tptr, mptr, true);
|
||||
}
|
||||
|
||||
/** Remove a function from the list of functions to be called when a rising edge occurs
|
||||
*
|
||||
* @param pf the function object to remove
|
||||
*
|
||||
* @returns
|
||||
* true if the function was found and removed, false otherwise
|
||||
*/
|
||||
bool rise_remove(pFunctionPointer_t pf);
|
||||
|
||||
/** Attach a function to call when a falling edge occurs on the input
|
||||
*
|
||||
* @param fptr A pointer to a void function, or 0 to set as none
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t fall(void (*fptr)(void));
|
||||
|
||||
/** Add a function to be called when a falling edge occurs at the end of the call chain
|
||||
*
|
||||
* @param fptr the function to add
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t fall_add(void (*fptr)(void)) {
|
||||
return fall_add_common(fptr);
|
||||
}
|
||||
|
||||
/** Add a function to be called when a falling edge occurs at the beginning of the call chain
|
||||
*
|
||||
* @param fptr the function to add
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t fall_add_front(void (*fptr)(void)) {
|
||||
return fall_add_common(fptr, true);
|
||||
}
|
||||
|
||||
/** Attach a member function to call when a falling edge occurs on the input
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t fall(T* tptr, void (T::*mptr)(void)) {
|
||||
_fall.clear();
|
||||
pFunctionPointer_t pf = _fall.add(tptr, mptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
|
||||
return pf;
|
||||
}
|
||||
|
||||
/** Add a function to be called when a falling edge occurs at the end of the call chain
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t fall_add(T* tptr, void (T::*mptr)(void)) {
|
||||
return fall_add_common(tptr, mptr);
|
||||
}
|
||||
|
||||
/** Add a function to be called when a falling edge occurs at the beginning of the call chain
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t fall_add_front(T* tptr, void (T::*mptr)(void)) {
|
||||
return fall_add_common(tptr, mptr, true);
|
||||
}
|
||||
|
||||
/** Remove a function from the list of functions to be called when a falling edge occurs
|
||||
*
|
||||
* @param pf the function object to remove
|
||||
*
|
||||
* @returns
|
||||
* true if the function was found and removed, false otherwise
|
||||
*/
|
||||
bool fall_remove(pFunctionPointer_t pf);
|
||||
|
||||
/** Set the input pin mode
|
||||
*
|
||||
* @param mode PullUp, PullDown, PullNone
|
||||
*/
|
||||
void mode(PinMode pull);
|
||||
|
||||
static void _irq_handler(uint32_t id, gpio_irq_event event);
|
||||
|
||||
protected:
|
||||
pFunctionPointer_t rise_add_common(void (*fptr)(void), bool front=false);
|
||||
pFunctionPointer_t fall_add_common(void (*fptr)(void), bool front=false);
|
||||
|
||||
template<typename T>
|
||||
pFunctionPointer_t rise_add_common(T* tptr, void (T::*mptr)(void), bool front=false) {
|
||||
pFunctionPointer_t pf = front ? _rise.add_front(tptr, mptr) : _rise.add(tptr, mptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
|
||||
return pf;
|
||||
}
|
||||
template<typename T>
|
||||
pFunctionPointer_t fall_add_common(T* tptr, void (T::*mptr)(void), bool front=false) {
|
||||
pFunctionPointer_t pf = front ? _fall.add_front(tptr, mptr) : _fall.add(tptr, mptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
|
||||
return pf;
|
||||
}
|
||||
|
||||
gpio_t gpio;
|
||||
gpio_irq_t gpio_irq;
|
||||
|
||||
CallChain _rise;
|
||||
CallChain _fall;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_INTERRUPTIN_H
|
||||
#define MBED_INTERRUPTIN_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_INTERRUPTIN
|
||||
|
||||
#include "gpio_api.h"
|
||||
#include "gpio_irq_api.h"
|
||||
|
||||
#include "FunctionPointer.h"
|
||||
#include "CallChain.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A digital interrupt input, used to call a function on a rising or falling edge
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Flash an LED while waiting for events
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* InterruptIn event(p16);
|
||||
* DigitalOut led(LED1);
|
||||
*
|
||||
* void trigger() {
|
||||
* printf("triggered!\n");
|
||||
* }
|
||||
*
|
||||
* int main() {
|
||||
* event.rise(&trigger);
|
||||
* while(1) {
|
||||
* led = !led;
|
||||
* wait(0.25);
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class InterruptIn {
|
||||
|
||||
public:
|
||||
|
||||
/** Create an InterruptIn connected to the specified pin
|
||||
*
|
||||
* @param pin InterruptIn pin to connect to
|
||||
* @param name (optional) A string to identify the object
|
||||
*/
|
||||
InterruptIn(PinName pin);
|
||||
virtual ~InterruptIn();
|
||||
|
||||
int read();
|
||||
#ifdef MBED_OPERATORS
|
||||
operator int();
|
||||
|
||||
#endif
|
||||
|
||||
/** Attach a function to call when a rising edge occurs on the input
|
||||
*
|
||||
* @param fptr A pointer to a void function, or 0 to set as none
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t rise(void (*fptr)(void));
|
||||
|
||||
/** Add a function to be called when a rising edge occurs at the end of the call chain
|
||||
*
|
||||
* @param fptr the function to add
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t rise_add(void (*fptr)(void)) {
|
||||
return rise_add_common(fptr);
|
||||
}
|
||||
|
||||
/** Add a function to be called when a rising edge occurs at the beginning of the call chain
|
||||
*
|
||||
* @param fptr the function to add
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t rise_add_front(void (*fptr)(void)) {
|
||||
return rise_add_common(fptr, true);
|
||||
}
|
||||
|
||||
/** Attach a member function to call when a rising edge occurs on the input
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t rise(T* tptr, void (T::*mptr)(void)) {
|
||||
_rise.clear();
|
||||
pFunctionPointer_t pf = _rise.add(tptr, mptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
|
||||
return pf;
|
||||
}
|
||||
|
||||
/** Add a function to be called when a rising edge occurs at the end of the call chain
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t rise_add(T* tptr, void (T::*mptr)(void)) {
|
||||
return rise_add_common(tptr, mptr);
|
||||
}
|
||||
|
||||
/** Add a function to be called when a rising edge occurs at the beginning of the call chain
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t rise_add_front(T* tptr, void (T::*mptr)(void)) {
|
||||
return rise_add_common(tptr, mptr, true);
|
||||
}
|
||||
|
||||
/** Remove a function from the list of functions to be called when a rising edge occurs
|
||||
*
|
||||
* @param pf the function object to remove
|
||||
*
|
||||
* @returns
|
||||
* true if the function was found and removed, false otherwise
|
||||
*/
|
||||
bool rise_remove(pFunctionPointer_t pf);
|
||||
|
||||
/** Attach a function to call when a falling edge occurs on the input
|
||||
*
|
||||
* @param fptr A pointer to a void function, or 0 to set as none
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t fall(void (*fptr)(void));
|
||||
|
||||
/** Add a function to be called when a falling edge occurs at the end of the call chain
|
||||
*
|
||||
* @param fptr the function to add
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t fall_add(void (*fptr)(void)) {
|
||||
return fall_add_common(fptr);
|
||||
}
|
||||
|
||||
/** Add a function to be called when a falling edge occurs at the beginning of the call chain
|
||||
*
|
||||
* @param fptr the function to add
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t fall_add_front(void (*fptr)(void)) {
|
||||
return fall_add_common(fptr, true);
|
||||
}
|
||||
|
||||
/** Attach a member function to call when a falling edge occurs on the input
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t fall(T* tptr, void (T::*mptr)(void)) {
|
||||
_fall.clear();
|
||||
pFunctionPointer_t pf = _fall.add(tptr, mptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
|
||||
return pf;
|
||||
}
|
||||
|
||||
/** Add a function to be called when a falling edge occurs at the end of the call chain
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t fall_add(T* tptr, void (T::*mptr)(void)) {
|
||||
return fall_add_common(tptr, mptr);
|
||||
}
|
||||
|
||||
/** Add a function to be called when a falling edge occurs at the beginning of the call chain
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t fall_add_front(T* tptr, void (T::*mptr)(void)) {
|
||||
return fall_add_common(tptr, mptr, true);
|
||||
}
|
||||
|
||||
/** Remove a function from the list of functions to be called when a falling edge occurs
|
||||
*
|
||||
* @param pf the function object to remove
|
||||
*
|
||||
* @returns
|
||||
* true if the function was found and removed, false otherwise
|
||||
*/
|
||||
bool fall_remove(pFunctionPointer_t pf);
|
||||
|
||||
/** Set the input pin mode
|
||||
*
|
||||
* @param mode PullUp, PullDown, PullNone
|
||||
*/
|
||||
void mode(PinMode pull);
|
||||
|
||||
static void _irq_handler(uint32_t id, gpio_irq_event event);
|
||||
|
||||
protected:
|
||||
pFunctionPointer_t rise_add_common(void (*fptr)(void), bool front=false);
|
||||
pFunctionPointer_t fall_add_common(void (*fptr)(void), bool front=false);
|
||||
|
||||
template<typename T>
|
||||
pFunctionPointer_t rise_add_common(T* tptr, void (T::*mptr)(void), bool front=false) {
|
||||
pFunctionPointer_t pf = front ? _rise.add_front(tptr, mptr) : _rise.add(tptr, mptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
|
||||
return pf;
|
||||
}
|
||||
template<typename T>
|
||||
pFunctionPointer_t fall_add_common(T* tptr, void (T::*mptr)(void), bool front=false) {
|
||||
pFunctionPointer_t pf = front ? _fall.add_front(tptr, mptr) : _fall.add(tptr, mptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
|
||||
return pf;
|
||||
}
|
||||
|
||||
gpio_t gpio;
|
||||
gpio_irq_t gpio_irq;
|
||||
|
||||
CallChain _rise;
|
||||
CallChain _fall;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,202 +1,202 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_TICKER_H
|
||||
#define MBED_TICKER_H
|
||||
|
||||
#include "TimerEvent.h"
|
||||
#include "FunctionPointer.h"
|
||||
#include "CallChain.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A Ticker is used to call a function at a recurring interval
|
||||
*
|
||||
* You can use as many seperate Ticker objects as you require.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Toggle the blinking led after 5 seconds
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* Ticker timer;
|
||||
* DigitalOut led1(LED1);
|
||||
* DigitalOut led2(LED2);
|
||||
*
|
||||
* int flip = 0;
|
||||
*
|
||||
* void attime() {
|
||||
* flip = !flip;
|
||||
* }
|
||||
*
|
||||
* int main() {
|
||||
* timer.attach(&attime, 5);
|
||||
* while(1) {
|
||||
* if(flip == 0) {
|
||||
* led1 = !led1;
|
||||
* } else {
|
||||
* led2 = !led2;
|
||||
* }
|
||||
* wait(0.2);
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class Ticker : public TimerEvent {
|
||||
|
||||
public:
|
||||
|
||||
/** Attach a function to be called by the Ticker, specifiying the interval in seconds
|
||||
*
|
||||
* @param fptr pointer to the function to be called
|
||||
* @param t the time between calls in seconds
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t attach(void (*fptr)(void), float t) {
|
||||
return attach_us(fptr, t * 1000000.0f);
|
||||
}
|
||||
|
||||
/** Add a function to be called by the Ticker at the end of the call chain
|
||||
*
|
||||
* @param fptr the function to add
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t add_function(void (*fptr)(void)) {
|
||||
return add_function_helper(fptr);
|
||||
}
|
||||
|
||||
/** Add a function to be called by the Ticker at the beginning of the call chain
|
||||
*
|
||||
* @param fptr the function to add
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t add_function_front(void (*fptr)(void)) {
|
||||
return add_function_helper(fptr, true);
|
||||
}
|
||||
|
||||
/** Attach a member function to be called by the Ticker, specifiying the interval in seconds
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
* @param t the time between calls in seconds
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t attach(T* tptr, void (T::*mptr)(void), float t) {
|
||||
return attach_us(tptr, mptr, t * 1000000.0f);
|
||||
}
|
||||
|
||||
/** Add a function to be called by the Ticker at the end of the call chain
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t add_function(T* tptr, void (T::*mptr)(void)) {
|
||||
return add_function_helper(tptr, mptr);
|
||||
}
|
||||
|
||||
/** Add a function to be called by the Ticker at the beginning of the call chain
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t add_function_front(T* tptr, void (T::*mptr)(void)) {
|
||||
return add_function_helper(tptr, mptr, true);
|
||||
}
|
||||
|
||||
/** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
|
||||
*
|
||||
* @param fptr pointer to the function to be called
|
||||
* @param t the time between calls in micro-seconds
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t attach_us(void (*fptr)(void), unsigned int t) {
|
||||
pFunctionPointer_t pf = _chain.add(fptr);
|
||||
setup(t);
|
||||
return pf;
|
||||
}
|
||||
|
||||
/** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
* @param t the time between calls in micro-seconds
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) {
|
||||
pFunctionPointer_t pf = _chain.add(mptr, tptr);
|
||||
setup(t);
|
||||
return pf;
|
||||
}
|
||||
|
||||
/** Detach the function
|
||||
*/
|
||||
void detach();
|
||||
|
||||
/** Remove a function from the Ticker's call chain
|
||||
*
|
||||
* @param pf the function object to remove
|
||||
*
|
||||
* @returns
|
||||
* true if the function was found and removed, false otherwise
|
||||
*/
|
||||
bool remove_function(pFunctionPointer_t pf) {
|
||||
bool res = _chain.remove(pf);
|
||||
if (res && _chain.size() == 0)
|
||||
detach();
|
||||
return res;
|
||||
}
|
||||
|
||||
protected:
|
||||
void setup(unsigned int t);
|
||||
pFunctionPointer_t add_function_helper(void (*fptr)(void), bool front=false);
|
||||
virtual void handler();
|
||||
|
||||
template<typename T>
|
||||
pFunctionPointer_t add_function_helper(T* tptr, void (T::*mptr)(void), bool front=false) {
|
||||
if (_chain.size() == 0)
|
||||
return NULL;
|
||||
return front ? _chain.add_front(tptr, mptr) : _chain.add(tptr, mptr);
|
||||
}
|
||||
|
||||
unsigned int _delay;
|
||||
CallChain _chain;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_TICKER_H
|
||||
#define MBED_TICKER_H
|
||||
|
||||
#include "TimerEvent.h"
|
||||
#include "FunctionPointer.h"
|
||||
#include "CallChain.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A Ticker is used to call a function at a recurring interval
|
||||
*
|
||||
* You can use as many seperate Ticker objects as you require.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Toggle the blinking led after 5 seconds
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* Ticker timer;
|
||||
* DigitalOut led1(LED1);
|
||||
* DigitalOut led2(LED2);
|
||||
*
|
||||
* int flip = 0;
|
||||
*
|
||||
* void attime() {
|
||||
* flip = !flip;
|
||||
* }
|
||||
*
|
||||
* int main() {
|
||||
* timer.attach(&attime, 5);
|
||||
* while(1) {
|
||||
* if(flip == 0) {
|
||||
* led1 = !led1;
|
||||
* } else {
|
||||
* led2 = !led2;
|
||||
* }
|
||||
* wait(0.2);
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class Ticker : public TimerEvent {
|
||||
|
||||
public:
|
||||
|
||||
/** Attach a function to be called by the Ticker, specifiying the interval in seconds
|
||||
*
|
||||
* @param fptr pointer to the function to be called
|
||||
* @param t the time between calls in seconds
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t attach(void (*fptr)(void), float t) {
|
||||
return attach_us(fptr, t * 1000000.0f);
|
||||
}
|
||||
|
||||
/** Add a function to be called by the Ticker at the end of the call chain
|
||||
*
|
||||
* @param fptr the function to add
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t add_function(void (*fptr)(void)) {
|
||||
return add_function_helper(fptr);
|
||||
}
|
||||
|
||||
/** Add a function to be called by the Ticker at the beginning of the call chain
|
||||
*
|
||||
* @param fptr the function to add
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t add_function_front(void (*fptr)(void)) {
|
||||
return add_function_helper(fptr, true);
|
||||
}
|
||||
|
||||
/** Attach a member function to be called by the Ticker, specifiying the interval in seconds
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
* @param t the time between calls in seconds
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t attach(T* tptr, void (T::*mptr)(void), float t) {
|
||||
return attach_us(tptr, mptr, t * 1000000.0f);
|
||||
}
|
||||
|
||||
/** Add a function to be called by the Ticker at the end of the call chain
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t add_function(T* tptr, void (T::*mptr)(void)) {
|
||||
return add_function_helper(tptr, mptr);
|
||||
}
|
||||
|
||||
/** Add a function to be called by the Ticker at the beginning of the call chain
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t add_function_front(T* tptr, void (T::*mptr)(void)) {
|
||||
return add_function_helper(tptr, mptr, true);
|
||||
}
|
||||
|
||||
/** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
|
||||
*
|
||||
* @param fptr pointer to the function to be called
|
||||
* @param t the time between calls in micro-seconds
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'fptr'
|
||||
*/
|
||||
pFunctionPointer_t attach_us(void (*fptr)(void), unsigned int t) {
|
||||
pFunctionPointer_t pf = _chain.add(fptr);
|
||||
setup(t);
|
||||
return pf;
|
||||
}
|
||||
|
||||
/** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
* @param t the time between calls in micro-seconds
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) {
|
||||
pFunctionPointer_t pf = _chain.add(mptr, tptr);
|
||||
setup(t);
|
||||
return pf;
|
||||
}
|
||||
|
||||
/** Detach the function
|
||||
*/
|
||||
void detach();
|
||||
|
||||
/** Remove a function from the Ticker's call chain
|
||||
*
|
||||
* @param pf the function object to remove
|
||||
*
|
||||
* @returns
|
||||
* true if the function was found and removed, false otherwise
|
||||
*/
|
||||
bool remove_function(pFunctionPointer_t pf) {
|
||||
bool res = _chain.remove(pf);
|
||||
if (res && _chain.size() == 0)
|
||||
detach();
|
||||
return res;
|
||||
}
|
||||
|
||||
protected:
|
||||
void setup(unsigned int t);
|
||||
pFunctionPointer_t add_function_helper(void (*fptr)(void), bool front=false);
|
||||
virtual void handler();
|
||||
|
||||
template<typename T>
|
||||
pFunctionPointer_t add_function_helper(T* tptr, void (T::*mptr)(void), bool front=false) {
|
||||
if (_chain.size() == 0)
|
||||
return NULL;
|
||||
return front ? _chain.add_front(tptr, mptr) : _chain.add(tptr, mptr);
|
||||
}
|
||||
|
||||
unsigned int _delay;
|
||||
CallChain _chain;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "FunctionPointer.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
FunctionPointer::FunctionPointer(void (*function)(void)) {
|
||||
attach(function);
|
||||
}
|
||||
|
||||
void FunctionPointer::attach(void (*function)(void)) {
|
||||
_function = function;
|
||||
_object = 0;
|
||||
}
|
||||
|
||||
void FunctionPointer::call(void) {
|
||||
if (_function) {
|
||||
_function();
|
||||
} else if (_object) {
|
||||
_membercaller(_object, _member);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
void FunctionPointer::operator ()(void) {
|
||||
call();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace mbed
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "FunctionPointer.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
FunctionPointer::FunctionPointer(void (*function)(void)) {
|
||||
attach(function);
|
||||
}
|
||||
|
||||
void FunctionPointer::attach(void (*function)(void)) {
|
||||
_function = function;
|
||||
_object = 0;
|
||||
}
|
||||
|
||||
void FunctionPointer::call(void) {
|
||||
if (_function) {
|
||||
_function();
|
||||
} else if (_object) {
|
||||
_membercaller(_object, _member);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
void FunctionPointer::operator ()(void) {
|
||||
call();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace mbed
|
||||
|
|
|
@ -1,110 +1,110 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "InterruptIn.h"
|
||||
|
||||
#if DEVICE_INTERRUPTIN
|
||||
|
||||
namespace mbed {
|
||||
|
||||
InterruptIn::InterruptIn(PinName pin) {
|
||||
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
|
||||
gpio_init(&gpio, pin, PIN_INPUT);
|
||||
}
|
||||
|
||||
InterruptIn::~InterruptIn() {
|
||||
gpio_irq_free(&gpio_irq);
|
||||
}
|
||||
|
||||
int InterruptIn::read() {
|
||||
return gpio_read(&gpio);
|
||||
}
|
||||
|
||||
void InterruptIn::mode(PinMode pull) {
|
||||
gpio_mode(&gpio, pull);
|
||||
}
|
||||
|
||||
pFunctionPointer_t InterruptIn::rise(void (*fptr)(void)) {
|
||||
pFunctionPointer_t pf = NULL;
|
||||
_rise.clear();
|
||||
if (fptr) {
|
||||
pf = _rise.add(fptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
|
||||
} else {
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
|
||||
}
|
||||
return pf;
|
||||
}
|
||||
|
||||
pFunctionPointer_t InterruptIn::rise_add_common(void (*fptr)(void), bool front) {
|
||||
if (NULL == fptr)
|
||||
return NULL;
|
||||
pFunctionPointer_t pf = front ? _rise.add_front(fptr) : _rise.add(fptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
|
||||
return pf;
|
||||
}
|
||||
|
||||
bool InterruptIn::rise_remove(pFunctionPointer_t pf) {
|
||||
bool res = _rise.remove(pf);
|
||||
if (res && _rise.size() == 0)
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
|
||||
return res;
|
||||
}
|
||||
|
||||
pFunctionPointer_t InterruptIn::fall(void (*fptr)(void)) {
|
||||
pFunctionPointer_t pf = NULL;
|
||||
_fall.clear();
|
||||
if (fptr) {
|
||||
pf = _fall.add(fptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
|
||||
} else {
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
|
||||
}
|
||||
return pf;
|
||||
}
|
||||
|
||||
pFunctionPointer_t InterruptIn::fall_add_common(void (*fptr)(void), bool front) {
|
||||
if (NULL == fptr)
|
||||
return NULL;
|
||||
pFunctionPointer_t pf = front ? _fall.add_front(fptr) : _fall.add(fptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
|
||||
return pf;
|
||||
}
|
||||
|
||||
bool InterruptIn::fall_remove(pFunctionPointer_t pf) {
|
||||
bool res = _fall.remove(pf);
|
||||
if (res && _fall.size() == 0)
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
|
||||
return res;
|
||||
}
|
||||
|
||||
void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
|
||||
InterruptIn *handler = (InterruptIn*)id;
|
||||
switch (event) {
|
||||
case IRQ_RISE: handler->_rise.call(); break;
|
||||
case IRQ_FALL: handler->_fall.call(); break;
|
||||
case IRQ_NONE: break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
InterruptIn::operator int() {
|
||||
return read();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "InterruptIn.h"
|
||||
|
||||
#if DEVICE_INTERRUPTIN
|
||||
|
||||
namespace mbed {
|
||||
|
||||
InterruptIn::InterruptIn(PinName pin) {
|
||||
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
|
||||
gpio_init(&gpio, pin, PIN_INPUT);
|
||||
}
|
||||
|
||||
InterruptIn::~InterruptIn() {
|
||||
gpio_irq_free(&gpio_irq);
|
||||
}
|
||||
|
||||
int InterruptIn::read() {
|
||||
return gpio_read(&gpio);
|
||||
}
|
||||
|
||||
void InterruptIn::mode(PinMode pull) {
|
||||
gpio_mode(&gpio, pull);
|
||||
}
|
||||
|
||||
pFunctionPointer_t InterruptIn::rise(void (*fptr)(void)) {
|
||||
pFunctionPointer_t pf = NULL;
|
||||
_rise.clear();
|
||||
if (fptr) {
|
||||
pf = _rise.add(fptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
|
||||
} else {
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
|
||||
}
|
||||
return pf;
|
||||
}
|
||||
|
||||
pFunctionPointer_t InterruptIn::rise_add_common(void (*fptr)(void), bool front) {
|
||||
if (NULL == fptr)
|
||||
return NULL;
|
||||
pFunctionPointer_t pf = front ? _rise.add_front(fptr) : _rise.add(fptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
|
||||
return pf;
|
||||
}
|
||||
|
||||
bool InterruptIn::rise_remove(pFunctionPointer_t pf) {
|
||||
bool res = _rise.remove(pf);
|
||||
if (res && _rise.size() == 0)
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
|
||||
return res;
|
||||
}
|
||||
|
||||
pFunctionPointer_t InterruptIn::fall(void (*fptr)(void)) {
|
||||
pFunctionPointer_t pf = NULL;
|
||||
_fall.clear();
|
||||
if (fptr) {
|
||||
pf = _fall.add(fptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
|
||||
} else {
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
|
||||
}
|
||||
return pf;
|
||||
}
|
||||
|
||||
pFunctionPointer_t InterruptIn::fall_add_common(void (*fptr)(void), bool front) {
|
||||
if (NULL == fptr)
|
||||
return NULL;
|
||||
pFunctionPointer_t pf = front ? _fall.add_front(fptr) : _fall.add(fptr);
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
|
||||
return pf;
|
||||
}
|
||||
|
||||
bool InterruptIn::fall_remove(pFunctionPointer_t pf) {
|
||||
bool res = _fall.remove(pf);
|
||||
if (res && _fall.size() == 0)
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
|
||||
return res;
|
||||
}
|
||||
|
||||
void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
|
||||
InterruptIn *handler = (InterruptIn*)id;
|
||||
switch (event) {
|
||||
case IRQ_RISE: handler->_rise.call(); break;
|
||||
case IRQ_FALL: handler->_fall.call(); break;
|
||||
case IRQ_NONE: break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
InterruptIn::operator int() {
|
||||
return read();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,45 +1,45 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Ticker.h"
|
||||
|
||||
#include "TimerEvent.h"
|
||||
#include "FunctionPointer.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
void Ticker::detach() {
|
||||
remove();
|
||||
_chain.clear();
|
||||
}
|
||||
|
||||
void Ticker::setup(unsigned int t) {
|
||||
remove();
|
||||
_delay = t;
|
||||
insert(_delay + us_ticker_read());
|
||||
}
|
||||
|
||||
void Ticker::handler() {
|
||||
insert(event.timestamp + _delay);
|
||||
_chain.call();
|
||||
}
|
||||
|
||||
pFunctionPointer_t Ticker::add_function_helper(void (*fptr)(void), bool front) {
|
||||
if (_chain.size() == 0)
|
||||
return NULL;
|
||||
return front ? _chain.add_front(fptr) : _chain.add(fptr);
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Ticker.h"
|
||||
|
||||
#include "TimerEvent.h"
|
||||
#include "FunctionPointer.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
void Ticker::detach() {
|
||||
remove();
|
||||
_chain.clear();
|
||||
}
|
||||
|
||||
void Ticker::setup(unsigned int t) {
|
||||
remove();
|
||||
_delay = t;
|
||||
insert(_delay + us_ticker_read());
|
||||
}
|
||||
|
||||
void Ticker::handler() {
|
||||
insert(event.timestamp + _delay);
|
||||
_chain.call();
|
||||
}
|
||||
|
||||
pFunctionPointer_t Ticker::add_function_helper(void (*fptr)(void), bool front) {
|
||||
if (_chain.size() == 0)
|
||||
return NULL;
|
||||
return front ? _chain.add_front(fptr) : _chain.add(fptr);
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Timeout.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
void Timeout::handler() {
|
||||
_chain.call();
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Timeout.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
void Timeout::handler() {
|
||||
_chain.call();
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -45,7 +45,7 @@
|
|||
//
|
||||
// <h> Watchdog Oscillator Control Register (WDTOSCCTRL)
|
||||
// <o2.0..4> DIVSEL: Select Divider for Fclkana
|
||||
// <i> wdt_osc_clk = Fclkana/ (2 × (1 + DIVSEL))
|
||||
// <i> wdt_osc_clk = Fclkana/ (2 * (1 + DIVSEL))
|
||||
// <0-31>
|
||||
// <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana)
|
||||
// <0=> Undefined
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
//
|
||||
// <h> Watchdog Oscillator Control Register (WDTOSCCTRL)
|
||||
// <o2.0..4> DIVSEL: Select Divider for Fclkana
|
||||
// <i> wdt_osc_clk = Fclkana/ (2 × (1 + DIVSEL))
|
||||
// <i> wdt_osc_clk = Fclkana/ (2 * (1 + DIVSEL))
|
||||
// <0-31>
|
||||
// <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana)
|
||||
// <0=> Undefined
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
//
|
||||
// <h> Watchdog Oscillator Control Register (WDTOSCCTRL)
|
||||
// <o2.0..4> DIVSEL: Select Divider for Fclkana
|
||||
// <i> wdt_osc_clk = Fclkana/ (2 × (1 + DIVSEL))
|
||||
// <i> wdt_osc_clk = Fclkana/ (2 * (1 + DIVSEL))
|
||||
// <0-31>
|
||||
// <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana)
|
||||
// <0=> Undefined
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
//
|
||||
// <h> Watchdog Oscillator Control Register (WDTOSCCTRL)
|
||||
// <o2.0..4> DIVSEL: Select Divider for Fclkana
|
||||
// <i> wdt_osc_clk = Fclkana/ (2 × (1 + DIVSEL))
|
||||
// <i> wdt_osc_clk = Fclkana/ (2 * (1 + DIVSEL))
|
||||
// <0-31>
|
||||
// <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana)
|
||||
// <0=> Undefined
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
//
|
||||
// <h> Watchdog Oscillator Control Register (WDTOSCCTRL)
|
||||
// <o2.0..4> DIVSEL: Select Divider for Fclkana
|
||||
// <i> wdt_osc_clk = Fclkana/ (2 × (1 + DIVSEL))
|
||||
// <i> wdt_osc_clk = Fclkana/ (2 * (1 + DIVSEL))
|
||||
// <0-31>
|
||||
// <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana)
|
||||
// <0=> Undefined
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,105 +1,105 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32f4xx.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 11-January-2013
|
||||
* @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32f4xx_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Define to prevent recursive inclusion
|
||||
*/
|
||||
#ifndef __SYSTEM_STM32F4XX_H
|
||||
#define __SYSTEM_STM32F4XX_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Exported_types
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern void SystemInit(void);
|
||||
extern void SystemCoreClockUpdate(void);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*__SYSTEM_STM32F4XX_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32f4xx.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 11-January-2013
|
||||
* @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32f4xx_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Define to prevent recursive inclusion
|
||||
*/
|
||||
#ifndef __SYSTEM_STM32F4XX_H
|
||||
#define __SYSTEM_STM32F4XX_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Exported_types
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern void SystemInit(void);
|
||||
extern void SystemCoreClockUpdate(void);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*__SYSTEM_STM32F4XX_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
|
Loading…
Reference in New Issue