Darien Figueroa / Mbed OS Final_Program

Dependencies:   USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RegisterField.cs Source File

RegisterField.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 System.Collections.Generic;
00038 using System.Linq;
00039 using System.Text;
00040 using System.Windows.Forms;
00041 using RPCSupport;
00042 using RPCSupport.Devices;
00043 
00044 namespace HealthSensorPlatform
00045 {
00046     class RegisterField : IRegisterFieldView
00047     {
00048         /// <summary>
00049         /// Device which is connected to this RegisterField
00050         /// </summary>
00051         public IRegisterDevice Device;
00052         /// <summary>
00053         /// Bit name in data sheet
00054         /// </summary>
00055         public string Name;
00056         /// <summary>
00057         /// Register number
00058         /// </summary>
00059         public int Register;
00060         /// <summary>
00061         /// LSB Bit index number of bit field
00062         /// </summary>
00063         public int Index; 
00064         /// <summary>
00065         /// Length of bit field
00066         /// </summary>
00067         public int Width;
00068         /// <summary>
00069         /// Description array of field settings
00070         /// </summary>
00071         public string[] Descriptions;
00072         /// <summary>
00073         /// Control associated with bit field
00074         /// </summary>
00075         Control control;
00076         public Control Control
00077         {
00078             get
00079             {
00080                 return control;
00081             }
00082             set
00083             {
00084                 control = value;
00085                 if (control.GetType() == typeof(MaximStyle.MaximComboBox))
00086                 {
00087                     MaximStyle.MaximComboBox cb = (MaximStyle.MaximComboBox)control;
00088                     cb.Items.Clear();
00089                     foreach (string s in Descriptions)
00090                     {
00091                         cb.Items.Add(s);
00092                     }
00093                 }
00094             }
00095         }
00096 
00097         /// <summary>
00098         /// Label (Text) associated with register field
00099         /// </summary>
00100         Label label;
00101         public Label Label
00102         { 
00103             set
00104             {
00105                 LabelDescription = value.Text;
00106                 label = value;
00107             }
00108 
00109             get
00110             {
00111                 return label;
00112             }
00113         }
00114 
00115         /// <summary>
00116         /// Text value of label
00117         /// </summary>
00118         public string LabelDescription;
00119 
00120         /// <summary>
00121         /// Automatically update register field 
00122         /// </summary>
00123         public bool AutoUpdate = true;
00124 
00125         /// <summary>
00126         /// Read register field value
00127         /// </summary>
00128         /// <returns></returns>
00129         public int ReadField()
00130         {
00131             int registerData;
00132 
00133             registerData = Device.ReadReg((byte)Register);
00134 
00135             return (registerData >> Index) & ((1 << Width) - 1);
00136         }
00137         
00138         /// <summary>
00139         /// Write register field value
00140         /// </summary>
00141         /// <param name="data">value to write to field</param>
00142         public void WriteField(int data)
00143         {
00144             int registerData;
00145 
00146             registerData = Device.ReadReg((byte)Register);
00147             registerData &= ~(((1 << Width) - 1) << Index); // Mask and Clear Bits
00148             registerData |= data << Index; // Set Bits 
00149 
00150             Device.WriteReg((byte)Register, registerData);
00151         }
00152 
00153     }
00154 }