Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MAX14720 MAX30205 USBDevice
I2cTest.cs
00001 /******************************************************************************* 00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved. 00003 * 00004 * This software is protected by copyright laws of the United States and 00005 * of foreign countries. This material may also be protected by patent laws 00006 * and technology transfer regulations of the United States and of foreign 00007 * countries. This software is furnished under a license agreement and/or a 00008 * nondisclosure agreement and may only be used or reproduced in accordance 00009 * with the terms of those agreements. Dissemination of this information to 00010 * any party or parties not specified in the license agreement and/or 00011 * nondisclosure agreement is expressly prohibited. 00012 * 00013 * The above copyright notice and this permission notice shall be included 00014 * in all copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00017 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00019 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00020 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00021 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00022 * OTHER DEALINGS IN THE SOFTWARE. 00023 * 00024 * Except as contained in this notice, the name of Maxim Integrated 00025 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00026 * Products, Inc. Branding Policy. 00027 * 00028 * The mere transfer of this software does not imply any licenses 00029 * of trade secrets, proprietary technology, copyrights, patents, 00030 * trademarks, maskwork rights, or any other form of intellectual 00031 * property whatsoever. Maxim Integrated Products, Inc. retains all 00032 * ownership rights. 00033 ******************************************************************************* 00034 */ 00035 00036 using System; 00037 using NUnit.Framework; 00038 using RPCSupport.Devices; 00039 using RPCSupport.DeviceSupport; 00040 using RPCSupport; 00041 00042 namespace RPCSupportTest 00043 { 00044 [TestFixture] 00045 [Property("Class", "I2C")] 00046 public class I2cTest 00047 { 00048 RPCClient rpcClient; 00049 I2cDevice i2cDevice; 00050 00051 [TestFixtureSetUp] 00052 public void Init() 00053 { 00054 rpcClient = new RPCClient(RPCClient.ePipeline.eSerialWrap); 00055 rpcClient.InitPipeline(); 00056 rpcClient.Connect(ComPort.Port); 00057 i2cDevice = rpcClient.Init_I2cDevice(); 00058 } 00059 00060 [TestFixtureTearDown] 00061 public void Dispose() 00062 { 00063 rpcClient.Disconnect(); 00064 } 00065 00066 [Test] 00067 public void I2CRead() 00068 { 00069 byte result = i2cDevice.ReadReg(1, 0x90, 0x01); 00070 00071 Assert.AreEqual(true, result >= 0 && result <= 0xff); 00072 } 00073 00074 [Test] 00075 public void I2CWriteConfigurationRegister() 00076 { 00077 /* 00078 byte data = max30205.ReadReg(0x01); 00079 00080 byte flipped = (byte)(data ^ 0xFF); 00081 00082 max30205.WriteReg(0x01, flipped); 00083 00084 byte result = max30205.ReadReg(0x01); 00085 00086 max30205.WriteReg(0x01, data); // Restore register value 00087 00088 Assert.AreEqual(flipped, result); 00089 */ 00090 byte data = i2cDevice.ReadReg(1, 0x90, 0x01); 00091 00092 byte flipped = (byte)(data & 0xFF); 00093 00094 i2cDevice.WriteReg(1, 0x90, 0x01, flipped); 00095 00096 byte result = i2cDevice.ReadReg(1, 0x90, 0x01); 00097 00098 i2cDevice.WriteReg(1, 0x90, 0x01, data); 00099 00100 Assert.AreEqual(flipped, result); 00101 } 00102 00103 [Test] 00104 public void I2CReadMultiple() 00105 { 00106 byte[] data = i2cDevice.ReadMultiReg(1, 0x90, 0x03, 2); 00107 00108 Assert.True(data[0] == 0x50 && data[1] == 0x00); 00109 Assert.AreEqual(new byte[] { 0x50, 0x00 }, data); 00110 } 00111 00112 [Test] 00113 public void I2CWriteMultiReg() 00114 { 00115 byte[] data = i2cDevice.ReadMultiReg(1, 0x90, 0x03, 2); 00116 00117 i2cDevice.WriteMultiReg(1, 0x90, 0x03, 2, new byte[] { 0x12, 0x34 }); 00118 byte[] result = i2cDevice.ReadMultiReg(1, 0x90, 0x03, 2); 00119 00120 00121 i2cDevice.WriteMultiReg(1, 0x90, 0x03, 2, data); // restore data 00122 00123 Assert.AreEqual(new byte[] {0x12, 0x34}, result); 00124 00125 } 00126 00127 [Test] 00128 public void I2CReadRegDetails() 00129 { 00130 DeviceDetails details = new DeviceDetails(); 00131 RegisterInfo reg = new RegisterInfo("CONFIG", 0x01); 00132 00133 details.InitI2c(1, 0x90); 00134 00135 i2cDevice.ReadReg(details, reg); 00136 00137 Assert.True(reg.data[0] >= 0x00 && reg.data[0] <= 0xFF); 00138 } 00139 00140 [Test] 00141 public void I2CReadMultipleDetails() 00142 { 00143 DeviceDetails details = new DeviceDetails(); 00144 RegisterInfo reg = new RegisterInfo("OVERT", 0x03, 2, RegisterInfo.RegisterType.None); 00145 00146 details.InitI2c(1, 0x90); 00147 00148 i2cDevice.ReadReg(details, reg); 00149 00150 Assert.True(reg.data[0] == 0x50 && reg.data[1] == 0x00); 00151 Assert.AreEqual(new byte[] { 0x50, 0x00 }, reg.data); 00152 } 00153 00154 [Test] 00155 public void I2CWriteRead() 00156 { 00157 byte[] data = i2cDevice.WriteRead(1, 0x90, new byte[] { 0x03 }, 2); 00158 00159 Assert.True(data[0] == 0x50 && data[1] == 0x00); 00160 Assert.AreEqual(new byte[] { 0x50, 0x00 }, data); 00161 } 00162 00163 } 00164 }
Generated on Thu Jul 28 2022 18:07:15 by
1.7.2