/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-05-08     LJ       the first version
 */
#ifndef APPLICATIONS_FRAM_MB85RS_H_
#define APPLICATIONS_FRAM_MB85RS_H_

#include <rtthread.h>
#include <rtdevice.h>
#include <drv_common.h>
#include <board.h>
#include "drv_spi.h"
//#include "drv_gpio.h"

//频率
#define MB85RS_SPICLOCK    20000000

//MB85RS64命令
#define    REG_READ_COMMAND    0x03 //读数据
#define    REG_WRITE_COMMAND   0x02 //写数据
#define    REG_WRITE_ENABLE    0x06 //写使能
#define    REG_WRITE_DISABLE   0x04 //写失能
#define    REG_READ_STATUS     0x05 //读取状态寄存器
#define    REG_WRITE_STATUS    0x01 //写入状态寄存器
#define    REG_READ_DEVICE_ID  0x9F

//初始化
void spi_flash_mb85rs_init(void);

/**
 * 读取ID
 */
void mb85rs_read_id();


/**
 * 读取字节
 * @param read_addr
 * @param read_buff
 * @param read_bytes
 */
rt_uint8_t mb85rs_read_bytes(rt_uint16_t read_addr, rt_uint8_t *read_buff, rt_uint16_t read_bytes);

/**
 * 写多字节
 * @param write_addr
 * @param write_buff
 * @param write_bytes
 */
rt_uint8_t mb85rs_write_bytes(rt_uint16_t write_addr, rt_uint8_t *write_buff, rt_uint16_t write_bytes);

/**
 * 写使能
 * @param select
 */
void mb85rs_write_enable(rt_uint8_t select);

/**
 * 读取状态
 * @return
 */
rt_uint8_t mb85rs_read_status(void);

/**
 * 写状态寄存器
 * @param write_data
 */
void mb85rs_write_status(rt_uint8_t write_data);


#endif /* APPLICATIONS_FRAM_MB85RS_H_ */
