SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
sys-pwm.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0+ */
2
3#ifndef __SYS_PWM_H__
4#define __SYS_PWM_H__
5
6#include <io.h>
7#include <stdarg.h>
8#include <stdbool.h>
9#include <stddef.h>
10#include <stdint.h>
11#include <types.h>
12
13#include <sys-clk.h>
14#include <sys-gpio.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif// __cplusplus
19
20typedef enum {
21 PWM_PIER = 0x00, /* PWM IRQ enable register */
22 PWM_PISR = 0x04, /* PWM IRQ status register */
23 PWM_CIER = 0x10, /* PWM capture IRQ enable register */
24 PWM_CISR = 0x14, /* PWM capture IRQ status register */
25
26 PWM_PCCR_BASE = 0x20, /* Base address for PWM clock configuration registers */
27 PWM_PCCR01 = 0x20, /* PWM01 clock configuration register */
28 PWM_PCCR23 = 0x24, /* PWM23 clock configuration register */
29 PWM_PCCR45 = 0x28, /* PWM45 clock configuration register */
30 PWM_PCCR67 = 0x2C, /* PWM67 clock configuration register */
31 PWM_PCCR89 = 0x30, /* PWM89 clock configuration register */
32 PWM_PCCRab = 0x34, /* PWMab clock configuration register */
33 PWM_PCCRcd = 0x38, /* PWMcd clock configuration register */
34 PWM_PCCRef = 0x3C, /* PWMef clock configuration register */
35
36 PWM_PCGR = 0x40, /* PWM Clock Gating Register */
37
38 PWM_PDZCR_BASE = 0x60, /* Base address for PWM Dead Zone Control registers */
39 PWM_PDZCR01 = 0x60, /* PWM01 Dead Zone Control Register */
40 PWM_PDZCR23 = 0x64, /* PWM23 Dead Zone Control Register */
41 PWM_PDZCR45 = 0x68, /* PWM45 Dead Zone Control Register */
42 PWM_PDZCR67 = 0x6C, /* PWM67 Dead Zone Control Register */
43 PWM_PDZCR89 = 0x70, /* PWM89 Dead Zone Control Register */
44 PWM_PDZCRab = 0x74, /* PWMad Dead Zone Control Register */
45 PWM_PDZCRcd = 0x78, /* PWMcd Dead Zone Control Register */
46 PWM_PDZCRef = 0x7C, /* PWMef Dead Zone Control Register */
47
48 PWM_PER = 0x80, /* PWM Enable Register */
49
50 PWM_PGR0 = 0x90, /* PWM Group0 Register */
51 PWM_PGR1 = 0x94, /* PWM Group1 Register */
52 PWM_PGR2 = 0x98, /* PWM Group2 Register */
53 PWM_PGR3 = 0x9C, /* PWM Group3 Register */
54
55 PWM_CER = 0xC0, /* PWM Capture Enable Register */
56
57 PWM_PCR = 0x0100, /* PWM Control Register */
58 PWM_PPR = 0x0104, /* PWM Period Register */
59 PWM_PCNTR = 0x0108, /* PWM Counter Register */
60 PWM_PPCNTR = 0x010C, /* PWM Pulse Counter Register */
61 PWM_CCR = 0x0110, /* Capture Control Register */
62 PWM_CRLR = 0x0114, /* Capture Rise Lock Register */
63 PWM_CFLR = 0x0118, /* Capture Fall Lock Register */
64
65 PWM_VR = 0x03F0, /* PWM Version Register */
67
68#define PWM_REG_CHN_OFFSET 0x20
69
70#define PWM_CLK_SRC_SHIFT 0x7
71#define PWM_CLK_SRC_WIDTH 0x2
72
73#define PWM_DIV_M_SHIFT 0x0
74#define PWM_DIV_M_WIDTH 0x4
75
76#define PWM_PRESCAL_SHIFT 0x0
77#define PWM_PRESCAL_WIDTH 0x8
78
79#define PWM_ACT_CYCLES_SHIFT 0x0
80#define PWM_ACT_CYCLES_WIDTH 0x10
81
82#define PWM_PERIOD_CYCLES_SHIFT 0x10
83#define PWM_PERIOD_CYCLES_WIDTH 0x10
84
85#define PWM_CLK_GATING_SHIFT 0x0
86#define PWM_CLK_GATING_WIDTH 0x1
87
88#define PWM_EN_CONTROL_SHIFT 0x0
89#define PWM_EN_CONTORL_WIDTH 0x1
90
91#define PWM_ACT_STA_SHIFT 0x8
92#define PWM_ACT_STA_WIDTH 0x1
93
94#define PWM_DZ_EN_SHIFT 0x0
95#define PWM_DZ_EN_WIDTH 0x1
96
97#define PWM_PDZINTV_SHIFT 0x8
98#define PWM_PDZINTV_WIDTH 0x8
99
100#define PWM_PULSE_SHIFT 0x9
101#define PWM_PULSE_WIDTH 0x1
102
103#define PWM_PULSE_NUM_SHIFT 0x10
104#define PWM_PULSE_NUM_WIDTH 0x10
105
106#define PWM_PULSE_START_SHIFT 0xa
107#define PWM_PULSE_START_WIDTH 0x1
108
109#define PWM_CLK_BYPASS_SHIFT 0x10
110
111#define TIME_1_SECOND 1000000000
112#define PWM_BIND_NUM (2)
113
125
137
149
161
175
186
203
217
226void sunxi_pwm_init(sunxi_pwm_t *pwm);
227
238
252int sunxi_pwm_set_config(sunxi_pwm_t *pwm, int channel, sunxi_pwm_config_t *config);
253
266int sunxi_pwm_release(sunxi_pwm_t *pwm, int channel);
267
268#ifdef __cplusplus
269}
270#endif// __cplusplus
271
272#endif//__SYS_PWM_H__
u32_t uint32_t
Definition stdint.h:13
u8_t uint8_t
Definition stdint.h:7
Definition sys-gpio.h:68
Definition sys-clk.h:17
PWM channel configuration.
Definition sys-pwm.h:169
uint32_t dead_time
Dead time (in nanoseconds) between signal transitions.
Definition sys-pwm.h:172
sunxi_pwm_channel_mode_t channel_mode
The mode of the PWM channel.
Definition sys-pwm.h:173
uint32_t bind_channel
The bind channel ID for multi-channel synchronization.
Definition sys-pwm.h:171
gpio_mux_t pin
GPIO pin used for the PWM signal.
Definition sys-pwm.h:170
PWM clock source configuration.
Definition sys-pwm.h:182
uint32_t clk_src_hosc
The oscillator clock source.
Definition sys-pwm.h:183
uint32_t clk_src_apb
The APB clock source.
Definition sys-pwm.h:184
PWM configuration parameters.
Definition sys-pwm.h:210
sunxi_pwm_polarity_t polarity
The polarity of the PWM signal.
Definition sys-pwm.h:213
uint32_t duty_ns
The duty cycle duration in nanoseconds.
Definition sys-pwm.h:211
sunxi_pwm_mode_t pwm_mode
The mode of operation for the PWM signal.
Definition sys-pwm.h:214
uint32_t pluse_count
The number of pulses in pulse mode operation.
Definition sys-pwm.h:215
uint32_t period_ns
The total period duration in nanoseconds.
Definition sys-pwm.h:212
Main PWM configuration structure.
Definition sys-pwm.h:193
bool status
The operational status of the PWM module (enabled/disabled).
Definition sys-pwm.h:201
sunxi_pwm_clk_src_t clk_src
The clock sources for the PWM module.
Definition sys-pwm.h:200
sunxi_clk_t pwm_clk
The main clock for the PWM module.
Definition sys-pwm.h:199
sunxi_clk_t pwm_bus_clk
Clock for the PWM bus.
Definition sys-pwm.h:198
uint32_t base
The base address of the PWM hardware module.
Definition sys-pwm.h:194
uint8_t id
The PWM module ID.
Definition sys-pwm.h:195
sunxi_pwm_channel_t * channel
Pointer to the array of PWM channels.
Definition sys-pwm.h:196
uint32_t channel_size
The number of PWM channels.
Definition sys-pwm.h:197
struct sunxi_pwm_channel sunxi_pwm_channel_t
PWM channel configuration.
sunxi_pwm_source_t
PWM clock source.
Definition sys-pwm.h:145
@ PWM_CLK_SRC_OSC
Clock source is the oscillator.
Definition sys-pwm.h:146
@ PWM_CLK_SRC_APB
Clock source is the APB bus.
Definition sys-pwm.h:147
void sunxi_pwm_deinit(sunxi_pwm_t *pwm)
Deinitialize the PWM instance.
Definition sys-pwm.c:600
sunxi_pwm_channel_mode_t
PWM channel modes.
Definition sys-pwm.h:157
@ PWM_CHANNEL_BIND
Multi-channel bind mode.
Definition sys-pwm.h:159
@ PWM_CHANNEL_SINGLE
Single-channel PWM mode.
Definition sys-pwm.h:158
struct sunxi_pwm_config sunxi_pwm_config_t
PWM configuration parameters.
sunxi_pwm_mode_t
PWM operation modes.
Definition sys-pwm.h:121
@ PWM_MODE_PLUSE
PWM operates in pulse mode.
Definition sys-pwm.h:123
@ PWM_MODE_CYCLE
PWM operates in cycle mode.
Definition sys-pwm.h:122
sunxi_pwm_reg_offset_t
Definition sys-pwm.h:20
@ PWM_PER
Definition sys-pwm.h:48
@ PWM_PPCNTR
Definition sys-pwm.h:60
@ PWM_CFLR
Definition sys-pwm.h:63
@ PWM_PCCR45
Definition sys-pwm.h:29
@ PWM_PDZCR23
Definition sys-pwm.h:40
@ PWM_CCR
Definition sys-pwm.h:61
@ PWM_PDZCR_BASE
Definition sys-pwm.h:38
@ PWM_PCNTR
Definition sys-pwm.h:59
@ PWM_PDZCRab
Definition sys-pwm.h:44
@ PWM_PCCR23
Definition sys-pwm.h:28
@ PWM_PDZCR89
Definition sys-pwm.h:43
@ PWM_PDZCRef
Definition sys-pwm.h:46
@ PWM_PDZCR67
Definition sys-pwm.h:42
@ PWM_PCCR_BASE
Definition sys-pwm.h:26
@ PWM_PCCRcd
Definition sys-pwm.h:33
@ PWM_PCR
Definition sys-pwm.h:57
@ PWM_PGR3
Definition sys-pwm.h:53
@ PWM_PISR
Definition sys-pwm.h:22
@ PWM_PDZCR45
Definition sys-pwm.h:41
@ PWM_PCCR67
Definition sys-pwm.h:30
@ PWM_CISR
Definition sys-pwm.h:24
@ PWM_CIER
Definition sys-pwm.h:23
@ PWM_PCCRab
Definition sys-pwm.h:32
@ PWM_CER
Definition sys-pwm.h:55
@ PWM_PCCRef
Definition sys-pwm.h:34
@ PWM_PPR
Definition sys-pwm.h:58
@ PWM_PGR2
Definition sys-pwm.h:52
@ PWM_PGR0
Definition sys-pwm.h:50
@ PWM_PGR1
Definition sys-pwm.h:51
@ PWM_VR
Definition sys-pwm.h:65
@ PWM_PDZCRcd
Definition sys-pwm.h:45
@ PWM_PCCR89
Definition sys-pwm.h:31
@ PWM_CRLR
Definition sys-pwm.h:62
@ PWM_PIER
Definition sys-pwm.h:21
@ PWM_PDZCR01
Definition sys-pwm.h:39
@ PWM_PCGR
Definition sys-pwm.h:36
@ PWM_PCCR01
Definition sys-pwm.h:27
void sunxi_pwm_init(sunxi_pwm_t *pwm)
Initialize the PWM instance.
Definition sys-pwm.c:586
sunxi_pwm_polarity_t
PWM signal polarity.
Definition sys-pwm.h:133
@ PWM_POLARITY_NORMAL
Normal PWM signal polarity.
Definition sys-pwm.h:135
@ PWM_POLARITY_INVERSED
Inverted PWM signal polarity.
Definition sys-pwm.h:134
struct sunxi_pwm sunxi_pwm_t
Main PWM configuration structure.
int sunxi_pwm_release(sunxi_pwm_t *pwm, int channel)
Release the PWM channel.
Definition sys-pwm.c:648
int sunxi_pwm_set_config(sunxi_pwm_t *pwm, int channel, sunxi_pwm_config_t *config)
Set configuration for a PWM channel.
Definition sys-pwm.c:618
struct sunxi_pwm_clk_src sunxi_pwm_clk_src_t
PWM clock source configuration.