1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

cleanup config.c, Makefile, OSD, and VTX

This commit is contained in:
Evgeny Sychov 2016-06-18 00:33:10 -07:00
parent ddf0fb5fda
commit 135ffc1c92
11 changed files with 123 additions and 118 deletions

View file

@ -536,15 +536,6 @@ endif
ifneq ($(filter VCP,$(FEATURES)),) ifneq ($(filter VCP,$(FEATURES)),)
TARGET_SRC += $(VCP_SRC) TARGET_SRC += $(VCP_SRC)
endif endif
ifneq ($(filter VTX_SOFT, $(FEATURES)),)
TARGET_SRC += $(SRC_DIR)/drivers/rtc6705_soft_spi.c
endif
ifneq ($(filter MAX_OSD, $(FEATURES)),)
TARGET_SRC += $(SRC_DIR)/drivers/max7456.c \
$(SRC_DIR)/io/osd.c
endif
# end target specific make file checks # end target specific make file checks

View file

@ -424,12 +424,6 @@ static void resetConf(void)
resetOsdConfig(); resetOsdConfig();
#endif #endif
#ifdef USE_RTC6705
featureSet(FEATURE_VTX);
masterConfig.vtx_channel = 19; // default to Boscam E channel 4
masterConfig.vtx_power = 1;
#endif
#ifdef BOARD_HAS_VOLTAGE_DIVIDER #ifdef BOARD_HAS_VOLTAGE_DIVIDER
// only enable the VBAT feature by default if the board has a voltage divider otherwise // only enable the VBAT feature by default if the board has a voltage divider otherwise
// the user may see incorrect readings and unexpected issues with pin mappings may occur. // the user may see incorrect readings and unexpected issues with pin mappings may occur.

View file

@ -36,8 +36,6 @@
#define DISABLE_MAX7456 IOHi(max7456CsPin) #define DISABLE_MAX7456 IOHi(max7456CsPin)
#define ENABLE_MAX7456 IOLo(max7456CsPin) #define ENABLE_MAX7456 IOLo(max7456CsPin)
static IO_t max7456CsPin = IO_NONE;
/** Artificial Horizon limits **/ /** Artificial Horizon limits **/
#define AHIPITCHMAX 200 // Specify maximum AHI pitch value displayed. Default 200 = 20.0 degrees #define AHIPITCHMAX 200 // Specify maximum AHI pitch value displayed. Default 200 = 20.0 degrees
#define AHIROLLMAX 400 // Specify maximum AHI roll value displayed. Default 400 = 40.0 degrees #define AHIROLLMAX 400 // Specify maximum AHI roll value displayed. Default 400 = 40.0 degrees
@ -45,10 +43,11 @@ static IO_t max7456CsPin = IO_NONE;
#define AHISIDEBARHEIGHTPOSITION 3 #define AHISIDEBARHEIGHTPOSITION 3
uint16_t max_screen_size; uint16_t max_screen_size;
uint8_t video_signal_type = 0;
uint8_t max7456_lock = 0;
char max7456_screen[VIDEO_BUFFER_CHARS_PAL]; char max7456_screen[VIDEO_BUFFER_CHARS_PAL];
static uint8_t video_signal_type = 0;
static uint8_t max7456_lock = 0;
static IO_t max7456CsPin = IO_NONE;
uint8_t max7456_send(uint8_t add, uint8_t data) { uint8_t max7456_send(uint8_t add, uint8_t data) {
spiTransferByte(MAX7456_SPI_INSTANCE, add); spiTransferByte(MAX7456_SPI_INSTANCE, add);
@ -113,19 +112,6 @@ void max7456_init(uint8_t video_system) {
DISABLE_MAX7456; DISABLE_MAX7456;
delay(100); delay(100);
// display logo
x = 160;
for (int i = 1; i < 5; i++) {
for (int j = 3; j < 27; j++)
max7456_screen[i * LINE + j] = (char)x++;
}
tfp_sprintf(buf, "BF VERSION: %s", FC_VERSION_STRING);
max7456_write_string(buf, LINE06+5);
max7456_write_string("MENU: THRT MID", LINE07+7);
max7456_write_string("YAW RIGHT", LINE08+13);
max7456_write_string("PITCH UP", LINE09+13);
max7456_draw_screen();
} }
// Copy string from ram into screen buffer // Copy string from ram into screen buffer

View file

@ -143,7 +143,7 @@
enum VIDEO_TYPES { AUTO = 0, PAL, NTSC }; enum VIDEO_TYPES { AUTO = 0, PAL, NTSC };
extern uint16_t max_screen_size; extern uint16_t max_screen_size;
char max7456_screen[VIDEO_BUFFER_CHARS_PAL]; extern char max7456_screen[VIDEO_BUFFER_CHARS_PAL];
void max7456_init(uint8_t system); void max7456_init(uint8_t system);

View file

@ -38,21 +38,13 @@
#define RTC6705_SPILE_ON IOHi(rtc6705LePin) #define RTC6705_SPILE_ON IOHi(rtc6705LePin)
#define RTC6705_SPILE_OFF IOLo(rtc6705LePin) #define RTC6705_SPILE_OFF IOLo(rtc6705LePin)
char *vtx_bands[] = { const uint16_t vtx_freq[] =
"BOSCAM A",
"BOSCAM B",
"BOSCAM E",
"FATSHARK",
"RACEBAND",
};
uint16_t vtx_freq[] =
{ {
5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725, 5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725, // Boacam A
5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866, 5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866, // Boscam B
5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945, 5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945, // Boscam E
5740, 5760, 5780, 5800, 5820, 5840, 5860, 5880, 5740, 5760, 5780, 5800, 5820, 5840, 5860, 5880, // FatShark
5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917, 5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917, // RaceBand
}; };
uint16_t current_vtx_channel; uint16_t current_vtx_channel;
@ -127,8 +119,8 @@ void rtc6705_soft_spi_set_channel(uint16_t channel_freq) {
rtc6705_write_register(1, (N << 7) | A); rtc6705_write_register(1, (N << 7) | A);
} }
void rtc6705_soft_spi_set_rf_power(uint8_t power) { void rtc6705_soft_spi_set_rf_power(uint8_t reduce_power) {
rtc6705_write_register(7, (power ? PA_CONTROL_DEFAULT : (PA_CONTROL_DEFAULT | PD_Q5G_MASK) & (~(PA5G_PW_MASK | PA5G_BS_MASK)))); rtc6705_write_register(7, (reduce_power ? (PA_CONTROL_DEFAULT | PD_Q5G_MASK) & (~(PA5G_PW_MASK | PA5G_BS_MASK)) : PA_CONTROL_DEFAULT));
} }
#endif #endif

