...
 
Commits (2)
/*
* cat25160.cpp
*
* Created on: 20 Jul 2020
* Author: louckas
*/
#include <cat25160.h>
CAT25160::CAT25160(SPI *spi, GPIO_TypeDef* chipSelectPort, uint16_t chipSelectPin) {
_spi = spi;
_Port = chipSelectPort;
_Pin = chipSelectPin;
}
CAT25160::~CAT25160() {
}
MsgStatus enable_write()
{
}
MsgStatus disable_write()
{
}
MsgStatus read_status(uint8_t &status)
{
}
MsgStatus read_status(uint8_t status)
{
}
MsgStatus read_byte(uint8_t &byte, uint16_t address)
{
}
MsgStatus write_byte(uint8_t byte, uint16_t address)
{
}
MsgStatus read_word(uint32_t &word, uint16_t address)
{
}
MsgStatus write_word(uint32_t &word, uint16_t address)
{
}
/*
* cat25160.h
*
* Created on: 20 Jul 2020
* Author: louckas
*/
#ifndef LIBRARY_MEMORY_CAT25160_H_
#define LIBRARY_MEMORY_CAT25160_H_
#include "spi.h"
#define CMD_WRITE_ENABLE 0x06
#define CMD_WRITE_DISABLE 0x04
#define CMD_READ_STATUS 0x05
#define CMD_WRITE_STATUS 0x01
#define CMD_READ 0x03
#define CMD_WRITE 0x02
/**
* @class SPI
*
* @brief Class used to wrap and easely access the CAT25160 chip.
*
* This class is to be used when a EEPROM CAT25160 memory is available on a SPI interface, this encapsulate the
* commands to control the chip. The pagging of the component is done on 32bytes and the total size is 16kb
* The address range from 0x0000 to 0x07FF
*
* @author Luc CHRISTIN (Comme christine mais sans le E)
* @date 20/07/2020
*/
class CAT25160 {
public:
/*!
* @brief Constructor of CAT25160
*
* Used to create and initialize a new CAT25160 class linked with an existing SPI class
*
* @param[in] SPI* Wrapping class of the SPI we have to use to reach the EEPROM
* @param[in] chipSelectPort* Port of the PIN used for the chip select
* @param[in] chipSelectPin Pin number of the chip select
* @sa class SPI
*/
CAT25160(SPI *spi, GPIO_TypeDef* chipSelectPort, uint16_t chipSelectPin);
~CAT25160();
/*!
* @brief Enable writing in the memory
*
* Enable the writing to the EEPROM, the WEL is set by the command
*
* @return MsgStatus status of the spi transaction
*/
MsgStatus enable_write();
/*!
* @brief Disable writing in the memory
*
* Disable the writing to the EEPROM, the WEL is reset by the command
*
* @return MsgStatus status of the spi transaction
*/
MsgStatus disable_write();
/*!
* @brief Read the status register
*
* This method will fetch and return the state of the status register.
* The following bit can be read:
* 7: Write protect Enable, enable the usage of the WP pin if 0 the pin is not read, 1 read the pin state
* 3-2: BP1 - BP0 Protect the first, second half or all of the memory from writting
* 1: WEL (Read only) if 1 the memory can be written
* 0: RDY if 0 the memory is ready
*
* @param[out] status Value of the status register
*
* @return MsgStatus status of the spi transaction
*/
MsgStatus read_status(uint8_t &status);
/*!
* @brief Write to the status register
*
* This method will write to the status register.
* The following bit can be writen:
* 7: Write protect Enable, enable the usage of the WP pin if 0 the pin is not read, 1 read the pin state
* 3-2: BP1 - BP0 Protect the first, second half or all of the memory from writting
*
* @param[in] status Value to write in the status register
*
* @return MsgStatus status of the spi transaction
*/
MsgStatus read_status(uint8_t status);
/*!
* @brief Read a byte from the memory
*
* This will read a byte from the specified address and return it when the transaction is finished
*
* @param[out] byte Value read from the address
* @param[in] address Adress where the byte is placed in the memory
*
* @return MsgStatus status of the spi transaction
*/
MsgStatus read_byte(uint8_t &byte, uint16_t address);
/*!
* @brief Write a byte to the memory
*
* This will write a byte at the specified address
*
* @param[out] byte Value to be written at the address
* @param[in] address Adress where the byte is placed in the memory
*
* @return MsgStatus status of the spi transaction
*/
MsgStatus write_byte(uint8_t byte, uint16_t address);
/*!
* @brief Read a word from the memory
*
* This will read a byte from the specified address and return it when the transaction is finished.
* /!\ This can overlape on a page (pagging is 32bytes)
*
* @param[out] word Value read from the address
* @param[in] address Adress where the word is placed in the memory
*
* @return MsgStatus status of the spi transaction
*/
MsgStatus read_word(uint32_t &word, uint16_t address);
/*!
* @brief Write a word to the memory
*
* This will write a word at the specified address
* /!\ This can overlape on a page (pagging is 32bytes)
*
* @param[out] word Value to be written at the address
* @param[in] address Adress where the word is placed in the memory
*
* @return MsgStatus status of the spi transaction
*/
MsgStatus write_word(uint32_t &word, uint16_t address);
private:
SPI *_spi {nullptr};
GPIO_TypeDef* _Port {nullptr};
uint16_t _Pin {0};
uint8_t writeEnableBuf[1] {CMD_WRITE_ENABLE};
uint8_t writeDisableBuf[1] {CMD_WRITE_DISABLE};
uint8_t writeStatusRegisterBuf[2] {CMD_WRITE_STATUS, 0x00};
uint8_t readStatusRegisterBuf[1] {CMD_READ_STATUS};
uint8_t writeByteBuf[2] {CMD_WRITE, 0x00};
uint8_t readByteBuf[1] {CMD_READ};
uint8_t writeWordBuf[2] {CMD_WRITE, 0x00, 0x00, 0x00, 0x00};
uint8_t readWordBuf[1] {CMD_READ};
};
#endif /* LIBRARY_MEMORY_CAT25160_H_ */