forked from haraldwolff/avr-fw-modules
62 lines
1.6 KiB
C
Executable File
62 lines
1.6 KiB
C
Executable File
#include <sys/adc.h>
|
|
#include <hwo/runtime.h>
|
|
#include <fixpoint/fp4816.h>
|
|
|
|
|
|
int adc_node_proc(int op,int regno,uint8_t *type,void *buffer){
|
|
|
|
switch (op & RNPOP_MASK)
|
|
{
|
|
case RNPOP_READ:
|
|
if ((regno >= 0x8000) && (regno < 0x8008))
|
|
{
|
|
if (*type & RDT_FLOAT) {
|
|
*(float*)buffer = fp4816_to_float( adc_value(regno & 0x07) );
|
|
} else {
|
|
*(int32_t*)buffer = (int32_t)adc_value(regno & 0x07);
|
|
};
|
|
return 0;
|
|
};
|
|
if ((regno >= 0x8008) && (regno < 0x8010))
|
|
{
|
|
*(int32_t*)buffer = (int32_t)adc_get_limit_min(regno & 0x07);
|
|
return 0;
|
|
};
|
|
if ((regno >= 0x8010) && (regno < 0x8018))
|
|
{
|
|
*(int32_t*)buffer = (int32_t)adc_get_limit_max(regno & 0x07);
|
|
return 0;
|
|
};
|
|
break;
|
|
case RNPOP_WRITE:
|
|
if (rt_authorized(RTA_SERVICE0) && (regno >= 0x8008) && (regno < 0x8010))
|
|
{
|
|
if (*(int32_t*)buffer == -1) {
|
|
adc_set_limit_min(regno & 0x07, adc.channels[regno & 0x07].raw);
|
|
} else {
|
|
adc_set_limit_min(regno & 0x07, *(int32_t*)buffer);
|
|
};
|
|
adc_save();
|
|
return 0;
|
|
};
|
|
if (rt_authorized(RTA_SERVICE0) && (regno >= 0x8010) && (regno < 0x8018))
|
|
{
|
|
if (*(int32_t*)buffer == -1) {
|
|
adc_set_limit_max(regno & 0x07, adc.channels[regno & 0x07].raw);
|
|
} else {
|
|
adc_set_limit_max(regno & 0x07, *(int32_t*)buffer);
|
|
};
|
|
adc_save();
|
|
return 0;
|
|
};
|
|
break;
|
|
default:
|
|
return -EPARAM;
|
|
};
|
|
return -EPARAM;
|
|
};
|
|
|
|
uint8_t adc_register_proc(RB2_REGISTER *reg,RB2_TELEGRAM *telegram) {
|
|
uint8_t t = telegram->flags.type;
|
|
return adc_node_proc( telegram->flags.read ? RNPOP_READ : RNPOP_WRITE, telegram->regno, &t, &telegram->i32);
|
|
}; |