/**
 * @file spi_drv.h
 * @author June6 (https://github.com/Junedoubling6)
 * @brief
 * @version 0.1
 * @date 2023-08-16
 *
 * @copyright Copyright (c) 2022 - , All rights reserved.
 *
 */
#ifndef SPI_DRV_H__
#define SPI_DRV_H__

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "err_code.h"

#ifdef __cplusplus
extern "C" {
#endif

#define SPI_DATA_MAX 54
#define SPI_MASTER_TRANSFER_SIZE 60

/* LCD需要初始化一组命令/参数值, 它们存储在此结构中 */
typedef struct {
  uint8_t cmd;
  uint8_t data[SPI_DATA_MAX];
  /*  数据中没有数据时bit7=设置后的延迟; 0xFF=cmds结束 */
  uint8_t data_bytes;
} spi_init_cmd_t;

/**
 * @brief Config spi lcd master.
 *
 * @param pin_sclk
 * @param pin_mosi
 * @param pin_miso
 * @param pin_cs
 * @param pin_dc
 * @return esp_err_t
 */
esp_err_t spi_lcd_master_config(int pin_sclk, int pin_mosi, int pin_miso,
                                int pin_cs, int pin_dc);

/**
 * @brief Deconfig spi lcd master.
 *
 * @return esp_err_t
 */
esp_err_t spi_lcd_master_deconfig(void);

/**
 * @brief SPI lcd master write.
 *
 * @param cmd_flag
 * @param data
 * @param len
 * @param keep_cs_active_flag
 * @return esp_err_t
 */
esp_err_t spi_lcd_write(bool cmd_flag, const uint8_t *data, size_t len,
                        bool keep_cs_active_flag);

/**
 * @brief Spi send cmd.
 *
 * @param cmd
 */
esp_err_t spi_send_cmd(uint8_t cmd);

/**
 * @brief Spi send data.
 *
 * @param data
 */
esp_err_t spi_send_data(uint8_t data);

#ifdef __cplusplus
}
#endif

#endif  // SPI_DRV_H__