Skip to content

Commit

Permalink
add:air780E的部分外设iomux
Browse files Browse the repository at this point in the history
  • Loading branch information
allewalker committed Apr 25, 2023
1 parent 661271f commit 9eaef51
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion luat/include/luat_i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ int luat_i2c_read_reg(int id, int addr, int reg, uint16_t* value);

int luat_i2c_transfer(int id, int addr, uint8_t *reg, size_t reg_len, uint8_t *buff, size_t len);
int luat_i2c_no_block_transfer(int id, int addr, uint8_t is_read, uint8_t *reg, size_t reg_len, uint8_t *buff, size_t len, uint16_t Toms, void *CB, void *pParam);

int luat_i2c_set_iomux(int id, uint8_t value);
#endif
7 changes: 7 additions & 0 deletions luat/include/luat_mcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
#define LUAT_MCU_H
#include "luat_base.h"

enum
{
LUAT_MCU_PERIPHERAL_UART,
LUAT_MCU_PERIPHERAL_I2C,
LUAT_MCU_PERIPHERAL_SPI,
};

int luat_mcu_set_clk(size_t mhz);
int luat_mcu_get_clk(void);

Expand Down
9 changes: 9 additions & 0 deletions luat/include/luat_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ typedef struct luat_uart_ctrl_param
*/
int luat_uart_ctrl(int uart_id, LUAT_UART_CTRL_CMD_E cmd, void* param);

/**
* @brief 串口复用函数,目前支持UART0,UART2
*
* @param uart_id 串口id
* @param use_alt_type 如果为1,UART0,复用到GPIO16,GPIO17;UART2复用到GPIO12 GPIO13
* @return int 0 失败,其他成功
*/
int luat_uart_pre_setup(int uart_id, uint8_t use_alt_type);

#ifdef LUAT_USE_SOFT_UART
#ifndef __BSP_COMMON_H__
#include "c_common.h"
Expand Down
39 changes: 39 additions & 0 deletions luat/modules/luat_lib_mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,38 @@ static int l_mcu_set_hardfault_mode(lua_State* L)
return 0;
}

LUAT_WEAK int luat_uart_pre_setup(int uart_id, uint8_t use_alt_type){;}
LUAT_WEAK int luat_i2c_set_iomux(int id, uint8_t value){;}
/*
在外设打开前,将外设IO复用到非默认配置上,目前只支持Air780E的部分外设复用到其他配置,这是一个临时接口,如果后续有更合适的api,本接口将不再更新
@api mcu.iomux(type, channel, value)
@int 外设类型,目前只有mcu.UART,mcu.I2C
@int 总线序号,0~N,
@int 新的配置,这个需要根据具体平台决定
@usage
mcu.iomux(mcu.UART, 2, 1) -- Air780E的UART2复用到gpio12和gpio13(Air780EG默认是这个复用,不要动)
mcu.iomux(mcu.UART, 2, 2) -- Air780E的UART2复用到gpio6和gpio7
mcu.iomux(mcu.I2C, 0, 1) -- Air780E的I2C0复用到gpio12和gpio13
mcu.iomux(mcu.I2C, 0, 2) -- Air780E的I2C0复用到gpio16和gpio17
mcu.iomux(mcu.I2C, 1, 1) -- Air780E的I2C1复用到gpio4和gpio5
*/
static int l_mcu_iomux(lua_State* L)
{
int type = luaL_optinteger(L, 1, 0xff);
int channel = luaL_optinteger(L, 2, 0xff);
int value = luaL_optinteger(L, 3, 0);
LLOGD("mcu iomux %d,%d,%d", type, channel, value);
switch(type)
{
case LUAT_MCU_PERIPHERAL_UART:
luat_uart_pre_setup(channel, value);
break;
case LUAT_MCU_PERIPHERAL_I2C:
luat_i2c_set_iomux(channel, value);
break;
}
return 0;
}
#include "rotable2.h"
static const rotable_Reg_t reg_mcu[] =
{
Expand All @@ -245,7 +277,14 @@ static const rotable_Reg_t reg_mcu[] =
{ "dtick64", ROREG_FUNC(l_mcu_hw_diff_tick64)},
{ "setXTAL", ROREG_FUNC(l_mcu_set_xtal)},
{ "hardfault", ROREG_FUNC(l_mcu_set_hardfault_mode)},
{ "iomux", ROREG_FUNC(l_mcu_iomux)},
// #endif
//@const UART number 外设类型-串口
{ "UART", ROREG_INT(LUAT_MCU_PERIPHERAL_UART) },
//@const UART number 外设类型-I2C
{ "I2C", ROREG_INT(LUAT_MCU_PERIPHERAL_I2C) },
//@const UART number 外设类型-SPI
{ "SPI", ROREG_INT(LUAT_MCU_PERIPHERAL_SPI) },
{ NULL, ROREG_INT(0) }
};

Expand Down

0 comments on commit 9eaef51

Please sign in to comment.