mirror of
https://github.com/elua/elua.git
synced 2025-01-08 20:56:17 +08:00
94438ff64b
- ADC adjusted to work with sequenced acquisition setups. It should now accomodate both sequenced and non-sequenced approaches on the backend. A few more adjustments should be made to handle multiple sequencers but right now neither LM3S or STM32 platforms use more than one sequencer. - Added adcpoll.lua to demonstrate a simple approach for using clocked acquisition and displaying results as they become available. - ADC now works for STM32 (all 16 channels!). This should receive more extensive testing, but everything should be working at this stage. - the build system now pays attention to changes in header files meaning that if any headers change or if the romfs changes (since it is generated as a header) these changes will get recompiled without having to do a clean.
62 lines
2.2 KiB
C
62 lines
2.2 KiB
C
#ifndef __ELUA_ADC_H__
|
|
#define __ELUA_ADC_H__
|
|
|
|
#include "type.h"
|
|
#include "platform_conf.h"
|
|
|
|
|
|
typedef struct
|
|
{
|
|
// Status Bit Flags
|
|
volatile u8 op_pending: 1, // Is there a pending conversion?
|
|
blocking: 1, // Are we in blocking or non-blocking mode? (0 - blocking, 1 - nonblocking)
|
|
freerunning: 1, // If true, we don't stop when we've acquired the requested number of samples
|
|
smooth_ready: 1; // Has smoothing filter warmed up (i.e. smoothlen samples collected)
|
|
|
|
unsigned id;
|
|
|
|
u8 logsmoothlen;
|
|
volatile u16 smoothidx;
|
|
volatile u32 smoothsum;
|
|
u16 *smoothbuf;
|
|
|
|
volatile u16 reqsamples;
|
|
volatile u16 *value_ptr;
|
|
} elua_adc_ch_state;
|
|
|
|
typedef struct
|
|
{
|
|
elua_adc_ch_state *ch_state[ NUM_ADC ];
|
|
volatile u16 sample_buf[ NUM_ADC ];
|
|
volatile u8 clocked: 1,
|
|
force_reseq: 1,
|
|
skip_cycle: 1,
|
|
running: 1; // Whether or not sequence is running
|
|
volatile u32 ch_active; // bits represent whether channel should be converted on this device
|
|
volatile u32 last_ch_active; // keep copy of old configuration
|
|
unsigned timer_id, seq_id; // Timer bound to device, sequencer device id
|
|
volatile u8 seq_ctr, seq_len;
|
|
} elua_adc_dev_state;
|
|
|
|
// Channel Management
|
|
#define ACTIVATE_CHANNEL( d, id ) ( d->ch_active |= ( ( u32 )1 << ( id ) ) )
|
|
#define INACTIVATE_CHANNEL( d, id ) ( d->ch_active &= ~( ( u32 )1 << ( id ) ) )
|
|
#define INCR_SEQCTR( d ) ( d->seq_ctr++ )
|
|
|
|
int adc_setup_channel( unsigned id, u8 logcount );
|
|
void adc_update_dev_sequence( unsigned dev_id );
|
|
void adc_init_dev_state( unsigned dev_id );
|
|
elua_adc_dev_state *adc_get_dev_state( unsigned dev_id );
|
|
void adc_smooth_data( unsigned id );
|
|
elua_adc_ch_state *adc_get_ch_state( unsigned id );
|
|
u16 adc_get_processed_sample( unsigned id );
|
|
void adc_init_ch_state( unsigned id );
|
|
int adc_update_smoothing( unsigned id, u8 loglen );
|
|
void adc_flush_smoothing( unsigned id );
|
|
u16 adc_samples_requested( unsigned id );
|
|
u16 adc_samples_available( unsigned id );
|
|
void adc_wait_samples( unsigned id, unsigned samples );
|
|
|
|
#endif
|
|
|