Improve bit manipulation macros

This commit is contained in:
Rihards Skuja 2018-01-02 19:14:50 +02:00
parent c21e086460
commit b74f68994d
No known key found for this signature in database
GPG Key ID: 53FA13A3F7F8571B
3 changed files with 13 additions and 10 deletions

View File

@ -1,9 +1,12 @@
#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)
#include <stdint.h>
#define BIT(mask) (1 << (mask))
#define SET(var, mask) ((var) |= (uint8_t)BIT(mask))
#define CLR(var, mask) ((var) &= (uint8_t)~(BIT(mask)))
#define CHK(var, mask) ((var) & (uint8_t)BIT(mask))
#define TOG(var, mask) ((var) ^= (uint8_t)BIT(mask)
#endif /* COMMON_H */

View File

@ -6,13 +6,13 @@ volatile uint32_t overflow_counter = 0;
volatile uint32_t trig_counter = 0;
volatile uint32_t no_of_cycles = 0;
void init_sonar()
void init_sonar(void)
{
SET(TRIG_DDR, TRIG_BIT);
CLR(ECHO_DDR, ECHO_BIT);
}
void trigger_sonar()
void trigger_sonar(void)
{
CLR(TRIG_PORT, TRIG_BIT);
_delay_us(1);
@ -28,7 +28,7 @@ ISR(TIMER1_OVF_vect)
TCNT1 = 0;
}
int read_sonar()
int read_sonar(void)
{
int dist_in_cm = 0;
init_sonar();

View File

@ -16,7 +16,7 @@ Please refer to LICENSE file for licensing information.
/*
* ds18b20 init
*/
uint8_t ds18b20_reset()
uint8_t ds18b20_reset(void)
{
uint8_t i;
@ -53,7 +53,7 @@ void ds18b20_writebit(uint8_t bit)
// wait 60uS and release the line
_delay_us(60);
DS18B20_DDR &= ~(1 << DS18B20_BIT);
CLR(DS18B20_DDR, DS18B20_BIT);
}
/*
@ -109,7 +109,7 @@ uint8_t ds18b20_readbyte(void)
/*
* get temperature
*/
double ds18b20_gettemp()
double ds18b20_gettemp(void)
{
uint8_t temperature_l;
uint8_t temperature_h;