You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
3.1 KiB
C++
151 lines
3.1 KiB
C++
/*
|
|
* ExtADC.h
|
|
*
|
|
* Author: Aleksey Gerasimenko
|
|
* gerasimenko.aleksey.n@gmail.com
|
|
*/
|
|
|
|
#include "DSP28335/GPIO.h"
|
|
#include "PERIPHERY/PeripheryMap.h"
|
|
|
|
#include "RUDRIVEFRAMEWORK/DataType.h"
|
|
#include "RUDRIVEFRAMEWORK/SystemDefinitions.h"
|
|
|
|
|
|
#ifndef PERIPHERY_EXTADC_H_
|
|
#define PERIPHERY_EXTADC_H_
|
|
|
|
namespace PERIPHERY
|
|
{
|
|
|
|
struct ExtADCSetup
|
|
{
|
|
pGPIO_FUNCTION p_gpio_setup;
|
|
pGPIO_FUNCTION p_start_convertion;
|
|
pGPIO_FUNCTION p_stop_convertion;
|
|
void set_default()
|
|
{
|
|
p_gpio_setup = &DSP28335::GPIO::ext_adc_start_convertion_setup;
|
|
p_start_convertion = &DSP28335::GPIO::set_ext_adc_start_convertion;
|
|
p_stop_convertion = &DSP28335::GPIO::clear_ext_adc_start_convertion;
|
|
};
|
|
ExtADCSetup():
|
|
p_gpio_setup(&DSP28335::GPIO::ext_adc_start_convertion_setup),
|
|
p_start_convertion(&DSP28335::GPIO::set_ext_adc_start_convertion),
|
|
p_stop_convertion(&DSP28335::GPIO::clear_ext_adc_start_convertion)
|
|
{}
|
|
//
|
|
};//
|
|
|
|
|
|
struct ExtADCStatusBitField
|
|
{
|
|
uint16_t busy: 1;
|
|
uint16_t read: 1;
|
|
uint16_t ready: 1;
|
|
};//ExtADCStatus
|
|
|
|
|
|
union ExtADCStatusRegister
|
|
{
|
|
uint16_t all;
|
|
ExtADCStatusBitField bit;
|
|
ExtADCStatusRegister():
|
|
all(0)
|
|
{}
|
|
};//
|
|
|
|
|
|
union ADC_RESULT_TYPE
|
|
{
|
|
uint16_t u16;
|
|
int16_t i16;
|
|
ADC_RESULT_TYPE():
|
|
u16(0)
|
|
{}
|
|
};//ADC_RESULT_TYPE
|
|
|
|
struct ADC_RESULT
|
|
{
|
|
int16_t channel_00;
|
|
int16_t channel_01;
|
|
int16_t channel_02;
|
|
int16_t channel_03;
|
|
int16_t channel_04;
|
|
int16_t channel_05;
|
|
int16_t channel_06;
|
|
int16_t channel_07;
|
|
int16_t channel_08;
|
|
int16_t channel_09;
|
|
int16_t channel_10;
|
|
int16_t channel_11;
|
|
int16_t channel_12;
|
|
int16_t channel_13;
|
|
int16_t channel_14;
|
|
int16_t channel_15;
|
|
int16_t channel_16;
|
|
int16_t channel_17;
|
|
ADC_RESULT():
|
|
channel_00(0),
|
|
channel_01(0),
|
|
channel_02(0),
|
|
channel_03(0),
|
|
channel_04(0),
|
|
channel_05(0),
|
|
channel_06(0),
|
|
channel_07(0),
|
|
channel_08(0),
|
|
channel_09(0),
|
|
channel_10(0),
|
|
channel_11(0),
|
|
channel_12(0),
|
|
channel_13(0),
|
|
channel_14(0),
|
|
channel_15(0),
|
|
channel_16(0),
|
|
channel_17(0)
|
|
{}
|
|
};//
|
|
|
|
|
|
class ExtADC
|
|
{
|
|
private:
|
|
uint16_t *p_channel_00;
|
|
uint16_t *p_channel_01;
|
|
uint16_t *p_channel_02;
|
|
uint16_t *p_channel_03;
|
|
uint16_t *p_channel_04;
|
|
uint16_t *p_channel_05;
|
|
uint16_t *p_channel_06;
|
|
uint16_t *p_channel_07;
|
|
uint16_t *p_channel_08;
|
|
uint16_t *p_channel_09;
|
|
uint16_t *p_channel_10;
|
|
uint16_t *p_channel_11;
|
|
uint16_t *p_channel_12;
|
|
uint16_t *p_channel_13;
|
|
uint16_t *p_channel_14;
|
|
uint16_t *p_channel_15;
|
|
uint16_t *p_channel_16;
|
|
uint16_t *p_channel_17;
|
|
public:
|
|
ExtADC();
|
|
void setup(uint16_t *memzone);
|
|
void setup(uint16_t *memzone, const ExtADCSetup& setup);
|
|
public:
|
|
void read_adc(ADC_RESULT& adc_result);
|
|
void read_adc(uint16_t adc_result[18]);
|
|
void start_convertion();
|
|
void stop_convertion();
|
|
private:
|
|
void (*_gpio_setup)();
|
|
void (*_start_convertion)();
|
|
void (*_stop_convertion)();
|
|
|
|
};
|
|
|
|
} /* namespace PERIPHERY */
|
|
|
|
#endif /* PERIPHERY_EXTADC_H_ */
|