kopia lustrzana https://github.com/mobilinkd/tnc3-firmware
Support power on/off via USB. Initialize PTT on power-on. Reset on resume from stop2.
rodzic
c33c97a1ef
commit
b5dccefb7e
66
Src/main.c
66
Src/main.c
|
@ -59,6 +59,7 @@
|
||||||
#include "LEDIndicator.h"
|
#include "LEDIndicator.h"
|
||||||
#include "bm78.h"
|
#include "bm78.h"
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
|
#include "KissHardware.h"
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
@ -276,12 +277,13 @@ void configure_wakeup_gpio()
|
||||||
HAL_NVIC_DisableIRQ(EXTI1_IRQn);
|
HAL_NVIC_DisableIRQ(EXTI1_IRQn);
|
||||||
HAL_GPIO_DeInit(GPIOH, USB_POWER_Pin|SW_POWER_Pin);
|
HAL_GPIO_DeInit(GPIOH, USB_POWER_Pin|SW_POWER_Pin);
|
||||||
|
|
||||||
// Wake up whenever there is a change in VUSB to handle connect and
|
// Wake up whenever there is a change in VUSB to handle connect events.
|
||||||
// disconnect events.
|
if (powerOnViaUSB()) {
|
||||||
GPIO_InitStruct.Pin = USB_POWER_Pin;
|
GPIO_InitStruct.Pin = USB_POWER_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING_FALLING;
|
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL; // Pulled down on PCB.
|
GPIO_InitStruct.Pull = GPIO_NOPULL; // Pulled down on PCB.
|
||||||
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
|
||||||
|
}
|
||||||
|
|
||||||
// Only wake up after the button has been released. This avoids the case
|
// Only wake up after the button has been released. This avoids the case
|
||||||
// where the TNC is woken up on button down and then immediately put back
|
// where the TNC is woken up on button down and then immediately put back
|
||||||
|
@ -1263,57 +1265,7 @@ void stop2()
|
||||||
HAL_PWREx_DisableLowPowerRunMode();
|
HAL_PWREx_DisableLowPowerRunMode();
|
||||||
HAL_DBGMCU_DisableDBGStopMode();
|
HAL_DBGMCU_DisableDBGStopMode();
|
||||||
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFE);
|
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFE);
|
||||||
|
HAL_NVIC_SystemReset();
|
||||||
uint16_t wakeup_pin = SW_POWER_Pin;
|
|
||||||
|
|
||||||
if (HAL_GPIO_ReadPin(USB_POWER_GPIO_Port, USB_POWER_Pin) != usb)
|
|
||||||
{
|
|
||||||
wakeup_pin = USB_POWER_Pin;
|
|
||||||
}
|
|
||||||
|
|
||||||
HAL_NVIC_ClearPendingIRQ(EXTI0_IRQn);
|
|
||||||
HAL_NVIC_ClearPendingIRQ(EXTI1_IRQn);
|
|
||||||
HAL_NVIC_ClearPendingIRQ(EXTI3_IRQn);
|
|
||||||
HAL_NVIC_ClearPendingIRQ(EXTI4_IRQn);
|
|
||||||
HAL_NVIC_ClearPendingIRQ(EXTI9_5_IRQn);
|
|
||||||
|
|
||||||
__asm volatile ( "cpsie i" );
|
|
||||||
__asm volatile ( "dsb" );
|
|
||||||
__asm volatile ( "isb" );
|
|
||||||
|
|
||||||
MX_GPIO_Init();
|
|
||||||
|
|
||||||
// Let power stabilize.
|
|
||||||
for (int i = 0; i < 4800; ++i) asm volatile("nop");
|
|
||||||
|
|
||||||
SystemClock_Config();
|
|
||||||
|
|
||||||
if (HAL_CRC_Init(&hcrc) != HAL_OK) Error_Handler();
|
|
||||||
// Need to re-init and calibrate after deep power down.
|
|
||||||
if (HAL_ADC_Init(&hadc1) != HAL_OK) Error_Handler();
|
|
||||||
if (HAL_DAC_Init(&hdac1) != HAL_OK) Error_Handler();
|
|
||||||
if (HAL_OPAMP_Init(&hopamp1) != HAL_OK) Error_Handler();
|
|
||||||
|
|
||||||
if (HAL_UART_Init(&huart3) != HAL_OK) Error_Handler();
|
|
||||||
__HAL_UART_DISABLE(&huart3);
|
|
||||||
|
|
||||||
HAL_TIM_Base_Init(&htim1);
|
|
||||||
HAL_TIM_MspPostInit(&htim1);
|
|
||||||
HAL_TIM_Base_Init(&htim7);
|
|
||||||
HAL_TIM_Base_Init(&htim6);
|
|
||||||
|
|
||||||
if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED) != HAL_OK) Error_Handler();
|
|
||||||
if (HAL_DAC_Start(&hdac1, DAC_CHANNEL_2) != HAL_OK) Error_Handler();
|
|
||||||
if (HAL_DAC_Start(&hdac1, DAC_CHANNEL_1) != HAL_OK) Error_Handler();
|
|
||||||
if (HAL_OPAMP_Start(&hopamp1) != HAL_OK) Error_Handler();
|
|
||||||
HAL_PWR_EnablePVD();
|
|
||||||
|
|
||||||
if (HAL_GPIO_ReadPin(USB_POWER_GPIO_Port, USB_POWER_Pin) == GPIO_PIN_SET)
|
|
||||||
{
|
|
||||||
HAL_PCD_Init(&hpcd_USB_FS);
|
|
||||||
}
|
|
||||||
|
|
||||||
osThreadResumeAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
|
|
|
@ -32,6 +32,11 @@ extern "C" void stop2(void);
|
||||||
extern "C" void shutdown(void);
|
extern "C" void shutdown(void);
|
||||||
extern "C" void startLedBlinkerTask(void const*);
|
extern "C" void startLedBlinkerTask(void const*);
|
||||||
|
|
||||||
|
static PTT getPttStyle(const mobilinkd::tnc::kiss::Hardware& hardware)
|
||||||
|
{
|
||||||
|
return hardware.options & KISS_OPTION_PTT_SIMPLEX ? PTT::SIMPLEX : PTT::MULTIPLEX;
|
||||||
|
}
|
||||||
|
|
||||||
void startIOEventTask(void const*)
|
void startIOEventTask(void const*)
|
||||||
{
|
{
|
||||||
using namespace mobilinkd::tnc;
|
using namespace mobilinkd::tnc;
|
||||||
|
@ -54,6 +59,7 @@ void startIOEventTask(void const*)
|
||||||
audio::init_log_volume();
|
audio::init_log_volume();
|
||||||
audio::setAudioOutputLevel();
|
audio::setAudioOutputLevel();
|
||||||
audio::setAudioInputLevels();
|
audio::setAudioInputLevels();
|
||||||
|
setPtt(getPttStyle(hardware));
|
||||||
|
|
||||||
// Cannot enable these interrupts until we start the io loop because
|
// Cannot enable these interrupts until we start the io loop because
|
||||||
// they send messages on the queue.
|
// they send messages on the queue.
|
||||||
|
@ -119,11 +125,16 @@ void startIOEventTask(void const*)
|
||||||
break;
|
break;
|
||||||
case CMD_USB_DISCONNECTED:
|
case CMD_USB_DISCONNECTED:
|
||||||
INFO("VBUS Lost");
|
INFO("VBUS Lost");
|
||||||
HAL_PCD_MspDeInit(&hpcd_USB_FS);
|
if (powerOffViaUSB()) {
|
||||||
HAL_GPIO_WritePin(USB_CE_GPIO_Port, USB_CE_Pin, GPIO_PIN_SET);
|
stop2();
|
||||||
if (ioport != getUsbPort())
|
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
HAL_PCD_MspDeInit(&hpcd_USB_FS);
|
||||||
|
HAL_GPIO_WritePin(USB_CE_GPIO_Port, USB_CE_Pin, GPIO_PIN_SET);
|
||||||
|
if (ioport != getUsbPort())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Fallthrough*/ // when the CDC part was connected.
|
/* Fallthrough*/ // when the CDC part was connected.
|
||||||
case CMD_USB_CDC_DISCONNECT:
|
case CMD_USB_CDC_DISCONNECT:
|
||||||
|
|
|
@ -15,9 +15,19 @@
|
||||||
extern I2C_HandleTypeDef hi2c1;
|
extern I2C_HandleTypeDef hi2c1;
|
||||||
extern RTC_HandleTypeDef hrtc;
|
extern RTC_HandleTypeDef hrtc;
|
||||||
|
|
||||||
|
int powerOnViaUSB(void)
|
||||||
|
{
|
||||||
|
return mobilinkd::tnc::kiss::settings().options & KISS_OPTION_VIN_POWER_ON;
|
||||||
|
}
|
||||||
|
|
||||||
|
int powerOffViaUSB(void)
|
||||||
|
{
|
||||||
|
return mobilinkd::tnc::kiss::settings().options & KISS_OPTION_VIN_POWER_OFF;
|
||||||
|
}
|
||||||
|
|
||||||
namespace mobilinkd { namespace tnc { namespace kiss {
|
namespace mobilinkd { namespace tnc { namespace kiss {
|
||||||
|
|
||||||
const char FIRMWARE_VERSION[] = "0.8.9";
|
const char FIRMWARE_VERSION[] = "0.8.10";
|
||||||
const char HARDWARE_VERSION[] = "Mobilinkd TNC3 2.1.1";
|
const char HARDWARE_VERSION[] = "Mobilinkd TNC3 2.1.1";
|
||||||
|
|
||||||
Hardware& settings()
|
Hardware& settings()
|
||||||
|
@ -373,8 +383,8 @@ void Hardware::handle_request(hdlc::IoFrame* frame) {
|
||||||
|
|
||||||
case hardware::SET_PTT_CHANNEL:
|
case hardware::SET_PTT_CHANNEL:
|
||||||
DEBUG("SET_PTT_CHANNEL");
|
DEBUG("SET_PTT_CHANNEL");
|
||||||
options &= ~KISS_OPTION_PTT_SIMPLEX;
|
|
||||||
if (*it) {
|
if (*it) {
|
||||||
|
options &= ~KISS_OPTION_PTT_SIMPLEX;
|
||||||
osMessagePut(ioEventQueueHandle, CMD_SET_PTT_MULTIPLEX, osWaitForever);
|
osMessagePut(ioEventQueueHandle, CMD_SET_PTT_MULTIPLEX, osWaitForever);
|
||||||
} else {
|
} else {
|
||||||
options |= KISS_OPTION_PTT_SIMPLEX;
|
options |= KISS_OPTION_PTT_SIMPLEX;
|
||||||
|
@ -449,8 +459,8 @@ void Hardware::handle_request(hdlc::IoFrame* frame) {
|
||||||
sizeof(HARDWARE_VERSION) - 1);
|
sizeof(HARDWARE_VERSION) - 1);
|
||||||
reply(hardware::GET_SERIAL_NUMBER, (uint8_t*) serial_number_64,
|
reply(hardware::GET_SERIAL_NUMBER, (uint8_t*) serial_number_64,
|
||||||
sizeof(serial_number_64) - 1);
|
sizeof(serial_number_64) - 1);
|
||||||
reply8(hardware::GET_USB_POWER_OFF, options & KISS_OPTION_VIN_POWER_OFF ? 0 : 1);
|
reply8(hardware::GET_USB_POWER_OFF, options & KISS_OPTION_VIN_POWER_OFF ? 1 : 0);
|
||||||
reply8(hardware::GET_USB_POWER_ON, options & KISS_OPTION_VIN_POWER_ON ? 0 : 1);
|
reply8(hardware::GET_USB_POWER_ON, options & KISS_OPTION_VIN_POWER_ON ? 1 : 0);
|
||||||
reply16(hardware::GET_OUTPUT_GAIN, output_gain);
|
reply16(hardware::GET_OUTPUT_GAIN, output_gain);
|
||||||
reply8(hardware::GET_OUTPUT_TWIST, tx_twist);
|
reply8(hardware::GET_OUTPUT_TWIST, tx_twist);
|
||||||
reply16(hardware::GET_INPUT_GAIN, input_gain);
|
reply16(hardware::GET_INPUT_GAIN, input_gain);
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright 2018 Rob Riggs <rob@mobilinkd.com>
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
#ifndef MOBILINKD__TNC__KISS_HARDWARE_H_
|
||||||
|
#define MOBILINKD__TNC__KISS_HARDWARE_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int powerOnViaUSB(void);
|
||||||
|
int powerOffViaUSB(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // MOBILINKD__TNC__KISS_HARDWARE_H_
|
|
@ -4,6 +4,7 @@
|
||||||
#ifndef MOBILINKD__TNC__KISS_HARDWARE_HPP_
|
#ifndef MOBILINKD__TNC__KISS_HARDWARE_HPP_
|
||||||
#define MOBILINKD__TNC__KISS_HARDWARE_HPP_
|
#define MOBILINKD__TNC__KISS_HARDWARE_HPP_
|
||||||
|
|
||||||
|
#include "KissHardware.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "HdlcFrame.hpp"
|
#include "HdlcFrame.hpp"
|
||||||
|
|
||||||
|
@ -163,8 +164,8 @@ constexpr const uint8_t MODEM_TYPE_MFSK16 = 6;
|
||||||
// Boolean options.
|
// Boolean options.
|
||||||
#define KISS_OPTION_CONN_TRACK 0x01
|
#define KISS_OPTION_CONN_TRACK 0x01
|
||||||
#define KISS_OPTION_VERBOSE 0x02
|
#define KISS_OPTION_VERBOSE 0x02
|
||||||
#define KISS_OPTION_VIN_POWER_ON 0x04 // Power on when plugged in to USB
|
#define KISS_OPTION_VIN_POWER_ON 0x04 // Power on when plugged into USB
|
||||||
#define KISS_OPTION_VIN_POWER_OFF 0x08 // Power off when plugged in to USB
|
#define KISS_OPTION_VIN_POWER_OFF 0x08 // Power off when unplugged from USB
|
||||||
#define KISS_OPTION_PTT_SIMPLEX 0x10 // Simplex PTT (the default)
|
#define KISS_OPTION_PTT_SIMPLEX 0x10 // Simplex PTT (the default)
|
||||||
|
|
||||||
const char TOCALL[] = "APML30"; // Update for every feature change.
|
const char TOCALL[] = "APML30"; // Update for every feature change.
|
||||||
|
|
Ładowanie…
Reference in New Issue