Complete the code to set a GPIO pin as output.
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = [1];
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);To set a GPIO pin as output, you use GPIO_MODE_OUTPUT_PP which means push-pull output mode.
Complete the code to read the state of a GPIO pin.
int pin_state = HAL_GPIO_ReadPin(GPIOB, [1]);We read the state of pin 7 on port B using GPIO_PIN_7.
Fix the error in the code to toggle a GPIO pin.
HAL_GPIO_TogglePin(GPIOC, [1]);Pin 13 on port C is commonly used for toggling an LED on many boards.
Fill both blanks to create a dictionary comprehension that maps pin numbers to their states if the pin state is high.
pin_states = {pin: HAL_GPIO_ReadPin(GPIOA, pin) for pin in pins if HAL_GPIO_ReadPin(GPIOA, pin) [1] [2]The condition checks if the pin state is equal to GPIO_PIN_SET, which means the pin is high.
Fill all three blanks to create a dictionary comprehension that maps pin names in uppercase to their states if the state is low.
pin_status = { [1]: HAL_GPIO_ReadPin(GPIOB, [2]) for [3] in pins if HAL_GPIO_ReadPin(GPIOB, pin) == GPIO_PIN_RESET }The dictionary keys are the uppercase pin names, values are the pin states, and the loop variable is pin.