Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
5 years, 9 months ago.
How to check a pin supports required capture functionality?
Hi,
I'm writing a class that uses the capture functionality of the timer block. Different devices have certain fixed location pins that support capture functionality. If I want to allow the user of the class to select which pin they want to use, how can I check that they've selected a pin that actually has the capture functionality?
Thanks.
1 Answer
5 years, 8 months ago.
Hello, Shareef
There are probably many ways how to do it. You can for example let the compiler check/enforce it by declaring an enum type and class as follows:
MyClass.h
#define "mbed.h" typedef enum { #if defined(TARGET_LPC1768) capturePin1 = p9, capturePin2 = p10, #elif defined(TARGET_STM) capturePin1 = PA_3, capturePin2 = PA_4, capturePin3 = PB_10, capturePin4 = PC_4, #endif } CapturePin; class MyClass : public InterruptIn { public: MyClass(CapturePin pin) : InterruptIn((PinName)pin) { } };
The user will be then forced to use only the designed pins:
main.cpp
#include "mbed.h" #include "MyClass.h" //MyClass myClass(p9); // reports compile time error MyClass myClass(capturePin3); // compiles fine for STM boards but reports compile time error for LCP1768 int main() { //..