diff options
| author | Abel Tim <git@abeltim.com> | 2025-06-12 10:28:13 +0200 |
|---|---|---|
| committer | Abel Tim <git@abeltim.com> | 2025-06-12 10:28:13 +0200 |
| commit | f6832123c23f394c3069bad6f8b19a896c705e51 (patch) | |
| tree | 03301be92270c03498778d1ae0c5bc7f7f686891 /code | |
| parent | 66a1669fd97feb4d026778c486e0db58baa0c687 (diff) | |
| download | robotica-f6832123c23f394c3069bad6f8b19a896c705e51.tar.gz robotica-f6832123c23f394c3069bad6f8b19a896c705e51.zip | |
recenltly removed three commit becouse it included files that shouldn't be included.
Did reset hard,
localy unstaged commits, deleted files and recommited the good files.
think this is all i did since,
-changed extra PCB name to bave and _ instead of a space so i dont have to use ""
-added button and led to teensy41 goaly overlay
-started on PWM, not complete
Abel Tim <git@abeltim.com>
Diffstat (limited to 'code')
| -rw-r--r-- | code/main/teensy_goalie/CMakeLists.txt | 38 | ||||
| -rw-r--r-- | code/main/teensy_goalie/prj.conf | 9 | ||||
| -rw-r--r-- | code/main/teensy_goalie/src/main.c | 55 | ||||
| -rw-r--r-- | code/main/teensy_goalie/teensy41.overlay | 58 | ||||
| -rw-r--r-- | code/main/teensy_player/player.yaml | 46 | ||||
| -rw-r--r-- | code/main/teensy_player/prj.conf | 1 | ||||
| -rw-r--r-- | code/main/teensy_player/src/main.c | 30 |
7 files changed, 133 insertions, 104 deletions
diff --git a/code/main/teensy_goalie/CMakeLists.txt b/code/main/teensy_goalie/CMakeLists.txt new file mode 100644 index 0000000..27e5715 --- /dev/null +++ b/code/main/teensy_goalie/CMakeLists.txt @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project( + player + VERSION 1.0 + DESCRIPTION "The code for the soccer player robot. https://github.com/mendelcollege-robotics/robotica" + LANGUAGES C +) + +#[===[ +# Create a static library target named "my_lib" +add_library(my_lib + STATIC + src/my_lib.c +) +target_include_directories( + my_lib + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include +) + +# Create an executable target with the same name as the project name +add_executable( + ${PROJECT_NAME} + src/main.c +) + +# Link the library to the executable. PRIVATE means that the library is not +# exposed to targets that depend on this target. +target_link_libraries( + ${PROJECT_NAME} + PRIVATE + my_lib +) +]===] +target_sources(app PRIVATE src/main.c) diff --git a/code/main/teensy_goalie/prj.conf b/code/main/teensy_goalie/prj.conf new file mode 100644 index 0000000..8379fac --- /dev/null +++ b/code/main/teensy_goalie/prj.conf @@ -0,0 +1,9 @@ +CONFIG_GPIO=y +CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y +CONFIG_PRINTK=y +CONFIG_SERIAL=y +CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_PWM=y +CONFIG_LOG=y +CONFIG_LOG_MODE_IMMEDIATE=y +CONFIG_PWM_LOG_LEVEL_DBG=y diff --git a/code/main/teensy_goalie/src/main.c b/code/main/teensy_goalie/src/main.c index f8aff35..137e898 100644 --- a/code/main/teensy_goalie/src/main.c +++ b/code/main/teensy_goalie/src/main.c @@ -1,48 +1,17 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - #include <stdio.h> #include <zephyr/kernel.h> +#include <zephyr/sys/printk.h> +#include <zephyr/device.h> +#include <zephyr/drivers/pwm.h> +#include <zephyr/devicetree.h> #include <zephyr/drivers/gpio.h> -/* 1000 msec = 1 sec */ -#define SLEEP_TIME_MS 1000 - -/* The devicetree node identifier for the "led0" alias. */ -#define LED0_NODE DT_ALIAS(led0) - -/* - * A build error on this line means your board is unsupported. - * See the sample documentation for information on how to fix this. - */ -static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); - -int main(void) -{ - int ret; - bool led_state = true; - - if (!gpio_is_ready_dt(&led)) { - return 0; - } - - ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); - if (ret < 0) { - return 0; - } - - while (1) { - ret = gpio_pin_toggle_dt(&led); - if (ret < 0) { - return 0; - } +// Settings +#define PWM_PERIOD_NS 20000000 +#define PWM_PULSE_WIDTH 1400000 +static const int32_t sleep_time_ms = 100; +static const struct gpio_dt_spec btn = GPIO_DT_SPEC_GET(DT_ALIAS(powerswitch), gpios); +static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(redled), gpios); - led_state = !led_state; - printf("LED state: %s\n", led_state ? "ON" : "OFF"); - k_msleep(SLEEP_TIME_MS); - } - return 0; -} +#define LED0_NODE DT_ALIAS(redled) +#define PWM_LED0 DT_ALIAS(en3a) diff --git a/code/main/teensy_goalie/teensy41.overlay b/code/main/teensy_goalie/teensy41.overlay new file mode 100644 index 0000000..3b023e3 --- /dev/null +++ b/code/main/teensy_goalie/teensy41.overlay @@ -0,0 +1,58 @@ +/* + * + * This is the overlay device tree file for the teensy 4.1 in the robosoccer mendelcollege robot. + * + * For more information on overlay files see + * https://docs.zephyrproject.org/latest/build/dts/howtos.html#set-devicetree-overlays + * https://www.digikey.be/en/maker/tutorials/2025/introduction-to-zephyr-part-4-devicetree-tutorial + * + */ +/ { + aliases { + powerswitch = &soft_power_switch; + redled = &red_led; + greenled = &green_led; + bueled = &blue_led; + en3a = &pwm_dev0; + }; + + buttons { + compatible = "gpio-keys"; + debounce-interval-ms = <50>; + polling-mode; + + soft_power_switch: d5 { + gpios = <&gpio4 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; + }; + }; + leds { + compatible = "gpio-leds"; + red_led: red-led { + gpios = <&gpio2 29 GPIO_ACTIVE_HIGH>; + label = "LED Pin 34 --> RED"; + }; + green_led: green-led { + gpios = <&gpio2 7 GPIO_ACTIVE_HIGH>; + label = "LED Pin 33 --> GREEN"; + }; + blue_led: blue-led { + gpios = <&gpio1 23 GPIO_ACTIVE_HIGH>; + label = "LED Pin 16 --> BLUE"; + }; + }; + pwmdevs { + compatible = "imx-pwm"; + pwm_dev0: pwm_dev_0 { + pwms = <&gpio2 10>; + }; + }; + +}; +&flexpwm1 { + status = "ok"; + flexpwm1_pwm0: flexpwm1_pwm0 { + status = "ok"; + }; + +}; + diff --git a/code/main/teensy_player/player.yaml b/code/main/teensy_player/player.yaml deleted file mode 100644 index df8f963..0000000 --- a/code/main/teensy_player/player.yaml +++ /dev/null @@ -1,46 +0,0 @@ -sample: - name: Blinky Sample -tests: - sample.basic.blinky: - tags: - - LED - - gpio - filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds") - depends_on: gpio - harness: led - integration_platforms: - - frdm_k64f - -manifest: - remotes: - # short names for project URLs - projects: - # a list of projects managed by west - defaults: - # default project attributes - self: - # configuration related to the manifest repository itself, - # i.e. the repository containing west.yml - version: "<schema-version>" - group-filter: - # a list of project groups to enable or disable - remotes: - - name: remote1 - url-base: https://git.example.com/base1 - - name: remote2 - url-base: https://git.example.com/base2 - projects: - - name: proj1 - description: the first example project - remote: remote1 - path: extra/project-1 - - name: proj2 - description: | - A multi-line description of the second example - project. - repo-path: my-path - remote: remote2 - revision: v1.3 - - name: proj3 - url: https://github.com/user/project-three - revision: abcde413a111 diff --git a/code/main/teensy_player/prj.conf b/code/main/teensy_player/prj.conf index 456b0fc..db01a00 100644 --- a/code/main/teensy_player/prj.conf +++ b/code/main/teensy_player/prj.conf @@ -3,3 +3,4 @@ CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y CONFIG_PRINTK=y CONFIG_SERIAL=y CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_PWM=y diff --git a/code/main/teensy_player/src/main.c b/code/main/teensy_player/src/main.c index 5b04ac2..3f84f88 100644 --- a/code/main/teensy_player/src/main.c +++ b/code/main/teensy_player/src/main.c @@ -7,8 +7,10 @@ #include <zephyr/drivers/pwm.h> #include <string.h> -/* size of stack area used by each thread */ -#define GEN_THRESD_STACKSIZE 1024 +/* Stack sizes (now only one size)*/ +/* To figure out how much is necessary: */ +/* https://zephyr-docs.listenai.com/guides/debug_tools/thread-analyzer.html */ +#define GENERAL_THREAD_STACKSIZE 1024 /*the pinout configuration*/ /*https://docs.zephyrproject.org/latest/boards/pjrc/teensy4/doc/index.html*/ @@ -18,23 +20,21 @@ #define m1pwm1 DT_ALIAS(GPIO4_6) /*pin 4*/ #define m1pwm2 DT_ALIAS(GPIO4_5) /*pin 3*/ /*encoder pins*/ -#define m1encoA 32 /*pin 32*//*encoder number 1*/ -#define Nm1encoA INT_TO_POINTER(0) /*gives encoder number N*/ -#define m1encoB 31 /*pin 31*//*encoder number 2*/ -#define Nm1encoB INT_TO_POINTER(1) /*gives encoder number N*/ - +#define m1encoA 32 /*pin 32 && encoder number 0*/ +#define Nm1encoA INT_TO_POINTER(0) +#define m1encoB 31 /*pin 31 && encoder number 1*/ +#define Nm1encoB INT_TO_POINTER(1) /*set priorities*/ -#define ENC_ISR_PRIO 1 /* set encoder interrupt service routine*/ - +#define ENC_ISR_PRIO 1 -/*variables*/ /*encoders/PWM/PID*/ #define NUM_ENCODERS 2 /*how many encoder pins there are*/ -volatile int encCount[NUM_ENCODERS] = {0}; /*sets all encoder counts to 0 changes of state*/ +volatile int encCount[NUM_ENCODERS] = {0}; /*misc*/ -#define MY_IRQ_FLAGS 0 /*no IRQ flags*/ +#define NO_IRQ_FLAGS 0 +#define PWM_PERIOD_µS 1600 /*The lengt of an full PWM cycle in microseconds*/ void ENCO_ISR(void *encN){ /*adds one to the encoder where a change of state is detected*/ @@ -46,9 +46,9 @@ void ENCO_ISR(void *encN){ } void ENC_ISR_installer(void){ - /*sets up the interupts for the encoder at same priority, need to configure FIFO in case of simultaneous call*/ - IRQ_CONNECT(m1encoA, ENC_ISR_PRIO, ENCO_ISR, '0', MY_IRQ_FLAGS); - IRQ_CONNECT(m1encoB, ENC_ISR_PRIO, ENCO_ISR, '1', MY_IRQ_FLAGS); + /*sets up the interrupts for the encoder at same priority, need to configure FIFO in case of simultaneous call*/ + IRQ_CONNECT(m1encoA, ENC_ISR_PRIO, ENCO_ISR, '0', NO_IRQ_FLAGS); + IRQ_CONNECT(m1encoB, ENC_ISR_PRIO, ENCO_ISR, '1', NO_IRQ_FLAGS); } int main(void){} |
