Skip to content

Commit 578eb3b

Browse files
committed
add MiniCAN example
1 parent 6324911 commit 578eb3b

File tree

5 files changed

+196
-4
lines changed

5 files changed

+196
-4
lines changed

.github/workflows/arduino-action-cores3-compile.yml .github/workflows/arduino-action-compile.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ jobs:
4040
# You may add a suffix behind the fqbn with "|" to specify one board for e.g. different compile options like arduino:avr:uno|trace
4141
#############################################################################################################
4242
arduino-boards-fqbn:
43-
- m5stack:esp32:cores3
43+
- m5stack:esp32:m5stack_cores3
4444

4545
# Specify parameters for each board.
4646
#############################################################################################################
4747
include:
48-
- arduino-boards-fqbn: m5stack:esp32:cores3
48+
- arduino-boards-fqbn: m5stack:esp32:m5stack_cores3
4949
platform-url: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json
5050
sketches-exclude: WhistleSwitch,50Hz,SimpleFrequencyDetector
5151

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# M5CoreS3 Library
22

3-
[![Arduino Compile](https://github.com/m5stack/M5CoreS3/actions/workflows/arduino-action-cores3-compile.yml/badge.svg)](https://github.com/m5stack/M5CoreS3/actions/workflows/arduino-action-cores3-compile.yml)
3+
[![Arduino Compile](https://github.com/m5stack/M5CoreS3/actions/workflows/arduino-action-compile.yml/badge.svg)](https://github.com/m5stack/M5CoreS3/actions/workflows/arduino-action-compile.yml)
44
[![Arduino Lint](https://github.com/m5stack/M5CoreS3/actions/workflows/Arduino-Lint-Check.yml/badge.svg)](https://github.com/m5stack/M5CoreS3/actions/workflows/Arduino-Lint-Check.yml)
55
[![Clang Format](https://github.com/m5stack/M5CoreS3/actions/workflows/clang-format-check.yml/badge.svg)](https://github.com/m5stack/M5CoreS3/actions/workflows/clang-format-check.yml)
66

README_cn.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# M5CoreS3 Library
22

3-
[![Arduino Compile](https://github.com/m5stack/M5CoreS3/actions/workflows/arduino-action-cores3-compile.yml/badge.svg)](https://github.com/m5stack/M5CoreS3/actions/workflows/arduino-action-cores3-compile.yml)
3+
[![Arduino Compile](https://github.com/m5stack/M5CoreS3/actions/workflows/arduino-action-compile.yml/badge.svg)](https://github.com/m5stack/M5CoreS3/actions/workflows/arduino-action-compile.yml)
44
[![Arduino Lint](https://github.com/m5stack/M5CoreS3/actions/workflows/Arduino-Lint-Check.yml/badge.svg)](https://github.com/m5stack/M5CoreS3/actions/workflows/Arduino-Lint-Check.yml)
55
[![Clang Format](https://github.com/m5stack/M5CoreS3/actions/workflows/clang-format-check.yml/badge.svg)](https://github.com/m5stack/M5CoreS3/actions/workflows/clang-format-check.yml)
66

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* @file Slave.ino
3+
* @author SeanKwok ([email protected])
4+
* @brief Unit Mini CAN Test Master
5+
* @version 0.1
6+
* @date 2024-02-01
7+
*
8+
*
9+
* @Hardwares: M5CoreS3 + Unit Mini CAN
10+
* @Platform Version: Arduino M5Stack Board Manager v2.0.9
11+
* @Dependent Library:
12+
* M5GFX: https://github.com/m5stack/M5GFX
13+
* M5Unified: https://github.com/m5stack/M5Unified
14+
* M5CoreS3: https://github.com/m5stack/M5CoreS3
15+
*/
16+
17+
#include <stdio.h>
18+
#include <stdlib.h>
19+
#include "freertos/FreeRTOS.h"
20+
#include "freertos/task.h"
21+
#include "freertos/queue.h"
22+
#include "freertos/semphr.h"
23+
#include "esp_err.h"
24+
#include "esp_log.h"
25+
#include "driver/twai.h"
26+
#include "esp_err.h"
27+
28+
#include "M5CoreS3.h"
29+
30+
M5Canvas canvas(&CoreS3.Display);
31+
32+
/* --------------------- Definitions and static variables ------------------ */
33+
34+
#define TX_TASK_PRIO 8 // Receiving task priority
35+
#define TX_GPIO_NUM gpio_num_t(9)
36+
#define RX_GPIO_NUM gpio_num_t(8)
37+
38+
static const twai_general_config_t g_config =
39+
TWAI_GENERAL_CONFIG_DEFAULT(TX_GPIO_NUM, RX_GPIO_NUM, TWAI_MODE_NORMAL);
40+
static const twai_timing_config_t t_config = TWAI_TIMING_CONFIG_25KBITS();
41+
static const twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
42+
43+
#define ID_SLAVE_1 0x0B1
44+
45+
static const twai_message_t slave_1_on = {.identifier = ID_SLAVE_1,
46+
.data_length_code = 8,
47+
.data = {1, 2, 3, 4, 5, 6, 7, 8}};
48+
49+
static const twai_message_t slave_1_off = {.identifier = ID_SLAVE_1,
50+
.data_length_code = 8,
51+
.data = {0, 0, 0, 0, 0, 0, 0, 0}};
52+
53+
static void twai_transmit_task(void *arg) {
54+
while (1) {
55+
twai_transmit(&slave_1_on, portMAX_DELAY);
56+
57+
Serial.printf("send cmd on to 0x%02X\r\n", ID_SLAVE_1);
58+
Serial.print("send data: ");
59+
canvas.printf("send cmd on to 0x%02X\r\n", ID_SLAVE_1);
60+
canvas.print("send data: ");
61+
for (int i = 0; i < slave_1_on.data_length_code; i++) {
62+
Serial.printf("0x%02X ", slave_1_on.data[i]);
63+
canvas.printf("0x%02X ", slave_1_on.data[i]);
64+
}
65+
Serial.println();
66+
canvas.println("\r\n");
67+
canvas.pushSprite(0, 0);
68+
vTaskDelay(pdMS_TO_TICKS(1000));
69+
70+
twai_transmit(&slave_1_off, portMAX_DELAY);
71+
Serial.printf("send cmd off to 0x%02X\r\n", ID_SLAVE_1);
72+
Serial.print("send data: ");
73+
canvas.printf("send cmd off to 0x%02X\r\n", ID_SLAVE_1);
74+
canvas.print("send data: ");
75+
for (int i = 0; i < slave_1_off.data_length_code; i++) {
76+
Serial.printf("0x%02X ", slave_1_off.data[i]);
77+
canvas.printf("0x%02X ", slave_1_on.data[i]);
78+
}
79+
Serial.println();
80+
canvas.println("\r\n");
81+
canvas.pushSprite(0, 0);
82+
vTaskDelay(pdMS_TO_TICKS(1000));
83+
}
84+
vTaskDelete(NULL);
85+
}
86+
87+
void setup() {
88+
auto cfg = M5.config();
89+
CoreS3.begin(cfg);
90+
91+
canvas.setColorDepth(1); // mono color
92+
canvas.createSprite(CoreS3.Display.width(), CoreS3.Display.height());
93+
canvas.setPaletteColor(1, GREEN);
94+
canvas.setTextScroll(true);
95+
96+
canvas.println("CAN Master");
97+
98+
canvas.pushSprite(0, 0);
99+
100+
ESP_ERROR_CHECK(twai_driver_install(&g_config, &t_config, &f_config));
101+
Serial.println("Driver installed");
102+
ESP_ERROR_CHECK(twai_start());
103+
xTaskCreatePinnedToCore(twai_transmit_task, "twai_transmit_task", 4096,
104+
NULL, TX_TASK_PRIO, NULL, tskNO_AFFINITY);
105+
}
106+
107+
void loop() {
108+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* @file Slave.ino
3+
* @author SeanKwok ([email protected])
4+
* @brief Unit Mini CAN Test Slave
5+
* @version 0.1
6+
* @date 2024-02-01
7+
*
8+
*
9+
* @Hardwares: M5CoreS3 + Unit Mini CAN
10+
* @Platform Version: Arduino M5Stack Board Manager v2.0.9
11+
* @Dependent Library:
12+
* M5GFX: https://github.com/m5stack/M5GFX
13+
* M5Unified: https://github.com/m5stack/M5Unified
14+
* M5CoreS3: https://github.com/m5stack/M5CoreS3
15+
*/
16+
17+
#include <stdio.h>
18+
#include <stdlib.h>
19+
#include "freertos/FreeRTOS.h"
20+
#include "freertos/task.h"
21+
#include "freertos/queue.h"
22+
#include "freertos/semphr.h"
23+
#include "esp_err.h"
24+
#include "esp_log.h"
25+
#include "driver/twai.h"
26+
#include "esp_err.h"
27+
28+
#include "M5CoreS3.h"
29+
M5Canvas canvas(&CoreS3.Display);
30+
31+
/* --------------------- Definitions and static variables ------------------ */
32+
33+
#define RX_TASK_PRIO 8 // Receiving task priority
34+
#define TX_GPIO_NUM gpio_num_t(9)
35+
#define RX_GPIO_NUM gpio_num_t(8)
36+
37+
static const twai_general_config_t g_config =
38+
TWAI_GENERAL_CONFIG_DEFAULT(TX_GPIO_NUM, RX_GPIO_NUM, TWAI_MODE_NORMAL);
39+
static const twai_timing_config_t t_config = TWAI_TIMING_CONFIG_25KBITS();
40+
static const twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
41+
42+
static void twai_receive_task(void *arg) {
43+
twai_message_t rx_msg;
44+
while (1) {
45+
twai_receive(&rx_msg, portMAX_DELAY);
46+
Serial.printf("received identifier: 0x%02X\r\n", rx_msg.identifier);
47+
canvas.printf("received identifier: 0x%02X\r\n", rx_msg.identifier);
48+
// rx_msg.data
49+
Serial.print("received data: ");
50+
canvas.print("received data: ");
51+
for (int i = 0; i < rx_msg.data_length_code; i++) {
52+
Serial.printf("0x%02X ", rx_msg.data[i]);
53+
canvas.printf("0x%02X ", rx_msg.data[i]);
54+
}
55+
Serial.println();
56+
canvas.println("\r\n");
57+
canvas.pushSprite(0, 0);
58+
vTaskDelay(pdMS_TO_TICKS(100));
59+
}
60+
vTaskDelete(NULL);
61+
}
62+
63+
void setup() {
64+
auto cfg = M5.config();
65+
CoreS3.begin(cfg);
66+
67+
canvas.setColorDepth(1); // mono color
68+
canvas.createSprite(CoreS3.Display.width(), CoreS3.Display.height());
69+
canvas.setPaletteColor(1, GREEN);
70+
canvas.setTextScroll(true);
71+
72+
canvas.println("CAN Slave");
73+
74+
canvas.pushSprite(0, 0);
75+
76+
ESP_ERROR_CHECK(twai_driver_install(&g_config, &t_config, &f_config));
77+
Serial.println("Driver installed");
78+
ESP_ERROR_CHECK(twai_start());
79+
xTaskCreatePinnedToCore(twai_receive_task, "twai_receive_task", 4096, NULL,
80+
RX_TASK_PRIO, NULL, tskNO_AFFINITY);
81+
}
82+
83+
void loop() {
84+
}

0 commit comments

Comments
 (0)