Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #43 from venustrg/hourly_chime
Browse files Browse the repository at this point in the history
added hourly chime support
  • Loading branch information
zerog2k authored Dec 16, 2019
2 parents c4c2c8d + 4d935b8 commit 6f17503
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 70 deletions.
26 changes: 24 additions & 2 deletions src/ds1302.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ void ds_alarm_minutes_incr() {
}

void ds_alarm_hours_incr() {
uint8_t hh = cfg_table[CFG_ALARM_HOURS_BYTE] >> 3;
uint8_t hh = cfg_table[CFG_ALARM_HOURS_BYTE] >> CFG_ALARM_HOURS_SHIFT;
INCR(hh, 0, 23);
hh <<= 3;
hh <<= CFG_ALARM_HOURS_SHIFT;
cfg_table[CFG_ALARM_HOURS_BYTE] &= ~CFG_ALARM_HOURS_MASK;
cfg_table[CFG_ALARM_HOURS_BYTE] |= hh;
ds_ram_config_write();
Expand All @@ -275,6 +275,28 @@ void ds_alarm_on_toggle() {
ds_ram_config_write();
}

void ds_chime_since_incr() {
uint8_t hh = cfg_table[CFG_CHIME_SINCE_BYTE ] >> CFG_CHIME_SINCE_SHIFT;
INCR(hh, 0, 23);
hh <<= CFG_CHIME_SINCE_SHIFT;
cfg_table[CFG_CHIME_SINCE_BYTE] &= ~CFG_CHIME_SINCE_MASK ;
cfg_table[CFG_CHIME_SINCE_BYTE] |= hh;
ds_ram_config_write();
}

void ds_chime_until_incr() {
uint8_t hh = cfg_table[CFG_CHIME_UNTIL_BYTE] & CFG_CHIME_UNTIL_MASK;
INCR(hh, 0, 23);
cfg_table[CFG_CHIME_UNTIL_BYTE] &= ~CFG_CHIME_UNTIL_MASK;
cfg_table[CFG_CHIME_UNTIL_BYTE] |= hh;
ds_ram_config_write();
}

void ds_chime_on_toggle() {
CONF_CHIME_ON = !CONF_CHIME_ON;
ds_ram_config_write();
}

void ds_date_mmdd_toggle() {
CONF_SW_MMDD = !CONF_SW_MMDD;
ds_ram_config_write();
Expand Down
28 changes: 25 additions & 3 deletions src/ds1302.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
#define DS_ADDR_WP 7
#define DS_ADDR_TCSDS 8

// trickle charge for super capacitors - 1/2 diodes, 2/4/8 kOhm resistor
#define DS_TCS_TCON 0b10100000

#define DS_TC_D1_2KO 0b0101
#define DS_TC_D1_4KO 0b0110
#define DS_TC_D1_8KO 0b0111
#define DS_TC_D2_2KO 0b1001
#define DS_TC_D2_4KO 0b1010
#define DS_TC_D2_8KO 0b1011

#define DS_BURST_MODE 31

// DS_ADDR_SECONDS c111_1111 0_0-5_9 c=clock_halt
Expand Down Expand Up @@ -84,13 +94,22 @@ __bit __at (0x37) H12_12;
uint8_t __at (0x2c) cfg_table[4];

#define CFG_ALARM_HOURS_BYTE 0
#define CFG_ALARM_MINUTES_BYTE 1
#define CFG_TEMP_BYTE 2

#define CFG_ALARM_HOURS_MASK 0b11111000
#define CFG_ALARM_HOURS_SHIFT 3

#define CFG_ALARM_MINUTES_BYTE 1
#define CFG_ALARM_MINUTES_MASK 0b00111111

#define CFG_TEMP_BYTE 2
#define CFG_TEMP_MASK 0b00000111

#define CFG_CHIME_SINCE_BYTE 2
#define CFG_CHIME_SINCE_MASK 0b11111000
#define CFG_CHIME_SINCE_SHIFT 3

#define CFG_CHIME_UNTIL_BYTE 3
#define CFG_CHIME_UNTIL_MASK 0b00011111

// Offset 0 => alarm_hour (7..3) / chime_on (2) / alarm_on (1) / temp_C_F (0)
// Offset 1 => (7) not used / (6) sw_mmdd / alarm_minute (5..0)
// Offset 2 => chime_hour_start (7..3) / temp_offset (2..0), signed -4 / +3
Expand Down Expand Up @@ -156,6 +175,9 @@ uint8_t ds_int2bcd_ones(uint8_t integer);
void ds_alarm_minutes_incr();
void ds_alarm_hours_incr();
void ds_alarm_on_toggle();
void ds_chime_since_incr();
void ds_chime_until_incr();
void ds_chime_on_toggle();
void ds_date_mmdd_toggle();
void ds_temperature_offset_incr();
void ds_temperature_cf_toggle();
Loading

0 comments on commit 6f17503

Please sign in to comment.