 
 #ifdef USE_HARDWARE_SPI
 #include "SPI.h"
-#define SPI_CLOCK_DIV_MAX	SPI_CLOCK_DIV128
 #else
 
-#define SPI_CLOCK_DIV_MAX	255
+#define SPI_MODE0 0x00
+
+class SPISettings {
+public:
+  // clock is in Hz
+  SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) : clock(clock){
+    (void) bitOrder;
+    (void) dataMode;
+  };
+
+private:
+  uint32_t clock;
+
+friend class BitBangedSPI;
+};
 
 class BitBangedSPI {
   public:
-    void setDataMode(uint8_t dataMode) {
-      (void) dataMode;
+
+    void beginTransaction(SPISettings settings) {
+	pulseWidth = 1000 / (settings.clock / 1000);
+        if (pulseWidth == 0)
+          pulseWidth = 1;
     }
-    void setBitOrder(uint8_t bitOrder) {
-      (void) bitOrder;
-    }
-    void setClockDivider(uint8_t clockDiv) {
-      (void) clockDiv;
-    }
 
     void begin() {
-      // slow enough for an attiny85 @ 1MHz
-      // (pulseWidth should be > 2 cpu cycles, so take 3 cycles:)
-      pulseWidth = 3;
       
       pinMode(MISO, INPUT);
       pinMode(RESET, OUTPUT);

#define LED_PMODE 7
#define PROG_FLICKER true

#if !defined(ARDUINO_ARCH_SAM) and !defined(ARDUINO_ARCH_SAMD)

#define USE_HARDWARE_SPI

#endif


// Configure the serial port to use.
//


void setup() {
  SERIAL.begin(19200);

  SPI.beginTransaction(SPISettings(SPI_CLOCK, MSBFIRST, SPI_MODE0));

  pinMode(LED_PMODE, OUTPUT);
  pulse(LED_PMODE, 2);
  pinMode(LED_ERR, OUTPUT);
