initialize ad9833 and mcp41
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "ctrl_bottom_button.h"
|
||||
#include "ctrl_channel_button.h"
|
||||
#include "ctrl_encoder.h"
|
||||
#include "ctrl_generator.h"
|
||||
|
||||
#include "ctrl_app.h"
|
||||
|
||||
@@ -24,7 +25,7 @@ static const uint32_t pow_of_10[7] = {1, 10, 100, 1000, 10000, 100000, 1000000};
|
||||
static HW_BotBtnName_t last_key;
|
||||
static APP_data_t *_app_data;
|
||||
|
||||
static const GENERATOR_t generators[CHANNEL_MAX] = {
|
||||
static GENERATOR_t generators[CHANNEL_MAX] = {
|
||||
{.gen_type = GEN_FG_TYPE, .gen = &func_gen[0]},
|
||||
{.gen_type = GEN_FG_TYPE, .gen = &func_gen[1]},
|
||||
{.gen_type = GEN_FG_TYPE, .gen = &func_gen[2]},
|
||||
@@ -55,13 +56,15 @@ void APP_init(APP_data_t *app_data)
|
||||
_app_data->isButtonBlink = 1;
|
||||
|
||||
CTRL_buttonsInit();
|
||||
HAL_GPIO_WritePin(LED_CH1_GPIO_Port, LED_CH1_Pin, GPIO_PIN_SET);
|
||||
gen_init();
|
||||
}
|
||||
|
||||
void CTRL_buttonsInit(void)
|
||||
{
|
||||
|
||||
CTRL_bottomButtonInit();
|
||||
// CTRL_channelButtonInit();
|
||||
CTRL_channelButtonInit();
|
||||
}
|
||||
|
||||
void CTRL_buttonsHandler(void)
|
||||
@@ -84,6 +87,25 @@ void CTRL_pushedChanBtnEvent(ButtonKey_t *key)
|
||||
UNUSED(key);
|
||||
}
|
||||
|
||||
void CTRL_longPushedChanBtnEvent(ButtonKey_t *key)
|
||||
{
|
||||
ULOG_TRACE("Chan btn(long): %d", key->instance);
|
||||
GEN_fg_t *dds_ch0 = generators[key->instance].gen;
|
||||
if (dds_ch0->enabled)
|
||||
{
|
||||
dds_ch0->enabled = FALSE;
|
||||
setEnabled(&generators[CHANNEL1], CHANNEL1);
|
||||
HAL_GPIO_WritePin(LED_CH1_GPIO_Port, LED_CH1_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
else
|
||||
{
|
||||
dds_ch0->enabled = TRUE;
|
||||
setEnabled(&generators[CHANNEL1], CHANNEL1);
|
||||
HAL_GPIO_WritePin(LED_CH1_GPIO_Port, LED_CH1_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
UNUSED(key);
|
||||
}
|
||||
|
||||
static void _changeValueFunGen(int8_t dir)
|
||||
{
|
||||
GEN_fg_t *gen = (GEN_fg_t *)_app_data->generator;
|
||||
@@ -99,6 +121,7 @@ static void _changeValueFunGen(int8_t dir)
|
||||
return;
|
||||
}
|
||||
gen->frequency = new_freq;
|
||||
setFreq(&generators[CHANNEL1], CHANNEL1);
|
||||
break;
|
||||
}
|
||||
case LAY_AMPL:
|
||||
@@ -110,6 +133,7 @@ static void _changeValueFunGen(int8_t dir)
|
||||
return;
|
||||
}
|
||||
gen->amplitude = new_ampl;
|
||||
setAmplitude(&generators[CHANNEL1], CHANNEL1);
|
||||
break;
|
||||
}
|
||||
case LAY_OFFS:
|
||||
@@ -121,6 +145,7 @@ static void _changeValueFunGen(int8_t dir)
|
||||
return;
|
||||
}
|
||||
gen->offset = new_offs;
|
||||
setOfsset(&generators[CHANNEL1], CHANNEL1);
|
||||
break;
|
||||
}
|
||||
case LAY_PHAS:
|
||||
@@ -158,6 +183,7 @@ static void _changeValuePwmGen(int8_t dir)
|
||||
return;
|
||||
}
|
||||
gen->frequency = new_freq;
|
||||
|
||||
break;
|
||||
}
|
||||
case LAY_AMPL:
|
||||
@@ -169,6 +195,7 @@ static void _changeValuePwmGen(int8_t dir)
|
||||
return;
|
||||
}
|
||||
gen->amplitude = new_ampl;
|
||||
|
||||
break;
|
||||
}
|
||||
case LAY_OFFS:
|
||||
@@ -180,6 +207,7 @@ static void _changeValuePwmGen(int8_t dir)
|
||||
return;
|
||||
}
|
||||
gen->offset = new_offs;
|
||||
|
||||
break;
|
||||
}
|
||||
case LAY_PHAS:
|
||||
|
||||
@@ -11,31 +11,31 @@ void CTRL_bottomButtonInit(void)
|
||||
bottom_buttons[BTN_BOT_1].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||
bottom_buttons[BTN_BOT_1].gpio_port = BTN1_GPIO_Port;
|
||||
bottom_buttons[BTN_BOT_1].gpio_pin = BTN1_Pin;
|
||||
bottom_buttons[BTN_BOT_1].pushed_state = GPIO_PIN_SET;
|
||||
bottom_buttons[BTN_BOT_1].pushed_state = GPIO_PIN_RESET;
|
||||
|
||||
bottom_buttons[BTN_BOT_2].instance = BTN_BOT_2;
|
||||
bottom_buttons[BTN_BOT_2].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||
bottom_buttons[BTN_BOT_2].gpio_port = BTN2_GPIO_Port;
|
||||
bottom_buttons[BTN_BOT_2].gpio_pin = BTN2_Pin;
|
||||
bottom_buttons[BTN_BOT_2].pushed_state = GPIO_PIN_SET;
|
||||
bottom_buttons[BTN_BOT_2].pushed_state = GPIO_PIN_RESET;
|
||||
|
||||
bottom_buttons[BTN_BOT_3].instance = BTN_BOT_3;
|
||||
bottom_buttons[BTN_BOT_3].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||
bottom_buttons[BTN_BOT_3].gpio_port = BTN3_GPIO_Port;
|
||||
bottom_buttons[BTN_BOT_3].gpio_pin = BTN3_Pin;
|
||||
bottom_buttons[BTN_BOT_3].pushed_state = GPIO_PIN_SET;
|
||||
bottom_buttons[BTN_BOT_3].pushed_state = GPIO_PIN_RESET;
|
||||
|
||||
bottom_buttons[BTN_BOT_4].instance = BTN_BOT_4;
|
||||
bottom_buttons[BTN_BOT_4].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||
bottom_buttons[BTN_BOT_4].gpio_port = BTN4_GPIO_Port;
|
||||
bottom_buttons[BTN_BOT_4].gpio_pin = BTN4_Pin;
|
||||
bottom_buttons[BTN_BOT_4].pushed_state = GPIO_PIN_SET;
|
||||
bottom_buttons[BTN_BOT_4].pushed_state = GPIO_PIN_RESET;
|
||||
|
||||
bottom_buttons[BTN_BOT_5].instance = BTN_BOT_5;
|
||||
bottom_buttons[BTN_BOT_5].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||
bottom_buttons[BTN_BOT_5].gpio_port = BTN5_GPIO_Port;
|
||||
bottom_buttons[BTN_BOT_5].gpio_pin = BTN5_Pin;
|
||||
bottom_buttons[BTN_BOT_5].pushed_state = GPIO_PIN_SET;
|
||||
bottom_buttons[BTN_BOT_5].pushed_state = GPIO_PIN_RESET;
|
||||
|
||||
for (HW_BotBtnName_t btn_key = BTN_BOT_1; btn_key < BTN_BOT_MAX; btn_key++)
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include "hw_button.h"
|
||||
#include "ctrl_channel_button.h"
|
||||
|
||||
#define DUMMY_GPIO_Port GPIOA
|
||||
#define DUMMY_GPIO_Pin GPIO_PIN_0
|
||||
#define DUMMY_GPIO_Port B1_GPIO_Port
|
||||
#define DUMMY_GPIO_Pin B1_Pin
|
||||
|
||||
static ButtonKey_t channel_buttons[BTN_CH_MAX];
|
||||
|
||||
@@ -11,39 +11,40 @@ void CTRL_channelButtonInit(void)
|
||||
{
|
||||
channel_buttons[BTN_CH_1].instance = BTN_CH_1;
|
||||
channel_buttons[BTN_CH_1].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||
channel_buttons[BTN_CH_1].gpio_port = DUMMY_GPIO_Port;
|
||||
channel_buttons[BTN_CH_1].gpio_pin = DUMMY_GPIO_Pin;
|
||||
channel_buttons[BTN_CH_1].pushed_state = GPIO_PIN_SET;
|
||||
channel_buttons[BTN_CH_1].buttonLongPressed = CTRL_longPushedChanBtnEvent;
|
||||
channel_buttons[BTN_CH_1].gpio_port = BTN_CH1_GPIO_Port;
|
||||
channel_buttons[BTN_CH_1].gpio_pin = BTN_CH1_Pin;
|
||||
channel_buttons[BTN_CH_1].pushed_state = GPIO_PIN_RESET;
|
||||
|
||||
channel_buttons[BTN_CH_2].instance = BTN_CH_2;
|
||||
channel_buttons[BTN_CH_2].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||
channel_buttons[BTN_CH_2].gpio_port = DUMMY_GPIO_Port;
|
||||
channel_buttons[BTN_CH_2].gpio_pin = DUMMY_GPIO_Pin;
|
||||
channel_buttons[BTN_CH_2].pushed_state = GPIO_PIN_SET;
|
||||
channel_buttons[BTN_CH_2].pushed_state = GPIO_PIN_RESET;
|
||||
|
||||
channel_buttons[BTN_CH_3].instance = BTN_CH_3;
|
||||
channel_buttons[BTN_CH_3].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||
channel_buttons[BTN_CH_3].gpio_port = DUMMY_GPIO_Port;
|
||||
channel_buttons[BTN_CH_3].gpio_pin = DUMMY_GPIO_Pin;
|
||||
channel_buttons[BTN_CH_3].pushed_state = GPIO_PIN_SET;
|
||||
channel_buttons[BTN_CH_3].pushed_state = GPIO_PIN_RESET;
|
||||
|
||||
channel_buttons[BTN_CH_4].instance = BTN_CH_4;
|
||||
channel_buttons[BTN_CH_4].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||
channel_buttons[BTN_CH_4].gpio_port = DUMMY_GPIO_Port;
|
||||
channel_buttons[BTN_CH_4].gpio_pin = DUMMY_GPIO_Pin;
|
||||
channel_buttons[BTN_CH_4].pushed_state = GPIO_PIN_SET;
|
||||
channel_buttons[BTN_CH_4].pushed_state = GPIO_PIN_RESET;
|
||||
|
||||
channel_buttons[BTN_CH_5].instance = BTN_CH_5;
|
||||
channel_buttons[BTN_CH_5].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||
channel_buttons[BTN_CH_5].gpio_port = DUMMY_GPIO_Port;
|
||||
channel_buttons[BTN_CH_5].gpio_pin = DUMMY_GPIO_Pin;
|
||||
channel_buttons[BTN_CH_5].pushed_state = GPIO_PIN_SET;
|
||||
channel_buttons[BTN_CH_5].pushed_state = GPIO_PIN_RESET;
|
||||
|
||||
channel_buttons[BTN_CH_6].instance = BTN_CH_6;
|
||||
channel_buttons[BTN_CH_6].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||
channel_buttons[BTN_CH_6].gpio_port = DUMMY_GPIO_Port;
|
||||
channel_buttons[BTN_CH_6].gpio_pin = DUMMY_GPIO_Pin;
|
||||
channel_buttons[BTN_CH_6].pushed_state = GPIO_PIN_SET;
|
||||
channel_buttons[BTN_CH_6].pushed_state = GPIO_PIN_RESET;
|
||||
|
||||
for (HW_chanBtnName_t btn_key = BTN_CH_1; btn_key < BTN_CH_MAX; btn_key++)
|
||||
{
|
||||
@@ -63,6 +64,11 @@ void CTRL_channelButtonsHandler(void)
|
||||
}
|
||||
|
||||
__weak void CTRL_pushedChanBtnEvent(ButtonKey_t *key)
|
||||
{
|
||||
UNUSED(key);
|
||||
}
|
||||
|
||||
__weak void CTRL_longPushedChanBtnEvent(ButtonKey_t *key)
|
||||
{
|
||||
UNUSED(key);
|
||||
}
|
||||
@@ -13,4 +13,5 @@ typedef enum
|
||||
|
||||
void CTRL_channelButtonInit(void);
|
||||
void CTRL_channelButtonsHandler(void);
|
||||
void CTRL_pushedChanBtnEvent(ButtonKey_t *key);
|
||||
void CTRL_pushedChanBtnEvent(ButtonKey_t *key);
|
||||
void CTRL_longPushedChanBtnEvent(ButtonKey_t *key);
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "spi.h"
|
||||
#include "i2c.h"
|
||||
#include "ctrl_app_types.h"
|
||||
#include "ctrl_app.h"
|
||||
#include "ad9833.h"
|
||||
#include "ltc2631.h"
|
||||
#include "mcp41x.h"
|
||||
@@ -47,35 +46,35 @@ PWM_handle_t pwm_gen[PWM_CHAN_MAX];
|
||||
|
||||
uint8_t ch_to_gen_ch[CHANNEL_MAX] = {FG_CHAN1, FG_CHAN2, FG_CHAN3, PWM_CHAN1, PWM_CHAN2, PWM_CHAN3};
|
||||
|
||||
#define DDS1_CS_PORT GPIOC
|
||||
#define DDS2_CS_PORT GPIOC
|
||||
#define DDS3_CS_PORT GPIOC
|
||||
// #define DDS1_CS_PORT GPIOC
|
||||
// #define DDS2_CS_PORT GPIOC
|
||||
// #define DDS3_CS_PORT GPIOC
|
||||
|
||||
#define DDS1_CS_PIN GPIO_PIN_0
|
||||
#define DDS2_CS_PIN GPIO_PIN_0
|
||||
#define DDS3_CS_PIN GPIO_PIN_0
|
||||
// #define DDS1_CS_PIN GPIO_PIN_0
|
||||
// #define DDS2_CS_PIN GPIO_PIN_0
|
||||
// #define DDS3_CS_PIN GPIO_PIN_0
|
||||
|
||||
#define AMP1_CS_PORT GPIOC
|
||||
#define AMP2_CS_PORT GPIOC
|
||||
#define AMP3_CS_PORT GPIOC
|
||||
// #define AMP1_CS_PORT GPIOC
|
||||
// #define AMP2_CS_PORT GPIOC
|
||||
// #define AMP3_CS_PORT GPIOC
|
||||
|
||||
#define AMP1_CS_PIN GPIO_PIN_0
|
||||
#define AMP2_CS_PIN GPIO_PIN_0
|
||||
#define AMP3_CS_PIN GPIO_PIN_0
|
||||
// #define AMP1_CS_PIN GPIO_PIN_0
|
||||
// #define AMP2_CS_PIN GPIO_PIN_0
|
||||
// #define AMP3_CS_PIN GPIO_PIN_0
|
||||
|
||||
void gen_init()
|
||||
{
|
||||
ad9833_init(&dds_gen[FG_CHAN1].hdds, &hspi2, DDS1_CS_PORT, DDS1_CS_PIN);
|
||||
ad9833_init(&dds_gen[FG_CHAN2].hdds, &hspi2, DDS2_CS_PORT, DDS2_CS_PIN);
|
||||
ad9833_init(&dds_gen[FG_CHAN3].hdds, &hspi2, DDS3_CS_PORT, DDS3_CS_PIN);
|
||||
ad9833_init(&dds_gen[FG_CHAN1].hdds, &hspi2, DDS1_CS_GPIO_Port, DDS1_CS_Pin);
|
||||
// ad9833_init(&dds_gen[FG_CHAN2].hdds, &hspi2, DDS2_CS_PORT, DDS2_CS_PIN);
|
||||
// ad9833_init(&dds_gen[FG_CHAN3].hdds, &hspi2, DDS3_CS_PORT, DDS3_CS_PIN);
|
||||
|
||||
ltc2631_init(&dds_gen[FG_CHAN1].hoffs, &hi2c1, 0x00, LTC2631_8BIT, LTC_REF_2V5);
|
||||
ltc2631_init(&dds_gen[FG_CHAN2].hoffs, &hi2c1, 0x01, LTC2631_8BIT, LTC_REF_2V5);
|
||||
ltc2631_init(&dds_gen[FG_CHAN3].hoffs, &hi2c1, 0x02, LTC2631_8BIT, LTC_REF_2V5);
|
||||
// ltc2631_init(&dds_gen[FG_CHAN1].hoffs, &hi2c1, 0x00, LTC2631_8BIT, LTC_REF_2V5);
|
||||
// ltc2631_init(&dds_gen[FG_CHAN2].hoffs, &hi2c1, 0x01, LTC2631_8BIT, LTC_REF_2V5);
|
||||
// ltc2631_init(&dds_gen[FG_CHAN3].hoffs, &hi2c1, 0x02, LTC2631_8BIT, LTC_REF_2V5);
|
||||
|
||||
mcp41x_init(&dds_gen[FG_CHAN1].hampl, &hspi2, AMP1_CS_PORT, AMP1_CS_PIN, MCP41X_10K);
|
||||
mcp41x_init(&dds_gen[FG_CHAN1].hampl, &hspi2, AMP2_CS_PORT, AMP2_CS_PIN, MCP41X_10K);
|
||||
mcp41x_init(&dds_gen[FG_CHAN1].hampl, &hspi2, AMP3_CS_PORT, AMP3_CS_PIN, MCP41X_10K);
|
||||
mcp41x_init(&dds_gen[FG_CHAN1].hampl, &hspi2, AMP1_CS_GPIO_Port, AMP1_CS_Pin, MCP41X_10K);
|
||||
// mcp41x_init(&dds_gen[FG_CHAN1].hampl, &hspi2, AMP2_CS_PORT, AMP2_CS_PIN, MCP41X_10K);
|
||||
// mcp41x_init(&dds_gen[FG_CHAN1].hampl, &hspi2, AMP3_CS_PORT, AMP3_CS_PIN, MCP41X_10K);
|
||||
}
|
||||
|
||||
static void _setAmpliude(mcp41x_handle_t *hampl, uint16_t ampl_x100)
|
||||
|
||||
@@ -1 +1,12 @@
|
||||
#pragma once
|
||||
#include "ctrl_app.h"
|
||||
|
||||
void setLink(GENERATOR_t *source_gen, GEN_channel_t source_ch, GENERATOR_t *dest_gen, GEN_channel_t dest_ch);
|
||||
void setEnabled(GENERATOR_t *gen, GEN_channel_t channel);
|
||||
void setDuty(GENERATOR_t *gen, GEN_channel_t channel);
|
||||
void setWave(GENERATOR_t *gen, GEN_channel_t channel);
|
||||
void setPhase(GENERATOR_t *gen, GEN_channel_t channel);
|
||||
void setOfsset(GENERATOR_t *gen, GEN_channel_t channel);
|
||||
void setAmplitude(GENERATOR_t *gen, GEN_channel_t channel);
|
||||
void setFreq(GENERATOR_t *gen, GEN_channel_t channel);
|
||||
void gen_init();
|
||||
@@ -249,7 +249,7 @@ static void _drawOffsetLine(GFX_display_t *disp, int16_t offs, uint32_t ampl)
|
||||
vert_shift = MIN(vert_shift, 20);
|
||||
vert_shift = MAX(vert_shift, -19);
|
||||
|
||||
ULOG_TRACE("<OFFSLINE> shift: %i", vert_shift);
|
||||
// ULOG_DEBUG("<OFFSLINE> shift: %i", vert_shift);
|
||||
DISP_drawHorizontalLine(disp, 2, 31 + vert_shift, 57, GFX_WHITE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user