Organizing project files
This commit is contained in:
parent
3515036a4c
commit
183a35b645
|
@ -1,2 +1,12 @@
|
|||
idf_component_register(SRCS "blackmagick.c"
|
||||
INCLUDE_DIRS ".")
|
||||
set(SOURCES
|
||||
"main.c"
|
||||
"usb-cdc.c"
|
||||
"wifi.c"
|
||||
)
|
||||
|
||||
set(INCLUDES
|
||||
"."
|
||||
)
|
||||
|
||||
idf_component_register(SRCS ${SOURCES}
|
||||
INCLUDE_DIRS ${INCLUDES})
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
#include <stdint.h>
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "tinyusb.h"
|
||||
#include "tusb_cdc_acm.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
static const char *TAG = "example";
|
||||
static uint8_t buf[CONFIG_USB_CDC_RX_BUFSIZE + 1];
|
||||
|
||||
void tinyusb_cdc_rx_callback(int itf, cdcacm_event_t *event)
|
||||
{
|
||||
/* initialization */
|
||||
size_t rx_size = 0;
|
||||
|
||||
/* read */
|
||||
esp_err_t ret = tinyusb_cdcacm_read(itf, buf, CONFIG_USB_CDC_RX_BUFSIZE, &rx_size);
|
||||
if (ret == ESP_OK) {
|
||||
buf[rx_size] = '\0';
|
||||
ESP_LOGI(TAG, "Got data (%d bytes): %s", rx_size, buf);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Read error");
|
||||
}
|
||||
|
||||
/* write back */
|
||||
tinyusb_cdcacm_write_queue(itf, buf, rx_size);
|
||||
tinyusb_cdcacm_write_flush(itf, 0);
|
||||
}
|
||||
|
||||
void tinyusb_cdc_line_state_changed_callback(int itf, cdcacm_event_t *event)
|
||||
{
|
||||
int dtr = event->line_state_changed_data.dtr;
|
||||
int rst = event->line_state_changed_data.rts;
|
||||
ESP_LOGI(TAG, "Line state changed! dtr:%d, rst:%d", dtr, rst);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "USB initialization");
|
||||
tinyusb_config_t tusb_cfg = {}; // the configuration using default values
|
||||
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
|
||||
|
||||
tinyusb_config_cdcacm_t amc_cfg = {
|
||||
.usb_dev = TINYUSB_USBDEV_0,
|
||||
.cdc_port = TINYUSB_CDC_ACM_0,
|
||||
.rx_unread_buf_sz = 64,
|
||||
.callback_rx = &tinyusb_cdc_rx_callback, // the first way to register a callback
|
||||
.callback_rx_wanted_char = NULL,
|
||||
.callback_line_state_changed = NULL,
|
||||
.callback_line_coding_changed = NULL
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK(tusb_cdc_acm_init(&amc_cfg));
|
||||
/* the second way to register a callback */
|
||||
ESP_ERROR_CHECK(tinyusb_cdcacm_register_callback(
|
||||
TINYUSB_CDC_ACM_0,
|
||||
CDC_EVENT_LINE_STATE_CHANGED,
|
||||
&tinyusb_cdc_line_state_changed_callback));
|
||||
ESP_LOGI(TAG, "USB initialization DONE");
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#include <stdint.h>
|
||||
#include <esp_log.h>
|
||||
#include "usb-cdc.h"
|
||||
#include "wifi.h"
|
||||
|
||||
static const char* TAG = "main";
|
||||
|
||||
void app_main(void) {
|
||||
ESP_LOGI(TAG, "start");
|
||||
|
||||
usb_cdc_init();
|
||||
wifi_init();
|
||||
|
||||
ESP_LOGI(TAG, "end");
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
#include <stdint.h>
|
||||
#include <esp_log.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <tinyusb.h>
|
||||
#include <tusb_cdc_acm.h>
|
||||
#include <sdkconfig.h>
|
||||
|
||||
static const char* TAG = "usb-cdc";
|
||||
static uint8_t buf[CONFIG_USB_CDC_RX_BUFSIZE + 1];
|
||||
|
||||
void usb_cdc_rx_callback(int itf, cdcacm_event_t* event) {
|
||||
size_t rx_size = 0;
|
||||
|
||||
esp_err_t ret = tinyusb_cdcacm_read(itf, buf, CONFIG_USB_CDC_RX_BUFSIZE, &rx_size);
|
||||
if(ret == ESP_OK) {
|
||||
buf[rx_size] = '\0';
|
||||
ESP_LOGI(TAG, "Got data (%d bytes): %s", rx_size, buf);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Read error");
|
||||
}
|
||||
|
||||
// echo
|
||||
tinyusb_cdcacm_write_queue(itf, buf, rx_size);
|
||||
tinyusb_cdcacm_write_flush(itf, 0);
|
||||
}
|
||||
|
||||
void usb_cdc_line_state_changed_callback(int itf, cdcacm_event_t* event) {
|
||||
int dtr = event->line_state_changed_data.dtr;
|
||||
int rst = event->line_state_changed_data.rts;
|
||||
|
||||
ESP_LOGI(TAG, "Line state changed! dtr:%d, rst:%d", dtr, rst);
|
||||
}
|
||||
|
||||
void usb_cdc_line_coding_changed_callback(int itf, cdcacm_event_t* event) {
|
||||
uint32_t bit_rate = event->line_coding_changed_data.p_line_coding->bit_rate;
|
||||
uint8_t stop_bits = event->line_coding_changed_data.p_line_coding->stop_bits;
|
||||
uint8_t parity = event->line_coding_changed_data.p_line_coding->parity;
|
||||
uint8_t data_bits = event->line_coding_changed_data.p_line_coding->data_bits;
|
||||
|
||||
ESP_LOGI(
|
||||
TAG,
|
||||
"Line coding changed! bit_rate:%d, stop_bits:%d, parity:%d, data_bits:%d",
|
||||
bit_rate,
|
||||
stop_bits,
|
||||
parity,
|
||||
data_bits);
|
||||
}
|
||||
|
||||
void usb_cdc_init(void) {
|
||||
ESP_LOGI(TAG, "USB initialization");
|
||||
tinyusb_config_t tusb_cfg = {};
|
||||
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
|
||||
|
||||
tinyusb_config_cdcacm_t amc_cfg = {
|
||||
.usb_dev = TINYUSB_USBDEV_0,
|
||||
.cdc_port = TINYUSB_CDC_ACM_0,
|
||||
.rx_unread_buf_sz = 64,
|
||||
.callback_rx = &usb_cdc_rx_callback,
|
||||
.callback_rx_wanted_char = NULL,
|
||||
.callback_line_state_changed = &usb_cdc_line_state_changed_callback,
|
||||
.callback_line_coding_changed = &usb_cdc_line_coding_changed_callback};
|
||||
|
||||
ESP_ERROR_CHECK(tusb_cdc_acm_init(&amc_cfg));
|
||||
|
||||
ESP_LOGI(TAG, "USB initialization DONE");
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void usb_cdc_init(void);
|
|
@ -0,0 +1,7 @@
|
|||
#include <esp_log.h>
|
||||
|
||||
static const char* TAG = "wifi";
|
||||
|
||||
void wifi_init(void) {
|
||||
ESP_LOGI(TAG, "Not implemented");
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void wifi_init(void);
|
Loading…
Reference in New Issue