Changeset 420
- Timestamp:
- 02/17/07 21:29:20 (2 years ago)
- Files:
-
- trunk/hal/lpc2106-cmucam3/cc3.c (modified) (10 diffs)
- trunk/hal/lpc2106-cmucam3/cc3_hal.c (modified) (1 diff)
- trunk/hal/lpc2106-cmucam3/gpio.c (modified) (3 diffs)
- trunk/hal/lpc2106-cmucam3/serial.c (modified) (3 diffs)
- trunk/hal/lpc2106-cmucam3/servo.c (modified) (8 diffs)
- trunk/hal/lpc2106-cmucam3/servo.h (modified) (2 diffs)
- trunk/hal/lpc2106-cmucam3/uart_driver.c (modified) (1 diff)
- trunk/hal/virtual-cam/cc3.c (modified) (15 diffs)
- trunk/hal/virtual-cam/cc3_hal.c (modified) (3 diffs)
- trunk/hal/virtual-cam/gpio.c (modified) (1 diff)
- trunk/hal/virtual-cam/serial.c (modified) (2 diffs)
- trunk/hal/virtual-cam/servo.c (modified) (3 diffs)
- trunk/include/cc3.h (modified) (17 diffs)
- trunk/projects/benchmark/bench.c (modified) (3 diffs)
- trunk/projects/cmucam2/cmucam2.c (modified) (13 diffs)
- trunk/projects/cmucam2/polly.c (modified) (4 diffs)
- trunk/projects/edge-follow/main.c (modified) (2 diffs)
- trunk/projects/edge-follow/polly.c (modified) (3 diffs)
- trunk/projects/eeprom-test/main.c (modified) (1 diff)
- trunk/projects/hello-world/main.c (modified) (9 diffs)
- trunk/projects/jpeg-cam/main.c (modified) (3 diffs)
- trunk/projects/led-test/main.c (modified) (1 diff)
- trunk/projects/png-grab/main.c (modified) (5 diffs)
- trunk/projects/polly/main.c (modified) (2 diffs)
- trunk/projects/polly/polly.c (modified) (4 diffs)
- trunk/projects/polly/polly_no_cc3.c (modified) (2 diffs)
- trunk/projects/ppm-grab/main.c (modified) (5 diffs)
- trunk/projects/spoonBot/main.c (modified) (1 diff)
- trunk/projects/spoonBot/spoonBot.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/hal/lpc2106-cmucam3/cc3.c
r414 r420 212 212 213 213 214 void cc3_ clr_led(uint8_t select)214 void cc3_led_set_off (uint8_t select) 215 215 { 216 216 switch (select) { … … 229 229 230 230 231 void cc3_ set_led(uint8_t select)231 void cc3_led_set_on (uint8_t select) 232 232 { 233 233 … … 391 391 * 392 392 */ 393 void cc3_ wait_ms (uint32_t delay)393 void cc3_timer_wait_ms (uint32_t delay) 394 394 { 395 395 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 401 uint32_t cc3_timer_get_current_ms () 402 402 { 403 403 return (REG (TIMER0_TC)); // REG in milliseconds … … 718 718 * For basic manipulation of camera parameters see other cc3_set_xxxx functions. 719 719 */ 720 bool cc3_ set_raw_register (uint8_t address, uint8_t value)720 bool cc3_camera_set_raw_register (uint8_t address, uint8_t value) 721 721 { 722 722 unsigned int data[3]; … … 741 741 * Takes enum CC3_RES_LOW and CC3_RES_HIGH. 742 742 */ 743 void cc3_ set_resolution (cc3_camera_resolution_t cam_res)743 void cc3_camera_set_resolution (cc3_camera_resolution_t cam_res) 744 744 { 745 745 _cc3_g_current_camera_state.resolution = cam_res; … … 755 755 756 756 757 void cc3_ set_colorspace (cc3_colorspace_t colorspace)757 void cc3_camera_set_colorspace (cc3_colorspace_t colorspace) 758 758 { 759 759 _cc3_g_current_camera_state.colorspace = colorspace; … … 762 762 763 763 764 void cc3_ set_framerate_divider (uint8_t rate_divider)764 void cc3_camera_set_framerate_divider (uint8_t rate_divider) 765 765 { 766 766 _cc3_g_current_camera_state.clock_divider = rate_divider; … … 768 768 } 769 769 770 void cc3_ set_auto_exposure (bool exp)770 void cc3_camera_set_auto_exposure (bool exp) 771 771 { 772 772 _cc3_g_current_camera_state.auto_exposure = exp; … … 774 774 } 775 775 776 void cc3_ set_auto_white_balance (bool awb)776 void cc3_camera_set_auto_white_balance (bool awb) 777 777 { 778 778 _cc3_g_current_camera_state.auto_white_balance = awb; … … 780 780 } 781 781 782 void cc3_ set_brightness (uint8_t level)782 void cc3_camera_set_brightness (uint8_t level) 783 783 { 784 784 _cc3_g_current_camera_state.brightness = level; 785 785 _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 788 void cc3_camera_set_contrast (uint8_t level) 790 789 { 791 790 _cc3_g_current_camera_state.contrast = level; 792 791 _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 795 bool cc3_button_get_state (void) 798 796 { 799 797 bool result = !(REG (GPIO_IOPIN) & _CC3_BUTTON); trunk/hal/lpc2106-cmucam3/cc3_hal.c
r412 r420 110 110 case _CC3_OV6620: 111 111 // Set the right data bus mode 112 result &= cc3_ set_raw_register (0x14, 0x20);112 result &= cc3_camera_set_raw_register (0x14, 0x20); 113 113 // 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) { 115 115 _cc3_g_current_camera_state.raw_width = CC3_LO_RES_WIDTH; // 88 * 2; 116 116 _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); 118 118 } 119 119 else { 120 120 _cc3_g_current_camera_state.raw_width = CC3_HI_RES_WIDTH; // 176 * 2; 121 121 _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); 123 123 } 124 124 125 125 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); 127 127 } 128 128 else { 129 129 // 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); 131 131 if (_cc3_g_current_camera_state.brightness != -1) 132 result &= cc3_ set_raw_register (0x06,132 result &= cc3_camera_set_raw_register (0x06, 133 133 (_cc3_g_current_camera_state. 134 134 brightness & 0xFF)); 135 135 136 136 if (_cc3_g_current_camera_state.contrast != -1) 137 result &= cc3_ set_raw_register (0x05,137 result &= cc3_camera_set_raw_register (0x05, 138 138 (_cc3_g_current_camera_state.contrast & 0xFF)); 139 139 } 140 140 // Set Colorspace and Auto White Balance 141 result &= cc3_ set_raw_register (0x12,141 result &= cc3_camera_set_raw_register (0x12, 142 142 0x20 | (_cc3_g_current_camera_state. 143 143 auto_white_balance << 2) 144 144 | (_cc3_g_current_camera_state.colorspace << 3)); 145 145 // 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); 147 147 148 148 break; trunk/hal/lpc2106-cmucam3/gpio.c
r395 r420 1 1 /* 2 * Copyright 2006 Anthony Rowe and Adam Goode2 * Copyright 2006-2007 Anthony Rowe and Adam Goode 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 18 18 19 19 #include "gpio.h" 20 #include "servo.h" 21 #include "LPC2100.h" 20 22 #include <stdio.h> 21 23 #include "cc3_pin_defines.h" … … 25 27 26 28 27 void cc3_gpio_set_ to_input(uint8_t mask)29 void cc3_gpio_set_mode(uint8_t pin, cc3_gpio_mode_t mode) 28 30 { 31 if (pin >= MAX_SERVOS) { 32 return; 33 } 29 34 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 } 30 63 } 31 64 32 void cc3_gpio_set_ to_output(uint8_t mask)65 void cc3_gpio_set_value(uint8_t pin, bool value) 33 66 { 67 if (pin >= MAX_SERVOS) { 68 return; 69 } 34 70 71 if (value) { 72 REG (GPIO_IOSET) = _cc3_servo_map[pin]; 73 } else { 74 REG (GPIO_IOCLR) = _cc3_servo_map[pin]; 75 } 35 76 } 36 77 37 uint8_t cc3_gpio_set_pin(uint8_t pin) 78 79 bool cc3_gpio_get_value(uint8_t pin) 38 80 { 81 if (pin >= MAX_SERVOS) { 82 return false; 83 } 39 84 85 return REG (GPIO_IOPIN) & _cc3_servo_map[pin]; 40 86 } 41 87 42 uint8_t cc3_gpio_get_pin(uint8_t pin) 88 89 uint8_t cc3_gpio_get_count() 43 90 { 44 45 91 return MAX_SERVOS; 46 92 } 47 trunk/hal/lpc2106-cmucam3/serial.c
r332 r420 108 108 } 109 109 110 uint8_t cc3_ get_uart_count(void)110 uint8_t cc3_uart_get_count(void) 111 111 { 112 112 return 2; … … 132 132 } 133 133 134 if (uart >= cc3_ get_uart_count()) {134 if (uart >= cc3_uart_get_count()) { 135 135 return false; 136 136 } … … 190 190 } 191 191 192 FILE *cc3_ fopen_uart(uint8_t uart, const char *mode)192 FILE *cc3_uart_fopen(uint8_t uart, const char *mode) 193 193 { 194 194 char buf[8]; // safe, because uint8_t trunk/hal/lpc2106-cmucam3/servo.c
r397 r420 1 1 /* 2 * Copyright 2006 Anthony Rowe and Adam Goode2 * Copyright 2006-2007 Anthony Rowe and Adam Goode 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 24 24 #include <stdio.h> 25 25 26 // Set a particular servo pin low 27 static void _cc3_servo_lo (uint8_t n); 26 static uint8_t servo_val[MAX_SERVOS] = { 27 SERVO_RESOLUTION / 2, 28 SERVO_RESOLUTION / 2, 29 SERVO_RESOLUTION / 2, 30 SERVO_RESOLUTION / 2, 31 }; 28 32 29 // Set all pins high at the start of the servo cycle 30 static void _cc3_servo_hi_all (void); 33 static uint8_t servo_tmp[MAX_SERVOS]; 34 static uint32_t servo_mask; 35 36 const uint32_t _cc3_servo_map[] = 37 { 38 _CC3_SERVO_0, 39 _CC3_SERVO_1, 40 _CC3_SERVO_2, 41 _CC3_SERVO_3, 42 }; 31 43 32 44 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) 45 bool cc3_gpio_set_servo_position (uint8_t servo, uint8_t pos) 48 46 { 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; 55 51 } 56 52 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 () 53 static void servo_init (void) 66 54 { 67 int i;68 servo_mask=0xFFFFF;69 for (i = 0; i < MAX_SERVOS; i++)70 servo_val[i] = SERVO_RESOLUTION / 2;71 55 // Setup timer1 to handle servos 72 56 REG (TIMER1_TCR) = 0; // turn off timer … … 82 66 } 83 67 84 void cc3_servo_mask(uint8_t mask)85 {86 servo_mask=mask;87 }88 89 90 68 /** 91 69 * _cc3_servo_hi_all() … … 94 72 * the 20ms servo period. 95 73 */ 96 void _cc3_servo_hi_all ()74 static void servo_hi_all (void) 97 75 { 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; 105 82 } 106 83 … … 110 87 * This pulls a particular servo line low. 111 88 */ 112 void _cc3_servo_lo (uint8_t n)89 static void servo_lo (uint8_t n) 113 90 { 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 94 void _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(); 131 111 } 132 112 113 // set to low 114 servo_lo(servo); 115 } 133 116 } 134 135 /**136 * cc3_disable()137 *138 * This function disables the servo interrupt and139 * 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 149 117 150 118 /** … … 152 120 * 153 121 * This is where the servo magic happens. This function is called from 154 * the timer1 interrupt in interrupt s.c.122 * the timer1 interrupt in interrupt.c. 155 123 * 156 124 * It will schedule the next timer interrupt to fire when the next pin … … 172 140 REG (TIMER1_TC) = 0; 173 141 REG (TIMER1_MR0) = SERVO_RESOLUTION; // schedule next wakeup for 1ms 174 _cc3_servo_hi_all ();142 servo_hi_all (); 175 143 // Copy current values into working values to avoid changes while 176 144 // in the scheduling loop … … 187 155 if (servo_tmp[i] < min && servo_tmp[i] > (ct + safety)) 188 156 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); 191 159 } 192 160 // If all pins have been serviced, set a new interrupt for the trunk/hal/lpc2106-cmucam3/servo.h
r302 r420 27 27 // SERVO_RESOLUTION sets resolution within 1ms 28 28 // Failure may occure above 512 29 #define SERVO_RESOLUTION 255 29 #define SERVO_RESOLUTION 255 30 30 #define MAX_SERVOS 4 31 31 #define SERVO_PERIOD 18 … … 36 36 void _cc3_servo_int (void); 37 37 38 void _cc3_servo_enable(uint8_t servo, bool enable); 39 40 extern const uint32_t _cc3_servo_map[]; 41 38 42 #endif trunk/hal/lpc2106-cmucam3/uart_driver.c
r360 r420 33 33 { 34 34 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()) { 36 36 return uart_num + max_uarts; // new uart 37 37 } else { trunk/hal/virtual-cam/cc3.c
r414 r420 117 117 do{ 118 118 // 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 ) 120 120 { 121 121 for(k=0; k<352; k++ ) … … 145 145 val = b2 = fgetc(fp); 146 146 // 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 ) { 148 148 r = fgetc(fp); 149 149 g = fgetc(fp); … … 273 273 274 274 275 void cc3_ clr_led(uint8_t select)275 void cc3_led_set_off (uint8_t select) 276 276 { 277 277 switch (select) { … … 290 290 291 291 292 void cc3_ set_led(uint8_t select)292 void cc3_led_set_on (uint8_t select) 293 293 { 294 294 … … 458 458 * 459 459 */ 460 void cc3_ wait_ms (uint32_t delay)460 void cc3_timer_wait_ms (uint32_t delay) 461 461 { 462 462 uint32_t start; … … 472 472 * This function returns the time since startup in ms as a uint32 473 473 */ 474 uint32_t cc3_timer ()474 uint32_t cc3_timer_get_current_ms () 475 475 { 476 476 //return (REG (TIMER0_TC)); // REG in milliseconds … … 697 697 * For basic manipulation of camera parameters see other cc3_set_xxxx functions. 698 698 */ 699 bool cc3_ set_raw_register (uint8_t address, uint8_t value)699 bool cc3_camera_set_raw_register (uint8_t address, uint8_t value) 700 700 { 701 701 unsigned int data[3]; … … 719 719 * Takes enum CC3_LOW_RES and CC3_HIGH_RES. 720 720 */ 721 void cc3_ set_resolution (cc3_camera_resolution_t cam_res)721 void cc3_camera_set_resolution (cc3_camera_resolution_t cam_res) 722 722 { 723 723 _cc3_g_current_camera_state.resolution = cam_res; … … 739 739 * the pixel array. 740 740 */ 741 void cc3_ set_colorspace (cc3_colorspace_t colorspace)741 void cc3_camera_set_colorspace (cc3_colorspace_t colorspace) 742 742 { 743 743 _cc3_g_current_camera_state.colorspace = colorspace; … … 746 746 747 747 748 void cc3_ set_framerate_divider (uint8_t rate_divider)748 void cc3_camera_set_framerate_divider (uint8_t rate_divider) 749 749 { 750 750 _cc3_g_current_camera_state.clock_divider = rate_divider; … … 752 752 } 753 753 754 void cc3_ set_auto_exposure (bool exp)754 void cc3_camera_set_auto_exposure (bool exp) 755 755 { 756 756 _cc3_g_current_camera_state.auto_exposure = exp; … … 758 758 } 759 759 760 void cc3_ set_auto_white_balance (bool awb)760 void cc3_camera_set_auto_white_balance (bool awb) 761 761 { 762 762 _cc3_g_current_camera_state.auto_white_balance = awb; … … 764 764 } 765 765 766 void cc3_ set_brightness (uint8_t level)766 void cc3_camera_set_brightness (uint8_t level) 767 767 { 768 768 _cc3_g_current_camera_state.brightness = level; … … 770 770 } 771 771 772 void cc3_ set_contrast (uint8_t level)772 void cc3_camera_set_contrast (uint8_t level) 773 773 { 774 774 _cc3_g_current_camera_state.contrast = level; … … 777 777 778 778 779 bool cc3_ read_button(void)779 bool cc3_button_get_state (void) 780 780 { 781 781 return 1; trunk/hal/virtual-cam/cc3_hal.c
r399 r420 23 23 24 24 25 void reset_virtual_fifo( );25 void reset_virtual_fifo(void); 26 26 27 27 void reset_virtual_fifo() … … 104 104 //cc3_set_raw_register (0x14, 0x20); 105 105 // 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) { 107 107 _cc3_g_current_camera_state.raw_width = CC3_LO_RES_WIDTH; 108 108 _cc3_g_current_camera_state.raw_height = CC3_LO_RES_HEIGHT; … … 120 120 else { 121 121 // 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); 123 123 //if (_cc3_g_current_camera_state.brightness != -1) 124 124 // cc3_set_raw_register (0x06, trunk/hal/virtual-cam/gpio.c
r395 r420 25 25 26 26 27 void cc3_gpio_set_ to_input(uint8_t mask)27 void cc3_gpio_set_mode(uint8_t pin, cc3_gpio_mode_t mode) 28 28 { 29 29 30 30 } 31 31 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 74 74 } 75 75 76 uint8_t cc3_ get_uart_count(void)76 uint8_t cc3_uart_get_count(void) 77 77 { 78 78 return 2; … … 156 156 } 157 157 158 FILE *cc3_ fopen_uart(uint8_t uart, const char *mode)158 FILE *cc3_uart_fopen(uint8_t uart, const char *mode) 159 159 { 160 160 // char buf[8]; // safe, because uint8_t trunk/hal/virtual-cam/servo.c
r395 r420 43 43 * The servo operates at 50hz. 44 44 */ 45 bool cc3_ servo_set (uint8_t servo, uint32_t pos)45 bool cc3_gpio_set_servo_position (uint8_t servo, uint8_t pos) 46 46 { 47 47 if (servo > MAX_SERVOS) … … 52 52 return true; 53 53 } 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.c60 *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 servos70 }71 72 void cc3_servo_mask(uint8_t mask)73 {74 servo_mask=mask;75 }76 77 54 78 55 /** … … 122 99 123 100 /** 124 * cc3_disable()125 *126 * This function disables the servo interrupt and127 * 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 /**137 101 * _cc3_servo_int() 138 102 * trunk/include/cc3.h
r414 r420 45 45 */ 46 46 typedef 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 */ 49 49 } cc3_camera_resolution_t; 50 50 … … 129 129 CC3_UART_BINMODE_TEXT, /**< Read CR as LF, write LF as CR */ 130 130 } cc3_uart_binmode_t; 131 132 /** 133 * GPIO configuration values. 134 * @sa cc3_gpio_set_mode() and cc3_gpio_get_mode(). 135 */ 136 typedef enum { 137 CC3_GPIO_MODE_INPUT, 138 CC3_GPIO_MODE_OUTPUT, 139 CC3_GPIO_MODE_SERVO, 140 } cc3_gpio_mode_t; 131 141 132 142 /** … … 202 212 * the amount of memory corresponding to the old row size. 203 213 * 204 * \sa cc3_pixbuf_read_rows()214 * @sa cc3_pixbuf_read_rows() 205 215 * 206 216 * @param[in] rows The number of rows to allocate space for. … … 268 278 * Activate an LED. 269 279 * 280 * \note Sometimes a LED is shared with GPIO or other functions. 281 * 270 282 * @param[in] led The LED to illuminate. 271 283 */ 272 void cc3_ set_led(uint8_t led);284 void cc3_led_set_on (uint8_t led); 273 285 274 286 /** 275 287 * Deactivate an LED. 276 288 * 289 * \note Sometimes a LED is shared with GPIO or other functions. 290 * 277 291 * @param[in] led The LED to extinguish. 278 292 */ 279 void cc3_ clr_led(uint8_t led);293 void cc3_led_set_off (uint8_t led); 280 294 281 295 /** … … 293 307 * @param[in] res Resolution to set. 294 308 */ 295 void cc3_ set_resolution (cc3_camera_resolution_t res);309 void cc3_camera_set_resolution (cc3_camera_resolution_t res); 296 310 297 311 /** … … 300 314 * @param[in] colorspace The colorspace. 301 315 */ 302 void cc3_ set_colorspace (cc3_colorspace_t colorspace);316 void cc3_camera_set_colorspace (cc3_colorspace_t colorspace); 303 317 304 318 /** … … 307 321 * @param[in] rate_divider Desired framerate divider. 308 322 */ 309 void cc3_ set_framerate_divider (uint8_t rate_divider);323 void cc3_camera_set_framerate_divider (uint8_t rate_divider); 310 324 311 325 /** … … 314 328 * @param[in] ae Auto exposure value. 315 329 */ 316 void cc3_ set_auto_exposure (bool ae);330 void cc3_camera_set_auto_exposure (bool ae); 317 331 318 332 /** … … 321 335 * @param[in] wb Auto white balance value. 322 336 */ 323 void cc3_ set_auto_white_balance (bool wb);337 void cc3_camera_set_auto_white_balance (bool wb); 324 338 325 339 /** … … 328 342 * @param[in] level The level. 329 343 */ 330 void cc3_ set_brightness (uint8_t level);344 void cc3_camera_set_brightness (uint8_t level); 331 345 332 346 /** … … 335 349 * @param[in] level The level. 336 350 */ 337 void cc3_ set_contrast (uint8_t level);351 void cc3_camera_set_contrast (uint8_t level); 338 352 339 353 /** … … 350 364 * @return \a true if successful. 351 365 */ 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); 366 bool cc3_camera_set_raw_register (uint8_t address, uint8_t value); 360 367 361 368 /** … … 373 380 374 381 /** 382 * Get the number of UARTs on this device. 383 * 384 * @return Number of UARTs. 385 */ 386 uint8_t cc3_uart_get_count (void); 387 388 /** 375 389 * Get a file handle for a UART. 376 390 * … … 379 393 * @return The file handle or \a NULL if error. 380 394 */ 381 FILE *cc3_ fopen_uart(uint8_t uart, const char *mode);395 FILE *cc3_uart_fopen (uint8_t uart, const char *mode); 382 396 383 397 /** … … 394 408 * @return Number of milliseconds since an arbitrary time in the past. 395 409 */ 396 uint32_t cc3_ get_current_ms (void);410 uint32_t cc3_timer_get_current_ms (void); 397 411 398 412 /** … … 401 415 * @param[in] delay Number of milliseconds to sleep. 402 416 */ 403 void cc3_ wait_ms (uint32_t delay);417 void cc3_timer_wait_ms (uint32_t delay); 404 418 405 419 /** … … 408 422 * @return \a true if button is depressed. 409 423 */ 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); 424 bool cc3_button_get_state (void); 425 424 426 425 427 /** 426 428 * Set a servo to a position. 427 429 * 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. 430 437 * @return \a true if successful. 431 438 */ 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 439 bool 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 */ 447 void 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 */ 455 cc3_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 */ 465 void 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 */ 475 bool 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 */ 482 uint8_t cc3_gpio_get_count(void); 446 483 447 484 #endif trunk/projects/benchmark/bench.c
r401 r420 27 27 cc3_camera_init (); 28 28 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); 33 33 34 34 buf = cc3_malloc_rows(1); … … 42 42 i = 0; 43 43 next_print = print_increment; 44 last_time = cc3_ get_current_ms();44 last_time = cc3_timer_get_current_ms(); 45 45 46 46 while(true) { … … 52 52 53 53 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); 55 55 printf("%d frames, %g fps\n", i, fps); 56 56 57 57 next_print += print_increment; 58 last_time = cc3_ get_current_ms();58 last_time = cc3_timer_get_current_ms(); 59 59 } 60 60 } trunk/projects/cmucam2/cmucam2.c
r419 r420 99 99 100 100 if (!cc3_camera_init ()) { 101 cc3_ set_led(0);101 cc3_led_set_on(0); 102 102 exit(1); 103 103 } … … 105 105 demo_mode=false; 106 106 auto_servo_mode=false; 107 start_time = cc3_ get_current_ms ();107 start_time = cc3_timer_get_current_ms (); 108 108 do 109 109 { 110 if(cc3_ read_button()==1)110 if(cc3_button_get_state()==1) 111 111 { 112 112 // Demo Mode flag … … 114 114 auto_servo_mode=true; 115 115 // Debounce Switch 116 cc3_ clr_led(0);117 cc3_ wait_ms(500);116 cc3_led_set_off(0); 117 cc3_timer_wait_ms(500); 118 118 break; 119 119 } <
