CameraSensor_Mt9v117.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #pragma once
  14. #include <AP_HAL/I2CDevice.h>
  15. #include "AP_HAL_Linux.h"
  16. #include "CameraSensor.h"
  17. namespace Linux {
  18. enum mt9v117_res {
  19. MT9V117_QVGA,
  20. };
  21. struct mt9v117_patch {
  22. uint8_t *data;
  23. uint8_t size;
  24. };
  25. #define MT9V117_PATCH_LINE_NUM 13
  26. class CameraSensor_Mt9v117 : public CameraSensor {
  27. public:
  28. CameraSensor_Mt9v117(const char *device_path,
  29. AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev,
  30. enum mt9v117_res res,
  31. uint16_t nrst_gpio, uint32_t clock_freq);
  32. private:
  33. static const struct mt9v117_patch _patch_lines[MT9V117_PATCH_LINE_NUM];
  34. uint8_t _read_reg8(uint16_t reg);
  35. void _write_reg8(uint16_t reg, uint8_t val);
  36. uint16_t _read_reg16(uint16_t reg);
  37. void _write_reg16(uint16_t reg, uint16_t val);
  38. void _write_reg32(uint16_t reg, uint32_t val);
  39. inline uint16_t _var2reg(uint16_t var, uint16_t offset);
  40. uint16_t _read_var16(uint16_t var, uint16_t offset);
  41. void _write_var16(uint16_t var, uint16_t offset, uint16_t value);
  42. uint8_t _read_var8(uint16_t var, uint16_t offset);
  43. void _write_var8(uint16_t var, uint16_t offset, uint8_t value);
  44. void _write_var32(uint16_t var, uint16_t offset, uint32_t value);
  45. void _config_change();
  46. void _itu656_enable();
  47. void _soft_reset();
  48. void _apply_patch();
  49. void _set_basic_settings();
  50. void _configure_sensor_qvga();
  51. void _init_sensor();
  52. AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev;
  53. uint32_t _clock_freq;
  54. uint16_t _nrst_gpio = 0xFFFF;
  55. uint8_t _addr;
  56. };
  57. }