diff options
author | Daniel Garcia <danielgarcia@gmail.com> | 2019-08-26 02:58:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-26 02:58:19 +0300 |
commit | 8ac3dd7f00e933a376530ecf86d360d167e1b82a (patch) | |
tree | 3a7189b462579d54fd3afe5f0a14bef73803b84b /examples | |
parent | 3c5484c336230f8346f2fd6ed8fb5a18ce835edc (diff) |
Defpin cleanup (#866)
* Bring fastpin_avr in line with standard defpin macros (to simplify porting document notes
* checkpoint - bring all the arm and esp platforms in line w/defpin macro naming/ordering
* checkpoint - update PORTING.md to include information around just adding pin definitions if needed
* Kick all the pin definitions to allow for some runtime querying of ports and tweak pintest to have it provide pin definitions for platforms that have port definitions but might be missing pin specifics (e.g. not yet-supported avr platforms
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Pintest/Pintest.ino | 79 |
1 files changed, 74 insertions, 5 deletions
diff --git a/examples/Pintest/Pintest.ino b/examples/Pintest/Pintest.ino index f0a0dadc..a8141520 100644 --- a/examples/Pintest/Pintest.ino +++ b/examples/Pintest/Pintest.ino @@ -94,12 +94,12 @@ template<uint8_t PIN> void CheckPin() { CheckPin<PIN - 1>(); - RwReg *systemThinksPortIs = portOutputRegister(digitalPinToPort(PIN)); + void *systemThinksPortIs = (void*)portOutputRegister(digitalPinToPort(PIN)); RwReg systemThinksMaskIs = digitalPinToBitMask(PIN); Serial.print("Pin "); Serial.print(PIN); Serial.print(": Port "); - if(systemThinksPortIs == FastPin<PIN>::port()) { + if(systemThinksPortIs == (void*)FastPin<PIN>::port()) { Serial.print("valid & mask "); } else { Serial.print("invalid, is "); Serial.print(getPort((void*)FastPin<PIN>::port())); Serial.print(" should be "); @@ -114,8 +114,68 @@ template<uint8_t PIN> void CheckPin() } } -template<> void CheckPin<-1> () {} +template<> void CheckPin<255> () {} + + +template<uint8_t _PORT> const char *_GetPinPort(void *ptr) { + if (__FL_PORT_INFO<_PORT>::hasPort() && (ptr == (void*)__FL_PORT_INFO<_PORT>::portAddr())) { + return __FL_PORT_INFO<_PORT>::portName(); + } else { + return _GetPinPort<_PORT - 1>(ptr); + } +} +template<> const char *_GetPinPort<-1>(void *ptr) { + return NULL; +} + +const char *GetPinPort(void *ptr) { + return _GetPinPort<'Z'>(ptr); +} + +static uint8_t pcount = 0; + + +template<uint8_t PIN> void PrintPins() { + PrintPins<PIN - 1>(); + + RwReg *systemThinksPortIs = portOutputRegister(digitalPinToPort(PIN)); + RwReg systemThinksMaskIs = digitalPinToBitMask(PIN); + + int maskBit = 0; + while(systemThinksMaskIs > 1) { systemThinksMaskIs >>= 1; maskBit++; } + const char *pinport = GetPinPort((void*)systemThinksPortIs); + if (pinport) { + Serial.print("__FL_DEFPIN("); Serial.print(PIN); + Serial.print(","); Serial.print(maskBit); + Serial.print(","); Serial.print(pinport); + Serial.print("); "); + pcount++; + if(pcount == 4) { pcount = 0; Serial.println(""); } + } else { + // Serial.print("Not found for pin "); Serial.println(PIN); + } +} + +template<> void PrintPins<0>() { + RwReg *systemThinksPortIs = portOutputRegister(digitalPinToPort(0)); + RwReg systemThinksMaskIs = digitalPinToBitMask(0); + + int maskBit = 0; + while(systemThinksMaskIs > 1) { systemThinksMaskIs >>= 1; maskBit++; } + + const char *pinport = GetPinPort((void*)systemThinksPortIs); + if (pinport) { + Serial.print("__FL_DEFPIN("); Serial.print(0); + Serial.print(","); Serial.print(maskBit); + Serial.print(","); Serial.print(pinport); + Serial.print("); "); + pcount++; + if(pcount == 4) { pcount = 0; Serial.println(""); } + } +} + +int counter = 0; void setup() { delay(5000); Serial.begin(38400); @@ -123,8 +183,17 @@ void setup() { } void loop() { + Serial.println(counter); + +#ifdef MAX_PIN CheckPin<MAX_PIN>(); - delay(100000); +#endif - Serial.print("GPIO_1_DR is: "); Serial.print(getPort((void*)&(GPIO1_DR))); + Serial.println("-----"); +#ifdef NUM_DIGITAL_PINS + PrintPins<NUM_DIGITAL_PINS>(); +#endif + Serial.println("------"); + + delay(100000); } |