pihwm
A lightweight C library for Raspberry Pi hardware modules.
Main Page
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Groups
Pages
pi_pwm.h
Go to the documentation of this file.
1
28
#ifndef PI_PWM_H
29
#define PI_PWM_H
30
31
32
#define BCM2708_PERI_BASE 0x20000000
33
#define CLOCK_BASE (BCM2708_PERI_BASE + 0x101000)
/* Clocks */
34
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000)
/* GPIO */
35
#define PWM_BASE (BCM2708_PERI_BASE + 0x20C000)
/* PWM */
36
37
/* PWM Registers */
38
#define GPIO_SET0 *(gpio+7)
/* Set GPIO high bits 0-31 */
39
#define GPIO_SET1 *(gpio+8)
/* Set GPIO high bits 32-53 */
40
41
#define GPIO_CLR0 *(gpio+10)
/* Set GPIO low bits 0-31 */
42
#define GPIO_CLR1 *(gpio+11)
/* Set GPIO low bits 32-53 */
43
44
#define PWMCLK_CNTL *(clk+40)
45
#define PWMCLK_DIV *(clk+41)
46
47
#define PWM_CONTROL *pwm
48
#define PWM_STATUS *(pwm+1)
49
#define PWM0_RANGE *(pwm+4)
50
#define PWM1_RANGE *(pwm+8)
51
#define PWM0_DATA *(pwm+5)
52
#define PWM1_DATA *(pwm+9)
53
54
/* PWM Control register bits */
55
#define PWM1_MS_MODE 0x8000
/* Run in MS mode */
56
#define PWM1_USEFIFO 0x2000
/* Data from FIFO */
57
#define PWM1_REVPOLAR 0x1000
/* Reverse polarity */
58
#define PWM1_OFFSTATE 0x0800
/* Ouput Off state */
59
#define PWM1_REPEATFF 0x0400
/* Repeat last value if FIFO empty */
60
#define PWM1_SERIAL 0x0200
/* Run in serial mode */
61
#define PWM1_ENABLE 0x0100
/* Channel Enable */
62
63
#define PWM0_MS_MODE 0x0080
/* Run in MS mode */
64
#define PWM0_USEFIFO 0x0020
/* Data from FIFO */
65
#define PWM0_REVPOLAR 0x0010
/* Reverse polarity */
66
#define PWM0_OFFSTATE 0x0008
/* Ouput Off state */
67
#define PWM0_REPEATFF 0x0004
/* Repeat last value if FIFO empty */
68
#define PWM0_SERIAL 0x0002
/* Run in serial mode */
69
#define PWM0_ENABLE 0x0001
/* Channel Enable */
70
71
#define PWM_CLRFIFO 0x0040
/* Clear FIFO (Self clearing bit) */
72
73
/* PWM status bits I need */
74
#define PWMS_BUSERR 0x0100
/* Register access was too fast */
75
/* (Write to clear it) */
76
77
78
#define PAGE_SIZE (4*1024)
79
#define BLOCK_SIZE (4*1024)
80
81
82
/* GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y) */
83
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
84
#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3))
85
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
86
87
#define GPIO_SET0 *(gpio+7)
/* Set GPIO high bits 0-31 */
88
#define GPIO_SET1 *(gpio+8)
/* Set GPIO high bits 32-53 */
89
90
#define GPIO_CLR0 *(gpio+10)
/* Set GPIO low bits 0-31 */
91
#define GPIO_CLR1 *(gpio+11)
/* Set GPIO low bits 32-53 */
92
#define GPIO_PULL *(gpio+37)
/* Pull up/pull down */
93
#define GPIO_PULLCLK0 *(gpio+38)
/* Pull up/pull down clock */
94
95
96
/* I/O access */
97
98
// Range for the PWM module
99
const
unsigned
int
PWM_MAX = 1024;
100
101
// FIXME: Remove these?
102
volatile
unsigned
int
*gpio;
103
volatile
unsigned
int
*pwm;
104
volatile
unsigned
int
*clk;
105
106
int
pwm_init
();
107
void
pwm_mode
(
unsigned
int
mode);
108
void
pwm_value
(
unsigned
int
value);
109
void
pwm_release
();
110
111
#endif
lib
pi_pwm.h
Generated on Wed Apr 17 2013 23:40:57 for pihwm by
1.8.2