forked from nanoframework/nanoFramework.IoT.Device
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mcp7940n.cs
94 lines (83 loc) · 3.41 KB
/
Mcp7940n.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Device.I2c;
using Iot.Device.Common;
namespace Iot.Device.Mcp7940xx
{
/// <summary>
/// Battery-Backed I2C Real-Time Clock/Calendar with SRAM.
/// </summary>
public partial class Mcp7940n : Mcp7940m
{
/// <summary>
/// Initializes a new instance of the <see cref="Mcp7940n" /> class.
/// </summary>
/// <param name="i2cDevice">The I2C device to use for communication.</param>
/// <param name="clockSource">The clocks oscillator configuration.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="i2cDevice"/> is <c>null</c>.</exception>
public Mcp7940n(I2cDevice i2cDevice, ClockSource clockSource)
: base(i2cDevice, clockSource)
{
}
#region Battery Backup
/// <summary>
/// Enables external battery backup.
/// </summary>
public void EnableExternalBatteryBackup()
{
RegisterHelper.SetRegisterBit(_i2cDevice, (byte)Register.TimekeepingWeekday, (byte)RegisterMask.ExternalBatteryBackupEnabledMask);
}
/// <summary>
/// Disables external battery backup.
/// </summary>
public void DisableExternalBatteryBackup()
{
RegisterHelper.ClearRegisterBit(_i2cDevice, (byte)Register.TimekeepingWeekday, (byte)RegisterMask.ExternalBatteryBackupEnabledMask);
}
/// <summary>
/// Gets a value indicating whether the external battery backup is enabled.
/// </summary>
public bool IsEnabledExternalBatteryBackup
{
get
{
return RegisterHelper.RegisterBitIsSet(_i2cDevice, (byte)Register.TimekeepingWeekday, (byte)RegisterMask.ExternalBatteryBackupEnabledMask);
}
}
/// <summary>
/// Gets a value indicating whether the device has experienced a power failure.
/// </summary>
public bool HasPowerFailureAlert
{
get
{
return RegisterHelper.RegisterBitIsSet(_i2cDevice, (byte)Register.TimekeepingWeekday, (byte)RegisterMask.PowerFailureStatusMask);
}
}
/// <summary>
/// Clears the power failure alert flag.
/// </summary>
public void ClearPowerFailureAlert()
{
RegisterHelper.ClearRegisterBit(_i2cDevice, (byte)Register.TimekeepingWeekday, (byte)RegisterMask.PowerFailureStatusMask);
}
/// <summary>
/// Gets a <see cref = "PowerEvent" /> object that is set to the date and time of the last power down event.
/// </summary>
/// <returns>An object whose value is the date and time of the last power down event.</returns>
public PowerEvent GetLastPowerDown()
{
return new PowerEvent(_i2cDevice, Register.PowerDownMinute);
}
/// <summary>
/// Gets a <see cref = "PowerEvent" /> object that is set to the date and time of the last power up event.
/// </summary>
/// <returns>An object whose value is the date and time of the last power up event.</returns>
public PowerEvent GetLastPowerUp()
{
return new PowerEvent(_i2cDevice, Register.PowerUpMinute);
}
#endregion
}
}