Pi Firmware: Added actions for SW1/2/3

Change-Id: I80749094e2447cfb37682bc7b0b33950f6fc636b
issue_1022
David Banks 2018-06-08 22:49:53 +01:00
rodzic 8a76edac33
commit 40e1dfe592
4 zmienionych plików z 112 dodań i 17 usunięć

Wyświetl plik

@ -7,6 +7,8 @@ typedef struct {
const char *name;
void (*init)();
void (*change_mode)(int mode7);
void (*inc_sampling_base)(int mode7);
void (*inc_sampling_offset)(int mode7);
void (*calibrate)(int mode7, int elk, int chars_per_line);
} cpld_t;

Wyświetl plik

@ -54,6 +54,12 @@ static void write_config(int *sp_base, int *sp_offset) {
RPI_SetGpioValue(SP_DATA_PIN, 0);
}
static void log_sp(int *sp_base, int *sp_offset) {
log_info("sp_base = %d %d %d, sp_offset = %d %d %d %d %d %d",
sp_base[0], sp_base[1], sp_base[2],
sp_offset[0], sp_offset[1], sp_offset[2], sp_offset[3], sp_offset[4], sp_offset[5]);
}
// =============================================================
// Public methods
// =============================================================
@ -145,9 +151,8 @@ static void cpld_calibrate(int mode7, int elk, int chars_per_line) {
}
}
log_info("Calibration complete: sp_base = %d %d %d, sp_offset = %d %d %d %d %d %d",
sp_base[0], sp_base[1], sp_base[2],
sp_offset[0], sp_offset[1], sp_offset[2], sp_offset[3], sp_offset[4], sp_offset[5]);
log_info("Calibration complete");
log_sp(sp_base, sp_offset);
write_config(sp_base, sp_offset);
}
@ -159,9 +164,32 @@ static void cpld_change_mode(int mode7) {
}
}
static void cpld_inc_sampling_base(int mode7) {
int *sp_base = mode7 ? mode7_sp_base : default_sp_base;
int *sp_offset = mode7 ? mode7_sp_offset : default_sp_offset;
int limit = mode7 ? 8 : 6;
for (int i = 0; i < NUM_CHANNELS; i++) {
sp_base[i] = (sp_base[i] + 1) % limit;
}
log_sp(sp_base, sp_offset);
write_config(sp_base, sp_offset);
}
static void cpld_inc_sampling_offset(int mode7) {
int *sp_base = mode7 ? mode7_sp_base : default_sp_base;
int *sp_offset = mode7 ? mode7_sp_offset : default_sp_offset;
for (int i = 0; i < NUM_OFFSETS; i++) {
sp_offset[i] = ((sp_offset[i] + 2) % 3) - 1;
}
log_sp(sp_base, sp_offset);
write_config(sp_base, sp_offset);
}
cpld_t cpld_alternative = {
.name = "Alternative",
.init = cpld_init,
.inc_sampling_base = cpld_inc_sampling_base,
.inc_sampling_offset = cpld_inc_sampling_offset,
.calibrate = cpld_calibrate,
.change_mode = cpld_change_mode
};

Wyświetl plik

@ -42,6 +42,16 @@ static void write_config(int *sp_mode7, int def) {
RPI_SetGpioValue(SP_DATA_PIN, 0);
}
static void log_sp_mode7() {
log_info("sp_mode7 = %d %d %d %d %d %d",
sp_mode7[0], sp_mode7[1], sp_mode7[2],
sp_mode7[3], sp_mode7[4], sp_mode7[5]);
}
static void log_sp_default() {
log_info("sp_default = %d", sp_default);
}
// =============================================================
// Public methods
// =============================================================
@ -116,6 +126,8 @@ static void cpld_calibrate(int mode7, int elk, int chars_per_line) {
log_debug("nudged %d right, metric = %d", i, ref);
}
}
log_info("Calibration complete:");
log_sp_mode7();
write_config(sp_mode7, sp_default);
}
@ -135,7 +147,8 @@ static void cpld_calibrate(int mode7, int elk, int chars_per_line) {
}
}
sp_default = min_i;
log_info("Setting sp_default = %d", min_i);
log_sp_default();
log_info("Calibration complete:");
write_config(sp_mode7, sp_default);
}
}
@ -144,9 +157,28 @@ static void cpld_change_mode(int mode7) {
// currently nothing to do
}
static void cpld_inc_sampling_base(int mode7) {
if (mode7) {
for (int i = 0; i < NUM_OFFSETS; i++) {
sp_mode7[i] = (sp_mode7[i] + 1) % 8;
}
log_sp_mode7();
} else {
sp_default = (sp_default + 1) % 6;
log_sp_default();
}
write_config(sp_mode7, sp_default);
}
static void cpld_inc_sampling_offset(int mode7) {
//
}
cpld_t cpld_normal = {
.name = "Normal",
.init = cpld_init,
.inc_sampling_base = cpld_inc_sampling_base,
.inc_sampling_offset = cpld_inc_sampling_offset,
.calibrate = cpld_calibrate,
.change_mode = cpld_change_mode
};

