summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Baumann <derflob@derflob.de>2014-11-05 22:41:37 +0100
committerFlorian Baumann <derflob@derflob.de>2014-11-05 22:41:37 +0100
commit5db4465944129256042804dd23342c645199d1d9 (patch)
tree012f2d2834d02ffa02005df54efb370f01d8d06f
parentf82152da8f4edf47c16ace8f769d6c1bd19e4a11 (diff)
downloadStripClock-5db4465944129256042804dd23342c645199d1d9.tar.gz
StripClock-5db4465944129256042804dd23342c645199d1d9.tar.bz2
cleanup
-rw-r--r--StripClock.c37
-rw-r--r--ds1307.c26
-rw-r--r--ds1307.h1
3 files changed, 21 insertions, 43 deletions
diff --git a/StripClock.c b/StripClock.c
index 060f01b..7b48fa0 100644
--- a/StripClock.c
+++ b/StripClock.c
@@ -6,11 +6,13 @@
#include "ds1307.h"
#include "light_ws2812.h"
-#define ENC_RESOLUTION 4
-const int8_t rotary_states[][4] = { { 0, -1, +1, 0 },
- { +1, 0, 0, -1 },
- { -1, 0, 0, +1 },
- { 0, +1, -1, 0 } };
+#define ROTARY_RESOLUTION 4
+const int8_t rotary_states[][4] = {
+ { 0, -1, +1, 0 },
+ { +1, 0, 0, -1 },
+ { -1, 0, 0, +1 },
+ { 0, +1, -1, 0 }
+};
enum display_mode {
DM_NONE,
@@ -127,26 +129,8 @@ ISR(INT0_vect)
}
}
-/*
-ISR(PCINT0_vect)
-{
- //debounce rotary encoder
- GIMSK &= ~(1 << PCIE0);
- //ctc mode, prescale 1024, 1.25ms, @8MHz
- TCCR1A = 0;
- TCCR1B = (1 << WGM12) | (1 << CS12) | (1 << CS10);
- OCR1A = 10;
- TIMSK |= (1 << OCIE1A);
-}
-*/
-
ISR(PCINT0_vect)
{
- //disable this interrupt aa
- //TIMSK &= ~(1 << OCIE1A);
- //enable pcint for rotary encoder
- //GIMSK |= (1 << PCIE0);
-
static uint8_t state = 0;
static int8_t delta = 0;
@@ -155,7 +139,7 @@ ISR(PCINT0_vect)
delta += rotary_states[state][new_state];
state = new_state;
- if (delta == ENC_RESOLUTION || delta == -ENC_RESOLUTION) {
+ if (delta == ROTARY_RESOLUTION || delta == -ROTARY_RESOLUTION) {
delta > 0 ? rotary_updated-- : rotary_updated++;
delta = 0;
}
@@ -169,7 +153,6 @@ ISR(PCINT0_vect)
uint8_t updateStripEncoder(void)
{
-
switch (mode) {
case DM_HOUR:
memset(leds, 0, sizeof(struct cRGB) * LEDS);
@@ -234,7 +217,6 @@ uint8_t updateStripEncoder(void)
uint8_t updateStripSimple(void)
{
-
memset(leds, 0, LEDS * sizeof(struct cRGB));
leds[dt.hour].r = 255;
@@ -251,10 +233,11 @@ uint8_t updateStrip(void)
if (brightness < 0) {
memset(leds, 0, sizeof(struct cRGB) * LEDS);
ws2812_setleds(leds, LEDS);
+
return 0;
}
- uint8_t hour_led = ((dt.hour % 12) * (LEDS/12)) - 1;
+ uint8_t hour_led = ((dt.hour % 12) * (LEDS / 12)) - 1;
if (hour_led == -1)
hour_led = 59;
diff --git a/ds1307.c b/ds1307.c
index e78f24a..17b9ef5 100644
--- a/ds1307.c
+++ b/ds1307.c
@@ -1,27 +1,23 @@
#include "i2cmaster.h"
#include "ds1307.h"
-static uint8_t bcd_dec(uint8_t bcd);
-static uint8_t dec_bcd(uint8_t dec);
-static uint8_t ds1307_init_rw(unsigned char reg);
-static uint8_t ds1307_init_write(unsigned char reg);
-static uint8_t ds1307_init_read(unsigned char reg);
+static inline uint8_t bcd_dec(uint8_t bcd);
+static inline uint8_t dec_bcd(uint8_t dec);
+static inline uint8_t ds1307_init_rw(unsigned char reg);
+static inline uint8_t ds1307_init_write(unsigned char reg);
+static inline uint8_t ds1307_init_read(unsigned char reg);
-static uint8_t bcd_dec(uint8_t bcd)
+static inline uint8_t bcd_dec(uint8_t bcd)
{
return ((10 * ((bcd & 0xF0) >> 4)) + (bcd & 0x0F));
}
-
-static uint8_t dec_bcd(uint8_t dec)
+static inline uint8_t dec_bcd(uint8_t dec)
{
return (((dec / 10) << 4) | dec % 10);
}
-#define BCD2DEC(x) (10 * (((x) & 0xF0) >> 4) + ((x) & 0x0F))
-#define DEC2BCD(x) ((((x) / 10) << 4) | ((x) % 10))
-
-static uint8_t ds1307_init_rw(unsigned char reg)
+static inline uint8_t ds1307_init_rw(unsigned char reg)
{
i2c_start_wait(DS1307_ADDR + I2C_WRITE);
i2c_write(reg);
@@ -29,12 +25,12 @@ static uint8_t ds1307_init_rw(unsigned char reg)
}
-static uint8_t ds1307_init_write(unsigned char reg)
+static inline uint8_t ds1307_init_write(unsigned char reg)
{
return ds1307_init_rw(reg);
}
-static uint8_t ds1307_init_read(unsigned char reg)
+static inline uint8_t ds1307_init_read(unsigned char reg)
{
ds1307_init_rw(reg);
i2c_rep_start(DS1307_ADDR + I2C_READ);
@@ -46,6 +42,7 @@ uint8_t ds1307_start(void)
//set 24 hour mode
ds1307_init_read(0x02);
unsigned char hour = i2c_readNak();
+ i2c_stop();
hour &= ~(1 << DS1307_BIT_AMPM);
ds1307_init_write(0x02);
i2c_write(hour);
@@ -75,7 +72,6 @@ uint8_t ds1307_halt(uint8_t halted)
return 0;
}
-
uint8_t ds1307_getDateTime(struct datetime* dt)
{
ds1307_init_read(0x00);
diff --git a/ds1307.h b/ds1307.h
index fb24b2b..2e0cf74 100644
--- a/ds1307.h
+++ b/ds1307.h
@@ -30,5 +30,4 @@ uint8_t ds1307_SQWRate(enum SQWRate rate);
uint8_t ds1307_getDateTime(struct datetime* dt);
uint8_t ds1307_setDateTime(struct datetime* dt);
-
#endif