Compare commits
77 Commits
master
...
prepare_fo
370 changed files with 52743 additions and 3333 deletions
@ -0,0 +1,108 @@ |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <transform.h> |
|||
|
|||
#define NULL_PARAMETER 0 |
|||
|
|||
#define DVP_INIT 0x00U |
|||
#define REG_SCCB_READ 0x12U |
|||
#define REG_SCCB_WRITE 0x13U |
|||
#define OUTPUT_CONFIG 0x20U |
|||
#define LCD_STRING_TYPE 0 |
|||
#define LCD_DOT_TYPE 1 |
|||
#define LCD_SIZE 320 |
|||
|
|||
static uint16_t image_buff[384000]; |
|||
|
|||
void TestCamera(int argc, char *argv[]) |
|||
{ |
|||
int frame_counter = 10000; |
|||
if (argc > 1) |
|||
{ |
|||
frame_counter = atoi(argv[1]); |
|||
} |
|||
printf("This test will refresh %d frames\n", frame_counter); |
|||
|
|||
int camera_fd = PrivOpen(CAMERA_DEV_DRIVER, O_RDWR); |
|||
if (camera_fd < 0) |
|||
{ |
|||
printf("open camera fd error:%d\n", camera_fd); |
|||
return; |
|||
} |
|||
int lcd_fd = PrivOpen(CAMERA_LCD_DEV_DRIVER, O_RDWR); |
|||
if (lcd_fd < 0) |
|||
{ |
|||
printf("open lcd fd error:%d\n", lcd_fd); |
|||
return; |
|||
} |
|||
|
|||
//configure the camera's output address
|
|||
struct PrivIoctlCfg ioctl_cfg; |
|||
ioctl_cfg.ioctl_driver_type = CAMERA_TYPE; |
|||
struct CameraCfg camera_cfg ={ |
|||
.gain_manu_enable = 0, |
|||
.gain = 0xFF, |
|||
.window_w = 800, |
|||
.window_h = 600, |
|||
.output_w = IMAGE_WIDTH, |
|||
.output_h = IMAGE_HEIGHT, |
|||
.window_xoffset = 0, |
|||
.window_yoffset = 0 |
|||
}; |
|||
ioctl_cfg.args = &camera_cfg; |
|||
if (0 != PrivIoctl(camera_fd, OPE_CFG, &ioctl_cfg)) |
|||
{ |
|||
printf("camera pin fd error %d\n", camera_fd); |
|||
PrivClose(camera_fd); |
|||
return; |
|||
} |
|||
|
|||
ioctl_cfg.args = (void *)image_buff; |
|||
|
|||
if (0 != PrivRead(camera_fd, image_buff, NULL_PARAMETER)) |
|||
{ |
|||
printf("camera pin fd error %d\n", camera_fd); |
|||
PrivClose(camera_fd); |
|||
return; |
|||
} |
|||
|
|||
printf("address buff is %x\n", image_buff); |
|||
|
|||
|
|||
LcdWriteParam graph_param; |
|||
graph_param.type = LCD_DOT_TYPE; |
|||
|
|||
//clear the LCD
|
|||
uint16_t back_color[LCD_SIZE]; |
|||
memset(back_color,0,sizeof(back_color)); |
|||
for (int i = 0; i < LCD_SIZE; i++) |
|||
{ |
|||
graph_param.pixel_info.pixel_color = &back_color; |
|||
graph_param.pixel_info.x_startpos = 0; |
|||
graph_param.pixel_info.y_startpos = i; |
|||
graph_param.pixel_info.x_endpos = LCD_SIZE -1; |
|||
graph_param.pixel_info.y_endpos = i; |
|||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER); |
|||
} |
|||
|
|||
//refresh the LCD using photo of camera
|
|||
while (frame_counter--) |
|||
{ |
|||
for (int i = 0; i < IMAGE_HEIGHT; i++) |
|||
{ |
|||
graph_param.pixel_info.pixel_color = image_buff + i * IMAGE_WIDTH; |
|||
graph_param.pixel_info.x_startpos = 0; |
|||
graph_param.pixel_info.y_startpos = i + (LCD_SIZE - IMAGE_HEIGHT) / 2; |
|||
graph_param.pixel_info.x_endpos = IMAGE_WIDTH - 1; |
|||
graph_param.pixel_info.y_endpos = i + (LCD_SIZE - IMAGE_HEIGHT) / 2; |
|||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER); |
|||
} |
|||
} |
|||
|
|||
// close test
|
|||
PrivClose(lcd_fd); |
|||
PrivClose(camera_fd); |
|||
printf("The camera test is finished successfully\n"); |
|||
} |
|||
|
|||
PRIV_SHELL_CMD_FUNCTION(TestCamera, a camera test sample, PRIV_SHELL_CMD_MAIN_ATTR); |
@ -0,0 +1,62 @@ |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <transform.h> |
|||
|
|||
#define MAX_READ_LENGTH 1000 |
|||
|
|||
// sd card here is loaded as "/"
|
|||
void TestFs(void) |
|||
{ |
|||
//open the file in sdcard
|
|||
int fd = open(FPATH,O_RDWR|O_CREAT); |
|||
if(fd<0){ |
|||
printf("fs fd open error:%d\n",fd); |
|||
return; |
|||
} |
|||
|
|||
char filewords[MAX_READ_LENGTH]; |
|||
memset(filewords,0,MAX_READ_LENGTH); |
|||
const char *input_words = "these words are going to write in fs\n"; |
|||
|
|||
//read and write then close file
|
|||
int err_flag = read(fd,filewords,MAX_READ_LENGTH); |
|||
if(err_flag<0){ |
|||
printf("read failed,error:%d\n",err_flag); |
|||
return; |
|||
} |
|||
printf("read data is \n%s\n",filewords); |
|||
|
|||
err_flag = write(fd,input_words,strlen(input_words)); |
|||
if(err_flag<0){ |
|||
printf("write failed,error:%d\n",err_flag); |
|||
return; |
|||
} |
|||
err_flag = close(fd); |
|||
if(err_flag<0){ |
|||
printf("close failed,error %d\n",err_flag); |
|||
return ; |
|||
} |
|||
|
|||
//re-open the file and re-read the file
|
|||
fd = open(FPATH,O_RDWR); |
|||
if(fd<0){ |
|||
printf("fs fd open error:%d\n",fd); |
|||
return; |
|||
} |
|||
err_flag = read(fd,filewords,MAX_READ_LENGTH); |
|||
if(err_flag<0){ |
|||
printf("read failed,error:%d\n",err_flag); |
|||
return; |
|||
} |
|||
|
|||
printf("read data is \n%s\n",filewords); |
|||
err_flag = close(fd); |
|||
if(err_flag<0){ |
|||
printf("close failed,error:%d\n",err_flag); |
|||
return; |
|||
} |
|||
|
|||
return; |
|||
} |
|||
|
|||
PRIV_SHELL_CMD_FUNCTION(TestFs, a sd or usb filesystem test sample, PRIV_SHELL_CMD_MAIN_ATTR); |
@ -0,0 +1,73 @@ |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <transform.h> |
|||
|
|||
#define BSP_LED_PIN 29 |
|||
#define BSP_KEY_PIN 31 |
|||
#define NULL_PARAMETER 0 |
|||
|
|||
void TestGpio(void) |
|||
{ |
|||
int pin_fd = PrivOpen(GPIO_DEV_DRIVER, O_RDWR); |
|||
if(pin_fd<0){ |
|||
printf("open pin fd error:%d\n",pin_fd); |
|||
return; |
|||
} |
|||
|
|||
//config led pin in board
|
|||
struct PinParam parameter; |
|||
parameter.cmd = GPIO_CONFIG_MODE; |
|||
parameter.pin = BSP_LED_PIN; |
|||
parameter.mode = GPIO_CFG_OUTPUT; |
|||
|
|||
struct PrivIoctlCfg ioctl_cfg; |
|||
ioctl_cfg.ioctl_driver_type = PIN_TYPE; |
|||
ioctl_cfg.args = (void *)¶meter; |
|||
|
|||
if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) { |
|||
printf("ioctl pin fd error %d\n", pin_fd); |
|||
PrivClose(pin_fd); |
|||
return; |
|||
} |
|||
|
|||
//config key pin in board
|
|||
parameter.pin = BSP_KEY_PIN; |
|||
parameter.mode = GPIO_CFG_INPUT; |
|||
|
|||
if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) { |
|||
printf("ioctl pin fd error %d\n", pin_fd); |
|||
PrivClose(pin_fd); |
|||
return; |
|||
} |
|||
|
|||
struct PinStat pin_led; |
|||
struct PinStat pin_key; |
|||
|
|||
pin_led.pin = BSP_LED_PIN; |
|||
pin_key.pin = BSP_KEY_PIN; |
|||
|
|||
//recycle read pin and write pin until key break
|
|||
while(1){ |
|||
if(0>PrivRead(pin_fd,&pin_key,NULL_PARAMETER)){ |
|||
printf("read pin fd error %d\n", pin_fd); |
|||
PrivClose(pin_fd); |
|||
return; |
|||
} |
|||
|
|||
//led on if key pressed,or led off
|
|||
if(pin_key.val){ |
|||
pin_led.val = GPIO_HIGH; |
|||
}else{ |
|||
pin_led.val = GPIO_LOW; |
|||
} |
|||
|
|||
if(0>PrivWrite(pin_fd,&pin_led,NULL_PARAMETER)){ |
|||
printf("write pin fd error %d\n", pin_fd); |
|||
PrivClose(pin_fd); |
|||
return; |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
PRIV_SHELL_CMD_FUNCTION(TestGpio, a gpio test sample, PRIV_SHELL_CMD_MAIN_ATTR); |
@ -0,0 +1,53 @@ |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <transform.h> |
|||
|
|||
#define BSP_LED_PIN 29 |
|||
#define NULL_PARAMETER 0 |
|||
|
|||
static uint16_t pinval=0; |
|||
static uint16_t pin_fd=0; |
|||
|
|||
void ledflip(void *parameter) |
|||
{ |
|||
struct PinStat pin_led; |
|||
pin_led.pin = BSP_LED_PIN; |
|||
pin_led.val = !pinval; |
|||
pinval = !pinval; |
|||
PrivWrite(pin_fd,&pin_led,NULL_PARAMETER); |
|||
// printf("Timer has callback once:%d\n",pinval);
|
|||
} |
|||
|
|||
void TestHwTimer(void) |
|||
{ |
|||
x_ticks_t period = 100;//uint:10ms
|
|||
|
|||
pin_fd = PrivOpen(HWTIMER_PIN_DEV_DRIVER, O_RDWR); |
|||
if(pin_fd<0){ |
|||
printf("open pin fd error:%d\n",pin_fd); |
|||
return; |
|||
} |
|||
|
|||
//config led pin in board
|
|||
struct PinParam parameter; |
|||
parameter.cmd = GPIO_CONFIG_MODE; |
|||
parameter.pin = BSP_LED_PIN; |
|||
parameter.mode = GPIO_CFG_OUTPUT; |
|||
|
|||
struct PrivIoctlCfg ioctl_cfg; |
|||
ioctl_cfg.ioctl_driver_type = PIN_TYPE; |
|||
ioctl_cfg.args = (void *)¶meter; |
|||
|
|||
if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) { |
|||
printf("ioctl pin fd error %d\n", pin_fd); |
|||
PrivClose(pin_fd); |
|||
return; |
|||
} |
|||
|
|||
int32 timer_handle = KCreateTimer("LED on and off by 1s",&ledflip,&pin_fd,period,TIMER_TRIGGER_PERIODIC); |
|||
|
|||
KTimerStartRun(timer_handle); |
|||
|
|||
} |
|||
|
|||
PRIV_SHELL_CMD_FUNCTION(TestHwTimer, a timer test sample, PRIV_SHELL_CMD_MAIN_ATTR); |
@ -0,0 +1,50 @@ |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <transform.h> |
|||
|
|||
#define I2C_SLAVE_ADDRESS 0x0012U |
|||
|
|||
void TestI2C(void) |
|||
{ |
|||
// config IIC pin(SCL:34.SDA:35) in menuconfig
|
|||
int iic_fd = PrivOpen(I2C_DEV_DRIVER, O_RDWR); |
|||
if (iic_fd < 0) |
|||
{ |
|||
printf("open iic_fd fd error:%d\n", iic_fd); |
|||
return; |
|||
} |
|||
printf("IIC open successful!\n"); |
|||
|
|||
// init iic
|
|||
uint16 iic_address = I2C_SLAVE_ADDRESS; |
|||
|
|||
struct PrivIoctlCfg ioctl_cfg; |
|||
ioctl_cfg.ioctl_driver_type = I2C_TYPE; |
|||
ioctl_cfg.args = (void *)&iic_address; |
|||
|
|||
if (0 != PrivIoctl(iic_fd, OPE_INT, &ioctl_cfg)) |
|||
{ |
|||
printf("ioctl iic fd error %d\n", iic_fd); |
|||
PrivClose(iic_fd); |
|||
return; |
|||
} |
|||
printf("IIC configure successful!\n"); |
|||
|
|||
// I2C read and write
|
|||
char tmp_buff[100]; |
|||
while (1) |
|||
{ |
|||
PrivTaskDelay(1000); |
|||
PrivWrite(iic_fd, "Hello World!\n", sizeof("Hello World!\n")); |
|||
printf("msg send:%s\n", "Hello World!\n"); |
|||
PrivTaskDelay(1000); |
|||
memset(tmp_buff, 0, sizeof(tmp_buff)); |
|||
PrivRead(iic_fd, tmp_buff, sizeof(tmp_buff)); |
|||
printf("msg recv:%s\n", tmp_buff); |
|||
} |
|||
|
|||
PrivClose(iic_fd); |
|||
return; |
|||
} |
|||
|
|||
PRIV_SHELL_CMD_FUNCTION(TestI2C, a iic test sample, PRIV_SHELL_CMD_MAIN_ATTR); |
@ -0,0 +1,50 @@ |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <transform.h> |
|||
|
|||
#define GRAPHIC_CTRL_RECT_UPDATE 0x00 |
|||
#define LCD_STRING_TYPE 0 |
|||
#define LCD_DOT_TYPE 1 |
|||
#define LCD_FONT_RECT_WIDTH 150 |
|||
#define LCD_FONT_RECT_HEIGHT 50 |
|||
#define NULL_PARAMETER 0 |
|||
|
|||
void TestLcd(void) |
|||
{ |
|||
int lcd_fd = PrivOpen(EDU_LCD_DEV_DRIVER, O_RDWR); |
|||
if (lcd_fd < 0) |
|||
{ |
|||
printf("open lcd fd error:%d\n", lcd_fd); |
|||
return; |
|||
} |
|||
|
|||
// draw text
|
|||
LcdWriteParam graph_param; |
|||
graph_param.type = LCD_STRING_TYPE; |
|||
graph_param.string_info.x_pos = 0; |
|||
graph_param.string_info.y_pos = 0; |
|||
graph_param.string_info.width = 250; |
|||
graph_param.string_info.height = 24; |
|||
graph_param.string_info.font_size = 24; |
|||
graph_param.string_info.back_color = 0xFFFF; |
|||
graph_param.string_info.font_color = 0x0000; |
|||
graph_param.string_info.addr = "hello_world!"; |
|||
|
|||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER); |
|||
|
|||
uint16 color_select = 0xF800; |
|||
for (int i = 0; i < 5; i++) |
|||
{ |
|||
graph_param.type = LCD_DOT_TYPE; |
|||
graph_param.pixel_info.x_startpos = 0; |
|||
graph_param.pixel_info.y_startpos = 50 * i; |
|||
graph_param.pixel_info.x_endpos = 320; |
|||
graph_param.pixel_info.y_endpos = 50 * i; |
|||
graph_param.pixel_info.pixel_color = &color_select; |
|||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER); |
|||
} |
|||
|
|||
PrivClose(lcd_fd); |
|||
} |
|||
|
|||
PRIV_SHELL_CMD_FUNCTION(TestLcd, a lcd test sample, PRIV_SHELL_CMD_MAIN_ATTR); |
@ -0,0 +1,147 @@ |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <transform.h> |
|||
|
|||
#define NULL_PARAMETER 0 |
|||
#define E220_CFG_LENGTH |
|||
#define GPIOSET(fd, buf, bit) \ |
|||
{ \ |
|||
buf.val = bit; \ |
|||
if (0 > PrivWrite(fd, &buf, NULL_PARAMETER)) \ |
|||
{ \ |
|||
printf("write pin fd error %d\n", fd); \ |
|||
PrivClose(fd); \ |
|||
return; \ |
|||
} \ |
|||
} |
|||
#define BSP_E220_M0_PIN 32 |
|||
#define BSP_E220_M1_PIN 33 |
|||
|
|||
void TestLora(int argc, char *argv[]) |
|||
{ |
|||
char uart_recvbuff[100]; |
|||
memset(uart_recvbuff, 0, sizeof(uart_recvbuff)); |
|||
|
|||
int pin_fd = PrivOpen(LORA_PIN_DEV_DRIVER, O_RDWR); |
|||
if (pin_fd < 0) |
|||
{ |
|||
printf("open pin fd error:%d\n", pin_fd); |
|||
return; |
|||
} |
|||
|
|||
int uart_fd = PrivOpen(LORA_UART_DEV_DRIVER, O_RDWR); |
|||
if (uart_fd < 0) |
|||
{ |
|||
printf("open pin fd error:%d\n", uart_fd); |
|||
return; |
|||
} |
|||
printf("uart and pin fopen success\n"); |
|||
|
|||
struct PinStat pin_m0; |
|||
struct PinStat pin_m1; |
|||
pin_m0.pin = BSP_E220_M0_PIN; |
|||
pin_m1.pin = BSP_E220_M1_PIN; |
|||
|
|||
// config led pin in board
|
|||
struct PrivIoctlCfg ioctl_cfg; |
|||
struct PinParam pin_param; |
|||
pin_param.cmd = GPIO_CONFIG_MODE; |
|||
pin_param.mode = GPIO_CFG_OUTPUT; |
|||
pin_param.pin = BSP_E220_M0_PIN; |
|||
ioctl_cfg.ioctl_driver_type = PIN_TYPE; |
|||
ioctl_cfg.args = &pin_param; |
|||
if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) |
|||
{ |
|||
printf("ioctl pin fd error %d\n", pin_fd); |
|||
PrivClose(pin_fd); |
|||
return; |
|||
} |
|||
|
|||
pin_param.pin = BSP_E220_M1_PIN; |
|||
if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) |
|||
{ |
|||
printf("ioctl pin fd error %d\n", pin_fd); |
|||
PrivClose(pin_fd); |
|||
return; |
|||
} |
|||
|
|||
printf("pin configure success\n"); |
|||
struct SerialDataCfg uart_cfg; |
|||
memset(&uart_cfg, 0, sizeof(struct SerialDataCfg)); |
|||
|
|||
// loraE220 support only 9600bps with 8N1 during initializing
|
|||
uart_cfg.serial_baud_rate = BAUD_RATE_9600; |
|||
uart_cfg.serial_data_bits = DATA_BITS_8; |
|||
uart_cfg.serial_stop_bits = STOP_BITS_1; |
|||
uart_cfg.serial_parity_mode = PARITY_NONE; |
|||
uart_cfg.serial_bit_order = BIT_ORDER_LSB; |
|||
uart_cfg.serial_invert_mode = NRZ_NORMAL; |
|||
uart_cfg.serial_buffer_size = SERIAL_RB_BUFSZ; |
|||
uart_cfg.serial_timeout = 1000; |
|||
uart_cfg.is_ext_uart = 0; |
|||
|
|||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE; |
|||
ioctl_cfg.args = (void *)&uart_cfg; |
|||
|
|||
if (0 != PrivIoctl(uart_fd, OPE_INT, &ioctl_cfg)) |
|||
{ |
|||
printf("ioctl uart fd error %d\n", uart_fd); |
|||
PrivClose(uart_fd); |
|||
return; |
|||
} |
|||
printf("uart configure success\n"); |
|||
|
|||
GPIOSET(pin_fd, pin_m0, GPIO_HIGH); |
|||
GPIOSET(pin_fd, pin_m1, GPIO_HIGH); |
|||
printf("lora configure into sleep(configure) mode\n"); |
|||
|
|||
// send configure data, and receive the same length of data
|
|||
char sendbuff[] = {0xC0, 0x00, 0x05, 0x19, 0x49, 0xE6, 0x00, 0x17}; // config as address 1949 CH17 36.8kps
|
|||
|
|||
PrivTaskDelay(2000); |
|||
|
|||
printf("Sending lora configure information(SIZE:%d)\n", sizeof(sendbuff)); |
|||
PrivWrite(uart_fd, sendbuff, sizeof(sendbuff)); |
|||
printf("lora configure information send\n"); |
|||
|
|||
PrivTaskDelay(2000); |
|||
|
|||
PrivRead(uart_fd, uart_recvbuff, sizeof(sendbuff)); |
|||
printf("%x %x %x %x", uart_recvbuff[0], uart_recvbuff[1], uart_recvbuff[2], uart_recvbuff[3]); |
|||
printf("lora configure success\n"); |
|||
|
|||
// error when all bytes are 0xff
|
|||
if (0xFF == (uart_recvbuff[0] & uart_recvbuff[1] & uart_recvbuff[2])) |
|||
{ |
|||
printf("from lora receive error:%d\n", 0xff); |
|||
return; |
|||
} |
|||
|
|||
uart_cfg.serial_baud_rate = BAUD_RATE_115200; |
|||
if (0 != PrivIoctl(uart_fd, OPE_INT, &ioctl_cfg)) |
|||
{ |
|||
printf("ioctl uart fd error %d\n", uart_fd); |
|||
PrivClose(uart_fd); |
|||
return; |
|||
} |
|||
|
|||
// into transparent transmission mode
|
|||
GPIOSET(pin_fd, pin_m0, GPIO_LOW); |
|||
GPIOSET(pin_fd, pin_m1, GPIO_LOW); |
|||
// receive and send "Hello World"
|
|||
while (1) |
|||
{ |
|||
PrivTaskDelay(500); |
|||
PrivWrite(uart_fd, "Hello_World!", sizeof("Hello_World!")); |
|||
printf("Data Send:\n%s\n", "Hello_World!"); |
|||
|
|||
PrivTaskDelay(500); |
|||
memset(uart_recvbuff, 0, sizeof(uart_recvbuff)); |
|||
PrivRead(uart_fd, uart_recvbuff, sizeof(uart_recvbuff)); |
|||
printf("Receive Data is :\n%s\n", uart_recvbuff); |
|||
} |
|||
PrivClose(pin_fd); |
|||
PrivClose(uart_fd); |
|||
} |
|||
|
|||
PRIV_SHELL_CMD_FUNCTION(TestLora, a lora test sample, PRIV_SHELL_CMD_MAIN_ATTR); |
@ -0,0 +1,103 @@ |
|||
/*
|
|||
* Copyright (c) 2020 AIIT XUOS Lab |
|||
* XiUOS is licensed under Mulan PSL v2. |
|||
* You can use this software according to the terms and conditions of the Mulan PSL v2. |
|||
* You may obtain a copy of Mulan PSL v2 at: |
|||
* http://license.coscl.org.cn/MulanPSL2
|
|||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, |
|||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, |
|||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. |
|||
* See the Mulan PSL v2 for more details. |
|||
*/ |
|||
|
|||
/**
|
|||
* @file: test_musl.c |
|||
* @brief: a application of musl test function |
|||
* @version: 2.0 |
|||
* @author: AIIT XUOS Lab |
|||
* @date: 2022/11/8 |
|||
*/ |
|||
|
|||
#include <transform.h> |
|||
|
|||
#ifdef ADD_NUTTX_FETURES |
|||
|
|||
#if defined(CONFIG_MUSL_LIBC) && defined(CONFIG_FS_AUTOMOUNTER) |
|||
|
|||
static void file_read_and_write(void) |
|||
{ |
|||
FILE *p; |
|||
char s[] = "good luck to you!"; |
|||
char buffer[20]; |
|||
|
|||
if((p = fopen("/mnt/sdcard/test.txt","w+")) == NULL) |
|||
{ |
|||
printf("Can not open file!\n"); |
|||
} |
|||
fwrite(s, sizeof(s) + 1, 1, p); |
|||
fseek(p, SEEK_SET, 0); |
|||
fread(buffer, sizeof(buffer) + 1, 1, p); |
|||
printf("read string is: %s\n", buffer); |
|||
fclose(p); |
|||
} |
|||
|
|||
static void file_operations(void) |
|||
{ |
|||
int ret; |
|||
FILE *fp; |
|||
char filename1[] = "/mnt/sdcard/file1.txt"; |
|||
char filename2[] = "/mnt/sdcard/file2.txt"; |
|||
|
|||
fp = fopen(filename1, "w"); |
|||
|
|||
fprintf(fp, "%s", "this is runoob.com"); |
|||
fclose(fp); |
|||
|
|||
ret = remove(filename1); |
|||
|
|||
if(ret == 0) |
|||
{ |
|||
printf("remove file1 success!\n"); |
|||
} |
|||
else |
|||
{ |
|||
printf("error,can not remove file1!\n"); |
|||
} |
|||
|
|||
ret = remove(filename2); |
|||
if(ret == 0) |
|||
{ |
|||
printf("remove file2 success!\n"); |
|||
} |
|||
else |
|||
{ |
|||
printf("error,can not remove file2!\n"); |
|||
} |
|||
} |
|||
|
|||
static void malloc_and_free(void) |
|||
{ |
|||
int *p; |
|||
int len; |
|||
for(int i = 0; i < 100; i++) |
|||
{ |
|||
len = 1024*(i+1); |
|||
p = malloc(len); |
|||
if(p) |
|||
{ |
|||
printf("malloc %d bytes success!\n",len); |
|||
free(p); |
|||
} |
|||
} |
|||
} |
|||
void Testmusl(void) |
|||
{ |
|||
printf("--------start test file read and write!--------\n"); |
|||
file_read_and_write(); |
|||
printf("----------start test file operationsn!---------\n"); |
|||
file_operations(); |
|||
printf("---------start test malloc and free!-----------\n"); |
|||
malloc_and_free(); |
|||
} |
|||
#endif |
|||
#endif |
@ -0,0 +1,86 @@ |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <transform.h> |
|||
|
|||
#define BSP_485_DIR_PIN 24 |
|||
|
|||
void Test485(void) |
|||
{ |
|||
int pin_fd = PrivOpen(RS485_PIN_DEV_DRIVER, O_RDWR); |
|||
if (pin_fd < 0) |
|||
{ |
|||
printf("open pin fd error:%d\n", pin_fd); |
|||
return; |
|||
} |
|||
|
|||
int uart_fd = PrivOpen(RS485_UART_DEV_DRIVER, O_RDWR); |
|||
if (uart_fd < 0) |
|||
{ |
|||
printf("open pin fd error:%d\n", uart_fd); |
|||
return; |
|||
} |
|||
printf("uart and pin fopen success\n"); |
|||
|
|||
//config led pin in board
|
|||
struct PinParam pin_parameter; |
|||
memset(&pin_parameter, 0, sizeof(struct PinParam)); |
|||
pin_parameter.cmd = GPIO_CONFIG_MODE; |
|||
pin_parameter.pin = BSP_485_DIR_PIN; |
|||
pin_parameter.mode = GPIO_CFG_OUTPUT; |
|||
|
|||
struct PrivIoctlCfg ioctl_cfg; |
|||
ioctl_cfg.ioctl_driver_type = PIN_TYPE; |
|||
ioctl_cfg.args = (void *)&pin_parameter; |
|||
|
|||
if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) { |
|||
printf("ioctl pin fd error %d\n", pin_fd); |
|||
PrivClose(pin_fd); |
|||
return; |
|||
} |
|||
|
|||
struct SerialDataCfg uart_cfg; |
|||
memset(&uart_cfg, 0, sizeof(struct SerialDataCfg)); |
|||
|
|||
uart_cfg.serial_baud_rate = BAUD_RATE_115200; |
|||
uart_cfg.serial_data_bits = DATA_BITS_8; |
|||
uart_cfg.serial_stop_bits = STOP_BITS_1; |
|||
uart_cfg.serial_parity_mode = PARITY_NONE; |
|||
uart_cfg.serial_bit_order = BIT_ORDER_LSB; |
|||
uart_cfg.serial_invert_mode = NRZ_NORMAL; |
|||
uart_cfg.serial_buffer_size = SERIAL_RB_BUFSZ; |
|||
uart_cfg.serial_timeout = 1000; |
|||
uart_cfg.is_ext_uart = 0; |
|||
|
|||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE; |
|||
ioctl_cfg.args = (void *)&uart_cfg; |
|||
|
|||
if (0 != PrivIoctl(uart_fd, OPE_INT, &ioctl_cfg)) |
|||
{ |
|||
printf("ioctl uart fd error %d\n", uart_fd); |
|||
PrivClose(uart_fd); |
|||
return; |
|||
} |
|||
|
|||
struct PinStat pin_dir; |
|||
pin_dir.pin = BSP_485_DIR_PIN; |
|||
while (1) |
|||
{ |
|||
pin_dir.val = GPIO_HIGH; |
|||
PrivWrite(pin_fd,&pin_dir,0); |
|||
PrivWrite(uart_fd,"Hello world!\n",sizeof("Hello world!\n")); |
|||
PrivTaskDelay(100); |
|||
|
|||
pin_dir.val = GPIO_LOW; |
|||
PrivWrite(pin_fd,&pin_dir,0); |
|||
char recv_buff[100]; |
|||
memset(recv_buff,0,sizeof(recv_buff)); |
|||
PrivRead(uart_fd,recv_buff,20); |
|||
printf("%s",recv_buff); |
|||
PrivTaskDelay(100); |
|||
} |
|||
PrivClose(pin_fd); |
|||
PrivClose(uart_fd); |
|||
return; |
|||
} |
|||
|
|||
PRIV_SHELL_CMD_FUNCTION(Test485, a RS485 test sample, PRIV_SHELL_CMD_MAIN_ATTR); |
@ -0,0 +1,38 @@ |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <transform.h> |
|||
|
|||
void TestRTC(int argc,char *argv[]) |
|||
{ |
|||
int rtc_fd = PrivOpen(RTC_DEV_DRIVER, O_RDWR); |
|||
if(rtc_fd<0){ |
|||
printf("open rtc fd error:%d\n",rtc_fd); |
|||
return; |
|||
} |
|||
|
|||
if(argc>1){ |
|||
|
|||
int times = atoi(argv[1]); |
|||
printf("Time will be printf %d times\n",times); |
|||
struct RtcDrvConfigureParam rtc_para; |
|||
rtc_para.rtc_operation_cmd = OPER_RTC_SET_TIME; |
|||
*(rtc_para.time) = 0; |
|||
|
|||
struct PrivIoctlCfg ioctl_cfg; |
|||
ioctl_cfg.ioctl_driver_type = RTC_TYPE; |
|||
ioctl_cfg.args = (void *)&rtc_para; |
|||
PrivIoctl(rtc_fd,0,&ioctl_cfg); |
|||
|
|||
rtc_para.rtc_operation_cmd = OPER_RTC_GET_TIME; |
|||
for(size_t i=0;i<times;i++){ |
|||
PrivIoctl(rtc_fd,0,&ioctl_cfg); |
|||
printf("The time now is %d\n",*(rtc_para.time)); |
|||
PrivTaskDelay(5000); |
|||
} |
|||
} |
|||
|
|||
PrivClose(rtc_fd); |
|||
return; |
|||
} |
|||
|
|||
PRIV_SHELL_CMD_FUNCTION(TestRTC, a rtc test sample, PRIV_SHELL_CMD_MAIN_ATTR); |
@ -0,0 +1,111 @@ |
|||
/****************************************************************************
|
|||
* apps/examples/fb/fb_main.c |
|||
* |
|||
* Licensed to the Apache Software Foundation (ASF) under one or more |
|||
* contributor license agreements. See the NOTICE file distributed with |
|||
* this work for additional information regarding copyright ownership. The |
|||
* ASF licenses this file to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance with the |
|||
* License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|||
* License for the specific language governing permissions and limitations |
|||
* under the License. |
|||
* |
|||
****************************************************************************/ |
|||
|
|||
/****************************************************************************
|
|||
* Included Files |
|||
****************************************************************************/ |
|||
|
|||
#include <transform.h> |
|||
|
|||
#ifdef ADD_NUTTX_FETURES |
|||
|
|||
#ifdef CONFIG_BSP_USING_TOUCH |
|||
void TestTouch(void) |
|||
{ |
|||
int fd; |
|||
TouchDataParam point = {0, 0, 0}; |
|||
fd = PrivOpen("/dev/touch_dev", O_RDWR); |
|||
while(1) |
|||
{ |
|||
PrivRead(fd,&point,1); |
|||
printf("Now touch point:(%d,%d)\n",point.x,point.y); |
|||
} |
|||
} |
|||
#endif |
|||
|
|||
#endif |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <transform.h> |
|||
|
|||
#define NULL_PARAMETER 0 |
|||
#define LCD_DOT_TYPE 1 |
|||
#define LCD_SIZE 320 |
|||
|
|||
|
|||
void TestTouch(void) |
|||
{ |
|||
int touch_fd = PrivOpen(TOUCH_DEV_DRIVER, O_RDWR); |
|||
if (touch_fd < 0) |
|||
{ |
|||
printf("open touch fd error:%d\n", touch_fd); |
|||
return; |
|||
} |
|||
int lcd_fd = PrivOpen(TOUCH_LCD_DEV_DRIVER, O_RDWR); |
|||
if (lcd_fd < 0) |
|||
{ |
|||
printf("open lcd fd error:%d\n", lcd_fd); |
|||
return; |
|||
} |
|||
|
|||
// draw text
|
|||
struct TouchDataStandard touch_pixel; |
|||
memset(&touch_pixel,0,sizeof(touch_pixel)); |
|||
LcdWriteParam graph_param; |
|||
|
|||
|
|||
graph_param.type = LCD_DOT_TYPE; |
|||
|
|||
uint16_t back_color[LCD_SIZE]; |
|||
memset(back_color,0x00,sizeof(back_color)); |
|||
for (int i = 0; i < LCD_SIZE; i++) |
|||
{ |
|||
graph_param.pixel_info.pixel_color = &back_color; |
|||
graph_param.pixel_info.x_startpos = 0; |
|||
graph_param.pixel_info.y_startpos = i; |
|||
graph_param.pixel_info.x_endpos = LCD_SIZE -1; |
|||
graph_param.pixel_info.y_endpos = i; |
|||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER); |
|||
} |
|||
|
|||
uint16 color_select[LCD_SIZE]; |
|||
memset(color_select,0xff,sizeof(color_select)); |
|||
graph_param.pixel_info.pixel_color = &color_select; |
|||
while(1){ |
|||
if(0 > PrivRead(touch_fd, &touch_pixel, NULL_PARAMETER)){ |
|||
printf("read touch error\n"); |
|||
return; |
|||
} |
|||
printf("touch pixel position x:%d,y:%d\n",touch_pixel.x,touch_pixel.y); |
|||
graph_param.pixel_info.x_startpos = touch_pixel.x-10>0?touch_pixel.x-10:0; |
|||
graph_param.pixel_info.y_startpos = touch_pixel.y; |
|||
graph_param.pixel_info.x_endpos = touch_pixel.x+10; |
|||
graph_param.pixel_info.y_endpos = touch_pixel.y; |
|||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER); |
|||
graph_param.pixel_info.x_startpos = touch_pixel.x; |
|||
graph_param.pixel_info.y_startpos = touch_pixel.y-10>0?touch_pixel.y-10:0; |
|||
graph_param.pixel_info.x_endpos = touch_pixel.x; |
|||
graph_param.pixel_info.y_endpos = touch_pixel.y+10; |
|||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER); |
|||
} |
|||
PrivClose(touch_fd); |
|||
} |
|||
|
|||
PRIV_SHELL_CMD_FUNCTION(TestTouch, a touch test sample, PRIV_SHELL_CMD_MAIN_ATTR); |
@ -0,0 +1,45 @@ |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <transform.h> |
|||
|
|||
void TestWDT(int argc, char *agrv[]) |
|||
{ |
|||
int wdt_fd = PrivOpen(WDT0_DEV_DRIVER, O_RDWR); |
|||
if (wdt_fd < 0) |
|||
{ |
|||
printf("open wdt_fd fd error:%d\n", wdt_fd); |
|||
return; |
|||
} |
|||
printf("hw watchdog open!\n"); |
|||
|
|||
// init watchdog
|
|||
int wdt_time = 1000; |
|||
|
|||
struct PrivIoctlCfg ioctl_cfg; |
|||
ioctl_cfg.ioctl_driver_type = WDT_TYPE; |
|||
ioctl_cfg.args = (void *)&wdt_time; |
|||
|
|||
if (0 != PrivIoctl(wdt_fd, OPER_WDT_SET_TIMEOUT, &ioctl_cfg)) |
|||
{ |
|||
printf("ioctl wdt fd error %d\n", wdt_fd); |
|||
PrivClose(wdt_fd); |
|||
return; |
|||
} |
|||
|
|||
int test_counter = 100; |
|||
|
|||
// wdt feed or not according to argc,if argc!=1 then dog won't be feed
|
|||
while (test_counter--) |
|||
{ |
|||
if (1 == argc) |
|||
{ |
|||
printf("dog is feed\n"); |
|||
PrivIoctl(wdt_fd, OPER_WDT_KEEPALIVE, &ioctl_cfg); // feed dog
|
|||
} |
|||
PrivTaskDelay(100); |
|||
} |
|||
PrivClose(wdt_fd); |
|||
return; |
|||
} |
|||
|
|||
PRIV_SHELL_CMD_FUNCTION(TestWDT, a wdt test sample, PRIV_SHELL_CMD_MAIN_ATTR); |