1 BSP定义

BSP(Board Support Package)是针对特定硬件平台或板级产品(例如嵌入式系统)的软件支持包。

简单来说,BSP开发是针对特定芯片和板卡,适配启动链、操作系统及硬件支持,使系统能够稳定启动、运行,并使用目标产品所需的硬件功能。

其内容可以因硬件平台而异,但通常包括以下内容:

  1. 引导加载程序(Bootloader):负责在启动时加载操作系统或其他软件,并对硬件进行初始化和配置。

  2. 驱动程序(Drivers):为特定硬件组件(如处理器、外设、传感器等)提供底层软件接口,允许操作系统或应用程序与硬件进行通信和控制。

  3. 操作系统(Operating System):可能包括操作系统内核和相应的 BSP 驱动程序,用于管理硬件资源、调度任务、提供文件系统支持等。

  4. 工具链(Toolchain):包括编译器、链接器、调试器等工具,用于开发和调试软件。

  5. 中间件(Middleware):提供额外的软件功能和服务,例如图形界面、网络协议栈、文件系统、USB 支持等。

  6. 文档和示例代码:包括硬件规格、软件开发手册、API 文档、示例代码等,帮助开发人员理解和使用 BSP。

  7. 测试工具和调试支持:用于验证和调试 BSP 的工具,例如测试套件、仿真器、调试代理等。

  8. 配置工具和脚本:用于配置 BSP 参数、生成初始化代码、自动化构建和部署等的工具和脚本。

总之,BSP 是为特定硬件平台定制的软件支持包,旨在简化嵌入式软件开发过程,并为开发人员提供必要的软件基础设施和工具。

阿里云这篇也写的很好:嵌入式BSP工程师基本任务分析-阿里云开发者社区

======================20261105补======================

如果是SOC厂商,还有

+1 硬件 Bring-up(硬件点亮与底层 Bring-up):

电源与时钟树配置(Power & Clock):配置 PMIC(电源管理芯片)、各路 DCDC/LDO 输出电压。配置 SoC 的 PLL、各总线(AHB/APB)及外设的时钟频率。DDR 内存调优与初始化:调试 DDR 控制器参数,确保内存读写稳定、高速(这是系统稳定性的基石)。基本引脚复用(Pinmux & GPIO):根据原理图配置芯片引脚的复用功能(如将某个引脚配置为 UART、I2C 或普通 GPIO)。

+2 引导加载程序(Bootloader 开发,如 U-Boot):

板级初始化:初始化串口(用于打印 Log)、初始化网卡、初始化存储控制器。加载机制:实现从 eMMC、UFS、NAND Flash、SPI Nor 或 TF 卡加载内核(Kernel)和设备树(DTB)。安全启动与烧录协议。

+3 操作系统内核裁剪与移植(Kernel Porting & Optimization)

内核配置(Kernel Config):根据产品需求裁剪内核,去掉无用的驱动和功能,缩减启动时间和内存占用。内核补丁与升级:将芯片厂商(如 Qualcomm、MTK、NXP)提供的 BSP Patch 打到标准 Linux Kernel 或 Android Kernel 源码上。性能与功耗优化。

+4 此外,如果是安卓平台还要实现HAL。

内核驱动之上还有 HAL、原生服务、系统服务和应用等层次。HAL 的作用就是把硬件实现接入 Android 的标准接口。

只是现在业界大部分方案商的开发是基于SOM的模式(SoM的理解_soc和som-CSDN博客),这个就意味着最麻烦的 DDR 内存调优与布线、PMIC 电源时序、CPU 核心电压、高频时钟树。这些在 SOM 核心板出厂时,模组厂商已经全部搞定并做好了高密度 PCB 验证。

基本上上面1,3,4,5,+1,+2,+3是不需要做了。核心的工作内容其实就专注于驱动,+4,以及后面的6,7,8就可以了。

所以BSP的工作内容和学习要求,也要看看公司在产业链中的位置。

2 ESP32的BSP

可以看一个实际的例子:https://github.com/espressif/esp-bsp

Main Purpose of BSP

  1. Simplify development on Espressif and M5Stack boards by providing ready-to-use peripheral initialization.
  2. Enable quick project startup on supported development boards, with an easy path to migrate to custom hardware.
  3. Facilitate cross-board development by offering a common API, making it easier to build and maintain projects for multiple boards.

