<commit_before>/**
 * @file logicdisplay.c
 * @author <NAME>
 * @date 2017-11-07
 *
 * @brief Implementation of the logic displays.
 *
 * The front logic display consists of two LED matrices with 4x7 LEDs. The rows
 * are powered by an ULN2804 chip. The columns are controlled by uC pins.
 *
 * The rear logic display has 4 rows and 22 columns, so a 16bit-demux (4 uC
 * pins) + 6 uC pins are used to switch through the columns. The rows are also
 * directly connected to the uC.
 *
 * Settings: >60 frames per second necessary for the eye. 60Hz * 8 rows of
 * front display gives row switch rate of <2ms. Switching all columns of the
 * rear display with >60Hz we have to update at <0.7ms.
 *
 * Low on row r and high on column c means the LED_{r,c} is on.
 */

#include "logicdisplay.h"
#include "io.h"	// port, pins definition
#include "gpt.h"

#include <avr/io.h>	// e.g., uint8_t
#include <stdlib.h>     // rand, srand

#define LD_FRONT_ROWS           (8)
#define LD_FRONT_COLS           (7)
#define LD_REAR_ROWS            (4)
#define LD_REAR_COLS            (22)

#define LD_REAR_COLS_UC         (0x7E) // column pins to LEDs directly
#define LD_REAR_DISABLE_DM      (0x80) // enable pin for demux (active low)
#define LD_REAR_COLS_DM         (0x0F) // column pins to demux
#define LD_REAR_ROWS_UC         (0xF0) // row pins of PORT2 (active high)

/** Status of the LEDs (0/1 .. on/off; one byte -- columns -- for each row) */
static volatile uint8_t frame_front[LD_FRONT_ROWS];
static volatile uint8_t frame_rear[LD_REAR_COLS];


/** Turn off all columns. */
static void logicdisplay_rear_reset_columns(void) {
    // 1 .. off
    LOGICDISPLAY_REAR_PORT1 |= LD_REAR_COLS_UC;
    // disable demux (all outputs high)
    LOGICDISPLAY_REAR_PORT1 |= LD_REAR_DISABLE_DM;
}

/** Switch to the specified column (0 .. LD_REAR_COLS-1). */
static void logicdisplay_rear_set_column(uint8_t column) {
    // 0 .. on
    if (column < 16) {
        // first 16 LED columns controlled by demux
        // set column and enable
        LOGICDISPLAY_REAR_PORT2 &= ~(LD_REAR_COLS_DM);
        LOGICDISPLAY_REAR_PORT2 |= column;
        LOGICDISPLAY_REAR_PORT1 &= ~(LD_REAR_DISABLE_DM);
    } else {
        // top 6 LED columns controlled by uc directly
        LOGICDISPLAY_REAR_PORT1 &= ~(1 << (column-16+1));
    }
}

/** Applys a row frame to the LEDs. */
static void logicdisplay_rear_apply(uint8_t frame) {
    // 1 .. on
    LOGICDISPLAY_REAR_PORT2 &= ~(LD_REAR_ROWS_UC);
    LOGICDISPLAY_REAR_PORT2 |= (frame & LD_REAR_ROWS_UC);
}

/** Applys columns of the frame to the LEDs subsequently. */
static void logicdisplay_step(void)<commit_msg>fix final rear logic display wiring<commit_after>/**
 * @file logicdisplay.c
 * @author <NAME>
 * @date 2017-11-07
 *
 * @brief Implementation of the logic displays.
 *
 * The front logic display consists of two LED matrices with 4x7 LEDs. The rows
 * are powered by an ULN2804 chip. The columns are controlled by uC pins.
 *
 * The rear logic display has 4 rows and 22 columns, so a 16bit-demux (4 uC
 * pins) + 6 uC pins are used to switch through the columns. The rows are also
 * directly connected to the uC.
 *
 * Settings: >60 frames per second necessary for the eye. 60Hz * 8 rows of
 * front display gives row switch rate of <2ms. Switching all columns of the
 * rear display with >60Hz we have to update at <0.7ms.
 *
 * Low on row r and high on column c means the LED_{r,c} is on.
 */

#include "logicdisplay.h"
#include "io.h"	// port, pins definition
#include "gpt.h"

#include <avr/io.h>	// e.g., uint8_t
#include <stdlib.h>     // rand, srand

#define LD_FRONT_ROWS           (8)
#define LD_FRONT_COLS           (7)
#define LD_REAR_ROWS            (4)
#define LD_REAR_COLS            (22)

#define LD_REAR_COLS_UC         (0xFC) // column pins to LEDs directly
#define LD_REAR_DISABLE_DM      (0x02) // enable pin for demux (active low)
#define LD_REAR_COLS_DM         (0x0F) // column pins to demux
#define LD_REAR_ROWS_UC         (0xF0) // row pins of PORT2 (active high)

/** Status of the LEDs (0/1 .. on/off; one byte -- columns -- for each row) */
static volatile uint8_t frame_front[LD_FRONT_ROWS];
static volatile uint8_t frame_rear[LD_REAR_COLS];


/** Turn off all columns. */
static void logicdisplay_rear_reset_columns(void) {
    // 1 .. off
    LOGICDISPLAY_REAR_PORT1 |= LD_REAR_COLS_UC;
    // disable demux (all outputs high)
    LOGICDISPLAY_REAR_PORT1 |= LD_REAR_DISABLE_DM;
}

/** Switch to the specified column (0 .. LD_REAR_COLS-1). */
static void logicdisplay_rear_set_column(uint8_t column) {
    // 0 .. on
    if (column < 16) {
        // first 16 LED columns controlled by demux
        // set column and enable
        LOGICDISPLAY_REAR_PORT2 &= ~(LD_REAR_COLS_DM);
        LOGICDISPLAY_REAR_PORT2 |= column;
        LOGICDISPLAY_REAR_PORT1 &= ~(LD_REAR_DISABLE_DM);
    } else {
        // top 6 LED columns controlled by uc directly
        LOGICDISPLAY_REAR_PORT1 &= ~(1 << (column-16+2));
    }
}

/** Applys a row frame to the LEDs. */
static void logicdisplay_rear_apply(uint8_t frame) {
    // 1 .. on
    LOGICDISPLAY_REAR_PORT2 &= ~(LD_REAR_ROWS_UC);
    LOGICDISPLAY_REAR_PORT2 |= (frame & LD_REAR_ROWS_UC);
}

/** Applys columns of the frame to the LEDs subsequently. */
static void logicdisplay_step(void)
{'fraction_non_alphanumeric': 0.10075471698113207, 'fraction_numerical': 0.02811320754716981, 'mean_word_length': 2.9917168674698793, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 13, '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': '4314265', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1837, 'n_words': 604}