kopia lustrzana https://github.com/pimoroni/pimoroni-pico
fixed bug in set_timer()
rodzic
4a5df45573
commit
755da537dd
|
@ -137,11 +137,13 @@ namespace pimoroni {
|
||||||
|
|
||||||
void PCF85063A::set_timer(uint8_t ticks, TimerTickPeriod ttp) {
|
void PCF85063A::set_timer(uint8_t ticks, TimerTickPeriod ttp) {
|
||||||
uint8_t bits = i2c->reg_read_uint8(address, Registers::TIMER_MODE);
|
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;
|
uint8_t timer[2] = {
|
||||||
// enable timer
|
ticks,
|
||||||
bits |= 0x04;
|
uint8_t((bits & ~0x18) | ttp | 0x04) // mask out current ttp and set new + enable
|
||||||
i2c->reg_write_uint8(address, Registers::TIMER_MODE, bits);
|
};
|
||||||
|
|
||||||
|
i2c->write_bytes(address, Registers::TIMER_VALUE, timer, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PCF85063A::read_timer_flag() {
|
bool PCF85063A::read_timer_flag() {
|
||||||
|
|
|
@ -38,10 +38,10 @@ namespace pimoroni {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum TimerTickPeriod : int8_t {
|
enum TimerTickPeriod : int8_t {
|
||||||
TIMER_TICK_4096HZ = 0,
|
TIMER_TICK_4096HZ = 0b00 << 3,
|
||||||
TIMER_TICK_64HZ = 1,
|
TIMER_TICK_64HZ = 0b01 << 3,
|
||||||
TIMER_TICK_1HZ = 2,
|
TIMER_TICK_1HZ = 0b10 << 3,
|
||||||
TIMER_TICK_1_OVER_60HZ = 3
|
TIMER_TICK_1_OVER_60HZ = 0b11 << 3
|
||||||
};
|
};
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
|
@ -93,8 +93,8 @@ int main() {
|
||||||
printf("check timer function\n");
|
printf("check timer function\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
printf("- setting timer for in 3 seconds\n");
|
printf("- setting timer for in 5 seconds\n");
|
||||||
rtc.set_timer(3);
|
rtc.set_timer(5);
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("- waiting for timer flag\n");
|
printf("- waiting for timer flag\n");
|
||||||
|
|
Ładowanie…
Reference in New Issue