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

  adc_data_t* result = (adc_data_t*)callback_args;

  switch (callback_type) {
    case SingleSample:
      result->error   = RETURNCODE_SUCCESS;
      result->channel = arg1;
      result->sample  = arg2;
      break;

    case ContinuousSample:
      result->error   = RETURNCODE_SUCCESS;
      result->channel = arg1;
      result->sample  = arg2;
      break;

    case SingleBuffer:
      result->error   = RETURNCODE_SUCCESS;
      result->channel = (arg1 & 0xFF);
      result->length  = ((arg1 >> 8) & 0xFFFFFF);
      result->buffer  = (uint16_t*)arg2;
      break;

    case ContinuousBuffer:
      result->error   = RETURNCODE_SUCCESS;
      result->channel = (arg1 & 0xFF);
      result->length  = ((arg1 >> 8) & 0xFFFFFF);
      result->buffer  = (uint16_t*)arg2;
      break;

    default:
      result->error = RETURNCODE_FAIL;
      break;
  }

  result->fired = true;
}
// Internal callback for creating synchronous functions
//
// 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 creating synchronous functions
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 creating synchronous functions 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_upcall(int callback_type,
                       int arg1,
                       int arg2,
                       void* callback_args) {
  adc_data_t* result = (adc_data_t*)callback_args;
  switch (callback_type) {
    case SingleSample:
      result->error   = RETURNCODE_SUCCESS;
      result->channel = arg1;
      result->sample  = arg2;
      break;
    case ContinuousSample:
      result->error   = RETURNCODE_SUCCESS;
      result->channel = arg1;
      result->sample  = arg2;
      break;
    case SingleBuffer:
      result->error   = RETURNCODE_SUCCESS;
      result->channel = (arg1 & 0xFF);
      result->length  = ((arg1 >> 8) & 0xFFFFFF);
      result->buffer  = (uint16_t*)arg2;
      break;
    case ContinuousBuffer:
      result->error   = RETURNCODE_SUCCESS;
      result->channel = (arg1 & 0xFF);
      result->length  = ((arg1 >> 8) & 0xFFFFFF);
      result->buffer  = (uint16_t*)arg2;
      break;
    default:
      result->error = RETURNCODE_FAIL;
      break;
  }
  result->fired = true;
}
static void adc_upcall ( int callback_type , int arg1 , int arg2 , void * callback_args ) { adc_data_t * result = ( adc_data_t * ) callback_args ; switch ( callback_type ) { case SingleSample : result -> error = RETURNCODE_SUCCESS ; result -> channel = arg1 ; result -> sample = arg2 ; break ; case ContinuousSample : result -> error = RETURNCODE_SUCCESS ; result -> channel = arg1 ; result -> sample = arg2 ; break ; case SingleBuffer : result -> error = RETURNCODE_SUCCESS ; result -> channel = ( arg1 & 0xFF ) ; result -> length = ( ( arg1 >> 8 ) & 0xFFFFFF ) ; result -> buffer = ( uint16_t * ) arg2 ; break ; case ContinuousBuffer : result -> error = RETURNCODE_SUCCESS ; result -> channel = ( arg1 & 0xFF ) ; result -> length = ( ( arg1 >> 8 ) & 0xFFFFFF ) ; result -> buffer = ( uint16_t * ) arg2 ; break ; default : result -> error = RETURNCODE_FAIL ; break ; } result -> fired = true ; }
Internal callback for creating synchronous functions
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 creating synchronous functions 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