ESPHome
2025.9.1
Loading...
Searching...
No Matches
esphome
components
nrf52
dfu.cpp
Go to the documentation of this file.
1
#include "
dfu.h
"
2
3
#ifdef USE_NRF52_DFU
4
5
#include <zephyr/device.h>
6
#include <zephyr/drivers/uart.h>
7
#include <zephyr/drivers/uart/cdc_acm.h>
8
#include "
esphome/core/log.h
"
9
10
namespace
esphome
{
11
namespace
nrf52 {
12
13
static
const
char
*
const
TAG =
"dfu"
;
14
15
volatile
bool
goto_dfu
=
false
;
// NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
16
17
static
const
uint32_t DFU_DBL_RESET_MAGIC = 0x5A1AD5;
// SALADS
18
19
#define DEVICE_AND_COMMA(node_id) DEVICE_DT_GET(node_id),
20
21
static
void
cdc_dte_rate_callback(
const
struct
device *
/*unused*/
, uint32_t rate) {
22
if
(rate == 1200) {
23
goto_dfu
=
true
;
24
}
25
}
26
void
DeviceFirmwareUpdate::setup
() {
27
this->
reset_pin_
->
setup
();
28
const
struct
device *cdc_dev[] = {DT_FOREACH_STATUS_OKAY(zephyr_cdc_acm_uart, DEVICE_AND_COMMA)};
29
for
(
auto
&idx : cdc_dev) {
30
cdc_acm_dte_rate_callback_set(idx, cdc_dte_rate_callback);
31
}
32
}
33
34
void
DeviceFirmwareUpdate::loop
() {
35
if
(
goto_dfu
) {
36
goto_dfu
=
false
;
37
volatile
uint32_t *dbl_reset_mem = (
volatile
uint32_t *) 0x20007F7C;
38
(*dbl_reset_mem) = DFU_DBL_RESET_MAGIC;
39
this->
reset_pin_
->
digital_write
(
true
);
40
}
41
}
42
43
void
DeviceFirmwareUpdate::dump_config
() {
44
ESP_LOGCONFIG(TAG,
"DFU:"
);
45
LOG_PIN(
" RESET Pin: "
, this->
reset_pin_
);
46
}
47
48
}
// namespace nrf52
49
}
// namespace esphome
50
51
#endif
esphome::GPIOPin::setup
virtual void setup()=0
esphome::GPIOPin::digital_write
virtual void digital_write(bool value)=0
esphome::nrf52::DeviceFirmwareUpdate::dump_config
void dump_config() override
Definition
dfu.cpp:43
esphome::nrf52::DeviceFirmwareUpdate::reset_pin_
GPIOPin * reset_pin_
Definition
dfu.h:18
esphome::nrf52::DeviceFirmwareUpdate::setup
void setup() override
Definition
dfu.cpp:26
esphome::nrf52::DeviceFirmwareUpdate::loop
void loop() override
Definition
dfu.cpp:34
dfu.h
log.h
esphome::nrf52::goto_dfu
volatile bool goto_dfu
Definition
dfu.cpp:15
esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition
a01nyub.cpp:7
Generated by
1.12.0