mirror of
https://github.com/elua/elua.git
synced 2025-01-25 01:02:54 +08:00
Merge branch 'stm32f4_enc'
- includes docs for enc module for stm32 and stm32f4 - migrates platform specific enc module from stm32 to stm32f4 - enables enc module on stm32f4 boards - adds adjustment to modules build system to still include platform specific modules if some have guards and others do not when a guard fails
This commit is contained in:
commit
4df361ffbb
@ -8,6 +8,7 @@ return {
|
||||
advanced_shell = true,
|
||||
term = { lines = 25, cols = 80 },
|
||||
linenoise = { shell_lines = 10, lua_lines = 50 },
|
||||
stm32f4_enc = true,
|
||||
rpc = { uart = 2, speed = 115200 },
|
||||
adc = { buf_size = 2 },
|
||||
xmodem = true,
|
||||
|
@ -8,6 +8,7 @@ return {
|
||||
advanced_shell = true,
|
||||
term = { lines = 25, cols = 80 },
|
||||
linenoise = { shell_lines = 10, lua_lines = 50 },
|
||||
stm32f4_enc = true,
|
||||
rpc = { uart = 2, speed = 115200 },
|
||||
adc = { buf_size = 2 },
|
||||
xmodem = true,
|
||||
|
@ -8,6 +8,7 @@ return {
|
||||
advanced_shell = true,
|
||||
term = { lines = 25, cols = 80 },
|
||||
linenoise = { shell_lines = 10, lua_lines = 50 },
|
||||
stm32f4_enc = true,
|
||||
rpc = { uart = 0, speed = 115200 },
|
||||
adc = { buf_size = 2 },
|
||||
xmodem = true,
|
||||
|
@ -9,6 +9,7 @@ return {
|
||||
advanced_shell = true,
|
||||
term = { lines = 25, cols = 80 },
|
||||
linenoise = { shell_lines = 10, lua_lines = 50 },
|
||||
stm32f4_enc = true,
|
||||
rpc = { uart = 0, speed = 115200 },
|
||||
adc = { buf_size = 2 },
|
||||
xmodem = true,
|
||||
|
@ -195,10 +195,13 @@ function gen_module_list( desc, plconf, platform, boardname )
|
||||
-- platform module if _any_ of the modules in gen_list_platform can be enabled.
|
||||
-- In order to do this, we gather their guards in a single, long condition
|
||||
-- Count all guards first
|
||||
local nguards = 0
|
||||
local nguards, nmodules = 0, 0
|
||||
local pltabname = mdesc.platform_name or platform
|
||||
for m, _ in pairs( gen_list_platform ) do nguards = nguards + #( platform_modules[ m ].guards or {} ) end
|
||||
if nguards == 0 then -- nothing to guard
|
||||
for m, _ in pairs( gen_list_platform ) do
|
||||
nmodules = nmodules + 1
|
||||
nguards = nguards + #( platform_modules[ m ].guards or {} )
|
||||
end
|
||||
if nguards == 0 or nguards < nmodules then -- nothing to guard or not all have guards
|
||||
gstr = gstr .. gen.print_define( "PLATFORM_MODULES_LINE", sf( '_ROM( "%s", luaopen_platform, platform_map )', pltabname ) )
|
||||
gstr = gstr .. gen.print_define( "PS_LIB_TABLE_NAME", sf( '"%s"', pltabname ) )
|
||||
gstr = gstr .. gen.print_define( "PLATFORM_MODULES_ENABLE" )
|
||||
|
@ -245,6 +245,8 @@ local menu =
|
||||
{
|
||||
{ "lm3s", "modules_lm3s.html", "refman_ps_lm3s" },
|
||||
{ "str9", "modules_str9.html", "refman_ps_str9" },
|
||||
{ "stm32", "modules_stm32.html", "refman_ps_stm32" },
|
||||
{ "stm32f4", "modules_stm32f4.html", "refman_ps_stm32f4" },
|
||||
{ "mbed", "modules_mbed.html", "refman_ps_mbed" },
|
||||
{ "mizar32", "modules_mizar32.html", "refman_ps_mizar32" },
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ local sf = string.format
|
||||
-- Data structure declarations
|
||||
|
||||
-- List here all the sections for which we're generating the documentation
|
||||
local doc_sections = { "arch_platform", "refman_gen", "refman_ps_lm3s", "refman_ps_str9", "refman_ps_mbed", "refman_ps_mizar32" }
|
||||
local doc_sections = { "arch_platform", "refman_gen", "refman_ps_lm3s", "refman_ps_str9", "refman_ps_stm32", "refman_ps_stm32f4", "refman_ps_mbed", "refman_ps_mizar32" }
|
||||
|
||||
-- List here all the components of each section
|
||||
local components =
|
||||
@ -19,6 +19,8 @@ local components =
|
||||
refman_ps_lm3s = { "disp" },
|
||||
refman_ps_str9 = { "pio" },
|
||||
refman_ps_mbed = { "pio" },
|
||||
refman_ps_stm32 = { "enc" },
|
||||
refman_ps_stm32f4 = { "enc" },
|
||||
refman_ps_mizar32 = { "lcd", "rtc" },
|
||||
}
|
||||
|
||||
|
47
doc/eluadoc/refman_ps_stm32_enc.lua
Normal file
47
doc/eluadoc/refman_ps_stm32_enc.lua
Normal file
@ -0,0 +1,47 @@
|
||||
-- eLua reference manual - platform data
|
||||
|
||||
data_en =
|
||||
{
|
||||
|
||||
-- Title
|
||||
title = "eLua reference manual - STM32 enc module",
|
||||
|
||||
-- Menu name
|
||||
menu_name = "enc",
|
||||
|
||||
-- Overview
|
||||
overview = [[This module contains functions to set up and use timers in quadrature encoder mode.]],
|
||||
|
||||
-- Functions
|
||||
funcs =
|
||||
{
|
||||
{ sig = "#stm32.enc.init#( id )",
|
||||
desc = "Configure the timer in quadrature mode.",
|
||||
args =
|
||||
{
|
||||
"$id$ - the timer ID"
|
||||
}
|
||||
},
|
||||
{ sig = "#stm32.enc.setcounter#( id, count )",
|
||||
desc = "Set the current count on a timer.",
|
||||
args =
|
||||
{
|
||||
"$id$ - the timer ID",
|
||||
"$count$ - value to set counter to"
|
||||
}
|
||||
},
|
||||
{ sig = "#stm32.enc.setidxtrig#( id, resnum, tmr_id, count )",
|
||||
desc = "Set up a trigger to set the counter to a specific value when an interrupt is triggered",
|
||||
args =
|
||||
{
|
||||
"$id$ - the interrupt ID",
|
||||
"$resnum$ - resource ID associated with interrupt",
|
||||
"$tmr_id$ - the timer ID",
|
||||
"$count$ - value to set counter to when triggered"
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
data_pt = data_en
|
47
doc/eluadoc/refman_ps_stm32f4_enc.lua
Normal file
47
doc/eluadoc/refman_ps_stm32f4_enc.lua
Normal file
@ -0,0 +1,47 @@
|
||||
-- eLua reference manual - platform data
|
||||
|
||||
data_en =
|
||||
{
|
||||
|
||||
-- Title
|
||||
title = "eLua reference manual - STM32F4 enc module",
|
||||
|
||||
-- Menu name
|
||||
menu_name = "enc",
|
||||
|
||||
-- Overview
|
||||
overview = [[This module contains functions to set up and use timers in quadrature encoder mode.]],
|
||||
|
||||
-- Functions
|
||||
funcs =
|
||||
{
|
||||
{ sig = "#stm32f4.enc.init#( id )",
|
||||
desc = "Configure the timer in quadrature mode.",
|
||||
args =
|
||||
{
|
||||
"$id$ - the timer ID"
|
||||
}
|
||||
},
|
||||
{ sig = "#stm32f4.enc.setcounter#( id, count )",
|
||||
desc = "Set the current count on a timer.",
|
||||
args =
|
||||
{
|
||||
"$id$ - the timer ID",
|
||||
"$count$ - value to set counter to"
|
||||
}
|
||||
},
|
||||
{ sig = "#stm32f4.enc.setidxtrig#( id, resnum, tmr_id, count )",
|
||||
desc = "Set up a trigger to set the counter to a specific value when an interrupt is triggered",
|
||||
args =
|
||||
{
|
||||
"$id$ - the interrupt ID",
|
||||
"$resnum$ - resource ID associated with interrupt",
|
||||
"$tmr_id$ - the timer ID",
|
||||
"$count$ - value to set counter to when triggered"
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
data_pt = data_en
|
@ -194,6 +194,13 @@ Besides the generic components in the table above, each platform can specify its
|
||||
|stm32_enc |None (true or false) |Enable support for the STM32 timer encoder module
|
||||
|===================================================================
|
||||
|
||||
.STM32F4 specific components
|
||||
[width="99%", cols="<3,<5,<10", options="header"]
|
||||
|===================================================================
|
||||
^|Key ^|Parameters ^|Meaning
|
||||
|stm32f4_enc |None (true or false) |Enable support for the STM32F4 timer encoder module
|
||||
|===================================================================
|
||||
|
||||
.LPC17xx specific components
|
||||
[width="99%", cols="<3,<5,<10", options="header"]
|
||||
|===================================================================
|
||||
|
7
doc/en/modules_stm32.txt
Normal file
7
doc/en/modules_stm32.txt
Normal file
@ -0,0 +1,7 @@
|
||||
// $$HEADER$$
|
||||
Reference manual - STM32 platform dependent modules
|
||||
--------------------------------------------------
|
||||
|
||||
This paragraph presents all the modules specific to the link:status.html[stm32] (stm32) platform.
|
||||
|
||||
// $$FOOTER$$
|
7
doc/en/modules_stm32f4.txt
Normal file
7
doc/en/modules_stm32f4.txt
Normal file
@ -0,0 +1,7 @@
|
||||
// $$HEADER$$
|
||||
Reference manual - STM32F4 platform dependent modules
|
||||
-----------------------------------------------------
|
||||
|
||||
This paragraph presents all the modules specific to the link:status.html[stm32f4] (stm32f4) platform.
|
||||
|
||||
// $$FOOTER$$
|
@ -8,6 +8,7 @@ local comps = require "components"
|
||||
-- Add specific components to the 'components' table
|
||||
function add_platform_components( t, board, cpu )
|
||||
t.cdc = comps.cdc_uart()
|
||||
t.stm32f4_enc = { macro = 'ENABLE_ENC' }
|
||||
end
|
||||
|
||||
-- Add specific configuration to the 'configs' table
|
||||
@ -26,6 +27,7 @@ end
|
||||
-- Return an array of all the available platform modules for the given cpu
|
||||
function get_platform_modules( board, cpu )
|
||||
return { pio = { lib = '"pio"', map = "stm32_pio_map", open = false },
|
||||
cpu = { lib = '"cpu"', map = "stm32_cpu_map", open = "luaopen_stm32_cpu" } }
|
||||
cpu = { lib = '"cpu"', map = "stm32_cpu_map", open = "luaopen_stm32_cpu" },
|
||||
enc = { guards = { 'ENABLE_ENC' }, lib = '"enc"' } }
|
||||
end
|
||||
|
||||
|
@ -9,7 +9,7 @@ addi( sf( 'src/platform/%s/FWLib/USB/VCP/inc', platform ) )
|
||||
|
||||
local fwlib_files = utils.get_files( "src/platform/" .. platform .. "/FWLib/library/src", ".*%.c$" )
|
||||
fwlib_files = fwlib_files .. " " .. utils.get_files( "src/platform/" .. platform .. "/FWLib/USB/", "%.c$" )
|
||||
specific_files = "system_stm32f4xx.c startup_stm32f4xx.s stm32f4xx_it.c platform.c platform_int.c cpu.c stm32_pio.c"
|
||||
specific_files = "system_stm32f4xx.c startup_stm32f4xx.s stm32f4xx_it.c platform.c platform_int.c cpu.c stm32_pio.c enc.c"
|
||||
local ldscript = "stm32.ld"
|
||||
|
||||
-- Prepend with path
|
||||
|
90
src/platform/stm32f4/enc.c
Normal file
90
src/platform/stm32f4/enc.c
Normal file
@ -0,0 +1,90 @@
|
||||
// eLua Module for STM32 timer encoder mode support
|
||||
// enc is a platform-dependent (STM32) module, that binds to Lua the basic API
|
||||
// from ST
|
||||
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
#include "platform.h"
|
||||
#include "lrotable.h"
|
||||
#include "platform_conf.h"
|
||||
#include "auxmods.h"
|
||||
#include "elua_int.h"
|
||||
#include "enc.h"
|
||||
|
||||
static elua_int_c_handler prev_handler;
|
||||
static elua_int_resnum index_resnum;
|
||||
static int index_tmr_id;
|
||||
static u16 index_count;
|
||||
static void index_handler( elua_int_resnum resnum );
|
||||
|
||||
//Lua: init(id)
|
||||
static int enc_init( lua_State *L )
|
||||
{
|
||||
unsigned id;
|
||||
|
||||
id = luaL_checkinteger( L, 1 );
|
||||
MOD_CHECK_ID( timer, id );
|
||||
stm32_enc_init( id );
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Lua: setcounter(id, count)
|
||||
static int enc_set_counter( lua_State *L )
|
||||
{
|
||||
unsigned id, count;
|
||||
|
||||
id = luaL_checkinteger( L, 1 );
|
||||
MOD_CHECK_ID( timer, id );
|
||||
count = luaL_checkinteger( L, 2 );
|
||||
|
||||
stm32_enc_set_counter( id, count );
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Lua: setidxtrig( id, resnum, tmr_id, count )
|
||||
static int enc_set_index_handler( lua_State *L )
|
||||
{
|
||||
elua_int_id id;
|
||||
|
||||
id = ( elua_int_id )luaL_checkinteger( L, 1 );
|
||||
if( id < ELUA_INT_FIRST_ID || id > INT_ELUA_LAST )
|
||||
return luaL_error( L, "invalid interrupt ID" );
|
||||
index_resnum = ( elua_int_resnum )luaL_checkinteger( L, 2 );
|
||||
index_tmr_id = luaL_checkinteger( L, 3 );
|
||||
MOD_CHECK_ID( timer, index_tmr_id );
|
||||
index_count = ( u16 )luaL_checkinteger( L, 4 );
|
||||
|
||||
platform_cpu_set_interrupt( id, index_resnum, PLATFORM_CPU_ENABLE );
|
||||
prev_handler = elua_int_set_c_handler( id, index_handler );
|
||||
}
|
||||
|
||||
static void index_handler( elua_int_resnum resnum )
|
||||
{
|
||||
if( prev_handler )
|
||||
prev_handler;
|
||||
|
||||
if( resnum != index_resnum )
|
||||
return;
|
||||
|
||||
stm32_enc_set_counter( index_tmr_id, index_count );
|
||||
}
|
||||
|
||||
|
||||
#define MIN_OPT_LEVEL 2
|
||||
#include "lrodefs.h"
|
||||
|
||||
// Module function map
|
||||
const LUA_REG_TYPE enc_map[] =
|
||||
{
|
||||
{ LSTRKEY( "init" ), LFUNCVAL( enc_init ) },
|
||||
{ LSTRKEY( "setcounter" ), LFUNCVAL( enc_set_counter ) },
|
||||
{ LSTRKEY( "setidxtrig" ), LFUNCVAL( enc_set_index_handler ) },
|
||||
{ LNILKEY, LNILVAL }
|
||||
};
|
||||
|
||||
LUALIB_API int luaopen_enc( lua_State *L )
|
||||
{
|
||||
LREGISTER( L, AUXLIB_ENC, enc_map );
|
||||
}
|
||||
|
9
src/platform/stm32f4/enc.h
Normal file
9
src/platform/stm32f4/enc.h
Normal file
@ -0,0 +1,9 @@
|
||||
// STM32 encoder support
|
||||
|
||||
#ifndef __ENC_H__
|
||||
#define __ENC_H__
|
||||
|
||||
void stm32_enc_init( unsigned id );
|
||||
void stm32_enc_set_counter( unsigned id, unsigned count );
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user