• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
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 
15 #pragma once
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include "hal_config.h"
22 #include "pwm_hw.h"
23 #include "pwm_ll.h"
24 #include <driver/hal/hal_pwm_types.h>
25 
26 typedef struct {
27 	pwm_hw_t *hw;
28 	pwm_unit_t id;
29 } pwm_hal_t;
30 
31 typedef struct {
32 	uint32_t t1;
33 	uint32_t t2;
34 	uint32_t t3;
35 	uint32_t t4;
36 } pwm_hal_config_t;
37 
38 typedef struct {
39 	pwm_capture_edge_t edge;
40 } pwm_hal_capture_config_t;
41 
42 typedef struct {
43 } pwm_hal_timer_config_t;
44 
45 typedef struct {
46 } pwm_hal_int_config_t;
47 
48 bk_err_t pwm_hal_init(pwm_hal_t *hal);
49 
50 bk_err_t pwm_hal_init_pwm(pwm_hal_t *hal, pwm_chan_t chan, const pwm_hal_config_t *config);
51 
52 bk_err_t pwm_hal_start_common(pwm_hal_t *hal, pwm_chan_t chan);
53 bk_err_t pwm_hal_stop_common(pwm_hal_t *hal, pwm_chan_t chan);
54 
55 bk_err_t pwm_hal_init_capture(pwm_hal_t *hal, pwm_chan_t chan, const pwm_hal_capture_config_t *config);
56 #define pwm_hal_get_capture_value(hal, chan) pwm_ll_get_capture_value((hal)->hw, chan)
57 
58 bk_err_t pwm_hal_timer_set_config(pwm_hal_t *hal, pwm_chan_t chan, const pwm_hal_timer_config_t *config);
59 bk_err_t pwm_hal_timer_start(pwm_hal_t *hal, pwm_chan_t chan);
60 bk_err_t pwm_hal_timer_stop(pwm_hal_t *hal, pwm_chan_t chan);
61 
62 #define pwm_hal_set_mode_timer(hal, chan) pwm_ll_set_mode_timer((hal)->hw, chan)
63 #define pwm_hal_enable_interrupt(hal, chan) pwm_ll_enable_interrupt((hal)->hw, chan)
64 #define pwm_hal_disable_interrupt(hal, chan) pwm_ll_disable_interrupt((hal)->hw, chan)
65 #define pwm_hal_get_interrupt_status(hal) pwm_ll_get_interrupt_status((hal)->hw)
66 #define pwm_hal_clear_interrupt_status(hal, status) pwm_ll_clear_interrupt_status((hal)->hw, (status))
67 #define pwm_hal_clear_chan_interrupt_status(hal, chan) pwm_ll_clear_chan_interrupt_status((hal)->hw, (chan))
68 #define pwm_hal_is_interrupt_triggered(hal, chan, status) pwm_ll_is_interrupt_triggered((hal)->hw, (chan), (status))
69 
70 #define pwm_hal_is_chan_started(hal, chan) pwm_ll_is_chan_started((hal)->hw, (chan))
71 
72 #define pwm_hal_set_t1(hal, chan, t1) pwm_ll_set_t1((hal)->hw, (chan), (t1))
73 #define pwm_hal_set_t2(hal, chan, t2) pwm_ll_set_t2((hal)->hw, (chan), (t2))
74 #define pwm_hal_set_t3(hal, chan, t3) pwm_ll_set_t3((hal)->hw, (chan), (t3))
75 #define pwm_hal_set_t4(hal, chan, t4) pwm_ll_set_t4((hal)->hw, (chan), (t4))
76 #define pwm_hal_set_init_signal_low(hal, chan) pwm_ll_set_init_signal_low((hal)->hw, (chan))
77 #define pwm_hal_set_init_signal_high(hal, chan) pwm_ll_set_init_signal_high((hal)->hw, (chan))
78 
79 #define pwm_hal_get_t1(hal, chan) pwm_ll_get_t1((hal)->hw, (chan))
80 #define pwm_hal_get_t4(hal, chan) pwm_ll_get_t4((hal)->hw, (chan))
81 
82 #define pwm_hal_is_duty_valid(period, t1, t2, t3) pwm_ll_is_duty_valid((period), (t1), (t2), (t3))
83 #define pwm_hal_is_capture_edge_valid(edge) pwm_ll_is_capture_edge_valid((edge))
84 
85 #define pwm_hal_reset_config_to_default(hal, chan) pwm_ll_reset_config_to_default((hal)->hw, (chan))
86 #define pwm_hal_load_new_config(hal, chan) pwm_ll_load_new_config((hal)->hw, (chan))
87 
88 #define pwm_hal_is_hardware_group(hal, chan1, chan2) pwm_ll_is_hardware_group((hal)->hw, (chan1), (chan2))
89 #define pwm_hal_start_hardware_group(hal, chan1, chan2) pwm_ll_start_hardware_group((hal)->hw, (chan1), (chan2))
90 #define pwm_hal_stop_hardware_group(hal, chan1, chan2) pwm_ll_stop_hardware_group((hal)->hw, (chan1), (chan2))
91 
92 #define pwm_hal_is_pwm2_interrupt(hal, chan) pwm_ll_is_pwm2_interrupt((hal)->hw, (chan))
93 #if CFG_HAL_DEBUG_PWM
94 void pwm_struct_dump(void);
95 #else
96 #define pwm_struct_dump()
97 #endif
98 
99 #ifdef __cplusplus
100 }
101 #endif
102