MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / bm8563_set_datetime

Function bm8563_set_datetime

Drivers/bm8563-module/source/bm8563.cpp:81–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81error_t bm8563_set_datetime(Device* device, const Bm8563DateTime* dt) {
82 if (dt->year < 2000 || dt->year > 2199 ||
83 dt->month < 1 || dt->month > 12 ||
84 dt->day < 1 || dt->day > 31 ||
85 dt->hour > 23 || dt->minute > 59 || dt->second > 59) {
86 return ERROR_INVALID_ARGUMENT;
87 }
88
89 auto* i2c_controller = device_get_parent(device);
90 auto address = GET_CONFIG(device)->address;
91
92 bool century = (dt->year >= 2100);
93 uint8_t y = static_cast<uint8_t>(century ? dt->year - 2100 : dt->year - 2000);
94
95 uint8_t buf[7] = {};
96 buf[0] = dec_to_bcd(dt->second);
97 buf[1] = dec_to_bcd(dt->minute);
98 buf[2] = dec_to_bcd(dt->hour);
99 buf[3] = dec_to_bcd(dt->day);
100 buf[4] = 0; // weekday — leave as Sunday (unused)
101 buf[5] = static_cast<uint8_t>(dec_to_bcd(dt->month) | (century ? 0x80u : 0x00u));
102 buf[6] = dec_to_bcd(y);
103
104 return i2c_controller_write_register(i2c_controller, address, REG_SECONDS, buf, sizeof(buf), I2C_TIMEOUT_TICKS);
105}
106
107Driver bm8563_driver = {
108 .name = "bm8563",

Callers

nothing calls this directly

Calls 3

device_get_parentFunction · 0.85
dec_to_bcdFunction · 0.70

Tested by

no test coverage detected