Wyświetl plik

@ -30,6 +30,9 @@ cpld_t *cpld = &cpld_normal;
// #define INSTRUMENT_CAL
#define NUM_CAL_PASSES 1
#define SHORT_PRESS 0
#define LONG_PRESS 1
#ifdef DOUBLE_BUFFER
#include "rpi-interrupts.h"
#endif
@ -44,6 +47,8 @@ extern int rgb_to_fb(unsigned char *fb, int chars_per_line, int bytes_per_line,
extern int measure_vsync();
static int mux = 0;
// 0 0 Hz Ground
// 1 19.2 MHz oscillator
// 2 0 Hz testdebug0
@ -309,7 +314,7 @@ void init_hardware() {
RPI_SetGpioPinFunction(SPARE_PIN, FS_INPUT);
RPI_SetGpioValue(SP_CLK_PIN, 1);
RPI_SetGpioValue(SP_DATA_PIN, 0);
RPI_SetGpioValue(MUX_PIN, 0);
RPI_SetGpioValue(MUX_PIN, mux);
RPI_SetGpioValue(LED1_PIN, 1); // 1 is off
RPI_SetGpioValue(SP_CLKEN_PIN, 0);
@ -507,13 +512,19 @@ int total_N_frames(int sp, int n, int mode7, int elk, int chars_per_line) {
}
#endif
// Wait for the cal button to be released
void wait_for_cal_release() {
int cal_bit = 0;
// Wait for a switch to be released
int wait_for_sw_release(int switch_pin) {
int bit = 0;
int length = 0;
volatile int j;
log_debug("waiting for switch release (gpio%d)", switch_pin);
do {
cal_bit = ((*(volatile uint32_t *)(PERIPHERAL_BASE + 0x200034)) >> SW1_PIN) & 1;
log_debug("cal_bit = %d", cal_bit);
} while (cal_bit == 0);
bit = RPI_GetGpioValue(switch_pin);
for (j = 0; j < 10000; j++);
length ++;
} while (bit == 0);
log_debug("switch release (length %d)", length);
return (length > 10000) ? LONG_PRESS : SHORT_PRESS;
}
int test_for_elk(int mode7, int chars_per_line) {
@ -585,6 +596,10 @@ void rgb_to_hdmi_main() {
init_framebuffer(mode7);
log_debug("Done setting up frame buffer");
log_debug("Loading sample points");
cpld->change_mode(mode7);
log_debug("Done loading sample points");
int chars_per_line = mode7 ? MODE7_CHARS_PER_LINE : DEFAULT_CHARS_PER_LINE;
do {
@ -594,14 +609,32 @@ void rgb_to_hdmi_main() {
log_debug("Leaving rgb_to_fb, result= %d", result);
if (result & RET_SW1) {
wait_for_cal_release();
elk = test_for_elk(mode7, chars_per_line);
RPI_SetGpioValue(MUX_PIN, elk);
log_debug("Elk mode = %d", elk);
for (int c = 0; c < NUM_CAL_PASSES; c++) {
cpld->calibrate(mode7, elk, chars_per_line);
int type = wait_for_sw_release(SW1_PIN);
if (type == LONG_PRESS) {
// Calibrate
elk = test_for_elk(mode7, chars_per_line);
log_debug("Elk mode = %d", elk);
for (int c = 0; c < NUM_CAL_PASSES; c++) {
cpld->calibrate(mode7, elk, chars_per_line);
}
} else {
// Cycle to next sampling point
cpld->inc_sampling_base(mode7);
}
}
if (result & RET_SW2) {
// Cycle to next sampling point
wait_for_sw_release(SW2_PIN);
cpld->inc_sampling_offset(mode7);
}
if (result & RET_SW3) {
// Toggle input mux
wait_for_sw_release(SW3_PIN);
mux = 1 - mux;
RPI_SetGpioValue(MUX_PIN, mux);
log_info("mux = %d", mux);
}
last_mode7 = mode7;
mode7 = result & BIT_MODE7;