#ifndef ADC_H_INCLUDED
#define ADC_H_INCLUDED



#define ADC_AXIS_VALUES            65521
#define ADC_AXIS_MIN_VALUE             0
#define ADC_AXIS_MAX_VALUE         65520
// these next three are dubious!
#define ADC_AXIS_HAT_MIN           12288
#define ADC_AXIS_HAT_MID           32760
#define ADC_AXIS_HAT_MAX           53247


extern void bytev_hook(void);
int32_t bytev_hook_handler(_kernel_swi_regs *r, void *pw);

extern struct adc_data_struct adc_data;
extern struct adc_map_struct adc_map;

extern osbool emulate_adc_on;


#define ADC_CHANNELS 4
#define ADC_BUTTONS 2

struct adc_channel_struct {
  int32_t     joy_id;
  int32_t     axis;
  int32_t     start;  // what will become ADC min (0)
  int32_t     end;    // what will become ADC max (65520)
  osbool  flip;
  int32_t     slope;
  osbool  slope_div;
};

struct adc_button_struct {
  int32_t joy_id;
  int32_t button;
};

struct adc_map_struct
{
  struct adc_channel_struct   channels[ADC_CHANNELS];
  struct adc_button_struct    buttons[ADC_BUTTONS];
};

struct adc_data_struct
{
  int32_t channels_to_be_sampled;
  int32_t current_channel;
  int32_t channel_values[ADC_CHANNELS];
  int32_t button_values[ADC_BUTTONS];
};


uint32_t adc_read_channel(uint32_t channel);
uint32_t adc_read_fire(void);


#endif
