<commit_before>#ifndef __SMALLFS_H__
#define __SMALLFS_H__

#ifdef __linux__

#else
#include "zpuino.h"
#endif
/** SmallFS filesystem magic */
#define SMALLFS_MAGIC 0x50411F50

#ifndef SEEK_SET
# define SEEK_SET   0
# define SEEK_CUR  1
# define SEEK_END  2
#endif

struct smallfs_header {
	unsigned int magic /** big-endian, magic number **/;
	unsigned int numfiles;
}__attribute__((packed));

struct smallfs_entry {
	unsigned int offset;
	unsigned int size;
	unsigned char namesize;
	char name[0];
} __attribute__((packed));

extern "C" void *bootloaderdata;
struct boot_t {
	unsigned int spiend;
};
/**
 * @brief SmallFS File Class
 */
class SmallFSFile
{
public:
	SmallFSFile(): flashoffset(-1),seekpos(0) {}
	SmallFSFile(unsigned o,unsigned size): flashoffset(o),filesize(size),seekpos(0) {}
	/**
	 * @brief Check if file was successfuly opened.
	 * @return true on success, false otherwise
     */
	bool valid() { return flashoffset>=0;}//!=-1; }

	/**
	 * @brief Read a chunk of data from file.
	 * @param buf The buffer where to store data
	 * @param size The number of bytes to read from file.
	 * @return The number of bytes read, 0 for EOF.
	 */
	int read(void *buf, int size);
	/**
	 * @brief Seek current file position
	 * @param pos The required position
	 * @param whence Where to perform seek. Either SEEK_SET, SEEK_CUR or SEEK_END
	 */
	void seek(int pos, int whence);
	/**
	 * @brief Get the file size.
	 * @return The file size.
     */
	inline int size() const { return filesize; }
	/**
	 * @brief Read a chunk of data from file, using a callback function.
	 * The function will be called for every byte read.
	 * @param size The number of bytes to read from file.
	 * @param callback The callback function to call
	 * @param data The data parameter to pass to callback function.
	 * @return The number of bytes read, 0 for EOF.
	 */
	
	int readCallback(int size, void (*callback)(unsigned char, void*), void *data);

	/**
	 * @brief Read a single byte
	 */
	unsigned readByte();

private:
	int flashoffset;
	int filesize;
    int seekpos;
};

/**
 * @brief Main filesystem class
 */
class SmallFS_class {
    friend class SmallFSFile;
public:
	/**
	 * @brief Initialize the SmallFS filesystem
	 * @return 0 on success, -1 otherwise
	 */
	int begin();

protected:
	void spi_disable()
	{
#ifndef __linux__
		digitalWrite(SPI_FLASH_SEL_PIN,HIGH);
#endif
	}

	static void spi_enable()
	{
#ifndef __linux__
		digitalWrite(SPI_FLASH_SEL_PIN,LOW);
#endif
	}

	static inline void spiwrite(unsigned int i)
	{
#ifndef __linux__
		SPIDATA=i;
#endif
	}

	static inline unsigned int spiread()
	{
#ifndef __linux__
		return SPIDATA;
#else
		return 0;
#endif
	}

protected:<commit_msg>smallfs: use new SPI api<commit_after>#ifndef __SMALLFS_H__
#define __SMALLFS_H__

#ifdef __linux__

#else
#include "zpuino.h"
#endif

/** SmallFS filesystem magic */
#define SMALLFS_MAGIC 0x50411F50

#ifndef SEEK_SET
# define SEEK_SET   0
# define SEEK_CUR  1
# define SEEK_END  2
#endif

struct smallfs_header {
	unsigned int magic /** big-endian, magic number **/;
	unsigned int numfiles;
}__attribute__((packed));

struct smallfs_entry {
	unsigned int offset;
	unsigned int size;
	unsigned char namesize;
	char name[0];
} __attribute__((packed));

extern "C" void *bootloaderdata;
struct boot_t {
	unsigned int spiend;
};
/**
 * @brief SmallFS File Class
 */
class SmallFSFile
{
public:
	SmallFSFile(): flashoffset(-1),seekpos(0) {}
	SmallFSFile(unsigned o,unsigned size): flashoffset(o),filesize(size),seekpos(0) {}
	/**
	 * @brief Check if file was successfuly opened.
	 * @return true on success, false otherwise
     */
	bool valid() { return flashoffset>=0;}//!=-1; }

	/**
	 * @brief Read a chunk of data from file.
	 * @param buf The buffer where to store data
	 * @param size The number of bytes to read from file.
	 * @return The number of bytes read, 0 for EOF.
	 */
	int read(void *buf, int size);
	/**
	 * @brief Seek current file position
	 * @param pos The required position
	 * @param whence Where to perform seek. Either SEEK_SET, SEEK_CUR or SEEK_END
	 */
	void seek(int pos, int whence);
	/**
	 * @brief Get the file size.
	 * @return The file size.
     */
	inline int size() const { return filesize; }
	/**
	 * @brief Read a chunk of data from file, using a callback function.
	 * The function will be called for every byte read.
	 * @param size The number of bytes to read from file.
	 * @param callback The callback function to call
	 * @param data The data parameter to pass to callback function.
	 * @return The number of bytes read, 0 for EOF.
	 */
	
	int readCallback(int size, void (*callback)(unsigned char, void*), void *data);

	/**
	 * @brief Read a single byte
	 */
	unsigned readByte();

private:
	int flashoffset;
	int filesize;
	int seekpos;
};

/**
 * @brief Main filesystem class
 */
class SmallFS_class {
    friend class SmallFSFile;
public:
	/**
	 * @brief Initialize the SmallFS filesystem
	 * @return 0 on success, -1 otherwise
	 */
	int begin();

protected:
	void spi_disable()
	{
#ifndef __linux__
		digitalWrite(SPI_FLASH_SEL_PIN,HIGH);
#endif
	}

	static void spi_enable()
	{
#ifndef __linux__
		digitalWrite(SPI_FLASH_SEL_PIN,LOW);
#endif
	}

	static inline void spiwrite(unsigned int i)
	{
#ifndef __linux__
		SPIDATA=i;
#endif
	}

	static inline unsigned int spiread()
	{
#ifndef __linux__
		return SPIDATA;
#else
		return 0;
#endif
	}

	static inline void spiwrite(register_t datareg, unsigned int i)
	{
#ifndef __linux__
		*datareg=i;
#endif
	}

	static inline unsigned int spiread(register_t datareg)
	{
#ifndef __linux__
		return *datareg;
#else
		return 0;
#endif
	}

protected:
{'fraction_non_alphanumeric': 0.10680646881108939, 'fraction_numerical': 0.007997156566554114, 'mean_word_length': 3.7897872340425534, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3598001', 'n_tokens_mistral': 1972, 'n_tokens_neox': 1841, 'n_words': 659}