| 210 | |
| 211 | |
| 212 | void GPIO::pinMode(uint8_t pin, uint8_t output) |
| 213 | { |
| 214 | struct gpio_entry *g = gpio_by_pin_num(pin); |
| 215 | if (g) { |
| 216 | if (!output && g->is_input && |
| 217 | (g->mode == PAL_MODE_INPUT_PULLUP || |
| 218 | g->mode == PAL_MODE_INPUT_PULLDOWN)) { |
| 219 | // already set |
| 220 | return; |
| 221 | } |
| 222 | g->mode = output?PAL_MODE_OUTPUT_PUSHPULL:PAL_MODE_INPUT; |
| 223 | #if defined(STM32F7) || defined(STM32H7) || defined(STM32F4) || defined(STM32G4) || defined(STM32L4) || defined(STM32L4PLUS) |
| 224 | if (g->mode == PAL_MODE_OUTPUT_PUSHPULL) { |
| 225 | // retain OPENDRAIN if already set |
| 226 | iomode_t old_mode = palReadLineMode(g->pal_line); |
| 227 | if ((old_mode & PAL_MODE_OUTPUT_OPENDRAIN) == PAL_MODE_OUTPUT_OPENDRAIN) { |
| 228 | g->mode = PAL_MODE_OUTPUT_OPENDRAIN; |
| 229 | } |
| 230 | } |
| 231 | #endif |
| 232 | palSetLineMode(g->pal_line, g->mode); |
| 233 | g->is_input = !output; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | |
| 238 | uint8_t GPIO::read(uint8_t pin) |
no test coverage detected