mirror of
https://github.com/elua/elua.git
synced 2025-01-25 01:02:54 +08:00
Merge branch 'andreas23-conf-pinout'
This commit is contained in:
commit
2dc402c8d7
@ -3,7 +3,7 @@
|
||||
return {
|
||||
cpu = 'lpc1769',
|
||||
components = {
|
||||
sercon = { uart = 0, speed = 115200 },
|
||||
sercon = { uart = 3, speed = 115200 },
|
||||
romfs = true,
|
||||
shell = true,
|
||||
term = { lines = 25, cols = 80 },
|
||||
@ -15,7 +15,12 @@ return {
|
||||
config = {
|
||||
egc = { mode = "alloc" },
|
||||
ram = { internal_rams = 2 },
|
||||
clocks = { external = 12000000, cpu = 120000000 }
|
||||
clocks = { external = 12000000, cpu = 120000000 },
|
||||
map_pins = {
|
||||
port = { 0, 0 },
|
||||
pin = { 0, 1 },
|
||||
pinfunction = { 2, 2 }
|
||||
}
|
||||
},
|
||||
modules = {
|
||||
generic = { 'all', "-spi", "-i2c", "-net" },
|
||||
|
@ -16,7 +16,12 @@ return {
|
||||
config = {
|
||||
egc = { mode = "alloc" },
|
||||
ram = { internal_rams = 2 },
|
||||
clocks = { external = 12000000, cpu = 100000000 }
|
||||
clocks = { external = 12000000, cpu = 100000000 },
|
||||
map_pins = {
|
||||
port = { 0, 0 },
|
||||
pin = { 2, 3 },
|
||||
pinfunction = { 1, 1 }
|
||||
}
|
||||
},
|
||||
modules = {
|
||||
generic = { 'all', "-spi", "-i2c", "-net" },
|
||||
|
@ -2,6 +2,7 @@
|
||||
-- It is used by the generic board configuration system (config/)
|
||||
|
||||
module( ..., package.seeall )
|
||||
local at = require "attributes"
|
||||
|
||||
-- Add specific components to the 'components' table
|
||||
function add_platform_components( t, board, cpu )
|
||||
@ -10,12 +11,18 @@ end
|
||||
|
||||
-- Add specific configuration to the 'configs' table
|
||||
function add_platform_configs( t, board, cpu )
|
||||
|
||||
t.map_pins = {
|
||||
attrs = {
|
||||
port = at.array_of( at.int_attr( 'LPC17XX_MAP_PORT' )),
|
||||
pin = at.array_of( at.int_attr( 'LPC17XX_MAP_PIN' )),
|
||||
pinfunction = at.array_of( at.int_attr( 'LPC17XX_MAP_PINFUNCTION' ))
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
-- Return an array of all the available platform modules for the given cpu
|
||||
function get_platform_modules( board, cpu )
|
||||
local m = { }
|
||||
local m = { pio = { map = "lpc17xx_pio_map", open = "luaopen_lpc17xx_pio" } }
|
||||
board = board:upper()
|
||||
if board == 'MBED' then
|
||||
m.pio = { map = "mbed_pio_map", open = "luaopen_mbed_pio" }
|
||||
|
@ -9,6 +9,8 @@ local board = comp.board:upper()
|
||||
|
||||
if board == "MBED" then
|
||||
specific_files = specific_files .. " mbed_pio.c"
|
||||
else
|
||||
specific_files = specific_files .. " lpc17xx_pio.c"
|
||||
end
|
||||
|
||||
local ldscript = "LPC17xx.ld"
|
||||
|
79
src/platform/lpc17xx/lpc17xx_pio.c
Normal file
79
src/platform/lpc17xx/lpc17xx_pio.c
Normal file
@ -0,0 +1,79 @@
|
||||
// LPC17xx specific PIO support
|
||||
#include <string.h>
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
#include "platform.h"
|
||||
#include "lrotable.h"
|
||||
#include "platform_conf.h"
|
||||
#include "auxmods.h"
|
||||
#include "lpc17xx_pinsel.h"
|
||||
|
||||
static int configpin( lua_State* L )
|
||||
{
|
||||
pio_type v = ( pio_type )luaL_checkinteger( L, 1 );
|
||||
int funcnum = luaL_checkinteger( L, 2 );
|
||||
int opendrain = luaL_checkinteger( L, 3 );
|
||||
int pinmode = luaL_checkinteger( L, 4 );
|
||||
PINSEL_CFG_Type PinCfg;
|
||||
int port, pin;
|
||||
|
||||
port = PLATFORM_IO_GET_PORT( v );
|
||||
pin = PLATFORM_IO_GET_PIN( v );
|
||||
if( PLATFORM_IO_IS_PORT( v ) || !platform_pio_has_port( port ) || !platform_pio_has_pin( port, pin ) )
|
||||
return luaL_error( L, "invalid pin" );
|
||||
|
||||
PinCfg.Funcnum = funcnum;
|
||||
PinCfg.OpenDrain = opendrain;
|
||||
PinCfg.Pinmode = pinmode;
|
||||
PinCfg.Portnum = port;
|
||||
PinCfg.Pinnum = pin;
|
||||
PINSEL_ConfigPin(&PinCfg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Module function map
|
||||
#define MIN_OPT_LEVEL 2
|
||||
#include "lrodefs.h"
|
||||
const LUA_REG_TYPE lpc17xx_pio_map[] =
|
||||
{
|
||||
#if LUA_OPTIMIZE_MEMORY > 0
|
||||
{ LSTRKEY( "__metatable" ), LROVAL( lpc17xx_pio_map ) },
|
||||
{ LSTRKEY( "RES_PULLUP" ), LNUMVAL( PINSEL_PINMODE_PULLUP )},
|
||||
{ LSTRKEY( "RES_TRISTATE" ), LNUMVAL( PINSEL_PINMODE_TRISTATE )},
|
||||
{ LSTRKEY( "RES_PULLDOWN" ), LNUMVAL( PINSEL_PINMODE_PULLDOWN )},
|
||||
{ LSTRKEY( "FUNCTION_0" ), LNUMVAL( PINSEL_FUNC_0 )},
|
||||
{ LSTRKEY( "FUNCTION_1" ), LNUMVAL( PINSEL_FUNC_1 )},
|
||||
{ LSTRKEY( "FUNCTION_2" ), LNUMVAL( PINSEL_FUNC_2 )},
|
||||
{ LSTRKEY( "FUNCTION_3" ), LNUMVAL( PINSEL_FUNC_3 )},
|
||||
{ LSTRKEY( "MODE_DEFAULT" ), LNUMVAL( PINSEL_PINMODE_NORMAL )},
|
||||
{ LSTRKEY( "MODE_OD" ), LNUMVAL( PINSEL_PINMODE_OPENDRAIN )},
|
||||
#endif
|
||||
{ LSTRKEY( "configpin" ), LFUNCVAL( configpin ) },
|
||||
{ LNILKEY, LNILVAL }
|
||||
};
|
||||
|
||||
LUALIB_API int luaopen_lpc17xx_pio( lua_State *L )
|
||||
{
|
||||
#if LUA_OPTIMIZE_MEMORY > 0
|
||||
return 0;
|
||||
#else
|
||||
luaL_register( L, PS_LIB_TABLE_NAME, lpc17xx_pio_map );
|
||||
MOD_REG_NUMBER( L, "RES_PULLUP", PINSEL_PINMODE_PULLUP );
|
||||
MOD_REG_NUMBER( L, "RES_TRISTATE", PINSEL_PINMODE_TRISTATE );
|
||||
MOD_REG_NUMBER( L, "RES_PULLDOWN", PINSEL_PINMODE_PULLDOWN );
|
||||
MOD_REG_NUMBER( L, "FUNCTION_0", PINSEL_FUNC_0 );
|
||||
MOD_REG_NUMBER( L, "FUNCTION_1", PINSEL_FUNC_1 );
|
||||
MOD_REG_NUMBER( L, "FUNCTION_2", PINSEL_FUNC_2 );
|
||||
MOD_REG_NUMBER( L, "FUNCTION_3", PINSEL_FUNC_3 );
|
||||
MOD_REG_NUMBER( L, "MODE_DEFAULT", PINSEL_PINMODE_NORMAL );
|
||||
MOD_REG_NUMBER( L, "MODE_OD", PINSEL_PINMODE_OPENDRAIN );
|
||||
|
||||
// Set it as its own metatable
|
||||
lua_pushvalue( L, -1 );
|
||||
lua_setmetatable( L, -2 );
|
||||
|
||||
return 1;
|
||||
#endif
|
||||
}
|
@ -38,6 +38,7 @@ static void platform_setup_timers();
|
||||
static void platform_setup_pwm();
|
||||
static void platform_setup_adcs();
|
||||
static void cans_init( void );
|
||||
static void platform_setup_pins();
|
||||
|
||||
int platform_init()
|
||||
{
|
||||
@ -73,6 +74,9 @@ int platform_init()
|
||||
// Setup CANs
|
||||
cans_init();
|
||||
|
||||
// Setup pin routing
|
||||
platform_setup_pins();
|
||||
|
||||
// System timer setup
|
||||
cmn_systimer_set_base_freq( lpc17xx_get_cpu_frequency() );
|
||||
cmn_systimer_set_interrupt_freq( SYSTICKHZ );
|
||||
@ -105,6 +109,27 @@ void SysTick_Handler()
|
||||
// ****************************************************************************
|
||||
// PIO section
|
||||
|
||||
static const u8 map_ports[] = LPC17XX_MAP_PORT;
|
||||
static const u8 map_pins [] = LPC17XX_MAP_PIN;
|
||||
static const u8 map_funcs[] = LPC17XX_MAP_PINFUNCTION;
|
||||
|
||||
static void platform_setup_pins(void)
|
||||
{
|
||||
PINSEL_CFG_Type PinCfg;
|
||||
u8 i;
|
||||
|
||||
PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
|
||||
PinCfg.Pinmode = PINSEL_PINMODE_PULLUP;
|
||||
|
||||
for(i=0; i<sizeof(map_ports); i++)
|
||||
{
|
||||
PinCfg.Portnum = map_ports[i];
|
||||
PinCfg.Pinnum = map_pins [i];
|
||||
PinCfg.Funcnum = map_funcs[i];
|
||||
PINSEL_ConfigPin(&PinCfg);
|
||||
}
|
||||
}
|
||||
|
||||
// The platform I/O functions
|
||||
pio_type platform_pio_op( unsigned port, pio_type pinmask, int op )
|
||||
{
|
||||
@ -159,9 +184,8 @@ pio_type platform_pio_op( unsigned port, pio_type pinmask, int op )
|
||||
// ****************************************************************************
|
||||
// UART section
|
||||
|
||||
// UART0: Rx = P0.3, Tx = P0.2
|
||||
// The other UARTs have assignable Rx/Tx pins and thus have to be configured
|
||||
// by the user
|
||||
// If you want to use an UART, make sure it is routed to your desired output
|
||||
// pin. See section 8.5 of the LPC17xx User Manual.
|
||||
|
||||
static LPC_UART_TypeDef* const uart[] = { LPC_UART0, LPC_UART1, LPC_UART2, LPC_UART3 };
|
||||
|
||||
@ -171,18 +195,6 @@ u32 platform_uart_setup( unsigned id, u32 baud, int databits, int parity, int st
|
||||
UART_CFG_Type UARTConfigStruct;
|
||||
// UART FIFO configuration Struct variable
|
||||
UART_FIFO_CFG_Type UARTFIFOConfigStruct;
|
||||
// Pin configuration for UART0
|
||||
PINSEL_CFG_Type PinCfg;
|
||||
|
||||
// UART0 Pin Config
|
||||
PinCfg.Funcnum = 1;
|
||||
PinCfg.OpenDrain = 0;
|
||||
PinCfg.Pinmode = 0;
|
||||
PinCfg.Pinnum = 2;
|
||||
PinCfg.Portnum = 0;
|
||||
PINSEL_ConfigPin(&PinCfg);
|
||||
PinCfg.Pinnum = 3;
|
||||
PINSEL_ConfigPin(&PinCfg);
|
||||
|
||||
UARTConfigStruct.Baud_rate = ( uint32_t )baud;
|
||||
|
||||
@ -524,7 +536,7 @@ u32 platform_adc_set_clock( unsigned id, u32 frequency )
|
||||
}
|
||||
|
||||
static const u8 adc_ports[] = { 0, 0, 0, 0, 1, 1, 0, 0 };
|
||||
static const u8 adc_pins[] = { 23, 24, 25, 26, 30, 31, 3, 2 };
|
||||
static const u8 adc_pins[] = { 23, 24, 25, 26, 30, 31, 3, 2 };
|
||||
static const u8 adc_funcs[] = { 1, 1, 1, 1, 3, 3, 2, 2 };
|
||||
|
||||
// Prepare Hardware Channel
|
||||
@ -544,7 +556,7 @@ int platform_adc_update_sequence( )
|
||||
id = d->ch_state[ seq_tmp ]->id;
|
||||
|
||||
PinCfg.Funcnum = adc_funcs[ id ];
|
||||
PinCfg.Pinnum = adc_pins[ id ];
|
||||
PinCfg.Pinnum = adc_pins[ id ];
|
||||
PinCfg.Portnum = adc_ports[ id ];
|
||||
PINSEL_ConfigPin(&PinCfg);
|
||||
}
|
||||
@ -813,4 +825,3 @@ int platform_can_recv( unsigned id, u32 *canid, u8 *idtype, u8 *len, u8 *data )
|
||||
else
|
||||
return PLATFORM_UNDERFLOW;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user