Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dedicated adc app hwconf pin defines for reverse and cruise switches #601

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions applications/app_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ static volatile bool rev_override = false;
static volatile bool cc_override = false;

void app_adc_configure(adc_config *conf) {

#ifdef HW_HARDWARE_ADC_APP_PINS
if (!buttons_detached) {
palSetPadMode(HW_REVERSE_SWITCH_PORT, HW_REVERSE_SWITCH_PIN, PAL_MODE_INPUT_PULLUP);
if ((conf->buttons >> 0) & 1) {
palSetPadMode(HW_CRUISE_SWITCH_PORT, HW_CRUISE_SWITCH_PIN, PAL_MODE_INPUT_PULLUP);
}
}
#else
if (!buttons_detached && (((conf->buttons >> 0) & 1) || CTRL_USES_BUTTON(conf->ctrl_type))) {
if (use_rx_tx_as_buttons) {
palSetPadMode(HW_UART_TX_PORT, HW_UART_TX_PIN, PAL_MODE_INPUT_PULLUP);
Expand All @@ -75,6 +84,7 @@ void app_adc_configure(adc_config *conf) {
palSetPadMode(HW_ICU_GPIO, HW_ICU_PIN, PAL_MODE_INPUT_PULLUP);
}
}
#endif

config = *conf;
ms_without_power = 0.0;
Expand Down Expand Up @@ -267,6 +277,17 @@ static THD_FUNCTION(adc_thread, arg) {
// Read the button pins
bool cc_button = false;
bool rev_button = false;

#ifdef HW_HARDWARE_ADC_APP_PINS
rev_button = !palReadPad(HW_REVERSE_SWITCH_PORT, HW_REVERSE_SWITCH_PIN);
if ((config.buttons >> 2) & 1) {
rev_button = !rev_button;
}
cc_button = !palReadPad(HW_CRUISE_SWITCH_PORT, HW_CRUISE_SWITCH_PIN);
if ((config.buttons >> 1) & 1) {
cc_button = !cc_button;
}
#else
if (use_rx_tx_as_buttons) {
cc_button = !palReadPad(HW_UART_TX_PORT, HW_UART_TX_PIN);
if ((config.buttons >> 1) & 1) {
Expand Down Expand Up @@ -294,6 +315,7 @@ static THD_FUNCTION(adc_thread, arg) {
}
}
}
#endif

// Override button values, when used from LISP
if (buttons_detached) {
Expand Down
7 changes: 7 additions & 0 deletions hwconf/trampa/75_300/hw_75_300_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@
#define HW_ADC_EXT2_GPIO GPIOA
#define HW_ADC_EXT2_PIN 6

// Hardcoded adc app pins that won't override uart port or ppm inputs. On swd pins for example
// #define HW_HARDWARE_ADC_APP_PINS
// #define HW_REVERSE_SWITCH_PORT GPIOA
// #define HW_REVERSE_SWITCH_PIN 13
// #define HW_CRUISE_SWITCH_PORT GPIOA
// #define HW_CRUISE_SWITCH_PIN 14

// UART Peripheral
#define HW_UART_DEV SD3
#define HW_UART_GPIO_AF GPIO_AF_USART3
Expand Down