Changeset - a02651c5dd9b
[Not reviewed]
default
0 3 0
Ethan Zonca - 17 months ago 2024-01-15 14:16:47
ez@ethanzonca.com
Add missing includes and update readme
3 files changed with 15 insertions and 3 deletions:
0 comments (0 inline, 0 general)
README.md
Show inline comments
 
# Protofusion ESP32S3 Template
 

	
 
## Configure
 
Set target with `idf.y set-target esp32s3`
 

	
 
Run menuconfig with `idf.py menuconfig` and choose the Protofusion menu option.
 

	
 
Set target with `idf.y set-target esp32s3`
 

	
 
Rename the project by editing CMakeLists.txt and change `project(protofusion_template)` to reflect your project name
 

	
 
Note that clean doesn't always clean everything... do `idf.py fullclean` to make sure all generated files are removed (especially when switching processors).
 

	
 
## Build and Flash
 

	
 
Build the project and flash it to the board, then run monitor tool to view serial output:
 
Build the project
 

	
 
```bash
 
idf.py build
 
```
 

	
 
Flash to board and run monitor tool to view serial output:
 

	
 
```bash
 
idf.py flash monitor
 
```
 

	
 
(To exit the serial monitor, type ``Ctrl-]``.)
 

	
main/can.c
Show inline comments
 
//
 
// can
 
//
 

	
 
#include "can.h"
 
#include "esp_log.h"
 
#include "driver/twai.h"
 
#include "freertos/FreeRTOS.h"
 
#include "freertos/task.h"
 
#include "freertos/event_groups.h"
 

	
 
// EMZ FIXME
 
#define TX_GPIO_NUM 5
 
#define RX_GPIO_NUM 6
 
#define RX_TASK_PRIO 3
 

	
 

	
 
// Private variables
 
static const char *TAG = "canbus";
 

	
 

	
 
// static QueueHandle_t tx_task_queue;
 
// static QueueHandle_t rx_task_queue;
 

	
 

	
 
// Task for receiving CAN messages
 
static void twai_receive_task(void *arg)
 
{
 
    while (1) {
 
        twai_message_t rx_msg;
 
        twai_receive(&rx_msg, portMAX_DELAY);
 
        if (rx_msg.identifier == 0xdead) {
 
            ESP_LOGI(TAG, "Received data ");
 
        }
 

	
 
    }
 
    vTaskDelete(NULL);
 
}
 

	
 

	
 
// Initialize the CAN bus
 
void can_init(void)
 
{
 
    // CAN bus configuration
 
    twai_timing_config_t t_config = TWAI_TIMING_CONFIG_125KBITS();
 
    twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
 
    twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(TX_GPIO_NUM, RX_GPIO_NUM, TWAI_MODE_NORMAL);
 
	
 
    // Move canbus irq to free up the default level 1 IRQ it will take up (processor panics if we don't do this)
 
    g_config.intr_flags = ESP_INTR_FLAG_LOWMED;
 

	
 
    // Install TWAI driver
 
    ESP_ERROR_CHECK(twai_driver_install(&g_config, &t_config, &f_config));
 
    ESP_LOGI(TAG, "Driver installed");
 
    ESP_ERROR_CHECK(twai_start());
 
    ESP_LOGI(TAG, "Driver started");
 

	
 
    // rx_task_queue = xQueueCreate(1, sizeof(rx_task_action_t));
main/wifi.c
Show inline comments
 
//
 
// wifi
 
//
 

	
 
#include "wifi.h"
 
#include "esp_wifi.h"
 
#include "esp_event.h"
 
#include "esp_log.h"
 
#include "lwip/err.h"
 
#include "lwip/sys.h"
 
#include "display.h"
 

	
 
#include "freertos/FreeRTOS.h"
 
#include "freertos/task.h"
 
#include "freertos/event_groups.h"
 

	
 
// Private variables
 

	
 
// FreeRTOS event group to signal when we are connected
 
static EventGroupHandle_t s_wifi_event_group;
 
static const char *TAG = "wifi station";
 
static int s_retry_num = 0;
 

	
 

	
 
// Handler for wifi events
 
static void __event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
 
{
 
    if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
 
        esp_wifi_connect();
 
    }
 
    else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) 
 
    {
 
        if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) 
 
        {
 
            esp_wifi_connect();
 
            s_retry_num++;
 
            ESP_LOGI(TAG, "retry to connect to the AP");
 
            display_update_text("AP Connect Retry");
 

	
 
        } 
 
        else 
 
        {
 
            xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
 
        }
 
        ESP_LOGI(TAG,"connect to the AP fail");
 
        display_update_text("AP Connect Fail");
 
        
 
    } 
 
    else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) 
 
    {
 
        ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
 
        ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
 
        char out[128] = {0};
 
        snprintf(out, 128, "Got IP " IPSTR, IP2STR(&event->ip_info.ip));
 
        display_update_text(out);
 
        s_retry_num = 0;
 
        xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
 
    }
 
}
 

	
 

	
 
// Initialize wifi and connect to network
 
void wifi_init(void)
0 comments (0 inline, 0 general)