change some io settings for TWR-K22F-120M

Dependents:   twr_helloworld

Committer:
Jasper_lee
Date:
Tue Dec 23 03:35:08 2014 +0000
Revision:
0:b16d94660a33
change some io setting used in TWR-K22F120M

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jasper_lee 0:b16d94660a33 1 /* mbed Microcontroller Library
Jasper_lee 0:b16d94660a33 2 * Copyright (c) 2006-2013 ARM Limited
Jasper_lee 0:b16d94660a33 3 *
Jasper_lee 0:b16d94660a33 4 * Licensed under the Apache License, Version 2.0 (the "License");
Jasper_lee 0:b16d94660a33 5 * you may not use this file except in compliance with the License.
Jasper_lee 0:b16d94660a33 6 * You may obtain a copy of the License at
Jasper_lee 0:b16d94660a33 7 *
Jasper_lee 0:b16d94660a33 8 * http://www.apache.org/licenses/LICENSE-2.0
Jasper_lee 0:b16d94660a33 9 *
Jasper_lee 0:b16d94660a33 10 * Unless required by applicable law or agreed to in writing, software
Jasper_lee 0:b16d94660a33 11 * distributed under the License is distributed on an "AS IS" BASIS,
Jasper_lee 0:b16d94660a33 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Jasper_lee 0:b16d94660a33 13 * See the License for the specific language governing permissions and
Jasper_lee 0:b16d94660a33 14 * limitations under the License.
Jasper_lee 0:b16d94660a33 15 */
Jasper_lee 0:b16d94660a33 16 #ifndef MBED_FUNCTIONPOINTER_H
Jasper_lee 0:b16d94660a33 17 #define MBED_FUNCTIONPOINTER_H
Jasper_lee 0:b16d94660a33 18
Jasper_lee 0:b16d94660a33 19 #include <string.h>
Jasper_lee 0:b16d94660a33 20
Jasper_lee 0:b16d94660a33 21 namespace mbed {
Jasper_lee 0:b16d94660a33 22
Jasper_lee 0:b16d94660a33 23 typedef void (*pvoidf_t)(void);
Jasper_lee 0:b16d94660a33 24
Jasper_lee 0:b16d94660a33 25 /** A class for storing and calling a pointer to a static or member void function
Jasper_lee 0:b16d94660a33 26 */
Jasper_lee 0:b16d94660a33 27 class FunctionPointer {
Jasper_lee 0:b16d94660a33 28 public:
Jasper_lee 0:b16d94660a33 29
Jasper_lee 0:b16d94660a33 30 /** Create a FunctionPointer, attaching a static function
Jasper_lee 0:b16d94660a33 31 *
Jasper_lee 0:b16d94660a33 32 * @param function The void static function to attach (default is none)
Jasper_lee 0:b16d94660a33 33 */
Jasper_lee 0:b16d94660a33 34 FunctionPointer(void (*function)(void) = 0);
Jasper_lee 0:b16d94660a33 35
Jasper_lee 0:b16d94660a33 36 /** Create a FunctionPointer, attaching a member function
Jasper_lee 0:b16d94660a33 37 *
Jasper_lee 0:b16d94660a33 38 * @param object The object pointer to invoke the member function on (i.e. the this pointer)
Jasper_lee 0:b16d94660a33 39 * @param function The address of the void member function to attach
Jasper_lee 0:b16d94660a33 40 */
Jasper_lee 0:b16d94660a33 41 template<typename T>
Jasper_lee 0:b16d94660a33 42 FunctionPointer(T *object, void (T::*member)(void)) {
Jasper_lee 0:b16d94660a33 43 attach(object, member);
Jasper_lee 0:b16d94660a33 44 }
Jasper_lee 0:b16d94660a33 45
Jasper_lee 0:b16d94660a33 46 /** Attach a static function
Jasper_lee 0:b16d94660a33 47 *
Jasper_lee 0:b16d94660a33 48 * @param function The void static function to attach (default is none)
Jasper_lee 0:b16d94660a33 49 */
Jasper_lee 0:b16d94660a33 50 void attach(void (*function)(void) = 0);
Jasper_lee 0:b16d94660a33 51
Jasper_lee 0:b16d94660a33 52 /** Attach a member function
Jasper_lee 0:b16d94660a33 53 *
Jasper_lee 0:b16d94660a33 54 * @param object The object pointer to invoke the member function on (i.e. the this pointer)
Jasper_lee 0:b16d94660a33 55 * @param function The address of the void member function to attach
Jasper_lee 0:b16d94660a33 56 */
Jasper_lee 0:b16d94660a33 57 template<typename T>
Jasper_lee 0:b16d94660a33 58 void attach(T *object, void (T::*member)(void)) {
Jasper_lee 0:b16d94660a33 59 _object = static_cast<void*>(object);
Jasper_lee 0:b16d94660a33 60 memcpy(_member, (char*)&member, sizeof(member));
Jasper_lee 0:b16d94660a33 61 _membercaller = &FunctionPointer::membercaller<T>;
Jasper_lee 0:b16d94660a33 62 _function = 0;
Jasper_lee 0:b16d94660a33 63 }
Jasper_lee 0:b16d94660a33 64
Jasper_lee 0:b16d94660a33 65 /** Call the attached static or member function
Jasper_lee 0:b16d94660a33 66 */
Jasper_lee 0:b16d94660a33 67 void call();
Jasper_lee 0:b16d94660a33 68
Jasper_lee 0:b16d94660a33 69 pvoidf_t get_function() const {
Jasper_lee 0:b16d94660a33 70 return (pvoidf_t)_function;
Jasper_lee 0:b16d94660a33 71 }
Jasper_lee 0:b16d94660a33 72
Jasper_lee 0:b16d94660a33 73 #ifdef MBED_OPERATORS
Jasper_lee 0:b16d94660a33 74 void operator ()(void);
Jasper_lee 0:b16d94660a33 75 #endif
Jasper_lee 0:b16d94660a33 76
Jasper_lee 0:b16d94660a33 77 private:
Jasper_lee 0:b16d94660a33 78 template<typename T>
Jasper_lee 0:b16d94660a33 79 static void membercaller(void *object, char *member) {
Jasper_lee 0:b16d94660a33 80 T* o = static_cast<T*>(object);
Jasper_lee 0:b16d94660a33 81 void (T::*m)(void);
Jasper_lee 0:b16d94660a33 82 memcpy((char*)&m, member, sizeof(m));
Jasper_lee 0:b16d94660a33 83 (o->*m)();
Jasper_lee 0:b16d94660a33 84 }
Jasper_lee 0:b16d94660a33 85
Jasper_lee 0:b16d94660a33 86 void (*_function)(void); // static function pointer - 0 if none attached
Jasper_lee 0:b16d94660a33 87 void *_object; // object this pointer - 0 if none attached
Jasper_lee 0:b16d94660a33 88 char _member[16]; // raw member function pointer storage - converted back by registered _membercaller
Jasper_lee 0:b16d94660a33 89 void (*_membercaller)(void*, char*); // registered membercaller function to convert back and call _member on _object
Jasper_lee 0:b16d94660a33 90 };
Jasper_lee 0:b16d94660a33 91
Jasper_lee 0:b16d94660a33 92 } // namespace mbed
Jasper_lee 0:b16d94660a33 93
Jasper_lee 0:b16d94660a33 94 #endif