68 lines
1.2 KiB
C
Executable file
68 lines
1.2 KiB
C
Executable file
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <rb2/regbus.h>
|
|
#include <hwo/eeprom.h>
|
|
|
|
#ifndef ADC_CHANNELS
|
|
#define ADC_CHANNELS 8
|
|
#endif
|
|
|
|
struct adc_channel {
|
|
#if !defined (__SIMPLE_ADC__)
|
|
uint16_t raw;
|
|
#else
|
|
#define raw value
|
|
#endif
|
|
uint16_t value;
|
|
};
|
|
|
|
#if !defined (__SIMPLE_ADC__)
|
|
|
|
struct adc_params {
|
|
uint16_t min;
|
|
uint16_t max;
|
|
};
|
|
|
|
#endif
|
|
|
|
struct adc {
|
|
struct adc_channel channels[ ADC_CHANNELS ];
|
|
|
|
#if !defined (__SIMPLE_ADC__)
|
|
union {
|
|
EEPROM eeprom;
|
|
struct adc_params params[ ADC_CHANNELS ];
|
|
};
|
|
#endif
|
|
|
|
};
|
|
|
|
#if !defined (__SIMPLE_ADC__)
|
|
extern uint8_t _adc_bank;
|
|
#endif
|
|
|
|
extern struct adc adc;
|
|
|
|
void adc_init(uint8_t bank);
|
|
void adc_reinit(void);
|
|
void adc_save(void);
|
|
|
|
static inline uint16_t adc_value(uint8_t ch) { if (ch < ADC_CHANNELS) return adc.channels[ch].value; return 0; };
|
|
|
|
#if !defined (__SIMPLE_ADC__)
|
|
|
|
void adc_set_limit_min(uint8_t ch,uint16_t limit);
|
|
void adc_set_limit_max(uint8_t ch,uint16_t limit);
|
|
void adc_set_limit_range(uint8_t ch,uint16_t limit);
|
|
|
|
uint16_t adc_get_limit_min(uint8_t ch);
|
|
uint16_t adc_get_limit_max(uint8_t ch);
|
|
uint16_t adc_get_limit_range(uint8_t ch);
|
|
|
|
uint8_t adc_register_proc(RB2_REGISTER *reg,RB2_TELEGRAM *telegram);
|
|
int adc_node_proc(int op,int regno,uint8_t *type,void *buffer);
|
|
|
|
#endif
|
|
|