Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

I2CEeprom.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (C) 2016 Krister W. <kisse66@hobbylabs.org>
  2. //
  3. // Original SPI flash driver this is based on:
  4. // Copyright (c) 2013-2015 by Felix Rusu, LowPowerLab.com
  5. //
  6. // I2C EEPROM library for MySensors OTA. Based on SPI Flash memory library for
  7. // arduino/moteino.
  8. // This driver is made to look like the SPI flash driver so changes needed to
  9. // MySensors OTA code is minimized.
  10. // This works with 32 or 64kB I2C EEPROM like an 24(L)C256. AVR HW I2C is assumed
  11. // and error handling is quite minimal. Uses extEEPROM as the underlying driver.
  12. // DEPENDS ON: Arduino Wire library, extEEPROM
  13. // **********************************************************************************
  14. // License
  15. // **********************************************************************************
  16. // This program is free software; you can redistribute it
  17. // and/or modify it under the terms of the GNU General
  18. // Public License as published by the Free Software
  19. // Foundation; either version 3 of the License, or
  20. // (at your option) any later version.
  21. //
  22. // This program is distributed in the hope that it will
  23. // be useful, but WITHOUT ANY WARRANTY; without even the
  24. // implied warranty of MERCHANTABILITY or FITNESS FOR A
  25. // PARTICULAR PURPOSE. See the GNU General Public
  26. // License for more details.
  27. //
  28. // You should have received a copy of the GNU General
  29. // Public License along with this program.
  30. // If not, see <http://www.gnu.org/licenses/>.
  31. //
  32. // Licence can be viewed at
  33. // http://www.gnu.org/licenses/gpl-3.0.txt
  34. //
  35. // Please maintain this license information along with authorship
  36. // and copyright notices in any redistribution of this code
  37. ///
  38. /// @file I2CEeprom.h
  39. ///
  40. /// @brief I2CEeprom provides access to a I2C EEPROM IC for OTA update or storing data
  41. ///
  42. /// This is a wrapper over extEEPROM to make it look like a flash chip.
  43. ///
  44. #ifndef _I2CEeprom_H_
  45. #define _I2CEeprom_H_
  46. #include <Arduino.h>
  47. #include <extEEPROM.h>
  48. /// I2C speed
  49. // 400kHz clock as default. Use extEEPROM type
  50. #ifndef I2CEEPROM_TWI_CLK
  51. #define I2CEEPROM_TWI_CLK twiClock400kHz
  52. #endif
  53. /// EEPROM page size
  54. //Typically 64 (see data sheet for your EEPROM)
  55. // Some 512kbit chips use 128 byte pages (e.g. Atmel AT24C512)
  56. #ifndef I2CEEPROM_PAGE_SIZE
  57. #define I2CEEPROM_PAGE_SIZE 64
  58. #endif
  59. /// EEPROM size
  60. // 24C256 is 32kB, minimum that fits code for ATmega328
  61. // Use extEEPROM type
  62. #ifndef I2CEEPROM_CHIP_SIZE
  63. #define I2CEEPROM_CHIP_SIZE kbits_256
  64. #endif
  65. /** I2CEeprom class */
  66. class I2CEeprom : extEEPROM
  67. {
  68. public:
  69. explicit I2CEeprom(uint8_t addr); //!< Constructor
  70. bool initialize(); //!< setup
  71. uint8_t readByte(uint32_t addr); //!< read 1 byte from flash memory
  72. void readBytes(uint32_t addr, void* buf, uint16_t len); //!< read multiple bytes
  73. void writeByte(uint32_t addr, uint8_t byt); //!< Write 1 byte to flash memory
  74. void writeBytes(uint32_t addr, const void* buf,
  75. uint16_t len); //!< write multiple bytes to flash memory (up to 64K), if define SPIFLASH_SST25TYPE is set AAI Word Programming will be used
  76. bool busy(); //!< check if the chip is busy erasing/writing
  77. // the rest not needed for EEPROMs, but kept so SPI flash code compiles as is (functions are NOP)
  78. /// dummy function for SPI flash compatibility
  79. uint16_t readDeviceId()
  80. {
  81. return 0xDEAD;
  82. };
  83. /// dummy function for SPI flash compatibility
  84. void chipErase() {};
  85. /// dummy function for SPI flash compatibility
  86. void blockErase4K(uint32_t address)
  87. {
  88. (void)address;
  89. };
  90. /// dummy function for SPI flash compatibility
  91. void blockErase32K(uint32_t address)
  92. {
  93. (void)address;
  94. };
  95. /// dummy function for SPI flash compatibility
  96. void sleep() {};
  97. /// dummy function for SPI flash compatibility
  98. void wakeup() {};
  99. /// dummy function for SPI flash compatibility
  100. void end() {};
  101. protected:
  102. uint8_t m_addr; ///< I2C address for busy()
  103. };
  104. #endif