Breytt Overlay fyrir Can stillingar, virkjað can í prj conf og test kóði búinn til fyrir CAN FRAME stöffið úr L4.4
This commit is contained in:
@@ -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)
|
||||
{
|
||||
motor_application_main();
|
||||
}
|
||||
// void main(void)
|
||||
// {
|
||||
// motor_application_main();
|
||||
// }
|
||||
|
||||
#endif
|
||||
// #endif
|
||||
@@ -6,10 +6,6 @@
|
||||
#include <zephyr/devicetree.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 =
|
||||
GPIO_DT_SPEC_GET(DT_ALIAS(encoder_c1), gpios);
|
||||
@@ -31,17 +27,11 @@ RotaryEncoderDriver::RotaryEncoderDriver()
|
||||
int RotaryEncoderDriver::begin()
|
||||
{
|
||||
if (!gpio_is_ready_dt(&encoder_c1) ||
|
||||
!gpio_is_ready_dt(&encoder_c2) ||
|
||||
!gpio_is_ready_dt(&isr_probe)) {
|
||||
!gpio_is_ready_dt(&encoder_c2)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
int ret = gpio_pin_configure_dt(&isr_probe, GPIO_OUTPUT_INACTIVE);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = gpio_pin_configure_dt(&encoder_c1, GPIO_INPUT);
|
||||
int ret = gpio_pin_configure_dt(&encoder_c1, GPIO_INPUT);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -51,6 +41,7 @@ int RotaryEncoderDriver::begin()
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
gpio_init_callback(
|
||||
&encoder_c1_callback,
|
||||
gpio_edge_handler,
|
||||
@@ -89,8 +80,7 @@ void RotaryEncoderDriver::gpio_edge_handler(
|
||||
|
||||
if ((pins & BIT(encoder_c1.pin)) != 0U) {
|
||||
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
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user