forked from xuos/xiuos
adapt qs-fs and qs-fx for edu-riscv64
This commit is contained in:
parent
100fe8c2d0
commit
a782b53423
|
@ -29,7 +29,14 @@ void WindDirectionQsFx(void)
|
||||||
struct SensorQuantity *wind_direction = SensorQuantityFind(SENSOR_QUANTITY_QS_FX_WINDDIRECTION, SENSOR_QUANTITY_WINDDIRECTION);
|
struct SensorQuantity *wind_direction = SensorQuantityFind(SENSOR_QUANTITY_QS_FX_WINDDIRECTION, SENSOR_QUANTITY_WINDDIRECTION);
|
||||||
SensorQuantityOpen(wind_direction);
|
SensorQuantityOpen(wind_direction);
|
||||||
PrivTaskDelay(2000);
|
PrivTaskDelay(2000);
|
||||||
uint16_t result = SensorQuantityReadValue(wind_direction);
|
int result = 0;
|
||||||
|
for(int i=0;i<2000;i++)
|
||||||
|
{
|
||||||
|
result = 0;
|
||||||
|
PrivTaskDelay(1000);
|
||||||
|
result = SensorQuantityReadValue(wind_direction);
|
||||||
|
if(result > 0)
|
||||||
printf("wind direction : %d degree\n", result);
|
printf("wind direction : %d degree\n", result);
|
||||||
|
}
|
||||||
SensorQuantityClose(wind_direction);
|
SensorQuantityClose(wind_direction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,14 @@ void WindSpeedQsFs(void)
|
||||||
struct SensorQuantity *wind_speed = SensorQuantityFind(SENSOR_QUANTITY_QS_FS_WINDSPEED, SENSOR_QUANTITY_WINDSPEED);
|
struct SensorQuantity *wind_speed = SensorQuantityFind(SENSOR_QUANTITY_QS_FS_WINDSPEED, SENSOR_QUANTITY_WINDSPEED);
|
||||||
SensorQuantityOpen(wind_speed);
|
SensorQuantityOpen(wind_speed);
|
||||||
PrivTaskDelay(2000);
|
PrivTaskDelay(2000);
|
||||||
uint16_t result = SensorQuantityReadValue(wind_speed);
|
int result = 0;
|
||||||
|
for(int i=0;i<2000;i++)
|
||||||
|
{
|
||||||
|
result = 0;
|
||||||
|
PrivTaskDelay(1000);
|
||||||
|
result = SensorQuantityReadValue(wind_speed);
|
||||||
|
if(result > 0)
|
||||||
printf("wind speed : %d.%d m/s\n", result/10, result%10);
|
printf("wind speed : %d.%d m/s\n", result/10, result%10);
|
||||||
|
}
|
||||||
SensorQuantityClose(wind_speed);
|
SensorQuantityClose(wind_speed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,14 @@ config SENSOR_QS_FX
|
||||||
default "/dev/uart2_dev2"
|
default "/dev/uart2_dev2"
|
||||||
depends on !SENSOR_QS_FX_DRIVER_EXTUART
|
depends on !SENSOR_QS_FX_DRIVER_EXTUART
|
||||||
|
|
||||||
|
config SENSOR_DEVICE_QS_FX_PIN_DEV
|
||||||
|
string "qs-fx pin device name"
|
||||||
|
default "/dev/pin_dev"
|
||||||
|
|
||||||
|
config SENSOR_DEVICE_QS_FX_PIN_NUMBER
|
||||||
|
int "qs-fx pin device number"
|
||||||
|
default 24
|
||||||
|
|
||||||
if SENSOR_QS_FX_DRIVER_EXTUART
|
if SENSOR_QS_FX_DRIVER_EXTUART
|
||||||
config SENSOR_DEVICE_QS_FX_DEV
|
config SENSOR_DEVICE_QS_FX_DEV
|
||||||
string "qs-fx device extra uart path"
|
string "qs-fx device extra uart path"
|
||||||
|
|
|
@ -53,6 +53,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||||
cfg.serial_parity_mode = PARITY_NONE;
|
cfg.serial_parity_mode = PARITY_NONE;
|
||||||
cfg.serial_bit_order = 0;
|
cfg.serial_bit_order = 0;
|
||||||
cfg.serial_invert_mode = 0;
|
cfg.serial_invert_mode = 0;
|
||||||
|
cfg.serial_timeout = 1000;
|
||||||
cfg.is_ext_uart = 0;
|
cfg.is_ext_uart = 0;
|
||||||
#ifdef SENSOR_QS_FX_DRIVER_EXTUART
|
#ifdef SENSOR_QS_FX_DRIVER_EXTUART
|
||||||
cfg.is_ext_uart = 1;
|
cfg.is_ext_uart = 1;
|
||||||
|
@ -68,6 +69,33 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int PinOpen(void){
|
||||||
|
int pin_fd = PrivOpen(SENSOR_DEVICE_QS_FX_PIN_DEV, O_RDWR);
|
||||||
|
if (pin_fd < 0) {
|
||||||
|
printf("open %s error\n", SENSOR_DEVICE_QS_FX_PIN_DEV);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//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 = SENSOR_DEVICE_QS_FX_PIN_NUMBER;
|
||||||
|
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 -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pin_fd;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: Read sensor device
|
* @description: Read sensor device
|
||||||
* @param sdev - sensor device pointer
|
* @param sdev - sensor device pointer
|
||||||
|
@ -76,12 +104,25 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||||
*/
|
*/
|
||||||
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
||||||
{
|
{
|
||||||
|
int pin_fd=PinOpen();
|
||||||
|
struct PinStat pin_dir;
|
||||||
|
pin_dir.pin = SENSOR_DEVICE_QS_FX_PIN_NUMBER;
|
||||||
|
|
||||||
|
pin_dir.val = GPIO_HIGH;
|
||||||
|
if (PrivWrite(pin_fd,&pin_dir,0) < 0) // pull-up pin to configure as tx mode
|
||||||
|
return -1;
|
||||||
|
PrivTaskDelay(20);
|
||||||
if (PrivWrite(sdev->fd, instructions, sizeof(instructions)) < 0)
|
if (PrivWrite(sdev->fd, instructions, sizeof(instructions)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
PrivTaskDelay(20);
|
||||||
|
pin_dir.val = GPIO_LOW;
|
||||||
|
if (PrivWrite(pin_fd,&pin_dir,0) < 0) // pull-down pin to configure as rx mode
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (PrivRead(sdev->fd, sdev->buffer, len) < 0)
|
if (PrivRead(sdev->fd, sdev->buffer, len) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
PrivClose(pin_fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +165,10 @@ static int32_t ReadWindDirection(struct SensorQuantity *quant)
|
||||||
short result;
|
short result;
|
||||||
if (quant->sdev->done->read != NULL) {
|
if (quant->sdev->done->read != NULL) {
|
||||||
if (quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
|
if (quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
|
||||||
quant->sdev->done->read(quant->sdev, 6);
|
quant->sdev->done->read(quant->sdev, 7);
|
||||||
|
if(Crc16(quant->sdev->buffer,7)!=0x00){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
result = (quant->sdev->buffer[3] << 8) | quant->sdev->buffer[4];
|
result = (quant->sdev->buffer[3] << 8) | quant->sdev->buffer[4];
|
||||||
|
|
||||||
return (int32_t)result;
|
return (int32_t)result;
|
||||||
|
|
|
@ -19,9 +19,17 @@ config SENSOR_QS_FS
|
||||||
|
|
||||||
config SENSOR_DEVICE_QS_FS_DEV
|
config SENSOR_DEVICE_QS_FS_DEV
|
||||||
string "qs-fx device name"
|
string "qs-fx device name"
|
||||||
default "/dev/uart2_dev2"
|
default "/dev/uart1_dev1"
|
||||||
depends on !SENSOR_QS_FS_DRIVER_EXTUART
|
depends on !SENSOR_QS_FS_DRIVER_EXTUART
|
||||||
|
|
||||||
|
config SENSOR_DEVICE_QS_FS_PIN_DEV
|
||||||
|
string "qs-fx pin device name"
|
||||||
|
default "/dev/pin_dev"
|
||||||
|
|
||||||
|
config SENSOR_DEVICE_QS_FS_PIN_NUMBER
|
||||||
|
int "qs-fs pin device number"
|
||||||
|
default 24
|
||||||
|
|
||||||
if SENSOR_QS_FS_DRIVER_EXTUART
|
if SENSOR_QS_FS_DRIVER_EXTUART
|
||||||
config SENSOR_DEVICE_QS_FS_DEV
|
config SENSOR_DEVICE_QS_FS_DEV
|
||||||
string "qs-fx device extra uart path"
|
string "qs-fx device extra uart path"
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
|
|
||||||
static struct SensorDevice qs_fs;
|
static struct SensorDevice qs_fs;
|
||||||
static const unsigned char instructions[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
|
static const unsigned char instructions[] = {0x02,0x03,0x00,0x00,0x00,0x01,0x84,0x39};
|
||||||
|
|
||||||
static struct SensorProductInfo info =
|
static struct SensorProductInfo info =
|
||||||
{
|
{
|
||||||
|
@ -68,6 +68,34 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int PinOpen(void){
|
||||||
|
int pin_fd = PrivOpen(SENSOR_DEVICE_QS_FS_PIN_DEV, O_RDWR);
|
||||||
|
if (pin_fd < 0) {
|
||||||
|
printf("open %s error\n", SENSOR_DEVICE_QS_FS_PIN_DEV);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//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 = SENSOR_DEVICE_QS_FS_PIN_NUMBER;
|
||||||
|
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 -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pin_fd;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: Read sensor device
|
* @description: Read sensor device
|
||||||
* @param sdev - sensor device pointer
|
* @param sdev - sensor device pointer
|
||||||
|
@ -76,12 +104,27 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||||
*/
|
*/
|
||||||
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
||||||
{
|
{
|
||||||
|
int pin_fd=PinOpen();
|
||||||
|
struct PinStat pin_dir;
|
||||||
|
pin_dir.pin = SENSOR_DEVICE_QS_FS_PIN_NUMBER;
|
||||||
|
|
||||||
|
pin_dir.val = GPIO_HIGH;
|
||||||
|
if (PrivWrite(pin_fd,&pin_dir,0) < 0) // pull-up pin to configure as tx mode
|
||||||
|
return -1;
|
||||||
|
PrivTaskDelay(20);
|
||||||
if (PrivWrite(sdev->fd, instructions, sizeof(instructions)) < 0)
|
if (PrivWrite(sdev->fd, instructions, sizeof(instructions)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
PrivTaskDelay(20);
|
||||||
|
|
||||||
|
|
||||||
|
pin_dir.val = GPIO_LOW;
|
||||||
|
if (PrivWrite(pin_fd,&pin_dir,0) < 0) // pull-down pin to configure as rx mode
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (PrivRead(sdev->fd, sdev->buffer, len) < 0)
|
if (PrivRead(sdev->fd, sdev->buffer, len) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
PrivClose(pin_fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +167,10 @@ static int32_t ReadWindSpeed(struct SensorQuantity *quant)
|
||||||
short result;
|
short result;
|
||||||
if (quant->sdev->done->read != NULL) {
|
if (quant->sdev->done->read != NULL) {
|
||||||
if (quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
|
if (quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
|
||||||
quant->sdev->done->read(quant->sdev, 6);
|
quant->sdev->done->read(quant->sdev, 7);
|
||||||
|
if(Crc16(quant->sdev->buffer,7)!=0x00){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
result = (quant->sdev->buffer[3] << 8) | quant->sdev->buffer[4];
|
result = (quant->sdev->buffer[3] << 8) | quant->sdev->buffer[4];
|
||||||
|
|
||||||
return (int32_t)result;
|
return (int32_t)result;
|
||||||
|
|
|
@ -111,16 +111,20 @@ static struct io_config
|
||||||
IOCONFIG(BSP_E220_M1_PIN, HS_GPIO(FUNC_GPIOHS11)),
|
IOCONFIG(BSP_E220_M1_PIN, HS_GPIO(FUNC_GPIOHS11)),
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BSP_USING_RS485
|
#ifdef USER_TEST_RS485
|
||||||
IOCONFIG(BSP_485_DIR_PIN,HS_GPIO(FUNC_GPIOHS12));
|
IOCONFIG(BSP_485_DIR_PIN,HS_GPIO(FUNC_GPIOHS12)),
|
||||||
|
#elif defined SENSOR_QS_FX
|
||||||
|
IOCONFIG(BSP_485_DIR_PIN,HS_GPIO(FUNC_GPIOHS12)),
|
||||||
|
#elif defined SENSOR_QS_FS
|
||||||
|
IOCONFIG(BSP_485_DIR_PIN,HS_GPIO(FUNC_GPIOHS12)),
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BSP_USING_LED
|
#ifdef BSP_USING_LED
|
||||||
IOCONFIG(BSP_LED_PIN,FUNC_GPIO5);
|
IOCONFIG(BSP_LED_PIN,FUNC_GPIO5),
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BSP_USING_KEY
|
#ifdef BSP_USING_KEY
|
||||||
IOCONFIG(BSP_KEY_PIN,FUNC_GPIO6);
|
IOCONFIG(BSP_KEY_PIN,FUNC_GPIO6),
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,11 @@ enum HS_GPIO_CONFIG {
|
||||||
#define BSP_E220_M1_PIN 33
|
#define BSP_E220_M1_PIN 33
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BSP_USING_RS485
|
#ifdef USER_TEST_RS485
|
||||||
|
#define BSP_485_DIR_PIN 24
|
||||||
|
#elif defined SENSOR_QS_FX
|
||||||
|
#define BSP_485_DIR_PIN 24
|
||||||
|
#elif defined SENSOR_QS_FS
|
||||||
#define BSP_485_DIR_PIN 24
|
#define BSP_485_DIR_PIN 24
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue