<commit_before>/*
 * Copyright (C) 2013-2017 by <NAME> <<EMAIL>>
 * Gameduino 2/3 library for Arduino, Arduino Due, Raspberry Pi,
 * Teensy 3.2 and ESP8266.
 *
 */

#ifndef _GD2_H_INCLUDED
#define _GD2_H_INCLUDED

#if defined(RASPBERRY_PI) || defined(DUMPDEV)
#include "wiring.h"
#endif

#include "Arduino.h"
#include <stdarg.h>

#define RGB(r, g, b)    ((uint32_t)((((r) & 0xffL) << 16) | (((g) & 0xffL) << 8) | ((b) & 0xffL)))
#define F8(x)           (int((x) * 256L))
#define F16(x)          ((int32_t)((x) * 65536L))

#define GD_CALIBRATE    1
#define GD_TRIM         2
#define GD_STORAGE      4

#ifdef __SAM3X8E__
#define __DUE__ 1
#endif

////////////////////////////////////////////////////////////////////////
// Decide if we want to compile in SDcard support
//
// For stock Arduino models: yes
// Raspberry PI: no
// Arduino Due: no
//

#if !defined(RASPBERRY_PI) && !defined(DUMPDEV)
#define SDCARD 1
#else
#define SDCARD 0
#endif

#if defined(__DUE__)
#define MOSI  11
#define MISO  12
#define SCK   13    // B.27

class ASPI_t {
public:
  void begin(void) {
    pinMode(MOSI, OUTPUT);
    pinMode(MISO, INPUT);
    pinMode(SCK, OUTPUT);
    digitalWrite(SCK, 0);

    // PIOB->PIO_PER = PIO_PB27;
    // PIOB->PIO_CODR = PIO_PB27;
    // PIOB->PIO_PUDR = PIO_PB27;
  }
  byte transfer(byte x ) {
    byte r = 0;
    for (byte i = 8; i; i--) {
      if (x & 0x80)
        PIOD->PIO_SODR = PIO_PD7;
      else
        PIOD->PIO_CODR = PIO_PD7;
      // digitalWrite(MOSI, (x >> 7) & 1);
      x <<= 1;
      // digitalWrite(SCK, 1);
      PIOB->PIO_SODR = PIO_PB27;
      r <<= 1;
      r |= digitalRead(MISO);
      // digitalWrite(SCK, 0);
      PIOB->PIO_CODR = PIO_PB27;
    }
    return r;
  }
};
static class ASPI_t ASPI;
#define SPI ASPI

#endif

#if defined(ARDUINO_STM32L4_BLACKICE)
// BlackIce Board uses SPI1 on the Arduino header.
#define SPI SPI1
// Board Support:<commit_msg>Implement block transfer for Due's SPI emulation<commit_after>/*
 * Copyright (C) 2013-2017 by <NAME> <<EMAIL>>
 * Gameduino 2/3 library for Arduino, Arduino Due, Raspberry Pi,
 * Teensy 3.2 and ESP8266.
 *
 */

#ifndef _GD2_H_INCLUDED
#define _GD2_H_INCLUDED

#if defined(RASPBERRY_PI) || defined(DUMPDEV)
#include "wiring.h"
#endif

#include "Arduino.h"
#include <stdarg.h>

#define RGB(r, g, b)    ((uint32_t)((((r) & 0xffL) << 16) | (((g) & 0xffL) << 8) | ((b) & 0xffL)))
#define F8(x)           (int((x) * 256L))
#define F16(x)          ((int32_t)((x) * 65536L))

#define GD_CALIBRATE    1
#define GD_TRIM         2
#define GD_STORAGE      4

#ifdef __SAM3X8E__
#define __DUE__ 1
#endif

////////////////////////////////////////////////////////////////////////
// Decide if we want to compile in SDcard support
//
// For stock Arduino models: yes
// Raspberry PI: no
// Arduino Due: no
//

#if !defined(RASPBERRY_PI) && !defined(DUMPDEV)
#define SDCARD 1
#else
#define SDCARD 0
#endif

#if defined(__DUE__)
#define MOSI  11
#define MISO  12
#define SCK   13    // B.27

class ASPI_t {
public:
  void begin(void) {
    pinMode(MOSI, OUTPUT);
    pinMode(MISO, INPUT);
    pinMode(SCK, OUTPUT);
    digitalWrite(SCK, 0);

    // PIOB->PIO_PER = PIO_PB27;
    // PIOB->PIO_CODR = PIO_PB27;
    // PIOB->PIO_PUDR = PIO_PB27;
  }
  byte transfer(byte x ) {
    byte r = 0;
    for (byte i = 8; i; i--) {
      if (x & 0x80)
        PIOD->PIO_SODR = PIO_PD7;
      else
        PIOD->PIO_CODR = PIO_PD7;
      // digitalWrite(MOSI, (x >> 7) & 1);
      x <<= 1;
      // digitalWrite(SCK, 1);
      PIOB->PIO_SODR = PIO_PB27;
      r <<= 1;
      r |= digitalRead(MISO);
      // digitalWrite(SCK, 0);
      PIOB->PIO_CODR = PIO_PB27;
    }
    return r;
  }
  void transfer(byte*m, int s) {
    while (s--) {
      *m = transfer(*m);
      m++;
    }
  }
};
static class ASPI_t ASPI;
#define SPI ASPI

#endif

#if defined(ARDUINO_STM32L4_BLACKICE)
// BlackIce Board uses SPI1 on the Arduino header.
#define SPI SPI1
// Board Support:
{'fraction_non_alphanumeric': 0.18200305033045247, 'fraction_numerical': 0.042704626334519574, 'mean_word_length': 2.3603757472245945, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, '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': '7494183', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1623, 'n_words': 402}