reflow-oven-control-sw/stm-firmware/include/reflow-controller/settings/spi-eeprom.h

83 lines
2.5 KiB
C

/* Reflow Oven Controller
*
* Copyright (C) 2021 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SETTINGS_SPI_EEPROM_H__
#define __SETTINGS_SPI_EEPROM_H__
#include <stdint.h>
#include <stdbool.h>
/**
* @brief Initialize the SPI for the eeprom.
* @return 0 if succesful
*/
int spi_eeprom_init(void);
/**
* @brief Uninitialize the SPI EEPROM
*/
void spi_eeprom_deinit(void);
/**
* @brief Read from SPI EEPROM
* @param addr address to read from
* @param rx_buff buffer to write data to
* @param count Amount of bytes to read
* @return 0 if successful
*/
int spi_eeprom_read(uint32_t addr, uint8_t *rx_buff, uint32_t count);
/**
* @brief Check if the EEPROM is currently performing a write and therefore cannot serve other requests
* @return true: Write in Progress, false: No write active
*/
bool spi_eeprom_write_in_progress(void);
/**
* @brief Write data to the EEPROM
* @param addr Address to write to
* @param data Data to write
* @param count Amount of bytes to write
* @return 0 if successful
* @note The page handling of the EEPROM is done internally. When using this function there is no need to worry about
* the 16 byte page boundaries of the EEPROM
*/
int spi_eeprom_write(uint32_t addr, const uint8_t *data, uint32_t count);
/**
* @brief Read the status register of the EEPROM
* @return status register
*/
uint8_t spi_eeprom_read_status_reg(void);
/**
* @brief Check if an EEPROM is connected to the SPI.
*
* This is done by trying to set the write enable latch in the status register and reading it back.
* After it has been set, it is immediately reset.
*
* If it can't be read back, no EEPROM is connected
*
* @return true: EEPROM is connected, false: No (compatible) EEPROM found
*/
bool spi_eeprom_check_connected(void);
#endif /* __SETTINGS_SPI_EEPROM_H__ */