diff --git a/examples/AtomicBase/AtomicGPS/GPS/GPS.ino b/examples/AtomicBase/AtomicGPS/GPS/GPS.ino index 1b94ba4..e180bbd 100644 --- a/examples/AtomicBase/AtomicGPS/GPS/GPS.ino +++ b/examples/AtomicBase/AtomicGPS/GPS/GPS.ino @@ -87,7 +87,7 @@ void setup() { AtomS3.Display.setTextColor(GREEN); AtomS3.Display.setTextDatum(middle_center); - AtomS3.Display.setTextFont(&fonts::FreeSerifBold24pt7b); + AtomS3.Display.setFont(&fonts::FreeSerifBold24pt7b); AtomS3.Display.setTextSize(1); AtomS3.Display.drawString("GPS", AtomS3.Display.width() / 2, AtomS3.Display.height() / 2); diff --git a/examples/AtomicBase/AtomicGPS/MicroSD/MicroSD.ino b/examples/AtomicBase/AtomicGPS/MicroSD/MicroSD.ino index fa60707..50c6a3b 100644 --- a/examples/AtomicBase/AtomicGPS/MicroSD/MicroSD.ino +++ b/examples/AtomicBase/AtomicGPS/MicroSD/MicroSD.ino @@ -193,7 +193,7 @@ void setup() { AtomS3.Display.setTextColor(GREEN); AtomS3.Display.setTextDatum(middle_center); - AtomS3.Display.setTextFont(&fonts::FreeSerifItalic12pt7b); + AtomS3.Display.setFont(&fonts::FreeSerifItalic12pt7b); AtomS3.Display.setTextSize(1); AtomS3.Display.drawString("MicroSD", AtomS3.Display.width() / 2, 20); diff --git a/examples/AtomicBase/AtomicHDriver/AtomicHDriver.ino b/examples/AtomicBase/AtomicHDriver/AtomicHDriver.ino index b5f4ba3..2322fad 100644 --- a/examples/AtomicBase/AtomicHDriver/AtomicHDriver.ino +++ b/examples/AtomicBase/AtomicHDriver/AtomicHDriver.ino @@ -32,7 +32,7 @@ void setup() { AtomS3.Display.setTextColor(GREEN); AtomS3.Display.setTextDatum(middle_center); - AtomS3.Display.setTextFont(&fonts::Orbitron_Light_24); + AtomS3.Display.setFont(&fonts::Orbitron_Light_24); AtomS3.Display.setTextSize(1); AtomS3.Display.drawString("H-Driver", AtomS3.Display.width() / 2, AtomS3.Display.height() / 2); diff --git a/examples/AtomicBase/AtomicPWM/AtomicPWM.ino b/examples/AtomicBase/AtomicPWM/AtomicPWM.ino index df24106..4be3c12 100644 --- a/examples/AtomicBase/AtomicPWM/AtomicPWM.ino +++ b/examples/AtomicBase/AtomicPWM/AtomicPWM.ino @@ -30,7 +30,7 @@ void setup() { AtomS3.Display.setTextColor(GREEN); AtomS3.Display.setTextDatum(middle_center); - AtomS3.Display.setTextFont(&fonts::Orbitron_Light_24); + AtomS3.Display.setFont(&fonts::Orbitron_Light_24); AtomS3.Display.setTextSize(1); AtomS3.Display.drawString("PWM", AtomS3.Display.width() / 2, AtomS3.Display.height() / 2); diff --git a/examples/AtomicBase/AtomicPoE/HTTP/HTTP.ino b/examples/AtomicBase/AtomicPoE/HTTP/HTTP.ino index 1e674a2..7aad251 100644 --- a/examples/AtomicBase/AtomicPoE/HTTP/HTTP.ino +++ b/examples/AtomicBase/AtomicPoE/HTTP/HTTP.ino @@ -40,7 +40,7 @@ void setup() { AtomS3.Display.setTextColor(GREEN); AtomS3.Display.setTextDatum(middle_center); - AtomS3.Display.setTextFont(&fonts::Orbitron_Light_24); + AtomS3.Display.setFont(&fonts::Orbitron_Light_24); AtomS3.Display.setTextSize(1); SPI.begin(SCK, MISO, MOSI, -1); diff --git a/examples/AtomicBase/AtomicPoE/LinkStatus/LinkStatus.ino b/examples/AtomicBase/AtomicPoE/LinkStatus/LinkStatus.ino index 8162000..e6020df 100644 --- a/examples/AtomicBase/AtomicPoE/LinkStatus/LinkStatus.ino +++ b/examples/AtomicBase/AtomicPoE/LinkStatus/LinkStatus.ino @@ -32,7 +32,7 @@ void setup() { AtomS3.Display.setTextColor(GREEN); AtomS3.Display.setTextDatum(middle_center); - AtomS3.Display.setTextFont(&fonts::Orbitron_Light_24); + AtomS3.Display.setFont(&fonts::Orbitron_Light_24); AtomS3.Display.setTextSize(1); AtomS3.Display.drawString("PoE", AtomS3.Display.width() / 2, 20); diff --git a/examples/AtomicBase/AtomicPoE/MQTT/MQTT.ino b/examples/AtomicBase/AtomicPoE/MQTT/MQTT.ino index 213337a..8af4ceb 100644 --- a/examples/AtomicBase/AtomicPoE/MQTT/MQTT.ino +++ b/examples/AtomicBase/AtomicPoE/MQTT/MQTT.ino @@ -83,7 +83,7 @@ void setup() { AtomS3.Display.setTextColor(GREEN); AtomS3.Display.setTextDatum(middle_center); - AtomS3.Display.setTextFont(&fonts::Orbitron_Light_24); + AtomS3.Display.setFont(&fonts::Orbitron_Light_24); AtomS3.Display.setTextSize(1); SPI.begin(SCK, MISO, MOSI, -1); diff --git a/examples/AtomicBase/AtomicPoE/WebServer/WebServer.ino b/examples/AtomicBase/AtomicPoE/WebServer/WebServer.ino index d24e642..080159d 100644 --- a/examples/AtomicBase/AtomicPoE/WebServer/WebServer.ino +++ b/examples/AtomicBase/AtomicPoE/WebServer/WebServer.ino @@ -35,7 +35,7 @@ void setup() { AtomS3.Display.setTextColor(GREEN); AtomS3.Display.setTextDatum(middle_center); - AtomS3.Display.setTextFont(&fonts::Orbitron_Light_24); + AtomS3.Display.setFont(&fonts::Orbitron_Light_24); AtomS3.Display.setTextSize(1); SPI.begin(SCK, MISO, MOSI, -1); diff --git a/examples/AtomicBase/AtomicTFCard/AtomicTFCard.ino b/examples/AtomicBase/AtomicTFCard/AtomicTFCard.ino index 52576de..9b59f82 100644 --- a/examples/AtomicBase/AtomicTFCard/AtomicTFCard.ino +++ b/examples/AtomicBase/AtomicTFCard/AtomicTFCard.ino @@ -193,7 +193,7 @@ void setup() { AtomS3.Display.setTextColor(GREEN); AtomS3.Display.setTextDatum(middle_center); - AtomS3.Display.setTextFont(&fonts::FreeSerifItalic12pt7b); + AtomS3.Display.setFont(&fonts::FreeSerifItalic12pt7b); AtomS3.Display.setTextSize(1); AtomS3.Display.drawString("MicroSD", AtomS3.Display.width() / 2, 20); diff --git a/examples/Basics/button/button.ino b/examples/Basics/button/button.ino index e21baf7..41e5356 100644 --- a/examples/Basics/button/button.ino +++ b/examples/Basics/button/button.ino @@ -22,7 +22,7 @@ void setup() { AtomS3.Display.setTextColor(GREEN); AtomS3.Display.setTextDatum(middle_center); - AtomS3.Display.setTextFont(&fonts::Orbitron_Light_24); + AtomS3.Display.setFont(&fonts::Orbitron_Light_24); AtomS3.Display.setTextSize(1); AtomS3.Display.drawString("Click!", AtomS3.Display.width() / 2, AtomS3.Display.height() / 2); diff --git a/examples/Basics/ir_nec/ir_nec.ino b/examples/Basics/ir_nec/ir_nec.ino index cefed90..6f8ece5 100644 --- a/examples/Basics/ir_nec/ir_nec.ino +++ b/examples/Basics/ir_nec/ir_nec.ino @@ -33,7 +33,7 @@ void setup() { AtomS3.begin(cfg); AtomS3.Display.setTextColor(GREEN); AtomS3.Display.setTextDatum(middle_center); - AtomS3.Display.setTextFont(&fonts::FreeMono9pt7b); + AtomS3.Display.setFont(&fonts::FreeMono9pt7b); AtomS3.Display.setTextSize(1); IrSender.begin(DISABLE_LED_FEEDBACK); // Start with IR_SEND_PIN as send pin diff --git a/examples/Unit/MiniCAN/Master/Master.ino b/examples/Unit/MiniCAN/Master/Master.ino new file mode 100644 index 0000000..4ad24f3 --- /dev/null +++ b/examples/Unit/MiniCAN/Master/Master.ino @@ -0,0 +1,95 @@ +/** + * @file Slave.ino + * @author SeanKwok (shaoxiang@m5stack.com) + * @brief Unit Mini CAN Test Master + * @version 0.1 + * @date 2024-02-01 + * + * + * @Hardwares: M5AtomS3 + Unit Mini CAN + * @Platform Version: Arduino M5Stack Board Manager v2.0.9 + * @Dependent Library: + * M5GFX: https://github.com/m5stack/M5GFX + * M5Unified: https://github.com/m5stack/M5Unified + * M5AtomS3: https://github.com/m5stack/M5AtomS3 + */ + +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" +#include "esp_err.h" +#include "esp_log.h" +#include "driver/twai.h" +#include "esp_err.h" + +#include "M5AtomS3.h" + +/* --------------------- Definitions and static variables ------------------ */ + +#define TX_TASK_PRIO 8 // Receiving task priority +#define TX_GPIO_NUM gpio_num_t(2) +#define RX_GPIO_NUM gpio_num_t(1) + +static const twai_general_config_t g_config = + TWAI_GENERAL_CONFIG_DEFAULT(TX_GPIO_NUM, RX_GPIO_NUM, TWAI_MODE_NORMAL); +static const twai_timing_config_t t_config = TWAI_TIMING_CONFIG_25KBITS(); +static const twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); + +#define ID_SLAVE_1 0x0B1 + +static const twai_message_t slave_1_on = {.identifier = ID_SLAVE_1, + .data_length_code = 8, + .data = {1, 2, 3, 4, 5, 6, 7, 8}}; + +static const twai_message_t slave_1_off = {.identifier = ID_SLAVE_1, + .data_length_code = 8, + .data = {0, 0, 0, 0, 0, 0, 0, 0}}; + +static void twai_transmit_task(void *arg) { + while (1) { + twai_transmit(&slave_1_on, portMAX_DELAY); + Serial.printf("send cmd on to 0x%02X\r\n", ID_SLAVE_1); + Serial.print("send data: "); + for (int i = 0; i < slave_1_on.data_length_code; i++) { + Serial.printf("0x%02X ", slave_1_on.data[i]); + } + Serial.println(); + + vTaskDelay(pdMS_TO_TICKS(1000)); + + twai_transmit(&slave_1_off, portMAX_DELAY); + Serial.printf("send cmd off to 0x%02X\r\n", ID_SLAVE_1); + Serial.print("send data: "); + for (int i = 0; i < slave_1_off.data_length_code; i++) { + Serial.printf("0x%02X ", slave_1_off.data[i]); + } + Serial.println(); + vTaskDelay(pdMS_TO_TICKS(1000)); + } + vTaskDelete(NULL); +} + +void setup() { + auto cfg = M5.config(); + AtomS3.begin(cfg); + + AtomS3.Display.setTextColor(GREEN); + AtomS3.Display.setTextDatum(middle_center); + AtomS3.Display.setFont(&fonts::FreeSansBold9pt7b); + AtomS3.Display.setTextSize(1); + + AtomS3.Display.drawString("CAN Master", AtomS3.Display.width() / 2, + AtomS3.Display.height() / 2); + + ESP_ERROR_CHECK(twai_driver_install(&g_config, &t_config, &f_config)); + Serial.println("Driver installed"); + ESP_ERROR_CHECK(twai_start()); + xTaskCreatePinnedToCore(twai_transmit_task, "twai_transmit_task", 4096, + NULL, TX_TASK_PRIO, NULL, tskNO_AFFINITY); +} + +void loop() { +} \ No newline at end of file diff --git a/examples/Unit/MiniCAN/Slave/Slave.ino b/examples/Unit/MiniCAN/Slave/Slave.ino new file mode 100644 index 0000000..c8eb50f --- /dev/null +++ b/examples/Unit/MiniCAN/Slave/Slave.ino @@ -0,0 +1,77 @@ +/** + * @file Slave.ino + * @author SeanKwok (shaoxiang@m5stack.com) + * @brief Unit Mini CAN Test Slave + * @version 0.1 + * @date 2024-02-01 + * + * + * @Hardwares: M5AtomS3 + Unit Mini CAN + * @Platform Version: Arduino M5Stack Board Manager v2.0.9 + * @Dependent Library: + * M5GFX: https://github.com/m5stack/M5GFX + * M5Unified: https://github.com/m5stack/M5Unified + * M5AtomS3: https://github.com/m5stack/M5AtomS3 + */ + +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" +#include "esp_err.h" +#include "esp_log.h" +#include "driver/twai.h" +#include "esp_err.h" + +#include "M5AtomS3.h" + +/* --------------------- Definitions and static variables ------------------ */ + +#define RX_TASK_PRIO 8 // Receiving task priority +#define TX_GPIO_NUM gpio_num_t(2) +#define RX_GPIO_NUM gpio_num_t(1) + +static const twai_general_config_t g_config = + TWAI_GENERAL_CONFIG_DEFAULT(TX_GPIO_NUM, RX_GPIO_NUM, TWAI_MODE_NORMAL); +static const twai_timing_config_t t_config = TWAI_TIMING_CONFIG_25KBITS(); +static const twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); + +static void twai_receive_task(void *arg) { + twai_message_t rx_msg; + while (1) { + twai_receive(&rx_msg, portMAX_DELAY); + Serial.printf("received identifier: 0x%02X\r\n", rx_msg.identifier); + // rx_msg.data + Serial.print("received data: "); + for (int i = 0; i < rx_msg.data_length_code; i++) { + Serial.printf("0x%02X ", rx_msg.data[i]); + } + Serial.println(); + vTaskDelay(pdMS_TO_TICKS(100)); + } + vTaskDelete(NULL); +} + +void setup() { + auto cfg = M5.config(); + AtomS3.begin(cfg); + + AtomS3.Display.setTextColor(GREEN); + AtomS3.Display.setTextDatum(middle_center); + AtomS3.Display.setFont(&fonts::FreeSansBold9pt7b); + AtomS3.Display.setTextSize(1); + + AtomS3.Display.drawString("CAN Slave", AtomS3.Display.width() / 2, + AtomS3.Display.height() / 2); + + ESP_ERROR_CHECK(twai_driver_install(&g_config, &t_config, &f_config)); + Serial.println("Driver installed"); + ESP_ERROR_CHECK(twai_start()); + xTaskCreatePinnedToCore(twai_receive_task, "twai_receive_task", 4096, NULL, + RX_TASK_PRIO, NULL, tskNO_AFFINITY); +} + +void loop() { +} \ No newline at end of file