本质就是简化开发,快速启动,并且在不同的板子直接提供同一套API。

可以看到,支持了很多开发板。上面有不同的功能,比如audio,IMU,Display。BSP就是把这些内容功能实现并提供向上接口。

然后官方也提供了很多示例:

看一个具体的LVGL的。

/*
 * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: CC0-1.0
 */

/**
 * @file
 * @brief BSP LVGL Demos Example
 * @details Run the LVGL demo player - all LVGL examples are included (LVGL)
 * @example https://espressif.github.io/esp-launchpad/?flashConfigURL=https://espressif.github.io/esp-bsp/config.toml&app=display_lvgl_demos-
 */

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

#include "lv_demos.h"
#include "bsp/esp-bsp.h"

static char *TAG = "app_main";

#define LOG_MEM_INFO    (0)

void app_main(void)
{
    /* Initialize display and LVGL */
    bsp_display_start();

#if CONFIG_BSP_DISPLAY_LVGL_AVOID_TEAR
    ESP_LOGI(TAG, "Avoid lcd tearing effect");
#if CONFIG_BSP_DISPLAY_LVGL_FULL_REFRESH
    ESP_LOGI(TAG, "LVGL full-refresh");
#elif CONFIG_BSP_DISPLAY_LVGL_DIRECT_MODE
    ESP_LOGI(TAG, "LVGL direct-mode");
#endif
#endif

    /* Set display brightness to 100% */
    bsp_display_backlight_on();

    ESP_LOGI(TAG, "Display LVGL demo");
    bsp_display_lock(0);
    // lv_demo_widgets();      /* A widgets example */
    lv_demo_music();        /* A modern, smartphone-like music player demo. */
    // lv_demo_stress();       /* A stress test for LVGL. */
    // lv_demo_benchmark();    /* A demo to measure the performance of LVGL or to compare different settings. */
    bsp_display_unlock();

#if LOG_MEM_INFO
    static char buffer[128];    /* Make sure buffer is enough for `sprintf` */
    while (1) {
        sprintf(buffer, "   Biggest /     Free /    Total\n"
                "\t  SRAM : [%8d / %8d / %8d]\n"
                "\t PSRAM : [%8d / %8d / %8d]",
                heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL),
                heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
                heap_caps_get_total_size(MALLOC_CAP_INTERNAL),
                heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM),
                heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
                heap_caps_get_total_size(MALLOC_CAP_SPIRAM));
        ESP_LOGI("MEM", "%s", buffer);

        vTaskDelay(pdMS_TO_TICKS(500));
    }
#endif
}

可以看到包含了一个bsp/esp-bsp.h,使用了很多封装后的函数。

    /* Set display brightness to 100% */
    bsp_display_backlight_on();

    ESP_LOGI(TAG, "Display LVGL demo");
    bsp_display_lock(0);

好了,最后看看esp-bsp.h吧,内容就挺清楚了。

/*
 * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
 * @file
 * @brief ESP BSP: ESP32-S3-EYE
 */

#pragma once

#include "sdkconfig.h"
#include "driver/gpio.h"
#include "bsp/config.h"
#include "driver/i2c_master.h"
#include "driver/sdmmc_host.h"
#include "driver/sdspi_host.h"
#include "esp_vfs_fat.h"
#include "driver/i2s_std.h"
#include "esp_codec_dev.h"
#include "iot_button.h"
#include "bsp/display.h"
#include "led_indicator.h"
#include "esp_adc/adc_oneshot.h"


#if (BSP_CONFIG_NO_GRAPHIC_LIB == 0)
#include "lvgl.h"
#include "esp_lvgl_port.h"
#endif // BSP_CONFIG_NO_GRAPHIC_LIB == 0
/**************************************************************************************************
 *  BSP Board Name
 **************************************************************************************************/

/** @defgroup boardname Board Name
 *  @brief BSP Board Name
 *  @{
 */
#define BSP_BOARD_ESP32_S3_EYE
/** @} */ // end of boardname

/**************************************************************************************************
 *  BSP Capabilities
 **************************************************************************************************/

/** @defgroup capabilities Capabilities
 *  @brief BSP Capabilities
 *  @{
 */
