I2CSensor.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. Unitemp - Universal temperature reader
  3. Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n)
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #ifndef UNITEMP_I2C
  16. #define UNITEMP_I2C
  17. #include "../unitemp.h"
  18. #include <furi_hal_i2c.h>
  19. //Структура I2C датчика
  20. typedef struct I2CSensor {
  21. //Указатель на интерфейс I2C
  22. FuriHalI2cBusHandle* i2c;
  23. //Минимальный адрес устройства на шине I2C
  24. uint8_t minI2CAdr;
  25. //Максимальный адрес устройства на шине I2C
  26. uint8_t maxI2CAdr;
  27. //Текущий адрес устройства на шине I2C
  28. uint8_t currentI2CAdr;
  29. //Указатель на собственный экземпляр датчика
  30. void* sensorInstance;
  31. } I2CSensor;
  32. /**
  33. * @brief Выделение памяти для датчика на шине I2C
  34. * @param sensor Указатель на датчик
  35. * @param st Тип датчика
  36. * @return Истина если всё ок
  37. */
  38. bool unitemp_I2C_sensor_alloc(Sensor* sensor, char* args);
  39. /**
  40. * @brief Высвобождение памяти инстанса датчика
  41. * @param sensor Указатель на датчик
  42. */
  43. bool unitemp_I2C_sensor_free(Sensor* sensor);
  44. /**
  45. * @brief Обновить значение с датчка
  46. * @param sensor Указатель на датчик
  47. * @return Статус обновления
  48. */
  49. UnitempStatus unitemp_I2C_sensor_update(Sensor* sensor);
  50. /**
  51. * @brief Прочитать значение регистра reg
  52. * @param i2c_sensor Указатель на инстанс датчика
  53. * @param reg Номер регистра
  54. * @return Значение регистра
  55. */
  56. uint8_t unitemp_i2c_readReg(I2CSensor* i2c_sensor, uint8_t reg);
  57. /**
  58. * @brief Прочитать масссив значений из памяти
  59. * @param i2c_sensor Указатель на инстанс датчика
  60. * @param startReg Адрес регистра с которого начнётся чтение
  61. * @param len Количество байт для считывания из регистра
  62. * @param data Указатель на массив куда будут считаны данные
  63. * @return Истина если устройство вернуло данные
  64. */
  65. bool unitemp_i2c_readRegArray(I2CSensor* i2c_sensor, uint8_t startReg, uint8_t len, uint8_t* data);
  66. /**
  67. * @brief Записать значение в регистр
  68. * @param i2c_sensor Указатель на инстанс датчика
  69. * @param reg Номер регистра
  70. * @param value Значение для записи
  71. * @return Истина если значение записано
  72. */
  73. bool unitemp_i2c_writeReg(I2CSensor* i2c_sensor, uint8_t reg, uint8_t value);
  74. #endif