mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-16 03:24:15 +02:00
Changed analogoutput to uint32_t
Added a few more support classes.
This commit is contained in:
@@ -49,7 +49,8 @@ namespace UserOutput {
|
||||
|
||||
// ==================================================================
|
||||
|
||||
AnalogOutput::AnalogOutput(uint8_t number, Pin& pin, float pwm_frequency) : _number(number), _pin(pin), _pwm_frequency(pwm_frequency) {
|
||||
AnalogOutput::AnalogOutput(uint8_t number, Pin& pin, uint32_t pwm_frequency) :
|
||||
_number(number), _pin(pin), _pwm_frequency(pwm_frequency) {
|
||||
if (_pin.undefined()) {
|
||||
return;
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ namespace UserOutput {
|
||||
|
||||
class AnalogOutput {
|
||||
public:
|
||||
AnalogOutput(uint8_t number, Pin& pin, float pwm_frequency);
|
||||
AnalogOutput(uint8_t number, Pin& pin, uint32_t pwm_frequency);
|
||||
bool set_level(uint32_t numerator);
|
||||
uint32_t denominator() { return 1UL << _resolution_bits; };
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace UserOutput {
|
||||
uint8_t _number = UNDEFINED_OUTPUT;
|
||||
Pin& _pin;
|
||||
uint8_t _pwm_channel = -1; // -1 means invalid or not setup
|
||||
float _pwm_frequency;
|
||||
uint32_t _pwm_frequency;
|
||||
uint8_t _resolution_bits;
|
||||
uint32_t _current_value;
|
||||
};
|
||||
|
@@ -166,6 +166,7 @@
|
||||
<ClInclude Include="Grbl_Esp32\test\TestFactory.h" />
|
||||
<ClInclude Include="Grbl_Esp32\test\TestFramework.h" />
|
||||
<ClInclude Include="X86TestSupport\Arduino.h" />
|
||||
<ClInclude Include="X86TestSupport\Capture.h" />
|
||||
<ClInclude Include="X86TestSupport\driver\dac.h" />
|
||||
<ClInclude Include="X86TestSupport\driver\ledc.h" />
|
||||
<ClInclude Include="X86TestSupport\driver\rmt.h" />
|
||||
@@ -304,6 +305,7 @@
|
||||
<ClCompile Include="X86TestSupport\Arduino.cpp" />
|
||||
<ClCompile Include="X86TestSupport\ExceptionHelper.cpp" />
|
||||
<ClCompile Include="X86TestSupport\FS.cpp" />
|
||||
<ClCompile Include="X86TestSupport\nvs.cpp" />
|
||||
<ClCompile Include="X86TestSupport\Print.cpp" />
|
||||
<ClCompile Include="X86TestSupport\Stream.cpp" />
|
||||
<ClCompile Include="X86TestSupport\WString.cpp" />
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -42,3 +42,7 @@ extern "C" void __digitalWrite(uint8_t pin, uint8_t val) {
|
||||
void delay(int ms) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
|
||||
}
|
||||
|
||||
int temperatureRead(void) {
|
||||
return 22; // Nobody cares
|
||||
}
|
||||
|
44
X86TestSupport/Capture.h
Normal file
44
X86TestSupport/Capture.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
// Capture here defines everything that we want to know. Specifically, we want to capture per ID:
|
||||
// 1. Timings. *When* did something happen?
|
||||
// 2. Data. This can be a simple '1' or '0', or a character stream. For simplicity, we store a vector of integers.
|
||||
//
|
||||
// An ID itself is a string. This can be a pin ID (gpio.1), an uart (uart.0), an ledc, or whatever.
|
||||
|
||||
struct CaptureEvent {
|
||||
uint32_t time;
|
||||
std::string id;
|
||||
std::vector<uint32_t> data;
|
||||
};
|
||||
|
||||
class Capture {
|
||||
Capture() {}
|
||||
|
||||
std::vector<CaptureEvent> events;
|
||||
uint32_t currentTime;
|
||||
|
||||
public:
|
||||
static Capture& instance() {
|
||||
static Capture instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void reset() { events.clear(); }
|
||||
|
||||
void write(std::string id, uint32_t value) {
|
||||
CaptureEvent evt;
|
||||
evt.time = currentTime;
|
||||
evt.id = id;
|
||||
evt.data.reserve(1);
|
||||
evt.data.push_back(value);
|
||||
events.push_back(evt);
|
||||
}
|
||||
|
||||
void wait(uint32_t delay) { currentTime += delay; }
|
||||
void yield() { wait(1); }
|
||||
};
|
@@ -16,22 +16,9 @@ TODO: Two things need to be captured: (1) uart/pin/etc and (2) timings. All timi
|
||||
"int __cdecl i2s_out_set_pulse_callback(void (__cdecl*)(void))" (?i2s_out_set_pulse_callback@@YAHP6AXXZ@Z)
|
||||
"int __cdecl i2s_out_set_pulse_period(unsigned int)" (?i2s_out_set_pulse_period@@YAHI@Z)
|
||||
"int __cdecl i2s_out_set_stepping(void)" (?i2s_out_set_stepping@@YAHXZ)
|
||||
"int __cdecl nvs_erase_key(class NvsEmulator *,char const *)" (?nvs_erase_key@@YAHPAVNvsEmulator@@PBD@Z)
|
||||
"int __cdecl nvs_get_blob(class NvsEmulator *,char const *,void *,unsigned int *)" (?nvs_get_blob@@YAHPAVNvsEmulator@@PBDPAXPAI@Z)
|
||||
"int __cdecl nvs_get_i32(class NvsEmulator *,char const *,int *)" (?nvs_get_i32@@YAHPAVNvsEmulator@@PBDPAH@Z)
|
||||
"int __cdecl nvs_get_i8(class NvsEmulator *,char const *,signed char *)" (?nvs_get_i8@@YAHPAVNvsEmulator@@PBDPAC@Z)
|
||||
"int __cdecl nvs_get_str(class NvsEmulator *,char const *,char *,unsigned int *)" (?nvs_get_str@@YAHPAVNvsEmulator@@PBDPADPAI@Z)
|
||||
"int __cdecl nvs_open(char const *,enum nvs_open_mode,class NvsEmulator * *)" (?nvs_open@@YAHPBDW4nvs_open_mode@@PAPAVNvsEmulator@@@Z)
|
||||
"int __cdecl nvs_set_blob(class NvsEmulator *,char const *,void const *,unsigned int)" (?nvs_set_blob@@YAHPAVNvsEmulator@@PBDPBXI@Z)
|
||||
"int __cdecl nvs_set_i32(class NvsEmulator *,char const *,int)" (?nvs_set_i32@@YAHPAVNvsEmulator@@PBDH@Z)
|
||||
"int __cdecl nvs_set_i8(class NvsEmulator *,char const *,int)" (?nvs_set_i8@@YAHPAVNvsEmulator@@PBDH@Z)
|
||||
"int __cdecl nvs_set_str(class NvsEmulator *,char const *,char const *)" (?nvs_set_str@@YAHPAVNvsEmulator@@PBD1@Z)
|
||||
"int __cdecl rmt_config(struct rmt_config_t const *)" (?rmt_config@@YAHPBUrmt_config_t@@@Z)
|
||||
"int __cdecl rmt_fill_tx_items(enum rmt_channel_t,struct rmt_item32_s const *,unsigned short,unsigned short)" (?rmt_fill_tx_items@@YAHW4rmt_channel_t@@PBUrmt_item32_s@@GG@Z)
|
||||
"int __cdecl rmt_set_source_clk(enum rmt_channel_t,enum rmt_source_clk_t)" (?rmt_set_source_clk@@YAHW4rmt_channel_t@@W4rmt_source_clk_t@@@Z)
|
||||
"int __cdecl strcasecmp(char const *,char const *)" (?strcasecmp@@YAHPBD0@Z)
|
||||
"int __cdecl strncasecmp(char const *,char const *,unsigned int)" (?strncasecmp@@YAHPBD0I@Z)
|
||||
"int __cdecl temperatureRead(void)" (?temperatureRead@@YAHXZ)
|
||||
"int __cdecl uart_driver_install(enum uart_port_t,int,int,int,void * *,int)" (?uart_driver_install@@YAHW4uart_port_t@@HHHPAPAXH@Z)
|
||||
"int __cdecl uart_flush(enum uart_port_t)" (?uart_flush@@YAHW4uart_port_t@@@Z)
|
||||
"int __cdecl uart_get_buffered_data_len(enum uart_port_t,unsigned int *)" (?uart_get_buffered_data_len@@YAHW4uart_port_t@@PAI@Z)
|
||||
|
@@ -3,12 +3,12 @@
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
#pragma warning(disable : 4996) // itoa
|
||||
#pragma warning(disable : 4996) // itoa
|
||||
|
||||
std::string String::ValueToString(int value, int base) {
|
||||
char buffer[100] = { 0 };
|
||||
int number_base = 10;
|
||||
std::string output = itoa(value, buffer, base);
|
||||
std::string output = itoa(value, buffer, base);
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -19,62 +19,78 @@ std::string String::DecToString(double value, int decimalPlaces) {
|
||||
return s;
|
||||
}
|
||||
|
||||
StringAppender& operator +(const StringAppender& lhs, const String& rhs) {
|
||||
StringAppender& operator+(const StringAppender& lhs, const String& rhs) {
|
||||
StringAppender& a = const_cast<StringAppender&>(lhs);
|
||||
a.concat(rhs);
|
||||
return a;
|
||||
}
|
||||
|
||||
StringAppender& operator +(const StringAppender& lhs, const char* cstr) {
|
||||
StringAppender& operator+(const StringAppender& lhs, const char* cstr) {
|
||||
StringAppender& a = const_cast<StringAppender&>(lhs);
|
||||
a.concat(cstr);
|
||||
return a;
|
||||
}
|
||||
|
||||
StringAppender& operator +(const StringAppender& lhs, char c) {
|
||||
StringAppender& operator+(const StringAppender& lhs, char c) {
|
||||
StringAppender& a = const_cast<StringAppender&>(lhs);
|
||||
a.concat(c);
|
||||
return a;
|
||||
}
|
||||
|
||||
StringAppender& operator +(const StringAppender& lhs, unsigned char num) {
|
||||
StringAppender& operator+(const StringAppender& lhs, unsigned char num) {
|
||||
StringAppender& a = const_cast<StringAppender&>(lhs);
|
||||
a.concat(num);
|
||||
return a;
|
||||
}
|
||||
|
||||
StringAppender& operator +(const StringAppender& lhs, int num) {
|
||||
StringAppender& operator+(const StringAppender& lhs, int num) {
|
||||
StringAppender& a = const_cast<StringAppender&>(lhs);
|
||||
a.concat(num);
|
||||
return a;
|
||||
}
|
||||
|
||||
StringAppender& operator +(const StringAppender& lhs, unsigned int num) {
|
||||
StringAppender& operator+(const StringAppender& lhs, unsigned int num) {
|
||||
StringAppender& a = const_cast<StringAppender&>(lhs);
|
||||
a.concat(num);
|
||||
return a;
|
||||
}
|
||||
|
||||
StringAppender& operator +(const StringAppender& lhs, long num) {
|
||||
StringAppender& operator+(const StringAppender& lhs, long num) {
|
||||
StringAppender& a = const_cast<StringAppender&>(lhs);
|
||||
a.concat(num);
|
||||
return a;
|
||||
}
|
||||
|
||||
StringAppender& operator +(const StringAppender& lhs, unsigned long num) {
|
||||
StringAppender& operator+(const StringAppender& lhs, unsigned long num) {
|
||||
StringAppender& a = const_cast<StringAppender&>(lhs);
|
||||
a.concat(num);
|
||||
return a;
|
||||
}
|
||||
|
||||
StringAppender& operator +(const StringAppender& lhs, float num) {
|
||||
StringAppender& operator+(const StringAppender& lhs, float num) {
|
||||
StringAppender& a = const_cast<StringAppender&>(lhs);
|
||||
a.concat(num);
|
||||
return a;
|
||||
}
|
||||
|
||||
StringAppender& operator +(const StringAppender& lhs, double num) {
|
||||
StringAppender& operator+(const StringAppender& lhs, double num) {
|
||||
StringAppender& a = const_cast<StringAppender&>(lhs);
|
||||
a.concat(num);
|
||||
return a;
|
||||
}
|
||||
|
||||
int strcasecmp(const char* lhs, const char* rhs) {
|
||||
while (*lhs && *rhs && tolower(*lhs) == tolower(*rhs)) {
|
||||
++lhs;
|
||||
++rhs;
|
||||
}
|
||||
return (*lhs) == '\0' && (*rhs) == '\0';
|
||||
}
|
||||
int strncasecmp(const char* lhs, const char* rhs, size_t count) {
|
||||
while (*lhs && *rhs && tolower(*lhs) == tolower(*rhs) && count > 0) {
|
||||
++lhs;
|
||||
++rhs;
|
||||
--count;
|
||||
}
|
||||
return count == 0 || ((*lhs) == '\0' && (*rhs) == '\0');
|
||||
}
|
||||
|
64
X86TestSupport/nvs.cpp
Normal file
64
X86TestSupport/nvs.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#include "nvs.h"
|
||||
|
||||
esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_handle* out_handle) {
|
||||
*out_handle = &(NvsEmulator::instance());
|
||||
return ESP_OK;
|
||||
}
|
||||
esp_err_t nvs_get_i32(nvs_handle handle, const char* key, int32_t* out_value) {
|
||||
if (handle->tryGetI32(key, *out_value)) {
|
||||
return ESP_OK;
|
||||
} else {
|
||||
return ESP_ERR_NVS_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
esp_err_t nvs_get_i8(nvs_handle handle, const char* key, int8_t* out_value) {
|
||||
if (handle->tryGetI8(key, *out_value)) {
|
||||
return ESP_OK;
|
||||
} else {
|
||||
return ESP_ERR_NVS_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
esp_err_t nvs_get_str(nvs_handle handle, const char* key, char* out_value, size_t* length) {
|
||||
if (handle->tryGetStr(key, out_value, *length)) {
|
||||
return ESP_OK;
|
||||
} else {
|
||||
return ESP_ERR_NVS_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
esp_err_t nvs_get_blob(nvs_handle handle, const char* key, void* out_value, size_t* length) {
|
||||
if (handle->tryGetBlob(key, out_value, *length)) {
|
||||
return ESP_OK;
|
||||
} else {
|
||||
return ESP_ERR_NVS_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
esp_err_t nvs_erase_key(nvs_handle handle, const char* key) {
|
||||
handle->erase(key);
|
||||
return ESP_OK;
|
||||
}
|
||||
esp_err_t nvs_erase_all(nvs_handle handle) {
|
||||
handle->clear();
|
||||
return ESP_OK;
|
||||
}
|
||||
esp_err_t nvs_set_i8(nvs_handle handle, const char* key, int8_t value) {
|
||||
char* v = reinterpret_cast<char*>(&value);
|
||||
std::string data(v, v + 1);
|
||||
handle->set(key, data);
|
||||
return ESP_OK;
|
||||
}
|
||||
esp_err_t nvs_set_i32(nvs_handle handle, const char* key, int32_t value) {
|
||||
char* v = reinterpret_cast<char*>(&value);
|
||||
std::string data(v, v + 4);
|
||||
handle->set(key, data);
|
||||
return ESP_OK;
|
||||
}
|
||||
esp_err_t nvs_set_str(nvs_handle handle, const char* key, const char* value) {
|
||||
handle->set(key, value);
|
||||
return ESP_OK;
|
||||
}
|
||||
esp_err_t nvs_set_blob(nvs_handle handle, const char* key, const void* value, size_t length) {
|
||||
auto c = static_cast<const char*>(value);
|
||||
std::string data(c, c + length);
|
||||
handle->set(key, data);
|
||||
return ESP_OK;
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include "esp_err.h"
|
||||
|
||||
class NvsEmulator {
|
||||
// NVS is basically a key-value store.
|
||||
@@ -28,10 +29,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool tryGetStr(const char* str, char* buf, int32_t& len) {
|
||||
bool tryGetStr(const char* str, char* buf, size_t& len) {
|
||||
auto it = data.find(str);
|
||||
if (it != data.end()) {
|
||||
auto v = int32_t(it->second.size());
|
||||
auto v = it->second.size();
|
||||
if (buf) {
|
||||
if (v > len) {
|
||||
v = len;
|
||||
@@ -47,10 +48,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool tryGetBlob(const char* str, char* buf, int32_t& len) {
|
||||
bool tryGetBlob(const char* str, void* buf, size_t& len) {
|
||||
auto it = data.find(str);
|
||||
if (it != data.end()) {
|
||||
auto v = int32_t(it->second.size());
|
||||
auto v = it->second.size();
|
||||
if (buf) {
|
||||
if (v > len) {
|
||||
v = len;
|
||||
@@ -66,6 +67,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void set(const char* str, std::string value) { data[str] = value; }
|
||||
|
||||
void erase(const char* str) {
|
||||
auto it = data.find(str);
|
||||
if (it != data.end()) {
|
||||
@@ -97,10 +100,7 @@ inline esp_err_t nvs_get_stats(const char* part_name, nvs_stats_t* stats) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
inline esp_err_t nvs_erase_all(nvs_handle handle) {
|
||||
handle->clear();
|
||||
return ESP_OK;
|
||||
}
|
||||
esp_err_t nvs_erase_all(nvs_handle handle);
|
||||
|
||||
enum nvs_open_mode { NVS_READWRITE };
|
||||
|
||||
@@ -157,7 +157,7 @@ esp_err_t nvs_get_blob(nvs_handle handle, const char* key, void* out_value, size
|
||||
esp_err_t nvs_erase_key(nvs_handle handle, const char* key);
|
||||
esp_err_t nvs_erase_all(nvs_handle handle);
|
||||
|
||||
esp_err_t nvs_set_i8(nvs_handle handle, const char* key, int32_t value);
|
||||
esp_err_t nvs_set_i8(nvs_handle handle, const char* key, int8_t value);
|
||||
esp_err_t nvs_set_i32(nvs_handle handle, const char* key, int32_t value);
|
||||
esp_err_t nvs_set_str(nvs_handle handle, const char* key, const char* value);
|
||||
esp_err_t nvs_set_blob(nvs_handle handle, const char* key, const void* value, size_t length);
|
||||
|
@@ -17,6 +17,7 @@ PATHS_TO_SEARCH = ['Grbl_Esp32']
|
||||
HEADER_EXT = ['.h', '.inl']
|
||||
SOURCE_EXT = ['.c', '.cpp']
|
||||
OTHER_EXT = ['.ino', '.md']
|
||||
TEST_IGNORE = ['I2SOut.cpp','I2SOut.h']
|
||||
|
||||
import os, uuid
|
||||
|
||||
@@ -276,5 +277,15 @@ def main(paths):
|
||||
for path in paths:
|
||||
generator.Walk(path)
|
||||
generator.Generate()
|
||||
|
||||
def tests(paths):
|
||||
generator = Generator()
|
||||
generator.Name = "UnitTests"
|
||||
OTHER_EXT = ['.md']
|
||||
newpaths = ['Grbl_Esp32', 'X86TestSupport']
|
||||
for path in newpaths:
|
||||
generator.Walk(path)
|
||||
generator.Generate()
|
||||
|
||||
main(PATHS_TO_SEARCH)
|
||||
|
||||
|
Reference in New Issue
Block a user