ads1115 only
Fork of mbed by
Revision 68:f37f3b9c9f0b, committed 2013-10-23
- Comitter:
- bogdanm
- Date:
- Wed Oct 23 16:23:06 2013 +0300
- Parent:
- 67:a9913a65894f
- Child:
- 69:4a7918f48478
- Commit message:
- Bug fixes and new features
Many changes in this release, including:
- The new RawSerial class is a simple wrapper over the serial HAL that can
be safely used from an interrupt handler.
- Interrupt chaining code was removed from InterruptIn, Serial and Ticker
because it caused lots of issues with the RTOS. Interrupt chaining is
still possible using the InterruptManager class.
- InterruptIn has two new methods (enable and disable irq)
Changed in this revision
--- a/InterruptIn.h Thu Sep 19 15:44:18 2013 +0300 +++ b/InterruptIn.h Wed Oct 23 16:23:06 2013 +0300 @@ -22,9 +22,7 @@ #include "gpio_api.h" #include "gpio_irq_api.h" - #include "FunctionPointer.h" -#include "CallChain.h" namespace mbed { @@ -73,197 +71,59 @@ /** 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); - } + void rise(void (*fptr)(void)); /** 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); + void rise(T* tptr, void (T::*mptr)(void)) { + _rise.attach(tptr, mptr); + gpio_irq_set(&gpio_irq, IRQ_RISE, 1); } - /** 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); - } + void fall(void (*fptr)(void)); /** 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); + void fall(T* tptr, void (T::*mptr)(void)) { + _fall.attach(tptr, mptr); + gpio_irq_set(&gpio_irq, IRQ_FALL, 1); } - /** 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); + /** Enable IRQ + */ + void enable_irq(); + + /** Disable IRQ + */ + void disable_irq(); + 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; + FunctionPointer _rise; + FunctionPointer _fall; }; } // namespace mbed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RawSerial.h Wed Oct 23 16:23:06 2013 +0300 @@ -0,0 +1,80 @@ +/* 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_RAW_SERIAL_H +#define MBED_RAW_SERIAL_H + +#include "platform.h" + +#if DEVICE_SERIAL + +#include "SerialBase.h" +#include "serial_api.h" + +namespace mbed { + +/** A serial port (UART) for communication with other serial devices + * This is a variation of the Serial class that doesn't use streams, + * thus making it safe to use in interrupt handlers with the RTOS. + * + * Can be used for Full Duplex communication, or Simplex by specifying + * one pin as NC (Not Connected) + * + * Example: + * @code + * // Send a char to the PC + * + * #include "mbed.h" + * + * RawSerial pc(USBTX, USBRX); + * + * int main() { + * pc.putc('A'); + * } + * @endcode + */ +class RawSerial: public SerialBase { + +public: + /** Create a RawSerial port, connected to the specified transmit and receive pins + * + * @param tx Transmit pin + * @param rx Receive pin + * + * @note + * Either tx or rx may be specified as NC if unused + */ + RawSerial(PinName tx, PinName rx); + + /** Write a char to the serial port + * + * @param c The char to write + * + * @returns The written char or -1 if an error occured + */ + int putc(int c); + + /** Read a char from the serial port + * + * @returns The char read from the serial port + */ + int getc(); +}; + +} // namespace mbed + +#endif + +#endif
--- a/Serial.h Thu Sep 19 15:44:18 2013 +0300 +++ b/Serial.h Wed Oct 23 16:23:06 2013 +0300 @@ -21,9 +21,8 @@ #if DEVICE_SERIAL #include "Stream.h" -#include "FunctionPointer.h" +#include "SerialBase.h" #include "serial_api.h" -#include "CallChain.h" namespace mbed { @@ -45,7 +44,7 @@ * } * @endcode */ -class Serial : public Stream { +class Serial : public SerialBase, public Stream { public: /** Create a Serial port, connected to the specified transmit and receive pins @@ -58,167 +57,9 @@ */ Serial(PinName tx, PinName rx, const char *name=NULL); - /** Set the baud rate of the serial port - * - * @param baudrate The baudrate of the serial port (default = 9600). - */ - void baud(int baudrate); - - enum Parity { - None = 0, - Odd, - Even, - Forced1, - Forced0 - }; - - enum IrqType { - RxIrq = 0, - TxIrq - }; - - /** Set the transmission format used by the Serial port - * - * @param bits The number of bits in a word (5-8; default = 8) - * @param parity The parity used (Serial::None, Serial::Odd, Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None) - * @param stop The number of stop bits (1 or 2; default = 1) - */ - void format(int bits=8, Parity parity=Serial::None, int stop_bits=1); - - /** Determine if there is a character available to read - * - * @returns - * 1 if there is a character available to read, - * 0 otherwise - */ - int readable(); - - /** Determine if there is space available to write a character - * - * @returns - * 1 if there is space to write a character, - * 0 otherwise - */ - int writeable(); - - /** Attach a function to call whenever a serial interrupt is generated - * - * @param fptr A pointer to a void function, or 0 to set as none - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @returns - * The function object created for 'fptr' - */ - pFunctionPointer_t attach(void (*fptr)(void), IrqType type=RxIrq); - - /** Add a function to be called when a serial interrupt is generated at the end of the call chain - * - * @param fptr the function to add - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @returns - * The function object created for 'fptr' - */ - pFunctionPointer_t add_handler(void (*fptr)(void), IrqType type=RxIrq) { - return add_handler_helper(fptr, type); - } - - /** Add a function to be called when a serial interrupt is generated at the beginning of the call chain - * - * @param fptr the function to add - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @returns - * The function object created for 'fptr' - */ - pFunctionPointer_t add_handler_front(void (*fptr)(void), IrqType type=RxIrq) { - return add_handler_helper(fptr, type, true); - } - - /** Attach a member function to call whenever a serial interrupt is generated - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @param - * The function object created for 'tptr' and 'mptr' - */ - template<typename T> - pFunctionPointer_t attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) { - if((mptr != NULL) && (tptr != NULL)) { - _irq[type].clear(); - pFunctionPointer_t pf = _irq[type].add(tptr, mptr); - serial_irq_set(&_serial, (SerialIrq)type, 1); - return pf; - } - else - return NULL; - } - - /** Add a function to be called when a serial interrupt is generated 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 - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @returns - * The function object created for 'fptr' - */ - template<typename T> - pFunctionPointer_t add_handler(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) { - return add_handler_helper(tptr, mptr, type); - } - - /** Add a function to be called when a serial interrupt is generated 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 - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @returns - * The function object created for 'fptr' - */ - template<typename T> - pFunctionPointer_t add_handler_front(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) { - return add_handler_helper(tptr, mptr, type, true); - } - - /** Remove a function from the list of functions to be called when a serial interrupt is generated - * - * @param pf the function object to remove - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @returns - * true if the function was found and removed, false otherwise - */ - bool remove_handler(pFunctionPointer_t pf, IrqType type=RxIrq); - - /** Generate a break condition on the serial line - */ - void send_break(); - - static void _irq_handler(uint32_t id, SerialIrq irq_type); - protected: virtual int _getc(); - virtual int _putc(int c); - pFunctionPointer_t add_handler_helper(void (*function)(void), IrqType type, bool front=false); - - template<typename T> - pFunctionPointer_t add_handler_helper(T* tptr, void (T::*mptr)(void), IrqType type, bool front=false) { - if ((mptr != NULL) && (tptr != NULL)) { - pFunctionPointer_t pf = front ? _irq[type].add_front(tptr, mptr) : _irq[type].add(tptr, mptr); - serial_irq_set(&_serial, (SerialIrq)type, 1); - return pf; - } - else - return NULL; - } - - serial_t _serial; - CallChain _irq[2]; - int _baud; + virtual int _putc(int c); }; } // namespace mbed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SerialBase.h Wed Oct 23 16:23:06 2013 +0300 @@ -0,0 +1,120 @@ +/* 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_SERIALBASE_H +#define MBED_SERIALBASE_H + +#include "platform.h" + +#if DEVICE_SERIAL + +#include "Stream.h" +#include "FunctionPointer.h" +#include "serial_api.h" + +namespace mbed { + +/** A base class for serial port implementations + * Can't be instantiated directly (use Serial or RawSerial) + */ +class SerialBase { + +public: + /** Set the baud rate of the serial port + * + * @param baudrate The baudrate of the serial port (default = 9600). + */ + void baud(int baudrate); + + enum Parity { + None = 0, + Odd, + Even, + Forced1, + Forced0 + }; + + enum IrqType { + RxIrq = 0, + TxIrq + }; + + /** Set the transmission format used by the serial port + * + * @param bits The number of bits in a word (5-8; default = 8) + * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None) + * @param stop The number of stop bits (1 or 2; default = 1) + */ + void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1); + + /** Determine if there is a character available to read + * + * @returns + * 1 if there is a character available to read, + * 0 otherwise + */ + int readable(); + + /** Determine if there is space available to write a character + * + * @returns + * 1 if there is space to write a character, + * 0 otherwise + */ + int writeable(); + + /** Attach a function to call whenever a serial interrupt is generated + * + * @param fptr A pointer to a void function, or 0 to set as none + * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) + */ + void attach(void (*fptr)(void), IrqType type=RxIrq); + + /** Attach a member function to call whenever a serial interrupt is generated + * + * @param tptr pointer to the object to call the member function on + * @param mptr pointer to the member function to be called + * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) + */ + template<typename T> + void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) { + if((mptr != NULL) && (tptr != NULL)) { + _irq[type].attach(tptr, mptr); + serial_irq_set(&_serial, (SerialIrq)type, 1); + } + } + + /** Generate a break condition on the serial line + */ + void send_break(); + + static void _irq_handler(uint32_t id, SerialIrq irq_type); + +protected: + SerialBase(PinName tx, PinName rx); + + int _base_getc(); + int _base_putc(int c); + + serial_t _serial; + FunctionPointer _irq[2]; + int _baud; +}; + +} // namespace mbed + +#endif + +#endif
Binary file TARGET_KL25Z/TOOLCHAIN_ARM_STD/cmsis_nvic.o has changed
Binary file TARGET_KL25Z/TOOLCHAIN_ARM_STD/mbed.ar has changed
Binary file TARGET_KL25Z/TOOLCHAIN_ARM_STD/retarget.o has changed
Binary file TARGET_KL25Z/TOOLCHAIN_ARM_STD/system_MKL25Z4.o has changed
Binary file TARGET_LPC1114/TOOLCHAIN_ARM_MICRO/cmsis_nvic.o has changed
Binary file TARGET_LPC1114/TOOLCHAIN_ARM_MICRO/mbed.ar has changed
Binary file TARGET_LPC1114/TOOLCHAIN_ARM_MICRO/retarget.o has changed
Binary file TARGET_LPC1114/TOOLCHAIN_ARM_MICRO/startup_LPC11xx.o has changed
Binary file TARGET_LPC1114/TOOLCHAIN_ARM_MICRO/sys.o has changed
Binary file TARGET_LPC1114/TOOLCHAIN_ARM_MICRO/system_LPC11xx.o has changed
--- a/TARGET_LPC1114/objects.h Thu Sep 19 15:44:18 2013 +0300 +++ b/TARGET_LPC1114/objects.h Wed Oct 23 16:23:06 2013 +0300 @@ -59,6 +59,12 @@ LPC_SSP_TypeDef *spi; }; +#if DEVICE_CAN +struct can_s { + int index; +}; +#endif + #include "gpio_object.h" #ifdef __cplusplus
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TARGET_LPC1114/reserved_pins.h Wed Oct 23 16:23:06 2013 +0300 @@ -0,0 +1,8 @@ +// List of reserved pins for LPC1114 + +#ifndef RESERVED_PINS_H +#define RESERVED_PINS_H + +#define TARGET_RESERVED_PINS {P0_0, P0_11, P1_0, P1_1, P1_2} + +#endif
Binary file TARGET_LPC11U24/TOOLCHAIN_ARM_MICRO/cmsis_nvic.o has changed
Binary file TARGET_LPC11U24/TOOLCHAIN_ARM_MICRO/mbed.ar has changed
Binary file TARGET_LPC11U24/TOOLCHAIN_ARM_MICRO/retarget.o has changed
Binary file TARGET_LPC11U24/TOOLCHAIN_ARM_MICRO/system_LPC11Uxx.o has changed
Binary file TARGET_LPC11U24/TOOLCHAIN_ARM_STD/cmsis_nvic.o has changed
Binary file TARGET_LPC11U24/TOOLCHAIN_ARM_STD/mbed.ar has changed
Binary file TARGET_LPC11U24/TOOLCHAIN_ARM_STD/retarget.o has changed
Binary file TARGET_LPC11U24/TOOLCHAIN_ARM_STD/system_LPC11Uxx.o has changed
Binary file TARGET_LPC1347/TOOLCHAIN_ARM_STD/cmsis_nvic.o has changed
Binary file TARGET_LPC1347/TOOLCHAIN_ARM_STD/mbed.ar has changed
Binary file TARGET_LPC1347/TOOLCHAIN_ARM_STD/retarget.o has changed
Binary file TARGET_LPC1347/TOOLCHAIN_ARM_STD/system_LPC13Uxx.o has changed
Binary file TARGET_LPC1768/TOOLCHAIN_ARM_STD/cmsis_nvic.o has changed
Binary file TARGET_LPC1768/TOOLCHAIN_ARM_STD/mbed.ar has changed
Binary file TARGET_LPC1768/TOOLCHAIN_ARM_STD/retarget.o has changed
Binary file TARGET_LPC1768/TOOLCHAIN_ARM_STD/system_LPC17xx.o has changed
Binary file TARGET_LPC1768/TOOLCHAIN_GCC_ARM/libmbed.a has changed
Binary file TARGET_LPC1768/TOOLCHAIN_GCC_CR/libmbed.a has changed
Binary file TARGET_LPC1768/TOOLCHAIN_GCC_CS/libmbed.a has changed
Binary file TARGET_LPC1768/TOOLCHAIN_IAR/mbed.a has changed
Binary file TARGET_LPC2368/TOOLCHAIN_ARM_STD/mbed.ar has changed
--- a/TARGET_LPC4088/LPC407x_8x_177x_8x.h Thu Sep 19 15:44:18 2013 +0300 +++ b/TARGET_LPC4088/LPC407x_8x_177x_8x.h Wed Oct 23 16:23:06 2013 +0300 @@ -34,7 +34,9 @@ #ifndef __LPC407x_8x_177x_8x_H__ #define __LPC407x_8x_177x_8x_H__ -#define CORE_M4 +#if defined(__CORTEX_M4) && !defined(CORE_M4) + #define CORE_M4 +#endif // ################## // Code Red - excluded extern "C" as unrequired
Binary file TARGET_LPC4088/TOOLCHAIN_ARM_STD/cmsis_nvic.o has changed
Binary file TARGET_LPC4088/TOOLCHAIN_ARM_STD/mbed.ar has changed
Binary file TARGET_LPC4088/TOOLCHAIN_ARM_STD/retarget.o has changed
Binary file TARGET_LPC4088/TOOLCHAIN_ARM_STD/system_LPC407x_8x_177x_8x.o has changed
Binary file TARGET_LPC812/TOOLCHAIN_ARM_MICRO/cmsis_nvic.o has changed
Binary file TARGET_LPC812/TOOLCHAIN_ARM_MICRO/mbed.ar has changed
Binary file TARGET_LPC812/TOOLCHAIN_ARM_MICRO/retarget.o has changed
Binary file TARGET_LPC812/TOOLCHAIN_ARM_MICRO/system_LPC8xx.o has changed
--- a/Ticker.h Thu Sep 19 15:44:18 2013 +0300 +++ b/Ticker.h Wed Oct 23 16:23:06 2013 +0300 @@ -18,7 +18,6 @@ #include "TimerEvent.h" #include "FunctionPointer.h" -#include "CallChain.h" namespace mbed { @@ -63,34 +62,9 @@ * * @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); + void attach(void (*fptr)(void), float t) { + attach_us(fptr, t * 1000000.0f); } /** Attach a member function to be called by the Ticker, specifiying the interval in seconds @@ -98,54 +72,20 @@ * @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); + void attach(T* tptr, void (T::*mptr)(void), float t) { + attach_us(tptr, mptr, t * 1000000.0f); } /** 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) { - _chain.clear(); - pFunctionPointer_t pf = _chain.add(fptr); + void attach_us(void (*fptr)(void), unsigned int t) { + _function.attach(fptr); setup(t); - return pf; } /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds @@ -153,50 +93,23 @@ * @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) { - _chain.clear(); - pFunctionPointer_t pf = _chain.add(tptr, mptr); + void attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) { + _function.attach(tptr, mptr); 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; + FunctionPointer _function; }; } // namespace mbed
--- a/gpio_irq_api.h Thu Sep 19 15:44:18 2013 +0300 +++ b/gpio_irq_api.h Wed Oct 23 16:23:06 2013 +0300 @@ -37,6 +37,8 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id); void gpio_irq_free(gpio_irq_t *obj); void gpio_irq_set (gpio_irq_t *obj, gpio_irq_event event, uint32_t enable); +void gpio_irq_enable(gpio_irq_t *obj); +void gpio_irq_disable(gpio_irq_t *obj); #ifdef __cplusplus }