Changeset 420

Show
Ignore:
Timestamp:
02/17/07 21:29:20 (2 years ago)
Author:
goodea
Message:

servos

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/hal/lpc2106-cmucam3/cc3.c

    r414 r420  
    212212 
    213213 
    214 void cc3_clr_led (uint8_t select) 
     214void cc3_led_set_off (uint8_t select) 
    215215{ 
    216216  switch (select) { 
     
    229229 
    230230 
    231 void cc3_set_led (uint8_t select) 
     231void cc3_led_set_on (uint8_t select) 
    232232{ 
    233233 
     
    391391 * 
    392392 */ 
    393 void cc3_wait_ms (uint32_t delay) 
     393void cc3_timer_wait_ms (uint32_t delay) 
    394394{ 
    395395  uint32_t start; 
    396   start = cc3_get_current_ms (); 
    397   while (cc3_get_current_ms () < (start + delay)); 
    398 } 
    399  
    400  
    401 uint32_t cc3_get_current_ms () 
     396  start = cc3_timer_get_current_ms (); 
     397  while (cc3_timer_get_current_ms () < (start + delay)); 
     398} 
     399 
     400 
     401uint32_t cc3_timer_get_current_ms () 
    402402{ 
    403403  return (REG (TIMER0_TC));     // REG in milliseconds 
     
    718718 * For basic manipulation of camera parameters see other cc3_set_xxxx functions. 
    719719 */ 
    720 bool cc3_set_raw_register (uint8_t address, uint8_t value) 
     720bool cc3_camera_set_raw_register (uint8_t address, uint8_t value) 
    721721{ 
    722722  unsigned int data[3]; 
     
    741741 * Takes enum CC3_RES_LOW and CC3_RES_HIGH. 
    742742 */ 
    743 void cc3_set_resolution (cc3_camera_resolution_t cam_res) 
     743void cc3_camera_set_resolution (cc3_camera_resolution_t cam_res) 
    744744{ 
    745745  _cc3_g_current_camera_state.resolution = cam_res; 
     
    755755 
    756756 
    757 void cc3_set_colorspace (cc3_colorspace_t colorspace) 
     757void cc3_camera_set_colorspace (cc3_colorspace_t colorspace) 
    758758{ 
    759759  _cc3_g_current_camera_state.colorspace = colorspace; 
     
    762762 
    763763 
    764 void cc3_set_framerate_divider (uint8_t rate_divider) 
     764void cc3_camera_set_framerate_divider (uint8_t rate_divider) 
    765765{ 
    766766  _cc3_g_current_camera_state.clock_divider = rate_divider; 
     
    768768} 
    769769 
    770 void cc3_set_auto_exposure (bool exp) 
     770void cc3_camera_set_auto_exposure (bool exp) 
    771771{ 
    772772  _cc3_g_current_camera_state.auto_exposure = exp; 
     
    774774} 
    775775 
    776 void cc3_set_auto_white_balance (bool awb) 
     776void cc3_camera_set_auto_white_balance (bool awb) 
    777777{ 
    778778  _cc3_g_current_camera_state.auto_white_balance = awb; 
     
    780780} 
    781781 
    782 void cc3_set_brightness (uint8_t level) 
     782void cc3_camera_set_brightness (uint8_t level) 
    783783{ 
    784784  _cc3_g_current_camera_state.brightness = level; 
    785785  _cc3_set_register_state ();   // XXX Don't reset all of them, this is just quick and dirty... 
    786   return 1; 
    787 
    788  
    789 void cc3_set_contrast (uint8_t level) 
     786
     787 
     788void cc3_camera_set_contrast (uint8_t level) 
    790789{ 
    791790  _cc3_g_current_camera_state.contrast = level; 
    792791  _cc3_set_register_state ();   // XXX Don't reset all of them, this is just quick and dirty... 
    793   return 1; 
    794 
    795  
    796  
    797 bool cc3_read_button (void) 
     792
     793 
     794 
     795bool cc3_button_get_state (void) 
    798796{ 
    799797  bool result = !(REG (GPIO_IOPIN) & _CC3_BUTTON); 
  • trunk/hal/lpc2106-cmucam3/cc3_hal.c

    r412 r420  
    110110  case _CC3_OV6620: 
    111111    // Set the right data bus mode 
    112     result &= cc3_set_raw_register (0x14, 0x20); 
     112    result &= cc3_camera_set_raw_register (0x14, 0x20); 
    113113    // Set the resolution and update the size flags 
    114     if (_cc3_g_current_camera_state.resolution == CC3_RES_LOW) { 
     114    if (_cc3_g_current_camera_state.resolution == CC3_CAMERA_RESOLUTION_LOW) { 
    115115      _cc3_g_current_camera_state.raw_width = CC3_LO_RES_WIDTH; // 88 * 2; 
    116116      _cc3_g_current_camera_state.raw_height = CC3_LO_RES_HEIGHT;       // 144; 
    117       result &= cc3_set_raw_register (0x14, 0x20); 
     117      result &= cc3_camera_set_raw_register (0x14, 0x20); 
    118118    } 
    119119    else { 
    120120      _cc3_g_current_camera_state.raw_width = CC3_HI_RES_WIDTH; // 176 * 2; 
    121121      _cc3_g_current_camera_state.raw_height = CC3_HI_RES_HEIGHT;       //288; 
    122       result &= cc3_set_raw_register (0x14, 0x00); 
     122      result &= cc3_camera_set_raw_register (0x14, 0x00); 
    123123    } 
    124124 
    125125    if (_cc3_g_current_camera_state.auto_exposure) { 
    126       result &= cc3_set_raw_register (0x13, 0x21); 
     126      result &= cc3_camera_set_raw_register (0x13, 0x21); 
    127127    } 
    128128    else { 
    129129      // No auto gain, so lets set brightness and contrast if need be 
    130       result &= cc3_set_raw_register (0x13, 0x20); 
     130      result &= cc3_camera_set_raw_register (0x13, 0x20); 
    131131      if (_cc3_g_current_camera_state.brightness != -1) 
    132         result &= cc3_set_raw_register (0x06, 
     132        result &= cc3_camera_set_raw_register (0x06, 
    133133                                        (_cc3_g_current_camera_state. 
    134134                                         brightness & 0xFF)); 
    135135 
    136136      if (_cc3_g_current_camera_state.contrast != -1) 
    137         result &= cc3_set_raw_register (0x05, 
     137        result &= cc3_camera_set_raw_register (0x05, 
    138138                                        (_cc3_g_current_camera_state.contrast & 0xFF)); 
    139139    } 
    140140    // Set Colorspace and Auto White Balance 
    141     result &= cc3_set_raw_register (0x12, 
     141    result &= cc3_camera_set_raw_register (0x12, 
    142142                                    0x20 | (_cc3_g_current_camera_state. 
    143143                                            auto_white_balance << 2) 
    144144                                    | (_cc3_g_current_camera_state.colorspace << 3)); 
    145145    // Set Frame Clock rate divider 
    146     result &= cc3_set_raw_register (0x11, _cc3_g_current_camera_state.clock_divider); 
     146    result &= cc3_camera_set_raw_register (0x11, _cc3_g_current_camera_state.clock_divider); 
    147147 
    148148    break; 
  • trunk/hal/lpc2106-cmucam3/gpio.c

    r395 r420  
    11/* 
    2  * Copyright 2006  Anthony Rowe and Adam Goode 
     2 * Copyright 2006-2007  Anthony Rowe and Adam Goode 
    33 * 
    44 * Licensed under the Apache License, Version 2.0 (the "License"); 
     
    1818 
    1919#include "gpio.h" 
     20#include "servo.h" 
     21#include "LPC2100.h" 
    2022#include <stdio.h> 
    2123#include "cc3_pin_defines.h" 
     
    2527 
    2628 
    27 void cc3_gpio_set_to_input(uint8_t mask
     29void cc3_gpio_set_mode(uint8_t pin, cc3_gpio_mode_t mode
    2830{ 
     31  if (pin >= MAX_SERVOS) { 
     32    return; 
     33  } 
    2934 
     35  uint32_t mask = 1 << pin; 
     36  uint32_t pin_val = _cc3_servo_map[pin]; 
     37 
     38  switch (mode) { 
     39  case CC3_GPIO_MODE_INPUT: 
     40    // not a servo 
     41    _cc3_servo_enable(pin, false); 
     42 
     43    // set to 0 
     44    REG (GPIO_IODIR) &= ~pin_val; 
     45    break; 
     46 
     47  case CC3_GPIO_MODE_OUTPUT: 
     48    // not a servo 
     49    _cc3_servo_enable(pin, false); 
     50 
     51    // set to 1 
     52    REG (GPIO_IODIR) |= pin_val; 
     53    break; 
     54 
     55  case CC3_GPIO_MODE_SERVO: 
     56    // a servo 
     57    _cc3_servo_enable(pin, true); 
     58 
     59    // set to 1 
     60    REG (GPIO_IODIR) |= pin_val; 
     61    break; 
     62  } 
    3063} 
    3164 
    32 void cc3_gpio_set_to_output(uint8_t mask
     65void cc3_gpio_set_value(uint8_t pin, bool value
    3366{ 
     67  if (pin >= MAX_SERVOS) { 
     68    return; 
     69  } 
    3470 
     71  if (value) { 
     72    REG (GPIO_IOSET) = _cc3_servo_map[pin]; 
     73  } else { 
     74    REG (GPIO_IOCLR) = _cc3_servo_map[pin]; 
     75  } 
    3576} 
    3677 
    37 uint8_t cc3_gpio_set_pin(uint8_t pin) 
     78 
     79bool cc3_gpio_get_value(uint8_t pin) 
    3880{ 
     81  if (pin >= MAX_SERVOS) { 
     82    return false; 
     83  } 
    3984 
     85  return REG (GPIO_IOPIN) & _cc3_servo_map[pin]; 
    4086} 
    4187 
    42 uint8_t cc3_gpio_get_pin(uint8_t pin) 
     88 
     89uint8_t cc3_gpio_get_count() 
    4390{ 
    44  
    45  
     91  return MAX_SERVOS; 
    4692} 
    47  
  • trunk/hal/lpc2106-cmucam3/serial.c

    r332 r420  
    108108} 
    109109 
    110 uint8_t cc3_get_uart_count(void) 
     110uint8_t cc3_uart_get_count(void) 
    111111{ 
    112112  return 2; 
     
    132132  } 
    133133 
    134   if (uart >= cc3_get_uart_count()) { 
     134  if (uart >= cc3_uart_get_count()) { 
    135135    return false; 
    136136  } 
     
    190190} 
    191191 
    192 FILE *cc3_fopen_uart(uint8_t uart, const char *mode) 
     192FILE *cc3_uart_fopen(uint8_t uart, const char *mode) 
    193193{ 
    194194  char buf[8];  // safe, because uint8_t 
  • trunk/hal/lpc2106-cmucam3/servo.c

    r397 r420  
    11/* 
    2  * Copyright 2006  Anthony Rowe and Adam Goode 
     2 * Copyright 2006-2007  Anthony Rowe and Adam Goode 
    33 * 
    44 * Licensed under the Apache License, Version 2.0 (the "License"); 
     
    2424#include <stdio.h> 
    2525 
    26 // Set a particular servo pin low 
    27 static void _cc3_servo_lo (uint8_t n); 
     26static uint8_t servo_val[MAX_SERVOS] = { 
     27  SERVO_RESOLUTION / 2, 
     28  SERVO_RESOLUTION / 2, 
     29  SERVO_RESOLUTION / 2, 
     30  SERVO_RESOLUTION / 2, 
     31}; 
    2832 
    29 // Set all pins high at the start of the servo cycle 
    30 static void _cc3_servo_hi_all (void); 
     33static uint8_t servo_tmp[MAX_SERVOS]; 
     34static uint32_t servo_mask; 
     35 
     36const uint32_t _cc3_servo_map[] = 
     37  { 
     38    _CC3_SERVO_0, 
     39    _CC3_SERVO_1, 
     40    _CC3_SERVO_2, 
     41    _CC3_SERVO_3, 
     42  }; 
    3143 
    3244 
    33 static uint32_t servo_val[MAX_SERVOS]; 
    34 static uint32_t servo_tmp[MAX_SERVOS]; 
    35 static uint32_t servo_mask; 
    36  
    37 /** 
    38  * cc3_servo_set() 
    39  * This function sets a servo to be at given position. 
    40  * 
    41  * Returns true upon success. 
    42  * Returns false if the servo or position is out of bounds. 
    43  * 
    44  *  The servo will physically move on the next servo cycle. 
    45  *  The servo operates at 50hz. 
    46  */ 
    47 bool cc3_servo_set (uint8_t servo, uint32_t pos) 
     45bool cc3_gpio_set_servo_position (uint8_t servo, uint8_t pos) 
    4846{ 
    49     if (servo > MAX_SERVOS) 
    50         return false; 
    51     if (pos > SERVO_RESOLUTION) 
    52         return false; 
    53     servo_val[servo] = pos; 
    54     return true; 
     47  if (servo > MAX_SERVOS) 
     48    return false; 
     49  servo_val[servo] = pos; 
     50  return true; 
    5551} 
    5652 
    57 /** 
    58  * cc3_servo_init() 
    59  * 
    60  * This function sets up timer1 to control the servos. 
    61  * It is periodically called by an interrupt in interrupt.c 
    62  * 
    63  * This function can be called again after servos are disabled. 
    64  */ 
    65 void cc3_servo_init () 
     53static void servo_init (void) 
    6654{ 
    67     int i; 
    68     servo_mask=0xFFFFF; 
    69     for (i = 0; i < MAX_SERVOS; i++) 
    70         servo_val[i] = SERVO_RESOLUTION / 2; 
    7155    // Setup timer1 to handle servos 
    7256    REG (TIMER1_TCR) = 0;       // turn off timer 
     
    8266} 
    8367 
    84 void cc3_servo_mask(uint8_t mask) 
    85 { 
    86 servo_mask=mask; 
    87 } 
    88  
    89  
    9068/** 
    9169 * _cc3_servo_hi_all() 
     
    9472 * the 20ms servo period. 
    9573 */ 
    96 void _cc3_servo_hi_all (
     74static void servo_hi_all (void
    9775{ 
    98 uint32_t tmp; 
    99    tmp=0; 
    100    if(servo_mask&0x1) tmp |= _CC3_SERVO_0; 
    101    if(servo_mask&0x2) tmp |= _CC3_SERVO_1; 
    102    if(servo_mask&0x4) tmp |= _CC3_SERVO_2; 
    103    if(servo_mask&0x8) tmp |= _CC3_SERVO_3; 
    104    REG( GPIO_IOSET) = tmp; 
     76  uint32_t tmp = 0; 
     77  if(servo_mask&0x1) tmp |= _CC3_SERVO_0; 
     78  if(servo_mask&0x2) tmp |= _CC3_SERVO_1; 
     79  if(servo_mask&0x4) tmp |= _CC3_SERVO_2; 
     80  if(servo_mask&0x8) tmp |= _CC3_SERVO_3; 
     81  REG( GPIO_IOSET) = tmp; 
    10582} 
    10683 
     
    11087 *  This pulls a particular servo line low. 
    11188 */ 
    112 void _cc3_servo_lo (uint8_t n) 
     89static void servo_lo (uint8_t n) 
    11390{ 
    114     switch (n) { 
    115     case 0: 
    116         if(servo_mask&0x1) 
    117            REG (GPIO_IOCLR) = _CC3_SERVO_0; 
    118         break; 
    119     case 1: 
    120         if(servo_mask&0x2) 
    121         REG (GPIO_IOCLR) = _CC3_SERVO_1; 
    122         break; 
    123     case 2: 
    124         if(servo_mask&0x4) 
    125         REG (GPIO_IOCLR) = _CC3_SERVO_2; 
    126         break; 
    127     case 3: 
    128         if(servo_mask&0x8) 
    129         REG (GPIO_IOCLR) = _CC3_SERVO_3; 
    130         break; 
     91  REG (GPIO_IOCLR) = _cc3_servo_map[n]; 
     92
     93 
     94void _cc3_servo_enable(uint8_t servo, bool enable) 
     95
     96  bool some_servos_already_enabled = !!servo_mask; 
     97 
     98  uint32_t mask = 1 << servo; 
     99 
     100  if (enable) { 
     101    servo_mask |= mask; 
     102    if (!some_servos_already_enabled) { 
     103      servo_init(); 
     104    } 
     105  } else { 
     106    servo_mask &= ~mask; 
     107 
     108    // any servos left? 
     109    if (!servo_mask) { 
     110      disable_servo_interrupt(); 
    131111    } 
    132112 
     113    // set to low 
     114    servo_lo(servo); 
     115  } 
    133116} 
    134  
    135 /** 
    136  * cc3_disable() 
    137  * 
    138  * This function disables the servo interrupt and 
    139  * sets the servo lines low. 
    140  */ 
    141 void cc3_servo_disable () 
    142 { 
    143 uint8_t i; 
    144     disable_servo_interrupt (); 
    145     for (i = 0; i < MAX_SERVOS; i++) 
    146          _cc3_servo_lo (i); 
    147 } 
    148  
    149117 
    150118/** 
     
    152120 * 
    153121 * This is where the servo magic happens.  This function is called from 
    154  * the timer1 interrupt in interrupts.c. 
     122 * the timer1 interrupt in interrupt.c. 
    155123 * 
    156124 * It will schedule the next timer interrupt to fire when the next pin 
     
    172140        REG (TIMER1_TC) = 0; 
    173141        REG (TIMER1_MR0) = SERVO_RESOLUTION;    // schedule next wakeup for 1ms 
    174         _cc3_servo_hi_all (); 
     142        servo_hi_all (); 
    175143        // Copy current values into working values to avoid changes while 
    176144        // in the scheduling loop 
     
    187155            if (servo_tmp[i] < min && servo_tmp[i] > (ct + safety)) 
    188156                min = servo_tmp[i]; 
    189             if (servo_tmp[i] <= (ct+safety)) 
    190                 _cc3_servo_lo (i); 
     157            if ((servo_tmp[i] <= (ct+safety)) && (servo_mask & (1 << i))) 
     158                servo_lo (i); 
    191159        } 
    192160        // If all pins have been serviced, set a new interrupt for the 
  • trunk/hal/lpc2106-cmucam3/servo.h

    r302 r420  
    2727// SERVO_RESOLUTION sets resolution within 1ms 
    2828// Failure may occure above 512 
    29 #define SERVO_RESOLUTION 255  
     29#define SERVO_RESOLUTION 255 
    3030#define MAX_SERVOS 4 
    3131#define SERVO_PERIOD 18 
     
    3636void _cc3_servo_int (void); 
    3737 
     38void _cc3_servo_enable(uint8_t servo, bool enable); 
     39 
     40extern const uint32_t _cc3_servo_map[]; 
     41 
    3842#endif 
  • trunk/hal/lpc2106-cmucam3/uart_driver.c

    r360 r420  
    3333{ 
    3434  int uart_num = process_uart_filename(name); 
    35   if (uart_num >= 0 && uart_num < cc3_get_uart_count()) { 
     35  if (uart_num >= 0 && uart_num < cc3_uart_get_count()) { 
    3636    return uart_num + max_uarts; // new uart 
    3737  } else { 
  • trunk/hal/virtual-cam/cc3.c

    r414 r420  
    117117   do{ 
    118118   // skip every other row in low-res mode 
    119      if(_cc3_g_current_camera_state.resolution==CC3_RES_LOW  && col_cnt>=176 )  
     119     if(_cc3_g_current_camera_state.resolution==CC3_CAMERA_RESOLUTION_LOW  && col_cnt>=176 )  
    120120        { 
    121121        for(k=0; k<352; k++ ) 
     
    145145   val = b2 = fgetc(fp); 
    146146  // skip every other pixel in low-res mode 
    147    if(_cc3_g_current_camera_state.resolution ==CC3_RES_LOW  ) { 
     147   if(_cc3_g_current_camera_state.resolution ==CC3_CAMERA_RESOLUTION_LOW  ) { 
    148148    r = fgetc(fp); 
    149149    g = fgetc(fp); 
     
    273273 
    274274 
    275 void cc3_clr_led (uint8_t select) 
     275void cc3_led_set_off (uint8_t select) 
    276276{ 
    277277  switch (select) { 
     
    290290 
    291291 
    292 void cc3_set_led (uint8_t select) 
     292void cc3_led_set_on (uint8_t select) 
    293293{ 
    294294 
     
    458458 * 
    459459 */ 
    460 void cc3_wait_ms (uint32_t delay) 
     460void cc3_timer_wait_ms (uint32_t delay) 
    461461{ 
    462462  uint32_t start; 
     
    472472 * This function returns the time since startup in ms as a uint32 
    473473 */ 
    474 uint32_t cc3_timer () 
     474uint32_t cc3_timer_get_current_ms () 
    475475{ 
    476476  //return (REG (TIMER0_TC));     // REG in milliseconds 
     
    697697 * For basic manipulation of camera parameters see other cc3_set_xxxx functions. 
    698698 */ 
    699 bool cc3_set_raw_register (uint8_t address, uint8_t value) 
     699bool cc3_camera_set_raw_register (uint8_t address, uint8_t value) 
    700700{ 
    701701  unsigned int data[3]; 
     
    719719 * Takes enum CC3_LOW_RES and CC3_HIGH_RES. 
    720720 */ 
    721 void cc3_set_resolution (cc3_camera_resolution_t cam_res) 
     721void cc3_camera_set_resolution (cc3_camera_resolution_t cam_res) 
    722722{ 
    723723  _cc3_g_current_camera_state.resolution = cam_res; 
     
    739739 * the pixel array. 
    740740 */ 
    741 void cc3_set_colorspace (cc3_colorspace_t colorspace) 
     741void cc3_camera_set_colorspace (cc3_colorspace_t colorspace) 
    742742{ 
    743743  _cc3_g_current_camera_state.colorspace = colorspace; 
     
    746746 
    747747 
    748 void cc3_set_framerate_divider (uint8_t rate_divider) 
     748void cc3_camera_set_framerate_divider (uint8_t rate_divider) 
    749749{ 
    750750  _cc3_g_current_camera_state.clock_divider = rate_divider; 
     
    752752} 
    753753 
    754 void cc3_set_auto_exposure (bool exp) 
     754void cc3_camera_set_auto_exposure (bool exp) 
    755755{ 
    756756  _cc3_g_current_camera_state.auto_exposure = exp; 
     
    758758} 
    759759 
    760 void cc3_set_auto_white_balance (bool awb) 
     760void cc3_camera_set_auto_white_balance (bool awb) 
    761761{ 
    762762  _cc3_g_current_camera_state.auto_white_balance = awb; 
     
    764764} 
    765765 
    766 void cc3_set_brightness (uint8_t level) 
     766void cc3_camera_set_brightness (uint8_t level) 
    767767{ 
    768768  _cc3_g_current_camera_state.brightness = level; 
     
    770770} 
    771771 
    772 void cc3_set_contrast (uint8_t level) 
     772void cc3_camera_set_contrast (uint8_t level) 
    773773{ 
    774774  _cc3_g_current_camera_state.contrast = level; 
     
    777777 
    778778 
    779 bool cc3_read_button (void) 
     779bool cc3_button_get_state (void) 
    780780{ 
    781781  return 1; 
  • trunk/hal/virtual-cam/cc3_hal.c

    r399 r420  
    2323 
    2424 
    25 void reset_virtual_fifo(); 
     25void reset_virtual_fifo(void); 
    2626 
    2727void reset_virtual_fifo() 
     
    104104        //cc3_set_raw_register (0x14, 0x20); 
    105105        // Set the resolution and update the cc3_g_current_frame size flags 
    106         if (_cc3_g_current_camera_state.resolution == CC3_RES_LOW) { 
     106        if (_cc3_g_current_camera_state.resolution == CC3_CAMERA_RESOLUTION_LOW) { 
    107107            _cc3_g_current_camera_state.raw_width = CC3_LO_RES_WIDTH; 
    108108            _cc3_g_current_camera_state.raw_height = CC3_LO_RES_HEIGHT; 
     
    120120        else { 
    121121            // No auto gain, so lets set brightness and contrast if need be 
    122             cc3_set_raw_register (0x13, 0x20); 
     122            cc3_camera_set_raw_register (0x13, 0x20); 
    123123            //if (_cc3_g_current_camera_state.brightness != -1) 
    124124            //    cc3_set_raw_register (0x06, 
  • trunk/hal/virtual-cam/gpio.c

    r395 r420  
    2525 
    2626 
    27 void cc3_gpio_set_to_input(uint8_t mask
     27void cc3_gpio_set_mode(uint8_t pin, cc3_gpio_mode_t mode
    2828{ 
    2929 
    3030} 
    3131 
    32 void cc3_gpio_set_to_output(uint8_t mask) 
    33 { 
    34  
    35 } 
    36  
    37 uint8_t cc3_gpio_set_pin(uint8_t pin) 
    38 { 
    39  
    40 } 
    41  
    42 uint8_t cc3_gpio_get_pin(uint8_t pin) 
    43 { 
    44  
    45  
    46 } 
    47  
  • trunk/hal/virtual-cam/serial.c

    r302 r420  
    7474} 
    7575 
    76 uint8_t cc3_get_uart_count(void)  
     76uint8_t cc3_uart_get_count(void)  
    7777{ 
    7878  return 2; 
     
    156156} 
    157157 
    158 FILE *cc3_fopen_uart(uint8_t uart, const char *mode) 
     158FILE *cc3_uart_fopen(uint8_t uart, const char *mode) 
    159159{ 
    160160 // char buf[8];  // safe, because uint8_t 
  • trunk/hal/virtual-cam/servo.c

    r395 r420  
    4343 *  The servo operates at 50hz. 
    4444 */ 
    45 bool cc3_servo_set (uint8_t servo, uint32_t pos) 
     45bool cc3_gpio_set_servo_position (uint8_t servo, uint8_t pos) 
    4646{ 
    4747    if (servo > MAX_SERVOS) 
     
    5252    return true; 
    5353} 
    54  
    55 /** 
    56  * cc3_servo_init() 
    57  * 
    58  * This function sets up timer1 to control the servos. 
    59  * It is periodically called by an interrupt in interrupt.c 
    60  * 
    61  * This function can be called again after servos are disabled. 
    62  */ 
    63 void cc3_servo_init () 
    64 { 
    65     int i; 
    66     servo_mask=0xFFFFF; 
    67     for (i = 0; i < MAX_SERVOS; i++) 
    68         servo_val[i] = SERVO_RESOLUTION / 2; 
    69     // Setup timer1 to handle servos 
    70 } 
    71  
    72 void cc3_servo_mask(uint8_t mask) 
    73 { 
    74 servo_mask=mask; 
    75 } 
    76  
    7754 
    7855/** 
     
    12299 
    123100/** 
    124  * cc3_disable() 
    125  * 
    126  * This function disables the servo interrupt and  
    127  * sets the servo lines low. 
    128  */ 
    129 void cc3_servo_disable () 
    130 { 
    131 uint8_t i; 
    132 printf( "cc3 servo disabled\n" ); 
    133 } 
    134  
    135  
    136 /** 
    137101 * _cc3_servo_int() 
    138102 * 
  • trunk/include/cc3.h

    r414 r420  
    4545 */ 
    4646typedef enum { 
    47   CC3_RES_LOW = 0,  /**< Low resolution */ 
    48   CC3_RES_HIGH = 1  /**< High resolution */ 
     47  CC3_CAMERA_RESOLUTION_LOW = 0,  /**< Low resolution */ 
     48  CC3_CAMERA_RESOLUTION_HIGH = 1  /**< High resolution */ 
    4949} cc3_camera_resolution_t; 
    5050 
     
    129129  CC3_UART_BINMODE_TEXT,     /**< Read CR as LF, write LF as CR */ 
    130130} cc3_uart_binmode_t; 
     131 
     132/** 
     133 * GPIO configuration values. 
     134 * @sa cc3_gpio_set_mode() and cc3_gpio_get_mode(). 
     135 */ 
     136typedef enum { 
     137  CC3_GPIO_MODE_INPUT, 
     138  CC3_GPIO_MODE_OUTPUT, 
     139  CC3_GPIO_MODE_SERVO, 
     140} cc3_gpio_mode_t; 
    131141 
    132142/** 
     
    202212 * the amount of memory corresponding to the old row size. 
    203213 * 
    204  * \sa cc3_pixbuf_read_rows() 
     214 * @sa cc3_pixbuf_read_rows() 
    205215 * 
    206216 * @param[in] rows The number of rows to allocate space for. 
     
    268278 * Activate an LED. 
    269279 * 
     280 * \note Sometimes a LED is shared with GPIO or other functions. 
     281 * 
    270282 * @param[in] led The LED to illuminate. 
    271283 */ 
    272 void cc3_set_led (uint8_t led); 
     284void cc3_led_set_on (uint8_t led); 
    273285 
    274286/** 
    275287 * Deactivate an LED. 
    276288 * 
     289 * \note Sometimes a LED is shared with GPIO or other functions. 
     290 * 
    277291 * @param[in] led The LED to extinguish. 
    278292 */ 
    279 void cc3_clr_led (uint8_t led); 
     293void cc3_led_set_off (uint8_t led); 
    280294 
    281295/** 
     
    293307 * @param[in] res Resolution to set. 
    294308 */ 
    295 void cc3_set_resolution (cc3_camera_resolution_t res); 
     309void cc3_camera_set_resolution (cc3_camera_resolution_t res); 
    296310 
    297311/** 
     
    300314 * @param[in] colorspace The colorspace. 
    301315 */ 
    302 void cc3_set_colorspace (cc3_colorspace_t colorspace); 
     316void cc3_camera_set_colorspace (cc3_colorspace_t colorspace); 
    303317 
    304318/** 
     
    307321 * @param[in] rate_divider Desired framerate divider. 
    308322 */ 
    309 void cc3_set_framerate_divider (uint8_t rate_divider); 
     323void cc3_camera_set_framerate_divider (uint8_t rate_divider); 
    310324 
    311325/** 
     
    314328 * @param[in] ae Auto exposure value. 
    315329 */ 
    316 void cc3_set_auto_exposure (bool ae); 
     330void cc3_camera_set_auto_exposure (bool ae); 
    317331 
    318332/** 
     
    321335 * @param[in] wb Auto white balance value. 
    322336 */ 
    323 void cc3_set_auto_white_balance (bool wb); 
     337void cc3_camera_set_auto_white_balance (bool wb); 
    324338 
    325339/** 
     
    328342 * @param[in] level The level. 
    329343 */ 
    330 void cc3_set_brightness (uint8_t level); 
     344void cc3_camera_set_brightness (uint8_t level); 
    331345 
    332346/** 
     
    335349 * @param[in] level The level. 
    336350 */ 
    337 void cc3_set_contrast (uint8_t level); 
     351void cc3_camera_set_contrast (uint8_t level); 
    338352 
    339353/** 
     
    350364 * @return \a true if successful. 
    351365 */ 
    352 bool cc3_set_raw_register (uint8_t address, uint8_t value); 
    353  
    354 /** 
    355  * Get the number of UARTs on this device. 
    356  * 
    357  * @return Number of UARTs. 
    358  */ 
    359 uint8_t cc3_get_uart_count (void); 
     366bool cc3_camera_set_raw_register (uint8_t address, uint8_t value); 
    360367 
    361368/** 
     
    373380 
    374381/** 
     382 * Get the number of UARTs on this device. 
     383 * 
     384 * @return Number of UARTs. 
     385 */ 
     386uint8_t cc3_uart_get_count (void); 
     387 
     388/** 
    375389 * Get a file handle for a UART. 
    376390 * 
     
    379393 * @return The file handle or \a NULL if error. 
    380394 */ 
    381 FILE *cc3_fopen_uart (uint8_t uart, const char *mode); 
     395FILE *cc3_uart_fopen (uint8_t uart, const char *mode); 
    382396 
    383397/** 
     
    394408 * @return Number of milliseconds since an arbitrary time in the past. 
    395409 */ 
    396 uint32_t cc3_get_current_ms (void); 
     410uint32_t cc3_timer_get_current_ms (void); 
    397411 
    398412/** 
     
    401415 * @param[in] delay Number of milliseconds to sleep. 
    402416 */ 
    403 void cc3_wait_ms (uint32_t delay); 
     417void cc3_timer_wait_ms (uint32_t delay); 
    404418 
    405419/** 
     
    408422 * @return \a true if button is depressed. 
    409423 */ 
    410 bool cc3_read_button (void); 
    411  
    412  
    413 /** 
    414  * Initialize the servo subsystem. 
    415  */ 
    416 void cc3_servo_init (void); 
    417  
    418 /** 
    419  * Set the servo mask. 
    420  * 
    421  * @param[in] mask The bitmask of servos to drive. 
    422  */ 
    423 void cc3_servo_mask (uint8_t mask); 
     424bool cc3_button_get_state (void); 
     425 
    424426 
    425427/** 
    426428 * Set a servo to a position. 
    427429 * 
    428  * @param[in] servo The servo to set. 
    429  * @param[in] pos The position to set the servo. 
     430 * \note If the pin is not in servo mode, this function will still 
     431 * set the position, but will not change the mode of the pin. 
     432 * 
     433 * @sa cc3_gpio_set_mode() for setting a pin to servo mode. 
     434 * 
     435 * @param[in] pin The pin to set. 
     436 * @param[in] position The position to set the servo. 
    430437 * @return \a true if successful. 
    431438 */ 
    432 bool cc3_servo_set (uint8_t servo, uint32_t pos); 
    433  
    434 /** 
    435  * Disable the servo subsystem to conserve power. To use the servos again, 
    436  * call cc3_servo_init(). 
    437  */ 
    438 void cc3_servo_disable (void); 
    439  
    440  
    441 void cc3_gpio_set_to_input(uint8_t mask); 
    442 void cc3_gpio_set_to_output(uint8_t mask); 
    443 uint8_t cc3_gpio_set_pin(uint8_t pin); 
    444 uint8_t cc3_gpio_get_pin(uint8_t pin); 
    445  
     439bool cc3_gpio_set_servo_position (uint8_t pin, uint8_t position); 
     440 
     441/** 
     442 * Configure a GPIO pin as input, output, or servo. 
     443 * 
     444 * @param[in] pin The pin to set. 
     445 * @param[in] mode The mode to set the pin to. 
     446 */ 
     447void cc3_gpio_set_mode (uint8_t pin, cc3_gpio_mode_t mode); 
     448 
     449/** 
     450 * Get the current mode setting for a GPIO pin. 
     451 * 
     452 * @param[in] pin The pin to assign a mode to. 
     453 * @return The GPIO mode for this pin. 
     454 */ 
     455cc3_gpio_mode_t cc3_gpio_get_mode(uint8_t pin); 
     456 
     457/** 
     458 * Set a GPIO pin to a value. 
     459 * \note This has no effect if a pin's mode is set to input. 
     460 * It has only a momentary effect if the pin's mode is set to servo. 
     461 * 
     462 * @param[in] pin The pin to set. 
     463 * @param[in] value The value to set the pin to. 
     464 */ 
     465void cc3_gpio_set_value(uint8_t pin, bool value); 
     466 
     467/** 
     468 * Read the value from a GPIO pin. 
     469 * \note If this pin is in input mode, this will return the last value 
     470 * the pin was set to. 
     471 * 
     472 * @param[in] pin The pin to get. 
     473 * @return The value of the pin. 
     474 */ 
     475bool cc3_gpio_get_value(uint8_t pin); 
     476 
     477/** 
     478 * Get the number of available GPIO pins. 
     479 * 
     480 * @return The number of GPIO pins. 
     481 */ 
     482uint8_t cc3_gpio_get_count(void); 
    446483 
    447484#endif 
  • trunk/projects/benchmark/bench.c

    r401 r420  
    2727  cc3_camera_init (); 
    2828   
    29   cc3_set_colorspace(CC3_COLORSPACE_RGB); 
    30   cc3_set_resolution(CC3_RES_LOW); 
    31   cc3_set_auto_white_balance(true); 
    32   cc3_set_auto_exposure(true); 
     29  cc3_camera_set_colorspace(CC3_COLORSPACE_RGB); 
     30  cc3_camera_set_resolution(CC3_CAMERA_RESOLUTION_LOW); 
     31  cc3_camera_set_auto_white_balance(true); 
     32  cc3_camera_set_auto_exposure(true); 
    3333   
    3434  buf = cc3_malloc_rows(1); 
     
    4242  i = 0; 
    4343  next_print = print_increment; 
    44   last_time = cc3_get_current_ms(); 
     44  last_time = cc3_timer_get_current_ms(); 
    4545 
    4646  while(true) { 
     
    5252 
    5353    if (i >= next_print) { 
    54       double fps = print_increment / ((cc3_get_current_ms() - last_time) / 1000.0); 
     54      double fps = print_increment / ((cc3_timer_get_current_ms() - last_time) / 1000.0); 
    5555      printf("%d frames, %g fps\n", i, fps); 
    5656       
    5757      next_print += print_increment; 
    58       last_time = cc3_get_current_ms(); 
     58      last_time = cc3_timer_get_current_ms(); 
    5959    } 
    6060  } 
  • trunk/projects/cmucam2/cmucam2.c

    r419 r420  
    9999 
    100100  if (!cc3_camera_init ()) { 
    101     cc3_set_led(0); 
     101    cc3_led_set_on(0); 
    102102    exit(1); 
    103103  } 
     
    105105  demo_mode=false; 
    106106  auto_servo_mode=false; 
    107   start_time = cc3_get_current_ms (); 
     107  start_time = cc3_timer_get_current_ms (); 
    108108  do  
    109109  { 
    110     if(cc3_read_button()==1) 
     110    if(cc3_button_get_state()==1) 
    111111    { 
    112112        // Demo Mode flag 
     
    114114        auto_servo_mode=true; 
    115115        // Debounce Switch 
    116         cc3_clr_led(0); 
    117         cc3_wait_ms(500); 
     116        cc3_led_set_off(0); 
     117        cc3_timer_wait_ms(500); 
    118118        break; 
    119119    } <