<commit_before>#include <SPI.h>
#include "SRAM.h"

// Should be good for 23K256 and 23LC1024 but untested with the former
//
// Implements Stream for convenience so you get readBytes() etc. Not the fastest way
// to do it because of that (setting the address for every byte transfered)
//
// Really only SRAM_SEQN_MODE is properly supported (please contribute)
// Use seek() to set the address before reading and writing

/*
  Example usage:
  
  SRAM sram(SRAM_CS_PIN, SRAM_1024);
  char test [] = "hello, world";
  sram.seek(1);
  sram.write((byte *) test, sizeof test);
  char buf[100];
  sram.seek(1);
  sram.readBytes((char *) buf, sizeof buf);
  Serial.println(buf);
*/

// setup SRAM device by turning into sequential mode
SRAM::SRAM(uint8_t cs_pin, uint8_t size, uint8_t mode) {
  this->address = 1;
  this->cs_pin = cs_pin;
  this->mode = mode;
  this->size = size;
  // Need to support 256k SRAM as well
}

SRAM::SRAM(uint8_t cs_pin, uint8_t size) {
  SRAM(cs_pin, size, SRAM_SEQN_MODE);
}
  
void SRAM::begin() {
  SPI.begin();
  pinMode(this->cs_pin, OUTPUT);
  digitalWrite(this->cs_pin, LOW);
  SPI.transfer(SRAM_WRSR);
  SPI.transfer(this->mode);
  digitalWrite(this->cs_pin, HIGH);
}

void SRAM::seek(uint32_t address) {
  this->address = address;
}

size_t SRAM::write(uint8_t data) {
  digitalWrite(this->cs_pin, LOW);  
  SPI.transfer(SRAM_WRITE);
  if(this->size == SRAM_1024)
    SPI.transfer((this->address >> 16) & 0xFF);
    
  SPI.transfer((this->address >> 8)  & 0xFF);
  SPI.transfer(this->address & 0xFF);
  SPI.transfer(data);
  this->address++;
  digitalWrite(this->cs_pin, HIGH);
  
  return 1;
}

int SRAM::read() {
  digitalWrite(this->cs_pin, LOW);
  SPI.transfer(SRAM_READ);
  if(this->size == SRAM_1024)
    SPI.transfer((this->address >> 16) & 0xFF);
    
  SPI.transfer((this->address >> 8)  & 0xFF);
  SPI.transfer(this->address & 0xFF);
  uint8_t data = SPI.transfer(0);
  this->address++;
  digitalWrite(this->cs_pin, HIGH);
  
  return data;
}<commit_msg>Constructor bug<commit_after>#include <SPI.h>
#include "SRAM.h"

SRAM::SRAM(uint8_t cs_pin, uint8_t size, uint8_t mode) {
  this->address = 1;
  this->cs_pin = cs_pin;
  this->mode = mode;
  this->size = size;
}

SRAM::SRAM(uint8_t cs_pin, uint8_t size) {
  this->address = 1;
  this->cs_pin = cs_pin;
  this->mode = SRAM_SEQN_MODE;
  this->size = size;
}

void SRAM::begin() {
  SPI.begin();
  pinMode(this->cs_pin, OUTPUT);
  digitalWrite(this->cs_pin, LOW);
  SPI.transfer(SRAM_WRSR);
  SPI.transfer(this->mode);
  digitalWrite(this->cs_pin, HIGH);
}

void SRAM::seek(uint32_t address) {
  this->address = address;
}

size_t SRAM::write(uint8_t data) {
  digitalWrite(this->cs_pin, LOW);  
  SPI.transfer(SRAM_WRITE);
  if(this->size == SRAM_1024)
    SPI.transfer((this->address >> 16) & 0xFF);

  SPI.transfer((this->address >> 8)  & 0xFF);
  SPI.transfer(this->address & 0xFF);
  SPI.transfer(data);
  this->address++;
  digitalWrite(this->cs_pin, HIGH);

  return 1;
}

int SRAM::read() {
  digitalWrite(this->cs_pin, LOW);
  SPI.transfer(SRAM_READ);
  if(this->size == SRAM_1024)
    SPI.transfer((this->address >> 16) & 0xFF);

  SPI.transfer((this->address >> 8)  & 0xFF);
  SPI.transfer(this->address & 0xFF);
  uint8_t data = SPI.transfer(0);
  this->address++;
  digitalWrite(this->cs_pin, HIGH);

  return data;
}
{'fraction_non_alphanumeric': 0.16395908543922985, 'fraction_numerical': 0.026474127557160047, 'mean_word_length': 4.007530120481928, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 71, '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': '5051077', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1277, 'n_words': 271}