离线
TA的每日心情 | 奋斗 2022-11-4 00:50 |
---|
签到天数: 45 天 [LV.5]
|
发表于 2022-6-22 19:09:21
|
显示全部楼层
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <aos/aos.h>
#include "aos/cli.h"
#include "app_init.h"
#include "lvgl.h"
#include "lv_label.h"
#include "oled.h"
#include "board_config.h"
#include "drv/gpio_pin.h"
#include <drv/pin.h>
#include <drv/adc.h>
#include "csi_core.h"
//include "app_config.h"
//#include "csi_config.h"
//#include "hw_config.h"
//#include <drv/common.h>
#define TAG "app"
static csi_adc_t adc;
uint32_t i=1;
static csi_adc_t adc;
void adc_init()
{
csi_error_t ret;
csi_pin_set_mux(EXAMPLE_ADC_CH1, PA4_ADC_A2);
ret = csi_adc_init(&adc, 0);
if (ret != CSI_OK)
{
printf("===%s, %d %d \n", __FUNCTION__, __LINE__,ret);
}
uint32_t freq_value = csi_adc_freq_div(&adc, 128);
printf("get freq_value: %d\n", freq_value);
/* Configure sampling time */
ret = csi_adc_sampling_time(&adc, 2);
if (ret != CSI_OK)
{
printf("===%s, %d %d \n", __FUNCTION__, __LINE__,ret);
}
/* Enable channel */
ret = csi_adc_channel_enable(&adc, 1, true);
if (ret != CSI_OK)
{
printf("===%s, %d %d \n", __FUNCTION__, __LINE__,ret);
}
/* Trigger new conversion */
ret = csi_adc_start(&adc);
if (ret != CSI_OK)
{
printf("===%s, %d %d \n", __FUNCTION__, __LINE__,ret);
}
/* Read result */
int32_t data = csi_adc_read(&adc);
printf("get adc result: %d\n", data);
printf("the voltage is: %d mV\n", data*3300/4096);
/* Uninit adc */
//csi_adc_uninit(&adc);
}
static void gui_label_create(void)
{
lv_obj_t *p = lv_label_create(lv_scr_act(), NULL);
lv_label_set_long_mode(p, LV_LABEL_LONG_BREAK);
lv_label_set_align(p, LV_LABEL_ALIGN_CENTER);
lv_obj_set_pos(p, 0, 4);
lv_obj_set_size(p, 128, 60);
lv_label_set_text(p, "THEAD RISC-V\nADC \nDEMO");
}
static void adc_lvgl_task(void *arg)
{
lv_init();
/*Initialize for LittlevGL*/
oled_init();
adc_init();
/*Select display 1*/
// demo_create();
gui_label_create();
while (1)
{
/* Periodically call the lv_task handler.
* It could be done in a timer interrupt or an OS task too.*/
lv_task_handler();
aos_msleep(5);
lv_tick_inc(1);
int32_t data = csi_adc_read(&adc);
printf("get adc result: %d\n", data);
printf("the voltage is: %d mV\n", data*3300/4096);
}
}
static void adc_lvgl_task(void *arg);
int main(void)
{
board_yoc_init();
aos_task_new("adc", adc_lvgl_task, NULL, 10 * 1024);
return 0;
}
|
|