Project Autus - Automated Plant Chamber
Fork of keypad_test by
Embed:
(wiki syntax)
Show/hide line numbers
OneWireCRC.h
00001 /* 00002 * OneWireCRC. This is a port to mbed of Jim Studt's Adruino One Wire 00003 * library. Please see additional copyrights below this one, including 00004 * references to other copyrights. 00005 * 00006 * Copyright (C) <2009> Petras Saduikis <petras@petras.co.uk> 00007 * 00008 * This file is part of OneWireCRC. 00009 * 00010 * OneWireCRC is free software: you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation, either version 3 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * OneWireCRC is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with OneWireCRC. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 /* 00024 Copyright (c) 2007, Jim Studt 00025 00026 Updated to work with arduino-0008 and to include skip() as of 00027 2007/07/06. --RJL20 00028 00029 Modified to calculate the 8-bit CRC directly, avoiding the need for 00030 the 256-byte lookup table to be loaded in RAM. Tested in arduino-0010 00031 -- Tom Pollard, Jan 23, 2008 00032 00033 Permission is hereby granted, free of charge, to any person obtaining 00034 a copy of this software and associated documentation files (the 00035 "Software"), to deal in the Software without restriction, including 00036 without limitation the rights to use, copy, modify, merge, publish, 00037 distribute, sublicense, and/or sell copies of the Software, and to 00038 permit persons to whom the Software is furnished to do so, subject to 00039 the following conditions: 00040 00041 The above copyright notice and this permission notice shall be 00042 included in all copies or substantial portions of the Software. 00043 00044 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00045 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00046 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00047 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00048 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00049 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00050 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00051 00052 Much of the code was inspired by Derek Yerger's code, though I don't 00053 think much of that remains. In any event that was.. 00054 (copyleft) 2006 by Derek Yerger - Free to distribute freely. 00055 00056 The CRC code was excerpted and inspired by the Dallas Semiconductor 00057 sample code bearing this copyright. 00058 */ 00059 //--------------------------------------------------------------------------- 00060 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved. 00061 // 00062 // Permission is hereby granted, free of charge, to any person obtaining a 00063 // copy of this software and associated documentation files (the "Software"), 00064 // to deal in the Software without restriction, including without limitation 00065 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 00066 // and/or sell copies of the Software, and to permit persons to whom the 00067 // Software is furnished to do so, subject to the following conditions: 00068 // 00069 // The above copyright notice and this permission notice shall be included 00070 // in all copies or substantial portions of the Software. 00071 // 00072 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00073 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00074 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00075 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES 00076 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00077 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00078 // OTHER DEALINGS IN THE SOFTWARE. 00079 // 00080 // Except as contained in this notice, the name of Dallas Semiconductor 00081 // shall not be used except as stated in the Dallas Semiconductor 00082 // Branding Policy. 00083 //-------------------------------------------------------------------------- 00084 00085 #ifndef SNATCH59_ONEWIRECRC_H 00086 #define SNATCH59_ONEWIRECRC_H 00087 00088 #include <mbed.h> 00089 00090 // Select the table-lookup method of computing the 8-bit CRC by setting this to 1 00091 #ifndef ONEWIRE_CRC8_TABLE 00092 #define ONEWIRE_CRC8_TABLE 1 00093 #endif 00094 00095 typedef unsigned char BYTE; // used to be uint8_t : something a byte wide, whatever .... 00096 00097 enum eSpeed {OVERDRIVE, STANDARD}; 00098 00099 class OneWireCRC 00100 { 00101 public: 00102 OneWireCRC(PinName oneWire, eSpeed); 00103 00104 // reset, read, write functions 00105 int reset(); 00106 void writeByte(int data); 00107 int readByte(); 00108 int touchByte(int data); 00109 void block(BYTE* data, int data_len); 00110 int overdriveSkip(BYTE* data, int data_len); 00111 00112 // address functions 00113 void matchROM(BYTE rom[8]); 00114 void skipROM(); 00115 00116 // address search functions 00117 void resetSearch(); 00118 BYTE search(BYTE* newAddr); 00119 00120 // CRC check functions 00121 static BYTE crc8(BYTE* addr, BYTE len); 00122 static unsigned short crc16(unsigned short* data, unsigned short len); 00123 00124 private: 00125 const int* timing; 00126 00127 BYTE address[8]; 00128 int searchJunction; // so we can set to it -1 somewhere 00129 bool searchExhausted; 00130 00131 DigitalInOut oneWirePort; 00132 00133 // read/write bit functions 00134 void writeBit(int bit); 00135 int readBit(); 00136 }; 00137 00138 #endif
Generated on Tue Jul 12 2022 21:16:07 by 1.7.2