<commit_before>#include <SPI.h>

#include "mx7219.h"
#include "pins.h"

byte spi_communicate(byte mxreg, byte mxval, byte key_out = 0) {
    byte key_state;

    SPI.beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE0));
    digitalWrite(DPYSS_BAR, LOW);
    key_state = SPI.transfer(0);
    SPI.transfer(key_out);
    SPI.transfer(mxreg);
    SPI.transfer(mxval);
    digitalWrite(DPYSS_BAR, HIGH);
    SPI.endTransaction();
    return key_state;
}

void setup() {
    digitalWrite(DPYSS_BAR, HIGH);
    pinMode(DPYSS_BAR, OUTPUT);

    digitalWrite(SCK, LOW);
    digitalWrite(MOSI, LOW);
    pinMode(MISO, INPUT);
    pinMode(MOSI, OUTPUT);
    pinMode(SCK, OUTPUT);
    pinMode(SS_BAR, OUTPUT);

    for(int digit=0; digit<8; ++digit) {
        spi_communicate(MX7219_DIGIT_0 + digit, 0);
    }
    spi_communicate(MX7219_DECODE_MODE, 0x00); // No decode
    spi_communicate(MX7219_INTENSITY, 0xFF);   // Maximum intensity
    spi_communicate(MX7219_SCN_LIMIT, 0x05);   // Scan digits 0-5
    spi_communicate(MX7219_DPLY_TEST, 0x00);   // Display test on
    spi_communicate(MX7219_SHUTDOWN, 0x01);    // Normal operation
}

unsigned long addr = 1;
unsigned long chase = 1;
byte state;

#define TICK_DELAY 30
unsigned long next_tick = millis() + TICK_DELAY;

void loop() {
    byte a0_7, a8_15, a16_24, ctrl;

    spi_communicate(MX7219_NOP, 0, 0x1);
    a0_7 = spi_communicate(MX7219_NOP, 0);
    spi_communicate(MX7219_NOP, 0, 0x2);
    a8_15 = spi_communicate(MX7219_NOP, 0);
    spi_communicate(MX7219_NOP, 0, 0x4);
    a16_24 = spi_communicate(MX7219_NOP, 0);
    spi_communicate(MX7219_NOP, 0, 0x8);
    ctrl = spi_communicate(MX7219_NOP, 0);

    spi_communicate(MX7219_DIGIT_0 + 0, ctrl);
    spi_communicate(MX7219_DIGIT_0 + 1, a0_7);
    spi_communicate(MX7219_DIGIT_0 + 2, a8_15);
    spi_communicate(MX7219_DIGIT_0 + 3, a16_24);
    spi_communicate(MX7219_DIGIT_0 + 4, chase & 0xff);
    spi_communicate(MX7219_DIGIT_0 + 5, (chase>>8) & 0xff);

    unsigned long now = millis();
    if(now > next_tick) {
        next_tick = now + TICK_DELAY;

        addr<<=1;
        if(addr >= 1UL<<24) {
            addr = 1;
        }

        chase<<=1;
        if(chase >= 1UL<<16) {
            chase = 1;
        }
    }
}
<commit_msg>make HALT do something in test firmware<commit_after>#include <SPI.h>

#include "mx7219.h"
#include "pins.h"

byte spi_communicate(byte mxreg, byte mxval, byte key_out = 0) {
    byte key_state;

    SPI.beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE0));
    digitalWrite(DPYSS_BAR, LOW);
    key_state = SPI.transfer(0);
    SPI.transfer(key_out);
    SPI.transfer(mxreg);
    SPI.transfer(mxval);
    digitalWrite(DPYSS_BAR, HIGH);
    SPI.endTransaction();
    return key_state;
}

void setup() {
    digitalWrite(DPYSS_BAR, HIGH);
    pinMode(DPYSS_BAR, OUTPUT);

    digitalWrite(SCK, LOW);
    digitalWrite(MOSI, LOW);
    pinMode(MISO, INPUT);
    pinMode(MOSI, OUTPUT);
    pinMode(SCK, OUTPUT);
    pinMode(SS_BAR, OUTPUT);

    for(int digit=0; digit<8; ++digit) {
        spi_communicate(MX7219_DIGIT_0 + digit, 0);
    }
    spi_communicate(MX7219_DECODE_MODE, 0x00); // No decode
    spi_communicate(MX7219_INTENSITY, 0xFF);   // Maximum intensity
    spi_communicate(MX7219_SCN_LIMIT, 0x05);   // Scan digits 0-5
    spi_communicate(MX7219_DPLY_TEST, 0x00);   // Display test on
    spi_communicate(MX7219_SHUTDOWN, 0x01);    // Normal operation
}

unsigned long addr = 1;
unsigned long chase = 1;
byte state;

#define TICK_DELAY 30
unsigned long next_tick = millis() + TICK_DELAY;

#define HALT_MASK (1<<6)

void loop() {
    byte a0_7, a8_15, a16_24, ctrl;

    spi_communicate(MX7219_NOP, 0, 0x1);
    a0_7 = spi_communicate(MX7219_NOP, 0);
    spi_communicate(MX7219_NOP, 0, 0x2);
    a8_15 = spi_communicate(MX7219_NOP, 0);
    spi_communicate(MX7219_NOP, 0, 0x4);
    a16_24 = spi_communicate(MX7219_NOP, 0);
    spi_communicate(MX7219_NOP, 0, 0x8);
    ctrl = spi_communicate(MX7219_NOP, 0);

    spi_communicate(MX7219_DIGIT_0 + 0, ctrl);

    if(ctrl & HALT_MASK) {
        spi_communicate(MX7219_DIGIT_0 + 1, a0_7);
        spi_communicate(MX7219_DIGIT_0 + 2, a8_15);
        spi_communicate(MX7219_DIGIT_0 + 3, a16_24);
        spi_communicate(MX7219_DIGIT_0 + 4, chase & 0xff);
        spi_communicate(MX7219_DIGIT_0 + 5, (chase>>8) & 0xff);
    }

    unsigned long now = millis();
    if(now > next_tick) {
        next_tick = now + TICK_DELAY;

        addr<<=1;
        if(addr >= 1UL<<24) {
            addr = 1;
        }

        chase<<=1;
        if(chase >= 1UL<<16) {
            chase = 1;
        }

        if(!(ctrl & HALT_MASK)) {
            for(int i=1; i<=5; ++i) {
                spi_communicate(MX7219_DIGIT_0 + i, random(0x100));
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.12413503879219963, 'fraction_numerical': 0.07989096246592577, 'mean_word_length': 3.158674803836094, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 15, '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': '6248085', 'n_tokens_mistral': 2186, 'n_tokens_neox': 1931, 'n_words': 352}