#define BSP_CAPS_DISPLAY          1
#define BSP_CAPS_TOUCH            0
#define BSP_CAPS_BUTTONS          1
#define BSP_CAPS_KNOB             0
#define BSP_CAPS_AUDIO            1
#define BSP_CAPS_AUDIO_SPEAKER    0
#define BSP_CAPS_AUDIO_MIC        1
#define BSP_CAPS_SDCARD           1
#define BSP_CAPS_LED              1
#define BSP_CAPS_CAMERA           1
#define BSP_CAPS_BAT              0
#define BSP_CAPS_IMU              0
/** @} */ // end of capabilities

/**************************************************************************************************
 *  Board pinout
 **************************************************************************************************/

/** @defgroup g01_i2c I2C
 *  @brief I2C BSP API
 *  @{
 */
#define BSP_I2C_SCL     (GPIO_NUM_5)
#define BSP_I2C_SDA     (GPIO_NUM_4)
/** @} */ // end of i2c

/** @defgroup g03_audio Audio
 *  @brief Audio BSP API
 *  @{
 */
#define BSP_I2S_MCLK         (GPIO_NUM_NC)
#define BSP_I2S_SCLK         (GPIO_NUM_41)
#define BSP_I2S_LCLK         (GPIO_NUM_42)
#define BSP_I2S_DOUT         (GPIO_NUM_NC)
#define BSP_I2S_DSIN         (GPIO_NUM_2)
/** @} */ // end of audio

/** @defgroup g04_display Display and Touch
 *  @brief Display BSP API
 *  @{
 */
#define BSP_LCD_PCLK         (GPIO_NUM_21)
#define BSP_LCD_DATA0        (GPIO_NUM_47)
#define BSP_LCD_DC           (GPIO_NUM_43)
#define BSP_LCD_CS           (GPIO_NUM_44)
#define BSP_LCD_RST          (GPIO_NUM_NC)
#define BSP_LCD_BACKLIGHT    (GPIO_NUM_48)
/** @} */ // end of display

/** @defgroup g12_camera Camera
 *  @brief Camera BSP API
 *  @{
 */
#define BSP_CAMERA_GPIO_XCLK (GPIO_NUM_15)
#define BSP_CAMERA_RST       (GPIO_NUM_NC)
#define BSP_CAMERA_PCLK      (GPIO_NUM_13)
#define BSP_CAMERA_VSYNC     (GPIO_NUM_6)
#define BSP_CAMERA_HSYNC     (GPIO_NUM_7)
#define BSP_CAMERA_D0        (GPIO_NUM_11)
#define BSP_CAMERA_D1        (GPIO_NUM_9)
#define BSP_CAMERA_D2        (GPIO_NUM_8)
#define BSP_CAMERA_D3        (GPIO_NUM_10)
#define BSP_CAMERA_D4        (GPIO_NUM_12)
#define BSP_CAMERA_D5        (GPIO_NUM_18)
#define BSP_CAMERA_D6        (GPIO_NUM_17)
#define BSP_CAMERA_D7        (GPIO_NUM_16)
/** @} */ // end of camera

/** @defgroup g05_buttons Buttons
 *  @brief Buttons BSP API
 *  @{
 */
#define BSP_BUTTON_5_IO      (GPIO_NUM_0)
/** @} */ // end of buttons

/** @defgroup g06_led Leds
 *  @brief Leds BSP API
 *  @{
 */
#define BSP_LED_1_IO         (GPIO_NUM_3)
/** @} */ // end of led

/** @defgroup g02_storage SD Card and SPIFFS
 *  @brief SPIFFS and SD card BSP API
 *  @{
 */
#define BSP_SD_D0            (GPIO_NUM_40)
#define BSP_SD_D1            (GPIO_NUM_NC)
#define BSP_SD_D2            (GPIO_NUM_NC)
#define BSP_SD_D3            (GPIO_NUM_NC)
#define BSP_SD_CMD           (GPIO_NUM_38)
#define BSP_SD_CLK           (GPIO_NUM_39)
#define BSP_SD_DET           (GPIO_NUM_NC)
/** @} */ // end of storage

/** \addtogroup g05_buttons
 *  @{
 */