View file

@ -17,21 +17,22 @@
#pragma once #pragma once
#define DP_5G_MASK 0x7000 #define DP_5G_MASK 0x7000
#define PA5G_BS_MASK 0x0E00 #define PA5G_BS_MASK 0x0E00
#define PA5G_PW_MASK 0x0180 #define PA5G_PW_MASK 0x0180
#define PD_Q5G_MASK 0x0040 #define PD_Q5G_MASK 0x0040
#define QI_5G_MASK 0x0038 #define QI_5G_MASK 0x0038
#define PA_BS_MASK 0x0007 #define PA_BS_MASK 0x0007
#define PA_CONTROL_DEFAULT 0x4FBD #define PA_CONTROL_DEFAULT 0x4FBD
#define CHANNELS_PER_BAND 8
#define BANDS_NUMBER 5
extern char* vtx_bands[]; extern uint16_t const vtx_freq[];
extern uint16_t vtx_freq[];
extern uint16_t current_vtx_channel; extern uint16_t current_vtx_channel;
void rtc6705_soft_spi_init(void); void rtc6705_soft_spi_init(void);
void rtc6705_soft_spi_set_channel(uint16_t channel_freq); void rtc6705_soft_spi_set_channel(uint16_t channel_freq);
void rtc6705_soft_spi_set_rf_power(uint8_t power); void rtc6705_soft_spi_set_rf_power(uint8_t reduce_power);

View file

