<commit_before>#include "controller.h"
#include "SNESPad.h"
#include "gpio.h"
#include "proto.h"
#include "printf.h"

const unsigned CLOCK = GPIO_PIN23;
const unsigned DATA = GPIO_PIN24;
const unsigned LATCH = GPIO_PIN25;

void controller_init(void) {
	gpio_set_function(LATCH, GPIO_FUNC_OUTPUT);
	gpio_set_function(CLOCK, GPIO_FUNC_OUTPUT);
	gpio_set_function(DATA, GPIO_FUNC_INPUT);
}

void latch(void) {
	gpio_write(LATCH, 1);
	gpio_write(LATCH, 0);
}

void clock_pulse(void) {
	gpio_write(CLOCK, 1);
	gpio_write(CLOCK, 0);
}

controller_state getState(void) {
	controller_state cs;

	latch();
	cs.B = !gpio_read(DATA);
	clock_pulse();
	cs.Y = !gpio_read(DATA);
	clock_pulse();
	cs.SELECT = !gpio_read(DATA);
	clock_pulse();
	cs.START = !gpio_read(DATA);
	clock_pulse();
	cs.UP = !gpio_read(DATA);
	clock_pulse();
	cs.DOWN = !gpio_read(DATA);
	clock_pulse();
	cs.LEFT = !gpio_read(DATA);
	clock_pulse();
	cs.RIGHT = !gpio_read(DATA);
	clock_pulse();
	cs.A = !gpio_read(DATA);<commit_msg>Some comments<commit_after>#include "controller.h"
#include "SNESPad.h"
#include "gpio.h"
#include "proto.h"
#include "printf.h"

const unsigned CLOCK = GPIO_PIN23;
const unsigned DATA = GPIO_PIN24;
const unsigned LATCH = GPIO_PIN25;

void controller_init(void) {
	gpio_set_function(LATCH, GPIO_FUNC_OUTPUT);
	gpio_set_function(CLOCK, GPIO_FUNC_OUTPUT);
	gpio_set_function(DATA, GPIO_FUNC_INPUT);
}

void latch(void) {
	gpio_write(LATCH, 1);
	gpio_write(LATCH, 0);
}

// Are you sure the clock on the controller is fast enough? Doesn't
// need interrupts or anything?
void clock_pulse(void) {
	gpio_write(CLOCK, 1);
	gpio_write(CLOCK, 0);
}

controller_state getState(void) {
	controller_state cs;

	latch();
	cs.B = !gpio_read(DATA);
	clock_pulse();
	cs.Y = !gpio_read(DATA);
	clock_pulse();
	cs.SELECT = !gpio_read(DATA);
	clock_pulse();
	cs.START = !gpio_read(DATA);
	clock_pulse();
	cs.UP = !gpio_read(DATA);
	clock_pulse();
	cs.DOWN = !gpio_read(DATA);
	clock_pulse();
	cs.LEFT = !gpio_read(DATA);
	clock_pulse();
	cs.RIGHT = !gpio_read(DATA);
	clock_pulse();
	cs.A = !gpio_read(DATA);
{'fraction_non_alphanumeric': 0.15144230769230768, 'fraction_numerical': 0.009615384615384616, 'mean_word_length': 5.983221476510067, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2063042', 'n_tokens_mistral': 860, 'n_tokens_neox': 815, 'n_words': 162}