mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
refactor(examples): reformat peripheral examples with astyle_py
This commit is contained in:
parent
1b2484214c
commit
b12e250b2c
@ -41,7 +41,6 @@ static adc_channel_t channel[2] = {ADC_CHANNEL_2, ADC_CHANNEL_3};
|
|||||||
static TaskHandle_t s_task_handle;
|
static TaskHandle_t s_task_handle;
|
||||||
static const char *TAG = "EXAMPLE";
|
static const char *TAG = "EXAMPLE";
|
||||||
|
|
||||||
|
|
||||||
static bool IRAM_ATTR s_conv_done_cb(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data)
|
static bool IRAM_ATTR s_conv_done_cb(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data)
|
||||||
{
|
{
|
||||||
BaseType_t mustYield = pdFALSE;
|
BaseType_t mustYield = pdFALSE;
|
||||||
@ -103,7 +102,7 @@ void app_main(void)
|
|||||||
ESP_ERROR_CHECK(adc_continuous_register_event_callbacks(handle, &cbs, NULL));
|
ESP_ERROR_CHECK(adc_continuous_register_event_callbacks(handle, &cbs, NULL));
|
||||||
ESP_ERROR_CHECK(adc_continuous_start(handle));
|
ESP_ERROR_CHECK(adc_continuous_start(handle));
|
||||||
|
|
||||||
while(1) {
|
while (1) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is to show you the way to use the ADC continuous mode driver event callback.
|
* This is to show you the way to use the ADC continuous mode driver event callback.
|
||||||
|
@ -52,7 +52,6 @@ static int voltage[2][10];
|
|||||||
static bool example_adc_calibration_init(adc_unit_t unit, adc_channel_t channel, adc_atten_t atten, adc_cali_handle_t *out_handle);
|
static bool example_adc_calibration_init(adc_unit_t unit, adc_channel_t channel, adc_atten_t atten, adc_cali_handle_t *out_handle);
|
||||||
static void example_adc_calibration_deinit(adc_cali_handle_t handle);
|
static void example_adc_calibration_deinit(adc_cali_handle_t handle);
|
||||||
|
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
//-------------ADC1 Init---------------//
|
//-------------ADC1 Init---------------//
|
||||||
@ -76,7 +75,6 @@ void app_main(void)
|
|||||||
bool do_calibration1_chan0 = example_adc_calibration_init(ADC_UNIT_1, EXAMPLE_ADC1_CHAN0, EXAMPLE_ADC_ATTEN, &adc1_cali_chan0_handle);
|
bool do_calibration1_chan0 = example_adc_calibration_init(ADC_UNIT_1, EXAMPLE_ADC1_CHAN0, EXAMPLE_ADC_ATTEN, &adc1_cali_chan0_handle);
|
||||||
bool do_calibration1_chan1 = example_adc_calibration_init(ADC_UNIT_1, EXAMPLE_ADC1_CHAN1, EXAMPLE_ADC_ATTEN, &adc1_cali_chan1_handle);
|
bool do_calibration1_chan1 = example_adc_calibration_init(ADC_UNIT_1, EXAMPLE_ADC1_CHAN1, EXAMPLE_ADC_ATTEN, &adc1_cali_chan1_handle);
|
||||||
|
|
||||||
|
|
||||||
#if EXAMPLE_USE_ADC2
|
#if EXAMPLE_USE_ADC2
|
||||||
//-------------ADC2 Init---------------//
|
//-------------ADC2 Init---------------//
|
||||||
adc_oneshot_unit_handle_t adc2_handle;
|
adc_oneshot_unit_handle_t adc2_handle;
|
||||||
@ -139,7 +137,6 @@ void app_main(void)
|
|||||||
#endif //#if EXAMPLE_USE_ADC2
|
#endif //#if EXAMPLE_USE_ADC2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------
|
/*---------------------------------------------------------------
|
||||||
ADC Calibration
|
ADC Calibration
|
||||||
---------------------------------------------------------------*/
|
---------------------------------------------------------------*/
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
static const char *TAG = "ana_cmpr_example";
|
static const char *TAG = "ana_cmpr_example";
|
||||||
|
|
||||||
static bool example_ana_cmpr_on_cross_callback(ana_cmpr_handle_t cmpr,
|
static bool example_ana_cmpr_on_cross_callback(ana_cmpr_handle_t cmpr,
|
||||||
const ana_cmpr_cross_event_data_t *edata,
|
const ana_cmpr_cross_event_data_t *edata,
|
||||||
void *user_ctx)
|
void *user_ctx)
|
||||||
{
|
{
|
||||||
#if CONFIG_EXAMPLE_HYSTERESIS_COMPARATOR
|
#if CONFIG_EXAMPLE_HYSTERESIS_COMPARATOR
|
||||||
static ana_cmpr_internal_ref_config_t ref_cfg = {
|
static ana_cmpr_internal_ref_config_t ref_cfg = {
|
||||||
@ -70,7 +70,7 @@ void example_init_analog_comparator_intr(void)
|
|||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(ana_cmpr_set_internal_reference(cmpr, &ref_cfg));
|
ESP_ERROR_CHECK(ana_cmpr_set_internal_reference(cmpr, &ref_cfg));
|
||||||
#else
|
#else
|
||||||
/* Step 1: Allocate the new analog comparator unit */
|
/* Step 1: Allocate the new analog comparator unit */
|
||||||
ana_cmpr_config_t config = {
|
ana_cmpr_config_t config = {
|
||||||
.unit = EXAMPLE_ANA_CMPR_UNIT,
|
.unit = EXAMPLE_ANA_CMPR_UNIT,
|
||||||
.clk_src = ANA_CMPR_CLK_SRC_DEFAULT,
|
.clk_src = ANA_CMPR_CLK_SRC_DEFAULT,
|
||||||
|
@ -43,7 +43,7 @@ static void dac_write_data_asynchronously(dac_continuous_handle_t handle, QueueH
|
|||||||
xQueueReceive(que, &evt_data, portMAX_DELAY);
|
xQueueReceive(que, &evt_data, portMAX_DELAY);
|
||||||
size_t loaded_bytes = 0;
|
size_t loaded_bytes = 0;
|
||||||
ESP_ERROR_CHECK(dac_continuous_write_asynchronously(handle, evt_data.buf, evt_data.buf_size,
|
ESP_ERROR_CHECK(dac_continuous_write_asynchronously(handle, evt_data.buf, evt_data.buf_size,
|
||||||
data + byte_written, data_size - byte_written, &loaded_bytes));
|
data + byte_written, data_size - byte_written, &loaded_bytes));
|
||||||
byte_written += loaded_bytes;
|
byte_written += loaded_bytes;
|
||||||
}
|
}
|
||||||
/* Clear the legacy data in DMA, clear times equal to the 'dac_continuous_config_t::desc_num' */
|
/* Clear the legacy data in DMA, clear times equal to the 'dac_continuous_config_t::desc_num' */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -32,20 +32,20 @@ static void dac_dma_write_task(void *args)
|
|||||||
while (1) {
|
while (1) {
|
||||||
/* The wave in the buffer will be converted cyclically */
|
/* The wave in the buffer will be converted cyclically */
|
||||||
switch (wav_sel) {
|
switch (wav_sel) {
|
||||||
case DAC_SINE_WAVE:
|
case DAC_SINE_WAVE:
|
||||||
ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)sin_wav, buf_len, NULL));
|
ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)sin_wav, buf_len, NULL));
|
||||||
break;
|
break;
|
||||||
case DAC_TRIANGLE_WAVE:
|
case DAC_TRIANGLE_WAVE:
|
||||||
ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)tri_wav, buf_len, NULL));
|
ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)tri_wav, buf_len, NULL));
|
||||||
break;
|
break;
|
||||||
case DAC_SAWTOOTH_WAVE:
|
case DAC_SAWTOOTH_WAVE:
|
||||||
ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)saw_wav, buf_len, NULL));
|
ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)saw_wav, buf_len, NULL));
|
||||||
break;
|
break;
|
||||||
case DAC_SQUARE_WAVE:
|
case DAC_SQUARE_WAVE:
|
||||||
ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)squ_wav, buf_len, NULL));
|
ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)squ_wav, buf_len, NULL));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Switch wave every CONFIG_EXAMPLE_WAVE_PERIOD_SEC seconds */
|
/* Switch wave every CONFIG_EXAMPLE_WAVE_PERIOD_SEC seconds */
|
||||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_EXAMPLE_WAVE_PERIOD_SEC * 1000));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_EXAMPLE_WAVE_PERIOD_SEC * 1000));
|
||||||
|
@ -54,7 +54,7 @@ static void example_generate_wave(void)
|
|||||||
uint32_t pnt_num = EXAMPLE_ARRAY_LEN;
|
uint32_t pnt_num = EXAMPLE_ARRAY_LEN;
|
||||||
|
|
||||||
for (int i = 0; i < pnt_num; i ++) {
|
for (int i = 0; i < pnt_num; i ++) {
|
||||||
sin_wav[i] = (uint8_t)((sin( i * CONST_PERIOD_2_PI / pnt_num) + 1) * (double)(EXAMPLE_DAC_AMPLITUDE) / 2 + 0.5);
|
sin_wav[i] = (uint8_t)((sin(i * CONST_PERIOD_2_PI / pnt_num) + 1) * (double)(EXAMPLE_DAC_AMPLITUDE) / 2 + 0.5);
|
||||||
tri_wav[i] = (i > (pnt_num / 2)) ? (2 * EXAMPLE_DAC_AMPLITUDE * (pnt_num - i) / pnt_num) : (2 * EXAMPLE_DAC_AMPLITUDE * i / pnt_num);
|
tri_wav[i] = (i > (pnt_num / 2)) ? (2 * EXAMPLE_DAC_AMPLITUDE * (pnt_num - i) / pnt_num) : (2 * EXAMPLE_DAC_AMPLITUDE * i / pnt_num);
|
||||||
saw_wav[i] = (i == pnt_num) ? 0 : (i * EXAMPLE_DAC_AMPLITUDE / pnt_num);
|
saw_wav[i] = (i == pnt_num) ? 0 : (i * EXAMPLE_DAC_AMPLITUDE / pnt_num);
|
||||||
squ_wav[i] = (i < (pnt_num / 2)) ? EXAMPLE_DAC_AMPLITUDE : 0;
|
squ_wav[i] = (i < (pnt_num / 2)) ? EXAMPLE_DAC_AMPLITUDE : 0;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -42,24 +42,24 @@ static bool IRAM_ATTR on_timer_alarm_cb(gptimer_handle_t timer, const gptimer_al
|
|||||||
// Switch wave every CONFIG_EXAMPLE_WAVE_PERIOD_SEC second
|
// Switch wave every CONFIG_EXAMPLE_WAVE_PERIOD_SEC second
|
||||||
if (point_cnt < EXAMPLE_CONVERT_FREQ_HZ * CONFIG_EXAMPLE_WAVE_PERIOD_SEC) {
|
if (point_cnt < EXAMPLE_CONVERT_FREQ_HZ * CONFIG_EXAMPLE_WAVE_PERIOD_SEC) {
|
||||||
switch (wav_sel) {
|
switch (wav_sel) {
|
||||||
case DAC_SINE_WAVE:
|
case DAC_SINE_WAVE:
|
||||||
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, sin_wav[index]));
|
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, sin_wav[index]));
|
||||||
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, sin_wav[index]));
|
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, sin_wav[index]));
|
||||||
break;
|
break;
|
||||||
case DAC_TRIANGLE_WAVE:
|
case DAC_TRIANGLE_WAVE:
|
||||||
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, tri_wav[index]));
|
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, tri_wav[index]));
|
||||||
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, tri_wav[index]));
|
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, tri_wav[index]));
|
||||||
break;
|
break;
|
||||||
case DAC_SAWTOOTH_WAVE:
|
case DAC_SAWTOOTH_WAVE:
|
||||||
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, saw_wav[index]));
|
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, saw_wav[index]));
|
||||||
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, saw_wav[index]));
|
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, saw_wav[index]));
|
||||||
break;
|
break;
|
||||||
case DAC_SQUARE_WAVE:
|
case DAC_SQUARE_WAVE:
|
||||||
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, squ_wav[index]));
|
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, squ_wav[index]));
|
||||||
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, squ_wav[index]));
|
ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, squ_wav[index]));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
point_cnt++;
|
point_cnt++;
|
||||||
index++;
|
index++;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -23,7 +23,6 @@ typedef enum {
|
|||||||
SOFT_I2C_FREQ_END
|
SOFT_I2C_FREQ_END
|
||||||
} soft_i2c_master_freq_t;
|
} soft_i2c_master_freq_t;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Structure defining the configuration for the software I2C master bus
|
* @brief Structure defining the configuration for the software I2C master bus
|
||||||
*/
|
*/
|
||||||
@ -33,13 +32,11 @@ typedef struct {
|
|||||||
soft_i2c_master_freq_t freq;
|
soft_i2c_master_freq_t freq;
|
||||||
} soft_i2c_master_config_t;
|
} soft_i2c_master_config_t;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Abstract type representing a software I2C bus.
|
* @brief Abstract type representing a software I2C bus.
|
||||||
*/
|
*/
|
||||||
typedef struct i2c_master_bus_impl_t* soft_i2c_master_bus_t;
|
typedef struct i2c_master_bus_impl_t* soft_i2c_master_bus_t;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create and configure the software I2C bus.
|
* @brief Create and configure the software I2C bus.
|
||||||
*
|
*
|
||||||
@ -50,7 +47,6 @@ typedef struct i2c_master_bus_impl_t* soft_i2c_master_bus_t;
|
|||||||
*/
|
*/
|
||||||
esp_err_t soft_i2c_master_new(soft_i2c_master_config_t *config, soft_i2c_master_bus_t *bus);
|
esp_err_t soft_i2c_master_new(soft_i2c_master_config_t *config, soft_i2c_master_bus_t *bus);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Delete a previously initialized I2C software bus.
|
* @brief Delete a previously initialized I2C software bus.
|
||||||
*
|
*
|
||||||
@ -60,7 +56,6 @@ esp_err_t soft_i2c_master_new(soft_i2c_master_config_t *config, soft_i2c_master_
|
|||||||
*/
|
*/
|
||||||
esp_err_t soft_i2c_master_del(soft_i2c_master_bus_t bus);
|
esp_err_t soft_i2c_master_del(soft_i2c_master_bus_t bus);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Perform a write to the given device on the software I2C bus.
|
* @brief Perform a write to the given device on the software I2C bus.
|
||||||
*
|
*
|
||||||
@ -75,7 +70,6 @@ esp_err_t soft_i2c_master_write(soft_i2c_master_bus_t bus,
|
|||||||
uint8_t device_address,
|
uint8_t device_address,
|
||||||
const uint8_t* write_buffer, size_t write_size);
|
const uint8_t* write_buffer, size_t write_size);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Perform a read from the given device on the software I2C bus.
|
* @brief Perform a read from the given device on the software I2C bus.
|
||||||
*
|
*
|
||||||
@ -90,7 +84,6 @@ esp_err_t soft_i2c_master_read(soft_i2c_master_bus_t bus,
|
|||||||
uint8_t device_address,
|
uint8_t device_address,
|
||||||
uint8_t* read_buffer, size_t read_size);
|
uint8_t* read_buffer, size_t read_size);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Perform a write followed by a read to the given device on the software I2C bus.
|
* @brief Perform a write followed by a read to the given device on the software I2C bus.
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -24,10 +24,9 @@
|
|||||||
/* Forward declaration of static functions */
|
/* Forward declaration of static functions */
|
||||||
static uint32_t freq_to_delay(soft_i2c_master_freq_t freq);
|
static uint32_t freq_to_delay(soft_i2c_master_freq_t freq);
|
||||||
static esp_err_t emulate_i2c_transfer(uint8_t device_address,
|
static esp_err_t emulate_i2c_transfer(uint8_t device_address,
|
||||||
const uint8_t* write_buffer, uint32_t write_size,
|
const uint8_t* write_buffer, uint32_t write_size,
|
||||||
uint8_t* read_buffer, uint32_t read_size,
|
uint8_t* read_buffer, uint32_t read_size,
|
||||||
soft_i2c_master_bus_t bus);
|
soft_i2c_master_bus_t bus);
|
||||||
|
|
||||||
|
|
||||||
/* Mutex required to enter critical sections */
|
/* Mutex required to enter critical sections */
|
||||||
static portMUX_TYPE g_lock = portMUX_INITIALIZER_UNLOCKED;
|
static portMUX_TYPE g_lock = portMUX_INITIALIZER_UNLOCKED;
|
||||||
@ -42,7 +41,6 @@ struct i2c_master_bus_impl_t {
|
|||||||
dedic_gpio_bundle_handle_t bundle;
|
dedic_gpio_bundle_handle_t bundle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
esp_err_t soft_i2c_master_new(soft_i2c_master_config_t *config, soft_i2c_master_bus_t *bus)
|
esp_err_t soft_i2c_master_new(soft_i2c_master_config_t *config, soft_i2c_master_bus_t *bus)
|
||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
@ -103,7 +101,6 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esp_err_t soft_i2c_master_del(soft_i2c_master_bus_t bus)
|
esp_err_t soft_i2c_master_del(soft_i2c_master_bus_t bus)
|
||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
@ -117,7 +114,6 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esp_err_t soft_i2c_master_write(soft_i2c_master_bus_t bus,
|
esp_err_t soft_i2c_master_write(soft_i2c_master_bus_t bus,
|
||||||
uint8_t device_address,
|
uint8_t device_address,
|
||||||
const uint8_t* write_buffer, size_t write_size)
|
const uint8_t* write_buffer, size_t write_size)
|
||||||
@ -159,7 +155,6 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esp_err_t soft_i2c_master_write_read(soft_i2c_master_bus_t bus,
|
esp_err_t soft_i2c_master_write_read(soft_i2c_master_bus_t bus,
|
||||||
uint8_t device_address,
|
uint8_t device_address,
|
||||||
const uint8_t* write_buffer, size_t write_size,
|
const uint8_t* write_buffer, size_t write_size,
|
||||||
@ -184,18 +179,17 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***** Private implementation *****/
|
/***** Private implementation *****/
|
||||||
|
|
||||||
static uint32_t freq_to_delay(soft_i2c_master_freq_t freq)
|
static uint32_t freq_to_delay(soft_i2c_master_freq_t freq)
|
||||||
{
|
{
|
||||||
switch(freq) {
|
switch (freq) {
|
||||||
case SOFT_I2C_100KHZ: return 3;
|
case SOFT_I2C_100KHZ: return 3;
|
||||||
case SOFT_I2C_200KHZ: return 2;
|
case SOFT_I2C_200KHZ: return 2;
|
||||||
case SOFT_I2C_300KHZ: return 1;
|
case SOFT_I2C_300KHZ: return 1;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +226,6 @@ static inline void emulate_start(soft_i2c_master_bus_t bus)
|
|||||||
set_sda(bidir_bundle, 0, delay);
|
set_sda(bidir_bundle, 0, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void emulate_stop(soft_i2c_master_bus_t bus)
|
static inline void emulate_stop(soft_i2c_master_bus_t bus)
|
||||||
{
|
{
|
||||||
dedic_gpio_bundle_handle_t bidir_bundle = bus->bundle;
|
dedic_gpio_bundle_handle_t bidir_bundle = bus->bundle;
|
||||||
@ -287,8 +280,7 @@ static inline uint8_t emulate_read_byte(soft_i2c_master_bus_t bus, int send_ack)
|
|||||||
set_scl(bidir_bundle, 0, delay);
|
set_scl(bidir_bundle, 0, delay);
|
||||||
set_sda(bidir_bundle, 1, delay);
|
set_sda(bidir_bundle, 1, delay);
|
||||||
|
|
||||||
for (int i = 7; i >= 0; i--)
|
for (int i = 7; i >= 0; i--) {
|
||||||
{
|
|
||||||
/* Set SCL to low */
|
/* Set SCL to low */
|
||||||
set_scl(bidir_bundle, 0, delay);
|
set_scl(bidir_bundle, 0, delay);
|
||||||
/* Get SDA value now and store it in the final result */
|
/* Get SDA value now and store it in the final result */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -23,13 +23,11 @@ typedef struct {
|
|||||||
uint32_t cs_pin;
|
uint32_t cs_pin;
|
||||||
} soft_spi_config_t;
|
} soft_spi_config_t;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Abstract type representing a software SPI bus.
|
* @brief Abstract type representing a software SPI bus.
|
||||||
*/
|
*/
|
||||||
typedef struct soft_spi_bus_impl_t* soft_spi_bus_t;
|
typedef struct soft_spi_bus_impl_t* soft_spi_bus_t;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create and configure the software SPI bus.
|
* @brief Create and configure the software SPI bus.
|
||||||
*
|
*
|
||||||
@ -40,7 +38,6 @@ typedef struct soft_spi_bus_impl_t* soft_spi_bus_t;
|
|||||||
*/
|
*/
|
||||||
esp_err_t soft_spi_new(soft_spi_config_t *config, soft_spi_bus_t *bus);
|
esp_err_t soft_spi_new(soft_spi_config_t *config, soft_spi_bus_t *bus);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Delete a previously initialized software SPI bus.
|
* @brief Delete a previously initialized software SPI bus.
|
||||||
*
|
*
|
||||||
@ -50,7 +47,6 @@ esp_err_t soft_spi_new(soft_spi_config_t *config, soft_spi_bus_t *bus);
|
|||||||
*/
|
*/
|
||||||
esp_err_t soft_spi_del(soft_spi_bus_t bus);
|
esp_err_t soft_spi_del(soft_spi_bus_t bus);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send the given bytes on the software SPI bus.
|
* @brief Send the given bytes on the software SPI bus.
|
||||||
*
|
*
|
||||||
@ -65,7 +61,6 @@ esp_err_t soft_spi_transfer(soft_spi_bus_t bus,
|
|||||||
const uint8_t* write_buffer, uint8_t* read_buffer,
|
const uint8_t* write_buffer, uint8_t* read_buffer,
|
||||||
size_t buf_size);
|
size_t buf_size);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -31,7 +31,6 @@ static portMUX_TYPE g_lock = portMUX_INITIALIZER_UNLOCKED;
|
|||||||
|
|
||||||
const char* __attribute__((used)) SOFT_SPI_TAG = "soft_spi";
|
const char* __attribute__((used)) SOFT_SPI_TAG = "soft_spi";
|
||||||
|
|
||||||
|
|
||||||
struct soft_spi_bus_impl_t {
|
struct soft_spi_bus_impl_t {
|
||||||
uint32_t clk_bit;
|
uint32_t clk_bit;
|
||||||
uint32_t mosi_bit;
|
uint32_t mosi_bit;
|
||||||
@ -41,7 +40,6 @@ struct soft_spi_bus_impl_t {
|
|||||||
dedic_gpio_bundle_handle_t in_bundle;
|
dedic_gpio_bundle_handle_t in_bundle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
esp_err_t soft_spi_new(soft_spi_config_t *config, soft_spi_bus_t *bus)
|
esp_err_t soft_spi_new(soft_spi_config_t *config, soft_spi_bus_t *bus)
|
||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
@ -121,7 +119,6 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esp_err_t soft_spi_del(soft_spi_bus_t bus)
|
esp_err_t soft_spi_del(soft_spi_bus_t bus)
|
||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
@ -135,7 +132,6 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esp_err_t soft_spi_transfer(soft_spi_bus_t bus, const uint8_t* write_buffer, uint8_t* read_buffer, size_t buf_size)
|
esp_err_t soft_spi_transfer(soft_spi_bus_t bus, const uint8_t* write_buffer, uint8_t* read_buffer, size_t buf_size)
|
||||||
{
|
{
|
||||||
esp_err_t ret = ESP_OK;
|
esp_err_t ret = ESP_OK;
|
||||||
@ -145,9 +141,9 @@ esp_err_t soft_spi_transfer(soft_spi_bus_t bus, const uint8_t* write_buffer, uin
|
|||||||
|
|
||||||
portENTER_CRITICAL(&g_lock);
|
portENTER_CRITICAL(&g_lock);
|
||||||
asm_emulate_spi_shift_byte(write_buffer, read_buffer, buf_size,
|
asm_emulate_spi_shift_byte(write_buffer, read_buffer, buf_size,
|
||||||
/* Provide the offset in special dedicated GPIO register for Clock, MOSI and Clock
|
/* Provide the offset in special dedicated GPIO register for Clock, MOSI and Clock
|
||||||
* respectively */
|
* respectively */
|
||||||
bus->clk_bit, bus->mosi_bit, bus->cs_bit, bus->miso_bit);
|
bus->clk_bit, bus->mosi_bit, bus->cs_bit, bus->miso_bit);
|
||||||
portEXIT_CRITICAL(&g_lock);
|
portEXIT_CRITICAL(&g_lock);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -24,7 +24,6 @@ typedef enum {
|
|||||||
SOFT_UART_BAUD_END
|
SOFT_UART_BAUD_END
|
||||||
} soft_uart_baudrate_t;
|
} soft_uart_baudrate_t;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Structure defining the configuration for the software UART port
|
* @brief Structure defining the configuration for the software UART port
|
||||||
*/
|
*/
|
||||||
@ -34,13 +33,11 @@ typedef struct {
|
|||||||
soft_uart_baudrate_t baudrate;
|
soft_uart_baudrate_t baudrate;
|
||||||
} soft_uart_config_t;
|
} soft_uart_config_t;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Abstract type representing a software UART port.
|
* @brief Abstract type representing a software UART port.
|
||||||
*/
|
*/
|
||||||
typedef struct soft_uart_port_impl_t* soft_uart_port_t;
|
typedef struct soft_uart_port_impl_t* soft_uart_port_t;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create and configure the software UART port.
|
* @brief Create and configure the software UART port.
|
||||||
*
|
*
|
||||||
@ -51,7 +48,6 @@ typedef struct soft_uart_port_impl_t* soft_uart_port_t;
|
|||||||
*/
|
*/
|
||||||
esp_err_t soft_uart_new(soft_uart_config_t *config, soft_uart_port_t *port);
|
esp_err_t soft_uart_new(soft_uart_config_t *config, soft_uart_port_t *port);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Delete a previously initialized software UART port.
|
* @brief Delete a previously initialized software UART port.
|
||||||
*
|
*
|
||||||
@ -61,7 +57,6 @@ esp_err_t soft_uart_new(soft_uart_config_t *config, soft_uart_port_t *port);
|
|||||||
*/
|
*/
|
||||||
esp_err_t soft_uart_del(soft_uart_port_t port);
|
esp_err_t soft_uart_del(soft_uart_port_t port);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send the given bytes on the software UART port.
|
* @brief Send the given bytes on the software UART port.
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -33,7 +33,6 @@ struct soft_uart_port_impl_t {
|
|||||||
dedic_gpio_bundle_handle_t rx_bundle;
|
dedic_gpio_bundle_handle_t rx_bundle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
esp_err_t soft_uart_new(soft_uart_config_t *config, soft_uart_port_t *port)
|
esp_err_t soft_uart_new(soft_uart_config_t *config, soft_uart_port_t *port)
|
||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
@ -82,7 +81,6 @@ esp_err_t soft_uart_new(soft_uart_config_t *config, soft_uart_port_t *port)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Allocate the master port structure now that we need it */
|
/* Allocate the master port structure now that we need it */
|
||||||
port_impl = malloc(sizeof(struct soft_uart_port_impl_t));
|
port_impl = malloc(sizeof(struct soft_uart_port_impl_t));
|
||||||
ESP_GOTO_ON_FALSE(port_impl != NULL, ESP_ERR_NO_MEM, error, SOFT_UART_TAG, "No more memory available in the system");
|
ESP_GOTO_ON_FALSE(port_impl != NULL, ESP_ERR_NO_MEM, error, SOFT_UART_TAG, "No more memory available in the system");
|
||||||
@ -118,7 +116,6 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esp_err_t soft_uart_del(soft_uart_port_t port)
|
esp_err_t soft_uart_del(soft_uart_port_t port)
|
||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
@ -132,7 +129,6 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esp_err_t soft_uart_send(soft_uart_port_t port, const uint8_t* write_buffer, size_t write_size)
|
esp_err_t soft_uart_send(soft_uart_port_t port, const uint8_t* write_buffer, size_t write_size)
|
||||||
{
|
{
|
||||||
esp_err_t ret = ESP_OK;
|
esp_err_t ret = ESP_OK;
|
||||||
@ -172,17 +168,17 @@ static uint32_t baudrate_to_cycles(soft_uart_baudrate_t baudrate)
|
|||||||
* For each delay, subtract a small amount of clock cycles which compensate for the instructions
|
* For each delay, subtract a small amount of clock cycles which compensate for the instructions
|
||||||
* used to prepare the next bits (loop, shifts, logic...).
|
* used to prepare the next bits (loop, shifts, logic...).
|
||||||
*/
|
*/
|
||||||
switch(baudrate) {
|
switch (baudrate) {
|
||||||
case SOFT_UART_115200: // 115200, 8.63us per bit
|
case SOFT_UART_115200: // 115200, 8.63us per bit
|
||||||
return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 863)/100 - 20);
|
return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 863) / 100 - 20);
|
||||||
case SOFT_UART_230400: // 4.34us per bit
|
case SOFT_UART_230400: // 4.34us per bit
|
||||||
return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 434)/100 - 24);
|
return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 434) / 100 - 24);
|
||||||
case SOFT_UART_460800: // 2.17us per bit
|
case SOFT_UART_460800: // 2.17us per bit
|
||||||
return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 217)/100 - 20);
|
return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 217) / 100 - 20);
|
||||||
case SOFT_UART_921600: // 1.085us per bit
|
case SOFT_UART_921600: // 1.085us per bit
|
||||||
return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 108)/100 - 23);
|
return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 108) / 100 - 23);
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,8 @@ static void IRAM_ATTR gpio_isr_handler(void* arg)
|
|||||||
static void gpio_task_example(void* arg)
|
static void gpio_task_example(void* arg)
|
||||||
{
|
{
|
||||||
uint32_t io_num;
|
uint32_t io_num;
|
||||||
for(;;) {
|
for (;;) {
|
||||||
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
|
if (xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
|
||||||
printf("GPIO[%"PRIu32"] intr, val: %d\n", io_num, gpio_get_level(io_num));
|
printf("GPIO[%"PRIu32"] intr, val: %d\n", io_num, gpio_get_level(io_num));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ void app_main(void)
|
|||||||
printf("Minimum free heap size: %"PRIu32" bytes\n", esp_get_minimum_free_heap_size());
|
printf("Minimum free heap size: %"PRIu32" bytes\n", esp_get_minimum_free_heap_size());
|
||||||
|
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
while(1) {
|
while (1) {
|
||||||
printf("cnt: %d\n", cnt++);
|
printf("cnt: %d\n", cnt++);
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
gpio_set_level(GPIO_OUTPUT_IO_0, cnt % 2);
|
gpio_set_level(GPIO_OUTPUT_IO_0, cnt % 2);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -86,7 +86,7 @@ static void matrix_kbd_debounce_timer_callback(TimerHandle_t xTimer)
|
|||||||
// col lines set to low level
|
// col lines set to low level
|
||||||
dedic_gpio_bundle_write(mkbd->col_bundle, (1 << mkbd->nr_col_gpios) - 1, 0);
|
dedic_gpio_bundle_write(mkbd->col_bundle, (1 << mkbd->nr_col_gpios) - 1, 0);
|
||||||
dedic_gpio_bundle_set_interrupt_and_callback(mkbd->row_bundle, (1 << mkbd->nr_row_gpios) - 1,
|
dedic_gpio_bundle_set_interrupt_and_callback(mkbd->row_bundle, (1 << mkbd->nr_row_gpios) - 1,
|
||||||
DEDIC_GPIO_INTR_BOTH_EDGE, matrix_kbd_row_isr_callback, mkbd);
|
DEDIC_GPIO_INTR_BOTH_EDGE, matrix_kbd_row_isr_callback, mkbd);
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t matrix_kbd_install(const matrix_kbd_config_t *config, matrix_kbd_handle_t *mkbd_handle)
|
esp_err_t matrix_kbd_install(const matrix_kbd_config_t *config, matrix_kbd_handle_t *mkbd_handle)
|
||||||
@ -145,9 +145,9 @@ esp_err_t matrix_kbd_install(const matrix_kbd_config_t *config, matrix_kbd_handl
|
|||||||
|
|
||||||
// Disable interrupt
|
// Disable interrupt
|
||||||
dedic_gpio_bundle_set_interrupt_and_callback(mkbd->row_bundle, (1 << config->nr_row_gpios) - 1,
|
dedic_gpio_bundle_set_interrupt_and_callback(mkbd->row_bundle, (1 << config->nr_row_gpios) - 1,
|
||||||
DEDIC_GPIO_INTR_NONE, NULL, NULL);
|
DEDIC_GPIO_INTR_NONE, NULL, NULL);
|
||||||
dedic_gpio_bundle_set_interrupt_and_callback(mkbd->col_bundle, (1 << config->nr_col_gpios) - 1,
|
dedic_gpio_bundle_set_interrupt_and_callback(mkbd->col_bundle, (1 << config->nr_col_gpios) - 1,
|
||||||
DEDIC_GPIO_INTR_NONE, NULL, NULL);
|
DEDIC_GPIO_INTR_NONE, NULL, NULL);
|
||||||
|
|
||||||
// Create a ont-shot os timer, used for key debounce
|
// Create a ont-shot os timer, used for key debounce
|
||||||
mkbd->debounce_timer = xTimerCreate("kb_debounce", pdMS_TO_TICKS(config->debounce_ms), pdFALSE, mkbd, matrix_kbd_debounce_timer_callback);
|
mkbd->debounce_timer = xTimerCreate("kb_debounce", pdMS_TO_TICKS(config->debounce_ms), pdFALSE, mkbd, matrix_kbd_debounce_timer_callback);
|
||||||
@ -200,7 +200,7 @@ esp_err_t matrix_kbd_start(matrix_kbd_handle_t mkbd_handle)
|
|||||||
|
|
||||||
// only enable row line interrupt
|
// only enable row line interrupt
|
||||||
dedic_gpio_bundle_set_interrupt_and_callback(mkbd_handle->row_bundle, (1 << mkbd_handle->nr_row_gpios) - 1,
|
dedic_gpio_bundle_set_interrupt_and_callback(mkbd_handle->row_bundle, (1 << mkbd_handle->nr_row_gpios) - 1,
|
||||||
DEDIC_GPIO_INTR_BOTH_EDGE, matrix_kbd_row_isr_callback, mkbd_handle);
|
DEDIC_GPIO_INTR_BOTH_EDGE, matrix_kbd_row_isr_callback, mkbd_handle);
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
err:
|
err:
|
||||||
@ -216,9 +216,9 @@ esp_err_t matrix_kbd_stop(matrix_kbd_handle_t mkbd_handle)
|
|||||||
|
|
||||||
// Disable interrupt
|
// Disable interrupt
|
||||||
dedic_gpio_bundle_set_interrupt_and_callback(mkbd_handle->row_bundle, (1 << mkbd_handle->nr_row_gpios) - 1,
|
dedic_gpio_bundle_set_interrupt_and_callback(mkbd_handle->row_bundle, (1 << mkbd_handle->nr_row_gpios) - 1,
|
||||||
DEDIC_GPIO_INTR_NONE, NULL, NULL);
|
DEDIC_GPIO_INTR_NONE, NULL, NULL);
|
||||||
dedic_gpio_bundle_set_interrupt_and_callback(mkbd_handle->col_bundle, (1 << mkbd_handle->nr_col_gpios) - 1,
|
dedic_gpio_bundle_set_interrupt_and_callback(mkbd_handle->col_bundle, (1 << mkbd_handle->nr_col_gpios) - 1,
|
||||||
DEDIC_GPIO_INTR_NONE, NULL, NULL);
|
DEDIC_GPIO_INTR_NONE, NULL, NULL);
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
err:
|
err:
|
||||||
|
@ -23,7 +23,7 @@ static void disp_buf(uint8_t *buf, int len)
|
|||||||
int i;
|
int i;
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
printf("%02x ", buf[i]);
|
printf("%02x ", buf[i]);
|
||||||
if (( i + 1 ) % 16 == 0) {
|
if ((i + 1) % 16 == 0) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ void app_main(void)
|
|||||||
uint8_t read_buf[LENGTH];
|
uint8_t read_buf[LENGTH];
|
||||||
ESP_ERROR_CHECK(i2c_eeprom_init(bus_handle, &eeprom_config, &eeprom_handle));
|
ESP_ERROR_CHECK(i2c_eeprom_init(bus_handle, &eeprom_config, &eeprom_handle));
|
||||||
|
|
||||||
while(1) {
|
while (1) {
|
||||||
ESP_ERROR_CHECK(i2c_eeprom_write(eeprom_handle, block_addr, buf, LENGTH));
|
ESP_ERROR_CHECK(i2c_eeprom_write(eeprom_handle, block_addr, buf, LENGTH));
|
||||||
// Needs wait for eeprom hardware done, referring from datasheet
|
// Needs wait for eeprom hardware done, referring from datasheet
|
||||||
i2c_eeprom_wait_idle(eeprom_handle);
|
i2c_eeprom_wait_idle(eeprom_handle);
|
||||||
|
@ -31,12 +31,12 @@ static const char *TAG = "i2c-example";
|
|||||||
#define DELAY_TIME_BETWEEN_ITEMS_MS 1000 /*!< delay time between different test items */
|
#define DELAY_TIME_BETWEEN_ITEMS_MS 1000 /*!< delay time between different test items */
|
||||||
|
|
||||||
#if SOC_I2C_NUM > 1
|
#if SOC_I2C_NUM > 1
|
||||||
#define I2C_SLAVE_SCL_IO CONFIG_I2C_SLAVE_SCL /*!< gpio number for i2c slave clock */
|
#define I2C_SLAVE_SCL_IO CONFIG_I2C_SLAVE_SCL /*!< gpio number for i2c slave clock */
|
||||||
#define I2C_SLAVE_SDA_IO CONFIG_I2C_SLAVE_SDA /*!< gpio number for i2c slave data */
|
#define I2C_SLAVE_SDA_IO CONFIG_I2C_SLAVE_SDA /*!< gpio number for i2c slave data */
|
||||||
#define I2C_SLAVE_NUM I2C_NUMBER(CONFIG_I2C_SLAVE_PORT_NUM) /*!< I2C port number for slave dev */
|
#define I2C_SLAVE_NUM I2C_NUMBER(CONFIG_I2C_SLAVE_PORT_NUM) /*!< I2C port number for slave dev */
|
||||||
#define I2C_SLAVE_TX_BUF_LEN (2 * DATA_LENGTH) /*!< I2C slave tx buffer size */
|
#define I2C_SLAVE_TX_BUF_LEN (2 * DATA_LENGTH) /*!< I2C slave tx buffer size */
|
||||||
#define I2C_SLAVE_RX_BUF_LEN (2 * DATA_LENGTH) /*!< I2C slave rx buffer size */
|
#define I2C_SLAVE_RX_BUF_LEN (2 * DATA_LENGTH) /*!< I2C slave rx buffer size */
|
||||||
#define ESP_SLAVE_ADDR CONFIG_I2C_SLAVE_ADDRESS /*!< ESP32 slave address, you can set any 7bit value */
|
#define ESP_SLAVE_ADDR CONFIG_I2C_SLAVE_ADDRESS /*!< ESP32 slave address, you can set any 7bit value */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL /*!< gpio number for I2C master clock */
|
#define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL /*!< gpio number for I2C master clock */
|
||||||
@ -280,7 +280,7 @@ static void i2c_test_task(void *arg)
|
|||||||
ret = i2c_master_write_slave(I2C_MASTER_NUM, data_wr, RW_TEST_LENGTH);
|
ret = i2c_master_write_slave(I2C_MASTER_NUM, data_wr, RW_TEST_LENGTH);
|
||||||
if (ret == ESP_OK) {
|
if (ret == ESP_OK) {
|
||||||
size = i2c_slave_read_buffer(I2C_SLAVE_NUM, data, RW_TEST_LENGTH, 1000 / portTICK_PERIOD_MS);
|
size = i2c_slave_read_buffer(I2C_SLAVE_NUM, data, RW_TEST_LENGTH, 1000 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
if (ret == ESP_ERR_TIMEOUT) {
|
if (ret == ESP_ERR_TIMEOUT) {
|
||||||
ESP_LOGE(TAG, "I2C Timeout");
|
ESP_LOGE(TAG, "I2C Timeout");
|
||||||
} else if (ret == ESP_OK) {
|
} else if (ret == ESP_OK) {
|
||||||
|
@ -78,7 +78,6 @@ static esp_err_t i2c_master_init(void)
|
|||||||
return i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
|
return i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
uint8_t data[2];
|
uint8_t data[2];
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#define EXAMPLE_PDM_RX_FREQ_HZ 16000 // I2S PDM RX frequency
|
#define EXAMPLE_PDM_RX_FREQ_HZ 16000 // I2S PDM RX frequency
|
||||||
|
|
||||||
|
|
||||||
static i2s_chan_handle_t i2s_example_init_pdm_rx(void)
|
static i2s_chan_handle_t i2s_example_init_pdm_rx(void)
|
||||||
{
|
{
|
||||||
i2s_chan_handle_t rx_chan; // I2S rx channel handler
|
i2s_chan_handle_t rx_chan; // I2S rx channel handler
|
||||||
@ -72,7 +71,6 @@ static i2s_chan_handle_t i2s_example_init_pdm_rx(void)
|
|||||||
return rx_chan;
|
return rx_chan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void i2s_example_pdm_rx_task(void *args)
|
void i2s_example_pdm_rx_task(void *args)
|
||||||
{
|
{
|
||||||
int16_t *r_buf = (int16_t *)calloc(1, EXAMPLE_BUFF_SIZE);
|
int16_t *r_buf = (int16_t *)calloc(1, EXAMPLE_BUFF_SIZE);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -25,14 +25,17 @@
|
|||||||
#define EXAMPLE_BYTE_NUM_EVERY_TONE (EXAMPLE_TONE_LAST_TIME_MS * EXAMPLE_PDM_TX_FREQ_HZ / 1000)
|
#define EXAMPLE_BYTE_NUM_EVERY_TONE (EXAMPLE_TONE_LAST_TIME_MS * EXAMPLE_PDM_TX_FREQ_HZ / 1000)
|
||||||
|
|
||||||
/* The frequency of tones: do, re, mi, fa, so, la, si, in Hz. */
|
/* The frequency of tones: do, re, mi, fa, so, la, si, in Hz. */
|
||||||
static const uint32_t tone[3][7] = {{262, 294, 330, 349, 392, 440, 494}, // bass
|
static const uint32_t tone[3][7] = {
|
||||||
{523, 587, 659, 698, 784, 880, 988}, // alto
|
{262, 294, 330, 349, 392, 440, 494}, // bass
|
||||||
{1046, 1175, 1318, 1397, 1568, 1760, 1976}}; // treble
|
{523, 587, 659, 698, 784, 880, 988}, // alto
|
||||||
|
{1046, 1175, 1318, 1397, 1568, 1760, 1976}, // treble
|
||||||
|
};
|
||||||
/* Numbered musical notation of 'twinkle twinkle little star' */
|
/* Numbered musical notation of 'twinkle twinkle little star' */
|
||||||
static const uint8_t song[28] = {1, 1, 5, 5, 6, 6, 5,
|
static const uint8_t song[28] = {1, 1, 5, 5, 6, 6, 5,
|
||||||
4, 4, 3, 3, 2, 2, 1,
|
4, 4, 3, 3, 2, 2, 1,
|
||||||
5, 5, 4, 4, 3, 3, 2,
|
5, 5, 4, 4, 3, 3, 2,
|
||||||
5, 5, 4, 4, 3, 3, 2};
|
5, 5, 4, 4, 3, 3, 2
|
||||||
|
};
|
||||||
/* Rhythm of 'twinkle twinkle little star', it's repeated in four sections */
|
/* Rhythm of 'twinkle twinkle little star', it's repeated in four sections */
|
||||||
static const uint8_t rhythm[7] = {1, 1, 1, 1, 1, 1, 2};
|
static const uint8_t rhythm[7] = {1, 1, 1, 1, 1, 1, 2};
|
||||||
|
|
||||||
@ -92,10 +95,10 @@ void i2s_example_pdm_tx_task(void *args)
|
|||||||
|
|
||||||
printf("Playing %s `twinkle twinkle little star`\n", tone_name[tone_select]);
|
printf("Playing %s `twinkle twinkle little star`\n", tone_name[tone_select]);
|
||||||
while (1) {
|
while (1) {
|
||||||
int tone_point = EXAMPLE_SINE_WAVE_LEN(tone[tone_select][song[cnt]-1]);
|
int tone_point = EXAMPLE_SINE_WAVE_LEN(tone[tone_select][song[cnt] - 1]);
|
||||||
/* Generate the tone buffer */
|
/* Generate the tone buffer */
|
||||||
for (int i = 0; i < tone_point; i++) {
|
for (int i = 0; i < tone_point; i++) {
|
||||||
w_buf[i] = (int16_t)((sin(2 * (float)i * CONST_PI / tone_point)) * EXAMPLE_WAVE_AMPLITUDE);
|
w_buf[i] = (int16_t)((sin(2 * (float)i * CONST_PI / tone_point)) * EXAMPLE_WAVE_AMPLITUDE);
|
||||||
}
|
}
|
||||||
for (int tot_bytes = 0; tot_bytes < EXAMPLE_BYTE_NUM_EVERY_TONE * rhythm[cnt % 7]; tot_bytes += w_bytes) {
|
for (int tot_bytes = 0; tot_bytes < EXAMPLE_BYTE_NUM_EVERY_TONE * rhythm[cnt % 7]; tot_bytes += w_bytes) {
|
||||||
/* Play the tone */
|
/* Play the tone */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -20,27 +20,27 @@
|
|||||||
#define EXAMPLE_I2S_DUPLEX_MODE CONFIG_USE_DUPLEX
|
#define EXAMPLE_I2S_DUPLEX_MODE CONFIG_USE_DUPLEX
|
||||||
|
|
||||||
#if CONFIG_IDF_TARGET_ESP32
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
#define EXAMPLE_STD_BCLK_IO1 GPIO_NUM_4 // I2S bit clock io number
|
#define EXAMPLE_STD_BCLK_IO1 GPIO_NUM_4 // I2S bit clock io number
|
||||||
#define EXAMPLE_STD_WS_IO1 GPIO_NUM_5 // I2S word select io number
|
#define EXAMPLE_STD_WS_IO1 GPIO_NUM_5 // I2S word select io number
|
||||||
#define EXAMPLE_STD_DOUT_IO1 GPIO_NUM_18 // I2S data out io number
|
#define EXAMPLE_STD_DOUT_IO1 GPIO_NUM_18 // I2S data out io number
|
||||||
#define EXAMPLE_STD_DIN_IO1 GPIO_NUM_19 // I2S data in io number
|
#define EXAMPLE_STD_DIN_IO1 GPIO_NUM_19 // I2S data in io number
|
||||||
#if !EXAMPLE_I2S_DUPLEX_MODE
|
#if !EXAMPLE_I2S_DUPLEX_MODE
|
||||||
#define EXAMPLE_STD_BCLK_IO2 GPIO_NUM_22 // I2S bit clock io number
|
#define EXAMPLE_STD_BCLK_IO2 GPIO_NUM_22 // I2S bit clock io number
|
||||||
#define EXAMPLE_STD_WS_IO2 GPIO_NUM_23 // I2S word select io number
|
#define EXAMPLE_STD_WS_IO2 GPIO_NUM_23 // I2S word select io number
|
||||||
#define EXAMPLE_STD_DOUT_IO2 GPIO_NUM_25 // I2S data out io number
|
#define EXAMPLE_STD_DOUT_IO2 GPIO_NUM_25 // I2S data out io number
|
||||||
#define EXAMPLE_STD_DIN_IO2 GPIO_NUM_26 // I2S data in io number
|
#define EXAMPLE_STD_DIN_IO2 GPIO_NUM_26 // I2S data in io number
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define EXAMPLE_STD_BCLK_IO1 GPIO_NUM_2 // I2S bit clock io number
|
#define EXAMPLE_STD_BCLK_IO1 GPIO_NUM_2 // I2S bit clock io number
|
||||||
#define EXAMPLE_STD_WS_IO1 GPIO_NUM_3 // I2S word select io number
|
#define EXAMPLE_STD_WS_IO1 GPIO_NUM_3 // I2S word select io number
|
||||||
#define EXAMPLE_STD_DOUT_IO1 GPIO_NUM_4 // I2S data out io number
|
#define EXAMPLE_STD_DOUT_IO1 GPIO_NUM_4 // I2S data out io number
|
||||||
#define EXAMPLE_STD_DIN_IO1 GPIO_NUM_5 // I2S data in io number
|
#define EXAMPLE_STD_DIN_IO1 GPIO_NUM_5 // I2S data in io number
|
||||||
#if !EXAMPLE_I2S_DUPLEX_MODE
|
#if !EXAMPLE_I2S_DUPLEX_MODE
|
||||||
#define EXAMPLE_STD_BCLK_IO2 GPIO_NUM_6 // I2S bit clock io number
|
#define EXAMPLE_STD_BCLK_IO2 GPIO_NUM_6 // I2S bit clock io number
|
||||||
#define EXAMPLE_STD_WS_IO2 GPIO_NUM_7 // I2S word select io number
|
#define EXAMPLE_STD_WS_IO2 GPIO_NUM_7 // I2S word select io number
|
||||||
#define EXAMPLE_STD_DOUT_IO2 GPIO_NUM_8 // I2S data out io number
|
#define EXAMPLE_STD_DOUT_IO2 GPIO_NUM_8 // I2S data out io number
|
||||||
#define EXAMPLE_STD_DIN_IO2 GPIO_NUM_9 // I2S data in io number
|
#define EXAMPLE_STD_DIN_IO2 GPIO_NUM_9 // I2S data in io number
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define EXAMPLE_BUFF_SIZE 2048
|
#define EXAMPLE_BUFF_SIZE 2048
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -22,10 +22,10 @@
|
|||||||
#define EXAMPLE_TDM_DOUT_IO1 GPIO_NUM_4 // I2S data out io number
|
#define EXAMPLE_TDM_DOUT_IO1 GPIO_NUM_4 // I2S data out io number
|
||||||
#define EXAMPLE_TDM_DIN_IO1 GPIO_NUM_5 // I2S data in io number
|
#define EXAMPLE_TDM_DIN_IO1 GPIO_NUM_5 // I2S data in io number
|
||||||
#if !EXAMPLE_I2S_DUPLEX_MODE
|
#if !EXAMPLE_I2S_DUPLEX_MODE
|
||||||
#define EXAMPLE_TDM_BCLK_IO2 GPIO_NUM_6 // I2S bit clock io number
|
#define EXAMPLE_TDM_BCLK_IO2 GPIO_NUM_6 // I2S bit clock io number
|
||||||
#define EXAMPLE_TDM_WS_IO2 GPIO_NUM_7 // I2S word select io number
|
#define EXAMPLE_TDM_WS_IO2 GPIO_NUM_7 // I2S word select io number
|
||||||
#define EXAMPLE_TDM_DOUT_IO2 GPIO_NUM_8 // I2S data out io number
|
#define EXAMPLE_TDM_DOUT_IO2 GPIO_NUM_8 // I2S data out io number
|
||||||
#define EXAMPLE_TDM_DIN_IO2 GPIO_NUM_9 // I2S data in io number
|
#define EXAMPLE_TDM_DIN_IO2 GPIO_NUM_9 // I2S data in io number
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define EXAMPLE_BUFF_SIZE 2048
|
#define EXAMPLE_BUFF_SIZE 2048
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -71,7 +71,6 @@
|
|||||||
|
|
||||||
static const char *TAG = "example";
|
static const char *TAG = "example";
|
||||||
|
|
||||||
|
|
||||||
static i2s_chan_handle_t es7210_i2s_init(void)
|
static i2s_chan_handle_t es7210_i2s_init(void)
|
||||||
{
|
{
|
||||||
i2s_chan_handle_t i2s_rx_chan = NULL;
|
i2s_chan_handle_t i2s_rx_chan = NULL;
|
||||||
@ -151,8 +150,8 @@ sdmmc_card_t * mount_sdcard(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Card size: %lluMB, speed: %dMHz",
|
ESP_LOGI(TAG, "Card size: %lluMB, speed: %dMHz",
|
||||||
(((uint64_t)sdmmc_card->csd.capacity) * sdmmc_card->csd.sector_size) >> 20,
|
(((uint64_t)sdmmc_card->csd.capacity) * sdmmc_card->csd.sector_size) >> 20,
|
||||||
sdmmc_card->max_freq_khz / 1000);
|
sdmmc_card->max_freq_khz / 1000);
|
||||||
|
|
||||||
return sdmmc_card;
|
return sdmmc_card;
|
||||||
}
|
}
|
||||||
@ -217,13 +216,13 @@ static esp_err_t record_wav(i2s_chan_handle_t i2s_rx_chan)
|
|||||||
static int16_t i2s_readraw_buff[4096];
|
static int16_t i2s_readraw_buff[4096];
|
||||||
ESP_GOTO_ON_ERROR(i2s_channel_enable(i2s_rx_chan), err, TAG, "error while starting i2s rx channel");
|
ESP_GOTO_ON_ERROR(i2s_channel_enable(i2s_rx_chan), err, TAG, "error while starting i2s rx channel");
|
||||||
while (wav_written < wav_size) {
|
while (wav_written < wav_size) {
|
||||||
if(wav_written % byte_rate < sizeof(i2s_readraw_buff)) {
|
if (wav_written % byte_rate < sizeof(i2s_readraw_buff)) {
|
||||||
ESP_LOGI(TAG, "Recording: %"PRIu32"/%ds", wav_written/byte_rate + 1, EXAMPLE_RECORD_TIME_SEC);
|
ESP_LOGI(TAG, "Recording: %"PRIu32"/%ds", wav_written / byte_rate + 1, EXAMPLE_RECORD_TIME_SEC);
|
||||||
}
|
}
|
||||||
size_t bytes_read = 0;
|
size_t bytes_read = 0;
|
||||||
/* Read RAW samples from ES7210 */
|
/* Read RAW samples from ES7210 */
|
||||||
ESP_GOTO_ON_ERROR(i2s_channel_read(i2s_rx_chan, i2s_readraw_buff, sizeof(i2s_readraw_buff), &bytes_read,
|
ESP_GOTO_ON_ERROR(i2s_channel_read(i2s_rx_chan, i2s_readraw_buff, sizeof(i2s_readraw_buff), &bytes_read,
|
||||||
pdMS_TO_TICKS(1000)), err, TAG, "error while reading samples from i2s");
|
pdMS_TO_TICKS(1000)), err, TAG, "error while reading samples from i2s");
|
||||||
/* Write the samples to the WAV file */
|
/* Write the samples to the WAV file */
|
||||||
ESP_GOTO_ON_FALSE(fwrite(i2s_readraw_buff, bytes_read, 1, f), ESP_FAIL, err,
|
ESP_GOTO_ON_FALSE(fwrite(i2s_readraw_buff, bytes_read, 1, f), ESP_FAIL, err,
|
||||||
TAG, "error while writing samples to wav file");
|
TAG, "error while writing samples to wav file");
|
||||||
@ -250,9 +249,9 @@ void app_main(void)
|
|||||||
esp_err_t err = record_wav(i2s_rx_chan);
|
esp_err_t err = record_wav(i2s_rx_chan);
|
||||||
/* Unmount SD card */
|
/* Unmount SD card */
|
||||||
esp_vfs_fat_sdcard_unmount(EXAMPLE_SD_MOUNT_POINT, sdmmc_card);
|
esp_vfs_fat_sdcard_unmount(EXAMPLE_SD_MOUNT_POINT, sdmmc_card);
|
||||||
if(err == ESP_OK) {
|
if (err == ESP_OK) {
|
||||||
ESP_LOGI(TAG, "Audio was successfully recorded into "EXAMPLE_RECORD_FILE_PATH
|
ESP_LOGI(TAG, "Audio was successfully recorded into "EXAMPLE_RECORD_FILE_PATH
|
||||||
". You can now remove the SD card safely");
|
". You can now remove the SD card safely");
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "Record failed, "EXAMPLE_RECORD_FILE_PATH" on SD card may not be playable.");
|
ESP_LOGE(TAG, "Record failed, "EXAMPLE_RECORD_FILE_PATH" on SD card may not be playable.");
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#define EXAMPLE_MIC_GAIN CONFIG_EXAMPLE_MIC_GAIN
|
#define EXAMPLE_MIC_GAIN CONFIG_EXAMPLE_MIC_GAIN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if !defined(CONFIG_EXAMPLE_BSP)
|
#if !defined(CONFIG_EXAMPLE_BSP)
|
||||||
|
|
||||||
/* I2C port and GPIOs */
|
/* I2C port and GPIOs */
|
||||||
@ -47,7 +46,6 @@
|
|||||||
#define I2S_DI_IO (GPIO_NUM_3)
|
#define I2S_DI_IO (GPIO_NUM_3)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#else // CONFIG_EXAMPLE_BSP
|
#else // CONFIG_EXAMPLE_BSP
|
||||||
#include "bsp/esp-bsp.h"
|
#include "bsp/esp-bsp.h"
|
||||||
#define I2C_NUM BSP_I2C_NUM
|
#define I2C_NUM BSP_I2C_NUM
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "es8311.h"
|
#include "es8311.h"
|
||||||
#include "example_config.h"
|
#include "example_config.h"
|
||||||
|
|
||||||
|
|
||||||
static const char *TAG = "i2s_es8311";
|
static const char *TAG = "i2s_es8311";
|
||||||
static const char err_reason[][30] = {"input param is invalid",
|
static const char err_reason[][30] = {"input param is invalid",
|
||||||
"operation timeout"
|
"operation timeout"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -15,11 +15,11 @@ uint16_t *pixels;
|
|||||||
static inline uint16_t get_bgnd_pixel(int x, int y)
|
static inline uint16_t get_bgnd_pixel(int x, int y)
|
||||||
{
|
{
|
||||||
//Get color of the pixel on x,y coords
|
//Get color of the pixel on x,y coords
|
||||||
return (uint16_t) *(pixels + (y * IMAGE_W) + x);
|
return (uint16_t) * (pixels + (y * IMAGE_W) + x);
|
||||||
}
|
}
|
||||||
|
|
||||||
//This variable is used to detect the next frame.
|
//This variable is used to detect the next frame.
|
||||||
static int prev_frame=-1;
|
static int prev_frame = -1;
|
||||||
|
|
||||||
//Instead of calculating the offsets for each pixel we grab, we pre-calculate the valueswhenever a frame changes, then re-use
|
//Instead of calculating the offsets for each pixel we grab, we pre-calculate the valueswhenever a frame changes, then re-use
|
||||||
//these as we go through all the pixels in the frame. This is much, much faster.
|
//these as we go through all the pixels in the frame. This is much, much faster.
|
||||||
@ -31,23 +31,30 @@ static int8_t xcomp[320], ycomp[240];
|
|||||||
//is displayed; this is used to go to the next frame of animation.
|
//is displayed; this is used to go to the next frame of animation.
|
||||||
void pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect)
|
void pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect)
|
||||||
{
|
{
|
||||||
if (frame!=prev_frame) {
|
if (frame != prev_frame) {
|
||||||
//We need to calculate a new set of offset coefficients. Take some random sines as offsets to make everything
|
//We need to calculate a new set of offset coefficients. Take some random sines as offsets to make everything
|
||||||
//look pretty and fluid-y.
|
//look pretty and fluid-y.
|
||||||
for (int x=0; x<320; x++) xofs[x]=sin(frame*0.15+x*0.06)*4;
|
for (int x = 0; x < 320; x++) {
|
||||||
for (int y=0; y<240; y++) yofs[y]=sin(frame*0.1+y*0.05)*4;
|
xofs[x] = sin(frame * 0.15 + x * 0.06) * 4;
|
||||||
for (int x=0; x<320; x++) xcomp[x]=sin(frame*0.11+x*0.12)*4;
|
}
|
||||||
for (int y=0; y<240; y++) ycomp[y]=sin(frame*0.07+y*0.15)*4;
|
for (int y = 0; y < 240; y++) {
|
||||||
prev_frame=frame;
|
yofs[y] = sin(frame * 0.1 + y * 0.05) * 4;
|
||||||
|
}
|
||||||
|
for (int x = 0; x < 320; x++) {
|
||||||
|
xcomp[x] = sin(frame * 0.11 + x * 0.12) * 4;
|
||||||
|
}
|
||||||
|
for (int y = 0; y < 240; y++) {
|
||||||
|
ycomp[y] = sin(frame * 0.07 + y * 0.15) * 4;
|
||||||
|
}
|
||||||
|
prev_frame = frame;
|
||||||
}
|
}
|
||||||
for (int y=line; y<line+linect; y++) {
|
for (int y = line; y < line + linect; y++) {
|
||||||
for (int x=0; x<320; x++) {
|
for (int x = 0; x < 320; x++) {
|
||||||
*dest++=get_bgnd_pixel(x+yofs[y]+xcomp[x], y+xofs[x]+ycomp[y]);
|
*dest++ = get_bgnd_pixel(x + yofs[y] + xcomp[x], y + xofs[x] + ycomp[y]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esp_err_t pretty_effect_init(void)
|
esp_err_t pretty_effect_init(void)
|
||||||
{
|
{
|
||||||
return decode_image(&pixels);
|
return decode_image(&pixels);
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calculate the effect for a bunch of lines.
|
* @brief Calculate the effect for a bunch of lines.
|
||||||
*
|
*
|
||||||
@ -19,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
void pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect);
|
void pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the effect
|
* @brief Initialize the effect
|
||||||
*
|
*
|
||||||
|
@ -195,9 +195,9 @@ void app_main(void)
|
|||||||
printf("1. LEDC fade up to duty = %d\n", LEDC_TEST_DUTY);
|
printf("1. LEDC fade up to duty = %d\n", LEDC_TEST_DUTY);
|
||||||
for (ch = 0; ch < LEDC_TEST_CH_NUM; ch++) {
|
for (ch = 0; ch < LEDC_TEST_CH_NUM; ch++) {
|
||||||
ledc_set_fade_with_time(ledc_channel[ch].speed_mode,
|
ledc_set_fade_with_time(ledc_channel[ch].speed_mode,
|
||||||
ledc_channel[ch].channel, LEDC_TEST_DUTY, LEDC_TEST_FADE_TIME);
|
ledc_channel[ch].channel, LEDC_TEST_DUTY, LEDC_TEST_FADE_TIME);
|
||||||
ledc_fade_start(ledc_channel[ch].speed_mode,
|
ledc_fade_start(ledc_channel[ch].speed_mode,
|
||||||
ledc_channel[ch].channel, LEDC_FADE_NO_WAIT);
|
ledc_channel[ch].channel, LEDC_FADE_NO_WAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < LEDC_TEST_CH_NUM; i++) {
|
for (int i = 0; i < LEDC_TEST_CH_NUM; i++) {
|
||||||
@ -207,9 +207,9 @@ void app_main(void)
|
|||||||
printf("2. LEDC fade down to duty = 0\n");
|
printf("2. LEDC fade down to duty = 0\n");
|
||||||
for (ch = 0; ch < LEDC_TEST_CH_NUM; ch++) {
|
for (ch = 0; ch < LEDC_TEST_CH_NUM; ch++) {
|
||||||
ledc_set_fade_with_time(ledc_channel[ch].speed_mode,
|
ledc_set_fade_with_time(ledc_channel[ch].speed_mode,
|
||||||
ledc_channel[ch].channel, 0, LEDC_TEST_FADE_TIME);
|
ledc_channel[ch].channel, 0, LEDC_TEST_FADE_TIME);
|
||||||
ledc_fade_start(ledc_channel[ch].speed_mode,
|
ledc_fade_start(ledc_channel[ch].speed_mode,
|
||||||
ledc_channel[ch].channel, LEDC_FADE_NO_WAIT);
|
ledc_channel[ch].channel, LEDC_FADE_NO_WAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < LEDC_TEST_CH_NUM; i++) {
|
for (int i = 0; i < LEDC_TEST_CH_NUM; i++) {
|
||||||
|
@ -64,7 +64,6 @@ static rgb_channel_config_t rgb_led_2_channels = {
|
|||||||
.blue_channel = LEDC_CHANNEL_GAMMA_BLUE,
|
.blue_channel = LEDC_CHANNEL_GAMMA_BLUE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Define some colors R, G, B channel PWM duty cycles
|
// Define some colors R, G, B channel PWM duty cycles
|
||||||
#define RGB_TO_DUTY(x) (x * (1 << LEDC_DUTY_RES) / 255)
|
#define RGB_TO_DUTY(x) (x * (1 << LEDC_DUTY_RES) / 255)
|
||||||
|
|
||||||
@ -126,7 +125,6 @@ static rgb_channel_config_t rgb_led_2_channels = {
|
|||||||
#define BLUEISH_PURPLE_G RGB_TO_DUTY(102)
|
#define BLUEISH_PURPLE_G RGB_TO_DUTY(102)
|
||||||
#define BLUEISH_PURPLE_B RGB_TO_DUTY(255)
|
#define BLUEISH_PURPLE_B RGB_TO_DUTY(255)
|
||||||
|
|
||||||
|
|
||||||
#if CONFIG_GAMMA_CORRECTION_WITH_LUT
|
#if CONFIG_GAMMA_CORRECTION_WITH_LUT
|
||||||
// Brightness 0 - 100% gamma correction look up table (gamma = 2.6)
|
// Brightness 0 - 100% gamma correction look up table (gamma = 2.6)
|
||||||
// Y = B ^ 2.6
|
// Y = B ^ 2.6
|
||||||
@ -158,7 +156,6 @@ static uint32_t gamma_correction_calculator(uint32_t duty)
|
|||||||
}
|
}
|
||||||
#endif // CONFIG_GAMMA_CORRECTION_WITH_LUT
|
#endif // CONFIG_GAMMA_CORRECTION_WITH_LUT
|
||||||
|
|
||||||
|
|
||||||
static void rgb_set_duty_and_update(rgb_channel_config_t rgb_channels,
|
static void rgb_set_duty_and_update(rgb_channel_config_t rgb_channels,
|
||||||
uint32_t target_r_duty, uint32_t target_g_duty, uint32_t target_b_duty)
|
uint32_t target_r_duty, uint32_t target_g_duty, uint32_t target_b_duty)
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -261,22 +261,22 @@ void app_main(void)
|
|||||||
// we will use the dead time module to add edge delay, also make gen_high and gen_low complementary
|
// we will use the dead time module to add edge delay, also make gen_high and gen_low complementary
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_timer_event(generators[i][BLDC_MCPWM_GEN_INDEX_HIGH],
|
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_timer_event(generators[i][BLDC_MCPWM_GEN_INDEX_HIGH],
|
||||||
MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH)));
|
MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH)));
|
||||||
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_compare_event(generators[i][BLDC_MCPWM_GEN_INDEX_HIGH],
|
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_compare_event(generators[i][BLDC_MCPWM_GEN_INDEX_HIGH],
|
||||||
MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparators[i], MCPWM_GEN_ACTION_LOW)));
|
MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparators[i], MCPWM_GEN_ACTION_LOW)));
|
||||||
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_brake_event(generators[i][BLDC_MCPWM_GEN_INDEX_HIGH],
|
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_brake_event(generators[i][BLDC_MCPWM_GEN_INDEX_HIGH],
|
||||||
MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW)));
|
MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW)));
|
||||||
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_brake_event(generators[i][BLDC_MCPWM_GEN_INDEX_HIGH],
|
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_brake_event(generators[i][BLDC_MCPWM_GEN_INDEX_HIGH],
|
||||||
MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW)));
|
MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW)));
|
||||||
|
|
||||||
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_timer_event(generators[i][BLDC_MCPWM_GEN_INDEX_LOW],
|
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_timer_event(generators[i][BLDC_MCPWM_GEN_INDEX_LOW],
|
||||||
MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH)));
|
MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH)));
|
||||||
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_compare_event(generators[i][BLDC_MCPWM_GEN_INDEX_LOW],
|
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_compare_event(generators[i][BLDC_MCPWM_GEN_INDEX_LOW],
|
||||||
MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparators[i], MCPWM_GEN_ACTION_LOW)));
|
MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparators[i], MCPWM_GEN_ACTION_LOW)));
|
||||||
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_brake_event(generators[i][BLDC_MCPWM_GEN_INDEX_LOW],
|
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_brake_event(generators[i][BLDC_MCPWM_GEN_INDEX_LOW],
|
||||||
MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW)));
|
MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW)));
|
||||||
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_brake_event(generators[i][BLDC_MCPWM_GEN_INDEX_LOW],
|
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_brake_event(generators[i][BLDC_MCPWM_GEN_INDEX_LOW],
|
||||||
MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW)));
|
MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Setup deadtime");
|
ESP_LOGI(TAG, "Setup deadtime");
|
||||||
|
@ -51,12 +51,11 @@ static const char *TAG = "example_foc";
|
|||||||
#define EXAMPLE_FOC_WAVE_FREQ 10 // 50Hz 3 phase AC wave
|
#define EXAMPLE_FOC_WAVE_FREQ 10 // 50Hz 3 phase AC wave
|
||||||
#define EXAMPLE_FOC_WAVE_AMPL 100 // Wave amplitude, Use up-down timer mode, max value should be (EXAMPLE_FOC_MCPWM_PERIOD/2)
|
#define EXAMPLE_FOC_WAVE_AMPL 100 // Wave amplitude, Use up-down timer mode, max value should be (EXAMPLE_FOC_MCPWM_PERIOD/2)
|
||||||
|
|
||||||
|
|
||||||
void bsp_bridge_driver_init(void)
|
void bsp_bridge_driver_init(void)
|
||||||
{
|
{
|
||||||
gpio_config_t drv_en_config = {
|
gpio_config_t drv_en_config = {
|
||||||
.pin_bit_mask = 1ULL << EXAMPLE_FOC_DRV_EN_GPIO,
|
|
||||||
.mode = GPIO_MODE_OUTPUT,
|
.mode = GPIO_MODE_OUTPUT,
|
||||||
|
.pin_bit_mask = 1ULL << EXAMPLE_FOC_DRV_EN_GPIO,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(gpio_config(&drv_en_config));
|
ESP_ERROR_CHECK(gpio_config(&drv_en_config));
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,11 @@
|
|||||||
*/
|
*/
|
||||||
#include "esp_foc.h"
|
#include "esp_foc.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* alpha = u - (v + w)sin(30) * (2/3), (2/3): Equal amplitude transformation const
|
* alpha = u - (v + w)sin(30) * (2/3), (2/3): Equal amplitude transformation const
|
||||||
* beta = (v - w)cos(30) * (2/3)
|
* beta = (v - w)cos(30) * (2/3)
|
||||||
*/
|
*/
|
||||||
void foc_clarke_transform (const foc_uvw_coord_t *v_uvw, foc_ab_coord_t *v_ab)
|
void foc_clarke_transform(const foc_uvw_coord_t *v_uvw, foc_ab_coord_t *v_ab)
|
||||||
{
|
{
|
||||||
const _iq foc_clark_k1_iq = _IQ(2.0 / 3.0);
|
const _iq foc_clark_k1_iq = _IQ(2.0 / 3.0);
|
||||||
const _iq foc_clark_k2_iq = _IQ(1.0 / 3.0);
|
const _iq foc_clark_k2_iq = _IQ(1.0 / 3.0);
|
||||||
@ -20,14 +19,14 @@ void foc_clarke_transform (const foc_uvw_coord_t *v_uvw, foc_ab_coord_t *v_ab)
|
|||||||
v_ab->beta = _IQmpy(v_uvw->v - v_uvw->w, foc_clark_k3_iq);
|
v_ab->beta = _IQmpy(v_uvw->v - v_uvw->w, foc_clark_k3_iq);
|
||||||
}
|
}
|
||||||
|
|
||||||
void foc_inverse_clarke_transform (const foc_ab_coord_t *v_ab, foc_uvw_coord_t *v_uvw)
|
void foc_inverse_clarke_transform(const foc_ab_coord_t *v_ab, foc_uvw_coord_t *v_uvw)
|
||||||
{
|
{
|
||||||
v_uvw->u = v_ab->alpha;
|
v_uvw->u = v_ab->alpha;
|
||||||
v_uvw->v = _IQdiv2(_IQmpy(v_ab->beta, _IQ(M_SQRT3)) - v_ab->alpha);
|
v_uvw->v = _IQdiv2(_IQmpy(v_ab->beta, _IQ(M_SQRT3)) - v_ab->alpha);
|
||||||
v_uvw->w = -v_uvw->u - v_uvw->v;
|
v_uvw->w = -v_uvw->u - v_uvw->v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void foc_park_transform (_iq theta_rad, const foc_ab_coord_t *v_ab, foc_dq_coord_t *v_dq)
|
void foc_park_transform(_iq theta_rad, const foc_ab_coord_t *v_ab, foc_dq_coord_t *v_dq)
|
||||||
{
|
{
|
||||||
_iq sin = _IQsin(theta_rad);
|
_iq sin = _IQsin(theta_rad);
|
||||||
_iq cos = _IQcos(theta_rad);
|
_iq cos = _IQcos(theta_rad);
|
||||||
@ -36,7 +35,7 @@ void foc_park_transform (_iq theta_rad, const foc_ab_coord_t *v_ab, foc_dq_coord
|
|||||||
v_dq->q = _IQmpy(v_ab->beta, cos) - _IQmpy(v_ab->alpha, sin);
|
v_dq->q = _IQmpy(v_ab->beta, cos) - _IQmpy(v_ab->alpha, sin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void foc_inverse_park_transform (_iq theta_rad, const foc_dq_coord_t *v_dq, foc_ab_coord_t *v_ab)
|
void foc_inverse_park_transform(_iq theta_rad, const foc_dq_coord_t *v_dq, foc_ab_coord_t *v_ab)
|
||||||
{
|
{
|
||||||
_iq sin = _IQsin(theta_rad);
|
_iq sin = _IQsin(theta_rad);
|
||||||
_iq cos = _IQcos(theta_rad);
|
_iq cos = _IQcos(theta_rad);
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#define GLOBAL_IQ 18
|
#define GLOBAL_IQ 18
|
||||||
#include "IQmathLib.h"
|
#include "IQmathLib.h"
|
||||||
|
|
||||||
|
|
||||||
// 3-phase uvw coord data type
|
// 3-phase uvw coord data type
|
||||||
typedef struct foc_uvw_coord {
|
typedef struct foc_uvw_coord {
|
||||||
_iq u; // U phase data in IQ type
|
_iq u; // U phase data in IQ type
|
||||||
@ -36,7 +35,7 @@ typedef struct foc_dq_coord {
|
|||||||
* @param[in] v_uvw data in 3-phase coord to be transformed
|
* @param[in] v_uvw data in 3-phase coord to be transformed
|
||||||
* @param[out] v_ab output data in alpha-beta coord
|
* @param[out] v_ab output data in alpha-beta coord
|
||||||
*/
|
*/
|
||||||
void foc_clarke_transform (const foc_uvw_coord_t *v_uvw, foc_ab_coord_t *v_ab);
|
void foc_clarke_transform(const foc_uvw_coord_t *v_uvw, foc_ab_coord_t *v_ab);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief inverse clark transform, to transform value in alpha_beta system to 3phase uvw system
|
* @brief inverse clark transform, to transform value in alpha_beta system to 3phase uvw system
|
||||||
@ -44,7 +43,7 @@ void foc_clarke_transform (const foc_uvw_coord_t *v_uvw, foc_ab_coord_t *v_ab);
|
|||||||
* @param[in] v_ab data in alpha-beta coord to be transformed
|
* @param[in] v_ab data in alpha-beta coord to be transformed
|
||||||
* @param[out] v_uvw output data in 3-phase coord
|
* @param[out] v_uvw output data in 3-phase coord
|
||||||
*/
|
*/
|
||||||
void foc_inverse_clarke_transform (const foc_ab_coord_t *v_ab, foc_uvw_coord_t *v_uvw);
|
void foc_inverse_clarke_transform(const foc_ab_coord_t *v_ab, foc_uvw_coord_t *v_uvw);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief park transform, to transform value in static alpha_beta system to rotate d-q system
|
* @brief park transform, to transform value in static alpha_beta system to rotate d-q system
|
||||||
@ -53,7 +52,7 @@ void foc_inverse_clarke_transform (const foc_ab_coord_t *v_ab, foc_uvw_coord_t *
|
|||||||
* @param[in] v_ab data in alpha-beta coord to be transformed
|
* @param[in] v_ab data in alpha-beta coord to be transformed
|
||||||
* @param[out] v_dq output data in dq coord
|
* @param[out] v_dq output data in dq coord
|
||||||
*/
|
*/
|
||||||
void foc_park_transform (_iq theta_rad, const foc_ab_coord_t *v_ab, foc_dq_coord_t *v_dq);
|
void foc_park_transform(_iq theta_rad, const foc_ab_coord_t *v_ab, foc_dq_coord_t *v_dq);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief inverse park transform, to transform value in rotate d-q system to alpha_beta system
|
* @brief inverse park transform, to transform value in rotate d-q system to alpha_beta system
|
||||||
@ -62,7 +61,7 @@ void foc_park_transform (_iq theta_rad, const foc_ab_coord_t *v_ab, foc_dq_coord
|
|||||||
* @param[in] v_dq data in dq coord to be transformed
|
* @param[in] v_dq data in dq coord to be transformed
|
||||||
* @param[out] v_ab output data in alpha-beta coord
|
* @param[out] v_ab output data in alpha-beta coord
|
||||||
*/
|
*/
|
||||||
void foc_inverse_park_transform (_iq theta_rad, const foc_dq_coord_t *v_dq, foc_ab_coord_t *v_ab);
|
void foc_inverse_park_transform(_iq theta_rad, const foc_dq_coord_t *v_dq, foc_ab_coord_t *v_ab);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 7-segment svpwm modulation
|
* @brief 7-segment svpwm modulation
|
||||||
@ -70,4 +69,4 @@ void foc_inverse_park_transform (_iq theta_rad, const foc_dq_coord_t *v_dq, foc_
|
|||||||
* @param v_ab[in] input value in alpha-beta coord
|
* @param v_ab[in] input value in alpha-beta coord
|
||||||
* @param out_uvw[out] output modulated pwm duty in IQ type
|
* @param out_uvw[out] output modulated pwm duty in IQ type
|
||||||
*/
|
*/
|
||||||
void foc_svpwm_duty_calculate (const foc_ab_coord_t *v_ab, foc_uvw_coord_t *out_uvw);
|
void foc_svpwm_duty_calculate(const foc_ab_coord_t *v_ab, foc_uvw_coord_t *out_uvw);
|
||||||
|
@ -18,7 +18,6 @@ typedef struct mcpwm_svpwm_ctx {
|
|||||||
mcpwm_gen_handle_t generators[3][2];
|
mcpwm_gen_handle_t generators[3][2];
|
||||||
} mcpwm_svpwm_ctx_t;
|
} mcpwm_svpwm_ctx_t;
|
||||||
|
|
||||||
|
|
||||||
esp_err_t svpwm_new_inverter(const inverter_config_t *config, inverter_handle_t *ret_inverter)
|
esp_err_t svpwm_new_inverter(const inverter_config_t *config, inverter_handle_t *ret_inverter)
|
||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
@ -51,9 +50,9 @@ esp_err_t svpwm_new_inverter(const inverter_config_t *config, inverter_handle_t
|
|||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
ESP_GOTO_ON_ERROR(mcpwm_generator_set_actions_on_compare_event(svpwm_dev->generators[i][0],
|
ESP_GOTO_ON_ERROR(mcpwm_generator_set_actions_on_compare_event(svpwm_dev->generators[i][0],
|
||||||
MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, svpwm_dev->comparators[i], MCPWM_GEN_ACTION_LOW),
|
MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, svpwm_dev->comparators[i], MCPWM_GEN_ACTION_LOW),
|
||||||
MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_DOWN, svpwm_dev->comparators[i], MCPWM_GEN_ACTION_HIGH),
|
MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_DOWN, svpwm_dev->comparators[i], MCPWM_GEN_ACTION_HIGH),
|
||||||
MCPWM_GEN_COMPARE_EVENT_ACTION_END()), err, TAG, "Set generator actions failed");
|
MCPWM_GEN_COMPARE_EVENT_ACTION_END()), err, TAG, "Set generator actions failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
@ -67,10 +67,10 @@ void app_main(void)
|
|||||||
ESP_LOGI(TAG, "Set generator action on timer and compare event");
|
ESP_LOGI(TAG, "Set generator action on timer and compare event");
|
||||||
// go high on counter empty
|
// go high on counter empty
|
||||||
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_timer_event(generator,
|
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_timer_event(generator,
|
||||||
MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH)));
|
MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH)));
|
||||||
// go low on compare threshold
|
// go low on compare threshold
|
||||||
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_compare_event(generator,
|
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_compare_event(generator,
|
||||||
MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparator, MCPWM_GEN_ACTION_LOW)));
|
MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparator, MCPWM_GEN_ACTION_LOW)));
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Enable and start timer");
|
ESP_LOGI(TAG, "Enable and start timer");
|
||||||
ESP_ERROR_CHECK(mcpwm_timer_enable(timer));
|
ESP_ERROR_CHECK(mcpwm_timer_enable(timer));
|
||||||
|
@ -176,11 +176,11 @@ void app_main(void)
|
|||||||
ESP_LOGI(TAG, "Set generator actions on timer and compare event");
|
ESP_LOGI(TAG, "Set generator actions on timer and compare event");
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_timer_event(generators[i],
|
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_timer_event(generators[i],
|
||||||
// when the timer value is zero, and is counting up, set output to high
|
// when the timer value is zero, and is counting up, set output to high
|
||||||
MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH)));
|
MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH)));
|
||||||
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_compare_event(generators[i],
|
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_compare_event(generators[i],
|
||||||
// when compare event happens, and timer is counting up, set output to low
|
// when compare event happens, and timer is counting up, set output to low
|
||||||
MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparators[i], MCPWM_GEN_ACTION_LOW)));
|
MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparators[i], MCPWM_GEN_ACTION_LOW)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Start timers one by one, so they are not synced");
|
ESP_LOGI(TAG, "Start timers one by one, so they are not synced");
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include "driver/rmt_tx.h"
|
#include "driver/rmt_tx.h"
|
||||||
#include "led_strip_encoder.h"
|
#include "led_strip_encoder.h"
|
||||||
|
|
||||||
|
|
||||||
#define RMT_LED_STRIP_RESOLUTION_HZ 10000000 // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
|
#define RMT_LED_STRIP_RESOLUTION_HZ 10000000 // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
|
||||||
#define RMT_LED_STRIP_GPIO_NUM 0
|
#define RMT_LED_STRIP_GPIO_NUM 0
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "sdmmc_cmd.h"
|
#include "sdmmc_cmd.h"
|
||||||
|
|
||||||
|
|
||||||
#define TIMEOUT_MAX UINT32_MAX
|
#define TIMEOUT_MAX UINT32_MAX
|
||||||
|
|
||||||
#define GPIO_B1 21
|
#define GPIO_B1 21
|
||||||
@ -55,7 +54,6 @@
|
|||||||
#define PIN_D3 SDMMC_SLOT1_IOMUX_PIN_NUM_D3
|
#define PIN_D3 SDMMC_SLOT1_IOMUX_PIN_NUM_D3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
sdio host example.
|
sdio host example.
|
||||||
|
|
||||||
@ -298,7 +296,6 @@ esp_err_t slave_init(essl_handle_t* handle)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void slave_power_on(void)
|
void slave_power_on(void)
|
||||||
{
|
{
|
||||||
#ifdef SLAVE_PWR_GPIO
|
#ifdef SLAVE_PWR_GPIO
|
||||||
@ -338,9 +335,13 @@ static esp_err_t get_intr(essl_handle_t handle, uint32_t* out_raw, uint32_t* out
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = essl_get_intr(handle, out_raw, out_st, TIMEOUT_MAX);
|
ret = essl_get_intr(handle, out_raw, out_st, TIMEOUT_MAX);
|
||||||
if (ret != ESP_OK) return ret;
|
if (ret != ESP_OK) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
ret = essl_clear_intr(handle, *out_raw, TIMEOUT_MAX);
|
ret = essl_clear_intr(handle, *out_raw, TIMEOUT_MAX);
|
||||||
if (ret != ESP_OK) return ret;
|
if (ret != ESP_OK) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
ESP_LOGD(TAG, "intr: %08"PRIX32, *out_raw);
|
ESP_LOGD(TAG, "intr: %08"PRIX32, *out_raw);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
@ -75,8 +75,8 @@ typedef enum {
|
|||||||
static const char TAG[] = "example_slave";
|
static const char TAG[] = "example_slave";
|
||||||
static int s_job = JOB_IDLE;
|
static int s_job = JOB_IDLE;
|
||||||
|
|
||||||
DMA_ATTR uint8_t data_to_send[BUFFER_SIZE] = {0x97, 0x84, 0x43, 0x67, 0xc1, 0xdd, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x56, 0x55, 0x44, 0x33 ,0x22, 0x11, 0x00 };
|
DMA_ATTR uint8_t data_to_send[BUFFER_SIZE] = {0x97, 0x84, 0x43, 0x67, 0xc1, 0xdd, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x56, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 };
|
||||||
DMA_ATTR uint8_t data_to_recv[BUFFER_SIZE] = {0x97, 0x84, 0x43, 0x67, 0xc1, 0xdd, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x56, 0x55, 0x44, 0x33 ,0x22, 0x11, 0x00 };
|
DMA_ATTR uint8_t data_to_recv[BUFFER_SIZE] = {0x97, 0x84, 0x43, 0x67, 0xc1, 0xdd, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x56, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 };
|
||||||
|
|
||||||
static const char job_desc[][32] = {
|
static const char job_desc[][32] = {
|
||||||
"JOB_IDLE",
|
"JOB_IDLE",
|
||||||
@ -85,22 +85,27 @@ static const char job_desc[][32] = {
|
|||||||
"JOB_WRITE_REG",
|
"JOB_WRITE_REG",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//reset counters of the slave hardware, and clean the receive buffer (normally they should be sent back to the host)
|
//reset counters of the slave hardware, and clean the receive buffer (normally they should be sent back to the host)
|
||||||
static esp_err_t slave_reset(void)
|
static esp_err_t slave_reset(void)
|
||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
sdio_slave_stop();
|
sdio_slave_stop();
|
||||||
ret = sdio_slave_reset();
|
ret = sdio_slave_reset();
|
||||||
if (ret != ESP_OK) return ret;
|
if (ret != ESP_OK) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
ret = sdio_slave_start();
|
ret = sdio_slave_start();
|
||||||
if (ret != ESP_OK) return ret;
|
if (ret != ESP_OK) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
//Since the buffer will not be sent any more, we return them back to receving driver
|
//Since the buffer will not be sent any more, we return them back to receving driver
|
||||||
while(1) {
|
while (1) {
|
||||||
sdio_slave_buf_handle_t handle;
|
sdio_slave_buf_handle_t handle;
|
||||||
ret = sdio_slave_send_get_finished(&handle, 0);
|
ret = sdio_slave_send_get_finished(&handle, 0);
|
||||||
if (ret != ESP_OK) break;
|
if (ret != ESP_OK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
ret = sdio_slave_recv_load_buf(handle);
|
ret = sdio_slave_recv_load_buf(handle);
|
||||||
ESP_ERROR_CHECK(ret);
|
ESP_ERROR_CHECK(ret);
|
||||||
}
|
}
|
||||||
@ -110,12 +115,14 @@ static esp_err_t slave_reset(void)
|
|||||||
//sent interrupts to the host in turns
|
//sent interrupts to the host in turns
|
||||||
static esp_err_t task_hostint(void)
|
static esp_err_t task_hostint(void)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
ESP_LOGV(TAG, "send intr: %d", i);
|
ESP_LOGV(TAG, "send intr: %d", i);
|
||||||
sdio_slave_send_host_int(i);
|
sdio_slave_send_host_int(i);
|
||||||
//check reset for quick response to RESET signal
|
//check reset for quick response to RESET signal
|
||||||
if (s_job & JOB_RESET) break;
|
if (s_job & JOB_RESET) {
|
||||||
vTaskDelay(500/portTICK_PERIOD_MS);
|
break;
|
||||||
|
}
|
||||||
|
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@ -127,7 +134,7 @@ static esp_err_t task_write_reg(void)
|
|||||||
//the host write REG1, the slave should write its registers according to value of REG1
|
//the host write REG1, the slave should write its registers according to value of REG1
|
||||||
uint8_t read = sdio_slave_read_reg(1);
|
uint8_t read = sdio_slave_read_reg(1);
|
||||||
for (int i = 0; i < 60; i++) {
|
for (int i = 0; i < 60; i++) {
|
||||||
sdio_slave_write_reg(SLAVE_ADDR(i), read + 3*i);
|
sdio_slave_write_reg(SLAVE_ADDR(i), read + 3 * i);
|
||||||
}
|
}
|
||||||
uint8_t reg[60] = {0};
|
uint8_t reg[60] = {0};
|
||||||
for (int i = 0; i < 60; i++) {
|
for (int i = 0; i < 60; i++) {
|
||||||
@ -144,11 +151,11 @@ static esp_err_t task_write_reg(void)
|
|||||||
static void event_cb(uint8_t pos)
|
static void event_cb(uint8_t pos)
|
||||||
{
|
{
|
||||||
ESP_EARLY_LOGD(TAG, "event: %d", pos);
|
ESP_EARLY_LOGD(TAG, "event: %d", pos);
|
||||||
switch(pos) {
|
switch (pos) {
|
||||||
case 0:
|
case 0:
|
||||||
s_job = sdio_slave_read_reg(0);
|
s_job = sdio_slave_read_reg(0);
|
||||||
sdio_slave_write_reg(0, JOB_IDLE);
|
sdio_slave_write_reg(0, JOB_IDLE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +192,7 @@ void app_main(void)
|
|||||||
|
|
||||||
sdio_slave_write_reg(0, JOB_IDLE);
|
sdio_slave_write_reg(0, JOB_IDLE);
|
||||||
|
|
||||||
for(int i = 0; i < BUFFER_NUM; i++) {
|
for (int i = 0; i < BUFFER_NUM; i++) {
|
||||||
sdio_slave_buf_handle_t handle = sdio_slave_recv_register_buf(buffer[i]);
|
sdio_slave_buf_handle_t handle = sdio_slave_recv_register_buf(buffer[i]);
|
||||||
assert(handle != NULL);
|
assert(handle != NULL);
|
||||||
|
|
||||||
@ -194,21 +201,21 @@ void app_main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sdio_slave_set_host_intena(SDIO_SLAVE_HOSTINT_SEND_NEW_PACKET |
|
sdio_slave_set_host_intena(SDIO_SLAVE_HOSTINT_SEND_NEW_PACKET |
|
||||||
SDIO_SLAVE_HOSTINT_BIT0 |
|
SDIO_SLAVE_HOSTINT_BIT0 |
|
||||||
SDIO_SLAVE_HOSTINT_BIT1 |
|
SDIO_SLAVE_HOSTINT_BIT1 |
|
||||||
SDIO_SLAVE_HOSTINT_BIT2 |
|
SDIO_SLAVE_HOSTINT_BIT2 |
|
||||||
SDIO_SLAVE_HOSTINT_BIT3 |
|
SDIO_SLAVE_HOSTINT_BIT3 |
|
||||||
SDIO_SLAVE_HOSTINT_BIT4 |
|
SDIO_SLAVE_HOSTINT_BIT4 |
|
||||||
SDIO_SLAVE_HOSTINT_BIT5 |
|
SDIO_SLAVE_HOSTINT_BIT5 |
|
||||||
SDIO_SLAVE_HOSTINT_BIT6 |
|
SDIO_SLAVE_HOSTINT_BIT6 |
|
||||||
SDIO_SLAVE_HOSTINT_BIT7
|
SDIO_SLAVE_HOSTINT_BIT7
|
||||||
);
|
);
|
||||||
|
|
||||||
sdio_slave_start();
|
sdio_slave_start();
|
||||||
|
|
||||||
ESP_LOGI(TAG, EV_STR("slave ready"));
|
ESP_LOGI(TAG, EV_STR("slave ready"));
|
||||||
|
|
||||||
for(;;) {
|
for (;;) {
|
||||||
const TickType_t non_blocking = 0, blocking = portMAX_DELAY;
|
const TickType_t non_blocking = 0, blocking = portMAX_DELAY;
|
||||||
sdio_slave_buf_handle_t recv_queue[BUFFER_NUM];
|
sdio_slave_buf_handle_t recv_queue[BUFFER_NUM];
|
||||||
int packet_size = 0;
|
int packet_size = 0;
|
||||||
@ -266,7 +273,7 @@ void app_main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if there's finished sending desc, return the buffer to receiving driver
|
// if there's finished sending desc, return the buffer to receiving driver
|
||||||
for(;;){
|
for (;;) {
|
||||||
void* send_args = NULL;
|
void* send_args = NULL;
|
||||||
ret = sdio_slave_send_get_finished(&send_args, 0);
|
ret = sdio_slave_send_get_finished(&send_args, 0);
|
||||||
|
|
||||||
@ -281,12 +288,12 @@ void app_main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (s_job != 0) {
|
if (s_job != 0) {
|
||||||
for(int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
if (s_job & BIT(i)) {
|
if (s_job & BIT(i)) {
|
||||||
ESP_LOGI(TAG, EV_STR("%s"), job_desc[i+1]);
|
ESP_LOGI(TAG, EV_STR("%s"), job_desc[i + 1]);
|
||||||
s_job &= ~BIT(i);
|
s_job &= ~BIT(i);
|
||||||
|
|
||||||
switch(BIT(i)) {
|
switch (BIT(i)) {
|
||||||
case JOB_SEND_INT:
|
case JOB_SEND_INT:
|
||||||
ret = task_hostint();
|
ret = task_hostint();
|
||||||
ESP_ERROR_CHECK(ret);
|
ESP_ERROR_CHECK(ret);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
* SPDX-FileContributor: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileContributor: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* This is mbedtls boilerplate for library configuration */
|
/* This is mbedtls boilerplate for library configuration */
|
||||||
@ -46,7 +46,7 @@ static int configure_mbedtls_rng(void)
|
|||||||
|
|
||||||
mbedtls_entropy_init(&entropy);
|
mbedtls_entropy_init(&entropy);
|
||||||
ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
|
ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
|
||||||
(const unsigned char *)seed, strlen(seed));
|
(const unsigned char *)seed, strlen(seed));
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ESP_LOGI(TAG, " failed ! mbedtls_ctr_drbg_seed returned %d", ret);
|
ESP_LOGI(TAG, " failed ! mbedtls_ctr_drbg_seed returned %d", ret);
|
||||||
} else {
|
} else {
|
||||||
@ -108,7 +108,7 @@ static int atca_ecdsa_test(void)
|
|||||||
|
|
||||||
#ifdef MBEDTLS_ECDSA_SIGN_ALT
|
#ifdef MBEDTLS_ECDSA_SIGN_ALT
|
||||||
/* Convert to an mbedtls key */
|
/* Convert to an mbedtls key */
|
||||||
ESP_LOGI(TAG, " Using a hardware private key ..." );
|
ESP_LOGI(TAG, " Using a hardware private key ...");
|
||||||
ret = atca_mbedtls_pk_init(&pkey, 0);
|
ret = atca_mbedtls_pk_init(&pkey, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ESP_LOGI(TAG, " failed ! atca_mbedtls_pk_init returned %02x", ret);
|
ESP_LOGI(TAG, " failed ! atca_mbedtls_pk_init returned %02x", ret);
|
||||||
@ -116,20 +116,20 @@ static int atca_ecdsa_test(void)
|
|||||||
}
|
}
|
||||||
ESP_LOGI(TAG, " ok");
|
ESP_LOGI(TAG, " ok");
|
||||||
#else
|
#else
|
||||||
ESP_LOGI(TAG, " Generating a software private key ..." );
|
ESP_LOGI(TAG, " Generating a software private key ...");
|
||||||
mbedtls_pk_init(&pkey);
|
mbedtls_pk_init(&pkey);
|
||||||
ret = mbedtls_pk_setup(&pkey,
|
ret = mbedtls_pk_setup(&pkey,
|
||||||
mbedtls_pk_info_from_type( MBEDTLS_PK_ECDSA ));
|
mbedtls_pk_info_from_type(MBEDTLS_PK_ECDSA));
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ESP_LOGI(TAG, " failed ! mbedtls_pk_setup returned -0x%04x", -ret );
|
ESP_LOGI(TAG, " failed ! mbedtls_pk_setup returned -0x%04x", -ret);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mbedtls_ecp_gen_key( MBEDTLS_ECP_DP_SECP256R1,
|
ret = mbedtls_ecp_gen_key(MBEDTLS_ECP_DP_SECP256R1,
|
||||||
mbedtls_pk_ec( pkey ),
|
mbedtls_pk_ec(pkey),
|
||||||
mbedtls_ctr_drbg_random, &ctr_drbg );
|
mbedtls_ctr_drbg_random, &ctr_drbg);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ESP_LOGI(TAG, " failed ! mbedtls_ecp_gen_key returned -0x%04x", -ret );
|
ESP_LOGI(TAG, " failed ! mbedtls_ecp_gen_key returned -0x%04x", -ret);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, " ok");
|
ESP_LOGI(TAG, " ok");
|
||||||
@ -137,7 +137,7 @@ static int atca_ecdsa_test(void)
|
|||||||
|
|
||||||
ESP_LOGI(TAG, " Generating ECDSA Signature...");
|
ESP_LOGI(TAG, " Generating ECDSA Signature...");
|
||||||
ret = mbedtls_pk_sign(&pkey, MBEDTLS_MD_SHA256, hash, 0, buf, MBEDTLS_MPI_MAX_SIZE, &olen,
|
ret = mbedtls_pk_sign(&pkey, MBEDTLS_MD_SHA256, hash, 0, buf, MBEDTLS_MPI_MAX_SIZE, &olen,
|
||||||
mbedtls_ctr_drbg_random, &ctr_drbg);
|
mbedtls_ctr_drbg_random, &ctr_drbg);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ESP_LOGI(TAG, " failed ! mbedtls_pk_sign returned -0x%04x", -ret);
|
ESP_LOGI(TAG, " failed ! mbedtls_pk_sign returned -0x%04x", -ret);
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -146,7 +146,7 @@ static int atca_ecdsa_test(void)
|
|||||||
|
|
||||||
ESP_LOGI(TAG, " Verifying ECDSA Signature...");
|
ESP_LOGI(TAG, " Verifying ECDSA Signature...");
|
||||||
ret = mbedtls_pk_verify(&pkey, MBEDTLS_MD_SHA256, hash, 0,
|
ret = mbedtls_pk_verify(&pkey, MBEDTLS_MD_SHA256, hash, 0,
|
||||||
buf, olen);
|
buf, olen);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ESP_LOGI(TAG, " failed ! mbedtls_pk_verify returned -0x%04x", -ret);
|
ESP_LOGI(TAG, " failed ! mbedtls_pk_verify returned -0x%04x", -ret);
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
|
||||||
#define EEPROM_BUSY_TIMEOUT_MS 5
|
#define EEPROM_BUSY_TIMEOUT_MS 5
|
||||||
|
|
||||||
#define EEPROM_CLK_FREQ (1*1000*1000) //When powered by 3.3V, EEPROM max freq is 1MHz
|
#define EEPROM_CLK_FREQ (1*1000*1000) //When powered by 3.3V, EEPROM max freq is 1MHz
|
||||||
@ -42,7 +41,7 @@
|
|||||||
#define ADD_EWEN 0x60
|
#define ADD_EWEN 0x60
|
||||||
|
|
||||||
/// Context (config and data) of the spi_eeprom
|
/// Context (config and data) of the spi_eeprom
|
||||||
struct eeprom_context_t{
|
struct eeprom_context_t {
|
||||||
eeprom_config_t cfg; ///< Configuration by the caller.
|
eeprom_config_t cfg; ///< Configuration by the caller.
|
||||||
spi_device_handle_t spi; ///< SPI device handle
|
spi_device_handle_t spi; ///< SPI device handle
|
||||||
SemaphoreHandle_t ready_sem; ///< Semaphore for ready signal
|
SemaphoreHandle_t ready_sem; ///< Semaphore for ready signal
|
||||||
@ -52,7 +51,6 @@ typedef struct eeprom_context_t eeprom_context_t;
|
|||||||
|
|
||||||
static const char TAG[] = "eeprom";
|
static const char TAG[] = "eeprom";
|
||||||
|
|
||||||
|
|
||||||
// Workaround: The driver depends on some data in the flash and cannot be placed to DRAM easily for
|
// Workaround: The driver depends on some data in the flash and cannot be placed to DRAM easily for
|
||||||
// now. Using the version in LL instead.
|
// now. Using the version in LL instead.
|
||||||
#define gpio_set_level gpio_set_level_patch
|
#define gpio_set_level gpio_set_level_patch
|
||||||
@ -63,7 +61,6 @@ static inline esp_err_t gpio_set_level_patch(gpio_num_t gpio_num, uint32_t level
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static esp_err_t eeprom_simple_cmd(eeprom_context_t *ctx, uint16_t cmd)
|
static esp_err_t eeprom_simple_cmd(eeprom_context_t *ctx, uint16_t cmd)
|
||||||
{
|
{
|
||||||
spi_transaction_t t = {
|
spi_transaction_t t = {
|
||||||
@ -89,7 +86,9 @@ static esp_err_t eeprom_wait_done(eeprom_context_t* ctx)
|
|||||||
gpio_intr_disable(ctx->cfg.miso_io);
|
gpio_intr_disable(ctx->cfg.miso_io);
|
||||||
gpio_set_level(ctx->cfg.cs_io, 0);
|
gpio_set_level(ctx->cfg.cs_io, 0);
|
||||||
|
|
||||||
if (ret != pdTRUE) return ESP_ERR_TIMEOUT;
|
if (ret != pdTRUE) {
|
||||||
|
return ESP_ERR_TIMEOUT;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
bool timeout = true;
|
bool timeout = true;
|
||||||
gpio_set_level(ctx->cfg.cs_io, 1);
|
gpio_set_level(ctx->cfg.cs_io, 1);
|
||||||
@ -101,7 +100,9 @@ static esp_err_t eeprom_wait_done(eeprom_context_t* ctx)
|
|||||||
usleep(1);
|
usleep(1);
|
||||||
}
|
}
|
||||||
gpio_set_level(ctx->cfg.cs_io, 0);
|
gpio_set_level(ctx->cfg.cs_io, 0);
|
||||||
if (timeout) return ESP_ERR_TIMEOUT;
|
if (timeout) {
|
||||||
|
return ESP_ERR_TIMEOUT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@ -144,13 +145,15 @@ esp_err_t spi_eeprom_init(const eeprom_config_t *cfg, eeprom_context_t** out_ctx
|
|||||||
}
|
}
|
||||||
|
|
||||||
eeprom_context_t* ctx = (eeprom_context_t*)malloc(sizeof(eeprom_context_t));
|
eeprom_context_t* ctx = (eeprom_context_t*)malloc(sizeof(eeprom_context_t));
|
||||||
if (!ctx) return ESP_ERR_NO_MEM;
|
if (!ctx) {
|
||||||
|
return ESP_ERR_NO_MEM;
|
||||||
|
}
|
||||||
|
|
||||||
*ctx = (eeprom_context_t) {
|
*ctx = (eeprom_context_t) {
|
||||||
.cfg = *cfg,
|
.cfg = *cfg,
|
||||||
};
|
};
|
||||||
|
|
||||||
spi_device_interface_config_t devcfg={
|
spi_device_interface_config_t devcfg = {
|
||||||
.command_bits = 10,
|
.command_bits = 10,
|
||||||
.clock_speed_hz = EEPROM_CLK_FREQ,
|
.clock_speed_hz = EEPROM_CLK_FREQ,
|
||||||
.mode = 0, //SPI mode 0
|
.mode = 0, //SPI mode 0
|
||||||
@ -167,7 +170,7 @@ esp_err_t spi_eeprom_init(const eeprom_config_t *cfg, eeprom_context_t** out_ctx
|
|||||||
};
|
};
|
||||||
//Attach the EEPROM to the SPI bus
|
//Attach the EEPROM to the SPI bus
|
||||||
err = spi_bus_add_device(ctx->cfg.host, &devcfg, &ctx->spi);
|
err = spi_bus_add_device(ctx->cfg.host, &devcfg, &ctx->spi);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +220,9 @@ esp_err_t spi_eeprom_read(eeprom_context_t* ctx, uint8_t addr, uint8_t* out_data
|
|||||||
.user = ctx,
|
.user = ctx,
|
||||||
};
|
};
|
||||||
esp_err_t err = spi_device_polling_transmit(ctx->spi, &t);
|
esp_err_t err = spi_device_polling_transmit(ctx->spi, &t);
|
||||||
if (err!= ESP_OK) return err;
|
if (err != ESP_OK) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
*out_data = t.rx_data[0];
|
*out_data = t.rx_data[0];
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
@ -227,7 +232,9 @@ esp_err_t spi_eeprom_erase(eeprom_context_t* ctx, uint8_t addr)
|
|||||||
{
|
{
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
err = spi_device_acquire_bus(ctx->spi, portMAX_DELAY);
|
err = spi_device_acquire_bus(ctx->spi, portMAX_DELAY);
|
||||||
if (err != ESP_OK) return err;
|
if (err != ESP_OK) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
err = eeprom_simple_cmd(ctx, CMD_ERASE | (addr & ADDR_MASK));
|
err = eeprom_simple_cmd(ctx, CMD_ERASE | (addr & ADDR_MASK));
|
||||||
|
|
||||||
@ -243,7 +250,9 @@ esp_err_t spi_eeprom_write(eeprom_context_t* ctx, uint8_t addr, uint8_t data)
|
|||||||
{
|
{
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
err = spi_device_acquire_bus(ctx->spi, portMAX_DELAY);
|
err = spi_device_acquire_bus(ctx->spi, portMAX_DELAY);
|
||||||
if (err != ESP_OK) return err;
|
if (err != ESP_OK) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
spi_transaction_t t = {
|
spi_transaction_t t = {
|
||||||
.cmd = CMD_WRITE | (addr & ADDR_MASK),
|
.cmd = CMD_WRITE | (addr & ADDR_MASK),
|
||||||
@ -282,7 +291,9 @@ esp_err_t spi_eeprom_erase_all(eeprom_context_t* ctx)
|
|||||||
|
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
err = spi_device_acquire_bus(ctx->spi, portMAX_DELAY);
|
err = spi_device_acquire_bus(ctx->spi, portMAX_DELAY);
|
||||||
if (err != ESP_OK) return err;
|
if (err != ESP_OK) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
err = eeprom_simple_cmd(ctx, CMD_ERAL | ADD_ERAL);
|
err = eeprom_simple_cmd(ctx, CMD_ERAL | ADD_ERAL);
|
||||||
|
|
||||||
@ -304,7 +315,9 @@ esp_err_t spi_eeprom_write_all(eeprom_context_t* ctx, uint8_t data)
|
|||||||
|
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
err = spi_device_acquire_bus(ctx->spi, portMAX_DELAY);
|
err = spi_device_acquire_bus(ctx->spi, portMAX_DELAY);
|
||||||
if (err != ESP_OK) return err;
|
if (err != ESP_OK) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
spi_transaction_t t = {
|
spi_transaction_t t = {
|
||||||
.cmd = CMD_WRAL | ADD_WRAL,
|
.cmd = CMD_WRAL | ADD_WRAL,
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "spi_eeprom.h"
|
#include "spi_eeprom.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This code demonstrates how to use the SPI master half duplex mode to read/write a AT932C46D EEPROM (8-bit mode).
|
This code demonstrates how to use the SPI master half duplex mode to read/write a AT932C46D EEPROM (8-bit mode).
|
||||||
*/
|
*/
|
||||||
@ -70,15 +69,14 @@
|
|||||||
# define PIN_NUM_CS 1
|
# define PIN_NUM_CS 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static const char TAG[] = "main";
|
static const char TAG[] = "main";
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
#ifndef CONFIG_EXAMPLE_USE_SPI1_PINS
|
#ifndef CONFIG_EXAMPLE_USE_SPI1_PINS
|
||||||
ESP_LOGI(TAG, "Initializing bus SPI%d...", EEPROM_HOST+1);
|
ESP_LOGI(TAG, "Initializing bus SPI%d...", EEPROM_HOST + 1);
|
||||||
spi_bus_config_t buscfg={
|
spi_bus_config_t buscfg = {
|
||||||
.miso_io_num = PIN_NUM_MISO,
|
.miso_io_num = PIN_NUM_MISO,
|
||||||
.mosi_io_num = PIN_NUM_MOSI,
|
.mosi_io_num = PIN_NUM_MOSI,
|
||||||
.sclk_io_num = PIN_NUM_CLK,
|
.sclk_io_num = PIN_NUM_CLK,
|
||||||
|
@ -20,11 +20,11 @@ uint16_t *pixels;
|
|||||||
static inline uint16_t get_bgnd_pixel(int x, int y)
|
static inline uint16_t get_bgnd_pixel(int x, int y)
|
||||||
{
|
{
|
||||||
//Get color of the pixel on x,y coords
|
//Get color of the pixel on x,y coords
|
||||||
return (uint16_t) *(pixels + (y * IMAGE_W) + x);
|
return (uint16_t) * (pixels + (y * IMAGE_W) + x);
|
||||||
}
|
}
|
||||||
|
|
||||||
//This variable is used to detect the next frame.
|
//This variable is used to detect the next frame.
|
||||||
static int prev_frame=-1;
|
static int prev_frame = -1;
|
||||||
|
|
||||||
//Instead of calculating the offsets for each pixel we grab, we pre-calculate the valueswhenever a frame changes, then re-use
|
//Instead of calculating the offsets for each pixel we grab, we pre-calculate the valueswhenever a frame changes, then re-use
|
||||||
//these as we go through all the pixels in the frame. This is much, much faster.
|
//these as we go through all the pixels in the frame. This is much, much faster.
|
||||||
@ -36,23 +36,30 @@ static int8_t xcomp[320], ycomp[240];
|
|||||||
//is displayed; this is used to go to the next frame of animation.
|
//is displayed; this is used to go to the next frame of animation.
|
||||||
void pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect)
|
void pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect)
|
||||||
{
|
{
|
||||||
if (frame!=prev_frame) {
|
if (frame != prev_frame) {
|
||||||
//We need to calculate a new set of offset coefficients. Take some random sines as offsets to make everything
|
//We need to calculate a new set of offset coefficients. Take some random sines as offsets to make everything
|
||||||
//look pretty and fluid-y.
|
//look pretty and fluid-y.
|
||||||
for (int x=0; x<320; x++) xofs[x]=sin(frame*0.15+x*0.06)*4;
|
for (int x = 0; x < 320; x++) {
|
||||||
for (int y=0; y<240; y++) yofs[y]=sin(frame*0.1+y*0.05)*4;
|
xofs[x] = sin(frame * 0.15 + x * 0.06) * 4;
|
||||||
for (int x=0; x<320; x++) xcomp[x]=sin(frame*0.11+x*0.12)*4;
|
}
|
||||||
for (int y=0; y<240; y++) ycomp[y]=sin(frame*0.07+y*0.15)*4;
|
for (int y = 0; y < 240; y++) {
|
||||||
prev_frame=frame;
|
yofs[y] = sin(frame * 0.1 + y * 0.05) * 4;
|
||||||
|
}
|
||||||
|
for (int x = 0; x < 320; x++) {
|
||||||
|
xcomp[x] = sin(frame * 0.11 + x * 0.12) * 4;
|
||||||
|
}
|
||||||
|
for (int y = 0; y < 240; y++) {
|
||||||
|
ycomp[y] = sin(frame * 0.07 + y * 0.15) * 4;
|
||||||
|
}
|
||||||
|
prev_frame = frame;
|
||||||
}
|
}
|
||||||
for (int y=line; y<line+linect; y++) {
|
for (int y = line; y < line + linect; y++) {
|
||||||
for (int x=0; x<320; x++) {
|
for (int x = 0; x < 320; x++) {
|
||||||
*dest++=get_bgnd_pixel(x+yofs[y]+xcomp[x], y+xofs[x]+ycomp[y]);
|
*dest++ = get_bgnd_pixel(x + yofs[y] + xcomp[x], y + xofs[x] + ycomp[y]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esp_err_t pretty_effect_init(void)
|
esp_err_t pretty_effect_init(void)
|
||||||
{
|
{
|
||||||
return decode_image(&pixels);
|
return decode_image(&pixels);
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calculate the effect for a bunch of lines.
|
* @brief Calculate the effect for a bunch of lines.
|
||||||
*
|
*
|
||||||
@ -25,7 +24,6 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
void pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect);
|
void pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the effect
|
* @brief Initialize the effect
|
||||||
*
|
*
|
||||||
|
@ -96,9 +96,9 @@ typedef enum {
|
|||||||
} type_lcd_t;
|
} type_lcd_t;
|
||||||
|
|
||||||
//Place data into DRAM. Constant data gets placed into DROM by default, which is not accessible by DMA.
|
//Place data into DRAM. Constant data gets placed into DROM by default, which is not accessible by DMA.
|
||||||
DRAM_ATTR static const lcd_init_cmd_t st_init_cmds[]={
|
DRAM_ATTR static const lcd_init_cmd_t st_init_cmds[] = {
|
||||||
/* Memory Data Access Control, MX=MV=1, MY=ML=MH=0, RGB=0 */
|
/* Memory Data Access Control, MX=MV=1, MY=ML=MH=0, RGB=0 */
|
||||||
{0x36, {(1<<5)|(1<<6)}, 1},
|
{0x36, {(1 << 5) | (1 << 6)}, 1},
|
||||||
/* Interface Pixel Format, 16bits/pixel for RGB/MCU interface */
|
/* Interface Pixel Format, 16bits/pixel for RGB/MCU interface */
|
||||||
{0x3A, {0x55}, 1},
|
{0x3A, {0x55}, 1},
|
||||||
/* Porch Setting */
|
/* Porch Setting */
|
||||||
@ -130,7 +130,7 @@ DRAM_ATTR static const lcd_init_cmd_t st_init_cmds[]={
|
|||||||
{0, {0}, 0xff}
|
{0, {0}, 0xff}
|
||||||
};
|
};
|
||||||
|
|
||||||
DRAM_ATTR static const lcd_init_cmd_t ili_init_cmds[]={
|
DRAM_ATTR static const lcd_init_cmd_t ili_init_cmds[] = {
|
||||||
/* Power contorl B, power control = 0, DC_ENA = 1 */
|
/* Power contorl B, power control = 0, DC_ENA = 1 */
|
||||||
{0xCF, {0x00, 0x83, 0X30}, 3},
|
{0xCF, {0x00, 0x83, 0X30}, 3},
|
||||||
/* Power on sequence control,
|
/* Power on sequence control,
|
||||||
@ -202,14 +202,14 @@ void lcd_cmd(spi_device_handle_t spi, const uint8_t cmd, bool keep_cs_active)
|
|||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
spi_transaction_t t;
|
spi_transaction_t t;
|
||||||
memset(&t, 0, sizeof(t)); //Zero out the transaction
|
memset(&t, 0, sizeof(t)); //Zero out the transaction
|
||||||
t.length=8; //Command is 8 bits
|
t.length = 8; //Command is 8 bits
|
||||||
t.tx_buffer=&cmd; //The data is the cmd itself
|
t.tx_buffer = &cmd; //The data is the cmd itself
|
||||||
t.user=(void*)0; //D/C needs to be set to 0
|
t.user = (void*)0; //D/C needs to be set to 0
|
||||||
if (keep_cs_active) {
|
if (keep_cs_active) {
|
||||||
t.flags = SPI_TRANS_CS_KEEP_ACTIVE; //Keep CS active after data transfer
|
t.flags = SPI_TRANS_CS_KEEP_ACTIVE; //Keep CS active after data transfer
|
||||||
}
|
}
|
||||||
ret=spi_device_polling_transmit(spi, &t); //Transmit!
|
ret = spi_device_polling_transmit(spi, &t); //Transmit!
|
||||||
assert(ret==ESP_OK); //Should have had no issues.
|
assert(ret == ESP_OK); //Should have had no issues.
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send data to the LCD. Uses spi_device_polling_transmit, which waits until the
|
/* Send data to the LCD. Uses spi_device_polling_transmit, which waits until the
|
||||||
@ -223,20 +223,22 @@ void lcd_data(spi_device_handle_t spi, const uint8_t *data, int len)
|
|||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
spi_transaction_t t;
|
spi_transaction_t t;
|
||||||
if (len==0) return; //no need to send anything
|
if (len == 0) {
|
||||||
|
return; //no need to send anything
|
||||||
|
}
|
||||||
memset(&t, 0, sizeof(t)); //Zero out the transaction
|
memset(&t, 0, sizeof(t)); //Zero out the transaction
|
||||||
t.length=len*8; //Len is in bytes, transaction length is in bits.
|
t.length = len * 8; //Len is in bytes, transaction length is in bits.
|
||||||
t.tx_buffer=data; //Data
|
t.tx_buffer = data; //Data
|
||||||
t.user=(void*)1; //D/C needs to be set to 1
|
t.user = (void*)1; //D/C needs to be set to 1
|
||||||
ret=spi_device_polling_transmit(spi, &t); //Transmit!
|
ret = spi_device_polling_transmit(spi, &t); //Transmit!
|
||||||
assert(ret==ESP_OK); //Should have had no issues.
|
assert(ret == ESP_OK); //Should have had no issues.
|
||||||
}
|
}
|
||||||
|
|
||||||
//This function is called (in irq context!) just before a transmission starts. It will
|
//This function is called (in irq context!) just before a transmission starts. It will
|
||||||
//set the D/C line to the value indicated in the user field.
|
//set the D/C line to the value indicated in the user field.
|
||||||
void lcd_spi_pre_transfer_callback(spi_transaction_t *t)
|
void lcd_spi_pre_transfer_callback(spi_transaction_t *t)
|
||||||
{
|
{
|
||||||
int dc=(int)t->user;
|
int dc = (int)t->user;
|
||||||
gpio_set_level(PIN_NUM_DC, dc);
|
gpio_set_level(PIN_NUM_DC, dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,12 +252,12 @@ uint32_t lcd_get_id(spi_device_handle_t spi)
|
|||||||
|
|
||||||
spi_transaction_t t;
|
spi_transaction_t t;
|
||||||
memset(&t, 0, sizeof(t));
|
memset(&t, 0, sizeof(t));
|
||||||
t.length=8*3;
|
t.length = 8 * 3;
|
||||||
t.flags = SPI_TRANS_USE_RXDATA;
|
t.flags = SPI_TRANS_USE_RXDATA;
|
||||||
t.user = (void*)1;
|
t.user = (void*)1;
|
||||||
|
|
||||||
esp_err_t ret = spi_device_polling_transmit(spi, &t);
|
esp_err_t ret = spi_device_polling_transmit(spi, &t);
|
||||||
assert( ret == ESP_OK );
|
assert(ret == ESP_OK);
|
||||||
|
|
||||||
// Release bus
|
// Release bus
|
||||||
spi_device_release_bus(spi);
|
spi_device_release_bus(spi);
|
||||||
@ -266,12 +268,12 @@ uint32_t lcd_get_id(spi_device_handle_t spi)
|
|||||||
//Initialize the display
|
//Initialize the display
|
||||||
void lcd_init(spi_device_handle_t spi)
|
void lcd_init(spi_device_handle_t spi)
|
||||||
{
|
{
|
||||||
int cmd=0;
|
int cmd = 0;
|
||||||
const lcd_init_cmd_t* lcd_init_cmds;
|
const lcd_init_cmd_t* lcd_init_cmds;
|
||||||
|
|
||||||
//Initialize non-SPI GPIOs
|
//Initialize non-SPI GPIOs
|
||||||
gpio_config_t io_conf = {};
|
gpio_config_t io_conf = {};
|
||||||
io_conf.pin_bit_mask = ((1ULL<<PIN_NUM_DC) | (1ULL<<PIN_NUM_RST) | (1ULL<<PIN_NUM_BCKL));
|
io_conf.pin_bit_mask = ((1ULL << PIN_NUM_DC) | (1ULL << PIN_NUM_RST) | (1ULL << PIN_NUM_BCKL));
|
||||||
io_conf.mode = GPIO_MODE_OUTPUT;
|
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||||
io_conf.pull_up_en = true;
|
io_conf.pull_up_en = true;
|
||||||
gpio_config(&io_conf);
|
gpio_config(&io_conf);
|
||||||
@ -288,7 +290,7 @@ void lcd_init(spi_device_handle_t spi)
|
|||||||
int lcd_type;
|
int lcd_type;
|
||||||
|
|
||||||
printf("LCD ID: %08"PRIx32"\n", lcd_id);
|
printf("LCD ID: %08"PRIx32"\n", lcd_id);
|
||||||
if ( lcd_id == 0 ) {
|
if (lcd_id == 0) {
|
||||||
//zero, ili
|
//zero, ili
|
||||||
lcd_detected_type = LCD_TYPE_ILI;
|
lcd_detected_type = LCD_TYPE_ILI;
|
||||||
printf("ILI9341 detected.\n");
|
printf("ILI9341 detected.\n");
|
||||||
@ -307,7 +309,7 @@ void lcd_init(spi_device_handle_t spi)
|
|||||||
printf("kconfig: force CONFIG_LCD_TYPE_ILI9341.\n");
|
printf("kconfig: force CONFIG_LCD_TYPE_ILI9341.\n");
|
||||||
lcd_type = LCD_TYPE_ILI;
|
lcd_type = LCD_TYPE_ILI;
|
||||||
#endif
|
#endif
|
||||||
if ( lcd_type == LCD_TYPE_ST ) {
|
if (lcd_type == LCD_TYPE_ST) {
|
||||||
printf("LCD ST7789V initialization.\n");
|
printf("LCD ST7789V initialization.\n");
|
||||||
lcd_init_cmds = st_init_cmds;
|
lcd_init_cmds = st_init_cmds;
|
||||||
} else {
|
} else {
|
||||||
@ -316,10 +318,10 @@ void lcd_init(spi_device_handle_t spi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Send all the commands
|
//Send all the commands
|
||||||
while (lcd_init_cmds[cmd].databytes!=0xff) {
|
while (lcd_init_cmds[cmd].databytes != 0xff) {
|
||||||
lcd_cmd(spi, lcd_init_cmds[cmd].cmd, false);
|
lcd_cmd(spi, lcd_init_cmds[cmd].cmd, false);
|
||||||
lcd_data(spi, lcd_init_cmds[cmd].data, lcd_init_cmds[cmd].databytes&0x1F);
|
lcd_data(spi, lcd_init_cmds[cmd].data, lcd_init_cmds[cmd].databytes & 0x1F);
|
||||||
if (lcd_init_cmds[cmd].databytes&0x80) {
|
if (lcd_init_cmds[cmd].databytes & 0x80) {
|
||||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
cmd++;
|
cmd++;
|
||||||
@ -329,7 +331,6 @@ void lcd_init(spi_device_handle_t spi)
|
|||||||
gpio_set_level(PIN_NUM_BCKL, 0);
|
gpio_set_level(PIN_NUM_BCKL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* To send a set of lines we have to send a command, 2 data bytes, another command, 2 more data bytes and another command
|
/* To send a set of lines we have to send a command, 2 data bytes, another command, 2 more data bytes and another command
|
||||||
* before sending the line data itself; a total of 6 transactions. (We can't put all of this in just one transaction
|
* before sending the line data itself; a total of 6 transactions. (We can't put all of this in just one transaction
|
||||||
* because the D/C line needs to be toggled in the middle.)
|
* because the D/C line needs to be toggled in the middle.)
|
||||||
@ -347,38 +348,38 @@ static void send_lines(spi_device_handle_t spi, int ypos, uint16_t *linedata)
|
|||||||
|
|
||||||
//In theory, it's better to initialize trans and data only once and hang on to the initialized
|
//In theory, it's better to initialize trans and data only once and hang on to the initialized
|
||||||
//variables. We allocate them on the stack, so we need to re-init them each call.
|
//variables. We allocate them on the stack, so we need to re-init them each call.
|
||||||
for (x=0; x<6; x++) {
|
for (x = 0; x < 6; x++) {
|
||||||
memset(&trans[x], 0, sizeof(spi_transaction_t));
|
memset(&trans[x], 0, sizeof(spi_transaction_t));
|
||||||
if ((x&1)==0) {
|
if ((x & 1) == 0) {
|
||||||
//Even transfers are commands
|
//Even transfers are commands
|
||||||
trans[x].length=8;
|
trans[x].length = 8;
|
||||||
trans[x].user=(void*)0;
|
trans[x].user = (void*)0;
|
||||||
} else {
|
} else {
|
||||||
//Odd transfers are data
|
//Odd transfers are data
|
||||||
trans[x].length=8*4;
|
trans[x].length = 8 * 4;
|
||||||
trans[x].user=(void*)1;
|
trans[x].user = (void*)1;
|
||||||
}
|
}
|
||||||
trans[x].flags=SPI_TRANS_USE_TXDATA;
|
trans[x].flags = SPI_TRANS_USE_TXDATA;
|
||||||
}
|
}
|
||||||
trans[0].tx_data[0]=0x2A; //Column Address Set
|
trans[0].tx_data[0] = 0x2A; //Column Address Set
|
||||||
trans[1].tx_data[0]=0; //Start Col High
|
trans[1].tx_data[0] = 0; //Start Col High
|
||||||
trans[1].tx_data[1]=0; //Start Col Low
|
trans[1].tx_data[1] = 0; //Start Col Low
|
||||||
trans[1].tx_data[2]=(320)>>8; //End Col High
|
trans[1].tx_data[2] = (320) >> 8; //End Col High
|
||||||
trans[1].tx_data[3]=(320)&0xff; //End Col Low
|
trans[1].tx_data[3] = (320) & 0xff; //End Col Low
|
||||||
trans[2].tx_data[0]=0x2B; //Page address set
|
trans[2].tx_data[0] = 0x2B; //Page address set
|
||||||
trans[3].tx_data[0]=ypos>>8; //Start page high
|
trans[3].tx_data[0] = ypos >> 8; //Start page high
|
||||||
trans[3].tx_data[1]=ypos&0xff; //start page low
|
trans[3].tx_data[1] = ypos & 0xff; //start page low
|
||||||
trans[3].tx_data[2]=(ypos+PARALLEL_LINES)>>8; //end page high
|
trans[3].tx_data[2] = (ypos + PARALLEL_LINES) >> 8; //end page high
|
||||||
trans[3].tx_data[3]=(ypos+PARALLEL_LINES)&0xff; //end page low
|
trans[3].tx_data[3] = (ypos + PARALLEL_LINES) & 0xff; //end page low
|
||||||
trans[4].tx_data[0]=0x2C; //memory write
|
trans[4].tx_data[0] = 0x2C; //memory write
|
||||||
trans[5].tx_buffer=linedata; //finally send the line data
|
trans[5].tx_buffer = linedata; //finally send the line data
|
||||||
trans[5].length=320*2*8*PARALLEL_LINES; //Data length, in bits
|
trans[5].length = 320 * 2 * 8 * PARALLEL_LINES; //Data length, in bits
|
||||||
trans[5].flags=0; //undo SPI_TRANS_USE_TXDATA flag
|
trans[5].flags = 0; //undo SPI_TRANS_USE_TXDATA flag
|
||||||
|
|
||||||
//Queue all transactions.
|
//Queue all transactions.
|
||||||
for (x=0; x<6; x++) {
|
for (x = 0; x < 6; x++) {
|
||||||
ret=spi_device_queue_trans(spi, &trans[x], portMAX_DELAY);
|
ret = spi_device_queue_trans(spi, &trans[x], portMAX_DELAY);
|
||||||
assert(ret==ESP_OK);
|
assert(ret == ESP_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
//When we are here, the SPI driver is busy (in the background) getting the transactions sent. That happens
|
//When we are here, the SPI driver is busy (in the background) getting the transactions sent. That happens
|
||||||
@ -387,20 +388,18 @@ static void send_lines(spi_device_handle_t spi, int ypos, uint16_t *linedata)
|
|||||||
//send_line_finish, which will wait for the transfers to be done and check their status.
|
//send_line_finish, which will wait for the transfers to be done and check their status.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void send_line_finish(spi_device_handle_t spi)
|
static void send_line_finish(spi_device_handle_t spi)
|
||||||
{
|
{
|
||||||
spi_transaction_t *rtrans;
|
spi_transaction_t *rtrans;
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
//Wait for all 6 transactions to be done and get back the results.
|
//Wait for all 6 transactions to be done and get back the results.
|
||||||
for (int x=0; x<6; x++) {
|
for (int x = 0; x < 6; x++) {
|
||||||
ret=spi_device_get_trans_result(spi, &rtrans, portMAX_DELAY);
|
ret = spi_device_get_trans_result(spi, &rtrans, portMAX_DELAY);
|
||||||
assert(ret==ESP_OK);
|
assert(ret == ESP_OK);
|
||||||
//We could inspect rtrans now if we received any info back. The LCD is treated as write-only, though.
|
//We could inspect rtrans now if we received any info back. The LCD is treated as write-only, though.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Simple routine to generate some patterns and send them to the LCD. Don't expect anything too
|
//Simple routine to generate some patterns and send them to the LCD. Don't expect anything too
|
||||||
//impressive. Because the SPI driver handles transactions in the background, we can calculate the next line
|
//impressive. Because the SPI driver handles transactions in the background, we can calculate the next line
|
||||||
//while the previous one is being sent.
|
//while the previous one is being sent.
|
||||||
@ -408,25 +407,27 @@ static void display_pretty_colors(spi_device_handle_t spi)
|
|||||||
{
|
{
|
||||||
uint16_t *lines[2];
|
uint16_t *lines[2];
|
||||||
//Allocate memory for the pixel buffers
|
//Allocate memory for the pixel buffers
|
||||||
for (int i=0; i<2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
lines[i]=heap_caps_malloc(320*PARALLEL_LINES*sizeof(uint16_t), MALLOC_CAP_DMA);
|
lines[i] = heap_caps_malloc(320 * PARALLEL_LINES * sizeof(uint16_t), MALLOC_CAP_DMA);
|
||||||
assert(lines[i]!=NULL);
|
assert(lines[i] != NULL);
|
||||||
}
|
}
|
||||||
int frame=0;
|
int frame = 0;
|
||||||
//Indexes of the line currently being sent to the LCD and the line we're calculating.
|
//Indexes of the line currently being sent to the LCD and the line we're calculating.
|
||||||
int sending_line=-1;
|
int sending_line = -1;
|
||||||
int calc_line=0;
|
int calc_line = 0;
|
||||||
|
|
||||||
while(1) {
|
while (1) {
|
||||||
frame++;
|
frame++;
|
||||||
for (int y=0; y<240; y+=PARALLEL_LINES) {
|
for (int y = 0; y < 240; y += PARALLEL_LINES) {
|
||||||
//Calculate a line.
|
//Calculate a line.
|
||||||
pretty_effect_calc_lines(lines[calc_line], y, frame, PARALLEL_LINES);
|
pretty_effect_calc_lines(lines[calc_line], y, frame, PARALLEL_LINES);
|
||||||
//Finish up the sending process of the previous line, if any
|
//Finish up the sending process of the previous line, if any
|
||||||
if (sending_line!=-1) send_line_finish(spi);
|
if (sending_line != -1) {
|
||||||
|
send_line_finish(spi);
|
||||||
|
}
|
||||||
//Swap sending_line and calc_line
|
//Swap sending_line and calc_line
|
||||||
sending_line=calc_line;
|
sending_line = calc_line;
|
||||||
calc_line=(calc_line==1)?0:1;
|
calc_line = (calc_line == 1) ? 0 : 1;
|
||||||
//Send the line we currently calculated.
|
//Send the line we currently calculated.
|
||||||
send_lines(spi, y, lines[sending_line]);
|
send_lines(spi, y, lines[sending_line]);
|
||||||
//The line set is queued up for sending now; the actual sending happens in the
|
//The line set is queued up for sending now; the actual sending happens in the
|
||||||
@ -440,35 +441,35 @@ void app_main(void)
|
|||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
spi_device_handle_t spi;
|
spi_device_handle_t spi;
|
||||||
spi_bus_config_t buscfg={
|
spi_bus_config_t buscfg = {
|
||||||
.miso_io_num=PIN_NUM_MISO,
|
.miso_io_num = PIN_NUM_MISO,
|
||||||
.mosi_io_num=PIN_NUM_MOSI,
|
.mosi_io_num = PIN_NUM_MOSI,
|
||||||
.sclk_io_num=PIN_NUM_CLK,
|
.sclk_io_num = PIN_NUM_CLK,
|
||||||
.quadwp_io_num=-1,
|
.quadwp_io_num = -1,
|
||||||
.quadhd_io_num=-1,
|
.quadhd_io_num = -1,
|
||||||
.max_transfer_sz=PARALLEL_LINES*320*2+8
|
.max_transfer_sz = PARALLEL_LINES * 320 * 2 + 8
|
||||||
};
|
};
|
||||||
spi_device_interface_config_t devcfg={
|
spi_device_interface_config_t devcfg = {
|
||||||
#ifdef CONFIG_LCD_OVERCLOCK
|
#ifdef CONFIG_LCD_OVERCLOCK
|
||||||
.clock_speed_hz=26*1000*1000, //Clock out at 26 MHz
|
.clock_speed_hz = 26 * 1000 * 1000, //Clock out at 26 MHz
|
||||||
#else
|
#else
|
||||||
.clock_speed_hz=10*1000*1000, //Clock out at 10 MHz
|
.clock_speed_hz = 10 * 1000 * 1000, //Clock out at 10 MHz
|
||||||
#endif
|
#endif
|
||||||
.mode=0, //SPI mode 0
|
.mode = 0, //SPI mode 0
|
||||||
.spics_io_num=PIN_NUM_CS, //CS pin
|
.spics_io_num = PIN_NUM_CS, //CS pin
|
||||||
.queue_size=7, //We want to be able to queue 7 transactions at a time
|
.queue_size = 7, //We want to be able to queue 7 transactions at a time
|
||||||
.pre_cb=lcd_spi_pre_transfer_callback, //Specify pre-transfer callback to handle D/C line
|
.pre_cb = lcd_spi_pre_transfer_callback, //Specify pre-transfer callback to handle D/C line
|
||||||
};
|
};
|
||||||
//Initialize the SPI bus
|
//Initialize the SPI bus
|
||||||
ret=spi_bus_initialize(LCD_HOST, &buscfg, SPI_DMA_CH_AUTO);
|
ret = spi_bus_initialize(LCD_HOST, &buscfg, SPI_DMA_CH_AUTO);
|
||||||
ESP_ERROR_CHECK(ret);
|
ESP_ERROR_CHECK(ret);
|
||||||
//Attach the LCD to the SPI bus
|
//Attach the LCD to the SPI bus
|
||||||
ret=spi_bus_add_device(LCD_HOST, &devcfg, &spi);
|
ret = spi_bus_add_device(LCD_HOST, &devcfg, &spi);
|
||||||
ESP_ERROR_CHECK(ret);
|
ESP_ERROR_CHECK(ret);
|
||||||
//Initialize the LCD
|
//Initialize the LCD
|
||||||
lcd_init(spi);
|
lcd_init(spi);
|
||||||
//Initialize the effect displayed
|
//Initialize the effect displayed
|
||||||
ret=pretty_effect_init();
|
ret = pretty_effect_init();
|
||||||
ESP_ERROR_CHECK(ret);
|
ESP_ERROR_CHECK(ret);
|
||||||
|
|
||||||
//Go do nice stuff.
|
//Go do nice stuff.
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#include "driver/spi_slave.h"
|
#include "driver/spi_slave.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
SPI receiver (slave) example.
|
SPI receiver (slave) example.
|
||||||
|
|
||||||
@ -71,7 +70,6 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i
|
|||||||
|
|
||||||
#endif //CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
|
#endif //CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
|
||||||
|
|
||||||
|
|
||||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||||
#define RCV_HOST HSPI_HOST
|
#define RCV_HOST HSPI_HOST
|
||||||
|
|
||||||
@ -80,48 +78,48 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Called after a transaction is queued and ready for pickup by master. We use this to set the handshake line high.
|
//Called after a transaction is queued and ready for pickup by master. We use this to set the handshake line high.
|
||||||
void my_post_setup_cb(spi_slave_transaction_t *trans) {
|
void my_post_setup_cb(spi_slave_transaction_t *trans)
|
||||||
|
{
|
||||||
gpio_set_level(GPIO_HANDSHAKE, 1);
|
gpio_set_level(GPIO_HANDSHAKE, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Called after transaction is sent/received. We use this to set the handshake line low.
|
//Called after transaction is sent/received. We use this to set the handshake line low.
|
||||||
void my_post_trans_cb(spi_slave_transaction_t *trans) {
|
void my_post_trans_cb(spi_slave_transaction_t *trans)
|
||||||
|
{
|
||||||
gpio_set_level(GPIO_HANDSHAKE, 0);
|
gpio_set_level(GPIO_HANDSHAKE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Main application
|
//Main application
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
int n=0;
|
int n = 0;
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
|
|
||||||
//Configuration for the SPI bus
|
//Configuration for the SPI bus
|
||||||
spi_bus_config_t buscfg={
|
spi_bus_config_t buscfg = {
|
||||||
.mosi_io_num=GPIO_MOSI,
|
.mosi_io_num = GPIO_MOSI,
|
||||||
.miso_io_num=GPIO_MISO,
|
.miso_io_num = GPIO_MISO,
|
||||||
.sclk_io_num=GPIO_SCLK,
|
.sclk_io_num = GPIO_SCLK,
|
||||||
.quadwp_io_num = -1,
|
.quadwp_io_num = -1,
|
||||||
.quadhd_io_num = -1,
|
.quadhd_io_num = -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
//Configuration for the SPI slave interface
|
//Configuration for the SPI slave interface
|
||||||
spi_slave_interface_config_t slvcfg={
|
spi_slave_interface_config_t slvcfg = {
|
||||||
.mode=0,
|
.mode = 0,
|
||||||
.spics_io_num=GPIO_CS,
|
.spics_io_num = GPIO_CS,
|
||||||
.queue_size=3,
|
.queue_size = 3,
|
||||||
.flags=0,
|
.flags = 0,
|
||||||
.post_setup_cb=my_post_setup_cb,
|
.post_setup_cb = my_post_setup_cb,
|
||||||
.post_trans_cb=my_post_trans_cb
|
.post_trans_cb = my_post_trans_cb
|
||||||
};
|
};
|
||||||
|
|
||||||
//Configuration for the handshake line
|
//Configuration for the handshake line
|
||||||
gpio_config_t io_conf={
|
gpio_config_t io_conf = {
|
||||||
.intr_type=GPIO_INTR_DISABLE,
|
.intr_type = GPIO_INTR_DISABLE,
|
||||||
.mode=GPIO_MODE_OUTPUT,
|
.mode = GPIO_MODE_OUTPUT,
|
||||||
.pin_bit_mask=(1<<GPIO_HANDSHAKE)
|
.pin_bit_mask = (1 << GPIO_HANDSHAKE)
|
||||||
};
|
};
|
||||||
|
|
||||||
//Configure handshake line as output
|
//Configure handshake line as output
|
||||||
@ -132,31 +130,31 @@ void app_main(void)
|
|||||||
gpio_set_pull_mode(GPIO_CS, GPIO_PULLUP_ONLY);
|
gpio_set_pull_mode(GPIO_CS, GPIO_PULLUP_ONLY);
|
||||||
|
|
||||||
//Initialize SPI slave interface
|
//Initialize SPI slave interface
|
||||||
ret=spi_slave_initialize(RCV_HOST, &buscfg, &slvcfg, SPI_DMA_CH_AUTO);
|
ret = spi_slave_initialize(RCV_HOST, &buscfg, &slvcfg, SPI_DMA_CH_AUTO);
|
||||||
assert(ret==ESP_OK);
|
assert(ret == ESP_OK);
|
||||||
|
|
||||||
WORD_ALIGNED_ATTR char sendbuf[129]="";
|
WORD_ALIGNED_ATTR char sendbuf[129] = "";
|
||||||
WORD_ALIGNED_ATTR char recvbuf[129]="";
|
WORD_ALIGNED_ATTR char recvbuf[129] = "";
|
||||||
memset(recvbuf, 0, 33);
|
memset(recvbuf, 0, 33);
|
||||||
spi_slave_transaction_t t;
|
spi_slave_transaction_t t;
|
||||||
memset(&t, 0, sizeof(t));
|
memset(&t, 0, sizeof(t));
|
||||||
|
|
||||||
while(1) {
|
while (1) {
|
||||||
//Clear receive buffer, set send buffer to something sane
|
//Clear receive buffer, set send buffer to something sane
|
||||||
memset(recvbuf, 0xA5, 129);
|
memset(recvbuf, 0xA5, 129);
|
||||||
sprintf(sendbuf, "This is the receiver, sending data for transmission number %04d.", n);
|
sprintf(sendbuf, "This is the receiver, sending data for transmission number %04d.", n);
|
||||||
|
|
||||||
//Set up a transaction of 128 bytes to send/receive
|
//Set up a transaction of 128 bytes to send/receive
|
||||||
t.length=128*8;
|
t.length = 128 * 8;
|
||||||
t.tx_buffer=sendbuf;
|
t.tx_buffer = sendbuf;
|
||||||
t.rx_buffer=recvbuf;
|
t.rx_buffer = recvbuf;
|
||||||
/* This call enables the SPI slave interface to send/receive to the sendbuf and recvbuf. The transaction is
|
/* This call enables the SPI slave interface to send/receive to the sendbuf and recvbuf. The transaction is
|
||||||
initialized by the SPI master, however, so it will not actually happen until the master starts a hardware transaction
|
initialized by the SPI master, however, so it will not actually happen until the master starts a hardware transaction
|
||||||
by pulling CS low and pulsing the clock etc. In this specific example, we use the handshake line, pulled up by the
|
by pulling CS low and pulsing the clock etc. In this specific example, we use the handshake line, pulled up by the
|
||||||
.post_setup_cb callback that is called as soon as a transaction is ready, to let the master know it is free to transfer
|
.post_setup_cb callback that is called as soon as a transaction is ready, to let the master know it is free to transfer
|
||||||
data.
|
data.
|
||||||
*/
|
*/
|
||||||
ret=spi_slave_transmit(RCV_HOST, &t, portMAX_DELAY);
|
ret = spi_slave_transmit(RCV_HOST, &t, portMAX_DELAY);
|
||||||
|
|
||||||
//spi_slave_transmit does not return until the master has done a transmission, so by here we have sent our data and
|
//spi_slave_transmit does not return until the master has done a transmission, so by here we have sent our data and
|
||||||
//received data from the master. Print it.
|
//received data from the master. Print it.
|
||||||
|
@ -31,7 +31,6 @@ ready to receive/send data. This code connects this line to a GPIO interrupt whi
|
|||||||
task waits for this semaphore to be given before queueing a transmission.
|
task waits for this semaphore to be given before queueing a transmission.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Pins in use. The SPI Master can use the GPIO mux, so feel free to change these if needed.
|
Pins in use. The SPI Master can use the GPIO mux, so feel free to change these if needed.
|
||||||
*/
|
*/
|
||||||
@ -72,7 +71,6 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i
|
|||||||
|
|
||||||
#endif //CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
|
#endif //CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
|
||||||
|
|
||||||
|
|
||||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||||
#define SENDER_HOST HSPI_HOST
|
#define SENDER_HOST HSPI_HOST
|
||||||
|
|
||||||
@ -81,7 +79,6 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//The semaphore indicating the slave is ready to receive stuff.
|
//The semaphore indicating the slave is ready to receive stuff.
|
||||||
static QueueHandle_t rdySem;
|
static QueueHandle_t rdySem;
|
||||||
|
|
||||||
@ -115,43 +112,43 @@ void app_main(void)
|
|||||||
spi_device_handle_t handle;
|
spi_device_handle_t handle;
|
||||||
|
|
||||||
//Configuration for the SPI bus
|
//Configuration for the SPI bus
|
||||||
spi_bus_config_t buscfg={
|
spi_bus_config_t buscfg = {
|
||||||
.mosi_io_num=GPIO_MOSI,
|
.mosi_io_num = GPIO_MOSI,
|
||||||
.miso_io_num=GPIO_MISO,
|
.miso_io_num = GPIO_MISO,
|
||||||
.sclk_io_num=GPIO_SCLK,
|
.sclk_io_num = GPIO_SCLK,
|
||||||
.quadwp_io_num=-1,
|
.quadwp_io_num = -1,
|
||||||
.quadhd_io_num=-1
|
.quadhd_io_num = -1
|
||||||
};
|
};
|
||||||
|
|
||||||
//Configuration for the SPI device on the other side of the bus
|
//Configuration for the SPI device on the other side of the bus
|
||||||
spi_device_interface_config_t devcfg={
|
spi_device_interface_config_t devcfg = {
|
||||||
.command_bits=0,
|
.command_bits = 0,
|
||||||
.address_bits=0,
|
.address_bits = 0,
|
||||||
.dummy_bits=0,
|
.dummy_bits = 0,
|
||||||
.clock_speed_hz=5000000,
|
.clock_speed_hz = 5000000,
|
||||||
.duty_cycle_pos=128, //50% duty cycle
|
.duty_cycle_pos = 128, //50% duty cycle
|
||||||
.mode=0,
|
.mode = 0,
|
||||||
.spics_io_num=GPIO_CS,
|
.spics_io_num = GPIO_CS,
|
||||||
.cs_ena_posttrans=3, //Keep the CS low 3 cycles after transaction, to stop slave from missing the last bit when CS has less propagation delay than CLK
|
.cs_ena_posttrans = 3, //Keep the CS low 3 cycles after transaction, to stop slave from missing the last bit when CS has less propagation delay than CLK
|
||||||
.queue_size=3
|
.queue_size = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
//GPIO config for the handshake line.
|
//GPIO config for the handshake line.
|
||||||
gpio_config_t io_conf={
|
gpio_config_t io_conf = {
|
||||||
.intr_type=GPIO_INTR_POSEDGE,
|
.intr_type = GPIO_INTR_POSEDGE,
|
||||||
.mode=GPIO_MODE_INPUT,
|
.mode = GPIO_MODE_INPUT,
|
||||||
.pull_up_en=1,
|
.pull_up_en = 1,
|
||||||
.pin_bit_mask=(1<<GPIO_HANDSHAKE)
|
.pin_bit_mask = (1 << GPIO_HANDSHAKE)
|
||||||
};
|
};
|
||||||
|
|
||||||
int n=0;
|
int n = 0;
|
||||||
char sendbuf[128] = {0};
|
char sendbuf[128] = {0};
|
||||||
char recvbuf[128] = {0};
|
char recvbuf[128] = {0};
|
||||||
spi_transaction_t t;
|
spi_transaction_t t;
|
||||||
memset(&t, 0, sizeof(t));
|
memset(&t, 0, sizeof(t));
|
||||||
|
|
||||||
//Create the semaphore.
|
//Create the semaphore.
|
||||||
rdySem=xSemaphoreCreateBinary();
|
rdySem = xSemaphoreCreateBinary();
|
||||||
|
|
||||||
//Set up handshake line interrupt.
|
//Set up handshake line interrupt.
|
||||||
gpio_config(&io_conf);
|
gpio_config(&io_conf);
|
||||||
@ -160,32 +157,32 @@ void app_main(void)
|
|||||||
gpio_isr_handler_add(GPIO_HANDSHAKE, gpio_handshake_isr_handler, NULL);
|
gpio_isr_handler_add(GPIO_HANDSHAKE, gpio_handshake_isr_handler, NULL);
|
||||||
|
|
||||||
//Initialize the SPI bus and add the device we want to send stuff to.
|
//Initialize the SPI bus and add the device we want to send stuff to.
|
||||||
ret=spi_bus_initialize(SENDER_HOST, &buscfg, SPI_DMA_CH_AUTO);
|
ret = spi_bus_initialize(SENDER_HOST, &buscfg, SPI_DMA_CH_AUTO);
|
||||||
assert(ret==ESP_OK);
|
assert(ret == ESP_OK);
|
||||||
ret=spi_bus_add_device(SENDER_HOST, &devcfg, &handle);
|
ret = spi_bus_add_device(SENDER_HOST, &devcfg, &handle);
|
||||||
assert(ret==ESP_OK);
|
assert(ret == ESP_OK);
|
||||||
|
|
||||||
//Assume the slave is ready for the first transmission: if the slave started up before us, we will not detect
|
//Assume the slave is ready for the first transmission: if the slave started up before us, we will not detect
|
||||||
//positive edge on the handshake line.
|
//positive edge on the handshake line.
|
||||||
xSemaphoreGive(rdySem);
|
xSemaphoreGive(rdySem);
|
||||||
|
|
||||||
while(1) {
|
while (1) {
|
||||||
int res = snprintf(sendbuf, sizeof(sendbuf),
|
int res = snprintf(sendbuf, sizeof(sendbuf),
|
||||||
"Sender, transmission no. %04i. Last time, I received: \"%s\"", n, recvbuf);
|
"Sender, transmission no. %04i. Last time, I received: \"%s\"", n, recvbuf);
|
||||||
if (res >= sizeof(sendbuf)) {
|
if (res >= sizeof(sendbuf)) {
|
||||||
printf("Data truncated\n");
|
printf("Data truncated\n");
|
||||||
}
|
}
|
||||||
t.length=sizeof(sendbuf)*8;
|
t.length = sizeof(sendbuf) * 8;
|
||||||
t.tx_buffer=sendbuf;
|
t.tx_buffer = sendbuf;
|
||||||
t.rx_buffer=recvbuf;
|
t.rx_buffer = recvbuf;
|
||||||
//Wait for slave to be ready for next byte before sending
|
//Wait for slave to be ready for next byte before sending
|
||||||
xSemaphoreTake(rdySem, portMAX_DELAY); //Wait until slave is ready
|
xSemaphoreTake(rdySem, portMAX_DELAY); //Wait until slave is ready
|
||||||
ret=spi_device_transmit(handle, &t);
|
ret = spi_device_transmit(handle, &t);
|
||||||
printf("Received: %s\n", recvbuf);
|
printf("Received: %s\n", recvbuf);
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Never reached.
|
//Never reached.
|
||||||
ret=spi_bus_remove_device(handle);
|
ret = spi_bus_remove_device(handle);
|
||||||
assert(ret==ESP_OK);
|
assert(ret == ESP_OK);
|
||||||
}
|
}
|
||||||
|
@ -53,14 +53,14 @@ static void init_driver(spi_device_handle_t *out_spi, essl_handle_t *out_essl)
|
|||||||
ESP_ERROR_CHECK(spi_bus_initialize(HOST_ID, &bus_cfg, SPI_DMA_CH_AUTO));
|
ESP_ERROR_CHECK(spi_bus_initialize(HOST_ID, &bus_cfg, SPI_DMA_CH_AUTO));
|
||||||
|
|
||||||
spi_device_interface_config_t dev_cfg = {
|
spi_device_interface_config_t dev_cfg = {
|
||||||
.clock_speed_hz = 1 * 1 * 1000,
|
.clock_speed_hz = 1 * 1 * 1000,
|
||||||
.flags = SPI_DEVICE_HALFDUPLEX,
|
.flags = SPI_DEVICE_HALFDUPLEX,
|
||||||
.spics_io_num = GPIO_CS,
|
.spics_io_num = GPIO_CS,
|
||||||
.queue_size = 16,
|
.queue_size = 16,
|
||||||
.command_bits = 8,
|
.command_bits = 8,
|
||||||
.address_bits = 8,
|
.address_bits = 8,
|
||||||
.dummy_bits = 8,
|
.dummy_bits = 8,
|
||||||
.mode = 0
|
.mode = 0
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(spi_bus_add_device(HOST_ID, &dev_cfg, &spi));
|
ESP_ERROR_CHECK(spi_bus_add_device(HOST_ID, &dev_cfg, &spi));
|
||||||
*out_spi = spi;
|
*out_spi = spi;
|
||||||
@ -88,7 +88,7 @@ static esp_err_t receiver(essl_handle_t essl)
|
|||||||
while (n--) {
|
while (n--) {
|
||||||
size_t actual_rx_length = 0;
|
size_t actual_rx_length = 0;
|
||||||
|
|
||||||
ret = essl_get_packet(essl, recv_buf, TRANSACTION_LEN/2, &actual_rx_length, portMAX_DELAY);
|
ret = essl_get_packet(essl, recv_buf, TRANSACTION_LEN / 2, &actual_rx_length, portMAX_DELAY);
|
||||||
if (ret == ESP_OK || ret == ESP_ERR_NOT_FINISHED) {
|
if (ret == ESP_OK || ret == ESP_ERR_NOT_FINISHED) {
|
||||||
ESP_LOGI("Receiver", "%d bytes are actually received:", actual_rx_length);
|
ESP_LOGI("Receiver", "%d bytes are actually received:", actual_rx_length);
|
||||||
ESP_LOG_BUFFER_HEX("Receiver", recv_buf, actual_rx_length);
|
ESP_LOG_BUFFER_HEX("Receiver", recv_buf, actual_rx_length);
|
||||||
@ -124,7 +124,7 @@ static esp_err_t sender(essl_handle_t essl)
|
|||||||
int n = EXAMPLE_CYCLES;
|
int n = EXAMPLE_CYCLES;
|
||||||
while (n--) {
|
while (n--) {
|
||||||
for (int i = 0; i < TRANSACTION_LEN; i++) {
|
for (int i = 0; i < TRANSACTION_LEN; i++) {
|
||||||
send_buf[i] = data+i;
|
send_buf[i] = data + i;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = essl_send_packet(essl, send_buf, TRANSACTION_LEN, portMAX_DELAY);
|
ret = essl_send_packet(essl, send_buf, TRANSACTION_LEN, portMAX_DELAY);
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
#define SLAVE_READY_FLAG 0x88
|
#define SLAVE_READY_FLAG 0x88
|
||||||
#define READY_FLAG_REG 0
|
#define READY_FLAG_REG 0
|
||||||
|
|
||||||
|
|
||||||
struct trans_link_s {
|
struct trans_link_s {
|
||||||
spi_slave_hd_data_t trans;
|
spi_slave_hd_data_t trans;
|
||||||
struct trans_link_s *next;
|
struct trans_link_s *next;
|
||||||
@ -41,7 +40,6 @@ typedef struct trans_link_s trans_link_t;
|
|||||||
trans_link_t *tx_curr_trans;
|
trans_link_t *tx_curr_trans;
|
||||||
trans_link_t *rx_curr_trans;
|
trans_link_t *rx_curr_trans;
|
||||||
|
|
||||||
|
|
||||||
static void init_slave_hd(void)
|
static void init_slave_hd(void)
|
||||||
{
|
{
|
||||||
spi_bus_config_t bus_cfg = {};
|
spi_bus_config_t bus_cfg = {};
|
||||||
@ -81,7 +79,7 @@ static esp_err_t create_transaction_pool(uint8_t **data_buf, trans_link_t *trans
|
|||||||
|
|
||||||
//link the recycling transaction descriptors
|
//link the recycling transaction descriptors
|
||||||
if (i != QUEUE_SIZE - 1) {
|
if (i != QUEUE_SIZE - 1) {
|
||||||
trans_link[i].next = &trans_link[i+1];
|
trans_link[i].next = &trans_link[i + 1];
|
||||||
} else {
|
} else {
|
||||||
trans_link[i].next = &trans_link[0];
|
trans_link[i].next = &trans_link[0];
|
||||||
}
|
}
|
||||||
@ -100,7 +98,7 @@ static void prepare_tx_data(trans_link_t *tx_trans)
|
|||||||
*/
|
*/
|
||||||
uint8_t data = rand() % 50;
|
uint8_t data = rand() % 50;
|
||||||
tx_trans->trans.len = TRANSACTION_LEN;
|
tx_trans->trans.len = TRANSACTION_LEN;
|
||||||
for(int i = 0; i < tx_trans->trans.len; i++) {
|
for (int i = 0; i < tx_trans->trans.len; i++) {
|
||||||
tx_trans->trans.data[i] = data + i;
|
tx_trans->trans.data[i] = data + i;
|
||||||
}
|
}
|
||||||
tx_trans->recycled = 0;
|
tx_trans->recycled = 0;
|
||||||
|
@ -68,7 +68,6 @@
|
|||||||
|
|
||||||
static const char TAG[] = "SEG_MASTER";
|
static const char TAG[] = "SEG_MASTER";
|
||||||
|
|
||||||
|
|
||||||
static void get_spi_bus_default_config(spi_bus_config_t *bus_cfg)
|
static void get_spi_bus_default_config(spi_bus_config_t *bus_cfg)
|
||||||
{
|
{
|
||||||
memset(bus_cfg, 0x0, sizeof(spi_bus_config_t));
|
memset(bus_cfg, 0x0, sizeof(spi_bus_config_t));
|
||||||
@ -85,7 +84,7 @@ static void get_spi_bus_default_config(spi_bus_config_t *bus_cfg)
|
|||||||
static void get_spi_device_default_config(spi_device_interface_config_t *dev_cfg)
|
static void get_spi_device_default_config(spi_device_interface_config_t *dev_cfg)
|
||||||
{
|
{
|
||||||
memset(dev_cfg, 0x0, sizeof(spi_device_interface_config_t));
|
memset(dev_cfg, 0x0, sizeof(spi_device_interface_config_t));
|
||||||
dev_cfg->clock_speed_hz = 10*1000*1000;
|
dev_cfg->clock_speed_hz = 10 * 1000 * 1000;
|
||||||
dev_cfg->mode = 0;
|
dev_cfg->mode = 0;
|
||||||
dev_cfg->spics_io_num = GPIO_CS;
|
dev_cfg->spics_io_num = GPIO_CS;
|
||||||
dev_cfg->cs_ena_pretrans = 0;
|
dev_cfg->cs_ena_pretrans = 0;
|
||||||
@ -114,7 +113,6 @@ static void init_master_hd(spi_device_handle_t* out_spi)
|
|||||||
ESP_ERROR_CHECK(spi_bus_add_device(MASTER_HOST, &dev_cfg, out_spi));
|
ESP_ERROR_CHECK(spi_bus_add_device(MASTER_HOST, &dev_cfg, out_spi));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------Function used for Master-Slave Synchronization---------------------------//
|
//-------------------------------Function used for Master-Slave Synchronization---------------------------//
|
||||||
//Wait for Slave to init the shared registers for its configurations, see the Helper Macros above
|
//Wait for Slave to init the shared registers for its configurations, see the Helper Macros above
|
||||||
static esp_err_t wait_for_slave_ready(spi_device_handle_t spi)
|
static esp_err_t wait_for_slave_ready(spi_device_handle_t spi)
|
||||||
|
@ -66,7 +66,6 @@
|
|||||||
//Value in these 4 registers indicates number of the RX buffer that Slave has loaded to the DMA
|
//Value in these 4 registers indicates number of the RX buffer that Slave has loaded to the DMA
|
||||||
#define SLAVE_RX_READY_BUF_NUM_REG 16
|
#define SLAVE_RX_READY_BUF_NUM_REG 16
|
||||||
|
|
||||||
|
|
||||||
static const char TAG[] = "SEG_SLAVE";
|
static const char TAG[] = "SEG_SLAVE";
|
||||||
|
|
||||||
/* Used for Master-Slave synchronization */
|
/* Used for Master-Slave synchronization */
|
||||||
@ -75,7 +74,6 @@ static uint32_t s_rx_ready_buf_num; //See ``cb_set_rx_ready_buf_num()``
|
|||||||
|
|
||||||
static uint32_t s_tx_data_id;
|
static uint32_t s_tx_data_id;
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------Function used for Master-Slave Synchronization---------------------------//
|
//-------------------------------Function used for Master-Slave Synchronization---------------------------//
|
||||||
/**
|
/**
|
||||||
* NOTE: Only if all the counters are in same size (here uint32_t), the calculation is safe (when the shared register overflows).
|
* NOTE: Only if all the counters are in same size (here uint32_t), the calculation is safe (when the shared register overflows).
|
||||||
|
@ -25,7 +25,6 @@ void app_main(void)
|
|||||||
temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(10, 50);
|
temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(10, 50);
|
||||||
ESP_ERROR_CHECK(temperature_sensor_install(&temp_sensor_config, &temp_sensor));
|
ESP_ERROR_CHECK(temperature_sensor_install(&temp_sensor_config, &temp_sensor));
|
||||||
|
|
||||||
|
|
||||||
temperature_sensor_event_callbacks_t cbs = {
|
temperature_sensor_event_callbacks_t cbs = {
|
||||||
.on_threshold = temp_sensor_monitor_cbs,
|
.on_threshold = temp_sensor_monitor_cbs,
|
||||||
};
|
};
|
||||||
|
@ -102,7 +102,6 @@ void app_main(void)
|
|||||||
user_data->timer_idx = 0;
|
user_data->timer_idx = 0;
|
||||||
user_data->alarm_value = TIMER_ALARM_PERIOD_S * TIMER_RESOLUTION_HZ;
|
user_data->alarm_value = TIMER_ALARM_PERIOD_S * TIMER_RESOLUTION_HZ;
|
||||||
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Init timer with auto-reload");
|
ESP_LOGI(TAG, "Init timer with auto-reload");
|
||||||
user_data->auto_reload = true;
|
user_data->auto_reload = true;
|
||||||
example_tg_timer_init(user_data);
|
example_tg_timer_init(user_data);
|
||||||
|
@ -108,8 +108,8 @@ void app_main(void)
|
|||||||
ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i]));
|
ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i]));
|
||||||
/* Subscribe touch button events (On Press, On Release, On LongPress) */
|
/* Subscribe touch button events (On Press, On Release, On LongPress) */
|
||||||
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i],
|
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i],
|
||||||
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS,
|
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS,
|
||||||
(void *)channel_array[i]));
|
(void *)channel_array[i]));
|
||||||
#ifdef CONFIG_TOUCH_ELEM_EVENT
|
#ifdef CONFIG_TOUCH_ELEM_EVENT
|
||||||
/* Set EVENT as the dispatch method */
|
/* Set EVENT as the dispatch method */
|
||||||
ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT));
|
ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT));
|
||||||
|
@ -75,8 +75,8 @@ void app_main(void)
|
|||||||
ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i]));
|
ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i]));
|
||||||
/* Subscribe touch button event(Press, Release, LongPress) */
|
/* Subscribe touch button event(Press, Release, LongPress) */
|
||||||
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i],
|
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i],
|
||||||
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS,
|
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS,
|
||||||
(void *)channel_array[i]));
|
(void *)channel_array[i]));
|
||||||
/* Button set dispatch method */
|
/* Button set dispatch method */
|
||||||
ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT));
|
ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT));
|
||||||
#ifdef CONFIG_TOUCH_WATERPROOF_GUARD_ENABLE
|
#ifdef CONFIG_TOUCH_WATERPROOF_GUARD_ENABLE
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -109,8 +109,8 @@ void button_example_init(void)
|
|||||||
ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i]));
|
ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i]));
|
||||||
/* Subscribe touch button events (On Press, On Release, On LongPress) */
|
/* Subscribe touch button events (On Press, On Release, On LongPress) */
|
||||||
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i],
|
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i],
|
||||||
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS,
|
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS,
|
||||||
(void *)button_channel_array[i]));
|
(void *)button_channel_array[i]));
|
||||||
/* Set EVENT as the dispatch method */
|
/* Set EVENT as the dispatch method */
|
||||||
ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT));
|
ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT));
|
||||||
/* Set LongPress event trigger threshold time */
|
/* Set LongPress event trigger threshold time */
|
||||||
@ -134,7 +134,7 @@ void slider_example_init(void)
|
|||||||
ESP_ERROR_CHECK(touch_slider_create(&slider_config, &slider_handle));
|
ESP_ERROR_CHECK(touch_slider_create(&slider_config, &slider_handle));
|
||||||
/* Subscribe touch slider events (On Press, On Release, On Calculation) */
|
/* Subscribe touch slider events (On Press, On Release, On Calculation) */
|
||||||
ESP_ERROR_CHECK(touch_slider_subscribe_event(slider_handle,
|
ESP_ERROR_CHECK(touch_slider_subscribe_event(slider_handle,
|
||||||
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_CALCULATION, NULL));
|
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_CALCULATION, NULL));
|
||||||
/* Set EVENT as the dispatch method */
|
/* Set EVENT as the dispatch method */
|
||||||
ESP_ERROR_CHECK(touch_slider_set_dispatch_method(slider_handle, TOUCH_ELEM_DISP_EVENT));
|
ESP_ERROR_CHECK(touch_slider_set_dispatch_method(slider_handle, TOUCH_ELEM_DISP_EVENT));
|
||||||
ESP_LOGI(TAG, "Touch slider created");
|
ESP_LOGI(TAG, "Touch slider created");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -60,13 +60,13 @@ static void matrix_handler_task(void *arg)
|
|||||||
const touch_matrix_message_t *matrix_message = touch_matrix_get_message(&element_message);
|
const touch_matrix_message_t *matrix_message = touch_matrix_get_message(&element_message);
|
||||||
if (matrix_message->event == TOUCH_MATRIX_EVT_ON_PRESS) {
|
if (matrix_message->event == TOUCH_MATRIX_EVT_ON_PRESS) {
|
||||||
ESP_LOGI(TAG, "Matrix Press, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, matrix_message->position.x_axis,
|
ESP_LOGI(TAG, "Matrix Press, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, matrix_message->position.x_axis,
|
||||||
matrix_message->position.y_axis, matrix_message->position.index);
|
matrix_message->position.y_axis, matrix_message->position.index);
|
||||||
} else if (matrix_message->event == TOUCH_MATRIX_EVT_ON_RELEASE) {
|
} else if (matrix_message->event == TOUCH_MATRIX_EVT_ON_RELEASE) {
|
||||||
ESP_LOGI(TAG, "Matrix Release, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, matrix_message->position.x_axis,
|
ESP_LOGI(TAG, "Matrix Release, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, matrix_message->position.x_axis,
|
||||||
matrix_message->position.y_axis, matrix_message->position.index);
|
matrix_message->position.y_axis, matrix_message->position.index);
|
||||||
} else if (matrix_message->event == TOUCH_MATRIX_EVT_ON_LONGPRESS) {
|
} else if (matrix_message->event == TOUCH_MATRIX_EVT_ON_LONGPRESS) {
|
||||||
ESP_LOGI(TAG, "Matrix LongPress, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, matrix_message->position.x_axis,
|
ESP_LOGI(TAG, "Matrix LongPress, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, matrix_message->position.x_axis,
|
||||||
matrix_message->position.y_axis, matrix_message->position.index);
|
matrix_message->position.y_axis, matrix_message->position.index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,13 +80,13 @@ void matrix_handler(touch_matrix_handle_t out_handle, touch_matrix_message_t *ou
|
|||||||
}
|
}
|
||||||
if (out_message->event == TOUCH_MATRIX_EVT_ON_PRESS) {
|
if (out_message->event == TOUCH_MATRIX_EVT_ON_PRESS) {
|
||||||
ESP_LOGI(TAG, "Matrix Press, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, out_message->position.x_axis,
|
ESP_LOGI(TAG, "Matrix Press, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, out_message->position.x_axis,
|
||||||
out_message->position.y_axis, out_message->position.index);
|
out_message->position.y_axis, out_message->position.index);
|
||||||
} else if (out_message->event == TOUCH_MATRIX_EVT_ON_RELEASE) {
|
} else if (out_message->event == TOUCH_MATRIX_EVT_ON_RELEASE) {
|
||||||
ESP_LOGI(TAG, "Matrix Release, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, out_message->position.x_axis,
|
ESP_LOGI(TAG, "Matrix Release, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, out_message->position.x_axis,
|
||||||
out_message->position.y_axis, out_message->position.index);
|
out_message->position.y_axis, out_message->position.index);
|
||||||
} else if (out_message->event == TOUCH_MATRIX_EVT_ON_LONGPRESS) {
|
} else if (out_message->event == TOUCH_MATRIX_EVT_ON_LONGPRESS) {
|
||||||
ESP_LOGI(TAG, "Matrix LongPress, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, out_message->position.x_axis,
|
ESP_LOGI(TAG, "Matrix LongPress, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, out_message->position.x_axis,
|
||||||
out_message->position.y_axis, out_message->position.index);
|
out_message->position.y_axis, out_message->position.index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -113,7 +113,7 @@ void app_main(void)
|
|||||||
ESP_ERROR_CHECK(touch_matrix_create(&matrix_config, &matrix_handle));
|
ESP_ERROR_CHECK(touch_matrix_create(&matrix_config, &matrix_handle));
|
||||||
/* Subscribe touch matrix events (On Press, On Release, On LongPress) */
|
/* Subscribe touch matrix events (On Press, On Release, On LongPress) */
|
||||||
ESP_ERROR_CHECK(touch_matrix_subscribe_event(matrix_handle,
|
ESP_ERROR_CHECK(touch_matrix_subscribe_event(matrix_handle,
|
||||||
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS, NULL));
|
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS, NULL));
|
||||||
#ifdef CONFIG_TOUCH_ELEM_EVENT
|
#ifdef CONFIG_TOUCH_ELEM_EVENT
|
||||||
/* Set EVENT as the dispatch method */
|
/* Set EVENT as the dispatch method */
|
||||||
ESP_ERROR_CHECK(touch_matrix_set_dispatch_method(matrix_handle, TOUCH_ELEM_DISP_EVENT));
|
ESP_ERROR_CHECK(touch_matrix_set_dispatch_method(matrix_handle, TOUCH_ELEM_DISP_EVENT));
|
||||||
|
@ -99,7 +99,7 @@ void app_main(void)
|
|||||||
ESP_ERROR_CHECK(touch_slider_create(&slider_config, &slider_handle));
|
ESP_ERROR_CHECK(touch_slider_create(&slider_config, &slider_handle));
|
||||||
/* Subscribe touch slider events (On Press, On Release, On Calculation) */
|
/* Subscribe touch slider events (On Press, On Release, On Calculation) */
|
||||||
ESP_ERROR_CHECK(touch_slider_subscribe_event(slider_handle,
|
ESP_ERROR_CHECK(touch_slider_subscribe_event(slider_handle,
|
||||||
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_CALCULATION, NULL));
|
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_CALCULATION, NULL));
|
||||||
#ifdef CONFIG_TOUCH_ELEM_EVENT
|
#ifdef CONFIG_TOUCH_ELEM_EVENT
|
||||||
/* Set EVENT as the dispatch method */
|
/* Set EVENT as the dispatch method */
|
||||||
ESP_ERROR_CHECK(touch_slider_set_dispatch_method(slider_handle, TOUCH_ELEM_DISP_EVENT));
|
ESP_ERROR_CHECK(touch_slider_set_dispatch_method(slider_handle, TOUCH_ELEM_DISP_EVENT));
|
||||||
|
@ -47,7 +47,7 @@ static void tp_example_read_task(void *pvParameter)
|
|||||||
|
|
||||||
static void tp_example_touch_pad_init(void)
|
static void tp_example_touch_pad_init(void)
|
||||||
{
|
{
|
||||||
for (int i = 0;i< TOUCH_PAD_MAX;i++) {
|
for (int i = 0; i < TOUCH_PAD_MAX; i++) {
|
||||||
touch_pad_config(i, TOUCH_THRESH_NO_USE);
|
touch_pad_config(i, TOUCH_THRESH_NO_USE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -43,11 +43,12 @@ static const twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
|
|||||||
static const twai_timing_config_t t_config = TWAI_TIMING_CONFIG_25KBITS();
|
static const twai_timing_config_t t_config = TWAI_TIMING_CONFIG_25KBITS();
|
||||||
//Set TX queue length to 0 due to listen only mode
|
//Set TX queue length to 0 due to listen only mode
|
||||||
static const twai_general_config_t g_config = {.mode = TWAI_MODE_LISTEN_ONLY,
|
static const twai_general_config_t g_config = {.mode = TWAI_MODE_LISTEN_ONLY,
|
||||||
.tx_io = TX_GPIO_NUM, .rx_io = RX_GPIO_NUM,
|
.tx_io = TX_GPIO_NUM, .rx_io = RX_GPIO_NUM,
|
||||||
.clkout_io = TWAI_IO_UNUSED, .bus_off_io = TWAI_IO_UNUSED,
|
.clkout_io = TWAI_IO_UNUSED, .bus_off_io = TWAI_IO_UNUSED,
|
||||||
.tx_queue_len = 0, .rx_queue_len = 5,
|
.tx_queue_len = 0, .rx_queue_len = 5,
|
||||||
.alerts_enabled = TWAI_ALERT_NONE,
|
.alerts_enabled = TWAI_ALERT_NONE,
|
||||||
.clkout_divider = 0};
|
.clkout_divider = 0
|
||||||
|
};
|
||||||
|
|
||||||
static SemaphoreHandle_t rx_sem;
|
static SemaphoreHandle_t rx_sem;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -64,11 +64,14 @@ static const twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
|
|||||||
static const twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(TX_GPIO_NUM, RX_GPIO_NUM, TWAI_MODE_NORMAL);
|
static const twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(TX_GPIO_NUM, RX_GPIO_NUM, TWAI_MODE_NORMAL);
|
||||||
|
|
||||||
static const twai_message_t ping_message = {.identifier = ID_MASTER_PING, .data_length_code = 0,
|
static const twai_message_t ping_message = {.identifier = ID_MASTER_PING, .data_length_code = 0,
|
||||||
.ss = 1, .data = {0, 0 , 0 , 0 ,0 ,0 ,0 ,0}};
|
.ss = 1, .data = {0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
|
};
|
||||||
static const twai_message_t start_message = {.identifier = ID_MASTER_START_CMD, .data_length_code = 0,
|
static const twai_message_t start_message = {.identifier = ID_MASTER_START_CMD, .data_length_code = 0,
|
||||||
.data = {0, 0 , 0 , 0 ,0 ,0 ,0 ,0}};
|
.data = {0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
|
};
|
||||||
static const twai_message_t stop_message = {.identifier = ID_MASTER_STOP_CMD, .data_length_code = 0,
|
static const twai_message_t stop_message = {.identifier = ID_MASTER_STOP_CMD, .data_length_code = 0,
|
||||||
.data = {0, 0 , 0 , 0 ,0 ,0 ,0 ,0}};
|
.data = {0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
static QueueHandle_t tx_task_queue;
|
static QueueHandle_t tx_task_queue;
|
||||||
static QueueHandle_t rx_task_queue;
|
static QueueHandle_t rx_task_queue;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -64,12 +64,15 @@ static const twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(TX_GPI
|
|||||||
static const twai_timing_config_t t_config = TWAI_TIMING_CONFIG_25KBITS();
|
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 const twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
|
||||||
static const twai_message_t ping_resp = {.identifier = ID_SLAVE_PING_RESP, .data_length_code = 0,
|
static const twai_message_t ping_resp = {.identifier = ID_SLAVE_PING_RESP, .data_length_code = 0,
|
||||||
.data = {0, 0 , 0 , 0 ,0 ,0 ,0 ,0}};
|
.data = {0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
|
};
|
||||||
static const twai_message_t stop_resp = {.identifier = ID_SLAVE_STOP_RESP, .data_length_code = 0,
|
static const twai_message_t stop_resp = {.identifier = ID_SLAVE_STOP_RESP, .data_length_code = 0,
|
||||||
.data = {0, 0 , 0 , 0 ,0 ,0 ,0 ,0}};
|
.data = {0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
|
};
|
||||||
//Data bytes of data message will be initialized in the transmit task
|
//Data bytes of data message will be initialized in the transmit task
|
||||||
static twai_message_t data_message = {.identifier = ID_SLAVE_DATA, .data_length_code = 4,
|
static twai_message_t data_message = {.identifier = ID_SLAVE_DATA, .data_length_code = 4,
|
||||||
.data = {0, 0 , 0 , 0 ,0 ,0 ,0 ,0}};
|
.data = {0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
static QueueHandle_t tx_task_queue;
|
static QueueHandle_t tx_task_queue;
|
||||||
static QueueHandle_t rx_task_queue;
|
static QueueHandle_t rx_task_queue;
|
||||||
@ -230,7 +233,6 @@ void app_main(void)
|
|||||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Create semaphores and tasks
|
//Create semaphores and tasks
|
||||||
tx_task_queue = xQueueCreate(1, sizeof(tx_task_action_t));
|
tx_task_queue = xQueueCreate(1, sizeof(tx_task_action_t));
|
||||||
rx_task_queue = xQueueCreate(1, sizeof(rx_task_action_t));
|
rx_task_queue = xQueueCreate(1, sizeof(rx_task_action_t));
|
||||||
|
@ -19,7 +19,8 @@ static const int RX_BUF_SIZE = 1024;
|
|||||||
#define TXD_PIN (GPIO_NUM_4)
|
#define TXD_PIN (GPIO_NUM_4)
|
||||||
#define RXD_PIN (GPIO_NUM_5)
|
#define RXD_PIN (GPIO_NUM_5)
|
||||||
|
|
||||||
void init(void) {
|
void init(void)
|
||||||
|
{
|
||||||
const uart_config_t uart_config = {
|
const uart_config_t uart_config = {
|
||||||
.baud_rate = 115200,
|
.baud_rate = 115200,
|
||||||
.data_bits = UART_DATA_8_BITS,
|
.data_bits = UART_DATA_8_BITS,
|
||||||
@ -56,7 +57,7 @@ static void rx_task(void *arg)
|
|||||||
{
|
{
|
||||||
static const char *RX_TASK_TAG = "RX_TASK";
|
static const char *RX_TASK_TAG = "RX_TASK";
|
||||||
esp_log_level_set(RX_TASK_TAG, ESP_LOG_INFO);
|
esp_log_level_set(RX_TASK_TAG, ESP_LOG_INFO);
|
||||||
uint8_t* data = (uint8_t*) malloc(RX_BUF_SIZE+1);
|
uint8_t* data = (uint8_t*) malloc(RX_BUF_SIZE + 1);
|
||||||
while (1) {
|
while (1) {
|
||||||
const int rxBytes = uart_read_bytes(UART_NUM_1, data, RX_BUF_SIZE, 1000 / portTICK_PERIOD_MS);
|
const int rxBytes = uart_read_bytes(UART_NUM_1, data, RX_BUF_SIZE, 1000 / portTICK_PERIOD_MS);
|
||||||
if (rxBytes > 0) {
|
if (rxBytes > 0) {
|
||||||
@ -71,6 +72,6 @@ static void rx_task(void *arg)
|
|||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
xTaskCreate(rx_task, "uart_rx_task", 1024*2, NULL, configMAX_PRIORITIES, NULL);
|
xTaskCreate(rx_task, "uart_rx_task", 1024 * 2, NULL, configMAX_PRIORITIES, NULL);
|
||||||
xTaskCreate(tx_task, "uart_tx_task", 1024*2, NULL, configMAX_PRIORITIES-1, NULL);
|
xTaskCreate(tx_task, "uart_tx_task", 1024 * 2, NULL, configMAX_PRIORITIES - 1, NULL);
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ static void echo_task(void *arg)
|
|||||||
ESP_LOGI(TAG, "UART start recieve loop.\r");
|
ESP_LOGI(TAG, "UART start recieve loop.\r");
|
||||||
echo_send(uart_num, "Start RS485 UART test.\r\n", 24);
|
echo_send(uart_num, "Start RS485 UART test.\r\n", 24);
|
||||||
|
|
||||||
while(1) {
|
while (1) {
|
||||||
//Read data from UART
|
//Read data from UART
|
||||||
int len = uart_read_bytes(uart_num, data, BUF_SIZE, PACKET_READ_TICS);
|
int len = uart_read_bytes(uart_num, data, BUF_SIZE, PACKET_READ_TICS);
|
||||||
|
|
||||||
|
@ -41,74 +41,74 @@ static void uart_event_task(void *pvParameters)
|
|||||||
uart_event_t event;
|
uart_event_t event;
|
||||||
size_t buffered_size;
|
size_t buffered_size;
|
||||||
uint8_t* dtmp = (uint8_t*) malloc(RD_BUF_SIZE);
|
uint8_t* dtmp = (uint8_t*) malloc(RD_BUF_SIZE);
|
||||||
for(;;) {
|
for (;;) {
|
||||||
//Waiting for UART event.
|
//Waiting for UART event.
|
||||||
if(xQueueReceive(uart0_queue, (void * )&event, (TickType_t)portMAX_DELAY)) {
|
if (xQueueReceive(uart0_queue, (void *)&event, (TickType_t)portMAX_DELAY)) {
|
||||||
bzero(dtmp, RD_BUF_SIZE);
|
bzero(dtmp, RD_BUF_SIZE);
|
||||||
ESP_LOGI(TAG, "uart[%d] event:", EX_UART_NUM);
|
ESP_LOGI(TAG, "uart[%d] event:", EX_UART_NUM);
|
||||||
switch(event.type) {
|
switch (event.type) {
|
||||||
//Event of UART receving data
|
//Event of UART receving data
|
||||||
/*We'd better handler data event fast, there would be much more data events than
|
/*We'd better handler data event fast, there would be much more data events than
|
||||||
other types of events. If we take too much time on data event, the queue might
|
other types of events. If we take too much time on data event, the queue might
|
||||||
be full.*/
|
be full.*/
|
||||||
case UART_DATA:
|
case UART_DATA:
|
||||||
ESP_LOGI(TAG, "[UART DATA]: %d", event.size);
|
ESP_LOGI(TAG, "[UART DATA]: %d", event.size);
|
||||||
uart_read_bytes(EX_UART_NUM, dtmp, event.size, portMAX_DELAY);
|
uart_read_bytes(EX_UART_NUM, dtmp, event.size, portMAX_DELAY);
|
||||||
ESP_LOGI(TAG, "[DATA EVT]:");
|
ESP_LOGI(TAG, "[DATA EVT]:");
|
||||||
uart_write_bytes(EX_UART_NUM, (const char*) dtmp, event.size);
|
uart_write_bytes(EX_UART_NUM, (const char*) dtmp, event.size);
|
||||||
break;
|
break;
|
||||||
//Event of HW FIFO overflow detected
|
//Event of HW FIFO overflow detected
|
||||||
case UART_FIFO_OVF:
|
case UART_FIFO_OVF:
|
||||||
ESP_LOGI(TAG, "hw fifo overflow");
|
ESP_LOGI(TAG, "hw fifo overflow");
|
||||||
// If fifo overflow happened, you should consider adding flow control for your application.
|
// If fifo overflow happened, you should consider adding flow control for your application.
|
||||||
// The ISR has already reset the rx FIFO,
|
// The ISR has already reset the rx FIFO,
|
||||||
// As an example, we directly flush the rx buffer here in order to read more data.
|
// As an example, we directly flush the rx buffer here in order to read more data.
|
||||||
|
uart_flush_input(EX_UART_NUM);
|
||||||
|
xQueueReset(uart0_queue);
|
||||||
|
break;
|
||||||
|
//Event of UART ring buffer full
|
||||||
|
case UART_BUFFER_FULL:
|
||||||
|
ESP_LOGI(TAG, "ring buffer full");
|
||||||
|
// If buffer full happened, you should consider increasing your buffer size
|
||||||
|
// As an example, we directly flush the rx buffer here in order to read more data.
|
||||||
|
uart_flush_input(EX_UART_NUM);
|
||||||
|
xQueueReset(uart0_queue);
|
||||||
|
break;
|
||||||
|
//Event of UART RX break detected
|
||||||
|
case UART_BREAK:
|
||||||
|
ESP_LOGI(TAG, "uart rx break");
|
||||||
|
break;
|
||||||
|
//Event of UART parity check error
|
||||||
|
case UART_PARITY_ERR:
|
||||||
|
ESP_LOGI(TAG, "uart parity error");
|
||||||
|
break;
|
||||||
|
//Event of UART frame error
|
||||||
|
case UART_FRAME_ERR:
|
||||||
|
ESP_LOGI(TAG, "uart frame error");
|
||||||
|
break;
|
||||||
|
//UART_PATTERN_DET
|
||||||
|
case UART_PATTERN_DET:
|
||||||
|
uart_get_buffered_data_len(EX_UART_NUM, &buffered_size);
|
||||||
|
int pos = uart_pattern_pop_pos(EX_UART_NUM);
|
||||||
|
ESP_LOGI(TAG, "[UART PATTERN DETECTED] pos: %d, buffered size: %d", pos, buffered_size);
|
||||||
|
if (pos == -1) {
|
||||||
|
// There used to be a UART_PATTERN_DET event, but the pattern position queue is full so that it can not
|
||||||
|
// record the position. We should set a larger queue size.
|
||||||
|
// As an example, we directly flush the rx buffer here.
|
||||||
uart_flush_input(EX_UART_NUM);
|
uart_flush_input(EX_UART_NUM);
|
||||||
xQueueReset(uart0_queue);
|
} else {
|
||||||
break;
|
uart_read_bytes(EX_UART_NUM, dtmp, pos, 100 / portTICK_PERIOD_MS);
|
||||||
//Event of UART ring buffer full
|
uint8_t pat[PATTERN_CHR_NUM + 1];
|
||||||
case UART_BUFFER_FULL:
|
memset(pat, 0, sizeof(pat));
|
||||||
ESP_LOGI(TAG, "ring buffer full");
|
uart_read_bytes(EX_UART_NUM, pat, PATTERN_CHR_NUM, 100 / portTICK_PERIOD_MS);
|
||||||
// If buffer full happened, you should consider increasing your buffer size
|
ESP_LOGI(TAG, "read data: %s", dtmp);
|
||||||
// As an example, we directly flush the rx buffer here in order to read more data.
|
ESP_LOGI(TAG, "read pat : %s", pat);
|
||||||
uart_flush_input(EX_UART_NUM);
|
}
|
||||||
xQueueReset(uart0_queue);
|
break;
|
||||||
break;
|
//Others
|
||||||
//Event of UART RX break detected
|
default:
|
||||||
case UART_BREAK:
|
ESP_LOGI(TAG, "uart event type: %d", event.type);
|
||||||
ESP_LOGI(TAG, "uart rx break");
|
break;
|
||||||
break;
|
|
||||||
//Event of UART parity check error
|
|
||||||
case UART_PARITY_ERR:
|
|
||||||
ESP_LOGI(TAG, "uart parity error");
|
|
||||||
break;
|
|
||||||
//Event of UART frame error
|
|
||||||
case UART_FRAME_ERR:
|
|
||||||
ESP_LOGI(TAG, "uart frame error");
|
|
||||||
break;
|
|
||||||
//UART_PATTERN_DET
|
|
||||||
case UART_PATTERN_DET:
|
|
||||||
uart_get_buffered_data_len(EX_UART_NUM, &buffered_size);
|
|
||||||
int pos = uart_pattern_pop_pos(EX_UART_NUM);
|
|
||||||
ESP_LOGI(TAG, "[UART PATTERN DETECTED] pos: %d, buffered size: %d", pos, buffered_size);
|
|
||||||
if (pos == -1) {
|
|
||||||
// There used to be a UART_PATTERN_DET event, but the pattern position queue is full so that it can not
|
|
||||||
// record the position. We should set a larger queue size.
|
|
||||||
// As an example, we directly flush the rx buffer here.
|
|
||||||
uart_flush_input(EX_UART_NUM);
|
|
||||||
} else {
|
|
||||||
uart_read_bytes(EX_UART_NUM, dtmp, pos, 100 / portTICK_PERIOD_MS);
|
|
||||||
uint8_t pat[PATTERN_CHR_NUM + 1];
|
|
||||||
memset(pat, 0, sizeof(pat));
|
|
||||||
uart_read_bytes(EX_UART_NUM, pat, PATTERN_CHR_NUM, 100 / portTICK_PERIOD_MS);
|
|
||||||
ESP_LOGI(TAG, "read data: %s", dtmp);
|
|
||||||
ESP_LOGI(TAG, "read pat : %s", pat);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//Others
|
|
||||||
default:
|
|
||||||
ESP_LOGI(TAG, "uart event type: %d", event.type);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,6 @@ static void configure_uarts(void)
|
|||||||
ESP_ERROR_CHECK(uart_set_pin(DEFAULT_UART_CHANNEL, DEFAULT_UART_TX_PIN, DEFAULT_UART_RX_PIN,
|
ESP_ERROR_CHECK(uart_set_pin(DEFAULT_UART_CHANNEL, DEFAULT_UART_TX_PIN, DEFAULT_UART_RX_PIN,
|
||||||
UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
|
UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
|
||||||
|
|
||||||
|
|
||||||
connect_uarts();
|
connect_uarts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +91,8 @@ static void configure_uarts(void)
|
|||||||
* @brief Function called when command `consoletest` will be invoked.
|
* @brief Function called when command `consoletest` will be invoked.
|
||||||
* It will simply print `test_message` defined above.
|
* It will simply print `test_message` defined above.
|
||||||
*/
|
*/
|
||||||
static int console_test(int argc, char **argv) {
|
static int console_test(int argc, char **argv)
|
||||||
|
{
|
||||||
printf("%s\n", test_message);
|
printf("%s\n", test_message);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -104,7 +104,8 @@ static int console_test(int argc, char **argv) {
|
|||||||
* the response on RX.
|
* the response on RX.
|
||||||
* The response shall contain the test_message string.
|
* The response shall contain the test_message string.
|
||||||
*/
|
*/
|
||||||
static void send_commands(void* arg) {
|
static void send_commands(void* arg)
|
||||||
|
{
|
||||||
static char data[READ_BUF_SIZE];
|
static char data[READ_BUF_SIZE];
|
||||||
char command[] = "consoletest\n";
|
char command[] = "consoletest\n";
|
||||||
int len = 0;
|
int len = 0;
|
||||||
@ -115,12 +116,12 @@ static void send_commands(void* arg) {
|
|||||||
len = uart_read_bytes(DEFAULT_UART_CHANNEL, data, READ_BUF_SIZE, 100 / portTICK_PERIOD_MS);
|
len = uart_read_bytes(DEFAULT_UART_CHANNEL, data, READ_BUF_SIZE, 100 / portTICK_PERIOD_MS);
|
||||||
} while (len == 0);
|
} while (len == 0);
|
||||||
|
|
||||||
if ( len == -1 ) {
|
if (len == -1) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
/* Send the command `consoletest` to the console UART. */
|
/* Send the command `consoletest` to the console UART. */
|
||||||
len = uart_write_bytes(DEFAULT_UART_CHANNEL, command, sizeof(command));
|
len = uart_write_bytes(DEFAULT_UART_CHANNEL, command, sizeof(command));
|
||||||
if ( len == -1 ) {
|
if (len == -1) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +130,7 @@ static void send_commands(void* arg) {
|
|||||||
len = uart_read_bytes(DEFAULT_UART_CHANNEL, data, READ_BUF_SIZE - 1, 250 / portTICK_PERIOD_MS);
|
len = uart_read_bytes(DEFAULT_UART_CHANNEL, data, READ_BUF_SIZE - 1, 250 / portTICK_PERIOD_MS);
|
||||||
} while (len == 0);
|
} while (len == 0);
|
||||||
|
|
||||||
if ( len == -1 ) {
|
if (len == -1) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,11 +159,11 @@ void app_main(void)
|
|||||||
.func = &console_test,
|
.func = &console_test,
|
||||||
};
|
};
|
||||||
esp_console_dev_uart_config_t uart_config = {
|
esp_console_dev_uart_config_t uart_config = {
|
||||||
.channel = CONSOLE_UART_CHANNEL,
|
.channel = CONSOLE_UART_CHANNEL,
|
||||||
.baud_rate = UARTS_BAUD_RATE,
|
.baud_rate = UARTS_BAUD_RATE,
|
||||||
.tx_gpio_num = CONSOLE_UART_TX_PIN,
|
.tx_gpio_num = CONSOLE_UART_TX_PIN,
|
||||||
.rx_gpio_num = CONSOLE_UART_RX_PIN,
|
.rx_gpio_num = CONSOLE_UART_RX_PIN,
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* As we don't have a real serial terminal, (we just use default UART to
|
* As we don't have a real serial terminal, (we just use default UART to
|
||||||
* send and receive commands, ) we won't handle any escape sequence, so the
|
* send and receive commands, ) we won't handle any escape sequence, so the
|
||||||
@ -172,7 +173,7 @@ void app_main(void)
|
|||||||
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
|
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
|
||||||
configure_uarts();
|
configure_uarts();
|
||||||
|
|
||||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||||
|
|
||||||
/* Create a task for sending and receiving commands to and from the second UART. */
|
/* Create a task for sending and receiving commands to and from the second UART. */
|
||||||
xTaskCreate(send_commands, "send_commands_task", TASK_STACK_SIZE, NULL, 10, NULL);
|
xTaskCreate(send_commands, "send_commands_task", TASK_STACK_SIZE, NULL, 10, NULL);
|
||||||
|
@ -22,7 +22,7 @@ static const char* TAG = "uart_select_example";
|
|||||||
|
|
||||||
static void uart_select_task(void *arg)
|
static void uart_select_task(void *arg)
|
||||||
{
|
{
|
||||||
if (uart_driver_install(UART_NUM_0, 2*1024, 0, 0, NULL, 0) != ESP_OK) {
|
if (uart_driver_install(UART_NUM_0, 2 * 1024, 0, 0, NULL, 0) != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Driver installation failed");
|
ESP_LOGE(TAG, "Driver installation failed");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
@ -95,5 +95,5 @@ static void uart_select_task(void *arg)
|
|||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
xTaskCreate(uart_select_task, "uart_select_task", 4*1024, NULL, 5, NULL);
|
xTaskCreate(uart_select_task, "uart_select_task", 4 * 1024, NULL, 5, NULL);
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,8 @@ static const char *TAG = "example";
|
|||||||
* so we must define both report descriptors
|
* so we must define both report descriptors
|
||||||
*/
|
*/
|
||||||
const uint8_t hid_report_descriptor[] = {
|
const uint8_t hid_report_descriptor[] = {
|
||||||
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(HID_ITF_PROTOCOL_KEYBOARD) ),
|
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(HID_ITF_PROTOCOL_KEYBOARD)),
|
||||||
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_ITF_PROTOCOL_MOUSE) )
|
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_ITF_PROTOCOL_MOUSE))
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,13 +70,13 @@ uint8_t const *tud_hid_descriptor_report_cb(uint8_t instance)
|
|||||||
// Return zero will cause the stack to STALL request
|
// Return zero will cause the stack to STALL request
|
||||||
uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
|
uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
|
||||||
{
|
{
|
||||||
(void) instance;
|
(void) instance;
|
||||||
(void) report_id;
|
(void) report_id;
|
||||||
(void) report_type;
|
(void) report_type;
|
||||||
(void) buffer;
|
(void) buffer;
|
||||||
(void) reqlen;
|
(void) reqlen;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoked when received SET_REPORT control request or
|
// Invoked when received SET_REPORT control request or
|
||||||
|
@ -131,7 +131,6 @@ static void _mount(void)
|
|||||||
ESP_LOGI(TAG, "Mount storage...");
|
ESP_LOGI(TAG, "Mount storage...");
|
||||||
ESP_ERROR_CHECK(tinyusb_msc_storage_mount(BASE_PATH));
|
ESP_ERROR_CHECK(tinyusb_msc_storage_mount(BASE_PATH));
|
||||||
|
|
||||||
|
|
||||||
// List all the files in this directory
|
// List all the files in this directory
|
||||||
ESP_LOGI(TAG, "\nls command output:");
|
ESP_LOGI(TAG, "\nls command output:");
|
||||||
struct dirent *d;
|
struct dirent *d;
|
||||||
@ -388,7 +387,7 @@ void app_main(void)
|
|||||||
esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
|
esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
|
||||||
ESP_ERROR_CHECK(esp_console_new_repl_uart(&hw_config, &repl_config, &repl));
|
ESP_ERROR_CHECK(esp_console_new_repl_uart(&hw_config, &repl_config, &repl));
|
||||||
for (int count = 0; count < sizeof(cmds) / sizeof(esp_console_cmd_t); count++) {
|
for (int count = 0; count < sizeof(cmds) / sizeof(esp_console_cmd_t); count++) {
|
||||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmds[count]) );
|
ESP_ERROR_CHECK(esp_console_cmd_register(&cmds[count]));
|
||||||
}
|
}
|
||||||
ESP_ERROR_CHECK(esp_console_start_repl(repl));
|
ESP_ERROR_CHECK(esp_console_start_repl(repl));
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include "tinyusb.h"
|
#include "tinyusb.h"
|
||||||
#include "tinyusb_net.h"
|
#include "tinyusb_net.h"
|
||||||
|
|
||||||
|
|
||||||
static const char *TAG = "USB_NCM";
|
static const char *TAG = "USB_NCM";
|
||||||
|
|
||||||
static esp_err_t usb_recv_callback(void *buffer, uint16_t len, void *ctx)
|
static esp_err_t usb_recv_callback(void *buffer, uint16_t len, void *ctx)
|
||||||
|
@ -56,21 +56,21 @@ static bool handle_rx(const uint8_t *data, size_t data_len, void *arg)
|
|||||||
static void handle_event(const cdc_acm_host_dev_event_data_t *event, void *user_ctx)
|
static void handle_event(const cdc_acm_host_dev_event_data_t *event, void *user_ctx)
|
||||||
{
|
{
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case CDC_ACM_HOST_ERROR:
|
case CDC_ACM_HOST_ERROR:
|
||||||
ESP_LOGE(TAG, "CDC-ACM error has occurred, err_no = %i", event->data.error);
|
ESP_LOGE(TAG, "CDC-ACM error has occurred, err_no = %i", event->data.error);
|
||||||
break;
|
break;
|
||||||
case CDC_ACM_HOST_DEVICE_DISCONNECTED:
|
case CDC_ACM_HOST_DEVICE_DISCONNECTED:
|
||||||
ESP_LOGI(TAG, "Device suddenly disconnected");
|
ESP_LOGI(TAG, "Device suddenly disconnected");
|
||||||
ESP_ERROR_CHECK(cdc_acm_host_close(event->data.cdc_hdl));
|
ESP_ERROR_CHECK(cdc_acm_host_close(event->data.cdc_hdl));
|
||||||
xSemaphoreGive(device_disconnected_sem);
|
xSemaphoreGive(device_disconnected_sem);
|
||||||
break;
|
break;
|
||||||
case CDC_ACM_HOST_SERIAL_STATE:
|
case CDC_ACM_HOST_SERIAL_STATE:
|
||||||
ESP_LOGI(TAG, "Serial state notif 0x%04X", event->data.serial_state.val);
|
ESP_LOGI(TAG, "Serial state notif 0x%04X", event->data.serial_state.val);
|
||||||
break;
|
break;
|
||||||
case CDC_ACM_HOST_NETWORK_CONNECTION:
|
case CDC_ACM_HOST_NETWORK_CONNECTION:
|
||||||
default:
|
default:
|
||||||
ESP_LOGW(TAG, "Unsupported CDC event: %i", event->type);
|
ESP_LOGW(TAG, "Unsupported CDC event: %i", event->type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,18 +60,18 @@ static bool handle_rx(const uint8_t *data, size_t data_len, void *arg)
|
|||||||
static void handle_event(const cdc_acm_host_dev_event_data_t *event, void *user_ctx)
|
static void handle_event(const cdc_acm_host_dev_event_data_t *event, void *user_ctx)
|
||||||
{
|
{
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case CDC_ACM_HOST_ERROR:
|
case CDC_ACM_HOST_ERROR:
|
||||||
ESP_LOGE(TAG, "CDC-ACM error has occurred, err_no = %d", event->data.error);
|
ESP_LOGE(TAG, "CDC-ACM error has occurred, err_no = %d", event->data.error);
|
||||||
break;
|
break;
|
||||||
case CDC_ACM_HOST_DEVICE_DISCONNECTED:
|
case CDC_ACM_HOST_DEVICE_DISCONNECTED:
|
||||||
ESP_LOGI(TAG, "Device suddenly disconnected");
|
ESP_LOGI(TAG, "Device suddenly disconnected");
|
||||||
xSemaphoreGive(device_disconnected_sem);
|
xSemaphoreGive(device_disconnected_sem);
|
||||||
break;
|
break;
|
||||||
case CDC_ACM_HOST_SERIAL_STATE:
|
case CDC_ACM_HOST_SERIAL_STATE:
|
||||||
ESP_LOGI(TAG, "Serial state notif 0x%04X", event->data.serial_state.val);
|
ESP_LOGI(TAG, "Serial state notif 0x%04X", event->data.serial_state.val);
|
||||||
break;
|
break;
|
||||||
case CDC_ACM_HOST_NETWORK_CONNECTION:
|
case CDC_ACM_HOST_NETWORK_CONNECTION:
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,8 +180,8 @@ static inline bool hid_keyboard_is_modifier_shift(uint8_t modifier)
|
|||||||
* @return false Key scancode unknown
|
* @return false Key scancode unknown
|
||||||
*/
|
*/
|
||||||
static inline bool hid_keyboard_get_char(uint8_t modifier,
|
static inline bool hid_keyboard_get_char(uint8_t modifier,
|
||||||
uint8_t key_code,
|
uint8_t key_code,
|
||||||
unsigned char *key_char)
|
unsigned char *key_char)
|
||||||
{
|
{
|
||||||
uint8_t mod = (hid_keyboard_is_modifier_shift(modifier)) ? 1 : 0;
|
uint8_t mod = (hid_keyboard_is_modifier_shift(modifier)) ? 1 : 0;
|
||||||
|
|
||||||
@ -342,7 +342,6 @@ static void hid_host_generic_report_callback(const uint8_t *const data, const in
|
|||||||
putchar('\r');
|
putchar('\r');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USB HID Host interface callback
|
* @brief USB HID Host interface callback
|
||||||
*
|
*
|
||||||
@ -357,14 +356,14 @@ void hid_host_interface_callback(hid_host_device_handle_t hid_device_handle,
|
|||||||
uint8_t data[64] = { 0 };
|
uint8_t data[64] = { 0 };
|
||||||
size_t data_length = 0;
|
size_t data_length = 0;
|
||||||
hid_host_dev_params_t dev_params;
|
hid_host_dev_params_t dev_params;
|
||||||
ESP_ERROR_CHECK( hid_host_device_get_params(hid_device_handle, &dev_params));
|
ESP_ERROR_CHECK(hid_host_device_get_params(hid_device_handle, &dev_params));
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case HID_HOST_INTERFACE_EVENT_INPUT_REPORT:
|
case HID_HOST_INTERFACE_EVENT_INPUT_REPORT:
|
||||||
ESP_ERROR_CHECK( hid_host_device_get_raw_input_report_data(hid_device_handle,
|
ESP_ERROR_CHECK(hid_host_device_get_raw_input_report_data(hid_device_handle,
|
||||||
data,
|
data,
|
||||||
64,
|
64,
|
||||||
&data_length));
|
&data_length));
|
||||||
|
|
||||||
if (HID_SUBCLASS_BOOT_INTERFACE == dev_params.sub_class) {
|
if (HID_SUBCLASS_BOOT_INTERFACE == dev_params.sub_class) {
|
||||||
if (HID_PROTOCOL_KEYBOARD == dev_params.proto) {
|
if (HID_PROTOCOL_KEYBOARD == dev_params.proto) {
|
||||||
@ -380,7 +379,7 @@ void hid_host_interface_callback(hid_host_device_handle_t hid_device_handle,
|
|||||||
case HID_HOST_INTERFACE_EVENT_DISCONNECTED:
|
case HID_HOST_INTERFACE_EVENT_DISCONNECTED:
|
||||||
ESP_LOGI(TAG, "HID Device, protocol '%s' DISCONNECTED",
|
ESP_LOGI(TAG, "HID Device, protocol '%s' DISCONNECTED",
|
||||||
hid_proto_name_str[dev_params.proto]);
|
hid_proto_name_str[dev_params.proto]);
|
||||||
ESP_ERROR_CHECK( hid_host_device_close(hid_device_handle) );
|
ESP_ERROR_CHECK(hid_host_device_close(hid_device_handle));
|
||||||
break;
|
break;
|
||||||
case HID_HOST_INTERFACE_EVENT_TRANSFER_ERROR:
|
case HID_HOST_INTERFACE_EVENT_TRANSFER_ERROR:
|
||||||
ESP_LOGI(TAG, "HID Device, protocol '%s' TRANSFER_ERROR",
|
ESP_LOGI(TAG, "HID Device, protocol '%s' TRANSFER_ERROR",
|
||||||
@ -405,7 +404,7 @@ void hid_host_device_event(hid_host_device_handle_t hid_device_handle,
|
|||||||
void *arg)
|
void *arg)
|
||||||
{
|
{
|
||||||
hid_host_dev_params_t dev_params;
|
hid_host_dev_params_t dev_params;
|
||||||
ESP_ERROR_CHECK( hid_host_device_get_params(hid_device_handle, &dev_params));
|
ESP_ERROR_CHECK(hid_host_device_get_params(hid_device_handle, &dev_params));
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case HID_HOST_DRIVER_EVENT_CONNECTED:
|
case HID_HOST_DRIVER_EVENT_CONNECTED:
|
||||||
@ -417,14 +416,14 @@ void hid_host_device_event(hid_host_device_handle_t hid_device_handle,
|
|||||||
.callback_arg = NULL
|
.callback_arg = NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
ESP_ERROR_CHECK( hid_host_device_open(hid_device_handle, &dev_config) );
|
ESP_ERROR_CHECK(hid_host_device_open(hid_device_handle, &dev_config));
|
||||||
if (HID_SUBCLASS_BOOT_INTERFACE == dev_params.sub_class) {
|
if (HID_SUBCLASS_BOOT_INTERFACE == dev_params.sub_class) {
|
||||||
ESP_ERROR_CHECK( hid_class_request_set_protocol(hid_device_handle, HID_REPORT_PROTOCOL_BOOT));
|
ESP_ERROR_CHECK(hid_class_request_set_protocol(hid_device_handle, HID_REPORT_PROTOCOL_BOOT));
|
||||||
if (HID_PROTOCOL_KEYBOARD == dev_params.proto) {
|
if (HID_PROTOCOL_KEYBOARD == dev_params.proto) {
|
||||||
ESP_ERROR_CHECK( hid_class_request_set_idle(hid_device_handle, 0, 0));
|
ESP_ERROR_CHECK(hid_class_request_set_idle(hid_device_handle, 0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ESP_ERROR_CHECK( hid_host_device_start(hid_device_handle) );
|
ESP_ERROR_CHECK(hid_host_device_start(hid_device_handle));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -443,14 +442,14 @@ static void usb_lib_task(void *arg)
|
|||||||
.mode = GPIO_MODE_INPUT,
|
.mode = GPIO_MODE_INPUT,
|
||||||
.pull_up_en = GPIO_PULLUP_ENABLE,
|
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK( gpio_config(&input_pin) );
|
ESP_ERROR_CHECK(gpio_config(&input_pin));
|
||||||
|
|
||||||
const usb_host_config_t host_config = {
|
const usb_host_config_t host_config = {
|
||||||
.skip_phy_setup = false,
|
.skip_phy_setup = false,
|
||||||
.intr_flags = ESP_INTR_FLAG_LEVEL1,
|
.intr_flags = ESP_INTR_FLAG_LEVEL1,
|
||||||
};
|
};
|
||||||
|
|
||||||
ESP_ERROR_CHECK( usb_host_install(&host_config) );
|
ESP_ERROR_CHECK(usb_host_install(&host_config));
|
||||||
xTaskNotifyGive(arg);
|
xTaskNotifyGive(arg);
|
||||||
|
|
||||||
while (gpio_get_level(APP_QUIT_PIN) != 0) {
|
while (gpio_get_level(APP_QUIT_PIN) != 0) {
|
||||||
@ -472,7 +471,7 @@ static void usb_lib_task(void *arg)
|
|||||||
ESP_LOGI(TAG, "USB shutdown");
|
ESP_LOGI(TAG, "USB shutdown");
|
||||||
// Clean up USB Host
|
// Clean up USB Host
|
||||||
vTaskDelay(10); // Short delay to allow clients clean-up
|
vTaskDelay(10); // Short delay to allow clients clean-up
|
||||||
ESP_ERROR_CHECK( usb_host_uninstall());
|
ESP_ERROR_CHECK(usb_host_uninstall());
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,7 +557,7 @@ void app_main(void)
|
|||||||
.callback_arg = NULL
|
.callback_arg = NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
ESP_ERROR_CHECK( hid_host_install(&hid_host_driver_config) );
|
ESP_ERROR_CHECK(hid_host_install(&hid_host_driver_config));
|
||||||
|
|
||||||
// Task is working until the devices are gone (while 'user_shutdown' if false)
|
// Task is working until the devices are gone (while 'user_shutdown' if false)
|
||||||
user_shutdown = false;
|
user_shutdown = false;
|
||||||
|
@ -164,13 +164,13 @@ void app_main(void)
|
|||||||
.mode = GPIO_MODE_INPUT,
|
.mode = GPIO_MODE_INPUT,
|
||||||
.pull_up_en = GPIO_PULLUP_ENABLE,
|
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK( gpio_config(&input_pin) );
|
ESP_ERROR_CHECK(gpio_config(&input_pin));
|
||||||
|
|
||||||
usb_flags = xEventGroupCreate();
|
usb_flags = xEventGroupCreate();
|
||||||
assert(usb_flags);
|
assert(usb_flags);
|
||||||
|
|
||||||
const usb_host_config_t host_config = { .intr_flags = ESP_INTR_FLAG_LEVEL1 };
|
const usb_host_config_t host_config = { .intr_flags = ESP_INTR_FLAG_LEVEL1 };
|
||||||
ESP_ERROR_CHECK( usb_host_install(&host_config) );
|
ESP_ERROR_CHECK(usb_host_install(&host_config));
|
||||||
task_created = xTaskCreate(handle_usb_events, "usb_events", 2048, NULL, 2, NULL);
|
task_created = xTaskCreate(handle_usb_events, "usb_events", 2048, NULL, 2, NULL);
|
||||||
assert(task_created);
|
assert(task_created);
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ void app_main(void)
|
|||||||
.stack_size = 4096,
|
.stack_size = 4096,
|
||||||
.callback = msc_event_cb,
|
.callback = msc_event_cb,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK( msc_host_install(&msc_config) );
|
ESP_ERROR_CHECK(msc_host_install(&msc_config));
|
||||||
|
|
||||||
const esp_vfs_fat_mount_config_t mount_config = {
|
const esp_vfs_fat_mount_config_t mount_config = {
|
||||||
.format_if_mount_failed = false,
|
.format_if_mount_failed = false,
|
||||||
@ -191,28 +191,28 @@ void app_main(void)
|
|||||||
do {
|
do {
|
||||||
uint8_t device_address = wait_for_msc_device();
|
uint8_t device_address = wait_for_msc_device();
|
||||||
|
|
||||||
ESP_ERROR_CHECK( msc_host_install_device(device_address, &msc_device) );
|
ESP_ERROR_CHECK(msc_host_install_device(device_address, &msc_device));
|
||||||
|
|
||||||
msc_host_print_descriptors(msc_device);
|
msc_host_print_descriptors(msc_device);
|
||||||
|
|
||||||
ESP_ERROR_CHECK( msc_host_get_device_info(msc_device, &info) );
|
ESP_ERROR_CHECK(msc_host_get_device_info(msc_device, &info));
|
||||||
print_device_info(&info);
|
print_device_info(&info);
|
||||||
|
|
||||||
ESP_ERROR_CHECK( msc_host_vfs_register(msc_device, "/usb", &mount_config, &vfs_handle) );
|
ESP_ERROR_CHECK(msc_host_vfs_register(msc_device, "/usb", &mount_config, &vfs_handle));
|
||||||
|
|
||||||
while (!wait_for_event(DEVICE_DISCONNECTED, 200)) {
|
while (!wait_for_event(DEVICE_DISCONNECTED, 200)) {
|
||||||
file_operations();
|
file_operations();
|
||||||
}
|
}
|
||||||
|
|
||||||
xEventGroupClearBits(usb_flags, READY_TO_UNINSTALL);
|
xEventGroupClearBits(usb_flags, READY_TO_UNINSTALL);
|
||||||
ESP_ERROR_CHECK( msc_host_vfs_unregister(vfs_handle) );
|
ESP_ERROR_CHECK(msc_host_vfs_unregister(vfs_handle));
|
||||||
ESP_ERROR_CHECK( msc_host_uninstall_device(msc_device) );
|
ESP_ERROR_CHECK(msc_host_uninstall_device(msc_device));
|
||||||
|
|
||||||
} while (gpio_get_level(USB_DISCONNECT_PIN) != 0);
|
} while (gpio_get_level(USB_DISCONNECT_PIN) != 0);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Uninitializing USB ...");
|
ESP_LOGI(TAG, "Uninitializing USB ...");
|
||||||
ESP_ERROR_CHECK( msc_host_uninstall() );
|
ESP_ERROR_CHECK(msc_host_uninstall());
|
||||||
wait_for_event(READY_TO_UNINSTALL, portMAX_DELAY);
|
wait_for_event(READY_TO_UNINSTALL, portMAX_DELAY);
|
||||||
ESP_ERROR_CHECK( usb_host_uninstall() );
|
ESP_ERROR_CHECK(usb_host_uninstall());
|
||||||
ESP_LOGI(TAG, "Done");
|
ESP_LOGI(TAG, "Done");
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -33,22 +33,22 @@ static void client_event_cb(const usb_host_client_event_msg_t *event_msg, void *
|
|||||||
{
|
{
|
||||||
class_driver_t *driver_obj = (class_driver_t *)arg;
|
class_driver_t *driver_obj = (class_driver_t *)arg;
|
||||||
switch (event_msg->event) {
|
switch (event_msg->event) {
|
||||||
case USB_HOST_CLIENT_EVENT_NEW_DEV:
|
case USB_HOST_CLIENT_EVENT_NEW_DEV:
|
||||||
if (driver_obj->dev_addr == 0) {
|
if (driver_obj->dev_addr == 0) {
|
||||||
driver_obj->dev_addr = event_msg->new_dev.address;
|
driver_obj->dev_addr = event_msg->new_dev.address;
|
||||||
//Open the device next
|
//Open the device next
|
||||||
driver_obj->actions |= ACTION_OPEN_DEV;
|
driver_obj->actions |= ACTION_OPEN_DEV;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case USB_HOST_CLIENT_EVENT_DEV_GONE:
|
case USB_HOST_CLIENT_EVENT_DEV_GONE:
|
||||||
if (driver_obj->dev_hdl != NULL) {
|
if (driver_obj->dev_hdl != NULL) {
|
||||||
//Cancel any other actions and close the device next
|
//Cancel any other actions and close the device next
|
||||||
driver_obj->actions = ACTION_CLOSE_DEV;
|
driver_obj->actions = ACTION_CLOSE_DEV;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//Should never occur
|
//Should never occur
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ void class_driver_task(void *arg)
|
|||||||
.max_num_event_msg = CLIENT_NUM_EVENT_MSG,
|
.max_num_event_msg = CLIENT_NUM_EVENT_MSG,
|
||||||
.async = {
|
.async = {
|
||||||
.client_event_callback = client_event_cb,
|
.client_event_callback = client_event_cb,
|
||||||
.callback_arg = (void *)&driver_obj,
|
.callback_arg = (void *) &driver_obj,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(usb_host_client_register(&client_config, &driver_obj.client_hdl));
|
ESP_ERROR_CHECK(usb_host_client_register(&client_config, &driver_obj.client_hdl));
|
||||||
|
@ -35,7 +35,7 @@ static void host_lib_daemon_task(void *arg)
|
|||||||
|
|
||||||
bool has_clients = true;
|
bool has_clients = true;
|
||||||
bool has_devices = true;
|
bool has_devices = true;
|
||||||
while (has_clients || has_devices ) {
|
while (has_clients || has_devices) {
|
||||||
uint32_t event_flags;
|
uint32_t event_flags;
|
||||||
ESP_ERROR_CHECK(usb_host_lib_handle_events(portMAX_DELAY, &event_flags));
|
ESP_ERROR_CHECK(usb_host_lib_handle_events(portMAX_DELAY, &event_flags));
|
||||||
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS) {
|
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -99,7 +99,7 @@ static void uninitialize_usb_host_lib(void)
|
|||||||
xSemaphoreTake(ready_to_uninstall_usb, portMAX_DELAY);
|
xSemaphoreTake(ready_to_uninstall_usb, portMAX_DELAY);
|
||||||
vSemaphoreDelete(ready_to_uninstall_usb);
|
vSemaphoreDelete(ready_to_uninstall_usb);
|
||||||
|
|
||||||
if ( usb_host_uninstall() != ESP_OK) {
|
if (usb_host_uninstall() != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to uninstall usb_host");
|
ESP_LOGE(TAG, "Failed to uninstall usb_host");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,9 +163,9 @@ int app_main(int argc, char **argv)
|
|||||||
.mode = GPIO_MODE_INPUT,
|
.mode = GPIO_MODE_INPUT,
|
||||||
.pull_up_en = GPIO_PULLUP_ENABLE,
|
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK( gpio_config(&input_pin) );
|
ESP_ERROR_CHECK(gpio_config(&input_pin));
|
||||||
|
|
||||||
ESP_ERROR_CHECK( initialize_usb_host_lib() );
|
ESP_ERROR_CHECK(initialize_usb_host_lib());
|
||||||
|
|
||||||
libuvc_adapter_config_t config = {
|
libuvc_adapter_config_t config = {
|
||||||
.create_background_task = true,
|
.create_background_task = true,
|
||||||
@ -176,20 +176,20 @@ int app_main(int argc, char **argv)
|
|||||||
|
|
||||||
libuvc_adapter_set_config(&config);
|
libuvc_adapter_set_config(&config);
|
||||||
|
|
||||||
UVC_CHECK( uvc_init(&ctx, NULL) );
|
UVC_CHECK(uvc_init(&ctx, NULL));
|
||||||
|
|
||||||
// Streaming takes place only when enabled in menuconfig
|
// Streaming takes place only when enabled in menuconfig
|
||||||
ESP_ERROR_CHECK( tcp_server_wait_for_connection() );
|
ESP_ERROR_CHECK(tcp_server_wait_for_connection());
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
printf("Waiting for device\n");
|
printf("Waiting for device\n");
|
||||||
wait_for_event(UVC_DEVICE_CONNECTED);
|
wait_for_event(UVC_DEVICE_CONNECTED);
|
||||||
|
|
||||||
UVC_CHECK( uvc_find_device(ctx, &dev, PID, VID, SERIAL_NUMBER) );
|
UVC_CHECK(uvc_find_device(ctx, &dev, PID, VID, SERIAL_NUMBER));
|
||||||
puts("Device found");
|
puts("Device found");
|
||||||
|
|
||||||
UVC_CHECK( uvc_open(dev, &devh) );
|
UVC_CHECK(uvc_open(dev, &devh));
|
||||||
|
|
||||||
// Uncomment to print configuration descriptor
|
// Uncomment to print configuration descriptor
|
||||||
// libuvc_adapter_print_descriptors(devh);
|
// libuvc_adapter_print_descriptors(devh);
|
||||||
@ -200,10 +200,10 @@ int app_main(int argc, char **argv)
|
|||||||
uvc_print_diag(devh, stderr);
|
uvc_print_diag(devh, stderr);
|
||||||
|
|
||||||
// Negotiate stream profile
|
// Negotiate stream profile
|
||||||
res = uvc_get_stream_ctrl_format_size(devh, &ctrl, FORMAT, WIDTH, HEIGHT, FPS );
|
res = uvc_get_stream_ctrl_format_size(devh, &ctrl, FORMAT, WIDTH, HEIGHT, FPS);
|
||||||
while (res != UVC_SUCCESS) {
|
while (res != UVC_SUCCESS) {
|
||||||
printf("Negotiating streaming format failed, trying again...\n");
|
printf("Negotiating streaming format failed, trying again...\n");
|
||||||
res = uvc_get_stream_ctrl_format_size(devh, &ctrl, FORMAT, WIDTH, HEIGHT, FPS );
|
res = uvc_get_stream_ctrl_format_size(devh, &ctrl, FORMAT, WIDTH, HEIGHT, FPS);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +213,7 @@ int app_main(int argc, char **argv)
|
|||||||
|
|
||||||
uvc_print_stream_ctrl(&ctrl, stderr);
|
uvc_print_stream_ctrl(&ctrl, stderr);
|
||||||
|
|
||||||
UVC_CHECK( uvc_start_streaming(devh, &ctrl, frame_callback, NULL, 0) );
|
UVC_CHECK(uvc_start_streaming(devh, &ctrl, frame_callback, NULL, 0));
|
||||||
puts("Streaming...");
|
puts("Streaming...");
|
||||||
|
|
||||||
wait_for_event(UVC_DEVICE_DISCONNECTED);
|
wait_for_event(UVC_DEVICE_DISCONNECTED);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -53,7 +53,7 @@ static void sender_task(void *arg)
|
|||||||
while (1) {
|
while (1) {
|
||||||
size_t bytes_received = 0;
|
size_t bytes_received = 0;
|
||||||
char *payload = (char *)xRingbufferReceiveUpTo(
|
char *payload = (char *)xRingbufferReceiveUpTo(
|
||||||
server->buffer, &bytes_received, pdMS_TO_TICKS(2500), 20000);
|
server->buffer, &bytes_received, pdMS_TO_TICKS(2500), 20000);
|
||||||
|
|
||||||
if (payload != NULL && server->is_active) {
|
if (payload != NULL && server->is_active) {
|
||||||
int sent = send(server->sock, payload, bytes_received, 0);
|
int sent = send(server->sock, payload, bytes_received, 0);
|
||||||
@ -82,7 +82,7 @@ esp_err_t tcp_server_send(uint8_t *payload, size_t size)
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( xRingbufferSend(s_server->buffer, payload, size, pdMS_TO_TICKS(1)) != pdTRUE ) {
|
if (xRingbufferSend(s_server->buffer, payload, size, pdMS_TO_TICKS(1)) != pdTRUE) {
|
||||||
ESP_LOGW(TAG, "Failed to send frame to ring buffer.");
|
ESP_LOGW(TAG, "Failed to send frame to ring buffer.");
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
@ -179,18 +179,17 @@ esp_err_t tcp_server_wait_for_connection(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
server->buffer = xRingbufferCreate(100000, RINGBUF_TYPE_BYTEBUF);
|
server->buffer = xRingbufferCreate(100000, RINGBUF_TYPE_BYTEBUF);
|
||||||
if ( server->buffer == NULL) {
|
if (server->buffer == NULL) {
|
||||||
free(server);
|
free(server);
|
||||||
return ESP_ERR_NO_MEM;;
|
return ESP_ERR_NO_MEM;;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( create_server(server) != ESP_OK) {
|
if (create_server(server) != ESP_OK) {
|
||||||
vRingbufferDelete(server->buffer);
|
vRingbufferDelete(server->buffer);
|
||||||
free(server);
|
free(server);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BaseType_t task_created = xTaskCreate(sender_task, "sender_task", 4096, server, 10, &task_handle);
|
BaseType_t task_created = xTaskCreate(sender_task, "sender_task", 4096, server, 10, &task_handle);
|
||||||
if (!task_created) {
|
if (!task_created) {
|
||||||
socket_close(server);
|
socket_close(server);
|
||||||
|
@ -127,7 +127,6 @@ components_not_formatted_temporary:
|
|||||||
- "/examples/mesh/"
|
- "/examples/mesh/"
|
||||||
- "/examples/network/"
|
- "/examples/network/"
|
||||||
- "/examples/openthread/"
|
- "/examples/openthread/"
|
||||||
- "/examples/peripherals/"
|
|
||||||
- "/examples/phy/"
|
- "/examples/phy/"
|
||||||
- "/examples/protocols/"
|
- "/examples/protocols/"
|
||||||
- "/examples/provisioning/"
|
- "/examples/provisioning/"
|
||||||
@ -174,6 +173,9 @@ components_not_formatted_permanent:
|
|||||||
- "/components/app_trace/sys_view/SEGGER/"
|
- "/components/app_trace/sys_view/SEGGER/"
|
||||||
# SoC header files (generated)
|
# SoC header files (generated)
|
||||||
- "/components/soc/*/include/soc/"
|
- "/components/soc/*/include/soc/"
|
||||||
|
# Example resource files (generated)
|
||||||
|
- "/examples/peripherals/lcd/i80_controller/main/images/"
|
||||||
|
- "/examples/peripherals/dac/dac_continuous/dac_audio/main/audio_example_file.h"
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
# Docs directory contains some .inc files, which are not C include files
|
# Docs directory contains some .inc files, which are not C include files
|
||||||
|
Loading…
Reference in New Issue
Block a user