|
| 1 | +/**************************************************************************** |
| 2 | + * boards/arm/stm32h7/nucleo-h743zi2/src/stm32_buttons.c |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * |
| 6 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 7 | + * contributor license agreements. See the NOTICE file distributed with |
| 8 | + * this work for additional information regarding copyright ownership. The |
| 9 | + * ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 10 | + * "License"); you may not use this file except in compliance with the |
| 11 | + * License. You may obtain a copy of the License at |
| 12 | + * |
| 13 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | + * |
| 15 | + * Unless required by applicable law or agreed to in writing, software |
| 16 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 18 | + * License for the specific language governing permissions and limitations |
| 19 | + * under the License. |
| 20 | + * |
| 21 | + ****************************************************************************/ |
| 22 | + |
| 23 | +/**************************************************************************** |
| 24 | + * Included Files |
| 25 | + ****************************************************************************/ |
| 26 | + |
| 27 | +#include <nuttx/config.h> |
| 28 | + |
| 29 | +#include <stddef.h> |
| 30 | +#include <errno.h> |
| 31 | + |
| 32 | +#include <nuttx/irq.h> |
| 33 | +#include <nuttx/board.h> |
| 34 | + |
| 35 | +#include "stm32_gpio.h" |
| 36 | +#include "nucleo-h743zi2.h" |
| 37 | +#include <arch/board/board.h> |
| 38 | + |
| 39 | +#ifdef CONFIG_ARCH_BUTTONS |
| 40 | + |
| 41 | +/**************************************************************************** |
| 42 | + * Public Functions |
| 43 | + ****************************************************************************/ |
| 44 | + |
| 45 | +/**************************************************************************** |
| 46 | + * Name: board_button_initialize |
| 47 | + * |
| 48 | + * Description: |
| 49 | + * board_button_initialize() must be called to initialize button resources. |
| 50 | + * After that, board_buttons() may be called to collect the current state |
| 51 | + * of all buttons or board_button_irq() may be called to register button |
| 52 | + * interrupt handlers. |
| 53 | + * |
| 54 | + ****************************************************************************/ |
| 55 | + |
| 56 | +uint32_t board_button_initialize(void) |
| 57 | +{ |
| 58 | + stm32_configgpio(GPIO_BTN_USER); |
| 59 | + return NUM_BUTTONS; |
| 60 | +} |
| 61 | + |
| 62 | +/**************************************************************************** |
| 63 | + * Name: board_buttons |
| 64 | + ****************************************************************************/ |
| 65 | + |
| 66 | +uint32_t board_buttons(void) |
| 67 | +{ |
| 68 | + return stm32_gpioread(GPIO_BTN_USER) ? 1 : 0; |
| 69 | +} |
| 70 | + |
| 71 | +/**************************************************************************** |
| 72 | + * Button support. |
| 73 | + * |
| 74 | + * Description: |
| 75 | + * board_button_initialize() must be called to initialize button resources. |
| 76 | + * After that, board_buttons() may be called to collect the current state |
| 77 | + * of all buttons or board_button_irq() may be called to register button |
| 78 | + * interrupt handlers. |
| 79 | + * |
| 80 | + * After board_button_initialize() has been called, board_buttons() may be |
| 81 | + * called to collect the state of all buttons. board_buttons() returns a |
| 82 | + * 32-bit bit set with each bit associated with a button. See the |
| 83 | + * BUTTON_*_BIT definitions in board.h for the meaning of each bit. |
| 84 | + * |
| 85 | + * board_button_irq() may be called to register an interrupt handler that |
| 86 | + * will be called when a button is depressed or released. The ID value is |
| 87 | + * a button enumeration value that uniquely identifies a button resource. |
| 88 | + * See the BUTTON_* definitions in board.h for the meaning of enumeration |
| 89 | + * value. |
| 90 | + * |
| 91 | + ****************************************************************************/ |
| 92 | + |
| 93 | +#ifdef CONFIG_ARCH_IRQBUTTONS |
| 94 | +int board_button_irq(int id, xcpt_t irqhandler, void *arg) |
| 95 | +{ |
| 96 | + int ret = -EINVAL; |
| 97 | + |
| 98 | + if (id == BUTTON_USER) |
| 99 | + { |
| 100 | + ret = stm32_gpiosetevent(GPIO_BTN_USER, true, true, true, |
| 101 | + irqhandler, arg); |
| 102 | + } |
| 103 | + |
| 104 | + return ret; |
| 105 | +} |
| 106 | +#endif |
| 107 | +#endif /* CONFIG_ARCH_BUTTONS */ |
0 commit comments