1 // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #pragma once
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #include <stdint.h>
21 #include <stdbool.h>
22 #include "soc/dedic_gpio_struct.h"
23
dedic_gpio_ll_enable_instruction_access_out(dedic_dev_t * dev,uint32_t channel_mask,bool enable)24 static inline void dedic_gpio_ll_enable_instruction_access_out(dedic_dev_t *dev, uint32_t channel_mask, bool enable)
25 {
26 if (enable) {
27 dev->gpio_out_cpu.val |= channel_mask;
28 } else {
29 dev->gpio_out_cpu.val &= ~channel_mask;
30 }
31 }
32
dedic_gpio_ll_write_all(dedic_dev_t * dev,uint32_t value)33 static inline void dedic_gpio_ll_write_all(dedic_dev_t *dev, uint32_t value)
34 {
35 dev->gpio_out_drt.val = value;
36 }
37
dedic_gpio_ll_write_mask(dedic_dev_t * dev,uint32_t channel_mask,uint32_t value)38 static inline void dedic_gpio_ll_write_mask(dedic_dev_t *dev, uint32_t channel_mask, uint32_t value)
39 {
40 dedic_gpio_out_msk_reg_t d = {
41 .gpio_out_msk = channel_mask,
42 .gpio_out_value = value
43 };
44 dev->gpio_out_msk.val = d.val;
45 }
46
dedic_gpio_ll_set_channel(dedic_dev_t * dev,uint32_t channel)47 static inline void dedic_gpio_ll_set_channel(dedic_dev_t *dev, uint32_t channel)
48 {
49 dev->gpio_out_idv.val = 1 << (2 * channel);
50 }
51
dedic_gpio_ll_clear_channel(dedic_dev_t * dev,uint32_t channel)52 static inline void dedic_gpio_ll_clear_channel(dedic_dev_t *dev, uint32_t channel)
53 {
54 dev->gpio_out_idv.val = 2 << (2 * channel);
55 }
56
dedic_gpio_ll_toggle_channel(dedic_dev_t * dev,uint32_t channel)57 static inline void dedic_gpio_ll_toggle_channel(dedic_dev_t *dev, uint32_t channel)
58 {
59 dev->gpio_out_idv.val = 3 << (2 * channel);
60 }
61
dedic_gpio_ll_read_out_all(dedic_dev_t * dev)62 static inline uint32_t dedic_gpio_ll_read_out_all(dedic_dev_t *dev)
63 {
64 return dev->gpio_out_scan.gpio_out_status;
65 }
66
dedic_gpio_ll_read_in_all(dedic_dev_t * dev)67 static inline uint32_t dedic_gpio_ll_read_in_all(dedic_dev_t *dev)
68 {
69 return dev->gpio_in_scan.gpio_in_status;
70 }
71
dedic_gpio_ll_set_input_delay(dedic_dev_t * dev,uint32_t channel,uint32_t delay_cpu_clks)72 static inline void dedic_gpio_ll_set_input_delay(dedic_dev_t *dev, uint32_t channel, uint32_t delay_cpu_clks)
73 {
74 dev->gpio_in_dly.val &= ~(3 << (2 * channel));
75 dev->gpio_in_dly.val |= (delay_cpu_clks & 0x03) << (2 * channel);
76 }
77
dedic_gpio_ll_get_input_delay(dedic_dev_t * dev,uint32_t channel)78 static inline uint32_t dedic_gpio_ll_get_input_delay(dedic_dev_t *dev, uint32_t channel)
79 {
80 return (dev->gpio_in_dly.val & (3 << (2 * channel)) >> (2 * channel));
81 }
82
dedic_gpio_ll_set_interrupt_type(dedic_dev_t * dev,uint32_t channel,uint32_t type)83 static inline void dedic_gpio_ll_set_interrupt_type(dedic_dev_t *dev, uint32_t channel, uint32_t type)
84 {
85 dev->gpio_intr_rcgn.val &= ~(7 << (3 * channel));
86 dev->gpio_intr_rcgn.val |= (type & 0x07) << (3 * channel);
87 }
88
dedic_gpio_ll_enable_interrupt(dedic_dev_t * dev,uint32_t channel_mask,bool enable)89 static inline void dedic_gpio_ll_enable_interrupt(dedic_dev_t *dev, uint32_t channel_mask, bool enable)
90 {
91 if (enable) {
92 dev->gpio_intr_rls.val |= channel_mask;
93 } else {
94 dev->gpio_intr_rls.val &= ~channel_mask;
95 }
96 }
97
dedic_gpio_ll_get_interrupt_status(dedic_dev_t * dev)98 static inline uint32_t __attribute__((always_inline)) dedic_gpio_ll_get_interrupt_status(dedic_dev_t *dev)
99 {
100 return dev->gpio_intr_st.val;
101 }
102
dedic_gpio_ll_clear_interrupt_status(dedic_dev_t * dev,uint32_t channel_mask)103 static inline void __attribute__((always_inline)) dedic_gpio_ll_clear_interrupt_status(dedic_dev_t *dev, uint32_t channel_mask)
104 {
105 dev->gpio_intr_clr.val = channel_mask;
106 }
107
108 #ifdef __cplusplus
109 }
110 #endif
111