ESP32 Module - smartel99/NilaiTFO GitHub Wiki
-
EspModule
- Types
- Operation
- Logging
- Theory of Operation
-
Public Functions
EspModule::EspModule(const std::string& label, UartModule* uart, const std::string& deviceName, const ESP32::Pins& pins)
void EspModule::Enable()
void EspModule::Disable()
bool EspModule::IsEnabled()
void EspModule::SetBootMode(ESP32::BootMode mode)
bool EspModule::ProgramEsp(const std::string& filepath = "esp32.bin")
void EspModule::Transmit(const char* msg, size_t len)
void EspModule::Transmit(const std::string& msg)
void EspModule::Transmit(const std::vector<uint8_t>& msg)
size_t EspModule::GetNumberOfWaitingFrames() const
CEP_UART::Frame EspModule::Receive()
void EspModule::SetExpectedRxLen(size_t len)
void EspModule::ClearExpectedRxLen()
void EspModule::SetFrameReceiveCpltCallback(const std::function<void()>& cb)
void EspModule::ClearFrameReceiveCpltCallback()
void EspModule::SetStartOfFrameSequence()
void EspModule::ClearStartOfFrameSequence()
void EspModule::SetEndOfFrameSequence()
void EspModule::ClearEndOfFrameSequence()
- Misc
- Location: shared/interfaces/Esp32Module.*
- Brief: Interface with the ESP32 serving as the bluetooth controller of the system.
-
Configuration: Connected to the ESP32 through a
UART
module, as well as throughESP32_EN
,ESP32_BOOT
,ESP32_TPOUT
andESP32_TPIN
.
Uses:
-
UartModule
- For communication
-
Pin
- To control the various I/O
Enum listing the boot modes of the ESP32.
Members:
- Bootloader = 0
- Normal = 1
Structure containing the control pins of the ESP32 module.
Members:
-
Pin enable
: Enable pin of the ESP32. When high, the ESP32 is enabled. -
Pin boot
: Boot selection pin. When high, normal boot. When low, runs the bootloader. -
Pin tpout
: Heartbeat pin from the ESP32 to the STM32. -
Pin tpin
: Debug signal from the STM32 to the ESP32, currently not used for any purpose.
The initialisation sequence consists of the following steps:
- Initialize the
UART
module - Set the
ESP32_EN
pin LOW - Set the
ESP32_BOOT
pin HIGH - Set the
ESP32_EN
pin HIGH - Do the POST
To pass the POST, the following list of actions must all succeed:
- Successfully initialised the
UART
peripheral -
ESP32_TPOUT
is HIGH - Send the device name to be used to the ESP32.
- The ESP32 responds with "OK" after receiving it's name.
During the run loop of this module, the ESP32_TPOUT
pin is monitored to make sure it is still in a HIGH state.
If it isn't, the ESP32 is reset by toggling the ESP32_EN
pin LOW then HIGH again.
The device name needs to be sent again when the ESP32 is reset.
Function | Event | Message | Appears On Debug Port | Appears in Log File |
---|---|---|---|---|
TODO |
Once initialized, this module acts like a regular UART module.
This module is basically just a wrapper around a UartModule
handle.
EspModule::EspModule(const std::string& label, UartModule* uart, const std::string& deviceName, const ESP32::Pins& pins)
Constructor of the module.
Parameters:
-
const std::string& label
: label to be used by the module -
UartModule* uart
: Pointer to the UART port to use -
const std::string& deviceName
: String to use as the device name -
const ESP32::Pins& pins
: Structure containing the control pins of the ESP32
Enables the ESP32.
Parameters: None
Returns: None
Disables the ESP32.
Parameters: None
Returns: None
Check if the ESP32 is currently enabled.
Parameters: None
Returns: True if the ESP32 is enabled, false otherwise
Set the boot mode of the ESP32.
For this to be of any use, you must follow these steps:
- Disable the ESP32
- Set the boot mode
- Enable the ESP32
Parameters:
-
ESP32::BootMode mode
: The desired boot mode
Returns: None
Programs the ESP32 with the specified binary file located on the SD card.
If the file cannot be found on the SD card, nothing is done.
To program the ESP32, you must follow these steps:
- Disable the ESP32
- Set the boot mode to
ESP32::BootMode::Bootloader
- Enable the ESP32
- Program the ESP32
- Disable the ESP32
- Set the boot mode back to
ESP32::BootMode::Normal
- Enable the ESP32
To minimize the risk of failure at any steps of the programming process, this function works in the following way:
- Check if the file specified in parameter exists on the SD card
- If it exists, open it and verify the checksum
- If the checksum is valid, set the ESP32 into bootloader mode
- Program the ESP32 with the binary file
Note: This function is completely disabled if the filesystem module is not enabled.
Parameters:
-
const std::string& filepath
: The path of the binary file to program the ESP32 with, defaults to "esp32.bin"
Returns: True if the programming was successful, false otherwise
Wrapper around UartModule::Transmit(const char* msg, size_t len)
.
Parameters:
-
const char* msg
: The packet to send. -
size_t len
: The number of bytes to send.
Returns: None
Wrapper around UartModule::Transmit(const std::string& msg)
.
Parameters:
-
const std::string& msg
: The packet to send.
Returns: None
Wrapper around UartModule::Transmit(const std::vector<uint8_t>& msg)
.
Parameters:
-
const std::vector<uint8_t>& msg
: The packet to send.
Returns: None
Wrapper around UartModule::GetNumberOfWaitingFrames()
.
Parameters: None
Returns: The number of frames waiting to be read.
Wrapper around UartModule::Receive()
.
Parameters: None
Returns: The received frame.
Wrapper around UartModule::SetExpectedRxLen(size_t len)
.
Parameters: The number of bytes that are expected to be received
Returns: None
Wrapper around UartModule::ClearExpectedRxLen()
.
Parameters: None
Returns: None
Wrapper around UartModule::SetFrameReceiveCpltCallback(const std::function<void()>& cb)
.
Parameters:
-
const std::function<void()>& cb
: The function to be called once a frame has been received.
Returns: None
Wrapper around UartModule::ClearFrameReceiveCpltCallback()
.
Parameters: None
Returns: None
void EspModule::SetStartOfFrameSequence(const char* sof, size_t len)
void EspModule::SetStartOfFrameSequence(const std::string& sof)
-
void EspModule::SetStartOfFrameSequence(const std::vector<uint8_t>& sof)
Wrapper aroundUartModule::SetStartOfFrameSequence()
.
Parameters:
-
void EspModule::SetStartOfFrameSequence(const char* sof, size_t len)
:-
const char* sof
: The start of frame -
size_t len
: The number of bytes in the start of frame
-
-
void EspModule::SetStartOfFrameSequence(const std::string& sof)
:-
const std::string& sof
: The start of frame
-
-
void EspModule::SetStartOfFrameSequence(const std::vector<uint8_t>& sof)
:-
const std::vector<uint8_t>& sof
: The start of frame
-
Returns: None
Wrapper around UartModule::ClearStartOfFrameSequence()
.
Parameters: None
Returns: None
void EspModule::SetEndOfFrameSequence(const char* sof, size_t len)
void EspModule::SetEndOfFrameSequence(const std::string& sof)
-
void EspModule::SetEndOfFrameSequence(const std::vector<uint8_t>& sof)
Wrapper aroundUartModule::SetEndOfFrameSequence()
.
Parameters:
-
void EspModule::SetEndOfFrameSequence(const char* sof, size_t len)
:-
const char* sof
: The end of frame -
size_t len
: The number of bytes in the end of frame
-
-
void EspModule::SetEndOfFrameSequence(const std::string& sof)
:-
const std::string& sof
: The end of frame
-
-
void EspModule::SetEndOfFrameSequence(const std::vector<uint8_t>& sof)
:-
const std::vector<uint8_t>& sof
: The end of frame
-
Returns: None
Wrapper around UartModule::ClearEndOfFrameSequence()
.
Parameters: None
Returns: None