libtock/adc.c
static void adc_routing_upcall(int callback_type,
                               int arg1,
                               int arg2,
                               void* callback_args) {

  switch (callback_type) {
    case SingleSample:
      if (single_sample_callback) {
        uint8_t channel = (uint8_t)arg1;
        uint16_t sample = (uint16_t)arg2;
        single_sample_callback(channel, sample, callback_args);
      }
      break;

    case ContinuousSample:
      if (continuous_sample_callback) {
        uint8_t channel = (uint8_t)arg1;
        uint16_t sample = (uint16_t)arg2;
        continuous_sample_callback(channel, sample, callback_args);
      }
      break;

    case SingleBuffer:
      if (buffered_sample_callback) {
        uint8_t channel  = (uint8_t)(arg1 & 0xFF);
        uint32_t length  = ((arg1 >> 8) & 0xFFFFFF);
        uint16_t* buffer = (uint16_t*)arg2;
        buffered_sample_callback(channel, length, buffer, callback_args);
      }
      break;

    case ContinuousBuffer:
      if (continuous_buffered_sample_callback) {
        uint8_t channel  = (uint8_t)(arg1 & 0xFF);
        uint32_t length  = ((arg1 >> 8) & 0xFFFFFF);
        uint16_t* buffer = (uint16_t*)arg2;
        continuous_buffered_sample_callback(channel, length, buffer, callback_args);
      }
      break;
  }
}
// Internal callback for routing to operation-specific callbacks
//
// callback_type - number indicating which type of callback occurred
// arg1, arg2 - meaning varies based on callback_type
// callback_args - user data passed into the set_callback function
//
// Possible callbacks
// SingleSample: single sample operation is complete
//      arg1 - channel number that collected sample corresponds to
//      arg2 - sample value
// MultipleSample: sampling a buffer worth of data is complete
//      arg1 - channel in lower 8 bits,
//             number of samples collected in upper 24 bits
//      arg2 - pointer to buffer filled with samples
// ContinuousSample: a buffer of sample data is ready
//      arg1 - channel in lower 8 bits,
//             number of samples collected in upper 24 bits
//      arg2 - pointer to buffer filled with samples
Internal callback for routing to operation-specific callbacks
callback_type - number indicating which type of callback occurred
arg1, arg2 - meaning varies based on callback_type
callback_args - user data passed into the set_callback function


Internal callback for routing to operation - specific callbacks callback_type - number indicating which type of callback occurred arg1 arg2 - meaning varies based on callback_type callback_args - user data passed into the set_callback function
static void adc_routing_upcall(int callback_type,
                               int arg1,
                               int arg2,
                               void* callback_args) {
  switch (callback_type) {
    case SingleSample:
      if (single_sample_callback) {
        uint8_t channel = (uint8_t)arg1;
        uint16_t sample = (uint16_t)arg2;
        single_sample_callback(channel, sample, callback_args);
      }
      break;
    case ContinuousSample:
      if (continuous_sample_callback) {
        uint8_t channel = (uint8_t)arg1;
        uint16_t sample = (uint16_t)arg2;
        continuous_sample_callback(channel, sample, callback_args);
      }
      break;
    case SingleBuffer:
      if (buffered_sample_callback) {
        uint8_t channel  = (uint8_t)(arg1 & 0xFF);
        uint32_t length  = ((arg1 >> 8) & 0xFFFFFF);
        uint16_t* buffer = (uint16_t*)arg2;
        buffered_sample_callback(channel, length, buffer, callback_args);
      }
      break;
    case ContinuousBuffer:
      if (continuous_buffered_sample_callback) {
        uint8_t channel  = (uint8_t)(arg1 & 0xFF);
        uint32_t length  = ((arg1 >> 8) & 0xFFFFFF);
        uint16_t* buffer = (uint16_t*)arg2;
        continuous_buffered_sample_callback(channel, length, buffer, callback_args);
      }
      break;
  }
}
static void adc_routing_upcall ( int callback_type , int arg1 , int arg2 , void * callback_args ) { switch ( callback_type ) { case SingleSample : if ( single_sample_callback ) { uint8_t channel = ( uint8_t ) arg1 ; uint16_t sample = ( uint16_t ) arg2 ; single_sample_callback ( channel , sample , callback_args ) ; } break ; case ContinuousSample : if ( continuous_sample_callback ) { uint8_t channel = ( uint8_t ) arg1 ; uint16_t sample = ( uint16_t ) arg2 ; continuous_sample_callback ( channel , sample , callback_args ) ; } break ; case SingleBuffer : if ( buffered_sample_callback ) { uint8_t channel = ( uint8_t ) ( arg1 & 0xFF ) ; uint32_t length = ( ( arg1 >> 8 ) & 0xFFFFFF ) ; uint16_t * buffer = ( uint16_t * ) arg2 ; buffered_sample_callback ( channel , length , buffer , callback_args ) ; } break ; case ContinuousBuffer : if ( continuous_buffered_sample_callback ) { uint8_t channel = ( uint8_t ) ( arg1 & 0xFF ) ; uint32_t length = ( ( arg1 >> 8 ) & 0xFFFFFF ) ; uint16_t * buffer = ( uint16_t * ) arg2 ; continuous_buffered_sample_callback ( channel , length , buffer , callback_args ) ; } break ; } }
Internal callback for routing to operation-specific callbacks
callback_type - number indicating which type of callback occurred
arg1, arg2 - meaning varies based on callback_type
callback_args - user data passed into the set_callback function
Internal callback for routing to operation - specific callbacks callback_type - number indicating which type of callback occurred arg1 arg2 - meaning varies based on callback_type callback_args - user data passed into the set_callback function