Skip to content

Commit c21405d

Browse files
chenzihan0416acassis
authored andcommitted
drivers/sensors/goldfish: goldfish support more sensors
add sensors type to align android Signed-off-by: chenzihan1 <chenzihan1@xiaomi.com>
1 parent 6beaf12 commit c21405d

File tree

2 files changed

+649
-320
lines changed

2 files changed

+649
-320
lines changed
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
=======================
2+
Goldfish Sensor Driver
3+
=======================
4+
5+
Introduction
6+
============
7+
8+
The Goldfish Sensor driver provides a virtual multi-sensor interface for
9+
Android Goldfish/QEMU emulator environments. This driver enables NuttX to
10+
interact with the QEMU sensor emulation infrastructure, allowing applications
11+
to access various simulated sensor types without requiring physical hardware.
12+
13+
The driver supports multiple sensor types through a unified interface based
14+
on the NuttX sensor framework (uORB), making it suitable for development,
15+
testing, and debugging of sensor-dependent applications in virtualized
16+
environments.
17+
18+
Supported Sensor Types
19+
=======================
20+
21+
The Goldfish Sensor driver supports the following sensor types:
22+
23+
Inertial Sensors
24+
----------------
25+
26+
- **Accelerometer** (``SENSOR_TYPE_ACCELEROMETER``)
27+
28+
- Measures linear acceleration in three axes (x, y, z)
29+
- Range: ±2.8 m/s²
30+
- Resolution: 1.0/4032.0 m/s²
31+
- Power consumption: 3.0 mW
32+
33+
- **Gyroscope** (``SENSOR_TYPE_GYROSCOPE``)
34+
35+
- Measures angular velocity in three axes
36+
- Range: ±11.11 rad/s
37+
- Resolution: 1.0/1000.0 rad/s
38+
- Power consumption: 3.0 mW
39+
40+
- **Uncalibrated Accelerometer** (``SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED``)
41+
42+
- Raw accelerometer data without calibration
43+
- Range: ±39.3 m/s²
44+
- Resolution: 1.0/4032.0 m/s²
45+
46+
- **Uncalibrated Gyroscope** (``SENSOR_TYPE_GYROSCOPE_UNCALIBRATED``)
47+
48+
- Raw gyroscope data without drift compensation
49+
- Range: ±16.46 rad/s
50+
- Resolution: 1.0/1000.0 rad/s
51+
52+
Magnetic Sensors
53+
----------------
54+
55+
- **Magnetometer** (``SENSOR_TYPE_MAGNETIC_FIELD``)
56+
57+
- Measures magnetic field strength in three axes
58+
- Range: ±2000.0 μT
59+
- Resolution: 1.0 μT
60+
- Power consumption: 6.7 mW
61+
62+
- **Uncalibrated Magnetometer** (``SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED``)
63+
64+
- Raw magnetic field data without hard/soft iron correction
65+
- Range: ±2000.0 μT
66+
- Resolution: 1.0 μT
67+
68+
Environmental Sensors
69+
---------------------
70+
71+
- **Ambient Temperature** (``SENSOR_TYPE_AMBIENT_TEMPERATURE``)
72+
73+
- Measures ambient temperature
74+
- Range: 0-80°C
75+
- Resolution: 1.0°C
76+
- Power consumption: 0.0 mW
77+
78+
- **Barometric Pressure** (``SENSOR_TYPE_BAROMETER``)
79+
80+
- Measures atmospheric pressure
81+
- Range: 0-800 hPa
82+
- Resolution: 1.0 hPa
83+
- Power consumption: 20.0 mW
84+
85+
- **Relative Humidity** (``SENSOR_TYPE_RELATIVE_HUMIDITY``)
86+
87+
- Measures relative humidity
88+
- Range: 0-100%
89+
- Resolution: 1.0%
90+
- Power consumption: 20.0 mW
91+
92+
Optical Sensors
93+
---------------
94+
95+
- **Ambient Light** (``SENSOR_TYPE_LIGHT``)
96+
97+
- Measures ambient light intensity
98+
- Range: 0-40000 lux
99+
- Resolution: 1.0 lux
100+
- Power consumption: 20.0 mW
101+
102+
- **Proximity** (``SENSOR_TYPE_PROXIMITY``)
103+
104+
- Detects nearby objects
105+
- Range: 0-1.0 (binary detection)
106+
- Resolution: 1.0
107+
- Power consumption: 20.0 mW
108+
109+
Orientation Sensors
110+
-------------------
111+
112+
- **Orientation** (``SENSOR_TYPE_ORIENTATION``)
113+
114+
- Provides device orientation (azimuth, pitch, roll)
115+
- Range: 0-360°
116+
- Resolution: 1.0°
117+
- Power consumption: 9.7 mW
118+
119+
Position Sensors
120+
----------------
121+
122+
- **Hinge Angle 0/1/2** (``SENSOR_TYPE_HINGE_ANGLE``)
123+
124+
- Measures foldable device hinge angles
125+
- Range: 0-360°
126+
- Resolution: 1.0°
127+
- Power consumption: 3.0 mW
128+
- Note: Supports up to 3 hinges (for multi-fold devices)
129+
130+
Biometric Sensors
131+
-----------------
132+
133+
- **Heart Rate** (``SENSOR_TYPE_HEART_RATE``)
134+
135+
- Measures heart rate in beats per minute
136+
- Range: 0-500 bpm
137+
- Resolution: 1.0 bpm
138+
- Power consumption: 20.0 mW
139+
140+
Gesture Sensors
141+
---------------
142+
143+
- **Wrist Tilt** (``SENSOR_TYPE_WRIST_TILT_GESTURE``)
144+
145+
- Detects wrist tilt gesture events
146+
- Range: 0-1.0 (event trigger)
147+
- Resolution: 1.0
148+
- Power consumption: 20.0 mW
149+
150+
Usage
151+
=====
152+
153+
Kernel Configuration
154+
--------------------
155+
156+
Enable the Goldfish Sensor driver in your NuttX configuration::
157+
158+
CONFIG_SENSORS=y
159+
CONFIG_SENSORS_GOLDFISH=y
160+
CONFIG_GOLDFISH_PIPE=y
161+
162+
Driver Initialization
163+
---------------------
164+
165+
The driver is typically initialized during board-level setup::
166+
167+
#include <nuttx/sensors/goldfish_sensor.h>
168+
169+
int board_sensors_initialize(void)
170+
{
171+
int ret;
172+
173+
/* Initialize Goldfish sensors with device number 0
174+
* and batch buffer size of 1
175+
*/
176+
ret = goldfish_sensor_init(0, 1);
177+
if (ret < 0)
178+
{
179+
snerr("ERROR: Failed to initialize Goldfish sensors: %d\n", ret);
180+
return ret;
181+
}
182+
183+
return OK;
184+
}
185+
186+
Application Usage
187+
-----------------
188+
189+
Applications can access sensors through the standard NuttX sensor interface::
190+
191+
#include <fcntl.h>
192+
#include <nuttx/sensors/sensor.h>
193+
194+
int main(int argc, char *argv[])
195+
{
196+
struct sensor_accel accel_data;
197+
int fd;
198+
int ret;
199+
200+
/* Open accelerometer sensor */
201+
fd = open("/dev/uorb/sensor_accel0", O_RDONLY);
202+
if (fd < 0)
203+
{
204+
printf("Failed to open accelerometer\n");
205+
return -1;
206+
}
207+
208+
/* Read sensor data */
209+
while (1)
210+
{
211+
ret = read(fd, &accel_data, sizeof(accel_data));
212+
if (ret == sizeof(accel_data))
213+
{
214+
printf("Accel: x=%.2f y=%.2f z=%.2f (timestamp=%llu)\n",
215+
accel_data.x, accel_data.y, accel_data.z,
216+
accel_data.timestamp);
217+
}
218+
219+
usleep(100000); /* 100ms */
220+
}
221+
222+
close(fd);
223+
return 0;
224+
}

0 commit comments

Comments
 (0)