• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved.
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 
16 #ifndef _DUET_PWM_H_
17 #define _DUET_PWM_H_
18 #include <stdint.h>
19 
20 #define PWM_OUTPUT_CH0 0
21 #define PWM_OUTPUT_CH1 1
22 #define PWM_OUTPUT_CH2 2
23 #define PWM_OUTPUT_CH3 3
24 #define PWM_OUTPUT_CH4 4
25 #define PWM_OUTPUT_CH5 5
26 #define PWM_OUTPUT_CH6 6
27 #define PWM_OUTPUT_CH7 7
28 #define DUET_PWM_CH_NUM 8
29 
30 typedef struct {
31     float    duty_cycle;  /* the pwm duty_cycle */
32     uint32_t freq;        /* the pwm freq */
33 } duet_pwm_config_t;
34 
35 typedef struct {
36     uint8_t      port;    /* pwm port */
37     duet_pwm_config_t config;  /* spi config */
38     void        *priv;    /* priv data */
39 } duet_pwm_dev_t;
40 
41 /**
42  * Initialises a PWM pin
43  *
44  *
45  * @param[in]  pwm  the PWM device
46  *
47  * @return  0 : on success, EIO : if an error occurred with any step
48  */
49 int32_t duet_pwm_init(duet_pwm_dev_t *pwm);
50 
51 /**
52  * Starts Pulse-Width Modulation signal output on a PWM pin
53  *
54  * @param[in]  pwm  the PWM device
55  *
56  * @return  0 : on success, EIO : if an error occurred with any step
57  */
58 int32_t duet_pwm_start(duet_pwm_dev_t *pwm);
59 
60 /**
61  * Stops output on a PWM pin
62  *
63  * @param[in]  pwm  the PWM device
64  *
65  * @return  0 : on success, EIO : if an error occurred with any step
66  */
67 int32_t duet_pwm_stop(duet_pwm_dev_t *pwm);
68 
69 /**
70  * change the para of pwm
71  *
72  * @param[in]  pwm  the PWM device
73  * @param[in]  para the para of pwm
74  *
75  * @return  0 : on success, EIO : if an error occurred with any step
76  */
77 int32_t duet_pwm_para_chg(duet_pwm_dev_t *pwm, duet_pwm_config_t para);
78 
79 /**
80  * De-initialises an PWM interface, Turns off an PWM hardware interface
81  *
82  * @param[in]  pwm  the interface which should be de-initialised
83  *
84  * @return  0 : on success, EIO : if an error occurred with any step
85  */
86 int32_t duet_pwm_finalize(duet_pwm_dev_t *pwm);
87 
88 #endif // _DUET_PWM_H_