#include <SPI.h>
#include "fontlar.h"
#include "ayarlar.h"

void verileri_Gonder(uint16_t komutlar[kacmatrix], uint8_t veriler[kacmatrix])
{
  SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
  digitalWrite(_Load_CS_PIN, LOW);
  for (int i = 0; i < kacmatrix; i++)
  {
    uint16_t x = (komutlar[i] << 8) | veriler[i];
    SPI.transfer16(x);
  }
  digitalWrite(_Load_CS_PIN, HIGH);
  SPI.endTransaction();
}

void dot_Matrix_baslat(void) {
  for (size_t i = 0; i < sizeof(ks); i++)
  {
    uint16_t klar[kacmatrix];
    uint8_t vler[kacmatrix];
    for (size_t j = 0; j < kacmatrix; j++)
    {
      klar[j] = ks[i];
      vler[j] = ds[i];
    }
    verileri_Gonder(klar, vler);
  }
}

void ekrana_Yaz(size_t x, size_t y, char *t) {
  int bayt = x;
  for (size_t i = 0; i < strlen(t); i++) {
    unsigned char harf = t[i];
    size_t kacinci = (harf - 32) * 9;
    size_t kac = fontlar_1[kacinci];
    for (size_t j = 0; j < kac; j++)
    {
      ekran[bayt] = fontlar_1[kacinci + 1 + j] << y;
      bayt++;
    }
    bayt++;
  }
}

void guncelle(void) {
  uint8_t temp[kacmatrix * 8];
  for(size_t i = 0; i < _dikey_Matrix * 8; i++) {
    
  }
}

void setup() {
  pinMode(_Load_CS_PIN, OUTPUT);
  Serial.begin(9600);
  SPI.begin();
  dot_Matrix_baslat();
}

void loop() {
  char *te = "abcdefghijklmno";
  ekrana_Yaz(0, 0, te);
  guncelle();
}