VSF Documented
vsf_espidf.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_ESPIDF_INTERNAL_H__
19#define __VSF_ESPIDF_INTERNAL_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "kernel/vsf_kernel.h"
24#include "hal/driver/driver.h"
25#include "./vsf_espidf_cfg.h"
26
27#if VSF_USE_ESPIDF == ENABLED
28
29#if VSF_ESPIDF_CFG_USE_PARTITION == ENABLED
32#endif
33
34#if VSF_ESPIDF_CFG_USE_ESP_FLASH == ENABLED
36# include "./include/esp_flash.h"
37#endif
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/*============================ MACROS ========================================*/
44/*============================ TYPES =========================================*/
45
46// Sub-system configuration (pure input). The ESP-IDF compatibility shim is
47// a process-wide singleton (esp_* APIs are global functions without an
48// instance handle), so configuration is passed by value: the caller fills
49// a cfg struct, hands it to vsf_espidf_init(), and the shim copies the
50// fields it needs into its own internal state. The cfg object does not
51// need to outlive the init call and may live on the stack.
52//
53// Field semantics:
54// rng Externally owned RNG source (commonly a vsf_multiplex_rng_t
55// instance cast to vsf_rng_t*). NULL -> the shim falls back to a
56// software PRNG for esp_random / esp_fill_random.
57#if VSF_ESPIDF_CFG_USE_PARTITION == ENABLED
58// One entry in the compile-time partition table. The shim slices the
59// configured root_mal at [offset, offset+size) into a vk_mim_mal_t on
60// boot and publishes it as a matching esp_partition_t. All offsets and
61// sizes are byte units; erase_size defaults to the root mal's natural
62// erase block when set to 0.
64 const char *label;
65 uint8_t type; // esp_partition_type_t
66 uint8_t subtype; // esp_partition_subtype_t
71 uint32_t erase_size; // 0 -> auto-detect via vk_mal_blksz
73
74// Partition sub-system configuration. root_mal is user-owned and MUST
75// outlive the sub-system. The shim never allocates, opens or closes
76// root_mal on behalf of the caller; the expected contract is that the
77// caller has already called vk_mal_init() on it from a stack-owner
78// thread (vsf_thread_t) so that it is in a usable state before being
79// handed over.
85#endif
86
87#if VSF_ESPIDF_CFG_USE_DRIVER_UART == ENABLED
88// uart sub-system configuration.
89//
90// Same pool-injection pattern as gptimer: the caller provides an array
91// of vsf_usart_t* instances. uart_port_t values (UART_NUM_0, 1, ...)
92// index directly into the pool.
93typedef struct vsf_espidf_uart_cfg_t {
97#endif
98
99#if VSF_ESPIDF_CFG_USE_DRIVER_I2C == ENABLED
100// i2c sub-system configuration.
101//
102// Same pool-injection pattern as gptimer / uart: the caller provides an
103// array of vsf_i2c_t* instances. i2c_port_num_t values (0, 1, ...)
104// index directly into the pool.
105typedef struct vsf_espidf_i2c_cfg_t {
109#endif
110
111#if VSF_ESPIDF_CFG_USE_DRIVER_SPI_MASTER == ENABLED
112// spi_master sub-system configuration.
113//
114// Same pool-injection pattern as gptimer / uart / i2c: the caller
115// provides an array of vsf_spi_t* instances. spi_host_device_t values
116// (SPI1_HOST, SPI2_HOST, ...) index directly into the pool.
117typedef struct vsf_espidf_spi_cfg_t {
121#endif
122
123#if VSF_ESPIDF_CFG_USE_DRIVER_LEDC == ENABLED
124// ledc sub-system configuration.
125//
126// Pool index equals ledc_mode_t: entry 0 -> LEDC_LOW_SPEED_MODE,
127// entry 1 (optional) -> LEDC_HIGH_SPEED_MODE. Each vsf_pwm_t is
128// shared by all channels of its speed_mode.
129typedef struct vsf_espidf_ledc_cfg_t {
133#endif
134
135#if VSF_ESPIDF_CFG_USE_DRIVER_ADC == ENABLED
136// adc (oneshot) sub-system configuration.
137//
138// Pool index equals adc_unit_t: entry 0 -> ADC_UNIT_1, entry 1 ->
139// ADC_UNIT_2. Only one-shot mode is bridged; callers requiring
140// continuous/DMA mode will receive ESP_ERR_NOT_SUPPORTED.
141typedef struct vsf_espidf_adc_cfg_t {
145#endif
146
147#if VSF_ESPIDF_CFG_USE_DRIVER_GPTIMER == ENABLED
148// gptimer sub-system configuration.
149//
150// ESP-IDF's gptimer_new_timer() allocates a timer handle opaquely
151// (the caller does not choose which hardware timer to use). To bridge
152// this onto VSF -- where each vsf_timer_t* is board/MCU-owned and
153// statically defined at BSP time -- the caller hands in an array of
154// pointers to vsf_timer_t instances that the shim may draw from.
155//
156// pool Array of vsf_timer_t* already brought up by the board
157// BSP. The shim neither initialises nor finalises these
158// instances itself; it only calls vsf_timer_init() /
159// vsf_timer_fini() on them when a gptimer handle is
160// allocated / released. Ownership stays with the caller.
161// pool_count Number of entries in pool.
162//
163// A zero-initialised cfg (pool=NULL, pool_count=0) disables gptimer_*
164// allocation entirely; gptimer_new_timer() then returns
165// ESP_ERR_INVALID_STATE.
170#endif
171
172typedef struct vsf_espidf_cfg_t {
173#if VSF_HAL_USE_RNG == ENABLED
175#endif
176#if VSF_ESPIDF_CFG_USE_PARTITION == ENABLED
178#endif
179#if VSF_ESPIDF_CFG_USE_DRIVER_GPTIMER == ENABLED
181#endif
182#if VSF_ESPIDF_CFG_USE_DRIVER_UART == ENABLED
184#endif
185#if VSF_ESPIDF_CFG_USE_DRIVER_I2C == ENABLED
187#endif
188#if VSF_ESPIDF_CFG_USE_DRIVER_SPI_MASTER == ENABLED
190#endif
191#if VSF_ESPIDF_CFG_USE_DRIVER_LEDC == ENABLED
193#endif
194#if VSF_ESPIDF_CFG_USE_DRIVER_ADC == ENABLED
196#endif
198
199/*============================ GLOBAL VARIABLES ==============================*/
200/*============================ PROTOTYPES ====================================*/
201
202// Sub-system lifecycle. Idempotent: subsequent calls are no-ops. Passing
203// NULL is permitted and equivalent to a zero-initialised cfg (all
204// peripherals left unset, shim uses built-in fallbacks).
205extern void vsf_espidf_init(const vsf_espidf_cfg_t *cfg);
206
207#if VSF_HAL_USE_RNG == ENABLED
208// Accessor used by internal port code. Returns the RNG source registered
209// via vsf_espidf_init(), or NULL if none was provided (callers should
210// fall back to their own default).
211extern vsf_rng_t * vsf_espidf_get_rng(void);
212#endif
213
214#ifdef __cplusplus
215}
216#endif
217
218#endif // VSF_USE_ESPIDF
219#endif // __VSF_ESPIDF_INTERNAL_H__
mal class
Definition vsf_mal.h:168
unsigned short uint16_t
Definition stdint.h:7
unsigned uint32_t
Definition stdint.h:9
unsigned char uint8_t
Definition stdint.h:5
Definition vsf_template_adc.h:755
Definition vsf_espidf.h:141
vsf_adc_t *const * pool
Definition vsf_espidf.h:142
uint16_t pool_count
Definition vsf_espidf.h:143
Definition vsf_espidf.h:172
vsf_espidf_i2c_cfg_t i2c
Definition vsf_espidf.h:186
vsf_espidf_ledc_cfg_t ledc
Definition vsf_espidf.h:192
vsf_espidf_partition_cfg_t partition
Definition vsf_espidf.h:177
vsf_rng_t * rng
Definition vsf_espidf.h:174
vsf_espidf_adc_cfg_t adc
Definition vsf_espidf.h:195
vsf_espidf_gptimer_cfg_t gptimer
Definition vsf_espidf.h:180
vsf_espidf_uart_cfg_t uart
Definition vsf_espidf.h:183
vsf_espidf_spi_cfg_t spi
Definition vsf_espidf.h:189
Definition vsf_espidf.h:166
uint16_t pool_count
Definition vsf_espidf.h:168
vsf_timer_t *const * pool
Definition vsf_espidf.h:167
Definition vsf_espidf.h:105
uint16_t pool_count
Definition vsf_espidf.h:107
vsf_i2c_t *const * pool
Definition vsf_espidf.h:106
Definition vsf_espidf.h:129
vsf_pwm_t *const * pool
Definition vsf_espidf.h:130
uint16_t pool_count
Definition vsf_espidf.h:131
Definition vsf_espidf.h:80
const vsf_espidf_partition_entry_t * entries
Definition vsf_espidf.h:82
uint16_t entry_count
Definition vsf_espidf.h:83
vk_mal_t * root_mal
Definition vsf_espidf.h:81
Definition vsf_espidf.h:63
uint32_t erase_size
Definition vsf_espidf.h:71
uint8_t type
Definition vsf_espidf.h:65
const char * label
Definition vsf_espidf.h:64
uint8_t encrypted
Definition vsf_espidf.h:67
uint8_t readonly
Definition vsf_espidf.h:68
uint8_t subtype
Definition vsf_espidf.h:66
uint32_t offset
Definition vsf_espidf.h:69
uint32_t size
Definition vsf_espidf.h:70
Definition vsf_espidf.h:117
vsf_spi_t *const * pool
Definition vsf_espidf.h:118
uint16_t pool_count
Definition vsf_espidf.h:119
Definition vsf_espidf.h:93
vsf_usart_t *const * pool
Definition vsf_espidf.h:94
uint16_t pool_count
Definition vsf_espidf.h:95
I2C instance structure for multi-class support.
Definition vsf_template_i2c.h:1056
Definition vsf_template_pwm.h:274
Definition vsf_template_rng.h:197
SPI instance structure, used for SPI Multi Class support, not needed in non Multi Class mode.
Definition vsf_template_spi.h:1131
Definition vsf_template_timer.h:754
USART instance structure Used for USART Multi Class support.
Definition vsf_template_usart.h:1138
vsf_rng_t * vsf_espidf_get_rng(void)
Definition vsf_espidf.c:131
void vsf_espidf_init(const vsf_espidf_cfg_t *cfg)
Definition vsf_espidf.c:48
Generated from commit: vsfteam/vsf@015f4d1