# -*- coding: utf-8 -*-
#====================================================================
#
# Copyright © 2023 China Mobile IOT. All rights reserved.
#
#
#====================================================================
Import('env')
from ModuleBuild import *
module = 'custom_main' # 模块名,同簇模块不得重名
current_dir = os.path.join(Dir('.').abspath)
target = None
#========================================================
# ram_source_files:运行在ram中
# flash_source_files:运行在flash中
#========================================================
ram_source_files = [#添加.c文件路径(让程序运行在ram中)
'custom_main/src/custom_main.c',
'custom_main/src/test.c',
]
flash_source_files = [#添加.c文件路径(让程序运行在flash中,节省内存)
]
#========================================================
# public_incs: 在这个里面添加其它模块里面的.h文件的路径
# private_incs:在这个里面添加本模块(custom_main文件夹)里面的 .h文件的路径
#========================================================
public_incs = [
current_dir + '/../examples/mcu_sys/inc',#这边使用mcu_sys.h是其它模块里面的,所以在这里添加路径
]
private_incs = [
current_dir + '/custom_main/inc',
current_dir + '/custom_main/src',#test.h是本模块里面的,所以在这里添加路径
]
#========================================================
# cpp_define:仅适用于本模块,对其他模块不可见
#========================================================
cpp_defines = [
]
#========================================================
# 模块编译
#========================================================
mod = ModuleBuild(env,
name = module,
ram_srcs = ram_source_files,
flash_srcs = flash_source_files,
pub_incs = public_incs,
pri_incs = private_incs,
cpp_define = cpp_defines
)
target = mod.build_object()
Return('target')
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
.
.
.
#include "cm_adc.h"
void test(void)
{
int32_t adc_value=0;
cm_adc_read(CM_ADC_0, &adc_value);//读取电压
}
#include "cm_adc.h"
#include <stdint.h>
#include "cm_adc.h"
#include "cm_os.h"
#include "cm_sys.h"
void test(void)
{
int32_t voltage=0;
uint32_t voltage_vbat=0;
int32_t ret;
ret = cm_adc_vbat_read(&voltage_vbat);
if(ret != 0)
{
cm_log_printf(0, "adc vbate read err,ret=%d\n", ret);//串口打印改为了使用日志打印
}
cm_log_printf(0, "adc vbate read:%ld(mv)!!\n",voltage_vbat);
//测试ADC0
ret = cm_adc_read(CM_ADC_0,&voltage);
if(ret != 0)
{
cm_log_printf(0, "adcCM_ADC_0 read err,ret=0x%08x\n", ret);
}
cm_log_printf(0, "adc CM_ADC_0 read:%ld(mv)!!\n",voltage);
cm_log_printf(0, "adc test end!!\n");
}
#include "test.h"
#include "cm_adc.h"
#include <stdint.h>
#include "cm_adc.h"
#include "cm_os.h"
#include "cm_sys.h"
void test(void)
{
int32_t voltage=0;
uint32_t voltage_vbat=0;
int32_t ret;
ret = cm_adc_vbat_read(&voltage_vbat);
if(ret != 0)
{
cm_log_printf(0, "adc vbate read err,ret=%d\n", ret);//串口打印改为了使用日志打印
}
cm_log_printf(0, "adc vbate read:%ld(mv)!!\n",voltage_vbat);
//测试ADC0
ret = cm_adc_read(CM_ADC_0,&voltage);
if(ret != 0)
{
cm_log_printf(0, "adcCM_ADC_0 read err,ret=0x%08x\n", ret);
}
cm_log_printf(0, "adc CM_ADC_0 read:%ld(mv)!!\n",voltage);
cm_log_printf(0, "adc test end!!\n");
}
#ifndef test_h_
#define test_h_
void test(void);
#endif
#include "custom_main.h"
#include "test.h"
int cm_opencpu_entry(void *param)
{
(void)param;
test();
return 0;
}