Split common macros in seperate header
This commit is contained in:
parent
e96258cdb8
commit
7e2007a0ba
9
include/common.h
Normal file
9
include/common.h
Normal 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 */
|
@ -3,10 +3,19 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SET(PORT, PIN) (PORT |= (1 << PIN))
|
||||
#define CLR(PORT, PIN) (PORT &= (~(1 << PIN)))
|
||||
#define CHK(PORT, PIN) (PORT & (1 << PIN))
|
||||
#define TOG(PORT, PIN) (PORT ^= (1 << PIN))
|
||||
#ifndef F_CPU
|
||||
#define F_CPU 1000000UL
|
||||
#endif
|
||||
|
||||
#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_pwm(void);
|
||||
|
10
src/main.c
10
src/main.c
@ -5,16 +5,6 @@
|
||||
#include "main.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)
|
||||
{
|
||||
SERVO_DDR |= _BV(SERVO_L_PIN) | _BV(SERVO_R_PIN);
|
||||
|
Loading…
Reference in New Issue
Block a user