/** * @file SPI_camera.hpp * @author Petr MalanĂ­k (TheColonelYoung(at)gmail(dot)com) * @brief * @version 0.1 * @date 11.09.2022 */ #pragma once #include "stm32l4xx_hal.h" #include #include #include using namespace std; typedef unsigned int uint; class SPI_camera { public: struct Chip_select_pin { GPIO_TypeDef *port; uint16_t pin; }; struct Register_blob_8 { uint8_t address; uint8_t data; }; struct Register_blob_16 { uint16_t address; uint8_t data; }; protected: I2C_HandleTypeDef I2C_handle; uint8_t I2C_address = 0; SPI_HandleTypeDef SPI_handle; Chip_select_pin SPI_CS; UART_HandleTypeDef UART_handle; vector image_data; public: SPI_camera(I2C_HandleTypeDef I2C_handle, uint8_t I2C_address, SPI_HandleTypeDef SPI_handle, Chip_select_pin SPI_CS, UART_HandleTypeDef UART_handle); virtual void Init() = 0; virtual void Capture() = 0; protected: int Sensor_write_register(uint8_t address, uint8_t data); int Sensor_write_register(uint16_t address, uint8_t data); int Sensor_write_register(Register_blob_8 reg); int Sensor_write_register(Register_blob_16 reg); void Sensor_write_register_bulk(vector regs); void Sensor_write_register_bulk(vector regs); int ArduChip_write(uint8_t addr, uint8_t data); int ArduChip_read(uint8_t address); int ArduChip_FIFO_length(); void ArduChip_start_burst_read(); void ArduChip_start_DMA_transfer(uint size); void ArduChip_CS_enable(){ HAL_GPIO_WritePin(SPI_CS.port, SPI_CS.pin, GPIO_PIN_RESET); }; void ArduChip_CS_disable(){ HAL_GPIO_WritePin(SPI_CS.port, SPI_CS.pin, GPIO_PIN_SET); }; };