first commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
# The following five lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(EXTRA_COMPONENT_DIRS
|
||||
./components
|
||||
)
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(test)
|
||||
@@ -0,0 +1,20 @@
|
||||
set(SRCS "")
|
||||
list(APPEND SRCS
|
||||
"src/bsp_board_extra.c"
|
||||
)
|
||||
|
||||
set(INCLUDE_DIRS "")
|
||||
list(APPEND INCLUDE_DIRS "include")
|
||||
|
||||
foreach(SRC_DIR IN LISTS SRC_DIRS)
|
||||
file(GLOB_RECURSE SRC ${SRC_DIR}/*.c)
|
||||
list(APPEND SRCS ${SRC})
|
||||
list(APPEND INCLUDE_DIRS ${SRC_DIR}/include)
|
||||
endforeach()
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SRCS}
|
||||
INCLUDE_DIRS ${INCLUDE_DIRS}
|
||||
REQUIRES driver
|
||||
PRIV_REQUIRES esp_timer fatfs esp_psram esp_mm
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
menu "Board Support Package"
|
||||
config BSP_I2S_NUM
|
||||
int "I2S peripheral index"
|
||||
default 1
|
||||
range 0 1
|
||||
help
|
||||
ESP32S3 has two I2S peripherals, pick the one you want to use.
|
||||
endmenu
|
||||
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -0,0 +1,20 @@
|
||||
dependencies:
|
||||
idf:
|
||||
version: '>=5.3.0'
|
||||
|
||||
# espressif/esp32_p4_function_ev_board:
|
||||
# version: "4.1.*"
|
||||
waveshare/esp32_p4_nano: "*"
|
||||
|
||||
chmorgan/esp-audio-player:
|
||||
version: "1.0.*"
|
||||
public: true
|
||||
|
||||
chmorgan/esp-file-iterator:
|
||||
version: "1.0.0"
|
||||
public: true
|
||||
|
||||
description: Board Support Package for ESP32-P4-Function-ev-board
|
||||
targets:
|
||||
- esp32p4
|
||||
version: 0.0.2
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_codec_dev.h"
|
||||
#include "esp_err.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/i2s_std.h"
|
||||
#include "audio_player.h"
|
||||
#include "file_iterator.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CODEC_DEFAULT_SAMPLE_RATE (16000)
|
||||
#define CODEC_DEFAULT_BIT_WIDTH (16)
|
||||
#define CODEC_DEFAULT_ADC_VOLUME (24.0)
|
||||
#define CODEC_DEFAULT_CHANNEL (2)
|
||||
#define CODEC_DEFAULT_VOLUME (60)
|
||||
|
||||
#define BSP_LCD_BACKLIGHT_BRIGHTNESS_MAX (95)
|
||||
#define BSP_LCD_BACKLIGHT_BRIGHTNESS_MIN (0)
|
||||
#define LCD_LEDC_CH (CONFIG_BSP_DISPLAY_BRIGHTNESS_LEDC_CH)
|
||||
|
||||
/**************************************************************************************************
|
||||
* BSP Extra interface
|
||||
* Mainly provided some I2S Codec interfaces.
|
||||
**************************************************************************************************/
|
||||
/**
|
||||
* @brief Player set mute.
|
||||
*
|
||||
* @param enable: true or false
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_extra_codec_mute_set(bool enable);
|
||||
|
||||
/**
|
||||
* @brief Player set volume.
|
||||
*
|
||||
* @param volume: volume set
|
||||
* @param volume_set: volume set response
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_extra_codec_volume_set(int volume, int *volume_set);
|
||||
|
||||
/**
|
||||
* @brief Player get volume.
|
||||
*
|
||||
* @return
|
||||
* - volume: volume get
|
||||
*/
|
||||
int bsp_extra_codec_volume_get(void);
|
||||
|
||||
/**
|
||||
* @brief Stop I2S function.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_extra_codec_dev_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Resume I2S function.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_extra_codec_dev_resume(void);
|
||||
|
||||
/**
|
||||
* @brief Set I2S format to codec.
|
||||
*
|
||||
* @param rate: Sample rate of sample
|
||||
* @param bits_cfg: Bit lengths of one channel data
|
||||
* @param ch: Channels of sample
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_extra_codec_set_fs(uint32_t rate, uint32_t bits_cfg, i2s_slot_mode_t ch);
|
||||
|
||||
/**
|
||||
* @brief Read data from recoder.
|
||||
*
|
||||
* @param audio_buffer: The pointer of receiving data buffer
|
||||
* @param len: Max data buffer length
|
||||
* @param bytes_read: Byte number that actually be read, can be NULL if not needed
|
||||
* @param timeout_ms: Max block time
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_extra_i2s_read(void *audio_buffer, size_t len, size_t *bytes_read, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Write data to player.
|
||||
*
|
||||
* @param audio_buffer: The pointer of sent data buffer
|
||||
* @param len: Max data buffer length
|
||||
* @param bytes_written: Byte number that actually be sent, can be NULL if not needed
|
||||
* @param timeout_ms: Max block time
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_extra_i2s_write(void *audio_buffer, size_t len, size_t *bytes_written, uint32_t timeout_ms);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize codec play and record handle.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_extra_codec_init();
|
||||
|
||||
/**
|
||||
* @brief Initialize audio player task.
|
||||
*
|
||||
* @param path file path
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_extra_player_init(void);
|
||||
|
||||
/**
|
||||
* @brief Delete audio player task.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_extra_player_del(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize a file iterator instance
|
||||
*
|
||||
* @param path The file path for the iterator.
|
||||
* @param ret_instance A pointer to the file iterator instance to be returned.
|
||||
* @return
|
||||
* - ESP_OK: Successfully initialized the file iterator instance.
|
||||
* - ESP_FAIL: Failed to initialize the file iterator instance due to invalid parameters or memory allocation failure.
|
||||
*/
|
||||
esp_err_t bsp_extra_file_instance_init(const char *path, file_iterator_instance_t **ret_instance);
|
||||
|
||||
/**
|
||||
* @brief Play the audio file at the specified index in the file iterator
|
||||
*
|
||||
* @param instance The file iterator instance.
|
||||
* @param index The index of the file to play within the iterator.
|
||||
* @return
|
||||
* - ESP_OK: Successfully started playing the audio file.
|
||||
* - ESP_FAIL: Failed to play the audio file due to invalid parameters or file access issues.
|
||||
*/
|
||||
esp_err_t bsp_extra_player_play_index(file_iterator_instance_t *instance, int index);
|
||||
|
||||
/**
|
||||
* @brief Play the audio file specified by the file path
|
||||
*
|
||||
* @param file_path The path to the audio file to be played.
|
||||
* @return
|
||||
* - ESP_OK: Successfully started playing the audio file.
|
||||
* - ESP_FAIL: Failed to play the audio file due to file access issues.
|
||||
*/
|
||||
esp_err_t bsp_extra_player_play_file(const char *file_path);
|
||||
|
||||
/**
|
||||
* @brief Register a callback function for the audio player
|
||||
*
|
||||
* @param cb The callback function to be registered.
|
||||
* @param user_data User data to be passed to the callback function.
|
||||
*/
|
||||
void bsp_extra_player_register_callback(audio_player_cb_t cb, void *user_data);
|
||||
|
||||
/**
|
||||
* @brief Check if the specified audio file is currently playing
|
||||
*
|
||||
* @param file_path The path to the audio file to check.
|
||||
* @return
|
||||
* - true: The specified audio file is currently playing.
|
||||
* - false: The specified audio file is not currently playing.
|
||||
*/
|
||||
bool bsp_extra_player_is_playing_by_path(const char *file_path);
|
||||
|
||||
/**
|
||||
* @brief Check if the audio file at the specified index is currently playing
|
||||
*
|
||||
* @param instance The file iterator instance.
|
||||
* @param index The index of the file to check.
|
||||
* @return
|
||||
* - true: The audio file at the specified index is currently playing.
|
||||
* - false: The audio file at the specified index is not currently playing.
|
||||
*/
|
||||
bool bsp_extra_player_is_playing_by_index(file_iterator_instance_t *instance, int index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_codec_dev_defaults.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "driver/i2c.h"
|
||||
#include "driver/i2s_std.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/ledc.h"
|
||||
|
||||
#include "bsp/esp-bsp.h"
|
||||
#include "bsp_board_extra.h"
|
||||
|
||||
static const char *TAG = "bsp_extra_board";
|
||||
|
||||
static esp_codec_dev_handle_t play_dev_handle;
|
||||
static esp_codec_dev_handle_t record_dev_handle;
|
||||
|
||||
static bool _is_audio_init = false;
|
||||
static bool _is_player_init = false;
|
||||
static int _vloume_intensity = CODEC_DEFAULT_VOLUME;
|
||||
|
||||
static audio_player_cb_t audio_idle_callback = NULL;
|
||||
static void *audio_idle_cb_user_data = NULL;
|
||||
static char audio_file_path[128];
|
||||
|
||||
/**************************************************************************************************
|
||||
*
|
||||
* Extra Board Function
|
||||
*
|
||||
**************************************************************************************************/
|
||||
|
||||
static esp_err_t audio_mute_function(AUDIO_PLAYER_MUTE_SETTING setting)
|
||||
{
|
||||
// Volume saved when muting and restored when unmuting. Restoring volume is necessary
|
||||
// as es8311_set_voice_mute(true) results in voice volume (REG32) being set to zero.
|
||||
|
||||
bsp_extra_codec_mute_set(setting == AUDIO_PLAYER_MUTE ? true : false);
|
||||
|
||||
// restore the voice volume upon unmuting
|
||||
if (setting == AUDIO_PLAYER_UNMUTE) {
|
||||
ESP_RETURN_ON_ERROR(esp_codec_dev_set_out_vol(play_dev_handle, _vloume_intensity), TAG, "Set Codec volume failed");
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void audio_callback(audio_player_cb_ctx_t *ctx)
|
||||
{
|
||||
if (audio_idle_callback) {
|
||||
ctx->user_ctx = audio_idle_cb_user_data;
|
||||
audio_idle_callback(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t bsp_extra_i2s_read(void *audio_buffer, size_t len, size_t *bytes_read, uint32_t timeout_ms)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ret = esp_codec_dev_read(record_dev_handle, audio_buffer, len);
|
||||
*bytes_read = len;
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_extra_i2s_write(void *audio_buffer, size_t len, size_t *bytes_written, uint32_t timeout_ms)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ret = esp_codec_dev_write(play_dev_handle, audio_buffer, len);
|
||||
*bytes_written = len;
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_extra_codec_set_fs(uint32_t rate, uint32_t bits_cfg, i2s_slot_mode_t ch)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
esp_codec_dev_sample_info_t fs = {
|
||||
.sample_rate = rate,
|
||||
.channel = ch,
|
||||
.bits_per_sample = bits_cfg,
|
||||
};
|
||||
|
||||
if (play_dev_handle) {
|
||||
ret = esp_codec_dev_close(play_dev_handle);
|
||||
}
|
||||
if (record_dev_handle) {
|
||||
ret |= esp_codec_dev_close(record_dev_handle);
|
||||
ret |= esp_codec_dev_set_in_gain(record_dev_handle, CODEC_DEFAULT_ADC_VOLUME);
|
||||
}
|
||||
|
||||
if (play_dev_handle) {
|
||||
ret |= esp_codec_dev_open(play_dev_handle, &fs);
|
||||
}
|
||||
if (record_dev_handle) {
|
||||
ret |= esp_codec_dev_open(record_dev_handle, &fs);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_extra_codec_volume_set(int volume, int *volume_set)
|
||||
{
|
||||
ESP_RETURN_ON_ERROR(esp_codec_dev_set_out_vol(play_dev_handle, volume), TAG, "Set Codec volume failed");
|
||||
_vloume_intensity = volume;
|
||||
|
||||
ESP_LOGI(TAG, "Setting volume: %d", volume);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int bsp_extra_codec_volume_get(void)
|
||||
{
|
||||
return _vloume_intensity;
|
||||
}
|
||||
|
||||
esp_err_t bsp_extra_codec_mute_set(bool enable)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ret = esp_codec_dev_set_out_mute(play_dev_handle, enable);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_extra_codec_dev_stop(void)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
if (play_dev_handle) {
|
||||
ret = esp_codec_dev_close(play_dev_handle);
|
||||
}
|
||||
|
||||
if (record_dev_handle) {
|
||||
ret = esp_codec_dev_close(record_dev_handle);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_extra_codec_dev_resume(void)
|
||||
{
|
||||
return bsp_extra_codec_set_fs(CODEC_DEFAULT_SAMPLE_RATE, CODEC_DEFAULT_BIT_WIDTH, CODEC_DEFAULT_CHANNEL);
|
||||
}
|
||||
|
||||
esp_err_t bsp_extra_codec_init()
|
||||
{
|
||||
if (_is_audio_init) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
play_dev_handle = bsp_audio_codec_speaker_init();
|
||||
assert((play_dev_handle) && "play_dev_handle not initialized");
|
||||
|
||||
record_dev_handle = bsp_audio_codec_microphone_init();
|
||||
assert((record_dev_handle) && "record_dev_handle not initialized");
|
||||
|
||||
bsp_extra_codec_set_fs(CODEC_DEFAULT_SAMPLE_RATE, CODEC_DEFAULT_BIT_WIDTH, CODEC_DEFAULT_CHANNEL);
|
||||
|
||||
_is_audio_init = true;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_extra_player_init(void)
|
||||
{
|
||||
if (_is_player_init) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
audio_player_config_t config = { .mute_fn = audio_mute_function,
|
||||
.write_fn = bsp_extra_i2s_write,
|
||||
.clk_set_fn = bsp_extra_codec_set_fs,
|
||||
.priority = 5
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(audio_player_new(config), TAG, "audio_player_init failed");
|
||||
audio_player_callback_register(audio_callback, NULL);
|
||||
|
||||
_is_player_init = true;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_extra_player_del(void)
|
||||
{
|
||||
_is_player_init = false;
|
||||
|
||||
ESP_RETURN_ON_ERROR(audio_player_delete(), TAG, "audio_player_delete failed");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_extra_file_instance_init(const char *path, file_iterator_instance_t **ret_instance)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(path, ESP_FAIL, TAG, "path is NULL");
|
||||
ESP_RETURN_ON_FALSE(ret_instance, ESP_FAIL, TAG, "ret_instance is NULL");
|
||||
|
||||
file_iterator_instance_t *file_iterator = file_iterator_new(path);
|
||||
ESP_RETURN_ON_FALSE(file_iterator, ESP_FAIL, TAG, "file_iterator_new failed, %s", path);
|
||||
|
||||
*ret_instance = file_iterator;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_extra_player_play_index(file_iterator_instance_t *instance, int index)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(instance, ESP_FAIL, TAG, "instance is NULL");
|
||||
|
||||
ESP_LOGI(TAG, "play_index(%d)", index);
|
||||
char filename[128];
|
||||
int retval = file_iterator_get_full_path_from_index(instance, index, filename, sizeof(filename));
|
||||
ESP_RETURN_ON_FALSE(retval != 0, ESP_FAIL, TAG, "file_iterator_get_full_path_from_index failed");
|
||||
|
||||
ESP_LOGI(TAG, "opening file '%s'", filename);
|
||||
FILE *fp = fopen(filename, "rb");
|
||||
ESP_RETURN_ON_FALSE(fp, ESP_FAIL, TAG, "unable to open file");
|
||||
|
||||
ESP_LOGI(TAG, "Playing '%s'", filename);
|
||||
ESP_RETURN_ON_ERROR(audio_player_play(fp), TAG, "audio_player_play failed");
|
||||
|
||||
memcpy(audio_file_path, filename, sizeof(audio_file_path));
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_extra_player_play_file(const char *file_path)
|
||||
{
|
||||
ESP_LOGI(TAG, "opening file '%s'", file_path);
|
||||
FILE *fp = fopen(file_path, "rb");
|
||||
ESP_RETURN_ON_FALSE(fp, ESP_FAIL, TAG, "unable to open file");
|
||||
|
||||
ESP_LOGI(TAG, "Playing '%s'", file_path);
|
||||
ESP_RETURN_ON_ERROR(audio_player_play(fp), TAG, "audio_player_play failed");
|
||||
|
||||
memcpy(audio_file_path, file_path, sizeof(audio_file_path));
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void bsp_extra_player_register_callback(audio_player_cb_t cb, void *user_data)
|
||||
{
|
||||
audio_idle_callback = cb;
|
||||
audio_idle_cb_user_data = user_data;
|
||||
}
|
||||
|
||||
bool bsp_extra_player_is_playing_by_path(const char *file_path)
|
||||
{
|
||||
return (strcmp(audio_file_path, file_path) == 0);
|
||||
}
|
||||
|
||||
bool bsp_extra_player_is_playing_by_index(file_iterator_instance_t *instance, int index)
|
||||
{
|
||||
return (index == file_iterator_get_index(instance));
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
idf_component_register(SRCS "esp_lcd_touch_gsl3680.c" "gsl_point_id.c" INCLUDE_DIRS "include" REQUIRES "esp_lcd")
|
||||
+705
@@ -0,0 +1,705 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/i2c_master.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_touch.h"
|
||||
#include "esp_lcd_touch_gsl3680.h"
|
||||
#include "gsl_point_id.h"
|
||||
|
||||
#define TAG "gsl3680"
|
||||
|
||||
/* gsl3680 registers */
|
||||
#define ESP_LCD_TOUCH_GSL3680_READ_XY_REG (0x80)
|
||||
|
||||
/* gsl3680 support key num */
|
||||
#define ESP_gsl3680_TOUCH_MAX_BUTTONS (9)
|
||||
|
||||
|
||||
|
||||
unsigned int gsl_config_data_id[] =
|
||||
{
|
||||
0xcecbac,
|
||||
0x200,
|
||||
0,0,
|
||||
0,
|
||||
0,0,0,
|
||||
0,0,0,0,0,0,0,0x1cc86fd6,
|
||||
|
||||
|
||||
0x40000d00,0xa,0xe001a,0xe001a,0x3200500,0,0x5100,0x8e00,
|
||||
0,0x320014,0,0x14,0,0,0,0,
|
||||
0x8,0x4000,0x1000,0x10170002,0x10110000,0,0,0x4040404,
|
||||
0x1b6db688,0x64,0xb3000f,0xad0019,0xa60023,0xa0002d,0xb3000f,0xad0019,
|
||||
0xa60023,0xa0002d,0xb3000f,0xad0019,0xa60023,0xa0002d,0xb3000f,0xad0019,
|
||||
0xa60023,0xa0002d,0x804000,0x90040,0x90001,0,0,0,
|
||||
0,0,0,0x14012c,0xa003c,0xa0078,0x400,0x1081,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
|
||||
0,//key_map
|
||||
0x3200384,0x64,0x503e8,//0
|
||||
0,0,0,//1
|
||||
0,0,0,//2
|
||||
0,0,0,//3
|
||||
0,0,0,//4
|
||||
0,0,0,//5
|
||||
0,0,0,//6
|
||||
0,0,0,//7
|
||||
|
||||
0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
|
||||
|
||||
0x220,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0x10203,0x4050607,0x8090a0b,0xc0d0e0f,0x10111213,0x14151617,0x18191a1b,0x1c1d1e1f,
|
||||
0x20212223,0x24252627,0x28292a2b,0x2c2d2e2f,0x30313233,0x34353637,0x38393a3b,0x3c3d3e3f,
|
||||
0x10203,0x4050607,0x8090a0b,0xc0d0e0f,0x10111213,0x14151617,0x18191a1b,0x1c1d1e1f,
|
||||
0x20212223,0x24252627,0x28292a2b,0x2c2d2e2f,0x30313233,0x34353637,0x38393a3b,0x3c3d3e3f,
|
||||
|
||||
0x10203,0x4050607,0x8090a0b,0xc0d0e0f,0x10111213,0x14151617,0x18191a1b,0x1c1d1e1f,
|
||||
0x20212223,0x24252627,0x28292a2b,0x2c2d2e2f,0x30313233,0x34353637,0x38393a3b,0x3c3d3e3f,
|
||||
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
|
||||
0x10203,0x4050607,0x8090a0b,0xc0d0e0f,0x10111213,0x14151617,0x18191a1b,0x1c1d1e1f,
|
||||
0x20212223,0x24252627,0x28292a2b,0x2c2d2e2f,0x30313233,0x34353637,0x38393a3b,0x3c3d3e3f,
|
||||
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,
|
||||
|
||||
|
||||
0x3,
|
||||
0x101,0,0x100,0,
|
||||
0x20,0x10,0x8,0x4,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
|
||||
0x4,0,0,0,0,0,0,0,
|
||||
0x3800680,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// static TG_STATE_E tpc_gesture_id = TG_UNKNOWN_STATE;
|
||||
static XY_DATA_T XY_Coordinate[MAX_FINGER_NUM]={0};
|
||||
esp_lcd_touch_handle_t esp_lcd_touch_gsl3680;
|
||||
|
||||
static uint8_t Finger_num = 0;
|
||||
static TP_STATE_E tp_event = TP_PEN_NONE;
|
||||
static uint8_t pre_pen_flag = 0;
|
||||
|
||||
static uint16_t x_new = 0;
|
||||
static uint16_t y_new = 0;
|
||||
static uint16_t x_start = 0 , y_start = 0;
|
||||
|
||||
|
||||
static esp_err_t esp_lcd_touch_gsl3680_read_data(esp_lcd_touch_handle_t tp);
|
||||
static bool esp_lcd_touch_gsl3680_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num);
|
||||
#if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0)
|
||||
static esp_err_t esp_lcd_touch_gsl3680_get_button_state(esp_lcd_touch_handle_t tp, uint8_t n, uint8_t *state);
|
||||
#endif
|
||||
static esp_err_t esp_lcd_touch_gsl3680_del(esp_lcd_touch_handle_t tp);
|
||||
|
||||
/* I2C read/write */
|
||||
static esp_err_t touch_gsl3680_i2c_read(esp_lcd_touch_handle_t tp, uint16_t reg, uint8_t *data, uint8_t len);
|
||||
static esp_err_t touch_gsl3680_i2c_write(esp_lcd_touch_handle_t tp, uint16_t reg, uint8_t *data, uint8_t len);
|
||||
|
||||
/* gsl3680 reset */
|
||||
static esp_err_t touch_gsl3680_reset(esp_lcd_touch_handle_t tp);
|
||||
/* Read status and config register */
|
||||
static esp_err_t touch_gsl3680_read_cfg(esp_lcd_touch_handle_t tp);
|
||||
|
||||
/* gsl3680 enter/exit sleep mode */
|
||||
static esp_err_t esp_lcd_touch_gsl3680_enter_sleep(esp_lcd_touch_handle_t tp);
|
||||
static esp_err_t esp_lcd_touch_gsl3680_exit_sleep(esp_lcd_touch_handle_t tp);
|
||||
static esp_err_t esp_lcd_touch_gsl3680_startup_chip(esp_lcd_touch_handle_t tp);
|
||||
static esp_err_t esp_lcd_touch_gsl3680_read_ram_fw(esp_lcd_touch_handle_t tp);
|
||||
static esp_err_t esp_lcd_touch_gsl3680_load_fw(esp_lcd_touch_handle_t tp);
|
||||
static esp_err_t esp_lcd_touch_gsl3680_clear_reg(esp_lcd_touch_handle_t tp);
|
||||
static esp_err_t esp_lcd_touch_gsl3680_init(esp_lcd_touch_handle_t tp);
|
||||
static TP_STATE_E _Get_Cal_msg(void);
|
||||
|
||||
esp_err_t esp_lcd_touch_new_i2c_gsl3680(esp_lcd_panel_io_handle_t io, const esp_lcd_touch_config_t *config, esp_lcd_touch_handle_t *out_touch)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
assert(io != NULL);
|
||||
assert(config != NULL);
|
||||
assert(out_touch != NULL);
|
||||
|
||||
/* Prepare main structure */
|
||||
esp_lcd_touch_gsl3680 = heap_caps_calloc(1, sizeof(esp_lcd_touch_t), MALLOC_CAP_DEFAULT);
|
||||
ESP_GOTO_ON_FALSE(esp_lcd_touch_gsl3680, ESP_ERR_NO_MEM, err, TAG, "no mem for GSL3680 controller");
|
||||
|
||||
/* Communication interface */
|
||||
esp_lcd_touch_gsl3680->io = io;
|
||||
|
||||
/* Only supported callbacks are set */
|
||||
esp_lcd_touch_gsl3680->read_data = esp_lcd_touch_gsl3680_read_data;
|
||||
// esp_lcd_touch_gsl3680->get_xy = esp_lcd_touch_gsl3680_get_xy;
|
||||
esp_lcd_touch_gsl3680->get_xy = esp_lcd_touch_gsl3680_get_xy;
|
||||
#if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0)
|
||||
esp_lcd_touch_gsl3680->get_button_state = esp_lcd_touch_gsl3680_get_button_state;
|
||||
#endif
|
||||
esp_lcd_touch_gsl3680->del = esp_lcd_touch_gsl3680_del;
|
||||
esp_lcd_touch_gsl3680->enter_sleep = esp_lcd_touch_gsl3680_enter_sleep;
|
||||
esp_lcd_touch_gsl3680->exit_sleep = esp_lcd_touch_gsl3680_exit_sleep;
|
||||
|
||||
/* Mutex */
|
||||
esp_lcd_touch_gsl3680->data.lock.owner = portMUX_FREE_VAL;
|
||||
|
||||
/* Save config */
|
||||
memcpy(&esp_lcd_touch_gsl3680->config, config, sizeof(esp_lcd_touch_config_t));
|
||||
esp_lcd_touch_io_gsl3680_config_t *gsl3680_config = (esp_lcd_touch_io_gsl3680_config_t *)esp_lcd_touch_gsl3680->config.driver_data;
|
||||
|
||||
/* Prepare pin for touch controller reset */
|
||||
if (esp_lcd_touch_gsl3680->config.rst_gpio_num != GPIO_NUM_NC) {
|
||||
const gpio_config_t rst_gpio_config = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = BIT64(esp_lcd_touch_gsl3680->config.rst_gpio_num),
|
||||
};
|
||||
ret = gpio_config(&rst_gpio_config);
|
||||
ESP_GOTO_ON_ERROR(ret, err, TAG, "GPIO config failed");
|
||||
}
|
||||
|
||||
if (gsl3680_config && esp_lcd_touch_gsl3680->config.rst_gpio_num != GPIO_NUM_NC && esp_lcd_touch_gsl3680->config.int_gpio_num != GPIO_NUM_NC) {
|
||||
/* Prepare pin for touch controller int */
|
||||
const gpio_config_t int_gpio_config = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
.pull_down_en = 0,
|
||||
.pull_up_en = true,
|
||||
.pin_bit_mask = BIT64(esp_lcd_touch_gsl3680->config.int_gpio_num),
|
||||
};
|
||||
ret = gpio_config(&int_gpio_config);
|
||||
ESP_GOTO_ON_ERROR(ret, err, TAG, "GPIO config failed");
|
||||
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(esp_lcd_touch_gsl3680->config.rst_gpio_num, esp_lcd_touch_gsl3680->config.levels.reset), TAG, "GPIO set level error!");
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(esp_lcd_touch_gsl3680->config.int_gpio_num, 1), TAG, "GPIO set level error!");
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
/* Select I2C addr, set output high or low */
|
||||
uint32_t gpio_level;
|
||||
if (ESP_LCD_TOUCH_IO_I2C_GSL3680_ADDRESS == gsl3680_config->dev_addr) {
|
||||
gpio_level = 1;
|
||||
} else {
|
||||
gpio_level = 0;
|
||||
ESP_LOGE(TAG, "Addr (0x%X) is invalid", gsl3680_config->dev_addr);
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(esp_lcd_touch_gsl3680->config.int_gpio_num, 1), TAG, "GPIO set level error!");
|
||||
vTaskDelay(pdMS_TO_TICKS(1));
|
||||
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(esp_lcd_touch_gsl3680->config.rst_gpio_num, !esp_lcd_touch_gsl3680->config.levels.reset), TAG, "GPIO set level error!");
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Unable to initialize the I2C address");
|
||||
/* Reset controller */
|
||||
ret = touch_gsl3680_reset(esp_lcd_touch_gsl3680);
|
||||
ESP_GOTO_ON_ERROR(ret, err, TAG, "GSL3680 reset failed");
|
||||
}
|
||||
|
||||
/* Read status and config info */
|
||||
ESP_LOGI(TAG,"init gls3680");
|
||||
touch_gsl3680_read_cfg(esp_lcd_touch_gsl3680);
|
||||
esp_lcd_touch_gsl3680_init(esp_lcd_touch_gsl3680);
|
||||
ret = esp_lcd_touch_gsl3680_read_ram_fw(esp_lcd_touch_gsl3680);
|
||||
// touch_gsl3680_read_cfg(esp_lcd_touch_gsl3680);
|
||||
|
||||
/* Prepare pin for touch interrupt */
|
||||
if (esp_lcd_touch_gsl3680->config.int_gpio_num != GPIO_NUM_NC) {
|
||||
const gpio_config_t int_gpio_config = {
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
.intr_type = (esp_lcd_touch_gsl3680->config.levels.interrupt ? GPIO_INTR_POSEDGE : GPIO_INTR_NEGEDGE),
|
||||
.pin_bit_mask = BIT64(esp_lcd_touch_gsl3680->config.int_gpio_num)
|
||||
};
|
||||
ret = gpio_config(&int_gpio_config);
|
||||
ESP_GOTO_ON_ERROR(ret, err, TAG, "GPIO config failed");
|
||||
|
||||
/* Register interrupt callback */
|
||||
if (esp_lcd_touch_gsl3680->config.interrupt_callback) {
|
||||
esp_lcd_touch_register_interrupt_callback(esp_lcd_touch_gsl3680, esp_lcd_touch_gsl3680->config.interrupt_callback);
|
||||
}
|
||||
}
|
||||
|
||||
err:
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Error (0x%x)! Touch controller GSL3680 initialization failed!", ret);
|
||||
if (esp_lcd_touch_gsl3680) {
|
||||
esp_lcd_touch_gsl3680_del(esp_lcd_touch_gsl3680);
|
||||
}
|
||||
}
|
||||
|
||||
*out_touch = esp_lcd_touch_gsl3680;
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static esp_err_t esp_lcd_touch_gsl3680_enter_sleep(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
// esp_err_t err = touch_gsl3680_i2c_write(tp, ESP_LCD_TOUCH_GSL3680_ENTER_SLEEP, 0x05);
|
||||
// ESP_RETURN_ON_ERROR(err, TAG, "Enter Sleep failed!");
|
||||
|
||||
if (tp->config.rst_gpio_num != GPIO_NUM_NC) {
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(tp->config.rst_gpio_num, 0), TAG, "GPIO set level error!");
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t esp_lcd_touch_gsl3680_exit_sleep(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(tp->config.rst_gpio_num, 1), TAG, "GPIO set level error!");
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t esp_lcd_touch_gsl3680_read_data(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
esp_err_t err;
|
||||
uint8_t touch_data[24];
|
||||
uint8_t touch_cnt = 0;
|
||||
uint16_t x_poit, y_poit, x2_poit, y2_poit;
|
||||
|
||||
assert(tp != NULL);
|
||||
|
||||
// #ifdef USE_GSL_NOID_VERSION
|
||||
struct gsl_touch_info cinfo = {0};
|
||||
unsigned int tmp1 = 0;
|
||||
uint8_t buf[4] = {0};
|
||||
// #endif
|
||||
|
||||
memset(XY_Coordinate,0,sizeof(XY_Coordinate));
|
||||
|
||||
err = touch_gsl3680_i2c_read(tp, ESP_LCD_TOUCH_GSL3680_READ_XY_REG, touch_data, 44);
|
||||
Finger_num = touch_data[0];
|
||||
// ESP_LOGI(TAG,"0x80 = %d",touch_data[0]);
|
||||
|
||||
cinfo.finger_num = Finger_num;
|
||||
for(int j=0;j<Finger_num;j++)
|
||||
{
|
||||
x_poit = touch_data[(j+1)*4+3] & 0x0f;
|
||||
x2_poit = touch_data[(j+1)*4+2];
|
||||
cinfo.x[j] = x_poit << 8 | x2_poit;
|
||||
y_poit = touch_data[(j+1)*4+1];
|
||||
y2_poit = touch_data[(j+1)*4+0];
|
||||
cinfo.y[j] = y_poit << 8 | y2_poit;
|
||||
cinfo.id[j] = ((touch_data[(j+1)*4+3] & 0xf0) >> 4);
|
||||
}
|
||||
|
||||
gsl_alg_id_main(&cinfo);
|
||||
tmp1=gsl_mask_tiaoping();
|
||||
|
||||
if(tmp1>0&&tmp1<0xffffffff)
|
||||
{
|
||||
uint8 addr = 0xf0;
|
||||
buf[0]=0xa;buf[1]=0;buf[2]=0;buf[3]=0;
|
||||
touch_gsl3680_i2c_write(tp,addr, buf, 4);
|
||||
addr = 0x8;
|
||||
buf[0]=(uint8)(tmp1 & 0xff);
|
||||
buf[1]=(uint8)((tmp1>>8) & 0xff);
|
||||
buf[2]=(uint8)((tmp1>>16) & 0xff);
|
||||
buf[3]=(uint8)((tmp1>>24) & 0xff);
|
||||
|
||||
touch_gsl3680_i2c_write(tp,addr, buf, 4);
|
||||
}
|
||||
Finger_num = cinfo.finger_num;
|
||||
|
||||
for(int j=0;j<Finger_num;j++)
|
||||
{
|
||||
XY_Coordinate[j].x_position = cinfo.x[j];
|
||||
XY_Coordinate[j].y_position = cinfo.y[j];
|
||||
XY_Coordinate[j].finger_id = cinfo.id[j];
|
||||
}
|
||||
|
||||
// if(Finger_num >0)
|
||||
// int i=0
|
||||
// printf("%s: %d[i], %d[x_position], %d[y_position], %d[finger_id], %d[finger_num]\n",
|
||||
// __func__, i, XY_Coordinate[i].x_position, XY_Coordinate[i].y_position, XY_Coordinate[i].finger_id,Finger_num);
|
||||
// i=1;
|
||||
// printf("%s: %d[i], %d[x_position], %d[y_position], %d[finger_id], %d[finger_num]\n",
|
||||
// __func__, i, XY_Coordinate[i].x_position, XY_Coordinate[i].y_position, XY_Coordinate[i].finger_id,Finger_num);
|
||||
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static bool esp_lcd_touch_gsl3680_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
assert(x != NULL);
|
||||
assert(y != NULL);
|
||||
assert(point_num != NULL);
|
||||
assert(max_point_num > 0);
|
||||
|
||||
portENTER_CRITICAL(&tp->data.lock);
|
||||
|
||||
|
||||
if(max_point_num > Finger_num)
|
||||
*point_num = Finger_num;
|
||||
else
|
||||
*point_num = max_point_num;
|
||||
for(int i=0;i< *point_num;i++)
|
||||
{
|
||||
x[i] = XY_Coordinate[i].x_position;
|
||||
y[i] = XY_Coordinate[i].y_position;
|
||||
// strength[i] = XY_Coordinate[i].finger_id;
|
||||
}
|
||||
|
||||
|
||||
portEXIT_CRITICAL(&tp->data.lock);
|
||||
|
||||
return (*point_num > 0);
|
||||
}
|
||||
|
||||
#if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0)
|
||||
static esp_err_t esp_lcd_touch_gsl3680_get_button_state(esp_lcd_touch_handle_t tp, uint8_t n, uint8_t *state)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
assert(tp != NULL);
|
||||
assert(state != NULL);
|
||||
|
||||
*state = 0;
|
||||
|
||||
portENTER_CRITICAL(&tp->data.lock);
|
||||
|
||||
if (n > tp->data.buttons) {
|
||||
err = ESP_ERR_INVALID_ARG;
|
||||
} else {
|
||||
*state = tp->data.button[n].status;
|
||||
}
|
||||
|
||||
portEXIT_CRITICAL(&tp->data.lock);
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
static esp_err_t esp_lcd_touch_gsl3680_del(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
|
||||
/* Reset GPIO pin settings */
|
||||
if (tp->config.int_gpio_num != GPIO_NUM_NC) {
|
||||
gpio_reset_pin(tp->config.int_gpio_num);
|
||||
if (tp->config.interrupt_callback) {
|
||||
gpio_isr_handler_remove(tp->config.int_gpio_num);
|
||||
}
|
||||
}
|
||||
|
||||
/* Reset GPIO pin settings */
|
||||
if (tp->config.rst_gpio_num != GPIO_NUM_NC) {
|
||||
gpio_reset_pin(tp->config.rst_gpio_num);
|
||||
}
|
||||
|
||||
free(tp);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/*===================================================================================================================================================================================================*/
|
||||
static esp_err_t esp_lcd_touch_gsl3680_init(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
ESP_LOGI(TAG,"start init");
|
||||
esp_lcd_touch_gsl3680_clear_reg(tp);
|
||||
touch_gsl3680_reset(tp);
|
||||
esp_lcd_touch_gsl3680_load_fw(tp);
|
||||
esp_lcd_touch_gsl3680_startup_chip(tp);
|
||||
touch_gsl3680_reset(tp);
|
||||
esp_lcd_touch_gsl3680_startup_chip(tp);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
static esp_err_t touch_gsl3680_reset(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
unsigned char write_buf[4];
|
||||
uint8_t addr;
|
||||
assert(tp != NULL);
|
||||
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(tp->config.rst_gpio_num, 0), TAG, "GPIO set level error!");
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(tp->config.rst_gpio_num, 1), TAG, "GPIO set level error!");
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
|
||||
// addr = 0xe0;
|
||||
// write_buf[0] = 0x88;
|
||||
// touch_gsl3680_i2c_write(tp,addr,write_buf,1);
|
||||
// vTaskDelay(pdMS_TO_TICKS(10));
|
||||
addr = 0xe4;
|
||||
write_buf[0]=0x04;
|
||||
touch_gsl3680_i2c_write(tp,addr,write_buf,1);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
write_buf[0] =0x00;
|
||||
write_buf[1] =0x00;
|
||||
write_buf[2] =0x00;
|
||||
write_buf[3] =0x00;
|
||||
touch_gsl3680_i2c_write(tp,0xbc,write_buf,4);
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t touch_gsl3680_read_cfg(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
uint8_t buf[4];
|
||||
uint8_t write[4];
|
||||
uint8_t i2c_buffer_read = 0;
|
||||
uint8_t i2c_buffer_write = 0x12;
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
write[0] = 0x12;
|
||||
write[1] = 0x34;
|
||||
write[2] = 0x56;
|
||||
assert(tp != NULL);
|
||||
|
||||
ESP_LOGI(TAG,"gsl3680 connect");
|
||||
|
||||
ESP_RETURN_ON_ERROR(touch_gsl3680_i2c_read(tp, 0xf0, (uint8_t *)&buf, 4), TAG, "gsl3680 read error!");
|
||||
ESP_LOGI(TAG,"gsl3680 read reg 0xf0 before is %x %x %x %x",buf[0],buf[1],buf[2],buf[3]);
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
ESP_LOGI(TAG,"gsl3680 writing 0xf0 0x12");
|
||||
ESP_RETURN_ON_ERROR(touch_gsl3680_i2c_write(tp,0xf0,write,4),TAG,"gsl3680 read error");
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
ESP_RETURN_ON_ERROR(touch_gsl3680_i2c_read(tp, 0xf0, (uint8_t *)&buf, 4), TAG, "gsl3680 read error!");
|
||||
ESP_LOGI(TAG,"gsl3680 read reg 0xf0 after is %x %x %x %x",buf[0],buf[1],buf[2],buf[3]);
|
||||
|
||||
if(i2c_buffer_read == i2c_buffer_write)
|
||||
{
|
||||
ret = ESP_OK;
|
||||
ESP_LOGI(TAG,"read cfg success");
|
||||
}
|
||||
else
|
||||
ret = ESP_FAIL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t esp_lcd_touch_gsl3680_startup_chip(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint8_t write_buf[4];
|
||||
uint8_t addr = 0xe0;
|
||||
write_buf[0] = 0x00;
|
||||
ESP_LOGI(TAG,"enter");
|
||||
ESP_RETURN_ON_ERROR(touch_gsl3680_i2c_write(tp,addr,write_buf,1),TAG,"gsl3680 read error");
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
gsl_DataInit(gsl_config_data_id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t esp_lcd_touch_gsl3680_read_ram_fw(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
uint8_t read_buf[4];
|
||||
uint8_t addr = 0xb0;
|
||||
ESP_LOGI(TAG,"enter read_ram_fw");
|
||||
vTaskDelay(pdMS_TO_TICKS(30));
|
||||
ESP_RETURN_ON_ERROR(touch_gsl3680_i2c_read(tp, addr, (uint8_t *)&read_buf, 4), TAG, "gsl3680 read error!");
|
||||
ESP_LOGI(TAG,"gsl3680 startup_chip failed read 0xb0 = %x,%x,%x,%x ",read_buf[3],read_buf[2],read_buf[1],read_buf[0]);
|
||||
if(read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a || read_buf[0] != 0x5a)
|
||||
{
|
||||
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t touch_gsl3680_i2c_read(esp_lcd_touch_handle_t tp, uint16_t reg, uint8_t *data, uint8_t len)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
assert(data != NULL);
|
||||
|
||||
|
||||
/* Read data */
|
||||
return esp_lcd_panel_io_rx_param(tp->io, reg, data, len);
|
||||
|
||||
}
|
||||
|
||||
static esp_err_t touch_gsl3680_i2c_write(esp_lcd_touch_handle_t tp, uint16_t reg, uint8_t *data,uint8_t len)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
|
||||
// *INDENT-OFF*
|
||||
// /* Write data */
|
||||
return esp_lcd_panel_io_tx_param(tp->io, reg, data, len);
|
||||
// // *INDENT-ON*
|
||||
}
|
||||
|
||||
static esp_err_t esp_lcd_touch_gsl3680_load_fw(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
ESP_LOGI(TAG,"start load fw");
|
||||
uint16_t addr;
|
||||
unsigned char wrbuf[4];
|
||||
uint16_t source_line = 0;
|
||||
uint16_t source_len = sizeof(GSLX680_FW) / sizeof(struct fw_data);
|
||||
|
||||
for(source_line=0;source_line<source_len;source_line++)
|
||||
{
|
||||
addr = GSLX680_FW[source_line].offset;
|
||||
wrbuf[0] = (uint8_t)(GSLX680_FW[source_line].val & 0x000000ff);
|
||||
wrbuf[1] = (uint8_t)((GSLX680_FW[source_line].val & 0x0000ff00) >> 8);
|
||||
wrbuf[2] = (uint8_t)((GSLX680_FW[source_line].val & 0x00ff0000) >> 16);
|
||||
wrbuf[3] = (uint8_t)((GSLX680_FW[source_line].val & 0xff000000) >> 24);
|
||||
if(addr == 0xf0)
|
||||
touch_gsl3680_i2c_write(tp,addr,wrbuf,1);
|
||||
else
|
||||
touch_gsl3680_i2c_write(tp,addr,wrbuf,4);
|
||||
|
||||
}
|
||||
ESP_LOGI(TAG,"load fw success");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t esp_lcd_touch_gsl3680_clear_reg(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
uint8_t addr;
|
||||
uint8_t wrbuf[4];
|
||||
|
||||
ESP_LOGI(TAG,"clear reg");
|
||||
// addr = 0xe0;
|
||||
// wrbuf[0] = 0x88;
|
||||
// touch_gsl3680_i2c_write(tp,addr,wrbuf,1);
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(tp->config.rst_gpio_num, 0), TAG, "GPIO set level error!");
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(tp->config.rst_gpio_num, 1), TAG, "GPIO set level error!");
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
addr = 0x88;
|
||||
wrbuf[0] = 0x01;
|
||||
touch_gsl3680_i2c_write(tp,addr,wrbuf,1);
|
||||
vTaskDelay(pdMS_TO_TICKS(5));
|
||||
addr = 0xe4;
|
||||
wrbuf[0] = 0x04;
|
||||
touch_gsl3680_i2c_write(tp,addr,wrbuf,1);
|
||||
vTaskDelay(pdMS_TO_TICKS(5));
|
||||
addr = 0xe0;
|
||||
wrbuf[0] = 0x00;
|
||||
touch_gsl3680_i2c_write(tp,addr,wrbuf,1);
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static TP_STATE_E _Get_Cal_msg(void)
|
||||
{
|
||||
uint8 pen_flag = 0;
|
||||
uint16 x_poit, y_poit, x2_poit, y2_poit;
|
||||
int32 x_delta = 0 , y_delta = 0;
|
||||
|
||||
pen_flag = Finger_num;
|
||||
x_poit = XY_Coordinate[0].x_position;
|
||||
y_poit = XY_Coordinate[0].y_position;
|
||||
x2_poit = XY_Coordinate[1].x_position;
|
||||
y2_poit = XY_Coordinate[1].y_position;
|
||||
|
||||
if(pen_flag==0)
|
||||
{
|
||||
if(tp_event == TP_PEN_MOVE)//the last event=move
|
||||
{
|
||||
x_new = x_poit;
|
||||
y_new = y_poit;
|
||||
}
|
||||
else//the last event=down
|
||||
{
|
||||
x_new = x_start;
|
||||
y_new = y_start;
|
||||
}
|
||||
|
||||
tp_event = TP_PEN_UP;
|
||||
}
|
||||
else if(pen_flag==2)
|
||||
{
|
||||
tp_event = TP_PEN_DOWN;
|
||||
x_start = x_poit;
|
||||
y_start = y_poit;
|
||||
x_new = x_poit;
|
||||
y_new = y_poit;
|
||||
}
|
||||
else if(pre_pen_flag!=1)//pen_flag=1,pre_pen_flag==0 or 2
|
||||
{
|
||||
tp_event = TP_PEN_DOWN;
|
||||
x_start = x_poit;
|
||||
y_start = y_poit;
|
||||
x_new = x_poit;
|
||||
y_new = y_poit;
|
||||
}
|
||||
else// if((pen_flag==1)&&(pre_pen_flag==1))
|
||||
{
|
||||
x_delta = x_poit - x_start;
|
||||
y_delta = y_poit - y_start;
|
||||
if((x_delta>20)||(x_delta<-20)||(y_delta>25)||(y_delta<-25))
|
||||
{
|
||||
tp_event = TP_PEN_MOVE;
|
||||
}
|
||||
|
||||
if(tp_event == TP_PEN_MOVE)
|
||||
{
|
||||
x_new = x_poit;
|
||||
y_new = y_poit;
|
||||
}
|
||||
else
|
||||
{
|
||||
x_new = x_start;
|
||||
y_new = y_start;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pre_pen_flag = pen_flag;
|
||||
return tp_event;
|
||||
}
|
||||
|
||||
esp_err_t esp_while_read()
|
||||
{
|
||||
return esp_lcd_touch_gsl3680_read_ram_fw(esp_lcd_touch_gsl3680);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,4 @@
|
||||
dependencies:
|
||||
esp_lcd_touch:
|
||||
public: true
|
||||
version: ^1.1.0
|
||||
+4702
File diff suppressed because it is too large
Load Diff
+18
@@ -0,0 +1,18 @@
|
||||
#ifndef _GSL_POINT_ID_H
|
||||
#define _GSL_POINT_ID_H
|
||||
|
||||
struct gsl_touch_info
|
||||
{
|
||||
int x[10];
|
||||
int y[10];
|
||||
int id[10];
|
||||
int finger_num;
|
||||
};
|
||||
|
||||
unsigned int gsl_mask_tiaoping(void);
|
||||
unsigned int gsl_version_id(void);
|
||||
void gsl_alg_id_main(struct gsl_touch_info *cinfo);
|
||||
void gsl_DataInit(unsigned int *conf_in);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS "ethernet_init.c"
|
||||
PRIV_REQUIRES esp_driver_gpio esp_eth
|
||||
INCLUDE_DIRS ".")
|
||||
@@ -0,0 +1,308 @@
|
||||
menu "Example Ethernet Configuration"
|
||||
|
||||
orsource "$IDF_PATH/examples/common_components/env_caps/$IDF_TARGET/Kconfig.env_caps"
|
||||
|
||||
config EXAMPLE_USE_INTERNAL_ETHERNET
|
||||
depends on SOC_EMAC_SUPPORTED
|
||||
select ETH_USE_ESP32_EMAC
|
||||
default y
|
||||
bool "Internal EMAC"
|
||||
help
|
||||
Use internal Ethernet MAC controller.
|
||||
|
||||
if EXAMPLE_USE_INTERNAL_ETHERNET
|
||||
choice EXAMPLE_ETH_PHY_MODEL
|
||||
prompt "Ethernet PHY Device"
|
||||
default EXAMPLE_ETH_PHY_IP101
|
||||
help
|
||||
Select the Ethernet PHY device to use in the example.
|
||||
|
||||
config EXAMPLE_ETH_PHY_GENERIC
|
||||
bool "Generic 802.3 PHY"
|
||||
help
|
||||
Any Ethernet PHY chip compliant with IEEE 802.3 can be used. However, while
|
||||
basic functionality should always work, some specific features might be limited,
|
||||
even if the PHY meets IEEE 802.3 standard. A typical example is loopback
|
||||
functionality, where certain PHYs may require setting a specific speed mode to
|
||||
operate correctly.
|
||||
|
||||
config EXAMPLE_ETH_PHY_IP101
|
||||
bool "IP101"
|
||||
help
|
||||
IP101 is a single port 10/100 MII/RMII/TP/Fiber Fast Ethernet Transceiver.
|
||||
Goto http://www.icplus.com.tw/pp-IP101G.html for more information about it.
|
||||
|
||||
config EXAMPLE_ETH_PHY_RTL8201
|
||||
bool "RTL8201/SR8201"
|
||||
help
|
||||
RTL8201F/SR8201F is a single port 10/100Mb Ethernet Transceiver with auto MDIX.
|
||||
Goto http://www.corechip-sz.com/productsview.asp?id=22 for more information about it.
|
||||
|
||||
config EXAMPLE_ETH_PHY_LAN87XX
|
||||
bool "LAN87xx"
|
||||
help
|
||||
Below chips are supported:
|
||||
LAN8710A is a small footprint MII/RMII 10/100 Ethernet Transceiver with HP Auto-MDIX and
|
||||
flexPWR® Technology.
|
||||
LAN8720A is a small footprint RMII 10/100 Ethernet Transceiver with HP Auto-MDIX Support.
|
||||
LAN8740A/LAN8741A is a small footprint MII/RMII 10/100 Energy Efficient Ethernet Transceiver
|
||||
with HP Auto-MDIX and flexPWR® Technology.
|
||||
LAN8742A is a small footprint RMII 10/100 Ethernet Transceiver with HP Auto-MDIX and
|
||||
flexPWR® Technology.
|
||||
Goto https://www.microchip.com for more information about them.
|
||||
|
||||
config EXAMPLE_ETH_PHY_DP83848
|
||||
bool "DP83848"
|
||||
help
|
||||
DP83848 is a single port 10/100Mb/s Ethernet Physical Layer Transceiver.
|
||||
Goto http://www.ti.com/product/DP83848J for more information about it.
|
||||
|
||||
config EXAMPLE_ETH_PHY_KSZ80XX
|
||||
bool "KSZ80xx"
|
||||
help
|
||||
With the KSZ80xx series, Microchip offers single-chip 10BASE-T/100BASE-TX
|
||||
Ethernet Physical Layer Transceivers (PHY).
|
||||
The following chips are supported: KSZ8001, KSZ8021, KSZ8031, KSZ8041,
|
||||
KSZ8051, KSZ8061, KSZ8081, KSZ8091
|
||||
Goto https://www.microchip.com for more information about them.
|
||||
endchoice # EXAMPLE_ETH_PHY_MODEL
|
||||
|
||||
config EXAMPLE_ETH_MDC_GPIO
|
||||
int "SMI MDC GPIO number"
|
||||
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
|
||||
default 23 if IDF_TARGET_ESP32
|
||||
default 31 if IDF_TARGET_ESP32P4
|
||||
help
|
||||
Set the GPIO number used by SMI MDC.
|
||||
|
||||
config EXAMPLE_ETH_MDIO_GPIO
|
||||
int "SMI MDIO GPIO number"
|
||||
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
|
||||
default 18 if IDF_TARGET_ESP32
|
||||
default 52 if IDF_TARGET_ESP32P4
|
||||
help
|
||||
Set the GPIO number used by SMI MDIO.
|
||||
|
||||
config EXAMPLE_ETH_PHY_RST_GPIO
|
||||
int "PHY Reset GPIO number"
|
||||
range -1 ENV_GPIO_OUT_RANGE_MAX
|
||||
default 5 if IDF_TARGET_ESP32
|
||||
default 51 if IDF_TARGET_ESP32P4
|
||||
help
|
||||
Set the GPIO number used to reset PHY chip.
|
||||
Set to -1 to disable PHY chip hardware reset.
|
||||
|
||||
config EXAMPLE_ETH_PHY_ADDR
|
||||
int "PHY Address"
|
||||
range -1 31
|
||||
default 1
|
||||
help
|
||||
Set PHY address according your board schematic.
|
||||
Set to -1 to driver find the PHY address automatically.
|
||||
endif # EXAMPLE_USE_INTERNAL_ETHERNET
|
||||
|
||||
config EXAMPLE_USE_SPI_ETHERNET
|
||||
bool "SPI Ethernet"
|
||||
default n
|
||||
select ETH_USE_SPI_ETHERNET
|
||||
help
|
||||
Use external SPI-Ethernet module(s).
|
||||
|
||||
if EXAMPLE_USE_SPI_ETHERNET
|
||||
config EXAMPLE_SPI_ETHERNETS_NUM
|
||||
int "Number of SPI Ethernet modules to use at a time"
|
||||
range 1 2
|
||||
default 1
|
||||
help
|
||||
Set the number of SPI Ethernet modules you want to use at a time. Multiple SPI modules can be connected
|
||||
to one SPI interface and can be separately accessed based on state of associated Chip Select (CS).
|
||||
|
||||
choice EXAMPLE_ETHERNET_TYPE_SPI
|
||||
prompt "Ethernet SPI"
|
||||
default EXAMPLE_USE_W5500
|
||||
help
|
||||
Select which kind of Ethernet will be used in the example.
|
||||
|
||||
config EXAMPLE_USE_DM9051
|
||||
bool "DM9051 Module"
|
||||
select ETH_SPI_ETHERNET_DM9051
|
||||
help
|
||||
Select external SPI-Ethernet module (DM9051).
|
||||
|
||||
config EXAMPLE_USE_KSZ8851SNL
|
||||
bool "KSZ8851SNL Module"
|
||||
select ETH_SPI_ETHERNET_KSZ8851SNL
|
||||
help
|
||||
Select external SPI-Ethernet module (KSZ8851SNL).
|
||||
|
||||
config EXAMPLE_USE_W5500
|
||||
bool "W5500 Module"
|
||||
select ETH_SPI_ETHERNET_W5500
|
||||
help
|
||||
Select external SPI-Ethernet module (W5500).
|
||||
endchoice
|
||||
|
||||
config EXAMPLE_ETH_SPI_HOST
|
||||
int "SPI Host Number"
|
||||
range 0 2
|
||||
default 1
|
||||
help
|
||||
Set the SPI host used to communicate with the SPI Ethernet Controller.
|
||||
|
||||
config EXAMPLE_ETH_SPI_SCLK_GPIO
|
||||
int "SPI SCLK GPIO number"
|
||||
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
|
||||
default 14 if IDF_TARGET_ESP32
|
||||
default 12 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||
default 6 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32C61
|
||||
default 4 if IDF_TARGET_ESP32H2
|
||||
default 33 if IDF_TARGET_ESP32P4
|
||||
default 8 if IDF_TARGET_ESP32C5
|
||||
help
|
||||
Set the GPIO number used by SPI SCLK.
|
||||
|
||||
config EXAMPLE_ETH_SPI_MOSI_GPIO
|
||||
int "SPI MOSI GPIO number"
|
||||
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
|
||||
default 13 if IDF_TARGET_ESP32
|
||||
default 11 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||
default 7 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32C61
|
||||
default 5 if IDF_TARGET_ESP32H2
|
||||
default 32 if IDF_TARGET_ESP32P4
|
||||
default 10 if IDF_TARGET_ESP32C5
|
||||
help
|
||||
Set the GPIO number used by SPI MOSI.
|
||||
|
||||
config EXAMPLE_ETH_SPI_MISO_GPIO
|
||||
int "SPI MISO GPIO number"
|
||||
range ENV_GPIO_RANGE_MIN ENV_GPIO_IN_RANGE_MAX
|
||||
default 12 if IDF_TARGET_ESP32
|
||||
default 13 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||
default 2 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32C61
|
||||
default 0 if IDF_TARGET_ESP32H2
|
||||
default 24 if IDF_TARGET_ESP32P4
|
||||
default 9 if IDF_TARGET_ESP32C5
|
||||
help
|
||||
Set the GPIO number used by SPI MISO.
|
||||
|
||||
config EXAMPLE_ETH_SPI_CLOCK_MHZ
|
||||
int "SPI clock speed (MHz)"
|
||||
range 5 80
|
||||
default 16
|
||||
help
|
||||
Set the clock speed (MHz) of SPI interface.
|
||||
|
||||
config EXAMPLE_ETH_SPI_CS0_GPIO
|
||||
int "SPI CS0 GPIO number for SPI Ethernet module #1"
|
||||
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
|
||||
default 15 if IDF_TARGET_ESP32
|
||||
default 10 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C2
|
||||
default 3 if IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32C5 || IDF_TARGET_ESP32C61
|
||||
default 1 if IDF_TARGET_ESP32H2
|
||||
default 21 if IDF_TARGET_ESP32P4
|
||||
help
|
||||
Set the GPIO number used by SPI CS0, i.e. Chip Select associated with the first SPI Eth module).
|
||||
|
||||
config EXAMPLE_ETH_SPI_CS1_GPIO
|
||||
depends on EXAMPLE_SPI_ETHERNETS_NUM > 1
|
||||
int "SPI CS1 GPIO number for SPI Ethernet module #2"
|
||||
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
|
||||
default 32 if IDF_TARGET_ESP32
|
||||
default 7 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||
default 8 if IDF_TARGET_ESP32C3
|
||||
default 21 if IDF_TARGET_ESP32C6
|
||||
default 3 if IDF_TARGET_ESP32C2
|
||||
default 11 if IDF_TARGET_ESP32H2
|
||||
default 23 if IDF_TARGET_ESP32P4 || IDF_TARGET_ESP32C61
|
||||
default 1 if IDF_TARGET_ESP32C5
|
||||
help
|
||||
Set the GPIO number used by SPI CS1, i.e. Chip Select associated with the second SPI Eth module.
|
||||
|
||||
config EXAMPLE_ETH_SPI_INT0_GPIO
|
||||
int "Interrupt GPIO number SPI Ethernet module #1"
|
||||
range -1 ENV_GPIO_IN_RANGE_MAX
|
||||
default 4 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3
|
||||
default 4 if IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32C5
|
||||
default 10 if IDF_TARGET_ESP32H2
|
||||
default 48 if IDF_TARGET_ESP32P4
|
||||
default 0 if IDF_TARGET_ESP32C61
|
||||
help
|
||||
Set the GPIO number used by the first SPI Ethernet module interrupt line.
|
||||
Set -1 to use SPI Ethernet module in polling mode.
|
||||
|
||||
config EXAMPLE_ETH_SPI_INT1_GPIO
|
||||
depends on EXAMPLE_SPI_ETHERNETS_NUM > 1
|
||||
int "Interrupt GPIO number SPI Ethernet module #2"
|
||||
range -1 ENV_GPIO_IN_RANGE_MAX
|
||||
default 33 if IDF_TARGET_ESP32
|
||||
default 5 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C2
|
||||
default 5 if IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32C5
|
||||
default 9 if IDF_TARGET_ESP32H2
|
||||
default 47 if IDF_TARGET_ESP32P4
|
||||
default 1 if IDF_TARGET_ESP32C61
|
||||
help
|
||||
Set the GPIO number used by the second SPI Ethernet module interrupt line.
|
||||
Set -1 to use SPI Ethernet module in polling mode.
|
||||
|
||||
config EXAMPLE_ETH_SPI_POLLING0_MS_VAL
|
||||
depends on EXAMPLE_ETH_SPI_INT0_GPIO < 0
|
||||
int "Polling period in msec of SPI Ethernet Module #1"
|
||||
default 10
|
||||
help
|
||||
Set SPI Ethernet module polling period.
|
||||
|
||||
config EXAMPLE_ETH_SPI_POLLING1_MS_VAL
|
||||
depends on EXAMPLE_SPI_ETHERNETS_NUM > 1 && EXAMPLE_ETH_SPI_INT1_GPIO < 0
|
||||
int "Polling period in msec of SPI Ethernet Module #2"
|
||||
default 10
|
||||
help
|
||||
Set SPI Ethernet module polling period.
|
||||
|
||||
# Hidden variable to ensure that polling period option is visible only when interrupt is set disabled and
|
||||
# it is set to known value (0) when interrupt is enabled at the same time.
|
||||
config EXAMPLE_ETH_SPI_POLLING0_MS
|
||||
int
|
||||
default EXAMPLE_ETH_SPI_POLLING0_MS_VAL if EXAMPLE_ETH_SPI_POLLING0_MS_VAL > 0
|
||||
default 0
|
||||
|
||||
# Hidden variable to ensure that polling period option is visible only when interrupt is set disabled and
|
||||
# it is set to known value (0) when interrupt is enabled at the same time.
|
||||
config EXAMPLE_ETH_SPI_POLLING1_MS
|
||||
depends on EXAMPLE_SPI_ETHERNETS_NUM > 1
|
||||
int
|
||||
default EXAMPLE_ETH_SPI_POLLING1_MS_VAL if EXAMPLE_ETH_SPI_POLLING1_MS_VAL > 0
|
||||
default 0
|
||||
|
||||
config EXAMPLE_ETH_SPI_PHY_RST0_GPIO
|
||||
int "PHY Reset GPIO number of SPI Ethernet Module #1"
|
||||
range -1 ENV_GPIO_OUT_RANGE_MAX
|
||||
default -1
|
||||
help
|
||||
Set the GPIO number used to reset PHY chip on the first SPI Ethernet module.
|
||||
Set to -1 to disable PHY chip hardware reset.
|
||||
|
||||
config EXAMPLE_ETH_SPI_PHY_RST1_GPIO
|
||||
depends on EXAMPLE_SPI_ETHERNETS_NUM > 1
|
||||
int "PHY Reset GPIO number of SPI Ethernet Module #2"
|
||||
range -1 ENV_GPIO_OUT_RANGE_MAX
|
||||
default -1
|
||||
help
|
||||
Set the GPIO number used to reset PHY chip on the second SPI Ethernet module.
|
||||
Set to -1 to disable PHY chip hardware reset.
|
||||
|
||||
config EXAMPLE_ETH_SPI_PHY_ADDR0
|
||||
int "PHY Address of SPI Ethernet Module #1"
|
||||
range 0 31
|
||||
default 1
|
||||
help
|
||||
Set the first SPI Ethernet module PHY address according your board schematic.
|
||||
|
||||
config EXAMPLE_ETH_SPI_PHY_ADDR1
|
||||
depends on EXAMPLE_SPI_ETHERNETS_NUM > 1
|
||||
int "PHY Address of SPI Ethernet Module #2"
|
||||
range 0 31
|
||||
default 1
|
||||
help
|
||||
Set the second SPI Ethernet module PHY address according your board schematic.
|
||||
endif # EXAMPLE_USE_SPI_ETHERNET
|
||||
endmenu
|
||||
@@ -0,0 +1,340 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include "ethernet_init.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_mac.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "sdkconfig.h"
|
||||
#if CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
#include "driver/spi_master.h"
|
||||
#endif // CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
|
||||
#if CONFIG_EXAMPLE_SPI_ETHERNETS_NUM
|
||||
#define SPI_ETHERNETS_NUM CONFIG_EXAMPLE_SPI_ETHERNETS_NUM
|
||||
#else
|
||||
#define SPI_ETHERNETS_NUM 0
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET
|
||||
#define INTERNAL_ETHERNETS_NUM 1
|
||||
#else
|
||||
#define INTERNAL_ETHERNETS_NUM 0
|
||||
#endif
|
||||
|
||||
#define INIT_SPI_ETH_MODULE_CONFIG(eth_module_config, num) \
|
||||
do { \
|
||||
eth_module_config[num].spi_cs_gpio = CONFIG_EXAMPLE_ETH_SPI_CS ##num## _GPIO; \
|
||||
eth_module_config[num].int_gpio = CONFIG_EXAMPLE_ETH_SPI_INT ##num## _GPIO; \
|
||||
eth_module_config[num].polling_ms = CONFIG_EXAMPLE_ETH_SPI_POLLING ##num## _MS; \
|
||||
eth_module_config[num].phy_reset_gpio = CONFIG_EXAMPLE_ETH_SPI_PHY_RST ##num## _GPIO; \
|
||||
eth_module_config[num].phy_addr = CONFIG_EXAMPLE_ETH_SPI_PHY_ADDR ##num; \
|
||||
} while(0)
|
||||
|
||||
typedef struct {
|
||||
uint8_t spi_cs_gpio;
|
||||
int8_t int_gpio;
|
||||
uint32_t polling_ms;
|
||||
int8_t phy_reset_gpio;
|
||||
uint8_t phy_addr;
|
||||
uint8_t *mac_addr;
|
||||
}spi_eth_module_config_t;
|
||||
|
||||
static const char *TAG = "example_eth_init";
|
||||
#if CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
static bool gpio_isr_svc_init_by_eth = false; // indicates that we initialized the GPIO ISR service
|
||||
#endif // CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
|
||||
|
||||
#if CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET
|
||||
/**
|
||||
* @brief Internal ESP32 Ethernet initialization
|
||||
*
|
||||
* @param[out] mac_out optionally returns Ethernet MAC object
|
||||
* @param[out] phy_out optionally returns Ethernet PHY object
|
||||
* @return
|
||||
* - esp_eth_handle_t if init succeeded
|
||||
* - NULL if init failed
|
||||
*/
|
||||
static esp_eth_handle_t eth_init_internal(esp_eth_mac_t **mac_out, esp_eth_phy_t **phy_out)
|
||||
{
|
||||
esp_eth_handle_t ret = NULL;
|
||||
|
||||
// Init common MAC and PHY configs to default
|
||||
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
|
||||
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
|
||||
|
||||
// Update PHY config based on board specific configuration
|
||||
phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR;
|
||||
phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO;
|
||||
// Init vendor specific MAC config to default
|
||||
eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG();
|
||||
// Update vendor specific MAC config based on board configuration
|
||||
esp32_emac_config.smi_gpio.mdc_num = CONFIG_EXAMPLE_ETH_MDC_GPIO;
|
||||
esp32_emac_config.smi_gpio.mdio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO;
|
||||
#if CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
// The DMA is shared resource between EMAC and the SPI. Therefore, adjust
|
||||
// EMAC DMA burst length when SPI Ethernet is used along with EMAC.
|
||||
esp32_emac_config.dma_burst_len = ETH_DMA_BURST_LEN_4;
|
||||
#endif // CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
// Create new ESP32 Ethernet MAC instance
|
||||
esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config);
|
||||
// Create new PHY instance based on board configuration
|
||||
#if CONFIG_EXAMPLE_ETH_PHY_GENERIC
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_generic(&phy_config);
|
||||
#elif CONFIG_EXAMPLE_ETH_PHY_IP101
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config);
|
||||
#elif CONFIG_EXAMPLE_ETH_PHY_RTL8201
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_rtl8201(&phy_config);
|
||||
#elif CONFIG_EXAMPLE_ETH_PHY_LAN87XX
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_lan87xx(&phy_config);
|
||||
#elif CONFIG_EXAMPLE_ETH_PHY_DP83848
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_dp83848(&phy_config);
|
||||
#elif CONFIG_EXAMPLE_ETH_PHY_KSZ80XX
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_ksz80xx(&phy_config);
|
||||
#endif
|
||||
// Init Ethernet driver to default and install it
|
||||
esp_eth_handle_t eth_handle = NULL;
|
||||
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
||||
ESP_GOTO_ON_FALSE(esp_eth_driver_install(&config, ð_handle) == ESP_OK, NULL,
|
||||
err, TAG, "Ethernet driver install failed");
|
||||
|
||||
if (mac_out != NULL) {
|
||||
*mac_out = mac;
|
||||
}
|
||||
if (phy_out != NULL) {
|
||||
*phy_out = phy;
|
||||
}
|
||||
return eth_handle;
|
||||
err:
|
||||
if (eth_handle != NULL) {
|
||||
esp_eth_driver_uninstall(eth_handle);
|
||||
}
|
||||
if (mac != NULL) {
|
||||
mac->del(mac);
|
||||
}
|
||||
if (phy != NULL) {
|
||||
phy->del(phy);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif // CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET
|
||||
|
||||
#if CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
/**
|
||||
* @brief SPI bus initialization (to be used by Ethernet SPI modules)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
static esp_err_t spi_bus_init(void)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
#if (CONFIG_EXAMPLE_ETH_SPI_INT0_GPIO >= 0) || (CONFIG_EXAMPLE_ETH_SPI_INT1_GPIO > 0)
|
||||
// Install GPIO ISR handler to be able to service SPI Eth modules interrupts
|
||||
ret = gpio_install_isr_service(0);
|
||||
if (ret == ESP_OK) {
|
||||
gpio_isr_svc_init_by_eth = true;
|
||||
} else if (ret == ESP_ERR_INVALID_STATE) {
|
||||
ESP_LOGW(TAG, "GPIO ISR handler has been already installed");
|
||||
ret = ESP_OK; // ISR handler has been already installed so no issues
|
||||
} else {
|
||||
ESP_LOGE(TAG, "GPIO ISR handler install failed");
|
||||
goto err;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Init SPI bus
|
||||
spi_bus_config_t buscfg = {
|
||||
.miso_io_num = CONFIG_EXAMPLE_ETH_SPI_MISO_GPIO,
|
||||
.mosi_io_num = CONFIG_EXAMPLE_ETH_SPI_MOSI_GPIO,
|
||||
.sclk_io_num = CONFIG_EXAMPLE_ETH_SPI_SCLK_GPIO,
|
||||
.quadwp_io_num = -1,
|
||||
.quadhd_io_num = -1,
|
||||
};
|
||||
ESP_GOTO_ON_ERROR(spi_bus_initialize(CONFIG_EXAMPLE_ETH_SPI_HOST, &buscfg, SPI_DMA_CH_AUTO),
|
||||
err, TAG, "SPI host #%d init failed", CONFIG_EXAMPLE_ETH_SPI_HOST);
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Ethernet SPI modules initialization
|
||||
*
|
||||
* @param[in] spi_eth_module_config specific SPI Ethernet module configuration
|
||||
* @param[out] mac_out optionally returns Ethernet MAC object
|
||||
* @param[out] phy_out optionally returns Ethernet PHY object
|
||||
* @return
|
||||
* - esp_eth_handle_t if init succeeded
|
||||
* - NULL if init failed
|
||||
*/
|
||||
static esp_eth_handle_t eth_init_spi(spi_eth_module_config_t *spi_eth_module_config, esp_eth_mac_t **mac_out, esp_eth_phy_t **phy_out)
|
||||
{
|
||||
esp_eth_handle_t ret = NULL;
|
||||
|
||||
// Init common MAC and PHY configs to default
|
||||
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
|
||||
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
|
||||
|
||||
// Update PHY config based on board specific configuration
|
||||
phy_config.phy_addr = spi_eth_module_config->phy_addr;
|
||||
phy_config.reset_gpio_num = spi_eth_module_config->phy_reset_gpio;
|
||||
|
||||
// Configure SPI interface for specific SPI module
|
||||
spi_device_interface_config_t spi_devcfg = {
|
||||
.mode = 0,
|
||||
.clock_speed_hz = CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
|
||||
.queue_size = 20,
|
||||
.spics_io_num = spi_eth_module_config->spi_cs_gpio
|
||||
};
|
||||
// Init vendor specific MAC config to default, and create new SPI Ethernet MAC instance
|
||||
// and new PHY instance based on board configuration
|
||||
#if CONFIG_EXAMPLE_USE_KSZ8851SNL
|
||||
eth_ksz8851snl_config_t ksz8851snl_config = ETH_KSZ8851SNL_DEFAULT_CONFIG(CONFIG_EXAMPLE_ETH_SPI_HOST, &spi_devcfg);
|
||||
ksz8851snl_config.int_gpio_num = spi_eth_module_config->int_gpio;
|
||||
ksz8851snl_config.poll_period_ms = spi_eth_module_config->polling_ms;
|
||||
esp_eth_mac_t *mac = esp_eth_mac_new_ksz8851snl(&ksz8851snl_config, &mac_config);
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_ksz8851snl(&phy_config);
|
||||
#elif CONFIG_EXAMPLE_USE_DM9051
|
||||
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(CONFIG_EXAMPLE_ETH_SPI_HOST, &spi_devcfg);
|
||||
dm9051_config.int_gpio_num = spi_eth_module_config->int_gpio;
|
||||
dm9051_config.poll_period_ms = spi_eth_module_config->polling_ms;
|
||||
esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config);
|
||||
#elif CONFIG_EXAMPLE_USE_W5500
|
||||
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(CONFIG_EXAMPLE_ETH_SPI_HOST, &spi_devcfg);
|
||||
w5500_config.int_gpio_num = spi_eth_module_config->int_gpio;
|
||||
w5500_config.poll_period_ms = spi_eth_module_config->polling_ms;
|
||||
esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_w5500(&phy_config);
|
||||
#endif //CONFIG_EXAMPLE_USE_W5500
|
||||
// Init Ethernet driver to default and install it
|
||||
esp_eth_handle_t eth_handle = NULL;
|
||||
esp_eth_config_t eth_config_spi = ETH_DEFAULT_CONFIG(mac, phy);
|
||||
ESP_GOTO_ON_FALSE(esp_eth_driver_install(ð_config_spi, ð_handle) == ESP_OK, NULL, err, TAG, "SPI Ethernet driver install failed");
|
||||
|
||||
// The SPI Ethernet module might not have a burned factory MAC address, we can set it manually.
|
||||
if (spi_eth_module_config->mac_addr != NULL) {
|
||||
ESP_GOTO_ON_FALSE(esp_eth_ioctl(eth_handle, ETH_CMD_S_MAC_ADDR, spi_eth_module_config->mac_addr) == ESP_OK,
|
||||
NULL, err, TAG, "SPI Ethernet MAC address config failed");
|
||||
}
|
||||
|
||||
if (mac_out != NULL) {
|
||||
*mac_out = mac;
|
||||
}
|
||||
if (phy_out != NULL) {
|
||||
*phy_out = phy;
|
||||
}
|
||||
return eth_handle;
|
||||
err:
|
||||
if (eth_handle != NULL) {
|
||||
esp_eth_driver_uninstall(eth_handle);
|
||||
}
|
||||
if (mac != NULL) {
|
||||
mac->del(mac);
|
||||
}
|
||||
if (phy != NULL) {
|
||||
phy->del(phy);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif // CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
|
||||
esp_err_t example_eth_init(esp_eth_handle_t *eth_handles_out[], uint8_t *eth_cnt_out)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
esp_eth_handle_t *eth_handles = NULL;
|
||||
uint8_t eth_cnt = 0;
|
||||
|
||||
#if CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET || CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
ESP_GOTO_ON_FALSE(eth_handles_out != NULL && eth_cnt_out != NULL, ESP_ERR_INVALID_ARG,
|
||||
err, TAG, "invalid arguments: initialized handles array or number of interfaces");
|
||||
eth_handles = calloc(SPI_ETHERNETS_NUM + INTERNAL_ETHERNETS_NUM, sizeof(esp_eth_handle_t));
|
||||
ESP_GOTO_ON_FALSE(eth_handles != NULL, ESP_ERR_NO_MEM, err, TAG, "no memory");
|
||||
|
||||
#if CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET
|
||||
eth_handles[eth_cnt] = eth_init_internal(NULL, NULL);
|
||||
ESP_GOTO_ON_FALSE(eth_handles[eth_cnt], ESP_FAIL, err, TAG, "internal Ethernet init failed");
|
||||
eth_cnt++;
|
||||
#endif //CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET
|
||||
|
||||
#if CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
ESP_GOTO_ON_ERROR(spi_bus_init(), err, TAG, "SPI bus init failed");
|
||||
// Init specific SPI Ethernet module configuration from Kconfig (CS GPIO, Interrupt GPIO, etc.)
|
||||
spi_eth_module_config_t spi_eth_module_config[CONFIG_EXAMPLE_SPI_ETHERNETS_NUM] = { 0 };
|
||||
INIT_SPI_ETH_MODULE_CONFIG(spi_eth_module_config, 0);
|
||||
// The SPI Ethernet module(s) might not have a burned factory MAC address, hence use manually configured address(es).
|
||||
// In this example, Locally Administered MAC address derived from ESP32x base MAC address is used.
|
||||
// Note that Locally Administered OUI range should be used only when testing on a LAN under your control!
|
||||
uint8_t base_mac_addr[ETH_ADDR_LEN];
|
||||
ESP_GOTO_ON_ERROR(esp_efuse_mac_get_default(base_mac_addr), err, TAG, "get EFUSE MAC failed");
|
||||
uint8_t local_mac_1[ETH_ADDR_LEN];
|
||||
esp_derive_local_mac(local_mac_1, base_mac_addr);
|
||||
spi_eth_module_config[0].mac_addr = local_mac_1;
|
||||
#if CONFIG_EXAMPLE_SPI_ETHERNETS_NUM > 1
|
||||
INIT_SPI_ETH_MODULE_CONFIG(spi_eth_module_config, 1);
|
||||
uint8_t local_mac_2[ETH_ADDR_LEN];
|
||||
base_mac_addr[ETH_ADDR_LEN - 1] += 1;
|
||||
esp_derive_local_mac(local_mac_2, base_mac_addr);
|
||||
spi_eth_module_config[1].mac_addr = local_mac_2;
|
||||
#endif
|
||||
#if CONFIG_EXAMPLE_SPI_ETHERNETS_NUM > 2
|
||||
#error Maximum number of supported SPI Ethernet devices is currently limited to 2 by this example.
|
||||
#endif
|
||||
for (int i = 0; i < CONFIG_EXAMPLE_SPI_ETHERNETS_NUM; i++) {
|
||||
eth_handles[eth_cnt] = eth_init_spi(&spi_eth_module_config[i], NULL, NULL);
|
||||
ESP_GOTO_ON_FALSE(eth_handles[eth_cnt], ESP_FAIL, err, TAG, "SPI Ethernet init failed");
|
||||
eth_cnt++;
|
||||
}
|
||||
#endif // CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
#else
|
||||
ESP_LOGD(TAG, "no Ethernet device selected to init");
|
||||
#endif // CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET || CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
*eth_handles_out = eth_handles;
|
||||
*eth_cnt_out = eth_cnt;
|
||||
|
||||
return ret;
|
||||
#if CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET || CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
err:
|
||||
free(eth_handles);
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t example_eth_deinit(esp_eth_handle_t *eth_handles, uint8_t eth_cnt)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(eth_handles != NULL, ESP_ERR_INVALID_ARG, TAG, "array of Ethernet handles cannot be NULL");
|
||||
for (int i = 0; i < eth_cnt; i++) {
|
||||
esp_eth_mac_t *mac = NULL;
|
||||
esp_eth_phy_t *phy = NULL;
|
||||
if (eth_handles[i] != NULL) {
|
||||
esp_eth_get_mac_instance(eth_handles[i], &mac);
|
||||
esp_eth_get_phy_instance(eth_handles[i], &phy);
|
||||
ESP_RETURN_ON_ERROR(esp_eth_driver_uninstall(eth_handles[i]), TAG, "Ethernet %p uninstall failed", eth_handles[i]);
|
||||
}
|
||||
if (mac != NULL) {
|
||||
mac->del(mac);
|
||||
}
|
||||
if (phy != NULL) {
|
||||
phy->del(phy);
|
||||
}
|
||||
}
|
||||
#if CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
spi_bus_free(CONFIG_EXAMPLE_ETH_SPI_HOST);
|
||||
#if (CONFIG_EXAMPLE_ETH_SPI_INT0_GPIO >= 0) || (CONFIG_EXAMPLE_ETH_SPI_INT1_GPIO > 0)
|
||||
// We installed the GPIO ISR service so let's uninstall it too.
|
||||
// BE CAREFUL HERE though since the service might be used by other functionality!
|
||||
if (gpio_isr_svc_init_by_eth) {
|
||||
ESP_LOGW(TAG, "uninstalling GPIO ISR service!");
|
||||
gpio_uninstall_isr_service();
|
||||
}
|
||||
#endif
|
||||
#endif //CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
||||
free(eth_handles);
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "esp_eth_driver.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize Ethernet driver based on Espressif IoT Development Framework Configuration
|
||||
*
|
||||
* @param[out] eth_handles_out array of initialized Ethernet driver handles
|
||||
* @param[out] eth_cnt_out number of initialized Ethernets
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG when passed invalid pointers
|
||||
* - ESP_ERR_NO_MEM when there is no memory to allocate for Ethernet driver handles array
|
||||
* - ESP_FAIL on any other failure
|
||||
*/
|
||||
esp_err_t example_eth_init(esp_eth_handle_t *eth_handles_out[], uint8_t *eth_cnt_out);
|
||||
|
||||
/**
|
||||
* @brief De-initialize array of Ethernet drivers
|
||||
* @note All Ethernet drivers in the array must be stopped prior calling this function.
|
||||
*
|
||||
* @param[in] eth_handles array of Ethernet drivers to be de-initialized
|
||||
* @param[in] eth_cnt number of Ethernets drivers to be de-initialized
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG when passed invalid pointers
|
||||
*/
|
||||
esp_err_t example_eth_deinit(esp_eth_handle_t *eth_handles, uint8_t eth_cnt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1 @@
|
||||
1dfd3c5ba9e921e437a4116a5a61b7be985a24720d9d610effa59f22268f6683
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
idf_component_register(
|
||||
SRCS "esp32_p4_nano.c"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_INCLUDE_DIRS "priv_include"
|
||||
REQUIRES driver
|
||||
PRIV_REQUIRES esp_lcd usb spiffs fatfs
|
||||
)
|
||||
@@ -0,0 +1,180 @@
|
||||
menu "Board Support Package(ESP32-P4)"
|
||||
|
||||
config BSP_ERROR_CHECK
|
||||
bool "Enable error check in BSP"
|
||||
default y
|
||||
help
|
||||
Error check assert the application before returning the error code.
|
||||
|
||||
menu "I2C"
|
||||
config BSP_I2C_NUM
|
||||
int "I2C peripheral index"
|
||||
default 1
|
||||
range 0 1
|
||||
help
|
||||
ESP32P4 has two I2C peripherals, pick the one you want to use.
|
||||
|
||||
config BSP_I2C_FAST_MODE
|
||||
bool "Enable I2C fast mode"
|
||||
default y
|
||||
help
|
||||
I2C has two speed modes: normal (100kHz) and fast (400kHz).
|
||||
|
||||
config BSP_I2C_CLK_SPEED_HZ
|
||||
int
|
||||
default 400000 if BSP_I2C_FAST_MODE
|
||||
default 100000
|
||||
endmenu
|
||||
|
||||
menu "I2S"
|
||||
config BSP_I2S_NUM
|
||||
int "I2S peripheral index"
|
||||
default 1
|
||||
range 0 2
|
||||
help
|
||||
ESP32P4 has three I2S peripherals, pick the one you want to use.
|
||||
endmenu
|
||||
|
||||
menu "uSD card - Virtual File System"
|
||||
config BSP_SD_FORMAT_ON_MOUNT_FAIL
|
||||
bool "Format uSD card if mounting fails"
|
||||
default n
|
||||
help
|
||||
The SDMMC host will format (FAT) the uSD card if it fails to mount the filesystem.
|
||||
|
||||
config BSP_SD_MOUNT_POINT
|
||||
string "uSD card mount point"
|
||||
default "/sdcard"
|
||||
help
|
||||
Mount point of the uSD card in the Virtual File System
|
||||
|
||||
endmenu
|
||||
|
||||
menu "SPIFFS - Virtual File System"
|
||||
config BSP_SPIFFS_FORMAT_ON_MOUNT_FAIL
|
||||
bool "Format SPIFFS if mounting fails"
|
||||
default n
|
||||
help
|
||||
Format SPIFFS if it fails to mount the filesystem.
|
||||
|
||||
config BSP_SPIFFS_MOUNT_POINT
|
||||
string "SPIFFS mount point"
|
||||
default "/spiffs"
|
||||
help
|
||||
Mount point of SPIFFS in the Virtual File System.
|
||||
|
||||
config BSP_SPIFFS_PARTITION_LABEL
|
||||
string "Partition label of SPIFFS"
|
||||
default "storage"
|
||||
help
|
||||
Partition label which stores SPIFFS.
|
||||
|
||||
config BSP_SPIFFS_MAX_FILES
|
||||
int "Max files supported for SPIFFS VFS"
|
||||
default 5
|
||||
help
|
||||
Supported max files for SPIFFS in the Virtual File System.
|
||||
endmenu
|
||||
|
||||
menu "Display"
|
||||
config BSP_LCD_DPI_BUFFER_NUMS
|
||||
int "Set number of frame buffers"
|
||||
default 1
|
||||
range 1 3
|
||||
help
|
||||
Let DPI LCD driver create a specified number of frame-size buffers. Only when it is set to multiple can the avoiding tearing be turned on.
|
||||
|
||||
config BSP_DISPLAY_LVGL_AVOID_TEAR
|
||||
bool "Avoid tearing effect"
|
||||
depends on BSP_LCD_DPI_BUFFER_NUMS > 1
|
||||
default "n"
|
||||
help
|
||||
Avoid tearing effect through LVGL buffer mode and double frame buffers of RGB LCD. This feature is only available for RGB LCD.
|
||||
|
||||
choice BSP_DISPLAY_LVGL_MODE
|
||||
depends on BSP_DISPLAY_LVGL_AVOID_TEAR
|
||||
prompt "Select LVGL buffer mode"
|
||||
default BSP_DISPLAY_LVGL_FULL_REFRESH
|
||||
config BSP_DISPLAY_LVGL_FULL_REFRESH
|
||||
bool "Full refresh"
|
||||
config BSP_DISPLAY_LVGL_DIRECT_MODE
|
||||
bool "Direct mode"
|
||||
endchoice
|
||||
|
||||
config BSP_DISPLAY_BRIGHTNESS_LEDC_CH
|
||||
int "LEDC channel index"
|
||||
default 1
|
||||
range 0 7
|
||||
help
|
||||
LEDC channel is used to generate PWM signal that controls display brightness.
|
||||
Set LEDC index that should be used.
|
||||
|
||||
choice BSP_LCD_COLOR_FORMAT
|
||||
prompt "Select LCD color format"
|
||||
default BSP_LCD_COLOR_FORMAT_RGB565
|
||||
help
|
||||
Select the LCD color format RGB565/RGB888.
|
||||
|
||||
config BSP_LCD_COLOR_FORMAT_RGB565
|
||||
bool "RGB565"
|
||||
config BSP_LCD_COLOR_FORMAT_RGB888
|
||||
bool "RGB888"
|
||||
endchoice
|
||||
|
||||
choice BSP_LCD_TYPE
|
||||
prompt "Select LCD type"
|
||||
default BSP_LCD_TYPE_800_1280_10_1_INCH
|
||||
help
|
||||
Select the LCD.
|
||||
|
||||
config BSP_LCD_TYPE_800_1280_10_1_INCH
|
||||
bool "Waveshare 101M-8001280-IPS-CT-K Display"
|
||||
config BSP_LCD_TYPE_800_1280_10_1_INCH_A
|
||||
bool "Waveshare 10.1-DSI-TOUCH-A Display"
|
||||
config BSP_LCD_TYPE_800_1280_8_INCH_A
|
||||
bool "Waveshare 8-DSI-TOUCH-A Display"
|
||||
config BSP_LCD_TYPE_720_1280_7_INCH_A
|
||||
bool "Waveshare 7-DSI-TOUCH-A Display"
|
||||
config BSP_LCD_TYPE_480_640_2_8_INCH
|
||||
bool "Waveshare 2.8inch DSI LCD Display"
|
||||
config BSP_LCD_TYPE_800_800_3_4_INCH_C
|
||||
bool "Waveshare 3.4inch DSI LCD (C) Display"
|
||||
config BSP_LCD_TYPE_720_720_4_INCH_C
|
||||
bool "Waveshare 4inch DSI LCD (C) Display"
|
||||
config BSP_LCD_TYPE_480_800_4_INCH
|
||||
bool "Waveshare 4inch DSI LCD Display"
|
||||
config BSP_LCD_TYPE_720_1280_5_INCH_D
|
||||
bool "Waveshare 5inch DSI LCD (D) Display"
|
||||
config BSP_LCD_TYPE_720_1560_6_25_INCH
|
||||
bool "Waveshare 6.25inch DSI LCD Display"
|
||||
config BSP_LCD_TYPE_1024_600_5_INCH_C
|
||||
bool "Waveshare 5inch DSI LCD (C) Display"
|
||||
config BSP_LCD_TYPE_1024_600_7_INCH_C
|
||||
bool "Waveshare 7inch DSI LCD (C) Display"
|
||||
config BSP_LCD_TYPE_400_1280_7_9_INCH
|
||||
bool "Waveshare 7.9inch DSI LCD Display"
|
||||
config BSP_LCD_TYPE_1280_800_7_INCH_E
|
||||
bool "Waveshare 7inch DSI LCD (E) Display"
|
||||
config BSP_LCD_TYPE_1280_800_8_INCH_C
|
||||
bool "Waveshare 8inch DSI LCD (C) Display"
|
||||
config BSP_LCD_TYPE_1280_800_10_1_INCH_C
|
||||
bool "Waveshare 10.1inch DSI LCD (C) Display"
|
||||
config BSP_LCD_TYPE_480_1920_8_8_INCH
|
||||
bool "Waveshare 8.8inch DSI LCD Display"
|
||||
config BSP_LCD_TYPE_320_1480_11_9_INCH
|
||||
bool "Waveshare 11.9inch DSI LCD Display"
|
||||
endchoice
|
||||
|
||||
config BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS
|
||||
int "MIPI DSI lane bitrate (Mbps)"
|
||||
default 1500
|
||||
range 600 1500
|
||||
help
|
||||
Set the lane bitrate for the MIPI DSI interface in Mbps.
|
||||
Adjust this value based on the display's requirements and capabilities.
|
||||
Try 840, 860, 933, 1000, 1200, 1500.
|
||||
|
||||
|
||||
endmenu
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -0,0 +1,104 @@
|
||||
# BSP: Waveshare ESP32-P4-NANO
|
||||
|
||||
[](https://components.espressif.com/components/waveshare/esp32_p4_nano)
|
||||
|
||||
ESP32-P4-NANO is a small size and highly integrated development board designed by waveshare electronics based on ESP32-P4 chip
|
||||
| HW version | BSP Version |
|
||||
| :--------: | :---------: |
|
||||
| [V1.0](http://www.waveshare.com/wiki/ESP32-P4-NANO) | ^1 |
|
||||
|
||||
## Configuration
|
||||
|
||||
Configuration in `menuconfig`.
|
||||
|
||||
Selection LCD display `Board Support Package(ESP32-P4) --> Display --> Select LCD type`
|
||||
- Waveshare 101M-8001280-IPS-CT-K Display (default)
|
||||
- Waveshare 10.1-DSI-TOUCH-A Display
|
||||
- Waveshare 8-DSI-TOUCH-A Display
|
||||
- Waveshare 7-DSI-TOUCH-A Display
|
||||
- Waveshare 2.8inch DSI LCD Display
|
||||
- Waveshare 3.4inch DSI LCD (C) Display
|
||||
- Waveshare 4inch DSI LCD (C) Display
|
||||
- Waveshare 4inch DSI LCD Display
|
||||
- Waveshare 5inch DSI LCD (D) Display
|
||||
- Waveshare 6.25inch DSI LCD Display
|
||||
- Waveshare 5inch DSI LCD (C) Display
|
||||
- Waveshare 7inch DSI LCD (C) Display
|
||||
- Waveshare 7.9inch DSI LCD Display
|
||||
- Waveshare 7inch DSI LCD (E) Display
|
||||
- Waveshare 8inch DSI LCD (C) Display
|
||||
- Waveshare 10.1inch DSI LCD (C) Display
|
||||
- Waveshare 8.8inch DSI LCD Display
|
||||
- Waveshare 11.9inch DSI LCD Display
|
||||
|
||||
Selection color format `Board Support Package(ESP32-P4) --> Display --> Select LCD color format`
|
||||
- RGB565 (default)
|
||||
- RGB888
|
||||
|
||||
Change MIPI DSI lane bitrate `Board Support Package(ESP32-P4) --> Display --> MIPI DSI lane bitrate (Mbps)`
|
||||
- 1500 (default)
|
||||
|
||||
## Display Page
|
||||
|
||||
|
||||
### Recommended display screen
|
||||
|
||||
| Product ID | Dependency | tested |
|
||||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------|--------|
|
||||
| [10.1-DSI-TOUCH-A](https://www.waveshare.com/10.1-dsi-touch-a.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/1/0/10.1-dsi-touch-a-1.jpg"> | [waveshare/esp_lcd_jd9365_10_1](display/lcd/esp_lcd_jd9365_10_1) | ✅ |
|
||||
| [101M-8001280-IPS-CT-K](https://www.waveshare.com/101m-8001280-ips-ct-k.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/1/0/101m-8001280-ips-ct-k-1.jpg"> | [waveshare/esp_lcd_jd9365_10_1](display/lcd/esp_lcd_jd9365_10_1) | ✅ |
|
||||
| [7-DSI-TOUCH-A](https://www.waveshare.com/7-dsi-touch-a.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/7/-/7-dsi-touch-a-1.jpg"> | [waveshare/esp_lcd_ili9881c](display/lcd/esp_lcd_ili9881c) | ✅ |
|
||||
|
||||
### Common Raspberry adapter screen
|
||||
|
||||
|
||||
<details open>
|
||||
<summary>View full display</summary>
|
||||
|
||||
| Product ID | Dependency | tested |
|
||||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------|--------|
|
||||
| [2.8inch DSI LCD](https://www.waveshare.com/2.8inch-dsi-lcd.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/thumbnail/122x122/9df78eab33525d08d6e5fb8d27136e95/2/_/2.8inch-dsi-lcd-3.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
| [3.4inch DSI LCD (C)](https://www.waveshare.com/3.4inch-dsi-lcd-c.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/3/_/3.4inch-dsi-lcd-c-1.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
| [4inch DSI LCD (C)](https://www.waveshare.com/4inch-dsi-lcd-c.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/4/i/4inch-dsi-lcd-c-1.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
| [4inch DSI LCD](https://www.waveshare.com/4inch-dsi-lcd.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/4/i/4inch-dsi-lcd-1.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
| [5inch DSI LCD (D)](https://www.waveshare.com/5inch-dsi-lcd-d.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/5/i/5inch-dsi-lcd-d-2.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
| [6.25inch DSI LCD](https://www.waveshare.com/6.25inch-dsi-lcd.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/6/_/6.25inch-dsi-lcd-2.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
| [5inch DSI LCD (C)](https://www.waveshare.com/5inch-dsi-lcd-c.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/5/i/5inch-dsi-lcd-c-2.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
| [7inch DSI LCD (C)](https://www.waveshare.com/7inch-dsi-lcd-c-with-case-a.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/7/i/7inch-dsi-lcd-c-4.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
| [7.9inch DSI LCD](https://www.waveshare.com/7.9inch-dsi-lcd.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/7/_/7.9inch-dsi-lcd-2.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
| [7inch DSI LCD (E)](https://www.waveshare.com/7inch-dsi-lcd-e.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/7/i/7inch-dsi-lcd-e-2.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
| [8inch DSI LCD (C)](https://www.waveshare.com/8inch-dsi-lcd-c.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/8/i/8inch-dsi-lcd-c-2.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
| [10.1inch DSI LCD (C)](https://www.waveshare.com/10.1inch-dsi-lcd-c.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/1/0/10.1inch-dsi-lcd-c-2.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
| [8.8inch DSI LCD](https://www.waveshare.com/8.8inch-dsi-lcd.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/8/_/8.8inch-dsi-lcd-2.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
| [11.9inch DSI LCD](https://www.waveshare.com/11.9inch-dsi-lcd.htm) <br/><img style="width: 150px; height: auto; display: block; margin: 0 auto;" src="https://www.waveshare.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/1/1/11.9inch-dsi-lcd-3.jpg"> | [waveshare/esp_lcd_dsi](display/lcd/esp_lcd_dsi) | ✅ |
|
||||
</details>
|
||||
|
||||
|
||||
## BackLight
|
||||
```c
|
||||
bsp_display_brightness_init();
|
||||
|
||||
bsp_display_backlight_on();
|
||||
|
||||
bsp_display_backlight_off();
|
||||
|
||||
bsp_display_brightness_set(100);
|
||||
```
|
||||
|
||||
<!-- Autogenerated start: Dependencies -->
|
||||
### Capabilities and dependencies
|
||||
| Capability | Available | Component | Version |
|
||||
|-------------|------------------|-----------------------------------------------------------------------------------------------------|---------|
|
||||
| DISPLAY |:heavy_check_mark:| [waveshare/esp_lcd_jd9365_10_1](https://components.espressif.com/components/waveshare/esp_lcd_jd9365_10_1) | 1.0.3 |
|
||||
| DISPLAY |:heavy_check_mark:| [waveshare/esp_lcd_jd9365_8](https://components.espressif.com/components/waveshare/esp_lcd_jd9365_8) | 1.0.4 |
|
||||
| DISPLAY |:heavy_check_mark:| [waveshare/esp_lcd_ili9881c](https://components.espressif.com/components/waveshare/esp_lcd_ili9881c) | 1.0.1 |
|
||||
| DISPLAY |:heavy_check_mark:| [waveshare/esp_lcd_dsi](https://components.espressif.com/components/waveshare/esp_lcd_dsi) | 1.0.3 |
|
||||
| LVGL_PORT |:heavy_check_mark:| [espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port) | ^2 |
|
||||
| TOUCH |:heavy_check_mark:| [espressif/esp_lcd_touch_gt911](https://components.espressif.com/components/espressif/esp_lcd_touch_gt911) | ^1 |
|
||||
| BUTTONS | :x: | | |
|
||||
| AUDIO |:heavy_check_mark:| [espressif/esp_codec_dev](https://components.espressif.com/components/espressif/esp_codec_dev) | 1.2.* |
|
||||
|AUDIO_SPEAKER|:heavy_check_mark:| | |
|
||||
| AUDIO_MIC |:heavy_check_mark:| | |
|
||||
| SDCARD |:heavy_check_mark:| idf | >=5.3 |
|
||||
| IMU | :x: | | |
|
||||
<!-- Autogenerated end: Dependencies -->
|
||||
@@ -0,0 +1,901 @@
|
||||
#include "sdkconfig.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/ledc.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_spiffs.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "esp_lcd_mipi_dsi.h"
|
||||
#include "esp_ldo_regulator.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "usb/usb_host.h"
|
||||
#include "sd_pwr_ctrl_by_on_chip_ldo.h"
|
||||
|
||||
#if CONFIG_BSP_LCD_TYPE_800_1280_10_1_INCH || CONFIG_BSP_LCD_TYPE_800_1280_10_1_INCH_A
|
||||
#include "esp_lcd_jd9365_10_1.h"
|
||||
#elif CONFIG_BSP_LCD_TYPE_800_1280_8_INCH_A
|
||||
#include "esp_lcd_jd9365_8.h"
|
||||
#elif CONFIG_BSP_LCD_TYPE_720_1280_7_INCH_A
|
||||
#include "esp_lcd_ili9881c.h"
|
||||
#else
|
||||
#include "esp_lcd_dsi.h"
|
||||
#endif
|
||||
|
||||
#include "bsp/esp32_p4_nano.h"
|
||||
#include "bsp/display.h"
|
||||
#include "bsp/touch.h"
|
||||
#include "esp_lcd_touch_gt911.h"
|
||||
#include "bsp_err_check.h"
|
||||
#include "esp_codec_dev_defaults.h"
|
||||
|
||||
static const char *TAG = "ESP32_P4_EV";
|
||||
|
||||
#if (BSP_CONFIG_NO_GRAPHIC_LIB == 0)
|
||||
static lv_indev_t *disp_indev = NULL;
|
||||
#endif // (BSP_CONFIG_NO_GRAPHIC_LIB == 0)
|
||||
|
||||
sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler
|
||||
static bool i2c_initialized = false;
|
||||
static TaskHandle_t usb_host_task; // USB Host Library task
|
||||
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0))
|
||||
static i2c_master_bus_handle_t i2c_handle = NULL; // I2C Handle
|
||||
#endif
|
||||
static i2s_chan_handle_t i2s_tx_chan = NULL;
|
||||
static i2s_chan_handle_t i2s_rx_chan = NULL;
|
||||
static const audio_codec_data_if_t *i2s_data_if = NULL; /* Codec data interface */
|
||||
|
||||
/* Can be used for `i2s_std_gpio_config_t` and/or `i2s_std_config_t` initialization */
|
||||
#define BSP_I2S_GPIO_CFG \
|
||||
{ \
|
||||
.mclk = BSP_I2S_MCLK, \
|
||||
.bclk = BSP_I2S_SCLK, \
|
||||
.ws = BSP_I2S_LCLK, \
|
||||
.dout = BSP_I2S_DOUT, \
|
||||
.din = BSP_I2S_DSIN, \
|
||||
.invert_flags = { \
|
||||
.mclk_inv = false, \
|
||||
.bclk_inv = false, \
|
||||
.ws_inv = false, \
|
||||
}, \
|
||||
}
|
||||
|
||||
|
||||
// .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO),
|
||||
/* This configuration is used by default in `bsp_extra_audio_init()` */
|
||||
#define BSP_I2S_DUPLEX_MONO_CFG(_sample_rate) \
|
||||
{ \
|
||||
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(_sample_rate), \
|
||||
.slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO), \
|
||||
.gpio_cfg = BSP_I2S_GPIO_CFG, \
|
||||
}
|
||||
|
||||
esp_err_t bsp_i2c_init(void)
|
||||
{
|
||||
/* I2C was initialized before */
|
||||
if (i2c_initialized) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
// i2c_master_bus_config_t i2c_bus_conf = {
|
||||
// .clk_source = I2C_CLK_SRC_DEFAULT,
|
||||
// .sda_io_num = BSP_I2C_SDA,
|
||||
// .scl_io_num = BSP_I2C_SCL,
|
||||
// .i2c_port = BSP_I2C_NUM,
|
||||
// };
|
||||
|
||||
i2c_master_bus_config_t i2c_bus_conf = {
|
||||
.i2c_port = BSP_I2C_NUM,
|
||||
.sda_io_num = BSP_I2C_SDA,
|
||||
.scl_io_num = BSP_I2C_SCL,
|
||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||
.glitch_ignore_cnt = 7,
|
||||
.intr_priority = 0,
|
||||
.trans_queue_depth = 0,
|
||||
.flags = {
|
||||
.enable_internal_pullup = 1,
|
||||
},
|
||||
};
|
||||
BSP_ERROR_CHECK_RETURN_ERR(i2c_new_master_bus(&i2c_bus_conf, &i2c_handle));
|
||||
|
||||
i2c_initialized = true;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_i2c_deinit(void)
|
||||
{
|
||||
BSP_ERROR_CHECK_RETURN_ERR(i2c_del_master_bus(i2c_handle));
|
||||
i2c_initialized = false;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
i2c_master_bus_handle_t bsp_i2c_get_handle(void)
|
||||
{
|
||||
return i2c_handle;
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_mount(void)
|
||||
{
|
||||
const esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
#ifdef CONFIG_BSP_SD_FORMAT_ON_MOUNT_FAIL
|
||||
.format_if_mount_failed = true,
|
||||
#else
|
||||
.format_if_mount_failed = false,
|
||||
#endif
|
||||
.max_files = 5,
|
||||
.allocation_unit_size = 64 * 1024
|
||||
};
|
||||
|
||||
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
||||
host.slot = SDMMC_HOST_SLOT_0;
|
||||
host.max_freq_khz = SDMMC_FREQ_HIGHSPEED;
|
||||
|
||||
sd_pwr_ctrl_ldo_config_t ldo_config = {
|
||||
.ldo_chan_id = 4,
|
||||
};
|
||||
sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;
|
||||
esp_err_t ret = sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to create a new on-chip LDO power control driver");
|
||||
return ret;
|
||||
}
|
||||
host.pwr_ctrl_handle = pwr_ctrl_handle;
|
||||
|
||||
const sdmmc_slot_config_t slot_config = {
|
||||
/* SD card is connected to Slot 0 pins. Slot 0 uses IO MUX, so not specifying the pins here */
|
||||
.cd = SDMMC_SLOT_NO_CD,
|
||||
.wp = SDMMC_SLOT_NO_WP,
|
||||
.width = 4,
|
||||
.flags = 0,
|
||||
};
|
||||
|
||||
return esp_vfs_fat_sdmmc_mount(BSP_SD_MOUNT_POINT, &host, &slot_config, &mount_config, &bsp_sdcard);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_unmount(void)
|
||||
{
|
||||
return esp_vfs_fat_sdcard_unmount(BSP_SD_MOUNT_POINT, bsp_sdcard);
|
||||
}
|
||||
|
||||
esp_err_t bsp_spiffs_mount(void)
|
||||
{
|
||||
esp_vfs_spiffs_conf_t conf = {
|
||||
.base_path = CONFIG_BSP_SPIFFS_MOUNT_POINT,
|
||||
.partition_label = CONFIG_BSP_SPIFFS_PARTITION_LABEL,
|
||||
.max_files = CONFIG_BSP_SPIFFS_MAX_FILES,
|
||||
#ifdef CONFIG_BSP_SPIFFS_FORMAT_ON_MOUNT_FAIL
|
||||
.format_if_mount_failed = true,
|
||||
#else
|
||||
.format_if_mount_failed = false,
|
||||
#endif
|
||||
};
|
||||
|
||||
esp_err_t ret_val = esp_vfs_spiffs_register(&conf);
|
||||
|
||||
BSP_ERROR_CHECK_RETURN_ERR(ret_val);
|
||||
|
||||
size_t total = 0, used = 0;
|
||||
ret_val = esp_spiffs_info(conf.partition_label, &total, &used);
|
||||
if (ret_val != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret_val));
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
esp_err_t bsp_spiffs_unmount(void)
|
||||
{
|
||||
return esp_vfs_spiffs_unregister(CONFIG_BSP_SPIFFS_PARTITION_LABEL);
|
||||
}
|
||||
|
||||
esp_err_t bsp_audio_init(const i2s_std_config_t *i2s_config)
|
||||
{
|
||||
if (i2s_tx_chan && i2s_rx_chan) {
|
||||
/* Audio was initialized before */
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* Setup I2S peripheral */
|
||||
i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(CONFIG_BSP_I2S_NUM, I2S_ROLE_MASTER);
|
||||
chan_cfg.auto_clear = true; // Auto clear the legacy data in the DMA buffer
|
||||
ESP_ERROR_CHECK(i2s_new_channel(&chan_cfg, &i2s_tx_chan, &i2s_rx_chan));
|
||||
|
||||
/* Setup I2S channels */
|
||||
const i2s_std_config_t std_cfg_default = BSP_I2S_DUPLEX_MONO_CFG(22050);
|
||||
const i2s_std_config_t *p_i2s_cfg = &std_cfg_default;
|
||||
if (i2s_config != NULL) {
|
||||
p_i2s_cfg = i2s_config;
|
||||
}
|
||||
|
||||
if (i2s_tx_chan != NULL) {
|
||||
ESP_ERROR_CHECK(i2s_channel_init_std_mode(i2s_tx_chan, p_i2s_cfg));
|
||||
ESP_ERROR_CHECK(i2s_channel_enable(i2s_tx_chan));
|
||||
}
|
||||
|
||||
if (i2s_rx_chan != NULL) {
|
||||
ESP_ERROR_CHECK(i2s_channel_init_std_mode(i2s_rx_chan, p_i2s_cfg));
|
||||
ESP_ERROR_CHECK(i2s_channel_enable(i2s_rx_chan));
|
||||
}
|
||||
|
||||
audio_codec_i2s_cfg_t i2s_cfg = {
|
||||
.port = CONFIG_BSP_I2S_NUM,
|
||||
.tx_handle = i2s_tx_chan,
|
||||
.rx_handle = i2s_rx_chan,
|
||||
};
|
||||
i2s_data_if = audio_codec_new_i2s_data(&i2s_cfg);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_codec_dev_handle_t bsp_audio_codec_speaker_init(void)
|
||||
{
|
||||
if (i2s_data_if == NULL) {
|
||||
/* Initilize I2C */
|
||||
ESP_ERROR_CHECK(bsp_i2c_init());
|
||||
/* Configure I2S peripheral and Power Amplifier */
|
||||
ESP_ERROR_CHECK(bsp_audio_init(NULL));
|
||||
}
|
||||
assert(i2s_data_if);
|
||||
|
||||
const audio_codec_gpio_if_t *gpio_if = audio_codec_new_gpio();
|
||||
|
||||
audio_codec_i2c_cfg_t i2c_cfg = {
|
||||
.port = BSP_I2C_NUM,
|
||||
.addr = ES8311_CODEC_DEFAULT_ADDR,
|
||||
.bus_handle = i2c_handle,
|
||||
};
|
||||
const audio_codec_ctrl_if_t *i2c_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);
|
||||
assert(i2c_ctrl_if);
|
||||
|
||||
esp_codec_dev_hw_gain_t gain = {
|
||||
.pa_voltage = 5.0,
|
||||
.codec_dac_voltage = 3.3,
|
||||
};
|
||||
|
||||
es8311_codec_cfg_t es8311_cfg = {
|
||||
.ctrl_if = i2c_ctrl_if,
|
||||
.gpio_if = gpio_if,
|
||||
.codec_mode = ESP_CODEC_DEV_TYPE_OUT,
|
||||
.pa_pin = BSP_POWER_AMP_IO,
|
||||
.pa_reverted = false,
|
||||
.master_mode = false,
|
||||
.use_mclk = true,
|
||||
.digital_mic = false,
|
||||
.invert_mclk = false,
|
||||
.invert_sclk = false,
|
||||
.hw_gain = gain,
|
||||
};
|
||||
const audio_codec_if_t *es8311_dev = es8311_codec_new(&es8311_cfg);
|
||||
assert(es8311_dev);
|
||||
|
||||
esp_codec_dev_cfg_t codec_dev_cfg = {
|
||||
.dev_type = ESP_CODEC_DEV_TYPE_IN_OUT,
|
||||
.codec_if = es8311_dev,
|
||||
.data_if = i2s_data_if,
|
||||
};
|
||||
return esp_codec_dev_new(&codec_dev_cfg);
|
||||
}
|
||||
|
||||
esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void)
|
||||
{
|
||||
if (i2s_data_if == NULL) {
|
||||
/* Initilize I2C */
|
||||
ESP_ERROR_CHECK(bsp_i2c_init());
|
||||
/* Configure I2S peripheral and Power Amplifier */
|
||||
ESP_ERROR_CHECK(bsp_audio_init(NULL));
|
||||
}
|
||||
assert(i2s_data_if);
|
||||
|
||||
const audio_codec_gpio_if_t *gpio_if = audio_codec_new_gpio();
|
||||
|
||||
audio_codec_i2c_cfg_t i2c_cfg = {
|
||||
.port = BSP_I2C_NUM,
|
||||
.addr = ES8311_CODEC_DEFAULT_ADDR,
|
||||
.bus_handle = i2c_handle,
|
||||
};
|
||||
const audio_codec_ctrl_if_t *i2c_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);
|
||||
assert(i2c_ctrl_if);
|
||||
|
||||
esp_codec_dev_hw_gain_t gain = {
|
||||
.pa_voltage = 5.0,
|
||||
.codec_dac_voltage = 3.3,
|
||||
};
|
||||
|
||||
es8311_codec_cfg_t es8311_cfg = {
|
||||
.ctrl_if = i2c_ctrl_if,
|
||||
.gpio_if = gpio_if,
|
||||
.codec_mode = ESP_CODEC_DEV_WORK_MODE_BOTH,
|
||||
.pa_pin = BSP_POWER_AMP_IO,
|
||||
.pa_reverted = false,
|
||||
.master_mode = false,
|
||||
.use_mclk = true,
|
||||
.digital_mic = false,
|
||||
.invert_mclk = false,
|
||||
.invert_sclk = false,
|
||||
.hw_gain = gain,
|
||||
};
|
||||
|
||||
const audio_codec_if_t *es8311_dev = es8311_codec_new(&es8311_cfg);
|
||||
assert(es8311_dev);
|
||||
|
||||
esp_codec_dev_cfg_t codec_es8311_dev_cfg = {
|
||||
.dev_type = ESP_CODEC_DEV_TYPE_IN,
|
||||
.codec_if = es8311_dev,
|
||||
.data_if = i2s_data_if,
|
||||
};
|
||||
return esp_codec_dev_new(&codec_es8311_dev_cfg);
|
||||
}
|
||||
|
||||
// Bit number used to represent command and parameter
|
||||
#define LCD_LEDC_CH CONFIG_BSP_DISPLAY_BRIGHTNESS_LEDC_CH
|
||||
|
||||
esp_err_t bsp_display_brightness_init(void)
|
||||
{
|
||||
bsp_i2c_init();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_display_brightness_set(int brightness_percent)
|
||||
{
|
||||
if (brightness_percent > 100) {
|
||||
brightness_percent = 100;
|
||||
}
|
||||
if (brightness_percent < 0) {
|
||||
brightness_percent = 0;
|
||||
}
|
||||
|
||||
uint8_t data = (uint8_t)(255 * brightness_percent * 0.01);
|
||||
uint8_t chip_addr = 0x45;
|
||||
#if CONFIG_BSP_LCD_TYPE_800_1280_10_1_INCH
|
||||
uint8_t data_addr = 0x86;
|
||||
uint8_t data_to_send[2] = {data_addr, data};
|
||||
#elif CONFIG_BSP_LCD_TYPE_800_1280_10_1_INCH_A || CONFIG_BSP_LCD_TYPE_800_1280_8_INCH_A || CONFIG_BSP_LCD_TYPE_720_1280_7_INCH_A
|
||||
uint8_t data_addr = 0x96;
|
||||
uint8_t data_to_send[2] = {data_addr, data};
|
||||
#else
|
||||
uint8_t data_addr = 0xab;
|
||||
uint8_t data_to_send[2] = {data_addr, 0xff - data};
|
||||
#endif
|
||||
|
||||
i2c_device_config_t i2c_dev_conf = {
|
||||
.scl_speed_hz = 100 * 1000,
|
||||
.device_address = chip_addr,
|
||||
};
|
||||
|
||||
i2c_master_dev_handle_t dev_handle = NULL;
|
||||
if (i2c_master_bus_add_device(i2c_handle, &i2c_dev_conf, &dev_handle) != ESP_OK)
|
||||
{
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t ret = i2c_master_transmit(dev_handle, data_to_send, sizeof(data_to_send), 50);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
i2c_master_bus_rm_device(dev_handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
i2c_master_bus_rm_device(dev_handle);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_display_backlight_off(void)
|
||||
{
|
||||
return bsp_display_brightness_set(0);
|
||||
}
|
||||
|
||||
esp_err_t bsp_display_backlight_on(void)
|
||||
{
|
||||
return bsp_display_brightness_set(100);
|
||||
}
|
||||
|
||||
static esp_err_t bsp_enable_dsi_phy_power(void)
|
||||
{
|
||||
#if BSP_MIPI_DSI_PHY_PWR_LDO_CHAN > 0
|
||||
// Turn on the power for MIPI DSI PHY, so it can go from "No Power" state to "Shutdown" state
|
||||
static esp_ldo_channel_handle_t phy_pwr_chan = NULL;
|
||||
esp_ldo_channel_config_t ldo_cfg = {
|
||||
.chan_id = BSP_MIPI_DSI_PHY_PWR_LDO_CHAN,
|
||||
.voltage_mv = BSP_MIPI_DSI_PHY_PWR_LDO_VOLTAGE_MV,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(esp_ldo_acquire_channel(&ldo_cfg, &phy_pwr_chan), TAG, "Acquire LDO channel for DPHY failed");
|
||||
ESP_LOGI(TAG, "MIPI DSI PHY Powered on");
|
||||
#endif // BSP_MIPI_DSI_PHY_PWR_LDO_CHAN > 0
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_display_new(const bsp_display_config_t *config, esp_lcd_panel_handle_t *ret_panel, esp_lcd_panel_io_handle_t *ret_io)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
bsp_lcd_handles_t handles;
|
||||
ret = bsp_display_new_with_handles(config, &handles);
|
||||
|
||||
*ret_panel = handles.panel;
|
||||
*ret_io = handles.io;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_display_new_with_handles(const bsp_display_config_t *config, bsp_lcd_handles_t *ret_handles)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ESP_RETURN_ON_ERROR(bsp_display_brightness_init(), TAG, "Brightness init failed");
|
||||
ESP_RETURN_ON_ERROR(bsp_enable_dsi_phy_power(), TAG, "DSI PHY power failed");
|
||||
|
||||
/* create MIPI DSI bus first, it will initialize the DSI PHY as well */
|
||||
esp_lcd_dsi_bus_handle_t mipi_dsi_bus;
|
||||
esp_lcd_dsi_bus_config_t bus_config = {
|
||||
.bus_id = 0,
|
||||
.num_data_lanes = BSP_LCD_MIPI_DSI_LANE_NUM,
|
||||
.phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT,
|
||||
.lane_bit_rate_mbps = 1500,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_new_dsi_bus(&bus_config, &mipi_dsi_bus), TAG, "New DSI bus init failed");
|
||||
|
||||
ESP_LOGI(TAG, "Install MIPI DSI LCD control panel");
|
||||
// we use DBI interface to send LCD commands and parameters
|
||||
esp_lcd_panel_io_handle_t io;
|
||||
esp_lcd_dbi_io_config_t dbi_config = {
|
||||
.virtual_channel = 0,
|
||||
.lcd_cmd_bits = 8, // according to the LCD ILI9881C spec
|
||||
.lcd_param_bits = 8, // according to the LCD ILI9881C spec
|
||||
};
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_io_dbi(mipi_dsi_bus, &dbi_config, &io), err, TAG, "New panel IO failed");
|
||||
|
||||
esp_lcd_panel_handle_t disp_panel = NULL;
|
||||
#if CONFIG_BSP_LCD_TYPE_800_1280_10_1_INCH || CONFIG_BSP_LCD_TYPE_800_1280_10_1_INCH_A
|
||||
ESP_LOGI(TAG, "Install Waveshare 10.1-DSI-TOUCH-A or 101M-8001280-IPS-CT-K LCD control panel");
|
||||
|
||||
#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888
|
||||
esp_lcd_dpi_panel_config_t dpi_config = JD9365_800_1280_PANEL_60HZ_DPI_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#else
|
||||
esp_lcd_dpi_panel_config_t dpi_config = JD9365_800_1280_PANEL_60HZ_DPI_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#endif
|
||||
dpi_config.num_fbs = CONFIG_BSP_LCD_DPI_BUFFER_NUMS;
|
||||
|
||||
jd9365_vendor_config_t vendor_config = {
|
||||
.flags = {
|
||||
.use_mipi_interface = 1,
|
||||
},
|
||||
.mipi_config = {
|
||||
.dsi_bus = mipi_dsi_bus,
|
||||
.dpi_config = &dpi_config,
|
||||
.lane_num = 2,
|
||||
},
|
||||
};
|
||||
esp_lcd_panel_dev_config_t lcd_dev_config = {
|
||||
#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888
|
||||
.bits_per_pixel = 24,
|
||||
#else
|
||||
.bits_per_pixel = 16,
|
||||
#endif
|
||||
.rgb_ele_order = BSP_LCD_COLOR_SPACE,
|
||||
.reset_gpio_num = BSP_LCD_RST,
|
||||
.vendor_config = &vendor_config,
|
||||
};
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_jd9365(io, &lcd_dev_config, &disp_panel), err, TAG, "New LCD panel Waveshare failed");
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_panel_reset(disp_panel), err, TAG, "LCD panel reset failed");
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_panel_init(disp_panel), err, TAG, "LCD panel init failed");
|
||||
|
||||
#elif CONFIG_BSP_LCD_TYPE_800_1280_8_INCH_A
|
||||
ESP_LOGI(TAG, "Install Waveshare 8-DSI-TOUCH-A LCD control panel");
|
||||
|
||||
#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888
|
||||
esp_lcd_dpi_panel_config_t dpi_config = JD9365_8_800_1280_PANEL_60HZ_DPI_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#else
|
||||
esp_lcd_dpi_panel_config_t dpi_config = JD9365_8_800_1280_PANEL_60HZ_DPI_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#endif
|
||||
dpi_config.num_fbs = CONFIG_BSP_LCD_DPI_BUFFER_NUMS;
|
||||
|
||||
jd9365_8_vendor_config_t vendor_config = {
|
||||
.flags = {
|
||||
.use_mipi_interface = 1,
|
||||
},
|
||||
.mipi_config = {
|
||||
.dsi_bus = mipi_dsi_bus,
|
||||
.dpi_config = &dpi_config,
|
||||
.lane_num = 2,
|
||||
},
|
||||
};
|
||||
esp_lcd_panel_dev_config_t lcd_dev_config = {
|
||||
#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888
|
||||
.bits_per_pixel = 24,
|
||||
#else
|
||||
.bits_per_pixel = 16,
|
||||
#endif
|
||||
.rgb_ele_order = BSP_LCD_COLOR_SPACE,
|
||||
.reset_gpio_num = BSP_LCD_RST,
|
||||
.vendor_config = &vendor_config,
|
||||
};
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_jd9365_8(io, &lcd_dev_config, &disp_panel), err, TAG, "New LCD panel Waveshare failed");
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_panel_reset(disp_panel), err, TAG, "LCD panel reset failed");
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_panel_init(disp_panel), err, TAG, "LCD panel init failed");
|
||||
#elif CONFIG_BSP_LCD_TYPE_720_1280_7_INCH_A
|
||||
ESP_LOGI(TAG, "Install Waveshare 7-DSI-TOUCH-A LCD control panel");
|
||||
|
||||
#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888
|
||||
esp_lcd_dpi_panel_config_t dpi_config = ILI9881C_720_1280_PANEL_60HZ_DPI_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#else
|
||||
esp_lcd_dpi_panel_config_t dpi_config = ILI9881C_720_1280_PANEL_60HZ_DPI_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#endif
|
||||
dpi_config.num_fbs = CONFIG_BSP_LCD_DPI_BUFFER_NUMS;
|
||||
|
||||
ili9881c_vendor_config_t vendor_config = {
|
||||
.mipi_config = {
|
||||
.dsi_bus = mipi_dsi_bus,
|
||||
.dpi_config = &dpi_config,
|
||||
.lane_num = 2,
|
||||
},
|
||||
};
|
||||
esp_lcd_panel_dev_config_t lcd_dev_config = {
|
||||
#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888
|
||||
.bits_per_pixel = 24,
|
||||
#else
|
||||
.bits_per_pixel = 16,
|
||||
#endif
|
||||
.rgb_ele_order = BSP_LCD_COLOR_SPACE,
|
||||
.reset_gpio_num = BSP_LCD_RST,
|
||||
.vendor_config = &vendor_config,
|
||||
};
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_ili9881c(io, &lcd_dev_config, &disp_panel), err, TAG, "New LCD panel ILI9881C failed");
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_panel_reset(disp_panel), err, TAG, "LCD panel reset failed");
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_panel_init(disp_panel), err, TAG, "LCD panel init failed");
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_panel_disp_on_off(disp_panel, true), err, TAG, "LCD panel ON failed");
|
||||
#else
|
||||
ESP_LOGI(TAG, "Install Waveshare DSI LCD control panel");
|
||||
#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888
|
||||
#if CONFIG_BSP_LCD_TYPE_480_640_2_8_INCH
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_2_8_INCH_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#elif CONFIG_BSP_LCD_TYPE_800_800_3_4_INCH_C
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_3_4_INCH_C_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#elif CONFIG_BSP_LCD_TYPE_720_720_4_INCH_C
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_4_INCH_C_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#elif CONFIG_BSP_LCD_TYPE_480_800_4_INCH
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_4_INCH_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#elif CONFIG_BSP_LCD_TYPE_720_1280_5_INCH_D
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_5_INCH_D_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#elif CONFIG_BSP_LCD_TYPE_720_1560_6_25_INCH
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_6_25_INCH_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#elif CONFIG_BSP_LCD_TYPE_1024_600_5_INCH_C
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_5_INCH_C_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#elif CONFIG_BSP_LCD_TYPE_1024_600_7_INCH_C
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_7_INCH_C_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#elif CONFIG_BSP_LCD_TYPE_400_1280_7_9_INCH
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_7_9_INCH_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#elif CONFIG_BSP_LCD_TYPE_1280_800_7_INCH_E
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_7_INCH_E_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#elif CONFIG_BSP_LCD_TYPE_1280_800_8_INCH_C
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_8_INCH_C_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#elif CONFIG_BSP_LCD_TYPE_1280_800_10_1_INCH_C
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_10_1_INCH_C_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#elif CONFIG_BSP_LCD_TYPE_480_1920_8_8_INCH
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_8_8_INCH_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#elif CONFIG_BSP_LCD_TYPE_320_1480_11_9_INCH
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_11_9_INCH_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB888);
|
||||
#endif
|
||||
|
||||
#else
|
||||
#if CONFIG_BSP_LCD_TYPE_480_640_2_8_INCH
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_2_8_INCH_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#elif CONFIG_BSP_LCD_TYPE_800_800_3_4_INCH_C
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_3_4_INCH_C_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#elif CONFIG_BSP_LCD_TYPE_720_720_4_INCH_C
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_4_INCH_C_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#elif CONFIG_BSP_LCD_TYPE_480_800_4_INCH
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_4_INCH_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#elif CONFIG_BSP_LCD_TYPE_720_1280_5_INCH_D
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_5_INCH_D_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#elif CONFIG_BSP_LCD_TYPE_720_1560_6_25_INCH
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_6_25_INCH_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#elif CONFIG_BSP_LCD_TYPE_1024_600_5_INCH_C
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_5_INCH_C_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#elif CONFIG_BSP_LCD_TYPE_1024_600_7_INCH_C
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_7_INCH_C_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#elif CONFIG_BSP_LCD_TYPE_400_1280_7_9_INCH
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_7_9_INCH_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#elif CONFIG_BSP_LCD_TYPE_1280_800_7_INCH_E
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_7_INCH_E_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#elif CONFIG_BSP_LCD_TYPE_1280_800_8_INCH_C
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_8_INCH_C_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#elif CONFIG_BSP_LCD_TYPE_1280_800_10_1_INCH_C
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_10_1_INCH_C_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#elif CONFIG_BSP_LCD_TYPE_480_1920_8_8_INCH
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_8_8_INCH_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#elif CONFIG_BSP_LCD_TYPE_320_1480_11_9_INCH
|
||||
esp_lcd_dpi_panel_config_t dpi_config = DSI_PANEL_DPI_11_9_INCH_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
|
||||
#endif
|
||||
#endif
|
||||
dpi_config.num_fbs = CONFIG_BSP_LCD_DPI_BUFFER_NUMS;
|
||||
|
||||
dsi_vendor_config_t vendor_config = {
|
||||
.mipi_config = {
|
||||
.dsi_bus = mipi_dsi_bus,
|
||||
.dpi_config = &dpi_config,
|
||||
},
|
||||
};
|
||||
esp_lcd_panel_dev_config_t lcd_dev_config = {
|
||||
#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888
|
||||
.bits_per_pixel = 24,
|
||||
#else
|
||||
.bits_per_pixel = 16,
|
||||
#endif
|
||||
.rgb_ele_order = BSP_LCD_COLOR_SPACE,
|
||||
.reset_gpio_num = BSP_LCD_RST,
|
||||
.vendor_config = &vendor_config,
|
||||
};
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_dsi(io, &lcd_dev_config, &disp_panel), err, TAG, "New LCD panel Waveshare failed");
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_panel_reset(disp_panel), err, TAG, "LCD panel reset failed");
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_panel_init(disp_panel), err, TAG, "LCD panel init failed");
|
||||
#endif
|
||||
|
||||
/* Return all handles */
|
||||
ret_handles->io = io;
|
||||
ret_handles->mipi_dsi_bus = mipi_dsi_bus;
|
||||
ret_handles->panel = disp_panel;
|
||||
ret_handles->control = NULL;
|
||||
|
||||
ESP_LOGI(TAG, "Display initialized");
|
||||
|
||||
return ret;
|
||||
|
||||
err:
|
||||
if (disp_panel) {
|
||||
esp_lcd_panel_del(disp_panel);
|
||||
}
|
||||
if (io) {
|
||||
esp_lcd_panel_io_del(io);
|
||||
}
|
||||
if (mipi_dsi_bus) {
|
||||
esp_lcd_del_dsi_bus(mipi_dsi_bus);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_touch_new(const bsp_touch_config_t *config, esp_lcd_touch_handle_t *ret_touch)
|
||||
{
|
||||
/* Initilize I2C */
|
||||
BSP_ERROR_CHECK_RETURN_ERR(bsp_i2c_init());
|
||||
|
||||
/* Initialize touch */
|
||||
const esp_lcd_touch_config_t tp_cfg = {
|
||||
#if CONFIG_BSP_LCD_TYPE_480_640_2_8_INCH || CONFIG_BSP_LCD_TYPE_480_800_4_INCH
|
||||
.x_max = BSP_LCD_V_RES,
|
||||
.y_max = BSP_LCD_H_RES,
|
||||
#else
|
||||
.x_max = BSP_LCD_H_RES,
|
||||
.y_max = BSP_LCD_V_RES,
|
||||
#endif
|
||||
.rst_gpio_num = BSP_LCD_TOUCH_RST, // Shared with LCD reset
|
||||
.int_gpio_num = BSP_LCD_TOUCH_INT,
|
||||
.levels = {
|
||||
.reset = 0,
|
||||
.interrupt = 0,
|
||||
},
|
||||
.flags = {
|
||||
#if CONFIG_BSP_LCD_TYPE_800_1280_10_1_INCH || CONFIG_BSP_LCD_TYPE_800_1280_10_1_INCH_A
|
||||
.swap_xy = 0,
|
||||
.mirror_x = 0,
|
||||
.mirror_y = 0,
|
||||
#elif CONFIG_BSP_LCD_TYPE_800_1280_8_INCH_A
|
||||
.swap_xy = 0,
|
||||
.mirror_x = 0,
|
||||
.mirror_y = 0,
|
||||
#elif CONFIG_BSP_LCD_TYPE_480_640_2_8_INCH
|
||||
.swap_xy = 1,
|
||||
.mirror_x = 0,
|
||||
.mirror_y = 1,
|
||||
#elif CONFIG_BSP_LCD_TYPE_480_800_4_INCH
|
||||
.swap_xy = 1,
|
||||
.mirror_x = 1,
|
||||
.mirror_y = 0,
|
||||
#else
|
||||
.swap_xy = 0,
|
||||
.mirror_x = 0,
|
||||
.mirror_y = 0,
|
||||
#endif
|
||||
},
|
||||
};
|
||||
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
|
||||
esp_lcd_panel_io_i2c_config_t tp_io_config = {
|
||||
#if CONFIG_BSP_LCD_TYPE_800_1280_10_1_INCH || CONFIG_BSP_LCD_TYPE_800_1280_10_1_INCH_A || CONFIG_BSP_LCD_TYPE_800_1280_8_INCH_A || CONFIG_BSP_LCD_TYPE_720_1280_7_INCH_A
|
||||
.dev_addr = ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS,
|
||||
#else
|
||||
.dev_addr = ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP,
|
||||
#endif
|
||||
.control_phase_bytes = 1,
|
||||
.dc_bit_offset = 0,
|
||||
.lcd_cmd_bits = 16,
|
||||
.flags = {
|
||||
.disable_control_phase = 1,
|
||||
}
|
||||
};
|
||||
tp_io_config.scl_speed_hz = CONFIG_BSP_I2C_CLK_SPEED_HZ;
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c(i2c_handle, &tp_io_config, &tp_io_handle), TAG, "");
|
||||
return esp_lcd_touch_new_i2c_gt911(tp_io_handle, &tp_cfg, ret_touch);
|
||||
}
|
||||
|
||||
#if (BSP_CONFIG_NO_GRAPHIC_LIB == 0)
|
||||
static lv_display_t *bsp_display_lcd_init(const bsp_display_cfg_t *cfg)
|
||||
{
|
||||
assert(cfg != NULL);
|
||||
bsp_lcd_handles_t lcd_panels;
|
||||
BSP_ERROR_CHECK_RETURN_NULL(bsp_display_new_with_handles(NULL, &lcd_panels));
|
||||
|
||||
/* Add LCD screen */
|
||||
ESP_LOGD(TAG, "Add LCD screen");
|
||||
const lvgl_port_display_cfg_t disp_cfg = {
|
||||
.io_handle = lcd_panels.io,
|
||||
.panel_handle = lcd_panels.panel,
|
||||
.control_handle = lcd_panels.control,
|
||||
.buffer_size = cfg->buffer_size,
|
||||
.double_buffer = cfg->double_buffer,
|
||||
.hres = BSP_LCD_H_RES,
|
||||
.vres = BSP_LCD_V_RES,
|
||||
.monochrome = false,
|
||||
/* Rotation values must be same as used in esp_lcd for initial settings of the screen */
|
||||
.rotation = {
|
||||
.swap_xy = false,
|
||||
.mirror_x = false,
|
||||
.mirror_y = false,
|
||||
},
|
||||
#if LVGL_VERSION_MAJOR >= 9
|
||||
#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888
|
||||
.color_format = LV_COLOR_FORMAT_RGB888,
|
||||
#else
|
||||
.color_format = LV_COLOR_FORMAT_RGB565,
|
||||
#endif
|
||||
#endif
|
||||
.flags = {
|
||||
.buff_dma = cfg->flags.buff_dma,
|
||||
.buff_spiram = cfg->flags.buff_spiram,
|
||||
#if LVGL_VERSION_MAJOR >= 9
|
||||
.swap_bytes = (BSP_LCD_BIGENDIAN ? true : false),
|
||||
#endif
|
||||
#if CONFIG_BSP_DISPLAY_LVGL_AVOID_TEAR
|
||||
.sw_rotate = false, /* Avoid tearing is not supported for SW rotation */
|
||||
#else
|
||||
.sw_rotate = cfg->flags.sw_rotate, /* Only SW rotation is supported for 90° and 270° */
|
||||
#endif
|
||||
#if CONFIG_BSP_DISPLAY_LVGL_FULL_REFRESH
|
||||
.full_refresh = true,
|
||||
#elif CONFIG_BSP_DISPLAY_LVGL_DIRECT_MODE
|
||||
.direct_mode = true,
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
const lvgl_port_display_dsi_cfg_t dpi_cfg = {
|
||||
.flags = {
|
||||
#if CONFIG_BSP_DISPLAY_LVGL_AVOID_TEAR
|
||||
.avoid_tearing = true,
|
||||
#else
|
||||
.avoid_tearing = false,
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
return lvgl_port_add_disp_dsi(&disp_cfg, &dpi_cfg);
|
||||
}
|
||||
|
||||
static lv_indev_t *bsp_display_indev_init(lv_display_t *disp)
|
||||
{
|
||||
esp_lcd_touch_handle_t tp;
|
||||
BSP_ERROR_CHECK_RETURN_NULL(bsp_touch_new(NULL, &tp));
|
||||
assert(tp);
|
||||
|
||||
/* Add touch input (for selected screen) */
|
||||
const lvgl_port_touch_cfg_t touch_cfg = {
|
||||
.disp = disp,
|
||||
.handle = tp,
|
||||
};
|
||||
|
||||
return lvgl_port_add_touch(&touch_cfg);
|
||||
}
|
||||
|
||||
lv_display_t *bsp_display_start(void)
|
||||
{
|
||||
bsp_display_cfg_t cfg = {
|
||||
.lvgl_port_cfg = ESP_LVGL_PORT_INIT_CONFIG(),
|
||||
.buffer_size = BSP_LCD_DRAW_BUFF_SIZE,
|
||||
.double_buffer = BSP_LCD_DRAW_BUFF_DOUBLE,
|
||||
.flags = {
|
||||
#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888
|
||||
.buff_dma = false,
|
||||
#else
|
||||
.buff_dma = true,
|
||||
#endif
|
||||
.buff_spiram = false,
|
||||
.sw_rotate = true,
|
||||
}
|
||||
};
|
||||
return bsp_display_start_with_config(&cfg);
|
||||
}
|
||||
|
||||
lv_display_t *bsp_display_start_with_config(const bsp_display_cfg_t *cfg)
|
||||
{
|
||||
lv_display_t *disp;
|
||||
|
||||
assert(cfg != NULL);
|
||||
BSP_ERROR_CHECK_RETURN_NULL(lvgl_port_init(&cfg->lvgl_port_cfg));
|
||||
|
||||
BSP_ERROR_CHECK_RETURN_NULL(bsp_display_brightness_init());
|
||||
|
||||
BSP_NULL_CHECK(disp = bsp_display_lcd_init(cfg), NULL);
|
||||
|
||||
BSP_NULL_CHECK(disp_indev = bsp_display_indev_init(disp), NULL);
|
||||
|
||||
return disp;
|
||||
}
|
||||
|
||||
lv_indev_t *bsp_display_get_input_dev(void)
|
||||
{
|
||||
return disp_indev;
|
||||
}
|
||||
|
||||
void bsp_display_rotate(lv_display_t *disp, lv_disp_rotation_t rotation)
|
||||
{
|
||||
lv_disp_set_rotation(disp, rotation);
|
||||
}
|
||||
|
||||
bool bsp_display_lock(uint32_t timeout_ms)
|
||||
{
|
||||
return lvgl_port_lock(timeout_ms);
|
||||
}
|
||||
|
||||
void bsp_display_unlock(void)
|
||||
{
|
||||
lvgl_port_unlock();
|
||||
}
|
||||
|
||||
#endif // (BSP_CONFIG_NO_GRAPHIC_LIB == 0)
|
||||
|
||||
static void usb_lib_task(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
// Start handling system events
|
||||
uint32_t event_flags;
|
||||
usb_host_lib_handle_events(portMAX_DELAY, &event_flags);
|
||||
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS) {
|
||||
ESP_ERROR_CHECK(usb_host_device_free_all());
|
||||
}
|
||||
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_ALL_FREE) {
|
||||
ESP_LOGI(TAG, "USB: All devices freed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t bsp_usb_host_start(bsp_usb_host_power_mode_t mode, bool limit_500mA)
|
||||
{
|
||||
//Install USB Host driver. Should only be called once in entire application
|
||||
ESP_LOGI(TAG, "Installing USB Host");
|
||||
const usb_host_config_t host_config = {
|
||||
.skip_phy_setup = false,
|
||||
.intr_flags = ESP_INTR_FLAG_LEVEL1,
|
||||
};
|
||||
BSP_ERROR_CHECK_RETURN_ERR(usb_host_install(&host_config));
|
||||
|
||||
// Create a task that will handle USB library events
|
||||
if (xTaskCreate(usb_lib_task, "usb_lib", 4096, NULL, 10, &usb_host_task) != pdTRUE) {
|
||||
ESP_LOGE(TAG, "Creating USB host lib task failed");
|
||||
abort();
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_usb_host_stop(void)
|
||||
{
|
||||
usb_host_uninstall();
|
||||
if (usb_host_task) {
|
||||
vTaskSuspend(usb_host_task);
|
||||
vTaskDelete(usb_host_task);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
dependencies:
|
||||
esp_codec_dev:
|
||||
public: true
|
||||
version: 1.2.*
|
||||
esp_lcd_touch_gt911: ^1
|
||||
espressif/esp_lvgl_port:
|
||||
public: true
|
||||
version: ^2
|
||||
idf: '>=5.3'
|
||||
lvgl/lvgl: '8.4.0'
|
||||
waveshare/esp_lcd_dsi: '*'
|
||||
waveshare/esp_lcd_ili9881c: '*'
|
||||
waveshare/esp_lcd_jd9365_10_1: '*'
|
||||
waveshare/esp_lcd_jd9365_8: '*'
|
||||
description: a small size and highly integrated development board designed by waveshare
|
||||
electronics based on ESP32-P4 chip
|
||||
repository: git://github.com/waveshareteam/Waveshare-ESP32-components.git
|
||||
repository_info:
|
||||
commit_sha: 2888408bdb38e806de5851811fb0b2a673168fc7
|
||||
path: bsp/esp32_p4_nano
|
||||
tags:
|
||||
- bsp
|
||||
targets:
|
||||
- esp32p4
|
||||
url: https://www.waveshare.com/esp32-p4-nano.htm
|
||||
version: 1.1.5
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
/**************************************************************************************************
|
||||
* BSP configuration
|
||||
**************************************************************************************************/
|
||||
// By default, this BSP is shipped with LVGL graphical library. Enabling this option will exclude it.
|
||||
// If you want to use BSP without LVGL, select BSP version with 'noglib' suffix.
|
||||
#if !defined(BSP_CONFIG_NO_GRAPHIC_LIB) // Check if the symbol is not coming from compiler definitions (-D...)
|
||||
#define BSP_CONFIG_NO_GRAPHIC_LIB (0)
|
||||
#endif
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
#pragma once
|
||||
#include "esp_lcd_types.h"
|
||||
#include "esp_lcd_mipi_dsi.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
/* LCD color formats */
|
||||
#define ESP_LCD_COLOR_FORMAT_RGB565 (1)
|
||||
#define ESP_LCD_COLOR_FORMAT_RGB888 (2)
|
||||
|
||||
/* LCD display color format */
|
||||
#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888
|
||||
#define BSP_LCD_COLOR_FORMAT (ESP_LCD_COLOR_FORMAT_RGB888)
|
||||
#else
|
||||
#define BSP_LCD_COLOR_FORMAT (ESP_LCD_COLOR_FORMAT_RGB565)
|
||||
#endif
|
||||
/* LCD display color bytes endianess */
|
||||
#define BSP_LCD_BIGENDIAN (0)
|
||||
/* LCD display color bits */
|
||||
#define BSP_LCD_BITS_PER_PIXEL (16)
|
||||
/* LCD display color space */
|
||||
#define BSP_LCD_COLOR_SPACE (ESP_LCD_COLOR_SPACE_RGB)
|
||||
|
||||
#if CONFIG_BSP_LCD_TYPE_800_1280_10_1_INCH
|
||||
#define BSP_LCD_H_RES (800)
|
||||
#define BSP_LCD_V_RES (1280)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1500)
|
||||
#elif CONFIG_BSP_LCD_TYPE_800_1280_10_1_INCH_A
|
||||
#define BSP_LCD_H_RES (800)
|
||||
#define BSP_LCD_V_RES (1280)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1500)
|
||||
#elif CONFIG_BSP_LCD_TYPE_800_1280_8_INCH_A
|
||||
#define BSP_LCD_H_RES (800)
|
||||
#define BSP_LCD_V_RES (1280)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1500)
|
||||
#elif CONFIG_BSP_LCD_TYPE_720_1280_7_INCH_A
|
||||
#define BSP_LCD_H_RES (720)
|
||||
#define BSP_LCD_V_RES (1280)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1000)
|
||||
#elif CONFIG_BSP_LCD_TYPE_480_640_2_8_INCH
|
||||
#define BSP_LCD_H_RES (480)
|
||||
#define BSP_LCD_V_RES (640)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1500)
|
||||
#elif CONFIG_BSP_LCD_TYPE_800_800_3_4_INCH_C
|
||||
#define BSP_LCD_H_RES (800)
|
||||
#define BSP_LCD_V_RES (800)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1500)
|
||||
#elif CONFIG_BSP_LCD_TYPE_720_720_4_INCH_C
|
||||
#define BSP_LCD_H_RES (720)
|
||||
#define BSP_LCD_V_RES (720)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1500)
|
||||
#elif CONFIG_BSP_LCD_TYPE_480_800_4_INCH
|
||||
#define BSP_LCD_H_RES (480)
|
||||
#define BSP_LCD_V_RES (800)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1500)
|
||||
#elif CONFIG_BSP_LCD_TYPE_720_1280_5_INCH_D
|
||||
#define BSP_LCD_H_RES (720)
|
||||
#define BSP_LCD_V_RES (1280)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1500)
|
||||
#elif CONFIG_BSP_LCD_TYPE_720_1560_6_25_INCH
|
||||
#define BSP_LCD_H_RES (720)
|
||||
#define BSP_LCD_V_RES (1560)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1500)
|
||||
#elif CONFIG_BSP_LCD_TYPE_1024_600_5_INCH_C
|
||||
#define BSP_LCD_H_RES (1024)
|
||||
#define BSP_LCD_V_RES (600)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1500)
|
||||
#elif CONFIG_BSP_LCD_TYPE_1024_600_7_INCH_C
|
||||
#define BSP_LCD_H_RES (1024)
|
||||
#define BSP_LCD_V_RES (600)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1500)
|
||||
#elif CONFIG_BSP_LCD_TYPE_400_1280_7_9_INCH
|
||||
#define BSP_LCD_H_RES (400)
|
||||
#define BSP_LCD_V_RES (1280)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1200)
|
||||
#elif CONFIG_BSP_LCD_TYPE_1280_800_7_INCH_E
|
||||
#define BSP_LCD_H_RES (1280)
|
||||
#define BSP_LCD_V_RES (800)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1250)
|
||||
#elif CONFIG_BSP_LCD_TYPE_1280_800_8_INCH_C
|
||||
#define BSP_LCD_H_RES (1280)
|
||||
#define BSP_LCD_V_RES (800)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1250)
|
||||
#elif CONFIG_BSP_LCD_TYPE_1280_800_10_1_INCH_C
|
||||
#define BSP_LCD_H_RES (1280)
|
||||
#define BSP_LCD_V_RES (800)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1250)
|
||||
#elif CONFIG_BSP_LCD_TYPE_480_1920_8_8_INCH
|
||||
#define BSP_LCD_H_RES (480)
|
||||
#define BSP_LCD_V_RES (1920)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1500)
|
||||
#elif CONFIG_BSP_LCD_TYPE_320_1480_11_9_INCH
|
||||
#define BSP_LCD_H_RES (320)
|
||||
#define BSP_LCD_V_RES (1480)
|
||||
#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (1500)
|
||||
#endif
|
||||
|
||||
#define BSP_LCD_MIPI_DSI_LANE_NUM (2) // 2 data lanes
|
||||
#define BSP_MIPI_DSI_PHY_PWR_LDO_CHAN (3) // LDO_VO3 is connected to VDD_MIPI_DPHY
|
||||
#define BSP_MIPI_DSI_PHY_PWR_LDO_VOLTAGE_MV (2500)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief BSP display configuration structure
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
int dummy;
|
||||
} bsp_display_config_t;
|
||||
|
||||
/**
|
||||
* @brief BSP display return handles
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
esp_lcd_dsi_bus_handle_t mipi_dsi_bus; /*!< MIPI DSI bus handle */
|
||||
esp_lcd_panel_io_handle_t io; /*!< ESP LCD IO handle */
|
||||
esp_lcd_panel_handle_t panel; /*!< ESP LCD panel (color) handle */
|
||||
esp_lcd_panel_handle_t control; /*!< ESP LCD panel (control) handle */
|
||||
} bsp_lcd_handles_t;
|
||||
|
||||
/**
|
||||
* @brief Create new display panel
|
||||
*
|
||||
* For maximum flexibility, this function performs only reset and initialization of the display.
|
||||
* You must turn on the display explicitly by calling esp_lcd_panel_disp_on_off().
|
||||
* The display's backlight is not turned on either. You can use bsp_display_backlight_on/off(),
|
||||
* bsp_display_brightness_set() (on supported boards) or implement your own backlight control.
|
||||
*
|
||||
* If you want to free resources allocated by this function, you can use esp_lcd API, ie.:
|
||||
*
|
||||
* \code{.c}
|
||||
* esp_lcd_panel_del(panel);
|
||||
* esp_lcd_panel_io_del(io);
|
||||
* esp_lcd_del_dsi_bus(mipi_dsi_bus);
|
||||
* \endcode
|
||||
*
|
||||
* @param[in] config display configuration
|
||||
* @param[out] ret_panel esp_lcd panel handle
|
||||
* @param[out] ret_io esp_lcd IO handle
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Else esp_lcd failure
|
||||
*/
|
||||
esp_err_t bsp_display_new(const bsp_display_config_t *config, esp_lcd_panel_handle_t *ret_panel, esp_lcd_panel_io_handle_t *ret_io);
|
||||
|
||||
/**
|
||||
* @brief Create new display panel
|
||||
*
|
||||
* For maximum flexibility, this function performs only reset and initialization of the display.
|
||||
* You must turn on the display explicitly by calling esp_lcd_panel_disp_on_off().
|
||||
* The display's backlight is not turned on either. You can use bsp_display_backlight_on/off(),
|
||||
* bsp_display_brightness_set() (on supported boards) or implement your own backlight control.
|
||||
*
|
||||
* If you want to free resources allocated by this function, you can use esp_lcd API, ie.:
|
||||
*
|
||||
* \code{.c}
|
||||
* esp_lcd_panel_del(panel);
|
||||
* esp_lcd_panel_del(control);
|
||||
* esp_lcd_panel_io_del(io);
|
||||
* esp_lcd_del_dsi_bus(mipi_dsi_bus);
|
||||
* \endcode
|
||||
*
|
||||
* @param[in] config display configuration
|
||||
* @param[out] ret_handles all esp_lcd handles in one structure
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Else esp_lcd failure
|
||||
*/
|
||||
esp_err_t bsp_display_new_with_handles(const bsp_display_config_t *config, bsp_lcd_handles_t *ret_handles);
|
||||
|
||||
/**
|
||||
* @brief Initialize display's brightness
|
||||
*
|
||||
* Brightness is controlled with PWM signal to a pin controlling backlight.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t bsp_display_brightness_init(void);
|
||||
|
||||
/**
|
||||
* @brief Set display's brightness
|
||||
*
|
||||
* Brightness is controlled with PWM signal to a pin controlling backlight.
|
||||
* Brightness must be already initialized by calling bsp_display_brightness_init() or bsp_display_new()
|
||||
*
|
||||
* @param[in] brightness_percent Brightness in [%]
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t bsp_display_brightness_set(int brightness_percent);
|
||||
|
||||
/**
|
||||
* @brief Turn on display backlight
|
||||
*
|
||||
* Brightness is controlled with PWM signal to a pin controlling backlight.
|
||||
* Brightness must be already initialized by calling bsp_display_brightness_init() or bsp_display_new()
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t bsp_display_backlight_on(void);
|
||||
|
||||
/**
|
||||
* @brief Turn off display backlight
|
||||
*
|
||||
* Brightness is controlled with PWM signal to a pin controlling backlight.
|
||||
* Brightness must be already initialized by calling bsp_display_brightness_init() or bsp_display_new()
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t bsp_display_backlight_off(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
#pragma once
|
||||
#include "bsp/esp32_p4_nano.h"
|
||||
+363
@@ -0,0 +1,363 @@
|
||||
#pragma once
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/i2c_master.h"
|
||||
#include "driver/sdmmc_host.h"
|
||||
#include "driver/i2s_std.h"
|
||||
#include "bsp/config.h"
|
||||
#include "bsp/display.h"
|
||||
#include "esp_codec_dev.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#if (BSP_CONFIG_NO_GRAPHIC_LIB == 0)
|
||||
#include "lvgl.h"
|
||||
#include "esp_lvgl_port.h"
|
||||
#endif // BSP_CONFIG_NO_GRAPHIC_LIB == 0
|
||||
|
||||
/**************************************************************************************************
|
||||
* BSP Capabilities
|
||||
**************************************************************************************************/
|
||||
|
||||
#define BSP_CAPS_DISPLAY 1
|
||||
#define BSP_CAPS_TOUCH 1
|
||||
#define BSP_CAPS_BUTTONS 0
|
||||
#define BSP_CAPS_AUDIO 1
|
||||
#define BSP_CAPS_AUDIO_SPEAKER 1
|
||||
#define BSP_CAPS_AUDIO_MIC 1
|
||||
#define BSP_CAPS_SDCARD 1
|
||||
#define BSP_CAPS_IMU 0
|
||||
|
||||
/**************************************************************************************************
|
||||
* ESP-BOX pinout
|
||||
**************************************************************************************************/
|
||||
/* I2C */
|
||||
#define BSP_I2C_SCL (GPIO_NUM_8)
|
||||
#define BSP_I2C_SDA (GPIO_NUM_7)
|
||||
|
||||
/* Audio */
|
||||
#define BSP_I2S_SCLK (GPIO_NUM_12)
|
||||
#define BSP_I2S_MCLK (GPIO_NUM_13)
|
||||
#define BSP_I2S_LCLK (GPIO_NUM_10)
|
||||
#define BSP_I2S_DOUT (GPIO_NUM_9)
|
||||
#define BSP_I2S_DSIN (GPIO_NUM_48)
|
||||
#define BSP_POWER_AMP_IO (GPIO_NUM_11)
|
||||
|
||||
#define BSP_LCD_BACKLIGHT (GPIO_NUM_NC)
|
||||
#define BSP_LCD_RST (GPIO_NUM_NC)
|
||||
#define BSP_LCD_TOUCH_RST (GPIO_NUM_NC)
|
||||
#define BSP_LCD_TOUCH_INT (GPIO_NUM_NC)
|
||||
|
||||
/* uSD card */
|
||||
#define BSP_SD_D0 (GPIO_NUM_39)
|
||||
#define BSP_SD_D1 (GPIO_NUM_40)
|
||||
#define BSP_SD_D2 (GPIO_NUM_41)
|
||||
#define BSP_SD_D3 (GPIO_NUM_42)
|
||||
#define BSP_SD_CMD (GPIO_NUM_44)
|
||||
#define BSP_SD_CLK (GPIO_NUM_43)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
*
|
||||
* I2C interface
|
||||
*
|
||||
* There are multiple devices connected to I2C peripheral:
|
||||
* - Codec ES8311 (configuration only)
|
||||
* - LCD Touch controller
|
||||
**************************************************************************************************/
|
||||
#define BSP_I2C_NUM CONFIG_BSP_I2C_NUM
|
||||
|
||||
/**
|
||||
* @brief Init I2C driver
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG I2C parameter error
|
||||
* - ESP_FAIL I2C driver installation error
|
||||
*
|
||||
*/
|
||||
esp_err_t bsp_i2c_init(void);
|
||||
|
||||
/**
|
||||
* @brief Deinit I2C driver and free its resources
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG I2C parameter error
|
||||
*
|
||||
*/
|
||||
esp_err_t bsp_i2c_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Get I2C driver handle
|
||||
*
|
||||
* @return
|
||||
* - I2C handle
|
||||
*
|
||||
*/
|
||||
i2c_master_bus_handle_t bsp_i2c_get_handle(void);
|
||||
|
||||
/**************************************************************************************************
|
||||
*
|
||||
* I2S audio interface
|
||||
*
|
||||
* There are two devices connected to the I2S peripheral:
|
||||
* - Codec ES8311 for output(playback) and input(recording) path
|
||||
*
|
||||
* For speaker initialization use bsp_audio_codec_speaker_init() which is inside initialize I2S with bsp_audio_init().
|
||||
* For microphone initialization use bsp_audio_codec_microphone_init() which is inside initialize I2S with bsp_audio_init().
|
||||
* After speaker or microphone initialization, use functions from esp_codec_dev for play/record audio.
|
||||
* Example audio play:
|
||||
* \code{.c}
|
||||
* esp_codec_dev_set_out_vol(spk_codec_dev, DEFAULT_VOLUME);
|
||||
* esp_codec_dev_open(spk_codec_dev, &fs);
|
||||
* esp_codec_dev_write(spk_codec_dev, wav_bytes, bytes_read_from_spiffs);
|
||||
* esp_codec_dev_close(spk_codec_dev);
|
||||
* \endcode
|
||||
**************************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Init audio
|
||||
*
|
||||
* @note There is no deinit audio function. Users can free audio resources by calling i2s_del_channel()
|
||||
* @warning The type of i2s_config param is depending on IDF version.
|
||||
* @param[in] i2s_config I2S configuration. Pass NULL to use default values (Mono, duplex, 16bit, 22050 Hz)
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_NOT_SUPPORTED The communication mode is not supported on the current chip
|
||||
* - ESP_ERR_INVALID_ARG NULL pointer or invalid configuration
|
||||
* - ESP_ERR_NOT_FOUND No available I2S channel found
|
||||
* - ESP_ERR_NO_MEM No memory for storing the channel information
|
||||
* - ESP_ERR_INVALID_STATE This channel has not initialized or already started
|
||||
*/
|
||||
esp_err_t bsp_audio_init(const i2s_std_config_t *i2s_config);
|
||||
|
||||
/**
|
||||
* @brief Initialize speaker codec device
|
||||
*
|
||||
* @return Pointer to codec device handle or NULL when error occurred
|
||||
*/
|
||||
esp_codec_dev_handle_t bsp_audio_codec_speaker_init(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize microphone codec device
|
||||
*
|
||||
* @return Pointer to codec device handle or NULL when error occurred
|
||||
*/
|
||||
esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void);
|
||||
|
||||
/**************************************************************************************************
|
||||
*
|
||||
* SPIFFS
|
||||
*
|
||||
* After mounting the SPIFFS, it can be accessed with stdio functions ie.:
|
||||
* \code{.c}
|
||||
* FILE* f = fopen(BSP_SPIFFS_MOUNT_POINT"/hello.txt", "w");
|
||||
* fprintf(f, "Hello World!\n");
|
||||
* fclose(f);
|
||||
* \endcode
|
||||
**************************************************************************************************/
|
||||
#define BSP_SPIFFS_MOUNT_POINT CONFIG_BSP_SPIFFS_MOUNT_POINT
|
||||
|
||||
/**
|
||||
* @brief Mount SPIFFS to virtual file system
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_spiffs_register was already called
|
||||
* - ESP_ERR_NO_MEM if memory can not be allocated
|
||||
* - ESP_FAIL if partition can not be mounted
|
||||
* - other error codes
|
||||
*/
|
||||
esp_err_t bsp_spiffs_mount(void);
|
||||
|
||||
/**
|
||||
* @brief Unmount SPIFFS from virtual file system
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_NOT_FOUND if the partition table does not contain SPIFFS partition with given label
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_spiffs_unregister was already called
|
||||
* - ESP_ERR_NO_MEM if memory can not be allocated
|
||||
* - ESP_FAIL if partition can not be mounted
|
||||
* - other error codes
|
||||
*/
|
||||
esp_err_t bsp_spiffs_unmount(void);
|
||||
|
||||
/**************************************************************************************************
|
||||
*
|
||||
* uSD card
|
||||
*
|
||||
* After mounting the uSD card, it can be accessed with stdio functions ie.:
|
||||
* \code{.c}
|
||||
* FILE* f = fopen(BSP_MOUNT_POINT"/hello.txt", "w");
|
||||
* fprintf(f, "Hello %s!\n", bsp_sdcard->cid.name);
|
||||
* fclose(f);
|
||||
* \endcode
|
||||
**************************************************************************************************/
|
||||
#define BSP_SD_MOUNT_POINT CONFIG_BSP_SD_MOUNT_POINT
|
||||
extern sdmmc_card_t *bsp_sdcard;
|
||||
|
||||
/**
|
||||
* @brief Mount microSD card to virtual file system
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount was already called
|
||||
* - ESP_ERR_NO_MEM if memory cannot be allocated
|
||||
* - ESP_FAIL if partition cannot be mounted
|
||||
* - other error codes from SDMMC or SPI drivers, SDMMC protocol, or FATFS drivers
|
||||
*/
|
||||
esp_err_t bsp_sdcard_mount(void);
|
||||
|
||||
/**
|
||||
* @brief Unmount microSD card from virtual file system
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_NOT_FOUND if the partition table does not contain FATFS partition with given label
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_fat_spiflash_mount was already called
|
||||
* - ESP_ERR_NO_MEM if memory can not be allocated
|
||||
* - ESP_FAIL if partition can not be mounted
|
||||
* - other error codes from wear levelling library, SPI flash driver, or FATFS drivers
|
||||
*/
|
||||
esp_err_t bsp_sdcard_unmount(void);
|
||||
|
||||
/**************************************************************************************************
|
||||
*
|
||||
* LCD interface
|
||||
*
|
||||
* ESP-BOX is shipped with 2.4inch ST7789 display controller.
|
||||
* It features 16-bit colors, 320x240 resolution and capacitive touch controller.
|
||||
*
|
||||
* LVGL is used as graphics library. LVGL is NOT thread safe, therefore the user must take LVGL mutex
|
||||
* by calling bsp_display_lock() before calling and LVGL API (lv_...) and then give the mutex with
|
||||
* bsp_display_unlock().
|
||||
*
|
||||
* Display's backlight must be enabled explicitly by calling bsp_display_backlight_on()
|
||||
**************************************************************************************************/
|
||||
#define BSP_LCD_PIXEL_CLOCK_MHZ (80)
|
||||
|
||||
#if (BSP_CONFIG_NO_GRAPHIC_LIB == 0)
|
||||
|
||||
#define BSP_LCD_DRAW_BUFF_SIZE (BSP_LCD_H_RES * 50) // Frame buffer size in pixels
|
||||
#define BSP_LCD_DRAW_BUFF_DOUBLE (0)
|
||||
|
||||
/**
|
||||
* @brief BSP display configuration structure
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
lvgl_port_cfg_t lvgl_port_cfg; /*!< LVGL port configuration */
|
||||
uint32_t buffer_size; /*!< Size of the buffer for the screen in pixels */
|
||||
bool double_buffer; /*!< True, if should be allocated two buffers */
|
||||
struct {
|
||||
unsigned int buff_dma: 1; /*!< Allocated LVGL buffer will be DMA capable */
|
||||
unsigned int buff_spiram: 1; /*!< Allocated LVGL buffer will be in PSRAM */
|
||||
unsigned int sw_rotate: 1; /*!< Use software rotation (slower), The feature is unavailable under avoid-tear mode */
|
||||
} flags;
|
||||
} bsp_display_cfg_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize display
|
||||
*
|
||||
* This function initializes SPI, display controller and starts LVGL handling task.
|
||||
* LCD backlight must be enabled separately by calling bsp_display_brightness_set()
|
||||
*
|
||||
* @return Pointer to LVGL display or NULL when error occured
|
||||
*/
|
||||
lv_display_t *bsp_display_start(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize display
|
||||
*
|
||||
* This function initializes SPI, display controller and starts LVGL handling task.
|
||||
* LCD backlight must be enabled separately by calling bsp_display_brightness_set()
|
||||
*
|
||||
* @param cfg display configuration
|
||||
*
|
||||
* @return Pointer to LVGL display or NULL when error occured
|
||||
*/
|
||||
lv_display_t *bsp_display_start_with_config(const bsp_display_cfg_t *cfg);
|
||||
|
||||
/**
|
||||
* @brief Get pointer to input device (touch, buttons, ...)
|
||||
*
|
||||
* @note The LVGL input device is initialized in bsp_display_start() function.
|
||||
*
|
||||
* @return Pointer to LVGL input device or NULL when not initialized
|
||||
*/
|
||||
lv_indev_t *bsp_display_get_input_dev(void);
|
||||
|
||||
/**
|
||||
* @brief Take LVGL mutex
|
||||
*
|
||||
* @param timeout_ms Timeout in [ms]. 0 will block indefinitely.
|
||||
* @return true Mutex was taken
|
||||
* @return false Mutex was NOT taken
|
||||
*/
|
||||
bool bsp_display_lock(uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Give LVGL mutex
|
||||
*
|
||||
*/
|
||||
void bsp_display_unlock(void);
|
||||
|
||||
/**
|
||||
* @brief Rotate screen
|
||||
*
|
||||
* Display must be already initialized by calling bsp_display_start()
|
||||
*
|
||||
* @param[in] disp Pointer to LVGL display
|
||||
* @param[in] rotation Angle of the display rotation
|
||||
*/
|
||||
void bsp_display_rotate(lv_display_t *disp, lv_disp_rotation_t rotation);
|
||||
#endif // BSP_CONFIG_NO_GRAPHIC_LIB == 0
|
||||
|
||||
/**************************************************************************************************
|
||||
*
|
||||
* USB
|
||||
*
|
||||
**************************************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Power modes of USB Host connector
|
||||
*/
|
||||
typedef enum bsp_usb_host_power_mode_t {
|
||||
BSP_USB_HOST_POWER_MODE_USB_DEV, //!< Power from USB DEV port
|
||||
} bsp_usb_host_power_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Start USB host
|
||||
*
|
||||
* This is a one-stop-shop function that will configure the board for USB Host mode
|
||||
* and start USB Host library
|
||||
*
|
||||
* @param[in] mode USB Host connector power mode (Not used on this board)
|
||||
* @param[in] limit_500mA Limit output current to 500mA (Not used on this board)
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_ERR_NO_MEM Memory cannot be allocated
|
||||
*/
|
||||
esp_err_t bsp_usb_host_start(bsp_usb_host_power_mode_t mode, bool limit_500mA);
|
||||
|
||||
/**
|
||||
* @brief Stop USB host
|
||||
*
|
||||
* USB Host lib will be uninstalled and power from connector removed.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t bsp_usb_host_stop(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "esp_lcd_touch.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief BSP touch configuration structure
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
void *dummy; /*!< Prepared for future use. */
|
||||
} bsp_touch_config_t;
|
||||
|
||||
/**
|
||||
* @brief Create new touchscreen
|
||||
*
|
||||
* If you want to free resources allocated by this function, you can use esp_lcd_touch API, ie.:
|
||||
*
|
||||
* \code{.c}
|
||||
* esp_lcd_touch_del(tp);
|
||||
* \endcode
|
||||
*
|
||||
* @param[in] config touch configuration
|
||||
* @param[out] ret_touch esp_lcd_touch touchscreen handle
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Else esp_lcd_touch failure
|
||||
*/
|
||||
esp_err_t bsp_touch_new(const bsp_touch_config_t *config, esp_lcd_touch_handle_t *ret_touch);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "esp_check.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Assert on error, if selected in menuconfig. Otherwise return error code. */
|
||||
#if CONFIG_BSP_ERROR_CHECK
|
||||
#define BSP_ERROR_CHECK_RETURN_ERR(x) ESP_ERROR_CHECK(x)
|
||||
#define BSP_ERROR_CHECK_RETURN_NULL(x) ESP_ERROR_CHECK(x)
|
||||
#define BSP_ERROR_CHECK(x, ret) ESP_ERROR_CHECK(x)
|
||||
#define BSP_NULL_CHECK(x, ret) assert(x)
|
||||
#define BSP_NULL_CHECK_GOTO(x, goto_tag) assert(x)
|
||||
#else
|
||||
#define BSP_ERROR_CHECK_RETURN_ERR(x) do { \
|
||||
esp_err_t err_rc_ = (x); \
|
||||
if (unlikely(err_rc_ != ESP_OK)) { \
|
||||
return err_rc_; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define BSP_ERROR_CHECK_RETURN_NULL(x) do { \
|
||||
if (unlikely((x) != ESP_OK)) { \
|
||||
return NULL; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define BSP_NULL_CHECK(x, ret) do { \
|
||||
if ((x) == NULL) { \
|
||||
return ret; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define BSP_ERROR_CHECK(x, ret) do { \
|
||||
if (unlikely((x) != ESP_OK)) { \
|
||||
return ret; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define BSP_NULL_CHECK_GOTO(x, goto_tag) do { \
|
||||
if ((x) == NULL) { \
|
||||
goto goto_tag; \
|
||||
} \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,404 @@
|
||||
dependencies:
|
||||
chmorgan/esp-audio-player:
|
||||
component_hash: c8ac1998e9af863bc41b57e592f88d1a5791a0f891485122336ddabbf7a65033
|
||||
dependencies:
|
||||
- name: chmorgan/esp-libhelix-mp3
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: '>=1.0.0,<2.0.0'
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.0'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
version: 1.0.7
|
||||
chmorgan/esp-file-iterator:
|
||||
component_hash: 327091394b9ef5c2cd395a960ab70ae64479e0a8831cbd9925e38895fad93719
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=4.1.0'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
version: 1.0.0
|
||||
chmorgan/esp-libhelix-mp3:
|
||||
component_hash: cbb76089dc2c5749f7b470e2e70aedc44c9da519e04eb9a67d4c7ec275229e53
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=4.1.0'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
version: 1.0.3
|
||||
esp_lcd_touch_gsl3680:
|
||||
dependencies:
|
||||
- name: espressif/esp_lcd_touch
|
||||
public: true
|
||||
version: ^1.1.0
|
||||
source:
|
||||
path: /home/jczn/esp/P4M3/test/components/esp_lcd_touch_gsl3680
|
||||
type: local
|
||||
version: '*'
|
||||
espressif/cmake_utilities:
|
||||
component_hash: 351350613ceafba240b761b4ea991e0f231ac7a9f59a9ee901f751bddc0bb18f
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=4.1'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
version: 0.5.3
|
||||
espressif/eppp_link:
|
||||
component_hash: f82b41b83936cb99b01129c0aec5ebf39c4bbff252bea400062d8bc4e7b83e20
|
||||
dependencies:
|
||||
- name: espressif/esp_serial_slave_link
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: ^1.1.0
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.2'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
version: 0.3.1
|
||||
espressif/esp_cam_sensor:
|
||||
component_hash: f5873378a3a547e46e831736cbbbaf519a80fdd4ac24e5e5bcd00122d587c3d0
|
||||
dependencies:
|
||||
- name: espressif/cmake_utilities
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: 0.*
|
||||
- name: espressif/esp_sccb_intf
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: '>=0.0.2'
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.3'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
targets:
|
||||
- esp32p4
|
||||
version: 1.0.0
|
||||
espressif/esp_codec_dev:
|
||||
component_hash: 014948481bda426cd46714f297fe1891711246c62bea288863a8cc8cf13ef1f0
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=4.0'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
version: 1.2.0
|
||||
espressif/esp_h264:
|
||||
component_hash: fa5daaebc8a304f0b79bc57e51aab43e0a03eabc2ba3865bff4063c56b5d4564
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=4.4'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
version: 1.0.4
|
||||
espressif/esp_hosted:
|
||||
component_hash: ba380b52c57e1adfb384591dd8ad85ebc7fce6f990741c403af2ea06c33f3371
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.3'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
version: 2.0.10
|
||||
espressif/esp_ipa:
|
||||
component_hash: 854ba797f5cd5a49b739e2126287683605ed68f474a3a931b32d56dee2353d59
|
||||
dependencies:
|
||||
- name: espressif/cmake_utilities
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: 0.*
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.4'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
targets:
|
||||
- esp32p4
|
||||
version: 0.3.0~1
|
||||
espressif/esp_lcd_touch:
|
||||
component_hash: 779b4ba2464a3ae85681e4b860caa5fdc35801458c23f3039ee761bae7f442a4
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=4.4.2'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
version: 1.1.2
|
||||
espressif/esp_lcd_touch_gt911:
|
||||
component_hash: acc1c184358aa29ef72506f618c9c76a8cc2bf12af38a2bff3d44d84f3a08857
|
||||
dependencies:
|
||||
- name: espressif/esp_lcd_touch
|
||||
registry_url: https://components.espressif.com
|
||||
require: public
|
||||
version: ^1.1.0
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=4.4.2'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
version: 1.1.3
|
||||
espressif/esp_lvgl_port:
|
||||
component_hash: e720c95cf0667554a204591bb5fade4655fb2990465557041200fa44b5bc7556
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=4.4'
|
||||
- name: lvgl/lvgl
|
||||
registry_url: https://components.espressif.com
|
||||
require: public
|
||||
version: '>=8,<10'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
version: 2.6.0
|
||||
espressif/esp_sccb_intf:
|
||||
component_hash: 71e3def402f6193a23c599bdde4fa0b544ca2b1f63608b6d0ec2bee3cd9a1c33
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.3'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
version: 0.0.5
|
||||
espressif/esp_serial_slave_link:
|
||||
component_hash: 8c534b7d4986ca0e4c41db71f559492b795ab862f1d15359d7993034696b7bcc
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.0'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
version: 1.1.0
|
||||
espressif/esp_video:
|
||||
component_hash: 9731bd1c7b54cf54829800f049d058fc0907493867b0373bcd2d23852a305b14
|
||||
dependencies:
|
||||
- name: espressif/cmake_utilities
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: 0.*
|
||||
- name: espressif/esp_cam_sensor
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: 1.0.*
|
||||
- name: espressif/esp_h264
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: 1.0.4
|
||||
- name: espressif/esp_ipa
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: 0.3.*
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.4'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
targets:
|
||||
- esp32p4
|
||||
version: 0.9.1
|
||||
espressif/esp_wifi_remote:
|
||||
component_hash: cb5d6fe638e2a1363bbae086c3b65ac6d4704151f982872989f0020e43aa84a8
|
||||
dependencies:
|
||||
- name: espressif/eppp_link
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: '>=0.1'
|
||||
- name: espressif/esp_hosted
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
rules:
|
||||
- if: target in [esp32h2, esp32p4]
|
||||
version: '>=0.0.6'
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.3'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
version: 0.12.1
|
||||
espressif/i2c_bus:
|
||||
component_hash: e3dddc78baa172f4768f3973fbecbd6c6c1f2cb23cc6a36cf3132758be092482
|
||||
dependencies:
|
||||
- name: espressif/cmake_utilities
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: 0.*
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=4.0'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
version: 1.4.0
|
||||
idf:
|
||||
source:
|
||||
type: idf
|
||||
version: 6.0.0
|
||||
lvgl/lvgl:
|
||||
component_hash: d7c1ac037ae6e85d94897f807d6e7ba0946a83e720074fc95a4f6241da9f9f53
|
||||
dependencies: []
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
version: 8.4.0
|
||||
waveshare/esp32_p4_nano:
|
||||
component_hash: 1dfd3c5ba9e921e437a4116a5a61b7be985a24720d9d610effa59f22268f6683
|
||||
dependencies:
|
||||
- name: espressif/esp_codec_dev
|
||||
registry_url: https://components.espressif.com
|
||||
require: public
|
||||
version: 1.2.*
|
||||
- name: espressif/esp_lcd_touch_gt911
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: ^1
|
||||
- name: espressif/esp_lvgl_port
|
||||
registry_url: https://components.espressif.com
|
||||
require: public
|
||||
version: ^2
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.3'
|
||||
- name: lvgl/lvgl
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: '>=8,<10'
|
||||
- name: waveshare/esp_lcd_dsi
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: '*'
|
||||
- name: waveshare/esp_lcd_ili9881c
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: '*'
|
||||
- name: waveshare/esp_lcd_jd9365_10_1
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: '*'
|
||||
- name: waveshare/esp_lcd_jd9365_8
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: '*'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
targets:
|
||||
- esp32p4
|
||||
version: 1.1.5
|
||||
waveshare/esp_lcd_dsi:
|
||||
component_hash: 941c9d83db221182e8547d144c17139715fb41ba2abdbec45319595eaf59ee3e
|
||||
dependencies:
|
||||
- name: espressif/cmake_utilities
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: 0.*
|
||||
- name: espressif/i2c_bus
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: ^1.3.0
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.3'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
targets:
|
||||
- esp32p4
|
||||
version: 1.0.6
|
||||
waveshare/esp_lcd_ili9881c:
|
||||
component_hash: a1e89e1ec8d9ec15b0b6a65ea831d8c7a3c4796c2a32a13404faad126f00fb3c
|
||||
dependencies:
|
||||
- name: espressif/cmake_utilities
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: 0.*
|
||||
- name: espressif/i2c_bus
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: ^1.3.0
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.3'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
targets:
|
||||
- esp32p4
|
||||
version: 1.0.3
|
||||
waveshare/esp_lcd_jd9365_10_1:
|
||||
component_hash: 148d03ade699a7fa0f08c98e86c1df3d32e92580fac421c04e0ee5b779e86267
|
||||
dependencies:
|
||||
- name: espressif/cmake_utilities
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: 0.*
|
||||
- name: espressif/i2c_bus
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: ^1.3.0
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.3'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
targets:
|
||||
- esp32p4
|
||||
version: 1.0.3
|
||||
waveshare/esp_lcd_jd9365_8:
|
||||
component_hash: 04fc57f3a756e5734c4dfe347c62a06a719a7ba4d60fff4066943b9391c764b5
|
||||
dependencies:
|
||||
- name: espressif/cmake_utilities
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: 0.*
|
||||
- name: espressif/i2c_bus
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: ^1.3.0
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.3'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
targets:
|
||||
- esp32p4
|
||||
version: 1.0.4
|
||||
direct_dependencies:
|
||||
- chmorgan/esp-audio-player
|
||||
- chmorgan/esp-file-iterator
|
||||
- esp_lcd_touch_gsl3680
|
||||
- espressif/esp_hosted
|
||||
- espressif/esp_ipa
|
||||
- espressif/esp_lcd_touch
|
||||
- espressif/esp_video
|
||||
- espressif/esp_wifi_remote
|
||||
- idf
|
||||
- lvgl/lvgl
|
||||
- waveshare/esp32_p4_nano
|
||||
manifest_hash: 9a7139e5b8f8bf9359b371172159f3a855fdd782841bfc19b4de8254706f9f3e
|
||||
target: esp32p4
|
||||
version: 2.0.0
|
||||
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "app_camera.c" "test.c" "app_enthernet.c"
|
||||
INCLUDE_DIRS "." "include")
|
||||
@@ -0,0 +1,176 @@
|
||||
menu "Example EthToAP Configuration"
|
||||
|
||||
config EXAMPLE_WIFI_SSID
|
||||
string "Wi-Fi SSID"
|
||||
default "eth2ap"
|
||||
help
|
||||
Set the SSID of Wi-Fi ap interface.
|
||||
|
||||
config EXAMPLE_WIFI_PASSWORD
|
||||
string "Wi-Fi Password"
|
||||
default "12345678"
|
||||
help
|
||||
Set the password of Wi-Fi ap interface.
|
||||
|
||||
config EXAMPLE_WIFI_CHANNEL
|
||||
int "WiFi channel"
|
||||
range 1 13
|
||||
default 1
|
||||
help
|
||||
Set the channel of Wi-Fi ap.
|
||||
|
||||
config EXAMPLE_MAX_STA_CONN
|
||||
int "Maximum STA connections"
|
||||
default 4
|
||||
help
|
||||
Maximum number of the station that allowed to connect to current Wi-Fi hotspot.
|
||||
|
||||
endmenu
|
||||
|
||||
menu "Example CAM Configuration"
|
||||
|
||||
config EXAMPLE_ENABLE_MIPI_CSI_CAM_SENSOR
|
||||
bool "Enable MIPI CSI Camera Sensor"
|
||||
default y
|
||||
depends on ESP_VIDEO_ENABLE_MIPI_CSI_VIDEO_DEVICE
|
||||
|
||||
if EXAMPLE_ENABLE_MIPI_CSI_CAM_SENSOR
|
||||
config EXAMPLE_MIPI_CSI_SCCB_I2C_PORT
|
||||
int "MIPI CSI SCCB I2C Port Number"
|
||||
default 0
|
||||
range 0 1
|
||||
|
||||
config EXAMPLE_MIPI_CSI_SCCB_I2C_SCL_PIN
|
||||
int "MIPI CSI SCCB I2C SCL Pin"
|
||||
default 8
|
||||
range -1 56
|
||||
|
||||
config EXAMPLE_MIPI_CSI_SCCB_I2C_SDA_PIN
|
||||
int "MIPI CSI SCCB I2C SDA Pin"
|
||||
default 7
|
||||
range -1 56
|
||||
|
||||
config EXAMPLE_MIPI_CSI_SCCB_I2C_FREQ
|
||||
int "MIPI CSI SCCB I2C Frequency"
|
||||
default 100000
|
||||
range 100000 400000
|
||||
help
|
||||
Increasing this value can reduce the initialization time of the camera sensor.
|
||||
Please refer to the relevant instructions of the camera sensor to adjust the value.
|
||||
|
||||
config EXAMPLE_MIPI_CSI_CAM_SENSOR_RESET_PIN
|
||||
int "MIPI CSI Camera Sensor Reset Pin"
|
||||
default -1
|
||||
range -1 56
|
||||
|
||||
config EXAMPLE_MIPI_CSI_CAM_SENSOR_PWDN_PIN
|
||||
int "MIPI CSI Camera Sensor Power Down Pin"
|
||||
default -1
|
||||
range -1 56
|
||||
endif
|
||||
|
||||
config EXAMPLE_ENABLE_DVP_CAM_SENSOR
|
||||
bool "Enable DVP Camera Sensor"
|
||||
default n
|
||||
depends on ESP_VIDEO_ENABLE_DVP_VIDEO_DEVICE
|
||||
|
||||
if EXAMPLE_ENABLE_DVP_CAM_SENSOR
|
||||
config EXAMPLE_DVP_SCCB_I2C_PORT
|
||||
int "DVP SCCB I2C Port Number"
|
||||
default 1
|
||||
range 0 1
|
||||
|
||||
config EXAMPLE_DVP_SCCB_I2C_SCL_PIN
|
||||
int "DVP SCCB I2C SCL Pin"
|
||||
default 33
|
||||
range -1 56
|
||||
|
||||
config EXAMPLE_DVP_SCCB_I2C_SDA_PIN
|
||||
int "DVP SCCB I2C SDA Pin"
|
||||
default 32
|
||||
range -1 56
|
||||
|
||||
config EXAMPLE_DVP_SCCB_I2C_FREQ
|
||||
int "DVP SCCB I2C Frequency"
|
||||
default 100000
|
||||
range 100000 400000
|
||||
help
|
||||
Increasing this value can reduce the initialization time of the camera sensor.
|
||||
Please refer to the relevant instructions of the camera sensor to adjust the value.
|
||||
|
||||
config EXAMPLE_DVP_CAM_SENSOR_RESET_PIN
|
||||
int "DVP Camera Sensor Reset Pin"
|
||||
default -1
|
||||
range -1 56
|
||||
|
||||
config EXAMPLE_DVP_CAM_SENSOR_PWDN_PIN
|
||||
int "DVP Camera Sensor Power Down Pin"
|
||||
default -1
|
||||
range -1 56
|
||||
|
||||
config EXAMPLE_DVP_XCLK_FREQ
|
||||
int "DVP XCLK Frequency"
|
||||
default 20000000
|
||||
|
||||
config EXAMPLE_DVP_XCLK_PIN
|
||||
int "DVP XCLK Pin"
|
||||
range 0 56
|
||||
default 20
|
||||
|
||||
config EXAMPLE_DVP_PCLK_PIN
|
||||
int "DVP PCLK Pin"
|
||||
range 0 56
|
||||
default 21
|
||||
|
||||
config EXAMPLE_DVP_VSYNC_PIN
|
||||
int "DVP VSYNC Pin"
|
||||
range 0 56
|
||||
default 23
|
||||
|
||||
config EXAMPLE_DVP_DE_PIN
|
||||
int "DVP DE Pin"
|
||||
range 0 56
|
||||
default 22
|
||||
|
||||
config EXAMPLE_DVP_D0_PIN
|
||||
int "DVP D0 Pin"
|
||||
range 0 56
|
||||
default 53
|
||||
|
||||
config EXAMPLE_DVP_D1_PIN
|
||||
int "DVP D1 Pin"
|
||||
range 0 56
|
||||
default 54
|
||||
|
||||
config EXAMPLE_DVP_D2_PIN
|
||||
int "DVP D2 Pin"
|
||||
range 0 56
|
||||
default 52
|
||||
|
||||
config EXAMPLE_DVP_D3_PIN
|
||||
int "DVP D3 Pin"
|
||||
range 0 56
|
||||
default 1
|
||||
|
||||
config EXAMPLE_DVP_D4_PIN
|
||||
int "DVP D4 Pin"
|
||||
range 0 56
|
||||
default 0
|
||||
|
||||
config EXAMPLE_DVP_D5_PIN
|
||||
int "DVP D5 Pin"
|
||||
range 0 56
|
||||
default 45
|
||||
|
||||
config EXAMPLE_DVP_D6_PIN
|
||||
int "DVP D6 Pin"
|
||||
range 0 56
|
||||
default 46
|
||||
|
||||
config EXAMPLE_DVP_D7_PIN
|
||||
int "DVP D7 Pin"
|
||||
range 0 56
|
||||
default 47
|
||||
endif
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: ESPRESSIF MIT
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/errno.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
#include "driver/i2c_master.h"
|
||||
#include "linux/videodev2.h"
|
||||
#include "esp_video_init.h"
|
||||
#include "esp_video_ioctl.h"
|
||||
#include "app_camera.h"
|
||||
|
||||
#define MEMORY_TYPE V4L2_MEMORY_MMAP
|
||||
#define BUFFER_COUNT 2
|
||||
#define CAPTURE_SECONDS 3
|
||||
|
||||
static i2c_master_bus_handle_t i2c_handle = NULL;
|
||||
|
||||
static const char *TAG = "example";
|
||||
|
||||
#if CONFIG_EXAMPLE_ENABLE_MIPI_CSI_CAM_SENSOR
|
||||
static esp_video_init_csi_config_t csi_config[] = {
|
||||
{
|
||||
.sccb_config = {
|
||||
.init_sccb = true,
|
||||
.i2c_config = {
|
||||
.port = CONFIG_EXAMPLE_MIPI_CSI_SCCB_I2C_PORT,
|
||||
.scl_pin = CONFIG_EXAMPLE_MIPI_CSI_SCCB_I2C_SCL_PIN,
|
||||
.sda_pin = CONFIG_EXAMPLE_MIPI_CSI_SCCB_I2C_SDA_PIN,
|
||||
},
|
||||
.freq = CONFIG_EXAMPLE_MIPI_CSI_SCCB_I2C_FREQ,
|
||||
},
|
||||
.reset_pin = CONFIG_EXAMPLE_MIPI_CSI_CAM_SENSOR_RESET_PIN,
|
||||
.pwdn_pin = CONFIG_EXAMPLE_MIPI_CSI_CAM_SENSOR_PWDN_PIN,
|
||||
},
|
||||
};
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_ENABLE_DVP_CAM_SENSOR
|
||||
static const esp_video_init_dvp_config_t dvp_config[] = {
|
||||
{
|
||||
.sccb_config = {
|
||||
.init_sccb = true,
|
||||
.i2c_config = {
|
||||
.port = CONFIG_EXAMPLE_DVP_SCCB_I2C_PORT,
|
||||
.scl_pin = CONFIG_EXAMPLE_DVP_SCCB_I2C_SCL_PIN,
|
||||
.sda_pin = CONFIG_EXAMPLE_DVP_SCCB_I2C_SDA_PIN,
|
||||
},
|
||||
.freq = CONFIG_EXAMPLE_DVP_SCCB_I2C_FREQ,
|
||||
},
|
||||
.reset_pin = CONFIG_EXAMPLE_DVP_CAM_SENSOR_RESET_PIN,
|
||||
.pwdn_pin = CONFIG_EXAMPLE_DVP_CAM_SENSOR_PWDN_PIN,
|
||||
.dvp_pin = {
|
||||
.data_width = CAM_CTLR_DATA_WIDTH_8,
|
||||
.data_io = {
|
||||
CONFIG_EXAMPLE_DVP_D0_PIN, CONFIG_EXAMPLE_DVP_D1_PIN, CONFIG_EXAMPLE_DVP_D2_PIN, CONFIG_EXAMPLE_DVP_D3_PIN,
|
||||
CONFIG_EXAMPLE_DVP_D4_PIN, CONFIG_EXAMPLE_DVP_D5_PIN, CONFIG_EXAMPLE_DVP_D6_PIN, CONFIG_EXAMPLE_DVP_D7_PIN,
|
||||
},
|
||||
.vsync_io = CONFIG_EXAMPLE_DVP_VSYNC_PIN,
|
||||
.de_io = CONFIG_EXAMPLE_DVP_DE_PIN,
|
||||
.pclk_io = CONFIG_EXAMPLE_DVP_PCLK_PIN,
|
||||
.xclk_io = CONFIG_EXAMPLE_DVP_XCLK_PIN,
|
||||
},
|
||||
.xclk_freq = CONFIG_EXAMPLE_DVP_XCLK_FREQ,
|
||||
},
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static esp_err_t camera_capture_stream(void)
|
||||
{
|
||||
int fd;
|
||||
esp_err_t ret;
|
||||
int fmt_index = 0;
|
||||
uint32_t frame_size;
|
||||
uint32_t frame_count;
|
||||
struct v4l2_buffer buf;
|
||||
uint8_t *buffer[BUFFER_COUNT];
|
||||
struct v4l2_format init_format;
|
||||
struct v4l2_requestbuffers req;
|
||||
struct v4l2_capability capability;
|
||||
|
||||
const int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
|
||||
fd = open("/dev/video0", O_RDONLY);
|
||||
if (fd < 0) {
|
||||
ESP_LOGE(TAG, "failed to open device");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
if (ioctl(fd, VIDIOC_QUERYCAP, &capability)) {
|
||||
ESP_LOGE(TAG, "failed to get capability");
|
||||
ret = ESP_FAIL;
|
||||
goto exit_0;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "version: %d.%d.%d", (uint16_t)(capability.version >> 16),
|
||||
(uint8_t)(capability.version >> 8),
|
||||
(uint8_t)capability.version);
|
||||
ESP_LOGI(TAG, "driver: %s", capability.driver);
|
||||
ESP_LOGI(TAG, "card: %s", capability.card);
|
||||
ESP_LOGI(TAG, "bus: %s", capability.bus_info);
|
||||
ESP_LOGI(TAG, "capabilities:");
|
||||
if (capability.capabilities & V4L2_CAP_VIDEO_CAPTURE) {
|
||||
ESP_LOGI(TAG, "\tVIDEO_CAPTURE");
|
||||
}
|
||||
if (capability.capabilities & V4L2_CAP_READWRITE) {
|
||||
ESP_LOGI(TAG, "\tREADWRITE");
|
||||
}
|
||||
if (capability.capabilities & V4L2_CAP_ASYNCIO) {
|
||||
ESP_LOGI(TAG, "\tASYNCIO");
|
||||
}
|
||||
if (capability.capabilities & V4L2_CAP_STREAMING) {
|
||||
ESP_LOGI(TAG, "\tSTREAMING");
|
||||
}
|
||||
if (capability.capabilities & V4L2_CAP_META_OUTPUT) {
|
||||
ESP_LOGI(TAG, "\tMETA_OUTPUT");
|
||||
}
|
||||
if (capability.capabilities & V4L2_CAP_DEVICE_CAPS) {
|
||||
ESP_LOGI(TAG, "device capabilities:");
|
||||
if (capability.device_caps & V4L2_CAP_VIDEO_CAPTURE) {
|
||||
ESP_LOGI(TAG, "\tVIDEO_CAPTURE");
|
||||
}
|
||||
if (capability.device_caps & V4L2_CAP_READWRITE) {
|
||||
ESP_LOGI(TAG, "\tREADWRITE");
|
||||
}
|
||||
if (capability.device_caps & V4L2_CAP_ASYNCIO) {
|
||||
ESP_LOGI(TAG, "\tASYNCIO");
|
||||
}
|
||||
if (capability.device_caps & V4L2_CAP_STREAMING) {
|
||||
ESP_LOGI(TAG, "\tSTREAMING");
|
||||
}
|
||||
if (capability.device_caps & V4L2_CAP_META_OUTPUT) {
|
||||
ESP_LOGI(TAG, "\tMETA_OUTPUT");
|
||||
}
|
||||
}
|
||||
|
||||
/* Set custom register configuration */
|
||||
if (ioctl(fd, VIDIOC_S_SENSOR_FMT, &custom_format_info) != 0) {
|
||||
ret = ESP_FAIL;
|
||||
goto exit_0;
|
||||
}
|
||||
|
||||
memset(&init_format, 0, sizeof(struct v4l2_format));
|
||||
init_format.type = type;
|
||||
if (ioctl(fd, VIDIOC_G_FMT, &init_format) != 0) {
|
||||
ESP_LOGE(TAG, "failed to get format");
|
||||
ret = ESP_FAIL;
|
||||
goto exit_0;
|
||||
}
|
||||
|
||||
struct v4l2_fmtdesc fmtdesc = {
|
||||
.index = fmt_index++,
|
||||
.type = type,
|
||||
};
|
||||
|
||||
ESP_LOGI(TAG, "Capture %s format frames for %d seconds:", (char *)fmtdesc.description, CAPTURE_SECONDS);
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.count = BUFFER_COUNT;
|
||||
req.type = type;
|
||||
req.memory = MEMORY_TYPE;
|
||||
if (ioctl(fd, VIDIOC_REQBUFS, &req) != 0) {
|
||||
ESP_LOGE(TAG, "failed to require buffer");
|
||||
ret = ESP_FAIL;
|
||||
goto exit_0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < BUFFER_COUNT; i++) {
|
||||
struct v4l2_buffer buf;
|
||||
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
buf.type = type;
|
||||
buf.memory = MEMORY_TYPE;
|
||||
buf.index = i;
|
||||
if (ioctl(fd, VIDIOC_QUERYBUF, &buf) != 0) {
|
||||
ESP_LOGE(TAG, "failed to query buffer");
|
||||
ret = ESP_FAIL;
|
||||
goto exit_0;
|
||||
}
|
||||
|
||||
buffer[i] = (uint8_t *)mmap(NULL, buf.length, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED, fd, buf.m.offset);
|
||||
if (!buffer[i]) {
|
||||
ESP_LOGE(TAG, "failed to map buffer");
|
||||
ret = ESP_FAIL;
|
||||
goto exit_0;
|
||||
}
|
||||
|
||||
if (ioctl(fd, VIDIOC_QBUF, &buf) != 0) {
|
||||
ESP_LOGE(TAG, "failed to queue video frame");
|
||||
ret = ESP_FAIL;
|
||||
goto exit_0;
|
||||
}
|
||||
}
|
||||
|
||||
if (ioctl(fd, VIDIOC_STREAMON, &type) != 0) {
|
||||
ESP_LOGE(TAG, "failed to start stream");
|
||||
ret = ESP_FAIL;
|
||||
goto exit_0;
|
||||
}
|
||||
|
||||
frame_count = 0;
|
||||
frame_size = 0;
|
||||
int64_t start_time_us = esp_timer_get_time();
|
||||
while (esp_timer_get_time() - start_time_us < (CAPTURE_SECONDS * 1000 * 1000)) {
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
buf.type = type;
|
||||
buf.memory = MEMORY_TYPE;
|
||||
if (ioctl(fd, VIDIOC_DQBUF, &buf) != 0) {
|
||||
ESP_LOGE(TAG, "failed to receive video frame");
|
||||
ret = ESP_FAIL;
|
||||
goto exit_0;
|
||||
}
|
||||
|
||||
frame_size += buf.bytesused;
|
||||
|
||||
if (ioctl(fd, VIDIOC_QBUF, &buf) != 0) {
|
||||
ESP_LOGE(TAG, "failed to queue video frame");
|
||||
ret = ESP_FAIL;
|
||||
goto exit_0;
|
||||
}
|
||||
|
||||
frame_count++;
|
||||
}
|
||||
|
||||
if (ioctl(fd, VIDIOC_STREAMOFF, &type) != 0) {
|
||||
ESP_LOGE(TAG, "failed to stop stream");
|
||||
ret = ESP_FAIL;
|
||||
goto exit_0;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "\twidth: %" PRIu32, init_format.fmt.pix.width);
|
||||
ESP_LOGI(TAG, "\theight: %" PRIu32, init_format.fmt.pix.height);
|
||||
ESP_LOGI(TAG, "\tsize: %" PRIu32, frame_size / frame_count);
|
||||
ESP_LOGI(TAG, "\tFPS: %" PRIu32, frame_count / CAPTURE_SECONDS);
|
||||
|
||||
// bsp_display_lock(0);
|
||||
// lv_label_ins_text(label,LV_LABEL_POS_LAST,"Camera initial #00ff00 Success#\n");
|
||||
// bsp_display_unlock();
|
||||
ret = ESP_OK;
|
||||
|
||||
exit_0:
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void app_camera(void)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
i2c_master_get_bus_handle(1, &i2c_handle);
|
||||
csi_config[0].sccb_config.init_sccb = false;
|
||||
csi_config[0].sccb_config.i2c_handle = i2c_handle;
|
||||
|
||||
static const esp_video_init_config_t cam_config = {
|
||||
.csi = csi_config,
|
||||
};
|
||||
|
||||
ret = esp_video_init(&cam_config);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Camera init failed with error 0x%x", ret);
|
||||
// bsp_display_lock(0);
|
||||
// lv_label_ins_text(label,LV_LABEL_POS_LAST,"Camera initial #ff0000 Failed#\n");
|
||||
// bsp_display_unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
ret = camera_capture_stream();
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Camera capture stream failed with error 0x%x", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
/* eth2ap (Ethernet to Wi-Fi AP packet forwarding) Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_eth_driver.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_private/wifi.h"
|
||||
#include "ethernet_init.h"
|
||||
#include "app_enthernet.h"
|
||||
|
||||
static void wifi_scan_init(void);
|
||||
|
||||
|
||||
static const char *TAG = "eth2ap_example";
|
||||
static esp_eth_handle_t s_eth_handle = NULL;
|
||||
static QueueHandle_t flow_control_queue = NULL;
|
||||
static EventGroupHandle_t Btn_event_group = NULL;
|
||||
static bool s_sta_is_connected = false;
|
||||
static bool s_ethernet_is_connected = false;
|
||||
static uint8_t s_eth_mac[6];
|
||||
|
||||
|
||||
static bool enthernet_connect = false;
|
||||
static bool wifi_connect = false;
|
||||
|
||||
#define FLOW_CONTROL_QUEUE_TIMEOUT_MS (100)
|
||||
#define FLOW_CONTROL_QUEUE_LENGTH (40)
|
||||
#define FLOW_CONTROL_WIFI_SEND_TIMEOUT_MS (100)
|
||||
|
||||
typedef struct {
|
||||
void *packet;
|
||||
uint16_t length;
|
||||
} flow_control_msg_t;
|
||||
|
||||
typedef enum{
|
||||
ETHERNET_CONNECTED = BIT(0),
|
||||
ETHERNET_START = BIT(1),
|
||||
}event_id_t;
|
||||
|
||||
// Forward packets from Wi-Fi to Ethernet
|
||||
static esp_err_t pkt_wifi2eth(void *buffer, uint16_t len, void *eb)
|
||||
{
|
||||
if (s_ethernet_is_connected) {
|
||||
if (esp_eth_transmit(s_eth_handle, buffer, len) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Ethernet send packet failed");
|
||||
}
|
||||
}
|
||||
esp_wifi_internal_free_rx_buffer(eb);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
// Forward packets from Ethernet to Wi-Fi
|
||||
// Note that, Ethernet works faster than Wi-Fi on ESP32,
|
||||
// so we need to add an extra queue to balance their speed difference.
|
||||
static esp_err_t pkt_eth2wifi(esp_eth_handle_t eth_handle, uint8_t *buffer, uint32_t len, void *priv)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
flow_control_msg_t msg = {
|
||||
.packet = buffer,
|
||||
.length = len
|
||||
};
|
||||
if (xQueueSend(flow_control_queue, &msg, pdMS_TO_TICKS(FLOW_CONTROL_QUEUE_TIMEOUT_MS)) != pdTRUE) {
|
||||
ESP_LOGE(TAG, "send flow control message failed or timeout");
|
||||
free(buffer);
|
||||
ret = ESP_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// This task will fetch the packet from the queue, and then send out through Wi-Fi.
|
||||
// Wi-Fi handles packets slower than Ethernet, we might add some delay between each transmitting.
|
||||
static void eth2wifi_flow_control_task(void *args)
|
||||
{
|
||||
flow_control_msg_t msg;
|
||||
int res = 0;
|
||||
uint32_t timeout = 0;
|
||||
while (1) {
|
||||
if (xQueueReceive(flow_control_queue, &msg, pdMS_TO_TICKS(FLOW_CONTROL_QUEUE_TIMEOUT_MS)) == pdTRUE) {
|
||||
timeout = 0;
|
||||
if (s_sta_is_connected && msg.length) {
|
||||
do {
|
||||
vTaskDelay(pdMS_TO_TICKS(timeout));
|
||||
timeout += 2;
|
||||
res = esp_wifi_internal_tx(WIFI_IF_AP, msg.packet, msg.length);
|
||||
} while (res && timeout < FLOW_CONTROL_WIFI_SEND_TIMEOUT_MS);
|
||||
if (res != ESP_OK) {
|
||||
ESP_LOGE(TAG, "WiFi send packet failed: %d", res);
|
||||
}
|
||||
}
|
||||
free(msg.packet);
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
// Event handler for Ethernet
|
||||
static void eth_event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
switch (event_id) {
|
||||
case ETHERNET_EVENT_CONNECTED:
|
||||
ESP_LOGI(TAG, "Ethernet Link Up");
|
||||
s_ethernet_is_connected = true;
|
||||
xEventGroupSetBits(Btn_event_group,ETHERNET_CONNECTED);
|
||||
// esp_eth_ioctl(s_eth_handle, ETH_CMD_G_MAC_ADDR, s_eth_mac);
|
||||
// esp_wifi_set_mac(WIFI_IF_AP, s_eth_mac);
|
||||
// ESP_ERROR_CHECK(esp_wifi_start());
|
||||
bsp_display_lock(0);
|
||||
lv_label_ins_text(label,LV_LABEL_POS_LAST,"Enthernet initial success\n");
|
||||
// lv_label_ins_text(label,LV_LABEL_POS_LAST,"WIFI initial success\n");
|
||||
bsp_display_unlock();
|
||||
|
||||
break;
|
||||
case ETHERNET_EVENT_DISCONNECTED:
|
||||
ESP_LOGI(TAG, "Ethernet Link Down");
|
||||
s_ethernet_is_connected = false;
|
||||
// ESP_ERROR_CHECK(esp_wifi_stop());
|
||||
break;
|
||||
case ETHERNET_EVENT_START:
|
||||
ESP_LOGI(TAG, "Ethernet Started");
|
||||
break;
|
||||
case ETHERNET_EVENT_STOP:
|
||||
ESP_LOGI(TAG, "Ethernet Stopped");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Event handler for Wi-Fi
|
||||
static void wifi_event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
static uint8_t s_con_cnt = 0;
|
||||
switch (event_id) {
|
||||
case WIFI_EVENT_AP_STACONNECTED:
|
||||
ESP_LOGI(TAG, "Wi-Fi AP got a station connected");
|
||||
if (!s_con_cnt) {
|
||||
s_sta_is_connected = true;
|
||||
esp_wifi_internal_reg_rxcb(WIFI_IF_AP, pkt_wifi2eth);
|
||||
}
|
||||
s_con_cnt++;
|
||||
break;
|
||||
case WIFI_EVENT_AP_STADISCONNECTED:
|
||||
ESP_LOGI(TAG, "Wi-Fi AP got a station disconnected");
|
||||
s_con_cnt--;
|
||||
if (!s_con_cnt) {
|
||||
s_sta_is_connected = false;
|
||||
esp_wifi_internal_reg_rxcb(WIFI_IF_AP, NULL);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void initialize_ethernet(void)
|
||||
{
|
||||
uint8_t eth_port_cnt = 0;
|
||||
esp_eth_handle_t *eth_handles;
|
||||
ESP_ERROR_CHECK(example_eth_init(ð_handles, ð_port_cnt));
|
||||
if (eth_port_cnt > 1) {
|
||||
ESP_LOGW(TAG, "multiple Ethernet devices detected, the first initialized is to be used!");
|
||||
}
|
||||
s_eth_handle = eth_handles[0];
|
||||
free(eth_handles);
|
||||
ESP_ERROR_CHECK(esp_eth_update_input_path(s_eth_handle, pkt_eth2wifi, NULL));
|
||||
bool eth_promiscuous = true;
|
||||
ESP_ERROR_CHECK(esp_eth_ioctl(s_eth_handle, ETH_CMD_S_PROMISCUOUS, ð_promiscuous));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event_handler, NULL));
|
||||
ESP_ERROR_CHECK(esp_eth_start(s_eth_handle));
|
||||
|
||||
EventBits_t uxBits;
|
||||
uxBits = xEventGroupWaitBits(Btn_event_group,ETHERNET_CONNECTED,pdFALSE,pdFALSE,pdMS_TO_TICKS(5000));
|
||||
|
||||
if(!uxBits)
|
||||
{
|
||||
bsp_display_lock(0);
|
||||
lv_label_ins_text(label,LV_LABEL_POS_LAST,"Enthernet initial #ff0000 Failed#\n");
|
||||
// lv_label_ins_text(label,LV_LABEL_POS_LAST,"WIFI initial success\n");
|
||||
bsp_display_unlock();
|
||||
}
|
||||
|
||||
// vTaskDelay(pdMS_TO_TICKS(CONFIG_EXAMPLE_ETH_DEINIT_AFTER_S * 1000));
|
||||
// ESP_LOGI(TAG, "stop and deinitialize Ethernet network...");
|
||||
// // Stop Ethernet driver state machine and destroy netif
|
||||
// for (int i = 0; i < eth_port_cnt; i++) {
|
||||
// ESP_ERROR_CHECK(esp_eth_stop(eth_handles[i]));
|
||||
// ESP_ERROR_CHECK(esp_eth_del_netif_glue(eth_netif_glues[i]));
|
||||
// esp_netif_destroy(eth_netifs[i]);
|
||||
// }
|
||||
// esp_netif_deinit();
|
||||
// ESP_ERROR_CHECK(example_eth_deinit(eth_handles, eth_port_cnt));
|
||||
// ESP_ERROR_CHECK(esp_event_handler_unregister(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event_handler));
|
||||
}
|
||||
|
||||
static void initialize_wifi(void)
|
||||
{
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, wifi_event_handler, NULL));
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||
wifi_config_t wifi_config = {
|
||||
.ap = {
|
||||
.ssid = CONFIG_EXAMPLE_WIFI_SSID,
|
||||
.ssid_len = strlen(CONFIG_EXAMPLE_WIFI_SSID),
|
||||
.password = CONFIG_EXAMPLE_WIFI_PASSWORD,
|
||||
.max_connection = CONFIG_EXAMPLE_MAX_STA_CONN,
|
||||
.authmode = WIFI_AUTH_WPA_WPA2_PSK,
|
||||
.channel = CONFIG_EXAMPLE_WIFI_CHANNEL // default: channel 1
|
||||
},
|
||||
};
|
||||
if (strlen(CONFIG_EXAMPLE_WIFI_PASSWORD) == 0) {
|
||||
wifi_config.ap.authmode = WIFI_AUTH_OPEN;
|
||||
}
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &wifi_config));
|
||||
esp_wifi_get_mac(WIFI_IF_AP,s_eth_mac);
|
||||
esp_wifi_set_mac(WIFI_IF_AP, s_eth_mac);
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
wifi_scan_init();
|
||||
}
|
||||
|
||||
static void wifi_scan_init(void)
|
||||
{
|
||||
uint16_t ap_number;
|
||||
uint16_t ap_num=25;
|
||||
esp_err_t ret;
|
||||
ret = esp_wifi_scan_start(NULL,true);
|
||||
ESP_LOGI(TAG,"wifi scan = 0x%x",ret);
|
||||
esp_wifi_scan_get_ap_num(&ap_number);
|
||||
ESP_LOGI(TAG,"ap_number = %d",ap_number);
|
||||
// ap_num = 10;
|
||||
|
||||
wifi_ap_record_t ap_info;
|
||||
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_record(&ap_info));
|
||||
// vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
ESP_LOGI(TAG,"ret_wiff= 0x%x",ret);
|
||||
if(ret == ESP_OK)
|
||||
{
|
||||
ESP_LOGI(TAG,"ssid = %s,riss = %d db",ap_info.ssid,ap_info.rssi);
|
||||
vTaskDelay(pdMS_TO_TICKS(1));
|
||||
bsp_display_lock(0);
|
||||
// lv_label_ins_text(label,LV_LABEL_POS_LAST,"Enthernet initial success\n");
|
||||
lv_label_ins_text(label,LV_LABEL_POS_LAST,"WIFI initial #00ff00 Success#\n");
|
||||
bsp_display_unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
bsp_display_lock(0);
|
||||
// lv_label_ins_text(label,LV_LABEL_POS_LAST,"Enthernet initial success\n");
|
||||
lv_label_ins_text(label,LV_LABEL_POS_LAST,"WIFI initial #ff0000 Failed#\n");
|
||||
bsp_display_unlock();
|
||||
}
|
||||
}
|
||||
|
||||
static esp_err_t initialize_flow_control(void)
|
||||
{
|
||||
flow_control_queue = xQueueCreate(FLOW_CONTROL_QUEUE_LENGTH, sizeof(flow_control_msg_t));
|
||||
if (!flow_control_queue) {
|
||||
ESP_LOGE(TAG, "create flow control queue failed");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
BaseType_t ret = xTaskCreate(eth2wifi_flow_control_task, "flow_ctl", 2048, NULL, (tskIDLE_PRIORITY + 2), NULL);
|
||||
if (ret != pdTRUE) {
|
||||
ESP_LOGE(TAG, "create flow control task failed");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void test_enthernet_init(void)
|
||||
{
|
||||
Btn_event_group = xEventGroupCreate();
|
||||
xEventGroupClearBits(Btn_event_group,ETHERNET_CONNECTED);
|
||||
xEventGroupClearBits(Btn_event_group,ETHERNET_START);
|
||||
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
ESP_ERROR_CHECK(initialize_flow_control());
|
||||
initialize_wifi();
|
||||
initialize_ethernet();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
## Required IDF version
|
||||
idf:
|
||||
version: '>=4.1.0'
|
||||
# # Put list of dependencies here
|
||||
# # For components maintained by Espressif:
|
||||
# component: "~1.0.0"
|
||||
# # For 3rd party components:
|
||||
# username/component: ">=1.0.0,<2.0.0"
|
||||
# username2/component2:
|
||||
# version: "~1.0.0"
|
||||
# # For transient dependencies `public` flag can be set.
|
||||
# # `public` flag doesn't have an effect dependencies of the `main` component.
|
||||
# # All dependencies of `main` are public by default.
|
||||
# public: true
|
||||
espressif/esp_video: ^0.9.1
|
||||
|
||||
esp_lcd_touch_gsl3680:
|
||||
path: ../components/esp_lcd_touch_gsl3680
|
||||
|
||||
lvgl/lvgl: ^8.4.0
|
||||
|
||||
espressif/esp_hosted: '*'
|
||||
espressif/esp_wifi_remote: '*'
|
||||
espressif/esp_ipa: ^0.3.0
|
||||
@@ -0,0 +1,165 @@
|
||||
#ifndef __APP_CAMERA_H
|
||||
#define __APP_CAMERA_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_cam_sensor_types.h"
|
||||
#include "ov5647_types.h"
|
||||
#include "bsp/esp-bsp.h"
|
||||
|
||||
#include "lvgl.h"
|
||||
|
||||
extern lv_obj_t *label;
|
||||
|
||||
void app_camera(void);
|
||||
|
||||
#define OV5647_IDI_CLOCK_RATE_800x800_50FPS (100000000ULL)
|
||||
#define OV5647_8BIT_MODE (0x18)
|
||||
#define OV5647_REG_END 0xffff
|
||||
|
||||
|
||||
static const ov5647_reginfo_t ov5647_raw8_800x800_50fps[] = {
|
||||
{0x3034, OV5647_8BIT_MODE}, // set RAW format
|
||||
{0x3035, 0x41}, // system clk div
|
||||
{0x3036, ((OV5647_IDI_CLOCK_RATE_800x800_50FPS * 8 * 4) / 25000000)},
|
||||
{0x303c, 0x11},
|
||||
{0x3106, 0xf5},
|
||||
{0x3821, 0x03},
|
||||
{0x3820, 0x41},
|
||||
{0x3827, 0xec},
|
||||
{0x370c, 0x0f},
|
||||
{0x3612, 0x59},
|
||||
{0x3618, 0x00},
|
||||
{0x5000, 0xff},
|
||||
|
||||
{0x583e, 0xf0}, // LSC max gain
|
||||
{0x583f, 0x20}, // LSC min gain
|
||||
|
||||
{0x5002, 0x41},
|
||||
{0x5003, 0x08},
|
||||
{0x5a00, 0x08},
|
||||
{0x3000, 0x00},
|
||||
{0x3001, 0x00},
|
||||
{0x3002, 0x00},
|
||||
{0x3016, 0x08},
|
||||
{0x3017, 0xe0},
|
||||
{0x3018, 0x44},
|
||||
{0x301c, 0xf8},
|
||||
{0x301d, 0xf0},
|
||||
{0x3a18, 0x00},
|
||||
{0x3a19, 0xf8},
|
||||
{0x3c01, 0x80},
|
||||
{0x3c00, 0x40},
|
||||
{0x3b07, 0x0c},
|
||||
//HTS line exposure time in # of pixels
|
||||
{0x380c, (1896 >> 8) & 0x1F},
|
||||
{0x380d, 1896 & 0xFF},
|
||||
//VTS frame exposure time in # lines
|
||||
{0x380e, (984 >> 8) & 0xFF},
|
||||
{0x380f, 984 & 0xFF},
|
||||
{0x3814, 0x31},
|
||||
{0x3815, 0x31},
|
||||
{0x3708, 0x64},
|
||||
{0x3709, 0x52},
|
||||
//[3:0]=0 X address start high byte
|
||||
{0x3800, (500 >> 8) & 0x0F},
|
||||
//[7:0]=0 X address start low byte
|
||||
{0x3801, 500 & 0xFF},
|
||||
//[2:0]=0 Y address start high byte
|
||||
{0x3802, (0 >> 8) & 0x07},
|
||||
//[7:0]=0 Y address start low byte
|
||||
{0x3803, 0 & 0xFF},
|
||||
//[3:0] X address end high byte
|
||||
{0x3804, ((2624 - 1) >> 8) & 0x0F},
|
||||
//[7:0] X address end low byte
|
||||
{0x3805, (2624 - 1) & 0xFF},
|
||||
//[2:0] Y address end high byte
|
||||
{0x3806, ((1954 - 1) >> 8) & 0x07},
|
||||
//[7:0] Y address end low byte
|
||||
{0x3807, (1954 - 1) & 0xFF},
|
||||
//[3:0] Output horizontal width high byte
|
||||
{0x3808, (800 >> 8) & 0x0F},
|
||||
//[7:0] Output horizontal width low byte
|
||||
{0x3809, 800 & 0xFF},
|
||||
//[2:0] Output vertical height high byte
|
||||
{0x380a, (800 >> 8) & 0x7F},
|
||||
//[7:0] Output vertical height low byte
|
||||
{0x380b, 800 & 0xFF},
|
||||
//[3:0]=0 timing hoffset high byte
|
||||
{0x3810, (8 >> 8) & 0x0F},
|
||||
//[7:0]=0 timing hoffset low byte
|
||||
{0x3811, 8 & 0xFF},
|
||||
//[2:0]=0 timing voffset high byte
|
||||
{0x3812, (0 >> 8) & 0x07},
|
||||
//[7:0]=0 timing voffset low byte
|
||||
{0x3813, 0 & 0xFF},
|
||||
{0x3630, 0x2e},
|
||||
{0x3632, 0xe2},
|
||||
{0x3633, 0x23},
|
||||
{0x3634, 0x44},
|
||||
{0x3636, 0x06},
|
||||
{0x3620, 0x64},
|
||||
{0x3621, 0xe0},
|
||||
{0x3600, 0x37},
|
||||
{0x3704, 0xa0},
|
||||
{0x3703, 0x5a},
|
||||
{0x3715, 0x78},
|
||||
{0x3717, 0x01},
|
||||
{0x3731, 0x02},
|
||||
{0x370b, 0x60},
|
||||
{0x3705, 0x1a},
|
||||
{0x3f05, 0x02},
|
||||
{0x3f06, 0x10},
|
||||
{0x3f01, 0x0a},
|
||||
{0x3a08, 0x01},
|
||||
{0x3a09, 0x27},
|
||||
{0x3a0a, 0x00},
|
||||
{0x3a0b, 0xf6},
|
||||
{0x3a0d, 0x04},
|
||||
{0x3a0e, 0x03},
|
||||
{0x3a0f, 0x58},
|
||||
{0x3a10, 0x50},
|
||||
{0x3a1b, 0x58},
|
||||
{0x3a1e, 0x50},
|
||||
{0x3a11, 0x60},
|
||||
{0x3a1f, 0x28},
|
||||
{0x4001, 0x02},
|
||||
{0x4004, 0x02},
|
||||
{0x4000, 0x09},
|
||||
{0x4837, (1000000000 / OV5647_IDI_CLOCK_RATE_800x800_50FPS) * 2},
|
||||
{0x4050, 0x6e},
|
||||
{0x4051, 0x8f},
|
||||
{OV5647_REG_END, 0x00},
|
||||
};
|
||||
|
||||
static const esp_cam_sensor_isp_info_t custom_isp_info = {
|
||||
.isp_v1_info = {
|
||||
.version = SENSOR_ISP_INFO_VERSION_DEFAULT,
|
||||
.pclk = 81666700,
|
||||
.vts = 1896,
|
||||
.hts = 984,
|
||||
.bayer_type = ESP_CAM_SENSOR_BAYER_GBRG,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static const esp_cam_sensor_format_t custom_format_info = {
|
||||
.name = "MIPI_2lane_24Minput_RAW8_800x800_50fps",
|
||||
.format = ESP_CAM_SENSOR_PIXFORMAT_RAW8,
|
||||
.port = ESP_CAM_SENSOR_MIPI_CSI,
|
||||
.xclk = 24000000,
|
||||
.width = 800,
|
||||
.height = 800,
|
||||
.regs = ov5647_raw8_800x800_50fps,
|
||||
.regs_size = ARRAY_SIZE(ov5647_raw8_800x800_50fps),
|
||||
.fps = 50,
|
||||
.isp_info = &custom_isp_info,
|
||||
.mipi_info = {
|
||||
.mipi_clk = 400000000,
|
||||
.lane_num = 2,
|
||||
.line_sync_en = false,
|
||||
},
|
||||
.reserved = NULL,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef _ENTHERNET_H
|
||||
#define _ENTHERNET_H
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "lvgl.h"
|
||||
#include "bsp/esp-bsp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "c" {
|
||||
#endif
|
||||
|
||||
extern lv_obj_t *label;
|
||||
|
||||
void test_enthernet_init(void);
|
||||
void get_enthernet_Result(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,283 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_system.h"
|
||||
#include "driver/uart.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "app_enthernet.h"
|
||||
#include "lvgl.h"
|
||||
#include "bsp/esp-bsp.h"
|
||||
#include "bsp/display.h"
|
||||
#include "bsp_board_extra.h"
|
||||
#include "bsp/esp-bsp.h"
|
||||
#include "app_camera.h"
|
||||
|
||||
#define EXAMPLE_RECV_BUF_SIZE (2400)
|
||||
|
||||
#define ECHO_TEST_TXD (GPIO_NUM_26)
|
||||
#define ECHO_TEST_RXD (GPIO_NUM_27)
|
||||
|
||||
// RTS for RS485 Half-Duplex Mode manages DE/~RE
|
||||
#define ECHO_TEST_RTS (UART_PIN_NO_CHANGE)
|
||||
|
||||
// CTS is not used in RS485 Half-Duplex Mode
|
||||
#define ECHO_TEST_CTS (UART_PIN_NO_CHANGE)
|
||||
|
||||
#define BUF_SIZE (127)
|
||||
#define BAUD_RATE (115200)
|
||||
|
||||
#define PACKET_READ_TICS (100 / portTICK_PERIOD_MS)
|
||||
#define ECHO_TASK_STACK_SIZE (3072)
|
||||
#define ECHO_TASK_PRIO (10)
|
||||
#define ECHO_UART_PORT (1)
|
||||
|
||||
#define ECHO_READ_TOUT (3)
|
||||
|
||||
const int uart_num = ECHO_UART_PORT;
|
||||
|
||||
static const char err_reason[][30] = {"input param is invalid",
|
||||
"operation timeout"
|
||||
};
|
||||
|
||||
static const char *TAG = "MAIN";
|
||||
static lv_obj_t *obj = NULL;
|
||||
lv_obj_t *label = NULL;
|
||||
static lv_obj_t *btn = NULL;
|
||||
|
||||
static bool RS485_test_bool = false;
|
||||
|
||||
static void i2s_echo(void *args)
|
||||
{
|
||||
uint8_t *mic_data = malloc(EXAMPLE_RECV_BUF_SIZE);
|
||||
if (!mic_data) {
|
||||
ESP_LOGE(TAG, "[echo] No memory for read data buffer");
|
||||
abort();
|
||||
}
|
||||
esp_err_t ret = ESP_OK;
|
||||
size_t bytes_read = 0;
|
||||
size_t bytes_write = 0;
|
||||
ESP_LOGI(TAG, "[echo] Echo start");
|
||||
|
||||
while (1) {
|
||||
// ESP_LOGI(TAG,"i2s read");
|
||||
memset(mic_data, 0, EXAMPLE_RECV_BUF_SIZE);
|
||||
/* Read sample data from mic */
|
||||
ret = bsp_extra_i2s_read(mic_data, EXAMPLE_RECV_BUF_SIZE, &bytes_read, 1000);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "[echo] i2s read failed, %s", err_reason[ret == ESP_ERR_TIMEOUT]);
|
||||
abort();
|
||||
}
|
||||
/* Write sample data to earphone */
|
||||
ret = bsp_extra_i2s_write(mic_data, EXAMPLE_RECV_BUF_SIZE, &bytes_write, 1000);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "[echo] i2s write failed, %s", err_reason[ret == ESP_ERR_TIMEOUT]);
|
||||
abort();
|
||||
}
|
||||
if (bytes_read != bytes_write) {
|
||||
ESP_LOGW(TAG, "[echo] %d bytes read but only %d bytes are written", bytes_read, bytes_write);
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
static void echo_send(const int port, const char* str, uint8_t length)
|
||||
{
|
||||
// ESP_LOGI(TAG,"data = %s",str);
|
||||
if (uart_write_bytes(port, str, length) != length) {
|
||||
ESP_LOGE(TAG, "Send data critical failure.");
|
||||
// add your code to handle sending failure here
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void RS485_test_callback(lv_event_t *e)
|
||||
{
|
||||
// echo_send(uart_num, "\r\n", 2);
|
||||
char prefix[] = "RS485 TEST";
|
||||
echo_send(uart_num,prefix,sizeof(prefix));
|
||||
ESP_ERROR_CHECK(uart_wait_tx_done(uart_num, 10));
|
||||
}
|
||||
|
||||
static void echo_task(void *arg)
|
||||
{
|
||||
|
||||
uart_config_t uart_config = {
|
||||
.baud_rate = BAUD_RATE,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||
.rx_flow_ctrl_thresh = 122,
|
||||
.source_clk = UART_SCLK_DEFAULT,
|
||||
};
|
||||
|
||||
// // Set UART log level
|
||||
// esp_log_level_set(TAG, ESP_LOG_INFO);
|
||||
|
||||
ESP_LOGI(TAG, "Start RS485 application test and configure UART.");
|
||||
|
||||
// Install UART driver (we don't need an event queue here)
|
||||
// In this example we don't even use a buffer for sending data.
|
||||
ESP_ERROR_CHECK(uart_driver_install(uart_num, BUF_SIZE * 2, 0, 0, NULL, 0));
|
||||
|
||||
// Configure UART parameters
|
||||
ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
|
||||
|
||||
ESP_LOGI(TAG, "UART set pins, mode and install driver.");
|
||||
|
||||
// Set UART pins as per KConfig settings
|
||||
ESP_ERROR_CHECK(uart_set_pin(uart_num, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS));
|
||||
|
||||
// Set RS485 half duplex mode
|
||||
ESP_ERROR_CHECK(uart_set_mode(uart_num, UART_MODE_RS485_HALF_DUPLEX));
|
||||
|
||||
// Set read timeout of UART TOUT feature
|
||||
ESP_ERROR_CHECK(uart_set_rx_timeout(uart_num, ECHO_READ_TOUT));
|
||||
|
||||
// Allocate buffers for UART
|
||||
uint8_t* data = (uint8_t*) malloc(BUF_SIZE);
|
||||
|
||||
ESP_LOGI(TAG, "UART start receive loop.\r");
|
||||
// echo_send(uart_num, "Start RS485 UART test.\r\n", 24);
|
||||
|
||||
while (1) {
|
||||
//Read data from UART
|
||||
int len = uart_read_bytes(uart_num, data, BUF_SIZE, PACKET_READ_TICS);
|
||||
|
||||
//Write data back to UART
|
||||
if (len > 0) {
|
||||
// echo_send(uart_num, "\r\n", 2);
|
||||
// char prefix[] = "RS485 Received: [";
|
||||
// echo_send(uart_num, prefix, (sizeof(prefix) - 1));
|
||||
ESP_LOGI(TAG, "Received %u bytes:", len);
|
||||
printf("[ ");
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf("0x%.2x ", data[i]);
|
||||
// echo_send(uart_num, (const char*)&data[i], 1);
|
||||
// Add a Newline character if you get a return character from paste (Paste tests multibyte receipt/buffer)
|
||||
// if (data[i] == '\r') {
|
||||
// echo_send(uart_num, "\n", 1);
|
||||
// }
|
||||
}
|
||||
printf("] \n");
|
||||
// echo_send(uart_num, "]\r\n", 3);
|
||||
|
||||
char *re = strstr((char *)data,"RS485 TEST");
|
||||
if(re == NULL)
|
||||
{
|
||||
ESP_LOGI(TAG,"NOT send data");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!RS485_test_bool)
|
||||
{
|
||||
RS485_test_bool = true;
|
||||
lvgl_port_lock(-1);
|
||||
lv_label_ins_text(label,LV_LABEL_POS_LAST,"RS485 initial #00ff00 Success#\n");
|
||||
lvgl_port_unlock();
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// } else {
|
||||
// // Echo a "." to show we are alive while we wait for input
|
||||
// echo_send(uart_num, ".", 1);
|
||||
// ESP_ERROR_CHECK(uart_wait_tx_done(uart_num, 10));
|
||||
// }
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
esp_err_t ret_bsp = ESP_OK;
|
||||
|
||||
|
||||
// bsp_i2c_init();
|
||||
|
||||
bsp_display_cfg_t cfg = {
|
||||
.lvgl_port_cfg = ESP_LVGL_PORT_INIT_CONFIG(),
|
||||
.buffer_size = BSP_LCD_H_RES * BSP_LCD_V_RES,
|
||||
.double_buffer = BSP_LCD_DRAW_BUFF_DOUBLE,
|
||||
.flags = {
|
||||
.buff_dma = false,
|
||||
.buff_spiram = true,
|
||||
.sw_rotate = true,
|
||||
}
|
||||
};
|
||||
bsp_display_start_with_config(&cfg);
|
||||
bsp_display_backlight_on();
|
||||
|
||||
|
||||
|
||||
bsp_display_lock(0);
|
||||
obj = lv_obj_create(lv_scr_act());
|
||||
lv_obj_set_size(obj,800,1280);
|
||||
|
||||
btn = lv_btn_create(obj);
|
||||
lv_obj_align(btn,LV_ALIGN_TOP_MID,50,50);
|
||||
lv_obj_set_size(btn,200,100);
|
||||
lv_obj_t *label_btn = lv_label_create(btn);
|
||||
lv_obj_center(label_btn);
|
||||
lv_label_set_text(label_btn,"RS485 Test");
|
||||
lv_obj_add_event_cb(btn,RS485_test_callback,LV_EVENT_CLICKED,NULL);
|
||||
|
||||
label = lv_label_create(obj);
|
||||
lv_label_set_recolor(label,true);
|
||||
lv_obj_set_style_text_font(label,&lv_font_montserrat_28,0);
|
||||
lv_label_set_text(label,"LCD initial #00ff00 Success#\n");
|
||||
lv_label_ins_text(label,LV_LABEL_POS_LAST,"TP initial #00ff00 Success#\n");
|
||||
bsp_display_unlock();
|
||||
|
||||
|
||||
|
||||
esp_err_t ret;
|
||||
ret = bsp_sdcard_mount();
|
||||
if(ret == ESP_OK)
|
||||
{
|
||||
bsp_display_lock(0);
|
||||
lv_label_ins_text(label,LV_LABEL_POS_LAST,"SDCard initial #00ff00 Success#\n");
|
||||
bsp_display_unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
bsp_display_lock(0);
|
||||
lv_label_ins_text(label,LV_LABEL_POS_LAST,"SDCard initial #ff0000 Failed#\n");
|
||||
bsp_display_unlock();
|
||||
}
|
||||
test_enthernet_init();
|
||||
|
||||
ret_bsp = bsp_extra_codec_init();
|
||||
bsp_extra_codec_volume_set(50, NULL);
|
||||
if(ret_bsp == ESP_OK)
|
||||
{
|
||||
bsp_display_lock(0);
|
||||
lv_label_ins_text(label,LV_LABEL_POS_LAST,"ES8311 initial #00ff00 success#\n");
|
||||
bsp_display_unlock();
|
||||
// bsp_extra_codec_volume_set(50,NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
bsp_display_lock(0);
|
||||
lv_label_ins_text(label,LV_LABEL_POS_LAST,"ES8311 initial #ff0000 failed#\n");
|
||||
bsp_display_unlock();
|
||||
}
|
||||
// bsp_audio_init();
|
||||
// bsp_extra_codec_mute_set(true);
|
||||
// bsp_extra_codec_volume_set(50,NULL);
|
||||
//
|
||||
|
||||
app_camera();
|
||||
|
||||
xTaskCreate(i2s_echo, "i2s_echo", 8192, NULL, 4, NULL);
|
||||
xTaskCreate(echo_task, "uart_echo_task", ECHO_TASK_STACK_SIZE, NULL, 3, NULL);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
|
||||
nvs, data, nvs, 0x9000, 0x6000,
|
||||
phy_init, data, phy, 0xf000, 0x1000,
|
||||
factory, app, factory, , 9M,
|
||||
storage, data, spiffs, , 4M,
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user