|
@@ -31,6 +31,7 @@
|
|
#include "spi.h"
|
|
#include "spi.h"
|
|
#include "utils.h"
|
|
#include "utils.h"
|
|
#include "registers.h"
|
|
#include "registers.h"
|
|
|
|
+#include "buttons.h"
|
|
#include "generation.h"
|
|
#include "generation.h"
|
|
|
|
|
|
/* FLASH */
|
|
/* FLASH */
|
|
@@ -77,6 +78,26 @@ static bool timer_expired()
|
|
return success;
|
|
return success;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static void write_regs_to_mailbox()
|
|
|
|
+{
|
|
|
|
+ mailbox_regs->regs.period1 = out_params.regs._period1;
|
|
|
|
+ // TODO: seems like period2 etc are missing
|
|
|
|
+ mailbox_regs->regs.delay1 = out_params.regs.D1 / FXP_SCALING;
|
|
|
|
+ //mailbox_regs->regs.period2 = out_params.regs._period2;
|
|
|
|
+ mailbox_regs->regs.delay2 = out_params.regs.D2 / FXP_SCALING;
|
|
|
|
+ //mailbox_regs->regs.duty3 = out_params.regs._du
|
|
|
|
+ mailbox_regs->regs.delay3 = out_params.regs.D3 / FXP_SCALING;
|
|
|
|
+ mailbox_regs->regs.npuls3 = out_params.regs.N3;
|
|
|
|
+ mailbox_regs->regs.odd_train_flag = N_PULSE_TRAINS; // TODO: is this proper?
|
|
|
|
+ mailbox_regs->regs.ena_odd_out3 = out_params.regs.ena;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void clear_button_regs()
|
|
|
|
+{
|
|
|
|
+ for (int i = 0; i < 16; ++i)
|
|
|
|
+ mailbox_button_regs->data[i] = 0x0;
|
|
|
|
+}
|
|
|
|
+
|
|
static void print_mailbox_contents()
|
|
static void print_mailbox_contents()
|
|
{
|
|
{
|
|
int i = 0;
|
|
int i = 0;
|
|
@@ -112,21 +133,6 @@ static void store_generation_values_flash()
|
|
while (flash_read_sr() & 0x01) /* WIP bit */;
|
|
while (flash_read_sr() & 0x01) /* WIP bit */;
|
|
}
|
|
}
|
|
|
|
|
|
-/*
|
|
|
|
-static void dummy_write_to_flash()
|
|
|
|
-{
|
|
|
|
- printf("Dummy writing to flash\n");
|
|
|
|
- int i = 0;
|
|
|
|
- for (i = 0; i < 16; ++i)
|
|
|
|
- {
|
|
|
|
- mailbox_regs->data[i] = 0x7890;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- print_mailbox_contents();
|
|
|
|
- store_mailbox_regs_flash();
|
|
|
|
-}
|
|
|
|
-*/
|
|
|
|
-
|
|
|
|
static void
|
|
static void
|
|
serial_no_init()
|
|
serial_no_init()
|
|
{
|
|
{
|
|
@@ -222,7 +228,7 @@ boot_dfu(void)
|
|
void
|
|
void
|
|
usb_dfu_rt_cb_reboot(void)
|
|
usb_dfu_rt_cb_reboot(void)
|
|
{
|
|
{
|
|
- boot_dfu();
|
|
|
|
|
|
+ boot_dfu();
|
|
}
|
|
}
|
|
|
|
|
|
void main()
|
|
void main()
|
|
@@ -250,7 +256,10 @@ void main()
|
|
read_generation_values_from_flash();
|
|
read_generation_values_from_flash();
|
|
|
|
|
|
/* If values are wrong - fill defaults */
|
|
/* If values are wrong - fill defaults */
|
|
- validate_generation_values(&out_params.regs);
|
|
|
|
|
|
+ if (validate_generation_values(&out_params.regs) != 0)
|
|
|
|
+ init_params(&out_params.regs);
|
|
|
|
+
|
|
|
|
+ write_regs_to_mailbox();
|
|
|
|
|
|
/* Main loop */
|
|
/* Main loop */
|
|
while (1)
|
|
while (1)
|
|
@@ -258,11 +267,15 @@ void main()
|
|
/* Run the timer for button updates periodically */
|
|
/* Run the timer for button updates periodically */
|
|
if (timer_expired())
|
|
if (timer_expired())
|
|
{
|
|
{
|
|
- update_three_signal_values();
|
|
|
|
|
|
+ update_three_signal_values(&out_params.regs, mailbox_button_regs);
|
|
|
|
+ // button registers have to be cleared upon reading
|
|
|
|
+ clear_button_regs();
|
|
|
|
+ write_regs_to_mailbox();
|
|
// TODO: need a new value to write contents to flash ( probably +1 mailbox?)
|
|
// TODO: need a new value to write contents to flash ( probably +1 mailbox?)
|
|
//write_to_flash();
|
|
//write_to_flash();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // TODO: Add incrementing/decrementing values from console
|
|
#ifdef USE_KEYBOARD
|
|
#ifdef USE_KEYBOARD
|
|
/* Prompt ? */
|
|
/* Prompt ? */
|
|
if (cmd >= 0)
|
|
if (cmd >= 0)
|