fixed bug in set_timer()

pcf85063a
Jonathan Williamson 2022-05-30 09:04:04 +01:00 zatwierdzone przez Phil Howard
rodzic 4a5df45573
commit 755da537dd
3 zmienionych plików z 13 dodań i 11 usunięć

Wyświetl plik

@ -137,11 +137,13 @@ namespace pimoroni {
void PCF85063A::set_timer(uint8_t ticks, TimerTickPeriod ttp) {
uint8_t bits = i2c->reg_read_uint8(address, Registers::TIMER_MODE);
// mask out timer tick period value and set new value
bits = (bits & ~0x18) | ttp;
// enable timer
bits |= 0x04;
i2c->reg_write_uint8(address, Registers::TIMER_MODE, bits);
uint8_t timer[2] = {
ticks,
uint8_t((bits & ~0x18) | ttp | 0x04) // mask out current ttp and set new + enable
};
i2c->write_bytes(address, Registers::TIMER_VALUE, timer, 2);
}
bool PCF85063A::read_timer_flag() {

Wyświetl plik

@ -38,10 +38,10 @@ namespace pimoroni {
};
enum TimerTickPeriod : int8_t {
TIMER_TICK_4096HZ = 0,
TIMER_TICK_64HZ = 1,
TIMER_TICK_1HZ = 2,
TIMER_TICK_1_OVER_60HZ = 3
TIMER_TICK_4096HZ = 0b00 << 3,
TIMER_TICK_64HZ = 0b01 << 3,
TIMER_TICK_1HZ = 0b10 << 3,
TIMER_TICK_1_OVER_60HZ = 0b11 << 3
};
//--------------------------------------------------

Wyświetl plik

@ -93,8 +93,8 @@ int main() {
printf("check timer function\n");
printf("\n");
printf("- setting timer for in 3 seconds\n");
rtc.set_timer(3);
printf("- setting timer for in 5 seconds\n");
rtc.set_timer(5);
printf("\n");
printf("- waiting for timer flag\n");