add unified compile target
[avr_work.git] / lline / motor.h
blobfc4d39cc8c619fb828067292f89007512cca2463
1 #ifndef _MOTOR_H_
2 #define _MOTOR_H_
4 #include <stdint.h>
6 // Types
7 #define MOTOR_SPEED_MAX 0x3FF
8 typedef int16_t motor_speed_t; //only 11 bits used, 10+sign
9 typedef uint16_t motor_uspeed_t;
11 struct pin_s {
12 volatile uint8_t * const port;
13 const uint8_t mask;
16 typedef struct motor_s {
17 volatile uint8_t * const reg_pwm;
18 volatile uint8_t * const reg_pwmh;
19 const struct pin_s pin[2];
20 } motor_t;
22 // Motor structure constructor
23 #define MOTOR_DEF(reg, port1, index1, port2, index2) \
24 { \
25 .reg_pwm = &reg, \
26 .reg_pwmh= &TC1H, \
27 .pin[0].port = &port1, \
28 .pin[1].port = &port2, \
29 .pin[0].mask = (uint8_t) ( 1 << (index1) ), \
30 .pin[1].mask = (uint8_t) ( 1 << (index2) ) \
33 // Functions
34 void motor_init(void);
36 void motor_set(motor_t *motor, motor_speed_t value);
37 motor_speed_t motor_get(motor_t *motor);
39 #endif