initial commit

This commit is contained in:
2026-06-25 12:19:29 +03:00
commit 1160477945
19 changed files with 898 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
using LibUsbDotNet.LibUsb;
using RTCSync.Utils;
using static RTCSync.Utils.BinaryUtils;
namespace RTCSync.Services;
public class DeviceWriters
{
public static void SetTime(IUsbDevice device, DateTime dt)
{
var data = new byte[]
{
ToBcd(dt.Second), // 0x00 секунды
ToBcd(dt.Minute), // 0x01 минуты
ToBcd(dt.Hour), // 0x02 часы, бит6=0 → 24h
(byte)(dt.DayOfWeek + 1), // 0x03 день недели (в dt 0=вс, 1=пн..., а в DS3231 на 1 больше)
ToBcd(dt.Day), // 0x04 число
ToBcd(dt.Month), // 0x05 месяц
ToBcd(dt.Year % 100) // 0x06 год (последние 2 цифры)
};
I2CUtils.Write(device, 0x68, 0x00, data);
}
public static void ResetOSF(IUsbDevice device, byte[]? status)
{
status ??= DeviceReaders.GetStatusRegister(device);
status[0] &= 0x7F; // очистить бит 7
// TODO: убрать хак
I2CUtils.Write(device, 0x68, 0x0F, status);
I2CUtils.Write(device, 0x68, 0x0F, status);
I2CUtils.Write(device, 0x68, 0x0F, status);
}
public static void EnableEOSC(IUsbDevice device, byte[]? control)
{
control ??= DeviceReaders.GetControlRegister(device);
control[0] &= 0x7F; // EOSC = 0 (осциллятор включён) — бит 7 регистра 0x0E
// TODO: убрать хак
I2CUtils.Write(device, 0x68, 0x0E, control);
I2CUtils.Write(device, 0x68, 0x0E, control);
I2CUtils.Write(device, 0x68, 0x0E, control);
}
}