forked from nanoframework/nanoFramework.IoT.Device
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bmm150I2c.cs
54 lines (50 loc) · 1.69 KB
/
Bmm150I2c.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
// 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;
namespace Iot.Device.Magnetometer
{
/// <summary>
/// Default I2C interface for the Bmm150.
/// </summary>
public class Bmm150I2c : Bmm150I2cBase
{
/// <summary>
/// Read a byte.
/// </summary>
/// <param name="i2cDevice">An I2C device.</param>
/// <param name="reg">The register to read.</param>
/// <returns>The register value.</returns>
public override byte ReadByte(I2cDevice i2cDevice, byte reg)
{
i2cDevice.WriteByte(reg);
return i2cDevice.ReadByte();
}
/// <summary>
/// Read a byte array.
/// </summary>
/// <param name="i2cDevice">An I2C device.</param>
/// <param name="reg">The register to read.</param>
/// <param name="readBytes">A span of bytes with the read values.</param>
public override void ReadBytes(I2cDevice i2cDevice, byte reg, SpanByte readBytes)
{
i2cDevice.WriteByte(reg);
i2cDevice.Read(readBytes);
}
/// <summary>
/// Write a byte.
/// </summary>
/// <param name="i2cDevice">An I2C device.</param>
/// <param name="reg">The register to read.</param>
/// <param name="data">A byte to write.</param>
public override void WriteRegister(I2cDevice i2cDevice, byte reg, byte data)
{
SpanByte dataout = new byte[]
{
reg,
data
};
i2cDevice.Write(dataout);
}
}
}