| HOW TO USE API | EXAMPLES | |
|
| — | — | — | — |
| This is a generic BSP, which is configurable from `menuconfig`. The generic BSP can provide consistent API for simple boards, such as Espressif's DevKit-C and DevKit-M boards. Predefined settings for selected DevKits are in [generic_button_led](examples/generic_button_led). |
|
Supported features:
Predefined configurations are saved in generic_button_led example.
idf.py -p COM4 -D "SDKCONFIG_DEFAULTS=sdkconfig.esp32_s3_devkitc_1" flash monitor
menuconfig
BSP_I2C_GPIO_SCLBSP_I2C_GPIO_SDAmenuconfig
BSP_I2C_NUMExample code:
/* Initialization */
bsp_i2c_init();
/* Example I2C write with BSP_I2C_NUM */
i2c_master_write_to_device(BSP_I2C_NUM, 0x10, value, sizeof(value), 1000 / portTICK_PERIOD_MS);
...
bsp_i2c_deinit();
Note: The BSP automatically initialize I2C, when need it for some component (LCD touch, audio, etc.)
Example code:
/* Mount SPIFFS partition */
bsp_spiffs_mount();
/* Use file system read/write with BSP_SPIFFS_MOUNT_POINT */
FILE *in = fopen(BSP_SD_MOUNT_POINT"/text.txt", "rb");
...
bsp_spiffs_unmount();
Example code:
/* Mount SD card partition */
bsp_sdcard_mount();
/* Use file system read/write with BSP_SD_MOUNT_POINT */
FILE *in = fopen(BSP_SD_MOUNT_POINT"/text.txt", "rb");
...
bsp_sdcard_unmount();
Note: This API is available only in MCUs, which have SD MMC peripheral.
menuconfig
BSP_BUTTONS_NUM (max 5)menuconfig
BSP_BUTTON_x_TYPEBSP_BUTTON_x_GPIO (for GPIO button)BSP_BUTTON_x_LEVEL (for GPIO button)BSP_BUTTON_x_ADC_CHANNEL (for ADC button)BSP_BUTTON_x_ADC_VALUE (for ADC button)Example code:
/* Button callback */
static void btn_handler(void *button_handle, void *usr_data)
{
int button_pressed = (int)usr_data;
ESP_LOGI(TAG, "Button pressed: %d", button_pressed);
}
/* Initialize all buttons and register callback for them */
button_handle_t btns[BSP_BUTTON_NUM];
ESP_ERROR_CHECK(bsp_iot_button_create(btns, NULL, BSP_BUTTON_NUM));
for (int i = 0; i < BSP_BUTTON_NUM; i++) {
ESP_ERROR_CHECK(iot_button_register_cb(btns[i], BUTTON_PRESS_DOWN, btn_handler, (void *) i));
}
For button handling is used component iot_button. For more information, please look into guide for this component.
menuconfig
BSP_LEDS_NUM (max 5)menuconfig
BSP_LED_TYPE (GPIO / Adressable RGB LED / Classic RGB)menuconfig
BSP_LED_x_GPIOBSP_LED_x_LEVELmenuconfig
BSP_LED_RGB_GPIOBSP_LED_RGB_BACKENDmenuconfig
BSP_LED_RGB_RED_GPIOBSP_LED_RGB_GREEN_GPIOBSP_LED_RGB_BLUE_GPIOBSP_LED_RGB_CLASSIC_LEVELExample code:
/* Initialize all LEDs */
led_indicator_handle_t leds[BSP_LED_NUM];
ESP_ERROR_CHECK(bsp_led_indicator_create(leds, NULL, BSP_LED_NUM));
/* Set LED color for first LED (only for addressable RGB LEDs) */
led_indicator_set_rgb(leds[0], SET_IRGB(0, 0x00, 0x64, 0x64));
/* Start effect for each LED (predefined: BSP_LED_ON, BSP_LED_OFF, BSP_LED_BLINK_FAST, BSP_LED_BLINK_SLOW, BSP_LED_BREATHE_FAST, BSP_LED_BREATHE_SLOW) */
led_indicator_start(leds[0], BSP_LED_BREATHE_SLOW);
For LEDs handling is used component led_indicator with led_strip component. For more information, please look into guides for these components.