/** * @file eeprom_m95.h * @author xxx * @date 2023-08-30 14:05:55 * @brief 头文件 eeprom_m95.h * @copyright Copyright (c) 2023 by xxx, All Rights Reserved. */ #ifndef __EEPROM_M95_H #define __EEPROM_M95_H #include "main.h" #include "entity.h" #define _M95010_ 128 #define _M95020_ 256 #define _M95040_ 512 #define _M95080_ 1024 #define _M95160_ 2048 #define _M95320_ 4096 #define _M95640_ 8192 #define _M95128_ 16384 #define _M95256_ 32768 #define _M95512_ 65536 // 65K #define _M95M02_ 262144 // 256K #define _M95_SIZE _M95512_ #define M95_CMD_RDSR 0x05 /*!< Read Status Register instruction */ #define M95_CMD_WRSR 0x01 /*!< Write Status Register instruction */ #define M95_CMD_WREN 0x06 /*!< Write enable instruction */ #define M95_CMD_WRDI 0x04 /*!< Write disable instruction */ #define M95_CMD_READ 0x03 /*!< Read from Memory instruction */ #define M95_CMD_WRITE 0x02 /*!< Write to Memory instruction */ // Instruction available only for the M95_2-D device. #define M95_CMD_RDID 0x83 /*!< Read identification page*/ #define M95_CMD_WRID 0x82 /*!< Write identification page*/ #define M95_CMD_RDLS 0x83 /*!< Reads the Identification page lock status*/ #define M95_CMD_LID 0x82 /*!< Locks the Identification page in read-only mode*/ #define M95_DUMMY_BYTE 0xA5 // 虚拟字节 // 定义存储器大小(Bytes) typedef enum { M95_PAGE_SIZE_16 = 16, // _M95010_ 、_M95020_ 、_M95040_ M95_PAGE_SIZE_32 = 32, // _M95080_ 、_M95160_、_M95320_、_M95640_ M95_PAGE_SIZE_64 = 64, // _M95128_、_M95256_ M95_PAGE_SIZE_128 = 128, // _M95512_ M95_PAGE_SIZE_256 = 256, // _M95M02_ } m95_page_size_e; typedef enum { M95_1, M95_2, M95_MAX, } m95_number_e; // 板卡上2块m95芯片定义 typedef struct { m95_number_e num; uint32_t page_size; uint32_t total_size; spi_t *spi; uint8_t address_bytes; // M95M02 地址大小3个字节,其余M95型号芯片为2个字节 uint8_t *rxbuf; uint8_t *txbuf; } m95_number_t; extern __IO m95_number_e current_m95_number; ///< 当前使用的m95芯片编号 extern m95_number_t eeprom_m95s[M95_MAX]; ///< m95芯片数组 extern void eeprom_m95_init(m95_number_e num); ///< 初始化 extern void eeprom_m95_enable(void); ///< 使能 extern void eeprom_m95_disable(void); ///< 禁止 extern void eeprom_m95_read(m95_number_e num, uint32_t read_addr, uint8_t *data, uint16_t length); ///< 读取数据 extern void eeprom_m95_write(m95_number_e num, uint32_t write_addr, uint8_t *data, uint16_t length); ///< 写入数据 extern void eeprom_m95_test(m95_number_e num); ///< 测试 #endif // __EEPROM_M95_H