lua pwm hooks (#2687)
* pwm hook * dedicated pins * write hook * UI * more info * zero based, clamp * memory * don't compile lua in bootloader at all
This commit is contained in:
parent
6c88bafcf4
commit
5cb659a7b0
|
@ -176,6 +176,7 @@ endif
|
||||||
include $(PROJECT_DIR)/config/engines/engines.mk
|
include $(PROJECT_DIR)/config/engines/engines.mk
|
||||||
include $(PROJECT_DIR)/console/console.mk
|
include $(PROJECT_DIR)/console/console.mk
|
||||||
include $(PROJECT_DIR)/controllers/controllers.mk
|
include $(PROJECT_DIR)/controllers/controllers.mk
|
||||||
|
include $(PROJECT_DIR)/controllers/lua/lua.mk
|
||||||
include $(PROJECT_DIR)/development/development.mk
|
include $(PROJECT_DIR)/development/development.mk
|
||||||
include $(PROJECT_DIR)/hw_layer/hw_layer.mk
|
include $(PROJECT_DIR)/hw_layer/hw_layer.mk
|
||||||
include $(PROJECT_DIR)/hw_layer/drivers/drivers.mk
|
include $(PROJECT_DIR)/hw_layer/drivers/drivers.mk
|
||||||
|
|
|
@ -4,7 +4,6 @@ include $(PROJECT_DIR)/controllers/math/math.mk
|
||||||
include $(PROJECT_DIR)/controllers/trigger/trigger.mk
|
include $(PROJECT_DIR)/controllers/trigger/trigger.mk
|
||||||
include $(PROJECT_DIR)/controllers/sensors/sensors.mk
|
include $(PROJECT_DIR)/controllers/sensors/sensors.mk
|
||||||
include $(PROJECT_DIR)/controllers/system/system.mk
|
include $(PROJECT_DIR)/controllers/system/system.mk
|
||||||
include $(PROJECT_DIR)/controllers/lua/lua.mk
|
|
||||||
#include $(PROJECT_DIR)/controllers/gauges/gauges.mk
|
#include $(PROJECT_DIR)/controllers/gauges/gauges.mk
|
||||||
|
|
||||||
CONTROLLERS_DIR=$(PROJECT_DIR)/controllers
|
CONTROLLERS_DIR=$(PROJECT_DIR)/controllers
|
||||||
|
|
|
@ -702,7 +702,7 @@ void initEngineContoller(DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
* UNUSED_SIZE constants.
|
* UNUSED_SIZE constants.
|
||||||
*/
|
*/
|
||||||
#ifndef RAM_UNUSED_SIZE
|
#ifndef RAM_UNUSED_SIZE
|
||||||
#define RAM_UNUSED_SIZE 1800
|
#define RAM_UNUSED_SIZE 1500
|
||||||
#endif
|
#endif
|
||||||
#ifndef CCM_UNUSED_SIZE
|
#ifndef CCM_UNUSED_SIZE
|
||||||
#define CCM_UNUSED_SIZE 300
|
#define CCM_UNUSED_SIZE 300
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "adc_inputs.h"
|
#include "adc_inputs.h"
|
||||||
#include "efilib.h"
|
#include "efilib.h"
|
||||||
#include "tunerstudio_outputs.h"
|
#include "tunerstudio_outputs.h"
|
||||||
|
#include "pwm_generator_logic.h"
|
||||||
|
|
||||||
// Some functions lean on existing FSIO implementation
|
// Some functions lean on existing FSIO implementation
|
||||||
#include "fsio_impl.h"
|
#include "fsio_impl.h"
|
||||||
|
@ -64,6 +65,66 @@ static int lua_table3d(lua_State* l) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !EFI_UNIT_TEST
|
#if !EFI_UNIT_TEST
|
||||||
|
static SimplePwm pwms[LUA_PWM_COUNT];
|
||||||
|
static OutputPin pins[LUA_PWM_COUNT];
|
||||||
|
|
||||||
|
struct P {
|
||||||
|
SimplePwm& pwm;
|
||||||
|
lua_Integer idx;
|
||||||
|
};
|
||||||
|
|
||||||
|
static P luaL_checkPwmIndex(lua_State* l, int pos) {
|
||||||
|
auto channel = luaL_checkinteger(l, pos);
|
||||||
|
|
||||||
|
// Ensure channel is valid
|
||||||
|
if (channel < 0 || channel >= FSIO_COMMAND_COUNT) {
|
||||||
|
luaL_error(l, "setPwmDuty invalid channel %d", channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { pwms[channel], channel };
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lua_startPwm(lua_State* l) {
|
||||||
|
auto p = luaL_checkPwmIndex(l, 1);
|
||||||
|
auto freq = luaL_checknumber(l, 2);
|
||||||
|
auto duty = luaL_checknumber(l, 2);
|
||||||
|
|
||||||
|
// clamp to 1..1000 hz
|
||||||
|
freq = clampF(1, freq, 1000);
|
||||||
|
|
||||||
|
startSimplePwmExt(
|
||||||
|
&p.pwm, "lua", &engine->executor,
|
||||||
|
CONFIG(luaOutputPins[p.idx]), &pins[p.idx],
|
||||||
|
freq, duty
|
||||||
|
);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lua_setPwmDuty(lua_State* l) {
|
||||||
|
auto p = luaL_checkPwmIndex(l, 1);
|
||||||
|
auto duty = luaL_checknumber(l, 2);
|
||||||
|
|
||||||
|
// clamp to 0..1
|
||||||
|
duty = clampF(0, duty, 1);
|
||||||
|
|
||||||
|
p.pwm.setSimplePwmDutyCycle(duty);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lua_setPwmFreq(lua_State* l) {
|
||||||
|
auto p = luaL_checkPwmIndex(l, 1);
|
||||||
|
auto freq = luaL_checknumber(l, 2);
|
||||||
|
|
||||||
|
// clamp to 1..1000 hz
|
||||||
|
freq = clampF(1, freq, 1000);
|
||||||
|
|
||||||
|
p.pwm.setFrequency(freq);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int lua_fan(lua_State* l) {
|
static int lua_fan(lua_State* l) {
|
||||||
lua_pushboolean(l, enginePins.fanRelay.getLogicValue());
|
lua_pushboolean(l, enginePins.fanRelay.getLogicValue());
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -118,6 +179,10 @@ void configureRusefiLuaHooks(lua_State* l) {
|
||||||
lua_register(l, "table3d", lua_table3d);
|
lua_register(l, "table3d", lua_table3d);
|
||||||
|
|
||||||
#if !EFI_UNIT_TEST
|
#if !EFI_UNIT_TEST
|
||||||
|
lua_register(l, "startPwm", lua_startPwm);
|
||||||
|
lua_register(l, "setPwmDuty", lua_setPwmDuty);
|
||||||
|
lua_register(l, "setPwmFreq", lua_setPwmFreq);
|
||||||
|
|
||||||
lua_register(l, "getFan", lua_fan);
|
lua_register(l, "getFan", lua_fan);
|
||||||
lua_register(l, "getDigital", lua_getDigital);
|
lua_register(l, "getDigital", lua_getDigital);
|
||||||
lua_register(l, "setDebug", lua_setDebug);
|
lua_register(l, "setDebug", lua_setDebug);
|
||||||
|
|
|
@ -77,6 +77,8 @@ struct_no_prefix engine_configuration_s
|
||||||
|
|
||||||
#define FSIO_ANALOG_INPUT_COUNT 4
|
#define FSIO_ANALOG_INPUT_COUNT 4
|
||||||
|
|
||||||
|
#define LUA_PWM_COUNT 8
|
||||||
|
|
||||||
! V engines or flat engines would have pairs of shafts with same trigger shape and target position
|
! V engines or flat engines would have pairs of shafts with same trigger shape and target position
|
||||||
#define BANKS_COUNT 2
|
#define BANKS_COUNT 2
|
||||||
#define CAMS_PER_BANK 2
|
#define CAMS_PER_BANK 2
|
||||||
|
@ -1045,7 +1047,9 @@ custom maf_sensor_type_e 4 bits, S32, @OFFSET@, [0:1], @@maf_sensor_type_e_enum@
|
||||||
|
|
||||||
uint16_t[FUEL_LEVEL_TABLE_COUNT] fuelLevelBins;;"volt", {1/@@PACK_MULT_VOLTAGE@@}, 0, 0, 5, 3
|
uint16_t[FUEL_LEVEL_TABLE_COUNT] fuelLevelBins;;"volt", {1/@@PACK_MULT_VOLTAGE@@}, 0, 0, 5, 3
|
||||||
|
|
||||||
int[59] unusedAtOldBoardConfigurationEnd;;"units", 1, 0, -20, 100, 0
|
output_pin_e[LUA_PWM_COUNT iterate] luaOutputPins
|
||||||
|
|
||||||
|
int[57] unusedAtOldBoardConfigurationEnd;;"units", 1, 0, -20, 100, 0
|
||||||
uint16_t vehicleWeight;;"kg", 1, 0, 0, 10000, 0
|
uint16_t vehicleWeight;;"kg", 1, 0, 0, 10000, 0
|
||||||
brain_pin_e lps25BaroSensorScl
|
brain_pin_e lps25BaroSensorScl
|
||||||
brain_pin_e lps25BaroSensorSda
|
brain_pin_e lps25BaroSensorSda
|
||||||
|
|
|
@ -1505,6 +1505,9 @@ menuDialog = main
|
||||||
subMenu = fsioCurve3, "FSIO Curve #3"
|
subMenu = fsioCurve3, "FSIO Curve #3"
|
||||||
subMenu = fsioCurve4, "FSIO Curve #4"
|
subMenu = fsioCurve4, "FSIO Curve #4"
|
||||||
|
|
||||||
|
subMenu = std_separator
|
||||||
|
subMenu = luaOutputs, "Lua PWM Outputs"
|
||||||
|
|
||||||
subMenu = std_separator
|
subMenu = std_separator
|
||||||
subMenu = tcuControls, "Transmission Settings"
|
subMenu = tcuControls, "Transmission Settings"
|
||||||
subMenu = tcuSolenoidTableTbl, "TCU Solenoids"
|
subMenu = tcuSolenoidTableTbl, "TCU Solenoids"
|
||||||
|
@ -3201,6 +3204,19 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
|
||||||
field = "ADC #3", fsioAdc3
|
field = "ADC #3", fsioAdc3
|
||||||
field = "ADC #4", fsioAdc4
|
field = "ADC #4", fsioAdc4
|
||||||
|
|
||||||
|
dialog = luaOutputs, "Lua Outputs"
|
||||||
|
field = "#Call startPwm to initialize, then call"
|
||||||
|
field = "#setPwmDuty and setPwmFreq to vary duty/freq"
|
||||||
|
field = "#See rusefi.com/s/lua for more info"
|
||||||
|
field = "output #0", luaOutputPins1
|
||||||
|
field = "output #1", luaOutputPins2
|
||||||
|
field = "output #2", luaOutputPins3
|
||||||
|
field = "output #3", luaOutputPins4
|
||||||
|
field = "output #4", luaOutputPins5
|
||||||
|
field = "output #5", luaOutputPins6
|
||||||
|
field = "output #6", luaOutputPins7
|
||||||
|
field = "output #7", luaOutputPins8
|
||||||
|
|
||||||
dialog = transmissionPanel
|
dialog = transmissionPanel
|
||||||
field = "TCU Enabled" tcuEnabled
|
field = "TCU Enabled" tcuEnabled
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta http-equiv="refresh" content="0; url=https://github.com/rusefi/rusefi/wiki/Lua-Scripting" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<center>
|
||||||
|
|
||||||
|
<br><br><br><br><br>
|
||||||
|
|
||||||
|
<a href="https://github.com/rusefi/rusefi/wiki/Lua-Scripting">https://github.com/rusefi/rusefi/wiki/Lua-Scripting</a>
|
||||||
|
|
||||||
|
</center>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -138,6 +138,7 @@ include $(PROJECT_DIR)/console/binary/tunerstudio.mk
|
||||||
include $(PROJECT_DIR)/console/console.mk
|
include $(PROJECT_DIR)/console/console.mk
|
||||||
include $(PROJECT_DIR)/config/engines/engines.mk
|
include $(PROJECT_DIR)/config/engines/engines.mk
|
||||||
include $(PROJECT_DIR)/controllers/controllers.mk
|
include $(PROJECT_DIR)/controllers/controllers.mk
|
||||||
|
include $(PROJECT_DIR)/controllers/lua/lua.mk
|
||||||
include $(PROJECT_DIR)/development/development.mk
|
include $(PROJECT_DIR)/development/development.mk
|
||||||
include $(PROJECT_DIR)/hw_layer/hw_layer.mk
|
include $(PROJECT_DIR)/hw_layer/hw_layer.mk
|
||||||
include $(PROJECT_DIR)/hw_layer/drivers/drivers.mk
|
include $(PROJECT_DIR)/hw_layer/drivers/drivers.mk
|
||||||
|
|
|
@ -9,6 +9,7 @@ UNIT_TESTS_DIR=$(PROJECT_DIR)/../unit_tests
|
||||||
# Imported source files and paths
|
# Imported source files and paths
|
||||||
include $(PROJECT_DIR)/config/engines/engines.mk
|
include $(PROJECT_DIR)/config/engines/engines.mk
|
||||||
include $(PROJECT_DIR)/controllers/controllers.mk
|
include $(PROJECT_DIR)/controllers/controllers.mk
|
||||||
|
include $(PROJECT_DIR)/controllers/lua/lua.mk
|
||||||
include $(PROJECT_DIR)/development/development.mk
|
include $(PROJECT_DIR)/development/development.mk
|
||||||
include $(PROJECT_DIR)/console/console.mk
|
include $(PROJECT_DIR)/console/console.mk
|
||||||
include $(PROJECT_DIR)/console/binary/tunerstudio.mk
|
include $(PROJECT_DIR)/console/binary/tunerstudio.mk
|
||||||
|
|
Loading…
Reference in New Issue