|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +/******************************************************************************* |
| 8 | + * NOTICE |
| 9 | + * The ll is not public api, don't use in application code. |
| 10 | + * See readme.md in hal/readme.md |
| 11 | + ******************************************************************************/ |
| 12 | + |
| 13 | +#pragma once |
| 14 | + |
| 15 | +#include <stdbool.h> |
| 16 | +#include "soc/soc_caps.h" |
| 17 | +#include "soc/lp_aon_struct.h" |
| 18 | +#include "soc/lpperi_struct.h" |
| 19 | +#include "soc/pmu_struct.h" |
| 20 | +#include "hal/misc.h" |
| 21 | + |
| 22 | +#ifdef __cplusplus |
| 23 | +extern "C" { |
| 24 | +#endif |
| 25 | + |
| 26 | +#define RTCIO_LL_GPIO_NUM_OFFSET 5 // rtcio 0-6 correspond to gpio 5-11 |
| 27 | + |
| 28 | +typedef enum { |
| 29 | + RTCIO_LL_FUNC_RTC = 0x0, /*!< The pin controlled by RTC module. */ |
| 30 | + RTCIO_LL_FUNC_DIGITAL = 0x1, /*!< The pin controlled by DIGITAL module. */ |
| 31 | +} rtcio_ll_func_t; |
| 32 | + |
| 33 | + |
| 34 | +/** |
| 35 | + * @brief Enable/Disable LP_IO peripheral clock. |
| 36 | + * |
| 37 | + * @param enable true to enable the clock / false to disable the clock |
| 38 | + */ |
| 39 | +static inline void _rtcio_ll_enable_io_clock(bool enable) |
| 40 | +{ |
| 41 | + LPPERI.clk_en.lp_io_ck_en = enable; |
| 42 | + while (LPPERI.clk_en.lp_io_ck_en != enable) { |
| 43 | + ; |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +#define rtcio_ll_enable_io_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; _rtcio_ll_enable_io_clock(__VA_ARGS__) |
| 48 | + |
| 49 | +/** |
| 50 | + * @brief Select the rtcio function. |
| 51 | + * |
| 52 | + * @note The RTC function must be selected before the pad analog function is enabled. |
| 53 | + * |
| 54 | + * @param rtcio_num The index of rtcio. 0 ~ MAX(rtcio). |
| 55 | + * @param func Select pin function. |
| 56 | + */ |
| 57 | +static inline void rtcio_ll_function_select(int rtcio_num, rtcio_ll_func_t func) |
| 58 | +{ |
| 59 | + if (func == RTCIO_LL_FUNC_RTC) { |
| 60 | + // 0: GPIO connected to digital GPIO module. 1: GPIO connected to analog RTC module. |
| 61 | + uint32_t sel_mask = HAL_FORCE_READ_U32_REG_FIELD(LP_AON.gpio_mux, aon_gpio_mux_sel); |
| 62 | + sel_mask |= BIT(rtcio_num); |
| 63 | + HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.gpio_mux, aon_gpio_mux_sel, sel_mask); |
| 64 | + } else if (func == RTCIO_LL_FUNC_DIGITAL) { |
| 65 | + // Clear the bit to use digital GPIO module |
| 66 | + uint32_t sel_mask = HAL_FORCE_READ_U32_REG_FIELD(LP_AON.gpio_mux, aon_gpio_mux_sel); |
| 67 | + sel_mask &= ~BIT(rtcio_num); |
| 68 | + HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.gpio_mux, aon_gpio_mux_sel, sel_mask); |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +/** |
| 73 | + * Enable force hold function for an RTC IO pad. |
| 74 | + * |
| 75 | + * Enabling HOLD function will cause the pad to lock current status, such as, |
| 76 | + * input/output enable, input/output value, function, drive strength values. |
| 77 | + * This function is useful when going into light or deep sleep mode to prevent |
| 78 | + * the pin configuration from changing. |
| 79 | + * |
| 80 | + * @param rtcio_num The index of rtcio. 0 ~ MAX(rtcio). |
| 81 | + */ |
| 82 | +static inline void rtcio_ll_force_hold_enable(int rtcio_num) |
| 83 | +{ |
| 84 | + LP_AON.gpio_hold0.gpio_hold0 |= BIT(rtcio_num + RTCIO_LL_GPIO_NUM_OFFSET); |
| 85 | +} |
| 86 | + |
| 87 | +/** |
| 88 | + * Disable hold function on an RTC IO pad |
| 89 | + * |
| 90 | + * @note If disable the pad hold, the status of pad maybe changed in sleep mode. |
| 91 | + * @param rtcio_num The index of rtcio. 0 ~ MAX(rtcio). |
| 92 | + */ |
| 93 | +static inline void rtcio_ll_force_hold_disable(int rtcio_num) |
| 94 | +{ |
| 95 | + LP_AON.gpio_hold0.gpio_hold0 &= ~BIT(rtcio_num + RTCIO_LL_GPIO_NUM_OFFSET); |
| 96 | +} |
| 97 | + |
| 98 | +/** |
| 99 | + * Enable force hold function for all RTC IO pads |
| 100 | + * |
| 101 | + * Enabling HOLD function will cause the pad to lock current status, such as, |
| 102 | + * input/output enable, input/output value, function, drive strength values. |
| 103 | + * This function is useful when going into light or deep sleep mode to prevent |
| 104 | + * the pin configuration from changing. |
| 105 | + */ |
| 106 | +static inline void rtcio_ll_force_hold_all(void) |
| 107 | +{ |
| 108 | + PMU.imm.pad_hold_all.tie_high_lp_pad_hold_all = 1; |
| 109 | +} |
| 110 | + |
| 111 | +/** |
| 112 | + * Disable hold function fon all RTC IO pads |
| 113 | + * |
| 114 | + * @note If disable the pad hold, the status of pad maybe changed in sleep mode. |
| 115 | + */ |
| 116 | +static inline void rtcio_ll_force_unhold_all(void) |
| 117 | +{ |
| 118 | + PMU.imm.pad_hold_all.tie_low_lp_pad_hold_all = 1; |
| 119 | +} |
| 120 | + |
| 121 | +#ifdef __cplusplus |
| 122 | +} |
| 123 | +#endif |
0 commit comments