@ -22,6 +22,7 @@
#include <math.h> #include <math.h>
#include "platform.h" #include "platform.h"
#include "version.h"
#include "scheduler/scheduler.h" #include "scheduler/scheduler.h"
#include "common/axis.h" #include "common/axis.h"
@ -123,57 +124,73 @@
static uint32_t next_osd_update_at = 0; static uint32_t next_osd_update_at = 0;
static uint32_t armed_seconds = 0; static uint32_t armed_seconds = 0;
static uint32_t armed_at = 0; static uint32_t armed_at = 0;
static bool armed = false; static uint8_t armed = 0;
static uint8_t current_page = 0;
static uint8_t sticks[] = {0,0,0,0};
static uint8_t cursor_row = 255;
static uint8_t cursor_col = 0;
static uint8_t in_menu = 0;
static uint8_t activating_menu = 0;
static uint8_t current_page = 0;
static uint8_t sticks[] = {0,0,0,0};
static char string_buffer[30]; static char string_buffer[30];
static uint8_t cursor_row = 255;
static uint8_t cursor_col = 0;
static bool in_menu = false;
static bool activating_menu = false;
extern uint16_t rssi; extern uint16_t rssi;
enum {
MENU_VALUE_DECREASE = 0,
MENU_VALUE_INCREASE,
};
#ifdef USE_RTC6705 #ifdef USE_RTC6705
void update_vtx_band(bool increase, uint8_t col) {
(void)col; static const char *vtx_bands[] = {
if (increase) { "BOSCAM A",
if (current_vtx_channel < 32) "BOSCAM B",
current_vtx_channel += 8; "BOSCAM E",
"FATSHARK",
"RACEBAND",
};
void update_vtx_band(int value_change_direction, uint8_t col) {
UNUSED(col);
if (value_change_direction) {
if (current_vtx_channel < (BANDS_NUMBER * CHANNELS_PER_BAND - CHANNELS_PER_BAND))
current_vtx_channel += CHANNELS_PER_BAND;
} else { } else {
if (current_vtx_channel > 7) if (current_vtx_channel >= CHANNELS_PER_BAND)
current_vtx_channel -= 8; current_vtx_channel -= CHANNELS_PER_BAND;
} }
} }
void print_vtx_band(uint16_t pos, uint8_t col) { void print_vtx_band(uint16_t pos, uint8_t col) {
(void)col; UNUSED(col);
sprintf(string_buffer, "%s", vtx_bands[current_vtx_channel / 8]); sprintf(string_buffer, "%s", vtx_bands[current_vtx_channel / CHANNELS_PER_BAND]);
max7456_write_string(string_buffer, pos); max7456_write_string(string_buffer, pos);
} }
void update_vtx_channel(bool increase, uint8_t col) { void update_vtx_channel(int value_change_direction, uint8_t col) {
(void)col; UNUSED(col);
if (increase) { if (value_change_direction) {
if ((current_vtx_channel % 8) < 7) if ((current_vtx_channel % CHANNELS_PER_BAND) < (CHANNELS_PER_BAND - 1))
current_vtx_channel++; current_vtx_channel++;
} else { } else {
if ((current_vtx_channel % 8) > 0) if ((current_vtx_channel % CHANNELS_PER_BAND) > 0)
current_vtx_channel--; current_vtx_channel--;
} }
} }
void print_vtx_channel(uint16_t pos, uint8_t col) { void print_vtx_channel(uint16_t pos, uint8_t col) {
(void)col; UNUSED(col);
sprintf(string_buffer, "%d", current_vtx_channel % 8 + 1); sprintf(string_buffer, "%d", current_vtx_channel % CHANNELS_PER_BAND + 1);
max7456_write_string(string_buffer, pos); max7456_write_string(string_buffer, pos);
} }
void print_vtx_freq(uint16_t pos, uint8_t col) { void print_vtx_freq(uint16_t pos, uint8_t col) {
(void)col; UNUSED(col);
sprintf(string_buffer, "%d M", vtx_freq[current_vtx_channel]); sprintf(string_buffer, "%d M", vtx_freq[current_vtx_channel]);
max7456_write_string(string_buffer, pos); max7456_write_string(string_buffer, pos);
} }
@ -243,8 +260,9 @@ void print_tpa_brkpt(uint16_t pos, uint8_t col) {
} }
} }
void update_int_pid(bool inc, uint8_t col, int pid_term) { void update_int_pid(int value_change_direction, uint8_t col, int pid_term) {
void* ptr; void* ptr;
switch(col) { switch(col) {
case 0: case 0:
ptr = &currentProfile->pidProfile.P8[pid_term]; ptr = &currentProfile->pidProfile.P8[pid_term];
@ -259,7 +277,7 @@ void update_int_pid(bool inc, uint8_t col, int pid_term) {
return; return;
} }
if (inc) { if (value_change_direction) {
if (*(uint8_t*)ptr < 200) if (*(uint8_t*)ptr < 200)
*(uint8_t*)ptr += 1; *(uint8_t*)ptr += 1;
} else { } else {
@ -268,21 +286,22 @@ void update_int_pid(bool inc, uint8_t col, int pid_term) {
} }
} }
void update_roll_pid(bool inc, uint8_t col) { void update_roll_pid(int value_change_direction, uint8_t col) {
update_int_pid(inc, col, ROLL); update_int_pid(value_change_direction, col, ROLL);
} }
void update_pitch_pid(bool inc, uint8_t col) { void update_pitch_pid(int value_change_direction, uint8_t col) {
update_int_pid(inc, col, PITCH); update_int_pid(value_change_direction, col, PITCH);
} }
void update_yaw_pid(bool inc, uint8_t col) { void update_yaw_pid(int value_change_direction, uint8_t col) {
update_int_pid(inc, col, YAW); update_int_pid(value_change_direction, col, YAW);
} }
void update_roll_rate(bool inc, uint8_t col) { void update_roll_rate(int value_change_direction, uint8_t col) {
(void)col; UNUSED(col);
if (inc) {
if (value_change_direction) {
if (currentControlRateProfile->rates[FD_ROLL] < CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX) if (currentControlRateProfile->rates[FD_ROLL] < CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX)
currentControlRateProfile->rates[FD_ROLL]++; currentControlRateProfile->rates[FD_ROLL]++;
} else { } else {
@ -291,9 +310,10 @@ void update_roll_rate(bool inc, uint8_t col) {
} }
} }
void update_pitch_rate(bool increase, uint8_t col) { void update_pitch_rate(int value_change_direction, uint8_t col) {
(void)col; UNUSED(col);
if (increase) {
if (value_change_direction) {
if (currentControlRateProfile->rates[FD_PITCH] < CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX) if (currentControlRateProfile->rates[FD_PITCH] < CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX)
currentControlRateProfile->rates[FD_PITCH]++; currentControlRateProfile->rates[FD_PITCH]++;
} else { } else {
@ -302,9 +322,10 @@ void update_pitch_rate(bool increase, uint8_t col) {
} }
} }
void update_yaw_rate(bool increase, uint8_t col) { void update_yaw_rate(int value_change_direction, uint8_t col) {
(void)col; UNUSED(col);
if (increase) {
if (value_change_direction) {
if (currentControlRateProfile->rates[FD_YAW] < CONTROL_RATE_CONFIG_YAW_RATE_MAX) if (currentControlRateProfile->rates[FD_YAW] < CONTROL_RATE_CONFIG_YAW_RATE_MAX)
currentControlRateProfile->rates[FD_YAW]++; currentControlRateProfile->rates[FD_YAW]++;
} else { } else {
@ -313,9 +334,10 @@ void update_yaw_rate(bool increase, uint8_t col) {
} }
} }
void update_tpa_rate(bool increase, uint8_t col) { void update_tpa_rate(int value_change_direction, uint8_t col) {
(void)col; UNUSED(col);
if (increase) {
if (value_change_direction) {
if (currentControlRateProfile->dynThrPID < CONTROL_RATE_CONFIG_TPA_MAX) if (currentControlRateProfile->dynThrPID < CONTROL_RATE_CONFIG_TPA_MAX)
currentControlRateProfile->dynThrPID++; currentControlRateProfile->dynThrPID++;
} else { } else {
@ -324,9 +346,10 @@ void update_tpa_rate(bool increase, uint8_t col) {
} }
} }
void update_tpa_brkpt(bool increase, uint8_t col) { void update_tpa_brkpt(int value_change_direction, uint8_t col) {
(void)col; UNUSED(col);
if (increase) {
if (value_change_direction) {
if (currentControlRateProfile->tpa_breakpoint < PWM_RANGE_MAX) if (currentControlRateProfile->tpa_breakpoint < PWM_RANGE_MAX)
currentControlRateProfile->tpa_breakpoint++; currentControlRateProfile->tpa_breakpoint++;
} else { } else {
@ -336,13 +359,15 @@ void update_tpa_brkpt(bool increase, uint8_t col) {
} }
void print_average_system_load(uint16_t pos, uint8_t col) { void print_average_system_load(uint16_t pos, uint8_t col) {
(void)col; UNUSED(col);
sprintf(string_buffer, "%d", averageSystemLoadPercent); sprintf(string_buffer, "%d", averageSystemLoadPercent);
max7456_write_string(string_buffer, pos); max7456_write_string(string_buffer, pos);
} }
void print_batt_voltage(uint16_t pos, uint8_t col) { void print_batt_voltage(uint16_t pos, uint8_t col) {
(void)col; UNUSED(col);
sprintf(string_buffer, "%d.%1d", vbat / 10, vbat % 10); sprintf(string_buffer, "%d.%1d", vbat / 10, vbat % 10);
max7456_write_string(string_buffer, pos); max7456_write_string(string_buffer, pos);
} }
@ -503,7 +528,7 @@ void show_menu(void) {
} }
} else { } else {
if (menu_pages[current_page].rows[cursor_row].update) if (menu_pages[current_page].rows[cursor_row].update)
menu_pages[current_page].rows[cursor_row].update(true, cursor_col); menu_pages[current_page].rows[cursor_row].update(MENU_VALUE_INCREASE, cursor_col);
} }
} }
@ -514,7 +539,7 @@ void show_menu(void) {
} }
} else { } else {
if (menu_pages[current_page].rows[cursor_row].update) if (menu_pages[current_page].rows[cursor_row].update)
menu_pages[current_page].rows[cursor_row].update(false, cursor_col); menu_pages[current_page].rows[cursor_row].update(MENU_VALUE_DECREASE, cursor_col);
} }
} }
@ -697,10 +722,24 @@ void updateOsd(void)
} }
} }
void osdInit(void) void osdInit(void)
{ {
uint16_t x;
max7456_init(masterConfig.osdProfile.video_system); max7456_init(masterConfig.osdProfile.video_system);
// display logo and help
x = 160;
for (int i = 1; i < 5; i++) {
for (int j = 3; j < 27; j++)
max7456_screen[i * LINE + j] = (char)x++;
}
sprintf(string_buffer, "BF VERSION: %s", FC_VERSION_STRING);
max7456_write_string(string_buffer, LINE06 + 5);
max7456_write_string("MENU: THRT MID", LINE07 + 7);
max7456_write_string("YAW RIGHT", LINE08 + 13);
max7456_write_string("PITCH UP", LINE09 + 13);
max7456_draw_screen();
} }
void resetOsdConfig(void) void resetOsdConfig(void)

