kopia lustrzana https://github.com/mobilinkd/tnc3-firmware
Set the MAC address on startup. Support 'reset to defaults' by holding down power button while pressing reset.
rodzic
16eace0cc2
commit
9e699d07e4
|
@ -162,6 +162,7 @@ extern char error_message[80];
|
|||
extern int go_back_to_sleep;
|
||||
extern int usb_wake_state;
|
||||
extern int charging_enabled;
|
||||
extern int reset_button;
|
||||
|
||||
#define CxxErrorHandler() _Error_Handler(const_cast<char*>(__FILE__), __LINE__)
|
||||
|
||||
|
|
13
Src/main.c
13
Src/main.c
|
@ -156,6 +156,7 @@ int go_back_to_sleep __attribute__((section(".bss3")));
|
|||
int stop_now __attribute__((section(".bss3")));
|
||||
int charging_enabled __attribute__((section(".bss3")));
|
||||
int usb_wake_state __attribute__((section(".bss3")));
|
||||
int reset_button = 0;
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
|
@ -397,6 +398,11 @@ int main(void)
|
|||
stop_now = 0;
|
||||
usb_wake_state = 0;
|
||||
}
|
||||
if (RCC->CSR & (RCC_CSR_PINRSTF|RCC_CSR_BORRSTF)) {
|
||||
reset_button = 1;
|
||||
} else {
|
||||
reset_button = 0;
|
||||
}
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration----------------------------------------------------------*/
|
||||
|
@ -443,6 +449,9 @@ int main(void)
|
|||
SCB->SHCSR |= 0x70000; // Enable fault handlers;
|
||||
if (!go_back_to_sleep) {
|
||||
indicate_turning_on(); // LEDs on during boot.
|
||||
if (HAL_GPIO_ReadPin(SW_POWER_GPIO_Port, SW_POWER_Pin) && reset_button) {
|
||||
reset_requested = 1;
|
||||
}
|
||||
}
|
||||
|
||||
encode_serial_number();
|
||||
|
@ -595,10 +604,12 @@ int main(void)
|
|||
if (!go_back_to_sleep) {
|
||||
|
||||
// Initialize the BM78 Bluetooth module and the RTC date/time the first time we boot.
|
||||
if (!bm78_initialized()) {
|
||||
if (!bm78_initialized() || reset_requested) {
|
||||
bm78_initialize();
|
||||
memset(error_message, 0, sizeof(error_message));
|
||||
// init_rtc_date_time();
|
||||
} else if (reset_button) {
|
||||
bm78_initialize_mac_address();
|
||||
}
|
||||
else bm78_wait_until_ready();
|
||||
}
|
||||
|
|
|
@ -81,10 +81,6 @@ void startIOEventTask(void const*)
|
|||
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 6, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
|
||||
|
||||
if (reset_requested)
|
||||
{
|
||||
}
|
||||
|
||||
// FIXME: this is probably not right
|
||||
if (HAL_GPIO_ReadPin(BT_STATE2_GPIO_Port, BT_STATE2_Pin) == GPIO_PIN_RESET)
|
||||
{
|
||||
|
@ -181,6 +177,7 @@ void startIOEventTask(void const*)
|
|||
break;
|
||||
case CMD_POWER_BUTTON_UP:
|
||||
DEBUG("Power Up");
|
||||
if (power_button_counter == 0) break; // reset_requested
|
||||
power_button_duration = osKernelSysTick() - power_button_counter;
|
||||
DEBUG("Button pressed for %lums", power_button_duration);
|
||||
shutdown(0); // ***NO RETURN***
|
||||
|
|
|
@ -26,7 +26,7 @@ int powerOffViaUSB(void)
|
|||
|
||||
namespace mobilinkd { namespace tnc { namespace kiss {
|
||||
|
||||
const char FIRMWARE_VERSION[] = "1.0.1";
|
||||
const char FIRMWARE_VERSION[] = "1.0.2";
|
||||
const char HARDWARE_VERSION[] = "Mobilinkd TNC3 2.1.1";
|
||||
|
||||
Hardware& settings()
|
||||
|
|
|
@ -518,6 +518,15 @@ int bm78_initialized()
|
|||
return HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR1) == crc;
|
||||
}
|
||||
|
||||
void bm78_initialize_mac_address()
|
||||
{
|
||||
using namespace mobilinkd::tnc::bm78;
|
||||
|
||||
enter_program_mode();
|
||||
read_mac_address();
|
||||
exit_program_mode();
|
||||
}
|
||||
|
||||
int bm78_initialize()
|
||||
{
|
||||
using namespace mobilinkd::tnc;
|
||||
|
|
|
@ -32,6 +32,8 @@ int bm78_disable(void);
|
|||
int bm78_enable(void);
|
||||
int bm78_initialized(void);
|
||||
int bm78_initialize(void);
|
||||
void bm78_initialize_mac_address(void);
|
||||
|
||||
HAL_StatusTypeDef bm78_send(const char* data, uint16_t size, uint32_t timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Ładowanie…
Reference in New Issue