-
Notifications
You must be signed in to change notification settings - Fork 3
/
pwm.h
53 lines (42 loc) · 1.64 KB
/
pwm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
This file is part of AutoQuad.
AutoQuad is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
AutoQuad is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with AutoQuad. If not, see <http://www.gnu.org/licenses/>.
Copyright © 2014 Bill Nesbitt
*/
#ifndef _pwm_h
#define _pwm_h
#include "stm32f4xx_gpio.h"
#include <stdint.h>
#define pwmDigitalHi(p) { p->port->BSRRL = p->pin; }
#define pwmDigitalLo(p) { p->port->BSRRH = p->pin; }
#define pwmDigitalGet(p) ((p->port->ODR & p->pin) != 0)
enum pwmDirections {
PWM_OUTPUT = 1,
PWM_INPUT
};
typedef void pwmCallback_t(uint32_t, uint8_t);
typedef struct {
volatile uint32_t *ccr;
volatile uint32_t *cnt;
pwmCallback_t *callback;
uint32_t period;
int8_t direction;
GPIO_TypeDef* port;
uint16_t pin;
} pwmPortStruct_t;
extern pwmPortStruct_t *pwmInitOut(uint8_t pwmPort, uint32_t period, uint32_t inititalValue);
extern pwmPortStruct_t *pwmInitDigitalOut(uint8_t pwmPort);
extern pwmPortStruct_t *pwmInitIn(uint8_t pwmPort, int16_t polarity, uint32_t period, pwmCallback_t callback);
extern uint16_t pwmCheckTimer(uint8_t pwmPort);
extern void pwmZeroTimers(void);
extern void pwmDigitalToggle(pwmPortStruct_t *p);
#endif