From 18c3c81509f01b222d76b84c09d4ca8900754dea Mon Sep 17 00:00:00 2001 From: Lev Miroshnichenko <limiroshnichenko@edu.hse.ru> Date: Mon, 3 Mar 2025 17:58:11 +0300 Subject: [PATCH] Add partially task 1 --- .gitignore | 1 + tasks/task1/Makefile | 25 +++++++++++++++++++++++++ tasks/task1/main.c | 31 +++++++++++++++++++++++++++++++ tasks/task1/main.c.1 | 17 +++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 .gitignore create mode 100644 tasks/task1/Makefile create mode 100644 tasks/task1/main.c create mode 100644 tasks/task1/main.c.1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2501489 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/bin diff --git a/tasks/task1/Makefile b/tasks/task1/Makefile new file mode 100644 index 0000000..b276478 --- /dev/null +++ b/tasks/task1/Makefile @@ -0,0 +1,25 @@ +# name of your application +APPLICATION = blinky + +# If no BOARD is found in the environment, use this default: +BOARD ?= nucleo-f401re + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../../deps/RIOT + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +# Use a peripheral timer for the delay, if available +FEATURES_REQUIRED += periph_timer +FEATURES_REQUIRED += periph_gpio_irq +USEMODULE += ztimer +USEMODULE += ztimer_usec +USEMODULE += periph_gpio + +include $(RIOTBASE)/Makefile.include diff --git a/tasks/task1/main.c b/tasks/task1/main.c new file mode 100644 index 0000000..a72496f --- /dev/null +++ b/tasks/task1/main.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include "board.h" +#include "periph/gpio.h" +#include "ztimer.h" + +void timer_cb (void *arg) { + (void)arg; + gpio_toggle(LED0_PIN); + gpio_irq_enable(BTN0_PIN); +} + +void button_irq_handler(void *arg) { + (void)arg; + static ztimer_t timer_handler = { + .callback = timer_cb, + .arg = NULL + }; + gpio_irq_disable(BTN0_PIN); + ztimer_set(ZTIMER_USEC, &timer_handler, 300 * US_PER_MS); +} + +int main(void) { + gpio_init(LED0_PIN, GPIO_OUT); + gpio_init(BTN0_PIN, GPIO_IN_PU); + gpio_init_int(BTN0_PIN, GPIO_IN_PU, GPIO_BOTH, button_irq_handler, NULL); + + for (;;) { + ztimer_sleep(ZTIMER_USEC, US_PER_SEC); + } +} + diff --git a/tasks/task1/main.c.1 b/tasks/task1/main.c.1 new file mode 100644 index 0000000..4f3c734 --- /dev/null +++ b/tasks/task1/main.c.1 @@ -0,0 +1,17 @@ +#include <stdio.h> + +#include "board.h" +#include "periph/gpio.h" +#include "ztimer.h" + +int main(void) { + gpio_t led = LED0_PIN;// GPIO_PIN(0, 2); + gpio_init(led, GPIO_OUT); + while (1) { + gpio_toggle(led); + LED0_TOGGLE; + puts("Blink! (No LED present or configured...)"); + ztimer_sleep(ZTIMER_USEC, 1 * US_PER_SEC); + } + return 0; +} -- GitLab