/* Button definitions */
typedef enum {
    BSP_BUTTON_1,
    BSP_BUTTON_2,
    BSP_BUTTON_3,
    BSP_BUTTON_4,
    BSP_BUTTON_5,
    BSP_BUTTON_NUM
} bsp_button_t;
/** @} */ // end of buttons

/** \addtogroup g06_led
 *  @{
 */
/* LED definitions */
typedef enum {
    BSP_LED_1,
    BSP_LED_NUM
} bsp_led_t;

/* Default LED effects */
typedef enum {
    BSP_LED_ON,
    BSP_LED_OFF,
    BSP_LED_BLINK_FAST,
    BSP_LED_BLINK_SLOW,
    BSP_LED_MAX,
} bsp_led_effect_t;
/** @} */ // end of leds

#ifdef __cplusplus
extern "C" {
#endif

/** \addtogroup g03_audio
 *  @{
 */

/**************************************************************************************************
 *
 * I2S audio interface
 *
 * 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()
 * @param[in]  i2s_config I2S configuration. Pass NULL to use default values
 * @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 Get codec I2S interface (initialized in bsp_audio_init)
 *
 * @return
 *      - Pointer to codec I2S interface handle or NULL when error occurred
 */
const audio_codec_data_if_t *bsp_audio_get_codec_itf(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);

/** @} */ // end of audio

/** \addtogroup g01_i2c
 *  @{
 */

/**************************************************************************************************
 *
 * I2C interface
 *
 **************************************************************************************************/
#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);

/** @} */ // end of i2c

/** \addtogroup g02_storage
 *  @{
 */

/**************************************************************************************************
 *
 * 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);

/**************************************************************************************************
 *
 * SD card
 *
 * After mounting the SD card, it can be accessed with stdio functions ie.:
 * \code{.c}
 * FILE* f = fopen(BSP_SD_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

/**
 * @brief BSP SD card configuration structure
 */
typedef struct {
    const esp_vfs_fat_sdmmc_mount_config_t *mount;
    sdmmc_host_t *host;
    union {
        const sdmmc_slot_config_t   *sdmmc;
        const sdspi_device_config_t *sdspi;
    } slot;
} bsp_sdcard_cfg_t;

/**
 * @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 can not be allocated
 *      - ESP_FAIL if partition can not 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);

/**
 * @brief Get SD card handle
 *
 * @return SD card handle
 */
sdmmc_card_t *bsp_sdcard_get_handle(void);

/**
 * @brief Get SD card MMC host config
 *
 * @param slot SD card slot
 * @param config Structure which will be filled
 */
void bsp_sdcard_get_sdmmc_host(const int slot, sdmmc_host_t *config);

/**
 * @brief Get SD card SPI host config
 *
 * @param slot SD card slot
 * @param config Structure which will be filled
 */
void bsp_sdcard_get_sdspi_host(const int slot, sdmmc_host_t *config);

/**
 * @brief Get SD card MMC slot config
 *
 * @param slot SD card slot
 * @param config Structure which will be filled
 */
void bsp_sdcard_sdmmc_get_slot(const int slot, sdmmc_slot_config_t *config);

/**
 * @brief Get SD card SPI slot config
 *
 * @param spi_host SPI host ID
 * @param config Structure which will be filled
 */
void bsp_sdcard_sdspi_get_slot(const spi_host_device_t spi_host, sdspi_device_config_t *config);

/**
 * @brief Mount microSD card to virtual file system (MMC mode)
 *
 * @param cfg SD card configuration
 *
 * @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_sdmmc_mount(bsp_sdcard_cfg_t *cfg);

/**
 * @brief Mount microSD card to virtual file system (SPI mode)
 *
 * @param cfg SD card configuration
 *
 * @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_sdspi_mount(bsp_sdcard_cfg_t *cfg);

/** @} */ // end of storage

/** \addtogroup g04_display
 *  @{
 */

/**************************************************************************************************
 *
 * LCD interface
 *
 * 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 any 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_HZ     (80 * 1000 * 1000)
#define BSP_LCD_SPI_NUM            (SPI3_HOST)

#if (BSP_CONFIG_NO_GRAPHIC_LIB == 0)

/**
 * @brief BSP display (LVGL) 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 occurred
 */
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 occurred
 */
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 Set display enter sleep mode
 *
 * All the display (LCD, backlight, touch) will enter sleep mode.
 *
 * @return
 *      - ESP_OK on success
 *      - ESP_ERR_NOT_SUPPORTED if this function is not supported by the panel
 */
esp_err_t bsp_display_enter_sleep(void);

/**
 * @brief Set display exit sleep mode
 *
 * All the display (LCD, backlight, touch) will exit sleep mode.
 *
 * @return
 *      - ESP_OK on success
 *      - ESP_ERR_NOT_SUPPORTED if this function is not supported by the panel
 */
esp_err_t bsp_display_exit_sleep(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

/** @} */ // end of display

/** \addtogroup g12_camera
 *  @{
 */

/**************************************************************************************************
 *
 * Camera interface
 * Supported camera sensors: OV2640
 * More information in display_camera_video example
 *
 **************************************************************************************************/

#define BSP_CAMERA_DEVICE             (ESP_VIDEO_DVP_DEVICE_NAME)
#define BSP_CAMERA_VFLIP              (1)
#define BSP_CAMERA_HFLIP              (0)
#define BSP_CAMERA_XCLK_CLOCK_MHZ     (16)

/**
 * @brief BSP camera configuration structure (for future use)
 *
 */
typedef struct {
    uint8_t dummy;
} bsp_camera_cfg_t;

/**
 * @brief Initialize camera
 *
 * Camera sensor initialization.
 */
esp_err_t bsp_camera_start(const bsp_camera_cfg_t *cfg);

/** @} */ // end of camera

/** @defgroup g01_adc ADC
 *  @brief ADC BSP API
 *  @{
 */

/**************************************************************************************************
 *
 * ADC interface
 *
 * After initialization of ADC, use adc_handle when using ADC driver.
 **************************************************************************************************/

#define BSP_ADC_UNIT     ADC_UNIT_1

/**
 * @brief Initialize ADC
 *
 * The ADC can be initialized inside BSP, when needed.
 */
esp_err_t bsp_adc_initialize(void);

/**
 * @brief Get ADC handle
 *
 * @note This function is available only in IDF5 and higher
 *
 * @return ADC handle
 */
adc_oneshot_unit_handle_t bsp_adc_get_handle(void);

/** @} */ // end of adc

/** \addtogroup g06_led
 *  @{
 */

/**************************************************************************************************
 *
 * LEDs
 *
 **************************************************************************************************/

/**
 * @brief Initialize all LEDs
 *
 * @param[out] led_array      Output LED array
 * @param[out] led_cnt        Number of LED handlers saved to led_array, can be NULL
 * @param[in]  led_array_size Size of output LED array. Must be at least BSP_LED_NUM
 * @return
 *     - ESP_OK Success
 *     - ESP_ERR_INVALID_ARG Parameter error
 */
esp_err_t bsp_led_indicator_create(led_indicator_handle_t led_array[], int *led_cnt, int led_array_size);

/**
 * @brief Turn LED on/off
 *
 * @param handle led handle
 * @param on Switch LED on/off
 * @return
 *     - ESP_OK Success
 *     - ESP_ERR_INVALID_ARG Parameter error
 */
esp_err_t bsp_led_set(led_indicator_handle_t handle, const bool on);

/** @} */ // end of leds

/** \addtogroup g05_buttons
 *  @{
 */

/**************************************************************************************************
 *
 * Button
 *
 **************************************************************************************************/

/**
 * @brief Initialize all buttons
 *
 * Returned button handlers must be used with espressif/button component API
 *
 * @param[out] btn_array      Output button array
 * @param[out] btn_cnt        Number of button handlers saved to btn_array, can be NULL
 * @param[in]  btn_array_size Size of output button array. Must be at least BSP_BUTTON_NUM
 * @return
 *     - ESP_OK               All buttons initialized
 *     - ESP_ERR_INVALID_ARG  btn_array is too small or NULL
 *     - ESP_FAIL             Underlying iot_button_create failed
 */
esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int btn_array_size);

/** @} */ // end of buttons

#ifdef __cplusplus
}
#endif

Logo

openEuler 是由开放原子开源基金会孵化的全场景开源操作系统项目,面向数字基础设施四大核心场景(服务器、云计算、边缘计算、嵌入式),全面支持 ARM、x86、RISC-V、loongArch、PowerPC、SW-64 等多样性计算架构

更多推荐