<commit_before>#include "main.h"

void sendToLED (const uint8_t rgb[3])
{
    // RESET: 24us low
    // 0 bit: 0.7us high, 1.8us low, 200ns tolerance
    // 1 bit: 1.8us high, 0.7us low, 200ns tolerance
    
    // 10MHz clock: 1 cycle per 0.1us
    
    register uint8_t p = LED_PORT;
    
    register uint8_t byteCounter = 0;
    register uint8_t bitCounter = 0;
    register uint8_t workingByte = 0;
    
    // send a reset pulse
    clear (LED_PORT, LED_NUM);
    _delay_us (25);
    
    for (uint8_t timerLED = 0; timerLED != 2/*NUM_LEDS*/; timerLED++)
    {
        _delay_us (5);
        
        const uint8_t *x = rgb;
        
        /*
        // test:
        for (int i = 0; i < 3; i++)
        {
            __asm__ volatile
            (
              "ld %[byte], X+;\n"
              : [X]"+x"(x),
                [byte]"+r"(workingByte)
            );
            
            for (int j = 7; j >= 0; j--)
            {
                if (workingByte & (1 << j))
                    set (LED_PORT, LED_NUM);
                else
                    clear (LED_PORT, LED_NUM);
                _delay_us (1);
            }
            
            clear (LED_PORT, LED_NUM);
            _delay_us (5);
        }
        */
        
        // 10MHz clock:
        //   high bit must be 18 cycles high and 7 cycles low
        //   low bit must be 7 cycles high and 18 cycles low
        // There should be no delay between the RGB bytes an individual LED
        
        __asm__ volatile
        (
         "ldi %[byteCount], 3;         \n" // (1) load 3 into the byte count register
         "ld %[byte], X+;              \n" // (2) load byte from rgb[] and increment pointer
         
         // this runs on the first bit of every byte
         "byteLoop:                    \n"
         "  ldi %[bitCount], 8;        \n" // (1) load 8 into the bit count register
         "  ori %[buffer], %[pinHigh]; \n" // (1) LED output high in temp port buffer
         "  out %[port], %[buffer];    \n" // (1) send port buffer to port (LED HIGH)
         
	     "  sbrs %[byte], 7;           \n" // (1 if false, 2 if true) test MSB of input byte, skip if 1
	     "  rjmp lowBit;               \n" // (2) jump to lowBit if the MSB was 0
	     "  rjmp highBit;              \n" // (2) jump to highBit if the MSB was 1
         
         // this runs for all bits except the first
         "bitLoop:                     \n"
         "  nop;                       \n"
         "  nop;                       \n"
	     "  nop;                       \n" // (3)
         "  ori %[buffer], %[pinHigh]; \n" // (1) LED output high in temp port buffer
         "  out %[port], %[buffer];    \n" // (1) send port buffer to port (LED HIGH)
         <commit_msg>Removed debug code from sendToLED.c<commit_after>#include "main.h"

void sendToLED (const uint8_t rgb[3])
{
    // RESET: 24us low
    // 0 bit: 0.7us high, 1.8us low, 200ns tolerance
    // 1 bit: 1.8us high, 0.7us low, 200ns tolerance
    
    // 10MHz clock: 1 cycle per 0.1us
    
    register uint8_t p = LED_PORT;
    
    register uint8_t byteCounter = 0;
    register uint8_t bitCounter = 0;
    register uint8_t workingByte = 0;
    
    // send a reset pulse
    clear (LED_PORT, LED_NUM);
    _delay_us (25);
    
    for (uint8_t timerLED = 0; timerLED != NUM_LEDS; timerLED++)
    {
        const uint8_t *x = rgb;
        
        // 10MHz clock:
        //   high bit must be 18 cycles high and 7 cycles low
        //   low bit must be 7 cycles high and 18 cycles low
        // There should be no delay between the RGB bytes an individual LED
        
        __asm__ volatile
        (
         "ldi %[byteCount], 3;         \n" // (1) load 3 into the byte count register
         "ld %[byte], X+;              \n" // (2) load byte from rgb[] and increment pointer
         
         // this runs on the first bit of every byte
         "byteLoop:                    \n"
         "  ldi %[bitCount], 8;        \n" // (1) load 8 into the bit count register
         "  ori %[buffer], %[pinHigh]; \n" // (1) LED output high in temp port buffer
         "  out %[port], %[buffer];    \n" // (1) send port buffer to port (LED HIGH)
         
	     "  sbrs %[byte], 7;           \n" // (1 if false, 2 if true) test MSB of input byte, skip if 1
	     "  rjmp lowBit;               \n" // (2) jump to lowBit if the MSB was 0
	     "  rjmp highBit;              \n" // (2) jump to highBit if the MSB was 1
         
         // this runs for all bits except the first
         "bitLoop:                     \n"
         "  nop;                       \n"
         "  nop;                       \n"
	     "  nop;                       \n" // (3)
         "  ori %[buffer], %[pinHigh]; \n" // (1) LED output high in temp port buffer
         "  out %[port], %[buffer];    \n" // (1) send port buffer to port (LED HIGH)
         
{'fraction_non_alphanumeric': 0.11371988566761944, 'fraction_numerical': 0.02837893017558187, 'mean_word_length': 1.244159413650939, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, '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': '2307200', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1533, 'n_words': 566}