Compare commits
1
Commits
b90b84d94c
...
Isak_part2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9eadbf1be |
@@ -0,0 +1,47 @@
|
|||||||
|
#include <zephyr/device.h>
|
||||||
|
#include <zephyr/devicetree.h>
|
||||||
|
#include <zephyr/drivers/can.h>
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/sys/printk.h>
|
||||||
|
|
||||||
|
/* Devicetree node selected by zephyr,canbus in the overlay */
|
||||||
|
#define CANBUS_NODE DT_CHOSEN(zephyr_canbus)
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
const struct device *dev = DEVICE_DT_GET(CANBUS_NODE);
|
||||||
|
|
||||||
|
if (!device_is_ready(dev)) {
|
||||||
|
printk("CAN device not ready\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int err = can_set_bitrate(dev, 125000);
|
||||||
|
if (err != 0) {
|
||||||
|
printk("Error setting CAN bitrate (err %d)\n", err);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = can_start(dev);
|
||||||
|
if (err != 0) {
|
||||||
|
printk("Error starting CAN controller (err %d)\n", err);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct can_frame frame = {
|
||||||
|
.flags = 0,
|
||||||
|
.id = 0x123,
|
||||||
|
.dlc = 8,
|
||||||
|
.data = {1, 2, 3, 4, 5, 6, 7, 8},
|
||||||
|
};
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
k_msleep(10);
|
||||||
|
|
||||||
|
err = can_send(dev, &frame, K_MSEC(100), NULL, NULL);
|
||||||
|
if (err != 0) {
|
||||||
|
printk("Sending failed (err %d)\n", err);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-8
@@ -1,12 +1,12 @@
|
|||||||
#include <zephyr/kernel.h>
|
// #include <zephyr/kernel.h>
|
||||||
|
|
||||||
#ifndef PIO_UNIT_TESTING
|
// #ifndef PIO_UNIT_TESTING
|
||||||
|
|
||||||
void motor_application_main(void);
|
// void motor_application_main(void);
|
||||||
|
|
||||||
void main(void)
|
// void main(void)
|
||||||
{
|
// {
|
||||||
motor_application_main();
|
// motor_application_main();
|
||||||
}
|
// }
|
||||||
|
|
||||||
#endif
|
// #endif
|
||||||
@@ -6,10 +6,6 @@
|
|||||||
#include <zephyr/devicetree.h>
|
#include <zephyr/devicetree.h>
|
||||||
#include <zephyr/drivers/gpio.h>
|
#include <zephyr/drivers/gpio.h>
|
||||||
|
|
||||||
//#define ISR_PROBE_NODE DT_PATH(zephyr_user)
|
|
||||||
|
|
||||||
static const struct gpio_dt_spec isr_probe =
|
|
||||||
GPIO_DT_SPEC_GET(DT_ALIAS(encoder_isr_probe), gpios);
|
|
||||||
|
|
||||||
static const struct gpio_dt_spec encoder_c1 =
|
static const struct gpio_dt_spec encoder_c1 =
|
||||||
GPIO_DT_SPEC_GET(DT_ALIAS(encoder_c1), gpios);
|
GPIO_DT_SPEC_GET(DT_ALIAS(encoder_c1), gpios);
|
||||||
@@ -31,17 +27,11 @@ RotaryEncoderDriver::RotaryEncoderDriver()
|
|||||||
int RotaryEncoderDriver::begin()
|
int RotaryEncoderDriver::begin()
|
||||||
{
|
{
|
||||||
if (!gpio_is_ready_dt(&encoder_c1) ||
|
if (!gpio_is_ready_dt(&encoder_c1) ||
|
||||||
!gpio_is_ready_dt(&encoder_c2) ||
|
!gpio_is_ready_dt(&encoder_c2)) {
|
||||||
!gpio_is_ready_dt(&isr_probe)) {
|
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = gpio_pin_configure_dt(&isr_probe, GPIO_OUTPUT_INACTIVE);
|
int ret = gpio_pin_configure_dt(&encoder_c1, GPIO_INPUT);
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = gpio_pin_configure_dt(&encoder_c1, GPIO_INPUT);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -51,6 +41,7 @@ int RotaryEncoderDriver::begin()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gpio_init_callback(
|
gpio_init_callback(
|
||||||
&encoder_c1_callback,
|
&encoder_c1_callback,
|
||||||
gpio_edge_handler,
|
gpio_edge_handler,
|
||||||
@@ -89,8 +80,7 @@ void RotaryEncoderDriver::gpio_edge_handler(
|
|||||||
|
|
||||||
if ((pins & BIT(encoder_c1.pin)) != 0U) {
|
if ((pins & BIT(encoder_c1.pin)) != 0U) {
|
||||||
encoder->update(); // Reads C2 and updates the count
|
encoder->update(); // Reads C2 and updates the count
|
||||||
gpio_pin_set_dt(&isr_probe, 1); // Marker rising edge
|
|
||||||
gpio_pin_set_dt(&isr_probe, 0); // Reset for the next interrupt
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
#include <zephyr/dt-bindings/pwm/pwm.h>
|
#include <zephyr/dt-bindings/pwm/pwm.h>
|
||||||
|
|
||||||
/ {
|
/ {
|
||||||
|
chosen {
|
||||||
|
zephyr,canbus = &can1;
|
||||||
|
};
|
||||||
|
|
||||||
aliases {
|
aliases {
|
||||||
encoder-c1 = &encoder_c1;
|
encoder-c1 = &encoder_c1;
|
||||||
encoder-c2 = &encoder_c2;
|
encoder-c2 = &encoder_c2;
|
||||||
@@ -11,7 +15,6 @@
|
|||||||
motor-flt = &motor_flt;
|
motor-flt = &motor_flt;
|
||||||
motor-slp = &motor_slp;
|
motor-slp = &motor_slp;
|
||||||
fault-test-button = &fault_test_button;
|
fault-test-button = &fault_test_button;
|
||||||
encoder-isr-probe = &encoder_isr_probe;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
buttons {
|
buttons {
|
||||||
@@ -50,11 +53,6 @@
|
|||||||
gpios = <&gpioa 1 GPIO_ACTIVE_HIGH>; /* A1, PA1 */
|
gpios = <&gpioa 1 GPIO_ACTIVE_HIGH>; /* A1, PA1 */
|
||||||
label = "Motor sleep";
|
label = "Motor sleep";
|
||||||
};
|
};
|
||||||
|
|
||||||
encoder_isr_probe: encoder_isr_probe {
|
|
||||||
gpios = <&gpioa 12 GPIO_ACTIVE_HIGH>; /* D2, PA12 */
|
|
||||||
label = "Encoder ISR probe";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
motor_pwm_outputs {
|
motor_pwm_outputs {
|
||||||
@@ -65,9 +63,6 @@
|
|||||||
label = "Motor BIN1 PWM";
|
label = "Motor BIN1 PWM";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
zephyr,user {
|
|
||||||
encoder-isr-probe-gpios = <&gpioa 12 GPIO_ACTIVE_HIGH>; /* D2, PA12 */
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
&timers1 {
|
&timers1 {
|
||||||
@@ -80,3 +75,9 @@
|
|||||||
pinctrl-names = "default";
|
pinctrl-names = "default";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
&can1 {
|
||||||
|
pinctrl-0 = <&can1_rx_pa11 &can1_tx_pa12>;
|
||||||
|
pinctrl-names = "default";
|
||||||
|
status = "okay";
|
||||||
|
};
|
||||||
@@ -8,3 +8,5 @@ CONFIG_CONSOLE=y
|
|||||||
CONFIG_UART_CONSOLE=y
|
CONFIG_UART_CONSOLE=y
|
||||||
CONFIG_PRINTK=y
|
CONFIG_PRINTK=y
|
||||||
CONFIG_CBPRINTF_FP_SUPPORT=y
|
CONFIG_CBPRINTF_FP_SUPPORT=y
|
||||||
|
|
||||||
|
CONFIG_CAN=y
|
||||||
Reference in New Issue
Block a user