Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Smoothie by
Pin.cpp
00001 #include "Pin.h" 00002 00003 #include "utils.h" 00004 #include "Targets/Target.h" 00005 00006 Pin::Pin(){ 00007 this->inverting= false; 00008 } 00009 00010 // Make a new pin object from a string 00011 Pin* Pin::from_string(std::string value){ 00012 // Find the end of the pin name. 00013 std::string::size_type e = value.find_first_of("!o^V-@\n\r\t "); 00014 name = pin_name_from_string(value.substr(0, e)); 00015 if (name == NC) 00016 return this; 00017 00018 gpio_init(&pin, name, PIN_INPUT); 00019 00020 // The current position in the string 00021 const char* cn = value.c_str() + e; 00022 00023 for (;*cn;cn++) { 00024 switch(*cn) { 00025 case '!': 00026 this->inverting = true; 00027 break; 00028 case 'o': 00029 as_open_drain(); 00030 break; 00031 case '^': 00032 pull_up(); 00033 break; 00034 case 'v': 00035 pull_down(); 00036 break; 00037 case '-': 00038 pull_none(); 00039 break; 00040 case '@': 00041 as_repeater(); 00042 break; 00043 default: 00044 // skip any whitespace following the pin index 00045 if (!is_whitespace(*cn)) 00046 return this; 00047 } 00048 } 00049 00050 // from_string failed. TODO: some sort of error 00051 inverting = false; 00052 return this; 00053 } 00054 00055 // Configure this pin as OD 00056 Pin* Pin::as_open_drain(){ 00057 if (!connected()) return this; 00058 gpio_mode(&pin, OpenDrain); 00059 pull_none(); // no pull up by default 00060 return this; 00061 } 00062 00063 00064 // Configure this pin as a repeater 00065 Pin* Pin::as_repeater(){ 00066 if (!connected()) return this; 00067 // ? 00068 return this; 00069 } 00070 00071 // Configure this pin as no pullup or pulldown 00072 Pin* Pin::pull_none(){ 00073 if (!connected()) return this; 00074 gpio_mode(&pin, PullNone); 00075 return this; 00076 } 00077 00078 // Configure this pin as a pullup 00079 Pin* Pin::pull_up(){ 00080 if (!connected()) return this; 00081 gpio_mode(&pin, PullUp); 00082 return this; 00083 } 00084 00085 // Configure this pin as a pulldown 00086 Pin* Pin::pull_down(){ 00087 if (!connected()) return this; 00088 gpio_mode(&pin, PullDown); 00089 return this; 00090 }
Generated on Tue Jul 12 2022 20:09:02 by
1.7.2