View file

@ -25,7 +25,7 @@ typedef struct {
typedef struct { typedef struct {
const char* title; const char* title;
void (*update)(bool increase, uint8_t col); void (*update)(int value_change_direction, uint8_t col);
void (*print)(uint16_t pos, uint8_t col); void (*print)(uint16_t pos, uint8_t col);
} osd_row_t; } osd_row_t;

View file

@ -471,7 +471,7 @@ void init(void)
#endif #endif
#ifdef USE_RTC6705 #ifdef USE_RTC6705
if (feature(feature(FEATURE_VTX))) { if (feature(FEATURE_VTX)) {
rtc6705_soft_spi_init(); rtc6705_soft_spi_init();
current_vtx_channel = masterConfig.vtx_channel; current_vtx_channel = masterConfig.vtx_channel;
rtc6705_soft_spi_set_channel(vtx_freq[current_vtx_channel]); rtc6705_soft_spi_set_channel(vtx_freq[current_vtx_channel]);

View file

@ -135,7 +135,7 @@
// Performance logging for SD card operations: // Performance logging for SD card operations:
// #define AFATFS_USE_INTROSPECTIVE_LOGGING // #define AFATFS_USE_INTROSPECTIVE_LOGGING
#define DEFAULT_FEATURES (FEATURE_BLACKBOX | FEATURE_RX_SERIAL | FEATURE_OSD | FEATURE_VTX)
#define USE_ADC #define USE_ADC
#define BOARD_HAS_VOLTAGE_DIVIDER #define BOARD_HAS_VOLTAGE_DIVIDER

View file

@ -1,5 +1,5 @@
F3_TARGETS += $(TARGET) F3_TARGETS += $(TARGET)
FEATURES = VCP SDCARD MAX_OSD SOFT_VTX FEATURES = VCP SDCARD
TARGET_SRC = \ TARGET_SRC = \
drivers/accgyro_mpu.c \ drivers/accgyro_mpu.c \
@ -12,5 +12,7 @@ TARGET_SRC = \
drivers/flash_m25p16.c \ drivers/flash_m25p16.c \
drivers/light_ws2811strip.c \ drivers/light_ws2811strip.c \
drivers/light_ws2811strip_stm32f30x.c \ drivers/light_ws2811strip_stm32f30x.c \
drivers/vtx_soft_spi_rtc6705.c drivers/vtx_soft_spi_rtc6705.c \
drivers/max7456.c \
io/osd.c