SARADC is a 6-channel 10-bit effective digital-to-analog converter. When the input frequency is 13MHz, the conversion speed is 1MSPS.
Hot Wheels Technology has developed a rk3588s motherboard, youyeetoo R1, which provides 40pin expansion pins, including 1 CAN pin. The pin distribution is shown in the figure below:
If you want to use shell commands in the Android system, you need to enter the Android command line window through ADB. For tutorials on using ADB, please refer to the adb debugging chapter. After opening the Android system command line through adb,
cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw
The complete app is available here
The permission management of the Android system is very strict. Using c++ or java to operate files or resources in the Android root file system requires corresponding permissions. The ndk program written here is written based on the system app as a template. For system app, please refer to the chapter Creating system app.
#include <jni.h>
#include <string>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
#include <android/log.h>
#define LOG_TAG "R1-AdcTest"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define ADC_DEVICE "/sys/bus/iio/devices/iio\:device0/in_voltage4_raw"
extern "C" JNIEXPORT jstring JNICALL
Java_com_youyeetoo_r1_1adcdemo_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
FILE *fd=NULL;
char adc_value[5];
char show_buf[48];
float Voltage;
int tmp;
fd=fopen(ADC_DEVICE,"r");
if (fd == NULL){
return env->NewStringUTF("open ADC_DEVICE failed \n");
}
fscanf(fd,"%s",adc_value);
fclose(fd);
sscanf(adc_value, "%d", &tmp);
Voltage = tmp / 4096.0 * 1.8;
sprintf(show_buf, "adc value: %s Voltage: %f",adc_value, Voltage);
return env->NewStringUTF(show_buf);
}