Direct Port Manipulation Pins

Current situation on planet freeze..

const uint8_t PC_NOTIFY_PIN = 4; // (Notify FV1 s0)
const uint8_t I2C_EEPROM_EMUL_SDA_PIN = 7; // (FV1 SDA) Was Pin 5
const uint8_t I2C_EEPROM_EMUL_SCL_PIN = 8; // (FV1 SCL) Was Pin 6
void setup()
{
  // 24LC32 EEPROM emulation
  pinMode(PC_NOTIFY_PIN, OUTPUT);
  pinMode(I2C_EEPROM_EMUL_SDA_PIN, INPUT);
  pinMode(I2C_EEPROM_EMUL_SCL_PIN, INPUT);
void send_algo()
{
  // Copy FV-1 algorithm from PROGMEM to ram buffer.
  // Progmem is too slow in the send loop.
  // Since we will anyway have to copy from PROGMEM,
  // it makes sense to compress the algorithms and get
  // space savings (almost 2x).

  uint8_t algo = patch_data[current_patch].algorithm;
  decompress(algo_buffer, (prog_uchar *)pgm_read_word(&(algodata[algo].prog_addr)));

  // Set up everything to be ready
  const uint8_t sda_mask = (1 << PIND7); // Pin7 (was D5)
  const uint8_t clk_mask = (1 << PINB0); // Pin8 (was D6)
  uint8_t prev_clk = clk_mask;

  DDRB &= ~(clk_mask);   // clk pin as input
  DDRD &= ~(sda_mask);   // sda pin as input
  PORTD &= ~(sda_mask);  // SDA pin is pulled low or floated up
  // -> we need to set pin low only once.
  //    Toggling is done by setting pin to
  //    input (let float high) or output (pull low).
  //    FV-1 internal pullups are ok (tested).

  uint16_t pos = 0;
  uint8_t curr_byte = algo_buffer[pos];
  uint8_t bit_mask = 0b10000000;
  uint8_t clk_count = 0;

  // Undivided attention for FV-1 requests
  noInterrupts();

  // Notify FV-1 of patch change by toggling the notify pin
  PIND = _BV(4);   // Toggle pin 4
 
  while (clk_count < 37)             // Handle the header
  {
    uint8_t clk = PINB & clk_mask;

    if (!clk && prev_clk) {          // scl went down

      switch (clk_count)
      {
        case 8:
        case 17:
        case 26:
        case 36:
          DDRD  |= sda_mask;         // send ACK - pull sda pin low
          break;
        default:
          DDRD &= ~(sda_mask);       // Release
          break;
      }
      
      clk_count++;
    }
    prev_clk = clk;
  }
  
  ////Freezes Here////
  
  //// Blue Test Led //// Blue Test Led //// Blue Test Led ////
  pixels.begin();
  pixels.setPixelColor(0, 0, 0, 50); // BLUE
  pixels.show(); 
  //// Blue Test Led //// Blue Test Led //// Blue Test Led ////
  
  clk_count = 0;
  while (pos < 512)                  // Send the data
  {
    uint8_t clk = PINB & clk_mask;

    if (!clk && prev_clk) {          // scl went down

      if (clk_count != 8) {          // Sending byte

        if (curr_byte & bit_mask) {
          DDRD &= ~(sda_mask);       // Send 1 = Let High
        } else {
          DDRD  |= sda_mask;         // Send 0 = Pull Low
        }
        bit_mask >>= 1;
        clk_count++;

      } else {                       // Let reciever ACK

        DDRD &= ~(sda_mask);         // Release
        clk_count = 0;
        bit_mask = 0b10000000;
        pos++;
        curr_byte = algo_buffer[pos];
      }
    }
    prev_clk = clk;
  }

  interrupts();

}