Compare commits
No commits in common. "af3790be0dfe7f02770c72bc7976a929059d0574" and "56053c7f33bc7a18e39e21e5eb0fb36e09b502bf" have entirely different histories.
af3790be0d
...
56053c7f33
2 changed files with 15 additions and 490 deletions
|
@ -25,10 +25,6 @@
|
||||||
#define SI5351_ADDRESS 0x60
|
#define SI5351_ADDRESS 0x60
|
||||||
|
|
||||||
#define SI5351_REGISTER_3_OUTPUT_ENABLE_CONTROL 3
|
#define SI5351_REGISTER_3_OUTPUT_ENABLE_CONTROL 3
|
||||||
// ...
|
|
||||||
#define SI5351_REGISTER_26_MSNA 26
|
|
||||||
#define SI5351_REGISTER_34_MSNB 34
|
|
||||||
// ...
|
|
||||||
#define SI5351_REGISTER_177_PLL_RESET 177
|
#define SI5351_REGISTER_177_PLL_RESET 177
|
||||||
|
|
||||||
#define SYM_ENTRY(SYM) { SYM, sizeof(SYM) / 2 }
|
#define SYM_ENTRY(SYM) { SYM, sizeof(SYM) / 2 }
|
||||||
|
@ -169,30 +165,15 @@ static const struct symbol symbol_table[] = { SYM_ENTRY(sym_0),
|
||||||
|
|
||||||
enum input { cw, ccw, click, hold };
|
enum input { cw, ccw, click, hold };
|
||||||
|
|
||||||
static volatile enum state { home, ch1, ch2, ch3, plla, pllb, setup } current_state = home;
|
static volatile enum state { home, ch1, ch2, ch3, setup } current_state = home;
|
||||||
static volatile enum state home_state = ch1;
|
static volatile enum state home_state = ch1;
|
||||||
static volatile enum setup_state { contrast, backlight, back, change_contrast, change_backlight } setup_state = contrast;
|
static volatile enum setup_state { contrast, backlight, back, change_contrast, change_backlight } setup_state = contrast;
|
||||||
static volatile enum pll_state { integer, numerator, denominator, pll_back, change_integer, change_numerator, change_denominator } pll_state = integer;
|
|
||||||
|
|
||||||
static volatile uint8_t enc = 0;
|
static volatile uint8_t enc = 0;
|
||||||
static volatile uint8_t select_offset = 0;
|
|
||||||
static volatile uint8_t digit_select = 0;
|
|
||||||
static volatile uint8_t max_digits = 0;
|
|
||||||
static volatile bool digit_selected = false;
|
|
||||||
|
|
||||||
static volatile uint8_t value_contrast;
|
static volatile uint8_t value_contrast;
|
||||||
static volatile uint8_t value_backlight;
|
static volatile uint8_t value_backlight;
|
||||||
|
|
||||||
struct pll_config {
|
|
||||||
uint8_t reg;
|
|
||||||
uint32_t integer;
|
|
||||||
uint32_t numerator;
|
|
||||||
uint32_t denominator;
|
|
||||||
};
|
|
||||||
|
|
||||||
static volatile struct pll_config plla_config = { SI5351_REGISTER_26_MSNA, 0, 0, 0 };
|
|
||||||
static volatile struct pll_config pllb_config = { SI5351_REGISTER_34_MSNB, 0, 0, 0 };
|
|
||||||
|
|
||||||
static const uint8_t m_si5351_regs_15to92_149to170[100][2] = {
|
static const uint8_t m_si5351_regs_15to92_149to170[100][2] = {
|
||||||
// Init
|
// Init
|
||||||
{3, 0xFF},
|
{3, 0xFF},
|
||||||
|
@ -210,20 +191,15 @@ static const uint8_t m_si5351_regs_15to92_149to170[100][2] = {
|
||||||
{21, 0x80}, /* CLK5 Control: Not used ... clock powered down */
|
{21, 0x80}, /* CLK5 Control: Not used ... clock powered down */
|
||||||
{22, 0x80}, /* CLK6 Control: Not used ... clock powered down */
|
{22, 0x80}, /* CLK6 Control: Not used ... clock powered down */
|
||||||
{23, 0x80}, /* CLK7 Control: Not used ... clock powered down */
|
{23, 0x80}, /* CLK7 Control: Not used ... clock powered down */
|
||||||
{24, 0x00}, /* Clock disable state 0..3 (low when disabled) */
|
|
||||||
{25, 0x00}, /* Clock disable state 4..7 (low when disabled) */
|
|
||||||
// PLL_A Setup (720MHz)
|
// PLL_A Setup (720MHz)
|
||||||
// P1: 0x00C66 = 3174
|
{26, 0x00},
|
||||||
// P2: 0x00002 = 2
|
{27, 0x05},
|
||||||
// P3: 0x00005 = 5
|
{28, 0x00},
|
||||||
{26, 0x00}, // D7 - D0: MSNA_P3 [15:8]
|
{29, 0x0C},
|
||||||
{27, 0x05}, // D7 - D0: MSNA_P3 [7:0]
|
{30, 0x66},
|
||||||
{28, 0x00}, // D1 - D0: MSNA_P1 [17:16]
|
{31, 0x00},
|
||||||
{29, 0x0C}, // D7 - D0: MSNA_P1 [15:8]
|
{32, 0x00},
|
||||||
{30, 0x66}, // D7 - D0: MSNA_P1 [7:0]
|
{33, 0x02},
|
||||||
{31, 0x00}, // D7 - D4: MSNA_P3 [19:16], D3 - D0: MSNA_P2 [19:16]
|
|
||||||
{32, 0x00}, // D7 - D0: MSNA_P2 [15:8]
|
|
||||||
{33, 0x02}, // D7 - D0: MSNA_P2 [7:0]
|
|
||||||
// PLL_B Setup (705MHz)
|
// PLL_B Setup (705MHz)
|
||||||
{34, 0x02},
|
{34, 0x02},
|
||||||
{35, 0x71},
|
{35, 0x71},
|
||||||
|
@ -261,89 +237,6 @@ static const uint8_t m_si5351_regs_15to92_149to170[100][2] = {
|
||||||
{64, 0x00},
|
{64, 0x00},
|
||||||
{65, 0x00}};
|
{65, 0x00}};
|
||||||
|
|
||||||
static const uint8_t m_si5351_regs_custom[51][2] = {
|
|
||||||
// Init
|
|
||||||
{3, 0xFF},
|
|
||||||
{16, 0x4F}, /* CLK0 Control: 8mA drive, Multisynth 0 as CLK0 source, Clock
|
|
||||||
not inverted, Source = PLLA, Multisynth 0 in integer mode,
|
|
||||||
clock powered up */
|
|
||||||
{17, 0x4F}, /* CLK1 Control: 8mA drive, Multisynth 1 as CLK1 source, Clock
|
|
||||||
not inverted, Source = PLLA, Multisynth 1 in integer mode,
|
|
||||||
clock powered up */
|
|
||||||
{18, 0x6F}, /* CLK2 Control: 8mA drive, Multisynth 2 as CLK2 source, Clock
|
|
||||||
not inverted, Source = PLLB, Multisynth 2 in integer mode,
|
|
||||||
clock powered up */
|
|
||||||
{19, 0x80}, /* CLK3 Control: Not used ... clock powered down */
|
|
||||||
{20, 0x80}, /* CLK4 Control: Not used ... clock powered down */
|
|
||||||
{21, 0x80}, /* CLK5 Control: Not used ... clock powered down */
|
|
||||||
{22, 0x80}, /* CLK6 Control: Not used ... clock powered down */
|
|
||||||
{23, 0x80}, /* CLK7 Control: Not used ... clock powered down */
|
|
||||||
{24, 0x00}, /* Clock disable state 0..3 (low when disabled) */
|
|
||||||
{25, 0x00}, /* Clock disable state 4..7 (low when disabled) */
|
|
||||||
// PLL_A Setup (900MHz) (36 + 0/1)
|
|
||||||
// P1: 4096 => 0x01000
|
|
||||||
// P2: 0 => 0x00000
|
|
||||||
// P3: 1 => 0x00001
|
|
||||||
{26, 0x00}, // D7 - D0: MSNA_P3 [15:8]
|
|
||||||
{27, 0x01}, // D7 - D0: MSNA_P3 [7:0]
|
|
||||||
{28, 0x00}, // D1 - D0: MSNA_P1 [17:16]
|
|
||||||
{29, 0x10}, // D7 - D0: MSNA_P1 [15:8]
|
|
||||||
{30, 0x00}, // D7 - D0: MSNA_P1 [7:0]
|
|
||||||
{31, 0x00}, // D7 - D4: MSNA_P3 [19:16], D3 - D0: MSNA_P2 [19:16]
|
|
||||||
{32, 0x00}, // D7 - D0: MSNA_P2 [15:8]
|
|
||||||
{33, 0x00}, // D7 - D0: MSNA_P2 [7:0]
|
|
||||||
// PLL_B Setup (375MHz) (15 + 0/1)
|
|
||||||
/* // P1: 1408 => 0x00580 */
|
|
||||||
/* // P2: 0 => 0x00000 */
|
|
||||||
/* // P3: 1 => 0x00001 */
|
|
||||||
{34, 0x00}, // D7 - D0: MSNB_P3 [15:8] */
|
|
||||||
{35, 0x01}, // D7 - D0: MSNB_P3 [7:0] */
|
|
||||||
{36, 0x00}, // D1 - D0: MSNB_P1 [17:16] */
|
|
||||||
{37, 0x05}, // D7 - D0: MSNB_P1 [15:8] */
|
|
||||||
{38, 0x80}, // D7 - D0: MSNB_P1 [7:0] */
|
|
||||||
{39, 0x00}, // D7 - D4: MSNB_P3 [19:16], D3 - D0: MSNA_P2 [19:16] */
|
|
||||||
{40, 0x00}, // D7 - D0: MSNB_P2 [15:8] */
|
|
||||||
{41, 0x00}, // D7 - D0: MSNB_P2 [7:0] */
|
|
||||||
// Multisynth0 Setup (120MHz)
|
|
||||||
// P1: 1
|
|
||||||
// P2: 0
|
|
||||||
// P3: 1
|
|
||||||
{42, 0x00}, // D7 - D0: MS0_P3 [15:8]
|
|
||||||
{43, 0x01}, // D7 - D0: MS0_P3 [7:0]
|
|
||||||
{44, 0x00}, // D6 - D4: R0_DIV [2:0], D3 - D2: MS0_DIVBY4 [1:0], D1 -D0: MS0_P1 [17:16]
|
|
||||||
{45, 0x01}, // D7 - D0: MS0_P1 [15:8]
|
|
||||||
{46, 0x01}, // D7 - D0: MS0_P1 [7:0]
|
|
||||||
{47, 0x00}, // D7 - D4: MS0_P3 [19:16], D3 - D0: MS0_P2 [19:16]
|
|
||||||
{48, 0x00}, // D7 - D0: MS0_P2 [15:8]
|
|
||||||
{49, 0x00}, // D7 - D0: MS0_P2 [7:0]
|
|
||||||
// Multisynth1 Setup (12MHz)
|
|
||||||
{50, 0x00},
|
|
||||||
{51, 0x01},
|
|
||||||
{52, 0x00},
|
|
||||||
{53, 0x1C},
|
|
||||||
{54, 0x00},
|
|
||||||
{55, 0x00},
|
|
||||||
{56, 0x00},
|
|
||||||
{57, 0x00},
|
|
||||||
// Multisynth2 Setup (13.56MHz)
|
|
||||||
{58, 0x00},
|
|
||||||
{59, 0x01},
|
|
||||||
{60, 0x00},
|
|
||||||
{61, 0x18},
|
|
||||||
{62, 0x00},
|
|
||||||
{63, 0x00},
|
|
||||||
{64, 0x00},
|
|
||||||
{65, 0x00}};
|
|
||||||
|
|
||||||
static uint32_t ten_pow(const uint8_t exponent) {
|
|
||||||
uint32_t result = 1;
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < exponent; i++)
|
|
||||||
result *= 10;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void spi_init(void) {
|
static void spi_init(void) {
|
||||||
SPI_DDR |= (1 << SPI_SCK) | (1 << SPI_MOSI) | (1 << SPI_SS);
|
SPI_DDR |= (1 << SPI_SCK) | (1 << SPI_MOSI) | (1 << SPI_SS);
|
||||||
SPI_PORT |= (1 << SPI_SS);
|
SPI_PORT |= (1 << SPI_SS);
|
||||||
|
@ -497,51 +390,6 @@ static void lcd_write_integer_page(const uint32_t integer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lcd_write_selected_integer_page(const uint32_t integer,
|
|
||||||
const uint8_t digits,
|
|
||||||
const uint8_t page,
|
|
||||||
const bool invert) {
|
|
||||||
max_digits = digits;
|
|
||||||
|
|
||||||
if (digits != 0 || integer != 0) {
|
|
||||||
uint8_t input_digits = 0;
|
|
||||||
uint32_t comperator = 1;
|
|
||||||
|
|
||||||
// Get digits
|
|
||||||
for (; comperator <= integer; comperator *= 10, input_digits++);
|
|
||||||
lcd_write_kerning(1, invert);
|
|
||||||
|
|
||||||
// Print leading zeroes
|
|
||||||
for (int8_t i = digits - input_digits; i > 0; i--) {
|
|
||||||
if (input_digits + i - 1 != digit_select) {
|
|
||||||
lcd_write_kerning(1, invert);
|
|
||||||
lcd_write_digit_page(0, page, invert);
|
|
||||||
lcd_write_kerning(1, invert);
|
|
||||||
} else {
|
|
||||||
lcd_write_kerning(1, !invert);
|
|
||||||
lcd_write_digit_page(0, page, !invert);
|
|
||||||
lcd_write_kerning(1, !invert);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print number itself
|
|
||||||
for (; comperator >= 10; comperator /= 10, input_digits--) {
|
|
||||||
if (input_digits - 1 != digit_select) {
|
|
||||||
lcd_write_kerning(1, invert);
|
|
||||||
lcd_write_digit_page((integer % comperator) / (comperator / 10),
|
|
||||||
page, invert);
|
|
||||||
lcd_write_kerning(1, invert);
|
|
||||||
} else {
|
|
||||||
lcd_write_kerning(1, !invert);
|
|
||||||
|
|
||||||
lcd_write_digit_page((integer % comperator) / (comperator / 10),
|
|
||||||
page, !invert);
|
|
||||||
lcd_write_kerning(1, !invert);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void twi_error(bool inverted) {
|
static void twi_error(bool inverted) {
|
||||||
if (inverted)
|
if (inverted)
|
||||||
lcd_fill(0xFF);
|
lcd_fill(0xFF);
|
||||||
|
@ -660,8 +508,6 @@ static void draw_home(void) {
|
||||||
bool ch1_selected = false;
|
bool ch1_selected = false;
|
||||||
bool ch2_selected = false;
|
bool ch2_selected = false;
|
||||||
bool ch3_selected = false;
|
bool ch3_selected = false;
|
||||||
bool plla_selected = false;
|
|
||||||
bool pllb_selected = false;
|
|
||||||
bool setup_selected = false;
|
bool setup_selected = false;
|
||||||
|
|
||||||
switch (home_state) {
|
switch (home_state) {
|
||||||
|
@ -674,12 +520,6 @@ static void draw_home(void) {
|
||||||
case ch3:
|
case ch3:
|
||||||
ch3_selected = true;
|
ch3_selected = true;
|
||||||
break;
|
break;
|
||||||
case plla:
|
|
||||||
plla_selected = true;
|
|
||||||
break;
|
|
||||||
case pllb:
|
|
||||||
pllb_selected = true;
|
|
||||||
break;
|
|
||||||
default: // setup
|
default: // setup
|
||||||
setup_selected = true;
|
setup_selected = true;
|
||||||
break;
|
break;
|
||||||
|
@ -698,144 +538,12 @@ static void draw_home(void) {
|
||||||
lcd_write_string_page("CH3\0", 2, i, ch3_selected);
|
lcd_write_string_page("CH3\0", 2, i, ch3_selected);
|
||||||
lcd_write_kerning(2, ch3_selected);
|
lcd_write_kerning(2, ch3_selected);
|
||||||
|
|
||||||
lcd_move_cursor(0, 6 + i);
|
lcd_move_cursor(33, 6 + i);
|
||||||
lcd_write_kerning(1, plla_selected);
|
|
||||||
lcd_write_string_page("PLL\0", 1, i, plla_selected);
|
|
||||||
|
|
||||||
lcd_write_string_page("A\0", 1, i, plla_selected);
|
|
||||||
lcd_write_kerning(2, plla_selected);
|
|
||||||
|
|
||||||
lcd_write_kerning(1, false);
|
|
||||||
|
|
||||||
lcd_write_kerning(1, pllb_selected);
|
|
||||||
lcd_write_string_page("PLL\0", 1, i, pllb_selected);
|
|
||||||
|
|
||||||
lcd_write_string_page("B\0", 1, i, pllb_selected);
|
|
||||||
lcd_write_kerning(2, pllb_selected);
|
|
||||||
|
|
||||||
lcd_move_cursor(61, 6 + i);
|
|
||||||
lcd_write_string_page("SETUP\0", 2, i, setup_selected);
|
lcd_write_string_page("SETUP\0", 2, i, setup_selected);
|
||||||
lcd_write_kerning(2, setup_selected);
|
lcd_write_kerning(2, setup_selected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_pll(void) {
|
|
||||||
lcd_fill(0x00);
|
|
||||||
|
|
||||||
volatile struct pll_config* pll_config = &plla_config;
|
|
||||||
|
|
||||||
switch (current_state) {
|
|
||||||
case plla:
|
|
||||||
pll_config = &plla_config;
|
|
||||||
break;
|
|
||||||
case pllb:
|
|
||||||
pll_config = &pllb_config;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool integer_selected = false;
|
|
||||||
bool numerator_selected = false;
|
|
||||||
bool denominator_selected = false;
|
|
||||||
bool back_selected = false;
|
|
||||||
bool change_integer_selected = false;
|
|
||||||
bool change_numerator_selected = false;
|
|
||||||
bool change_denominator_selected = false;
|
|
||||||
|
|
||||||
switch (pll_state) {
|
|
||||||
case integer:
|
|
||||||
integer_selected = true;
|
|
||||||
break;
|
|
||||||
case numerator:
|
|
||||||
numerator_selected = true;
|
|
||||||
break;
|
|
||||||
case denominator:
|
|
||||||
denominator_selected = true;
|
|
||||||
break;
|
|
||||||
case pll_back:
|
|
||||||
back_selected = true;
|
|
||||||
break;
|
|
||||||
case change_integer:
|
|
||||||
change_integer_selected = true;
|
|
||||||
break;
|
|
||||||
case change_numerator:
|
|
||||||
change_numerator_selected = true;
|
|
||||||
break;
|
|
||||||
case change_denominator:
|
|
||||||
change_denominator_selected = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
|
||||||
lcd_move_cursor(0, i);
|
|
||||||
lcd_write_kerning(33, true);
|
|
||||||
lcd_write_string_page("PLL\0", 2, i, true);
|
|
||||||
lcd_write_kerning(4, true);
|
|
||||||
switch (current_state) {
|
|
||||||
case plla:
|
|
||||||
lcd_write_string_page("A\0", 2, i, true);
|
|
||||||
break;
|
|
||||||
case pllb:
|
|
||||||
lcd_write_string_page("B\0", 2, i, true);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
lcd_write_kerning(35, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (select_offset == 0)
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
|
||||||
lcd_move_cursor(0, 2 + i);
|
|
||||||
lcd_write_kerning(1, integer_selected);
|
|
||||||
lcd_write_string_page("INTEGER:\0", 1, i, integer_selected);
|
|
||||||
lcd_write_kerning(2, integer_selected);
|
|
||||||
lcd_write_kerning(7, false);
|
|
||||||
if (change_integer_selected)
|
|
||||||
lcd_write_selected_integer_page(pll_config->integer, 6,
|
|
||||||
i, false);
|
|
||||||
else
|
|
||||||
lcd_write_integer_page(pll_config->integer, 6, i, false);
|
|
||||||
lcd_write_kerning(2, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
|
||||||
lcd_move_cursor(0, 4 + i - select_offset * 2);
|
|
||||||
lcd_write_kerning(1, numerator_selected);
|
|
||||||
lcd_write_string_page("NUM:\0", 1, i, numerator_selected);
|
|
||||||
lcd_write_kerning(2, numerator_selected);
|
|
||||||
lcd_write_kerning(21, false);
|
|
||||||
if (change_numerator_selected)
|
|
||||||
lcd_write_selected_integer_page(pll_config->numerator, 7,
|
|
||||||
i, false);
|
|
||||||
else
|
|
||||||
lcd_write_integer_page(pll_config->numerator, 7, i, false);
|
|
||||||
lcd_write_kerning(2, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
|
||||||
lcd_move_cursor(0, 6 + i - select_offset * 2);
|
|
||||||
lcd_write_kerning(1, denominator_selected);
|
|
||||||
lcd_write_string_page("DENOM:\0", 1, i, denominator_selected);
|
|
||||||
lcd_write_kerning(2, denominator_selected);
|
|
||||||
lcd_write_kerning(8, false);
|
|
||||||
if (change_denominator_selected)
|
|
||||||
lcd_write_selected_integer_page(pll_config->denominator, 7,
|
|
||||||
i, false);
|
|
||||||
else
|
|
||||||
lcd_write_integer_page(pll_config->denominator, 7, i, false);
|
|
||||||
lcd_write_kerning(2, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (select_offset == 1)
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
|
||||||
lcd_move_cursor(33, 6 + i);
|
|
||||||
lcd_write_string_page("BACK\0", 2, i, back_selected);
|
|
||||||
lcd_write_kerning(2, back_selected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void draw_setup(void) {
|
static void draw_setup(void) {
|
||||||
lcd_fill(0x00);
|
lcd_fill(0x00);
|
||||||
|
|
||||||
|
@ -900,8 +608,8 @@ static void draw_setup(void) {
|
||||||
static void change_state(const enum state new_state) {
|
static void change_state(const enum state new_state) {
|
||||||
switch (new_state) {
|
switch (new_state) {
|
||||||
case home:
|
case home:
|
||||||
current_state = home;
|
|
||||||
draw_home();
|
draw_home();
|
||||||
|
current_state = home;
|
||||||
break;
|
break;
|
||||||
case ch1:
|
case ch1:
|
||||||
break;
|
break;
|
||||||
|
@ -909,22 +617,10 @@ static void change_state(const enum state new_state) {
|
||||||
break;
|
break;
|
||||||
case ch3:
|
case ch3:
|
||||||
break;
|
break;
|
||||||
case plla:
|
|
||||||
select_offset = 0;
|
|
||||||
pll_state = integer;
|
|
||||||
current_state = plla;
|
|
||||||
draw_pll();
|
|
||||||
break;
|
|
||||||
case pllb:
|
|
||||||
select_offset = 0;
|
|
||||||
pll_state = integer;
|
|
||||||
current_state = pllb;
|
|
||||||
draw_pll();
|
|
||||||
break;
|
|
||||||
case setup:
|
case setup:
|
||||||
setup_state = contrast;
|
setup_state = contrast;
|
||||||
current_state = setup;
|
|
||||||
draw_setup();
|
draw_setup();
|
||||||
|
current_state = setup;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -951,171 +647,6 @@ static void update_home(const enum input event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_pll(const enum input event) {
|
|
||||||
volatile struct pll_config* pll_config = &plla_config;
|
|
||||||
|
|
||||||
switch (current_state) {
|
|
||||||
case plla:
|
|
||||||
pll_config = &plla_config;
|
|
||||||
break;
|
|
||||||
case pllb:
|
|
||||||
pll_config = &pllb_config;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (event) {
|
|
||||||
case cw:
|
|
||||||
switch (pll_state) {
|
|
||||||
case integer:
|
|
||||||
case numerator:
|
|
||||||
case denominator:
|
|
||||||
case pll_back:
|
|
||||||
pll_state++;
|
|
||||||
if (pll_state > denominator)
|
|
||||||
select_offset = 1;
|
|
||||||
if (pll_state > pll_back) {
|
|
||||||
select_offset = 0;
|
|
||||||
pll_state = integer;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case change_integer:
|
|
||||||
if (digit_selected)
|
|
||||||
pll_config->integer += ten_pow(digit_select);
|
|
||||||
else
|
|
||||||
if (--digit_select > max_digits)
|
|
||||||
digit_select = max_digits - 1;
|
|
||||||
break;
|
|
||||||
case change_numerator:
|
|
||||||
if (digit_selected)
|
|
||||||
pll_config->numerator += ten_pow(digit_select);
|
|
||||||
else
|
|
||||||
if (--digit_select > max_digits)
|
|
||||||
digit_select = max_digits - 1;
|
|
||||||
break;
|
|
||||||
case change_denominator:
|
|
||||||
if (digit_selected)
|
|
||||||
pll_config->denominator += ten_pow(digit_select);
|
|
||||||
else
|
|
||||||
if (--digit_select > max_digits)
|
|
||||||
digit_select = max_digits - 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
draw_pll();
|
|
||||||
break;
|
|
||||||
case ccw:
|
|
||||||
switch (pll_state) {
|
|
||||||
case integer:
|
|
||||||
case numerator:
|
|
||||||
case denominator:
|
|
||||||
case pll_back:
|
|
||||||
pll_state--;
|
|
||||||
if (pll_state < numerator)
|
|
||||||
select_offset = 0;
|
|
||||||
if (pll_state > pll_back) {
|
|
||||||
select_offset = 1;
|
|
||||||
pll_state = pll_back;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case change_integer:
|
|
||||||
// TODO: Fix going back to zero
|
|
||||||
if (digit_selected)
|
|
||||||
pll_config->integer -= ten_pow(digit_select);
|
|
||||||
else
|
|
||||||
if (++digit_select >= max_digits)
|
|
||||||
digit_select = 0;
|
|
||||||
break;
|
|
||||||
case change_numerator:
|
|
||||||
// TODO: Fix going back to zero
|
|
||||||
if (digit_selected)
|
|
||||||
pll_config->numerator -= ten_pow(digit_select);
|
|
||||||
else
|
|
||||||
if (++digit_select >= max_digits)
|
|
||||||
digit_select = 0;
|
|
||||||
break;
|
|
||||||
case change_denominator:
|
|
||||||
// TODO: Fix going back to zero
|
|
||||||
if (digit_selected)
|
|
||||||
pll_config->denominator -= ten_pow(digit_select);
|
|
||||||
else
|
|
||||||
if (++digit_select >= max_digits)
|
|
||||||
digit_select = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
draw_pll();
|
|
||||||
break;
|
|
||||||
case click:
|
|
||||||
switch (pll_state) {
|
|
||||||
case integer:
|
|
||||||
pll_state = change_integer;
|
|
||||||
draw_pll();
|
|
||||||
break;
|
|
||||||
case numerator:
|
|
||||||
pll_state = change_numerator;
|
|
||||||
draw_pll();
|
|
||||||
break;
|
|
||||||
case denominator:
|
|
||||||
pll_state = change_denominator;
|
|
||||||
draw_pll();
|
|
||||||
break;
|
|
||||||
case pll_back:
|
|
||||||
change_state(home);
|
|
||||||
break;
|
|
||||||
case change_integer:
|
|
||||||
if (digit_selected) {
|
|
||||||
// TODO: Save/write new value
|
|
||||||
digit_selected = false;
|
|
||||||
digit_select = 0;
|
|
||||||
} else
|
|
||||||
digit_selected = true;
|
|
||||||
break;
|
|
||||||
case change_numerator:
|
|
||||||
if (digit_selected) {
|
|
||||||
// TODO: Save/write new value
|
|
||||||
digit_selected = false;
|
|
||||||
digit_select = 0;
|
|
||||||
} else
|
|
||||||
digit_selected = true;
|
|
||||||
break;
|
|
||||||
case change_denominator:
|
|
||||||
if (digit_selected) {
|
|
||||||
// TODO: Save/write new value
|
|
||||||
digit_selected = false;
|
|
||||||
digit_select = 0;
|
|
||||||
} else
|
|
||||||
digit_selected = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case hold:
|
|
||||||
switch (pll_state) {
|
|
||||||
case integer:
|
|
||||||
case numerator:
|
|
||||||
case denominator:
|
|
||||||
case pll_back:
|
|
||||||
change_state(home);
|
|
||||||
break;
|
|
||||||
case change_integer:
|
|
||||||
digit_selected = false;
|
|
||||||
pll_state = integer;
|
|
||||||
draw_pll();
|
|
||||||
break;
|
|
||||||
case change_numerator:
|
|
||||||
digit_selected = false;
|
|
||||||
pll_state = integer;
|
|
||||||
draw_pll();
|
|
||||||
break;
|
|
||||||
case change_denominator:
|
|
||||||
digit_selected = false;
|
|
||||||
pll_state = integer;
|
|
||||||
draw_pll();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void update_setup(const enum input event) {
|
static void update_setup(const enum input event) {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case cw:
|
case cw:
|
||||||
|
@ -1226,12 +757,6 @@ static void update_state(const enum input event) {
|
||||||
break;
|
break;
|
||||||
case ch3:
|
case ch3:
|
||||||
break;
|
break;
|
||||||
case plla:
|
|
||||||
update_pll(event);
|
|
||||||
break;
|
|
||||||
case pllb:
|
|
||||||
update_pll(event);
|
|
||||||
break;
|
|
||||||
case setup:
|
case setup:
|
||||||
update_setup(event);
|
update_setup(event);
|
||||||
break;
|
break;
|
||||||
|
@ -1353,9 +878,9 @@ int main(void) {
|
||||||
(void) &twi_read_register;
|
(void) &twi_read_register;
|
||||||
(void) &twi_write_register;
|
(void) &twi_write_register;
|
||||||
|
|
||||||
for (uint16_t i = 0; i < sizeof(m_si5351_regs_custom) / 2; i++)
|
for (uint16_t i = 0; i < sizeof(m_si5351_regs_15to92_149to170) / 2; i++)
|
||||||
twi_write_register(SI5351_ADDRESS, m_si5351_regs_custom[i][0],
|
twi_write_register(SI5351_ADDRESS, m_si5351_regs_15to92_149to170[i][0],
|
||||||
m_si5351_regs_custom[i][1]);
|
m_si5351_regs_15to92_149to170[i][1]);
|
||||||
|
|
||||||
twi_write_register(SI5351_ADDRESS, SI5351_REGISTER_177_PLL_RESET, 0xAC);
|
twi_write_register(SI5351_ADDRESS, SI5351_REGISTER_177_PLL_RESET, 0xAC);
|
||||||
twi_write_register(SI5351_ADDRESS, SI5351_REGISTER_3_OUTPUT_ENABLE_CONTROL, 0x00);
|
twi_write_register(SI5351_ADDRESS, SI5351_REGISTER_3_OUTPUT_ENABLE_CONTROL, 0x00);
|
Loading…
Reference in a new issue