application: pin action shows atual floating value
This commit is contained in:
parent
4aec3da96c
commit
2d5a2b7f4f
|
@ -319,7 +319,7 @@ static void command_pin(void* argument)
|
|||
|
||||
// print header
|
||||
if (!pin_level) {
|
||||
printf("pin set and state (H: out high, L: out low, h in high, l in low, x in floating):\n");
|
||||
printf("pin state (H: out high, L: out low, h in high, l in low, x in floating) and actual level (0: low, 1:high):\n");
|
||||
} else {
|
||||
printf("setting pin\n");
|
||||
}
|
||||
|
@ -356,36 +356,10 @@ static void command_pin(void* argument)
|
|||
}
|
||||
}
|
||||
// show actual value
|
||||
if (0 == mode) { // pin is configured as input
|
||||
bool high = (0 != gpio_get(pin_port, pin_pin)); // test if pin is high
|
||||
bool low = !high; // will be used to test if pin is low
|
||||
if (1 == conf) { // pin is in floating configuration
|
||||
gpio_set_mode(pin_port, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, pin_pin); // we will test if the input is floating by checking against a pull up and down
|
||||
gpio_set(pin_port, pin_pin); // pull up
|
||||
sleep_us(10); // wait for GPIO/line to settle
|
||||
high = (0 != gpio_get(pin_port, pin_pin)); // test if pin is high
|
||||
gpio_clear(pin_port, pin_pin); // pull down
|
||||
sleep_us(10); // wait for GPIO/line to settle
|
||||
low = (0 == gpio_get(pin_port, pin_pin)); // test if pin is low
|
||||
gpio_set_mode(pin_port, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, pin_pin); // put back to floating
|
||||
}
|
||||
// check and display result
|
||||
if (high && !low) { // pull down did not work
|
||||
putc('h'); // something is driving the pin high
|
||||
} else if (!high && low) { // pull up did not work
|
||||
putc('l'); // something is driving the pin low
|
||||
} else if (high && low) { // pull up and down worked
|
||||
putc('x'); // nothing is driving the pin
|
||||
} else { // pull up and down did not work
|
||||
putc('?'); // something is driving the pin randomly
|
||||
}
|
||||
} else { // pin is configured as output
|
||||
// only show the actual measured output, not the one set
|
||||
if (gpio_get(pin_port, pin_pin)) {
|
||||
putc('H'); // pin is high
|
||||
} else {
|
||||
putc('L'); // pin is low
|
||||
}
|
||||
if (gpio_get(pin_port, pin_pin)) {
|
||||
putc('1');
|
||||
} else {
|
||||
putc('0');
|
||||
}
|
||||
putc('\n');
|
||||
}
|
||||
|
@ -409,7 +383,6 @@ static void command_pin(void* argument)
|
|||
gpio_set_mode(pin_port, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, pin_pin);
|
||||
break;
|
||||
case 'x':
|
||||
case 'X':
|
||||
default:
|
||||
gpio_set_mode(pin_port, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, pin_pin);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue