project:cfg:BoardConfig_IPC: Added fastboot BoardConfig file and firmware post-scripts, distinguishing between the BoardConfigs for Luckfox Pico Pro and Luckfox Pico Max. project:app: Added fastboot_client and rk_smart_door for quick boot applications; updated rkipc app to adapt to the latest media library. media:samples: Added more usage examples. media:rockit: Fixed bugs; removed support for retrieving data frames from VPSS. media:isp: Updated rkaiq library and related tools to support connection to RKISP_Tuner. sysdrv:Makefile: Added support for compiling drv_ko on Luckfox Pico Ultra W using Ubuntu; added support for custom root filesystem. sysdrv:tools:board: Updated Buildroot optional mirror sources, updated some software versions, and stored device tree files and configuration files that undergo multiple modifications for U-Boot and kernel separately. sysdrv:source:mcu: Used RISC-V MCU SDK with RT-Thread system, mainly for initializing camera AE during quick boot. sysdrv:source:uboot: Added support for fastboot; added high baud rate DDR bin for serial firmware upgrades. sysdrv:source:kernel: Upgraded to version 5.10.160; increased NPU frequency for RV1106G3; added support for fastboot. Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
297 lines
7.5 KiB
C
297 lines
7.5 KiB
C
/*
|
|
* Copyright (c) 2006-2018, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2018-05-07 aozima the first version
|
|
* 2018-11-16 Ernest Chen add finsh command and update adc function
|
|
*/
|
|
|
|
#include <rtthread.h>
|
|
#include <rtdevice.h>
|
|
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#define DBG_SECTION_NAME "adc"
|
|
#define DBG_LEVEL DBG_INFO
|
|
#include <rtdbg.h>
|
|
|
|
static rt_size_t _adc_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
|
|
{
|
|
rt_err_t result = RT_EOK;
|
|
rt_size_t i;
|
|
struct rt_adc_device *adc = (struct rt_adc_device *)dev;
|
|
rt_uint32_t *value = (rt_uint32_t *)buffer;
|
|
|
|
for (i = 0; i < size; i += sizeof(int))
|
|
{
|
|
result = adc->ops->convert(adc, pos + i, value);
|
|
if (result != RT_EOK)
|
|
{
|
|
return 0;
|
|
}
|
|
value++;
|
|
}
|
|
|
|
return i;
|
|
}
|
|
|
|
static rt_err_t _adc_control(rt_device_t dev, int cmd, void *args)
|
|
{
|
|
rt_err_t result = RT_EOK;
|
|
rt_adc_device_t adc = (struct rt_adc_device *)dev;
|
|
|
|
if (adc->ops->enabled == RT_NULL)
|
|
{
|
|
return -RT_ENOSYS;
|
|
}
|
|
if (cmd == RT_ADC_CMD_ENABLE)
|
|
{
|
|
result = adc->ops->enabled(adc, (rt_uint32_t)args, RT_TRUE);
|
|
}
|
|
else if (cmd == RT_ADC_CMD_DISABLE)
|
|
{
|
|
result = adc->ops->enabled(adc, (rt_uint32_t)args, RT_FALSE);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#ifdef RT_USING_DEVICE_OPS
|
|
const static struct rt_device_ops adc_dev_ops =
|
|
{
|
|
RT_NULL,
|
|
RT_NULL,
|
|
RT_NULL,
|
|
_adc_read,
|
|
RT_NULL,
|
|
_adc_control,
|
|
};
|
|
#endif
|
|
|
|
rt_err_t rt_hw_adc_register(rt_adc_device_t device, const char *name, const struct rt_adc_ops *ops, const void *user_data)
|
|
{
|
|
rt_err_t result = RT_EOK;
|
|
RT_ASSERT(ops != RT_NULL && ops->convert != RT_NULL);
|
|
|
|
device->parent.type = RT_Device_Class_Miscellaneous;
|
|
#ifdef RT_USING_DEVICE_OPS
|
|
device->parent.ops = &adc_dev_ops;
|
|
#else
|
|
device->parent.init = RT_NULL;
|
|
device->parent.open = RT_NULL;
|
|
device->parent.close = RT_NULL;
|
|
device->parent.read = _adc_read;
|
|
device->parent.write = RT_NULL;
|
|
device->parent.control = _adc_control;
|
|
#endif
|
|
|
|
device->ops = ops;
|
|
device->parent.user_data = (void *)user_data;
|
|
|
|
result = rt_device_register(&device->parent, name, RT_DEVICE_FLAG_RDWR);
|
|
|
|
return result;
|
|
}
|
|
|
|
rt_uint32_t rt_adc_read(rt_adc_device_t dev, rt_uint32_t channel)
|
|
{
|
|
rt_uint32_t value;
|
|
rt_uint32_t ret;
|
|
|
|
RT_ASSERT(dev);
|
|
|
|
ret = dev->ops->convert(dev, channel, &value);
|
|
|
|
if (ret != RT_EOK)
|
|
return 0;
|
|
|
|
return value;
|
|
}
|
|
|
|
rt_err_t rt_adc_enable(rt_adc_device_t dev, rt_uint32_t channel)
|
|
{
|
|
rt_err_t result = RT_EOK;
|
|
|
|
RT_ASSERT(dev);
|
|
if (dev->ops->enabled != RT_NULL)
|
|
{
|
|
result = dev->ops->enabled(dev, channel, RT_TRUE);
|
|
}
|
|
else
|
|
{
|
|
result = -RT_ENOSYS;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
rt_err_t rt_adc_disable(rt_adc_device_t dev, rt_uint32_t channel)
|
|
{
|
|
rt_err_t result = RT_EOK;
|
|
|
|
RT_ASSERT(dev);
|
|
if (dev->ops->enabled != RT_NULL)
|
|
{
|
|
result = dev->ops->enabled(dev, channel, RT_FALSE);
|
|
}
|
|
else
|
|
{
|
|
result = -RT_ENOSYS;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#ifdef FINSH_USING_MSH
|
|
|
|
static int adc(int argc, char **argv)
|
|
{
|
|
int value = 0;
|
|
int result = RT_EOK;
|
|
static rt_adc_device_t adc_device = RT_NULL;
|
|
char *result_str;
|
|
|
|
if (argc > 1)
|
|
{
|
|
if (!strcmp(argv[1], "probe"))
|
|
{
|
|
if (argc == 3)
|
|
{
|
|
adc_device = (rt_adc_device_t)rt_device_find(argv[2]);
|
|
result_str = (adc_device == RT_NULL) ? "failure" : "success";
|
|
rt_kprintf("probe %s %s \n", argv[2], result_str);
|
|
}
|
|
else
|
|
{
|
|
rt_kprintf("adc probe <adc_name> - probe adc by name\n");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (adc_device == RT_NULL)
|
|
{
|
|
rt_kprintf("Please using 'adc probe <adc_name>' first\n");
|
|
return -RT_ERROR;
|
|
}
|
|
if (!strcmp(argv[1], "enable"))
|
|
{
|
|
if (argc == 3)
|
|
{
|
|
result = rt_adc_enable(adc_device, atoi(argv[2]));
|
|
result_str = (result == RT_EOK) ? "success" : "failure";
|
|
rt_kprintf("%s channel %d enables %s \n", adc_device->parent.parent.name, atoi(argv[2]), result_str);
|
|
}
|
|
else
|
|
{
|
|
rt_kprintf("adc enable <channel> - enable adc channel\n");
|
|
}
|
|
}
|
|
else if (!strcmp(argv[1], "read"))
|
|
{
|
|
if (argc == 3)
|
|
{
|
|
value = rt_adc_read(adc_device, atoi(argv[2]));
|
|
rt_kprintf("%s channel %d read value is 0x%08X \n", adc_device->parent.parent.name, atoi(argv[2]), value);
|
|
}
|
|
else
|
|
{
|
|
rt_kprintf("adc read <channel> - read adc value on the channel\n");
|
|
}
|
|
}
|
|
else if (!strcmp(argv[1], "disable"))
|
|
{
|
|
if (argc == 3)
|
|
{
|
|
result = rt_adc_disable(adc_device, atoi(argv[2]));
|
|
result_str = (result == RT_EOK) ? "success" : "failure";
|
|
rt_kprintf("%s channel %d disable %s \n", adc_device->parent.parent.name, atoi(argv[2]), result_str);
|
|
}
|
|
else
|
|
{
|
|
rt_kprintf("adc disable <channel> - disable adc channel\n");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
rt_kprintf("Unknown command. Please enter 'adc' for help\n");
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
rt_kprintf("Usage: \n");
|
|
rt_kprintf("adc probe <adc_name> - probe adc by name\n");
|
|
rt_kprintf("adc read <channel> - read adc value on the channel\n");
|
|
rt_kprintf("adc disable <channel> - disable adc channel\n");
|
|
rt_kprintf("adc enable <channel> - enable adc channel\n");
|
|
result = -RT_ERROR;
|
|
}
|
|
return RT_EOK;
|
|
}
|
|
|
|
static rt_timer_t timer;
|
|
static struct rt_event event;
|
|
|
|
void timer_func(void *parameter)
|
|
{
|
|
rt_uint32_t channel = 0;
|
|
int value = 0;
|
|
static rt_adc_device_t adc_device;
|
|
|
|
adc_device = (rt_adc_device_t)parameter;
|
|
|
|
value = rt_adc_read(adc_device, channel);
|
|
if (value != 0)
|
|
{
|
|
rt_kprintf("%s channel %d read value is 0x%x \n", adc_device->parent.parent.name, channel, value);
|
|
rt_timer_stop(timer);
|
|
rt_event_send(&event, 0x1);
|
|
}
|
|
}
|
|
|
|
int _at_saradc_test(void)
|
|
{
|
|
static rt_adc_device_t adc_device = RT_NULL;
|
|
rt_err_t ret;
|
|
rt_uint32_t status;
|
|
|
|
adc_device = (rt_adc_device_t)rt_device_find("rk_adc0");
|
|
RT_ASSERT(adc_device != RT_NULL);
|
|
|
|
if (!timer)
|
|
{
|
|
timer = rt_timer_create("adc_read", timer_func, adc_device,
|
|
RT_TICK_PER_SECOND / 8, RT_TIMER_FLAG_PERIODIC);
|
|
if (!timer)
|
|
return RT_ERROR;
|
|
|
|
rt_timer_start(timer);
|
|
}
|
|
|
|
rt_kprintf("start saradc auto test : \n");
|
|
|
|
/* TODO : simulate a saradc event */
|
|
|
|
/* wait saradc 2 seconds to trigger interrupt */
|
|
if (rt_event_recv(&event, 0xffffffff, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
|
|
rt_tick_from_millisecond(2000), &status) != RT_EOK)
|
|
{
|
|
rt_kprintf("wait saradc timeout");
|
|
rt_timer_stop(timer);
|
|
return -RT_ETIMEOUT;
|
|
}
|
|
|
|
if (status != 0x1)
|
|
return -RT_ERROR;
|
|
|
|
return RT_EOK;
|
|
}
|
|
MSH_CMD_EXPORT(adc, adc function);
|
|
FINSH_FUNCTION_EXPORT(_at_saradc_test, saradc test for auto test);
|
|
|
|
#endif /* FINSH_USING_MSH */
|