Split common macros in seperate header

This commit is contained in:
Rihards Skuja 2018-01-02 13:45:56 +02:00
parent e96258cdb8
commit 7e2007a0ba
No known key found for this signature in database
GPG Key ID: 53FA13A3F7F8571B
3 changed files with 22 additions and 14 deletions

9
include/common.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef COMMON_H
#define COMMON_H
#define SET(X, Y) X |= (1 << Y)
#define CLR(X, Y) X &= ~(1 << Y)
#define CHK(X, Y) X & (1 << Y)
#define TOG(X, Y) X ^= (1 << Y)
#endif /* COMMON_H */

View File

@ -3,10 +3,19 @@
#include <stdint.h> #include <stdint.h>
#define SET(PORT, PIN) (PORT |= (1 << PIN)) #ifndef F_CPU
#define CLR(PORT, PIN) (PORT &= (~(1 << PIN))) #define F_CPU 1000000UL
#define CHK(PORT, PIN) (PORT & (1 << PIN)) #endif
#define TOG(PORT, PIN) (PORT ^= (1 << PIN))
#ifdef DEBUG
#include "debug.h"
#endif /* DEBUG */
#define SERVO_MIN 930 // (us). Go backwards
#define SERVO_MAX 1930 // (us). Go forwards
#define SERVO_MID (SERVO_MIN + SERVO_MAX) / 2 // Stop
#define PWM_PERIOD 16384 // (1000000 / F_CPU) * PRESCALER * 256) / F_CPU (us)
#define US2TIMER0(us) (255 * (uint32_t)us) / PWM_PERIOD
void init_led(void); void init_led(void);
void init_pwm(void); void init_pwm(void);

View File

@ -5,16 +5,6 @@
#include "main.h" #include "main.h"
#include "io.h" #include "io.h"
#ifdef DEBUG
#include "debug.h"
#endif /* DEBUG */
#define SERVO_MIN 930 // (us). Go backwards
#define SERVO_MAX 1930 // (us). Go forwards
#define SERVO_MID (SERVO_MIN + SERVO_MAX) / 2 // Stop
#define PWM_PERIOD 16384 // (1000000 / F_CPU) * PRESCALER * 256) / F_CPU (us)
#define US2TIMER0(us) (255 * (uint32_t)us) / PWM_PERIOD
void init_pwm(void) void init_pwm(void)
{ {
SERVO_DDR |= _BV(SERVO_L_PIN) | _BV(SERVO_R_PIN); SERVO_DDR |= _BV(SERVO_L_PIN) | _BV(SERVO_R_PIN);