|
16 | 16 | * You should have received a copy of the GNU General Public License |
17 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 | */ |
| 19 | + |
| 20 | +#include <zephyr/drivers/gpio.h> |
19 | 21 | #include <zephyr/kernel.h> |
20 | 22 | #include <zephyr/logging/log.h> |
21 | | -#include <zephyr/settings/settings.h> |
22 | | -#include <zephyr/types.h> |
23 | 23 |
|
24 | 24 | #include <signals/signals.h> |
25 | 25 |
|
26 | | -#include <dk_buttons_and_leds.h> |
27 | | - |
28 | 26 | #define LOG_MODULE_NAME signals |
29 | 27 | LOG_MODULE_REGISTER(LOG_MODULE_NAME); |
30 | 28 |
|
31 | | -#define OUT_RESERVED DK_LED1 |
32 | | - |
33 | | -#define IN_STAY_IN_BOOTLOADER DK_BTN1_MSK |
| 29 | +static const struct gpio_dt_spec stay_in_bootloader_btn = |
| 30 | + GPIO_DT_SPEC_GET(DT_ALIAS(stay_in_bootloader), gpios); |
| 31 | +static const struct gpio_dt_spec reserved_output = |
| 32 | + GPIO_DT_SPEC_GET(DT_ALIAS(reserved_output), gpios); |
34 | 33 |
|
35 | 34 | static K_SEM_DEFINE(signals_ok, 0, 1); |
36 | 35 |
|
37 | 36 | static bool out_reserved = false; |
38 | 37 |
|
39 | | -void button_changed(uint32_t button_state, uint32_t has_changed) {} |
40 | | - |
41 | | -static void configure_gpio(void) { |
| 38 | +bool signals_init(void) { |
42 | 39 | int err; |
43 | 40 |
|
44 | | - err = dk_buttons_init(button_changed); |
| 41 | + err = gpio_pin_configure_dt(&stay_in_bootloader_btn, GPIO_INPUT); |
45 | 42 | if (err) { |
46 | | - LOG_ERR("Cannot init INPUT (err: %d)", err); |
| 43 | + LOG_ERR("Cannot configure bootloader button (err: %d)", err); |
| 44 | + return false; |
47 | 45 | } |
48 | 46 |
|
49 | | - err = dk_leds_init(); |
| 47 | + err = gpio_pin_configure_dt(&reserved_output, GPIO_OUTPUT_INACTIVE); |
50 | 48 | if (err) { |
51 | | - LOG_ERR("Cannot init OUTPUT (err: %d)", err); |
| 49 | + LOG_ERR("Cannot configure reserved output (err: %d)", err); |
| 50 | + return false; |
52 | 51 | } |
53 | | -} |
54 | | - |
55 | | -bool signals_is_stay_in_bootloader(void) { |
56 | | - return (dk_get_buttons() & IN_STAY_IN_BOOTLOADER) != 0; |
57 | | -} |
58 | | - |
59 | | -bool signals_init(void) { |
60 | | - configure_gpio(); |
61 | 52 |
|
62 | 53 | k_sem_give(&signals_ok); |
63 | 54 |
|
64 | 55 | return true; |
65 | 56 | } |
66 | 57 |
|
| 58 | +bool signals_is_stay_in_bootloader(void) { |
| 59 | + return gpio_pin_get_dt(&stay_in_bootloader_btn) > 0; |
| 60 | +} |
| 61 | + |
67 | 62 | void signals_set_reserved(bool set) { |
68 | 63 | out_reserved = set; |
69 | | - dk_set_led(OUT_RESERVED, set); |
| 64 | + gpio_pin_set_dt(&reserved_output, set); |
70 | 65 | } |
71 | 66 |
|
72 | 67 | bool signals_out_get_reserved(void) { return out_reserved; } |
0 commit comments