|
STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
|
Pin configuration and digital I/O. More...
Data Structures | |
| struct | GpioResetValues_t |
| Power-on values of the GPIO registers that are not zero on every port. More... | |
Macros | |
| #define | GPIO_AF_MAX (15U) |
| Highest alternate-function number (AF0-AF15). | |
Typedefs | |
| typedef enum GpioPin_e | GpioPin_e |
| Pin number within a port. | |
| typedef enum GpioPinState_e | GpioPinState_e |
| Logic level of a pin. | |
| typedef struct GpioResetValues_t | GpioResetValues_t |
| Power-on values of the GPIO registers that are not zero on every port. | |
Enumerations | |
| enum | GpioPin_e { GPIO_PIN_0 = 0 , GPIO_PIN_1 = 1 , GPIO_PIN_2 = 2 , GPIO_PIN_3 = 3 , GPIO_PIN_4 = 4 , GPIO_PIN_5 = 5 , GPIO_PIN_6 = 6 , GPIO_PIN_7 = 7 , GPIO_PIN_8 = 8 , GPIO_PIN_9 = 9 , GPIO_PIN_10 = 10 , GPIO_PIN_11 = 11 , GPIO_PIN_12 = 12 , GPIO_PIN_13 = 13 , GPIO_PIN_14 = 14 , GPIO_PIN_15 = 15 } |
| Pin number within a port. More... | |
| enum | GpioPinState_e { GPIO_PIN_RESET = 0 , GPIO_PIN_SET = 1 } |
| Logic level of a pin. More... | |
Functions | |
| GpioResetValues_t | gpioPortResetValues (const GpioRegisters_t *port) |
| Look up a port's power-on MODER, OSPEEDR and PUPDR values. | |
| DRIVER_MUST_CHECK DriverStatus_e | gpioInit (GpioRegisters_t *port, GpioPin_e pin, uint32_t mode, uint32_t otype, uint32_t ospeed, uint32_t pupd) |
| Configure a pin's mode, output type, speed and pull. | |
| void | gpioDeinit (GpioRegisters_t *port, GpioPin_e pin) |
| Return a pin to its power-on configuration. | |
| void | gpioDeinitToReset (GpioRegisters_t *port, GpioPin_e pin, GpioResetValues_t reset) |
| gpioDeinit() with the reset values supplied by the caller. | |
| DRIVER_MUST_CHECK DriverStatus_e | gpioSetAlternateFunction (GpioRegisters_t *port, GpioPin_e pin, uint32_t af) |
| Select a pin's alternate function in AFRL/AFRH. | |
| void | gpioWritePin (GpioRegisters_t *port, GpioPin_e pin, GpioPinState_e level) |
| Drive a pin high or low with one atomic BSRR write. | |
| GpioPinState_e | gpioReadPin (const GpioRegisters_t *port, GpioPin_e pin) |
| Read a pin's input level from IDR. | |
| void | gpioTogglePin (GpioRegisters_t *port, GpioPin_e pin) |
| Invert a pin's output level. | |
| static DriverStatus_e | gpioValidatePin (GpioPin_e pin) |
| Reject a pin outside 0-15, which would shift by 32 or more. | |
Pin configuration and digital I/O.
| #define GPIO_AF_MAX (15U) |
Highest alternate-function number (AF0-AF15).
Definition at line 29 of file gpio.h.
Referenced by gpioSetAlternateFunction().
Pin number within a port.
C does not stop a caller casting any integer in. Functions that return a DriverStatus_e reject a pin above 15; the others state it as an @pre, because a larger value shifts by 32 or more, which is undefined behaviour.
| enum GpioPin_e |
Pin number within a port.
C does not stop a caller casting any integer in. Functions that return a DriverStatus_e reject a pin above 15; the others state it as an @pre, because a larger value shifts by 32 or more, which is undefined behaviour.
| enum GpioPinState_e |
| GpioResetValues_t gpioPortResetValues | ( | const GpioRegisters_t * | port | ) |
Look up a port's power-on MODER, OSPEEDR and PUPDR values.
Only GPIOA and GPIOB are non-zero: they hold the SWD/JTAG pins. Compares port by address and never dereferences it. Public so the host tests can check the lookup.
| port | GPIO port (e.g. GPIOA); any other address gives all zeros. |
Definition at line 60 of file gpio.c.
References GPIOA, GPIOA_MODER_RESET, GPIOA_PUPDR_RESET, GPIOB, GPIOB_MODER_RESET, GPIOB_OSPEEDR_RESET, GPIOB_PUPDR_RESET, gpioPortResetValues(), GpioResetValues_t::MODER, GpioResetValues_t::OSPEEDR, and GpioResetValues_t::PUPDR.
Referenced by gpioDeinit(), and gpioPortResetValues().
| DriverStatus_e gpioInit | ( | GpioRegisters_t * | port, |
| GpioPin_e | pin, | ||
| uint32_t | mode, | ||
| uint32_t | otype, | ||
| uint32_t | ospeed, | ||
| uint32_t | pupd ) |
Configure a pin's mode, output type, speed and pull.
| port | GPIO port (e.g. GPIOA). |
| pin | Pin within the port. |
| mode | A GPIO_MODE_* value. |
| otype | A GPIO_OTYPE_* value. |
| ospeed | A GPIO_OSPEED_* value. |
| pupd | A GPIO_PUPD_* value. |
| DRIVER_STATUS_OK | Configured; MODER is written last. |
| DRIVER_STATUS_ERR_INVALID_PARAM | pin is above 15, or a value is not one of its macros (for example the reserved PUPDR 0b11). |
Definition at line 30 of file gpio.c.
References DRIVER_STATUS_ERR_INVALID_PARAM, DRIVER_STATUS_OK, GPIO_MODE_ANALOG, GPIO_OSPEED_HIGH, GPIO_OTYPE_OD, GPIO_PUPD_DOWN, gpioInit(), gpioValidatePin(), GpioRegisters_t::MODER, GpioRegisters_t::OSPEEDR, GpioRegisters_t::OTYPER, and GpioRegisters_t::PUPDR.
Referenced by gpioInit().
| void gpioDeinit | ( | GpioRegisters_t * | port, |
| GpioPin_e | pin ) |
Return a pin to its power-on configuration.
Restores MODER, OTYPER, OSPEEDR, PUPDR and the AFR field. The SWD/JTAG pins return to their debug configuration, so deinitialising one does not disconnect the debugger.
| port | GPIO port (e.g. GPIOA). |
| pin | Pin within the port. |
pin is 0-15; there is no status to report a bad one. Definition at line 83 of file gpio.c.
References gpioDeinit(), gpioDeinitToReset(), and gpioPortResetValues().
Referenced by gpioDeinit().
| void gpioDeinitToReset | ( | GpioRegisters_t * | port, |
| GpioPin_e | pin, | ||
| GpioResetValues_t | reset ) |
gpioDeinit() with the reset values supplied by the caller.
Exists for the host tests: gpioDeinit() looks the values up by comparing port with GPIOA and GPIOB, which a test's in-memory struct never matches. Firmware calls gpioDeinit().
| port | GPIO port. |
| pin | Pin within the port. |
| reset | The port's reset values, as from gpioPortResetValues(). |
pin is 0-15. Definition at line 88 of file gpio.c.
References GpioRegisters_t::AFRH, GpioRegisters_t::AFRL, gpioDeinitToReset(), GpioRegisters_t::MODER, GpioResetValues_t::MODER, GpioRegisters_t::OSPEEDR, GpioResetValues_t::OSPEEDR, GpioRegisters_t::OTYPER, GpioRegisters_t::PUPDR, and GpioResetValues_t::PUPDR.
Referenced by gpioDeinit(), and gpioDeinitToReset().
| DriverStatus_e gpioSetAlternateFunction | ( | GpioRegisters_t * | port, |
| GpioPin_e | pin, | ||
| uint32_t | af ) |
Select a pin's alternate function in AFRL/AFRH.
Has no effect on the pin until its mode is GPIO_MODE_AF.
| port | GPIO port (e.g. GPIOA). |
| pin | Pin within the port. |
| af | Alternate function, 0 to GPIO_AF_MAX. |
| DRIVER_STATUS_OK | Selected. |
| DRIVER_STATUS_ERR_INVALID_PARAM | pin is above 15 or af above GPIO_AF_MAX. |
Definition at line 110 of file gpio.c.
References GpioRegisters_t::AFRH, GpioRegisters_t::AFRL, DRIVER_STATUS_ERR_INVALID_PARAM, DRIVER_STATUS_OK, GPIO_AF_MAX, gpioSetAlternateFunction(), and gpioValidatePin().
Referenced by gpioSetAlternateFunction().
| void gpioWritePin | ( | GpioRegisters_t * | port, |
| GpioPin_e | pin, | ||
| GpioPinState_e | level ) |
Drive a pin high or low with one atomic BSRR write.
| port | GPIO port (e.g. GPIOA). |
| pin | Pin within the port. |
| level | GPIO_PIN_SET or GPIO_PIN_RESET. |
pin is 0-15. Definition at line 140 of file gpio.c.
References GpioRegisters_t::BSRR, GPIO_PIN_SET, and gpioWritePin().
Referenced by gpioWritePin().
| GpioPinState_e gpioReadPin | ( | const GpioRegisters_t * | port, |
| GpioPin_e | pin ) |
Read a pin's input level from IDR.
| port | GPIO port (e.g. GPIOA). |
| pin | Pin within the port. |
pin is 0-15. Definition at line 154 of file gpio.c.
References GPIO_PIN_RESET, GPIO_PIN_SET, gpioReadPin(), and GpioRegisters_t::IDR.
Referenced by gpioReadPin().
| void gpioTogglePin | ( | GpioRegisters_t * | port, |
| GpioPin_e | pin ) |
Invert a pin's output level.
Reads ODR, then writes BSRR.
| port | GPIO port (e.g. GPIOA). |
| pin | Pin within the port. |
pin is 0-15. Definition at line 167 of file gpio.c.
References GpioRegisters_t::BSRR, gpioTogglePin(), and GpioRegisters_t::ODR.
Referenced by gpioTogglePin().
|
static |
Reject a pin outside 0-15, which would shift by 32 or more.
| pin | Candidate pin. |
| DRIVER_STATUS_OK | pin is 0-15. |
| DRIVER_STATUS_ERR_INVALID_PARAM | Otherwise. |
Definition at line 18 of file gpio.c.
References DRIVER_STATUS_ERR_INVALID_PARAM, DRIVER_STATUS_OK, GPIO_PIN_15, and gpioValidatePin().
Referenced by gpioInit(), gpioSetAlternateFunction(), and gpioValidatePin().