From 0d40318621897a5ed3b82da04640c1fc9072773e Mon Sep 17 00:00:00 2001 From: leon <leon@leon-co.local> Date: Mon, 3 Mar 2025 20:16:56 +0300 Subject: [PATCH] Add task1 completed --- tasks/task1/main.c.1 | 17 -------- tasks/{task1 => task1_1}/Makefile | 0 tasks/task1_1/main.c | 22 +++++++++++ tasks/task1_2/Makefile | 25 ++++++++++++ tasks/{task1 => task1_2}/main.c | 3 +- tasks/task1_3/Makefile | 25 ++++++++++++ tasks/task1_3/main.c | 66 +++++++++++++++++++++++++++++++ 7 files changed, 139 insertions(+), 19 deletions(-) delete mode 100644 tasks/task1/main.c.1 rename tasks/{task1 => task1_1}/Makefile (100%) create mode 100644 tasks/task1_1/main.c create mode 100644 tasks/task1_2/Makefile rename tasks/{task1 => task1_2}/main.c (82%) create mode 100644 tasks/task1_3/Makefile create mode 100644 tasks/task1_3/main.c diff --git a/tasks/task1/main.c.1 b/tasks/task1/main.c.1 deleted file mode 100644 index 4f3c734..0000000 --- a/tasks/task1/main.c.1 +++ /dev/null @@ -1,17 +0,0 @@ -#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; -} diff --git a/tasks/task1/Makefile b/tasks/task1_1/Makefile similarity index 100% rename from tasks/task1/Makefile rename to tasks/task1_1/Makefile diff --git a/tasks/task1_1/main.c b/tasks/task1_1/main.c new file mode 100644 index 0000000..fb08901 --- /dev/null +++ b/tasks/task1_1/main.c @@ -0,0 +1,22 @@ +#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(LED0_PIN, GPIO_OUT); + gpio_init(BTN0_PIN, GPIO_IN_PU); + + for (;;) { + if (!gpio_read(BTN0_PIN)) { + gpio_set(LED0_PIN); + } else { + gpio_clear(LED0_PIN); + } + + ztimer_sleep(ZTIMER_USEC, 10 * US_PER_MS); + } + return 0; +} diff --git a/tasks/task1_2/Makefile b/tasks/task1_2/Makefile new file mode 100644 index 0000000..b276478 --- /dev/null +++ b/tasks/task1_2/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_2/main.c similarity index 82% rename from tasks/task1/main.c rename to tasks/task1_2/main.c index a72496f..2524ed8 100644 --- a/tasks/task1/main.c +++ b/tasks/task1_2/main.c @@ -21,8 +21,7 @@ void button_irq_handler(void *arg) { 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); + gpio_init_int(BTN0_PIN, GPIO_IN_PU, GPIO_FALLING, button_irq_handler, NULL); for (;;) { ztimer_sleep(ZTIMER_USEC, US_PER_SEC); diff --git a/tasks/task1_3/Makefile b/tasks/task1_3/Makefile new file mode 100644 index 0000000..b276478 --- /dev/null +++ b/tasks/task1_3/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_3/main.c b/tasks/task1_3/main.c new file mode 100644 index 0000000..ad37085 --- /dev/null +++ b/tasks/task1_3/main.c @@ -0,0 +1,66 @@ +#include <stdio.h> +#include <stdint.h> + +#include "board.h" +#include "periph/gpio.h" +#include "ztimer.h" + +// typedef struct { +// uint8_t pressed_series; +// uint8_t blink_multiplier; +// } button_context_t; +// +// void timer_cb (void *arg) { +// button_context_t* ctx = (button_context_t*)arg; +// if (!gpio_read(BTN0_PIN)) { +// ++(ctx->pressed_series); +// } +// // gpio_toggle(LED0_PIN); +// // gpio_irq_enable(BTN0_PIN); +// } +// +// void button_irq_handler(void *arg) { +// static ztimer_t timer_handler = { +// .callback = timer_cb, +// .arg = arg +// }; +// +// button_context_t* ctx = (button_context_t*)arg; +// +// // gpio_irq_disable(BTN0_PIN); +// ztimer_set(ZTIMER_USEC, &timer_handler, 200 * US_PER_MS); +// } + +int main(void) { + // button_context_t ctx = { + // .pressed_series = 0, + // .blink_multiplier = 3 + // }; + uint8_t blink_cnt = 0; + uint8_t blink_cnt_lim = 10; + uint8_t press_cnt = 0; + + gpio_init(LED0_PIN, GPIO_OUT); + gpio_init(BTN0_PIN, GPIO_IN_PU); + // gpio_init_int(BTN0_PIN, GPIO_IN_PU, GPIO_FALLING, button_irq_handler, &ctx); + + for (;;) { + if (!gpio_read(BTN0_PIN)) { + ++press_cnt; + } else { + press_cnt = 0; + } + if (press_cnt >= 20) { + blink_cnt_lim = blink_cnt_lim == 10 ? 30 : 10; + } + + ++blink_cnt; + if (blink_cnt > blink_cnt_lim) { + blink_cnt = 0; + gpio_toggle(LED0_PIN); + } + + ztimer_sleep(ZTIMER_USEC, 100 * US_PER_MS); + } +} + -- GitLab