| 1 | #include <cc3.h> |
|---|
| 2 | #include <math.h> |
|---|
| 3 | #include <stdbool.h> |
|---|
| 4 | #include <string.h> |
|---|
| 5 | #include <ctype.h> |
|---|
| 6 | #include <stdlib.h> |
|---|
| 7 | #include "../../hal/lpc2103-retkodfuncam/LPC2100.h" |
|---|
| 8 | #include "../../hal/lpc2103-retkodfuncam/cc3_pin_defines.h" |
|---|
| 9 | #include "../../hal/lpc2103-retkodfuncam/interrupt.h" |
|---|
| 10 | |
|---|
| 11 | //#define SERIAL_BAUD_RATE CC3_UART_RATE_230400 |
|---|
| 12 | #define SERIAL_BAUD_RATE CC3_UART_RATE_115200 |
|---|
| 13 | //#define SERIAL_BAUD_RATE CC3_UART_RATE_57600 |
|---|
| 14 | //#define SERIAL_BAUD_RATE CC3_UART_RATE_38400 |
|---|
| 15 | //#define SERIAL_BAUD_RATE CC3_UART_RATE_19200 |
|---|
| 16 | //#define SERIAL_BAUD_RATE CC3_UART_RATE_9600 |
|---|
| 17 | //#define SERIAL_BAUD_RATE CC3_UART_RATE_4800 |
|---|
| 18 | //#define SERIAL_BAUD_RATE CC3_UART_RATE_2400 |
|---|
| 19 | //#define SERIAL_BAUD_RATE CC3_UART_RATE_1200 |
|---|
| 20 | //#define SERIAL_BAUD_RATE CC3_UART_RATE_300 |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #define DEFAULT_COLOR 0 |
|---|
| 24 | #define HSV_COLOR 1 |
|---|
| 25 | |
|---|
| 26 | #define MAX_ARGS 10 |
|---|
| 27 | #define MAX_LINE 128 |
|---|
| 28 | |
|---|
| 29 | #define VERSION_BANNER "CMUcam v1.00 c6" |
|---|
| 30 | |
|---|
| 31 | #define I2C_WRITE_BIT (0x80) |
|---|
| 32 | #define I2C_I2EN (0x40) |
|---|
| 33 | #define I2C_STA (0x20) |
|---|
| 34 | #define I2C_STO (0x10) |
|---|
| 35 | #define I2C_SI (0x08) |
|---|
| 36 | #define I2C_AA (0x04) |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | typedef enum { |
|---|
| 40 | RESET, |
|---|
| 41 | DUMP_FRAME, |
|---|
| 42 | GET_VERSION, |
|---|
| 43 | CAMERA_REG, |
|---|
| 44 | CAMERA_POWER, |
|---|
| 45 | LED_0, |
|---|
| 46 | GET_BUTTON, |
|---|
| 47 | |
|---|
| 48 | RETURN, // Must be second to last |
|---|
| 49 | CMUCAM1_CMDS_COUNT // Must be last entry so array sizes are correct |
|---|
| 50 | } cmucam1_command_t; |
|---|
| 51 | |
|---|
| 52 | static const char cmucam1_cmds[CMUCAM1_CMDS_COUNT][3] = { |
|---|
| 53 | [RETURN] = "", |
|---|
| 54 | |
|---|
| 55 | /* Camera Module Commands */ |
|---|
| 56 | [CAMERA_REG] = "CR", |
|---|
| 57 | [CAMERA_POWER] = "CP", |
|---|
| 58 | // CT camera type |
|---|
| 59 | |
|---|
| 60 | /* Image Windowing Commands */ |
|---|
| 61 | [DUMP_FRAME] = "DF", |
|---|
| 62 | |
|---|
| 63 | /* Auxiliary I/O Commands */ |
|---|
| 64 | [GET_BUTTON] = "GB", |
|---|
| 65 | [LED_0] = "L0", |
|---|
| 66 | // L1 LED control |
|---|
| 67 | |
|---|
| 68 | [RESET] = "RS", |
|---|
| 69 | [GET_VERSION] = "GV", |
|---|
| 70 | }; |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | static int32_t cmucam1_get_command (cmucam1_command_t * cmd, |
|---|
| 74 | uint32_t arg_list[]); |
|---|
| 75 | static int32_t cmucam1_get_command_raw (cmucam1_command_t * cmd, |
|---|
| 76 | uint32_t arg_list[]); |
|---|
| 77 | |
|---|
| 78 | int i2c_test_write_polling(uint8_t addr, uint8_t *data, int len); |
|---|
| 79 | void print_num(uint32_t x); |
|---|
| 80 | static void print_ACK (void); |
|---|
| 81 | static void print_NCK (void); |
|---|
| 82 | static void print_prompt (void); |
|---|
| 83 | static void print_cr (void); |
|---|
| 84 | static void cmucam1_send_image_direct (bool auto_led); |
|---|
| 85 | |
|---|
| 86 | static void raw_print (uint8_t val); |
|---|
| 87 | |
|---|
| 88 | static bool packet_filter_flag; |
|---|
| 89 | static uint8_t s_pkt_mask; |
|---|
| 90 | |
|---|
| 91 | static bool raw_mode_output; |
|---|
| 92 | static bool raw_mode_no_confirmations; |
|---|
| 93 | static bool raw_mode_input; |
|---|
| 94 | |
|---|
| 95 | static cmucam1_command_t command; |
|---|
| 96 | static uint32_t arg_list[MAX_ARGS]; |
|---|
| 97 | static bool error, poll_mode, auto_led, buf_mode,frame_stream_mode; |
|---|
| 98 | static int8_t line_mode; |
|---|
| 99 | |
|---|
| 100 | static char line_buf[MAX_LINE]; |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | volatile uint32_t hblk_cnt; |
|---|
| 104 | //volatile uint32_t dclk_cnt; |
|---|
| 105 | volatile uint32_t frame_done; |
|---|
| 106 | |
|---|
| 107 | volatile uint32_t row_width; |
|---|
| 108 | extern volatile uint8_t row_buf[ROW_BUF_LEN]; |
|---|
| 109 | |
|---|
| 110 | // XXX: This moved to interrupt.h and fast_interrupt.c |
|---|
| 111 | //volatile static uint8_t row_buf[1280]; |
|---|
| 112 | //int capture_row(uint8_t row); |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | uint32_t capture_next_row(uint32_t width); |
|---|
| 116 | |
|---|
| 117 | uint32_t capture_next_row(uint32_t width) |
|---|
| 118 | { |
|---|
| 119 | row_done=0; |
|---|
| 120 | row_width=width; |
|---|
| 121 | do{ |
|---|
| 122 | } while(!row_done); |
|---|
| 123 | return hblk_cnt; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | void my_vblk() |
|---|
| 127 | { |
|---|
| 128 | |
|---|
| 129 | // start of frame |
|---|
| 130 | frame_done=0; |
|---|
| 131 | hblk_cnt=0; |
|---|
| 132 | dclk_cnt=0; |
|---|
| 133 | enable_hblk_interrupt(); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | void my_hblk() |
|---|
| 138 | { |
|---|
| 139 | if(hblk_cnt<285) |
|---|
| 140 | { |
|---|
| 141 | // New row is starting |
|---|
| 142 | // Reset the dclk_cnt which is the index into |
|---|
| 143 | // the row buffer that gets filled by the dclk int |
|---|
| 144 | hblk_cnt++; |
|---|
| 145 | if( row_done==0 ) { |
|---|
| 146 | dclk_cnt=0; |
|---|
| 147 | enable_dclk_interrupt(); |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | else |
|---|
| 151 | { |
|---|
| 152 | |
|---|
| 153 | // end of frame |
|---|
| 154 | disable_vblk_interrupt(); |
|---|
| 155 | disable_hblk_interrupt(); |
|---|
| 156 | disable_dclk_interrupt(); |
|---|
| 157 | frame_done=1; |
|---|
| 158 | // Bail on the row wait if it didn't capture enough |
|---|
| 159 | row_done=1; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | int main (void) |
|---|
| 168 | { |
|---|
| 169 | int32_t val, n,led_state,x; |
|---|
| 170 | uint8_t red,green,blue,pix_data[4],y1,u,v,y2; |
|---|
| 171 | int32_t raw_pix_data[4],raw_pix_data_tmp; |
|---|
| 172 | int32_t row,col,row_max,col_max,i,j; |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | disable_dclk_interrupt(); |
|---|
| 176 | disable_hblk_interrupt(); |
|---|
| 177 | disable_vblk_interrupt(); |
|---|
| 178 | |
|---|
| 179 | cc3_uart_init (0, |
|---|
| 180 | SERIAL_BAUD_RATE, |
|---|
| 181 | CC3_UART_MODE_8N1, CC3_UART_BINMODE_BINARY); |
|---|
| 182 | |
|---|
| 183 | //cc3_timer_wait_ms(1000); |
|---|
| 184 | |
|---|
| 185 | cc3_uart0_write("going to do camera_init\r\n"); |
|---|
| 186 | |
|---|
| 187 | if (!cc3_camera_init ()) { |
|---|
| 188 | cc3_led_set_state (0, true); |
|---|
| 189 | exit (1); |
|---|
| 190 | } |
|---|
| 191 | /* |
|---|
| 192 | uint8_t data[] = {0x02, 0x40}; |
|---|
| 193 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 194 | |
|---|
| 195 | data[0] = 0x0d; |
|---|
| 196 | data[1] = 0x01; |
|---|
| 197 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 198 | |
|---|
| 199 | data[0] = 0x0b; |
|---|
| 200 | data[1] = 0x00; |
|---|
| 201 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 202 | |
|---|
| 203 | data[0] = 0x6d; |
|---|
| 204 | data[1] = 0xa1; |
|---|
| 205 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 206 | |
|---|
| 207 | data[0] = 0x58; |
|---|
| 208 | data[1] = 0x10; |
|---|
| 209 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 210 | |
|---|
| 211 | // agr turn on PLL |
|---|
| 212 | // data[0] = 0x03; |
|---|
| 213 | // data[1] = 0x08; |
|---|
| 214 | //data[1] = 0x80; |
|---|
| 215 | // n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | data[0] = 0x05; |
|---|
| 219 | data[1] = 0x00; |
|---|
| 220 | //data[1] = 0x80; |
|---|
| 221 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 222 | |
|---|
| 223 | data[0] = 0x1a; |
|---|
| 224 | data[1] = 0x00; |
|---|
| 225 | // data[1] = 0xff; |
|---|
| 226 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 227 | |
|---|
| 228 | data[0] = 0x1b; |
|---|
| 229 | data[1] = 0x00; |
|---|
| 230 | // data[1] = 0xb3; |
|---|
| 231 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 232 | |
|---|
| 233 | // agr new since cmucam1 frame dump |
|---|
| 234 | data[0] = 0x1c; |
|---|
| 235 | data[1] = 0x00; |
|---|
| 236 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 237 | |
|---|
| 238 | data[0] = 0x1c; |
|---|
| 239 | data[1] = 0x00; |
|---|
| 240 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 241 | |
|---|
| 242 | data[0] = 0x0e; |
|---|
| 243 | // data[1] = 0x14; |
|---|
| 244 | data[1] = 0x1c; |
|---|
| 245 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 246 | |
|---|
| 247 | data[0] = 0x11; |
|---|
| 248 | // data[1] = 0x6a; |
|---|
| 249 | data[1] = 0x4a; |
|---|
| 250 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 251 | |
|---|
| 252 | data[0] = 0x14; |
|---|
| 253 | data[1] = 0x33; |
|---|
| 254 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 255 | |
|---|
| 256 | data[0] = 0x1f; |
|---|
| 257 | // data[1] = 0x0b; |
|---|
| 258 | data[1] = 0x01; |
|---|
| 259 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 260 | |
|---|
| 261 | data[0] = 0x1e; |
|---|
| 262 | data[1] = 0x7e; |
|---|
| 263 | // data[1] = 0xe7; |
|---|
| 264 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 265 | |
|---|
| 266 | data[0] = 0x04; |
|---|
| 267 | //data[1] = 0x18; |
|---|
| 268 | data[1] = 0x1d; |
|---|
| 269 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 270 | */ |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | uint8_t data[] = {0x02, 0x40}; |
|---|
| 274 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 275 | |
|---|
| 276 | data[0] = 0x0d; |
|---|
| 277 | data[1] = 0x01; |
|---|
| 278 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 279 | |
|---|
| 280 | data[0] = 0x0b; |
|---|
| 281 | data[1] = 0x00; |
|---|
| 282 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 283 | |
|---|
| 284 | data[0] = 0x6d; |
|---|
| 285 | data[1] = 0xa1; |
|---|
| 286 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 287 | |
|---|
| 288 | data[0] = 0x58; |
|---|
| 289 | data[1] = 0x10; |
|---|
| 290 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 291 | |
|---|
| 292 | data[0] = 0x05; |
|---|
| 293 | data[1] = 0x00; |
|---|
| 294 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 295 | |
|---|
| 296 | data[0] = 0x1a; |
|---|
| 297 | data[1] = 0xff; |
|---|
| 298 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 299 | |
|---|
| 300 | data[0] = 0x1b; |
|---|
| 301 | data[1] = 0xb3; |
|---|
| 302 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 303 | |
|---|
| 304 | data[0] = 0x0e; |
|---|
| 305 | data[1] = 0x1c; |
|---|
| 306 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 307 | |
|---|
| 308 | data[0] = 0x11; |
|---|
| 309 | data[1] = 0x4a; |
|---|
| 310 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 311 | |
|---|
| 312 | data[0] = 0x14; |
|---|
| 313 | data[1] = 0x33; |
|---|
| 314 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 315 | |
|---|
| 316 | data[0] = 0x1f; |
|---|
| 317 | data[1] = 0x0b; |
|---|
| 318 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 319 | |
|---|
| 320 | data[0] = 0x1e; |
|---|
| 321 | data[1] = 0xe7; |
|---|
| 322 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 323 | |
|---|
| 324 | data[0] = 0x04; |
|---|
| 325 | data[1] = 0x1d; //YUV |
|---|
| 326 | // data[1] = 0x19; //RGB |
|---|
| 327 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | /* |
|---|
| 332 | uint8_t data[] = {0x02, 0x40}; |
|---|
| 333 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 334 | |
|---|
| 335 | data[0] = 0x0d; data[1] = 0x01; |
|---|
| 336 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 337 | |
|---|
| 338 | data[0] = 0x0b; data[1] = 0x00; |
|---|
| 339 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 340 | |
|---|
| 341 | data[0] = 0x6d; data[1] = 0xa1; |
|---|
| 342 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 343 | |
|---|
| 344 | data[0] = 0x58; data[1] = 0x10; |
|---|
| 345 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 346 | |
|---|
| 347 | data[0] = 0x05; data[1] = 0x00; |
|---|
| 348 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 349 | |
|---|
| 350 | data[0] = 0x1a; data[1] = 0x00; |
|---|
| 351 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 352 | |
|---|
| 353 | data[0] = 0x1b; data[1] = 0x00; |
|---|
| 354 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 355 | |
|---|
| 356 | // data[0] = 0x1c; data[1] = 0x00; |
|---|
| 357 | // n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 358 | |
|---|
| 359 | data[0] = 0x1e; data[1] = 0x7e; |
|---|
| 360 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 361 | |
|---|
| 362 | data[0] = 0x1f; data[1] = 0x01; |
|---|
| 363 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 364 | |
|---|
| 365 | data[0] = 0x0e; data[1] = 0xac; |
|---|
| 366 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 367 | |
|---|
| 368 | data[0] = 0x04; data[1] = 0x1d; |
|---|
| 369 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 370 | |
|---|
| 371 | data[0] = 0x11; data[1] = 0x4a; |
|---|
| 372 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 373 | |
|---|
| 374 | data[0] = 0x14; data[1] = 0x33; |
|---|
| 375 | n=i2c_test_write_polling(0x3d, data, sizeof data); |
|---|
| 376 | */ |
|---|
| 377 | |
|---|
| 378 | |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | cc3_uart0_write("Cam Setup\r\n"); |
|---|
| 382 | |
|---|
| 383 | register_vblk_callback(&my_vblk); |
|---|
| 384 | //register_dclk_callback(&my_dclk); |
|---|
| 385 | register_hblk_callback(&my_hblk); |
|---|
| 386 | |
|---|
| 387 | init_camera_interrupts(); |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | |
|---|
| 391 | /* |
|---|
| 392 | // while(1){ |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | cc3_uart0_putchar (1); |
|---|
| 396 | // Start next frame capture (vblk stops at end of frame) |
|---|
| 397 | enable_vblk_interrupt(); |
|---|
| 398 | |
|---|
| 399 | do { |
|---|
| 400 | // ask for a row of size n, return which row was captured |
|---|
| 401 | row=capture_next_row(ROW_BUF_LEN); // 1280 is max |
|---|
| 402 | cc3_uart0_putchar (2); |
|---|
| 403 | for(i=0; i<ROW_BUF_LEN; i++ ) |
|---|
| 404 | { |
|---|
| 405 | |
|---|
| 406 | // red=row_buf[i+1] & 0xf8; |
|---|
| 407 | // blue=row_buf[i] & 0x1f<<3; |
|---|
| 408 | // green=(row_buf[i] & 0xe0>>5) | (row_buf[i+1]<<5); |
|---|
| 409 | // i++; |
|---|
| 410 | // if(red<4) red=4; |
|---|
| 411 | // if(green<4) green=4; |
|---|
| 412 | // if(blue<4) blue=4; |
|---|
| 413 | // cc3_uart0_putchar (red); |
|---|
| 414 | // cc3_uart0_putchar (green); |
|---|
| 415 | // cc3_uart0_putchar (blue); |
|---|
| 416 | |
|---|
| 417 | |
|---|
| 418 | |
|---|
| 419 | y1=row_buf[i]; |
|---|
| 420 | u=row_buf[i+1]; |
|---|
| 421 | y2=row_buf[i+2]; |
|---|
| 422 | v=row_buf[i+3]; |
|---|
| 423 | i+=3; |
|---|
| 424 | |
|---|
| 425 | cc3_uart0_putchar (y1); |
|---|
| 426 | cc3_uart0_putchar (u); |
|---|
| 427 | cc3_uart0_putchar (v); |
|---|
| 428 | |
|---|
| 429 | cc3_uart0_putchar (y2); |
|---|
| 430 | cc3_uart0_putchar (u); |
|---|
| 431 | cc3_uart0_putchar (v); |
|---|
| 432 | } |
|---|
| 433 | //print_num(row); |
|---|
| 434 | //cc3_uart0_write("\r\n"); |
|---|
| 435 | } while(!frame_done); |
|---|
| 436 | cc3_uart0_putchar (3); |
|---|
| 437 | while(1); |
|---|
| 438 | // } |
|---|
| 439 | */ |
|---|
| 440 | |
|---|
| 441 | cmucam1_start: |
|---|
| 442 | auto_led = true; |
|---|
| 443 | poll_mode = false; |
|---|
| 444 | frame_stream_mode = false; |
|---|
| 445 | line_mode = 0; |
|---|
| 446 | buf_mode = false; |
|---|
| 447 | packet_filter_flag = false; |
|---|
| 448 | s_pkt_mask = 0xFF; |
|---|
| 449 | |
|---|
| 450 | raw_mode_output = false; |
|---|
| 451 | raw_mode_no_confirmations = false; |
|---|
| 452 | raw_mode_input = false; |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | |
|---|
| 456 | cc3_camera_set_power_state (true); |
|---|
| 457 | cc3_camera_set_resolution (CC3_CAMERA_RESOLUTION_LOW); |
|---|
| 458 | |
|---|
| 459 | cc3_uart0_write(VERSION_BANNER "\r"); |
|---|
| 460 | |
|---|
| 461 | //cc3_pixbuf_frame_set_subsample (CC3_SUBSAMPLE_NEAREST, 2, 1); |
|---|
| 462 | |
|---|
| 463 | while (true) { |
|---|
| 464 | cc3_channel_t old_coi; |
|---|
| 465 | |
|---|
| 466 | print_prompt (); |
|---|
| 467 | error = false; |
|---|
| 468 | |
|---|
| 469 | if (raw_mode_input) { |
|---|
| 470 | n = cmucam1_get_command_raw (&command, arg_list); |
|---|
| 471 | } |
|---|
| 472 | else { |
|---|
| 473 | n = cmucam1_get_command (&command, arg_list); |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | //cc3_uart0_write("got command\r\n"); |
|---|
| 477 | |
|---|
| 478 | if (n != -1) { |
|---|
| 479 | switch (command) { |
|---|
| 480 | |
|---|
| 481 | case RESET: |
|---|
| 482 | if (n != 0) { |
|---|
| 483 | error = true; |
|---|
| 484 | break; |
|---|
| 485 | } |
|---|
| 486 | |
|---|
| 487 | print_ACK (); |
|---|
| 488 | print_cr (); |
|---|
| 489 | goto cmucam1_start; |
|---|
| 490 | break; |
|---|
| 491 | |
|---|
| 492 | case GET_VERSION: |
|---|
| 493 | if (n != 0) { |
|---|
| 494 | error = true; |
|---|
| 495 | break; |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | print_ACK (); |
|---|
| 499 | // no different in raw mode |
|---|
| 500 | cc3_uart0_write(VERSION_BANNER); |
|---|
| 501 | break; |
|---|
| 502 | |
|---|
| 503 | case LED_0: |
|---|
| 504 | if (n != 1 || arg_list[0] > 2) { |
|---|
| 505 | error = true; |
|---|
| 506 | break; |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | print_ACK (); |
|---|
| 510 | auto_led = false; |
|---|
| 511 | if (arg_list[0] == 0) |
|---|
| 512 | cc3_led_set_state (0, false); |
|---|
| 513 | if (arg_list[0] == 1) |
|---|
| 514 | cc3_led_set_state (0, true); |
|---|
| 515 | if (arg_list[0] == 2) |
|---|
| 516 | auto_led = true; |
|---|
| 517 | break; |
|---|
| 518 | |
|---|
| 519 | case DUMP_FRAME: |
|---|
| 520 | |
|---|
| 521 | |
|---|
| 522 | print_ACK (); |
|---|
| 523 | print_cr (); |
|---|
| 524 | |
|---|
| 525 | cc3_uart0_putchar (1); |
|---|
| 526 | // Start next frame capture (vblk stops at end of frame) |
|---|
| 527 | |
|---|
| 528 | for(x=0; x<704; x+=4 ) |
|---|
| 529 | { |
|---|
| 530 | cc3_uart0_putchar (2); |
|---|
| 531 | frame_done=0; |
|---|
| 532 | enable_vblk_interrupt(); |
|---|
| 533 | do { |
|---|
| 534 | // ask for a row of size n, return which row was captured |
|---|
| 535 | row=capture_next_row(ROW_BUF_LEN); // 1280 is max |
|---|
| 536 | /* |
|---|
| 537 | // RGB |
|---|
| 538 | red=row_buf[x] & 0xf8; |
|---|
| 539 | blue=row_buf[x+1] & 0x1f<<3; |
|---|
| 540 | green=(row_buf[x+1] & 0xe0>>5) | (row_buf[x]<<5); |
|---|
| 541 | if(red<4) red=4; |
|---|
| 542 | if(green<4) green=4; |
|---|
| 543 | if(blue<4) blue=4; |
|---|
| 544 | cc3_uart0_putchar (red); |
|---|
| 545 | cc3_uart0_putchar (green); |
|---|
| 546 | cc3_uart0_putchar (blue); |
|---|
| 547 | |
|---|
| 548 | red=row_buf[x+2] & 0xf8; |
|---|
| 549 | blue=row_buf[x+3] & 0x1f<<3; |
|---|
| 550 | green=(row_buf[x+3] & 0xe0>>5) | (row_buf[x+2]<<5); |
|---|
| 551 | if(red<4) red=4; |
|---|
| 552 | if(green<4) green=4; |
|---|
| 553 | if(blue<4) blue=4; |
|---|
| 554 | cc3_uart0_putchar (red); |
|---|
| 555 | cc3_uart0_putchar (green); |
|---|
| 556 | cc3_uart0_putchar (blue); |
|---|
| 557 | */ |
|---|
| 558 | |
|---|
| 559 | // YUV |
|---|
| 560 | y1=row_buf[x]; |
|---|
| 561 | v=row_buf[x+1]; |
|---|
| 562 | y2=row_buf[x+2]; |
|---|
| 563 | u=row_buf[x+3]; |
|---|
| 564 | |
|---|
| 565 | if(y1<4) y1=4; |
|---|
| 566 | if(y2<4) y2=4; |
|---|
| 567 | if(u<4) u=4; |
|---|
| 568 | if(v<4) v=4; |
|---|
| 569 | cc3_uart0_putchar (y1); |
|---|
| 570 | cc3_uart0_putchar (u); |
|---|
| 571 | cc3_uart0_putchar (v); |
|---|
| 572 | // Strange interlacing to get second pixel, fix later |
|---|
| 573 | cc3_uart0_putchar (y2); |
|---|
| 574 | cc3_uart0_putchar (u); |
|---|
| 575 | cc3_uart0_putchar (v); |
|---|
| 576 | |
|---|
| 577 | } while(!frame_done); |
|---|
| 578 | |
|---|
| 579 | } |
|---|
| 580 | cc3_uart0_putchar (3); |
|---|
| 581 | /*old_coi = cc3_g_pixbuf_frame.coi; |
|---|
| 582 | if (n == 1) { |
|---|
| 583 | if (arg_list[0] > 4) { |
|---|
| 584 | error = true; |
|---|
| 585 | break; |
|---|
| 586 | } |
|---|
| 587 | cc3_pixbuf_frame_set_coi (arg_list[0]); |
|---|
| 588 | } |
|---|
| 589 | else if (n > 1) { |
|---|
| 590 | error = true; |
|---|
| 591 | break; |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | print_ACK (); |
|---|
| 595 | do { |
|---|
| 596 | cmucam1_send_image_direct (auto_led); |
|---|
| 597 | // Check to see if data is on the UART to break from frame_stream_mode |
|---|
| 598 | if (!cc3_uart_has_data (0)) { |
|---|
| 599 | if (cc3_uart0_getchar () == '\r') |
|---|
| 600 | break; |
|---|
| 601 | } |
|---|
| 602 | } while (frame_stream_mode); |
|---|
| 603 | |
|---|
| 604 | cc3_pixbuf_frame_set_coi (old_coi); |
|---|
| 605 | */ |
|---|
| 606 | |
|---|
| 607 | break; |
|---|
| 608 | |
|---|
| 609 | case CAMERA_REG: |
|---|
| 610 | if (n % 2 != 0 || n < 2) { |
|---|
| 611 | error = true; |
|---|
| 612 | break; |
|---|
| 613 | } |
|---|
| 614 | |
|---|
| 615 | print_ACK (); |
|---|
| 616 | for (int i = 0; i < n; i += 2) |
|---|
| 617 | cc3_camera_set_raw_register (arg_list[i], arg_list[i + 1]); |
|---|
| 618 | break; |
|---|
| 619 | |
|---|
| 620 | case CAMERA_POWER: |
|---|
| 621 | if (n != 1) { |
|---|
| 622 | error = true; |
|---|
| 623 | break; |
|---|
| 624 | } |
|---|
| 625 | |
|---|
| 626 | print_ACK (); |
|---|
| 627 | { |
|---|
| 628 | // save |
|---|
| 629 | uint16_t x_0 = cc3_g_pixbuf_frame.x0; |
|---|
| 630 | uint16_t y_0 = cc3_g_pixbuf_frame.y0; |
|---|
| 631 | uint16_t x_1 = cc3_g_pixbuf_frame.x1; |
|---|
| 632 | uint16_t y_1 = cc3_g_pixbuf_frame.y1; |
|---|
| 633 | uint8_t x_step = cc3_g_pixbuf_frame.x_step; |
|---|
| 634 | uint8_t y_step = cc3_g_pixbuf_frame.y_step; |
|---|
| 635 | cc3_subsample_mode_t ss_mode = cc3_g_pixbuf_frame.subsample_mode; |
|---|
| 636 | |
|---|
| 637 | cc3_camera_set_power_state (arg_list[0]); |
|---|
| 638 | |
|---|
| 639 | // restore |
|---|
| 640 | cc3_pixbuf_frame_set_roi (x_0, y_0, x_1, y_1); |
|---|
| 641 | cc3_pixbuf_frame_set_subsample (ss_mode, x_step, y_step); |
|---|
| 642 | } |
|---|
| 643 | break; |
|---|
| 644 | |
|---|
| 645 | |
|---|
| 646 | case GET_BUTTON: |
|---|
| 647 | if (n != 0) { |
|---|
| 648 | error = true; |
|---|
| 649 | break; |
|---|
| 650 | } |
|---|
| 651 | |
|---|
| 652 | print_ACK (); |
|---|
| 653 | |
|---|
| 654 | { |
|---|
| 655 | int button = cc3_button_get_and_reset_trigger ()? 1 : 0; |
|---|
| 656 | if (raw_mode_output) { |
|---|
| 657 | cc3_uart0_putchar (255); |
|---|
| 658 | raw_print (button); |
|---|
| 659 | } |
|---|
| 660 | else { |
|---|
| 661 | cc3_uart0_write(button ? "1" : "0"); |
|---|
| 662 | } |
|---|
| 663 | } |
|---|
| 664 | break; |
|---|
| 665 | |
|---|
| 666 | |
|---|
| 667 | default: |
|---|
| 668 | print_ACK (); |
|---|
| 669 | break; |
|---|
| 670 | } |
|---|
| 671 | } |
|---|
| 672 | else |
|---|
| 673 | error = true; |
|---|
| 674 | |
|---|
| 675 | if (error) |
|---|
| 676 | print_NCK (); |
|---|
| 677 | } |
|---|
| 678 | |
|---|
| 679 | |
|---|
| 680 | return 0; |
|---|
| 681 | } |
|---|
| 682 | |
|---|
| 683 | int i2c_test_write_polling(uint8_t addr, uint8_t *data, int len) |
|---|
| 684 | { |
|---|
| 685 | int i = 0; // first byte is sent by state 0x18, remaining is state 0x28 |
|---|
| 686 | uint8_t state,last_state,done,blink; |
|---|
| 687 | |
|---|
| 688 | //cc3_uart0_write("Testing i2c\r\n"); |
|---|
| 689 | |
|---|
| 690 | REG (GPIO_IODIR) = _CC3_DEFAULT_PORT_DIR; |
|---|
| 691 | |
|---|
| 692 | REG(I2C_I2CONCLR)=I2C_I2EN | I2C_STA | I2C_SI | I2C_AA; // 0x6c; // clear all flags |
|---|
| 693 | REG(I2C_I2CONSET)=I2C_I2EN; // enable I2C |
|---|
| 694 | // REG (I2C_I2SCLH) = 100; |
|---|
| 695 | // REG (I2C_I2SCLL) = 60; |
|---|
| 696 | REG (I2C_I2SCLH) = 200; |
|---|
| 697 | REG (I2C_I2SCLL) = 120; |
|---|
| 698 | |
|---|
| 699 | //REG (GPIO_IOSET) = _CC3_CAM_RESET; |
|---|
| 700 | // cc3_timer_wait_ms(1000); |
|---|
| 701 | |
|---|
| 702 | last_state=REG(I2C_I2STAT); |
|---|
| 703 | //cc3_uart0_write("starting state:"); |
|---|
| 704 | //print_num(last_state); |
|---|
| 705 | //cc3_uart0_write("\r\n"); |
|---|
| 706 | // REG(I2C_I2ADR)= addr | I2C_WRITE_BIT; // set slave address and write bit |
|---|
| 707 | |
|---|
| 708 | REG(I2C_I2CONSET)=I2C_I2EN | I2C_STA; // Send Start Bit |
|---|
| 709 | done=0; |
|---|
| 710 | blink=0; |
|---|
| 711 | // I2C state machine |
|---|
| 712 | while(!done) { |
|---|
| 713 | // Poll for status change, this can be inside an interrupt later |
|---|
| 714 | do { |
|---|
| 715 | state=REG(I2C_I2STAT); |
|---|
| 716 | cc3_led_set_state (0, blink); blink=!blink; |
|---|
| 717 | } while(!(REG(I2C_I2CONSET) & I2C_SI)); |
|---|
| 718 | |
|---|
| 719 | switch(state) |
|---|
| 720 | { |
|---|
| 721 | case 0x00: |
|---|
| 722 | //cc3_uart0_write("zero state\r\n"); |
|---|
| 723 | break; |
|---|
| 724 | case 0x08: |
|---|
| 725 | REG(I2C_I2DAT)=addr << 1; // set slave address and write bit |
|---|
| 726 | REG(I2C_I2CONCLR)=I2C_STO | I2C_SI; |
|---|
| 727 | //cc3_uart0_write("0x08 state\r\n"); |
|---|
| 728 | break; |
|---|
| 729 | case 0x18: |
|---|
| 730 | // Ack received from slave for slave address |
|---|
| 731 | // set the data |
|---|
| 732 | //cc3_uart0_write_hex(data[i]); |
|---|
| 733 | REG(I2C_I2DAT)=data[i++]; |
|---|
| 734 | REG(I2C_I2CONCLR)=I2C_STA | I2C_STO | I2C_SI; |
|---|
| 735 | //cc3_uart0_write("0x18 state\r\n"); |
|---|
| 736 | break; |
|---|
| 737 | case 0x28: |
|---|
| 738 | // Ack received from slave for byte transmitted from master. |
|---|
| 739 | if (i < len) { |
|---|
| 740 | // continue sending |
|---|
| 741 | //cc3_uart0_write_hex(data[i]); |
|---|
| 742 | REG(I2C_I2DAT)=data[i++]; |
|---|
| 743 | REG(I2C_I2CONCLR)=I2C_STA | I2C_STO | I2C_SI; |
|---|
| 744 | //cc3_uart0_write("0x28 state\r\n"); |
|---|
| 745 | } else { |
|---|
| 746 | // Stop condition is transmitted in this state signaling the end of transmission |
|---|
| 747 | REG(I2C_I2CONSET)=I2C_STO; // Transmit stop condition |
|---|
| 748 | REG(I2C_I2CONCLR)=I2C_SI; // clear SI |
|---|
| 749 | done=1; |
|---|
| 750 | //cc3_uart0_write("0x28 done state\r\n"); |
|---|
| 751 | } |
|---|
| 752 | break; |
|---|
| 753 | case 0xF8: |
|---|
| 754 | //cc3_uart0_write("No relevant state data state\r\n"); |
|---|
| 755 | break; |
|---|
| 756 | default: |
|---|
| 757 | //cc3_uart0_write("unknown state:"); |
|---|
| 758 | //cc3_uart0_write_hex(state); |
|---|
| 759 | cc3_uart0_write("\r\n"); |
|---|
| 760 | break; |
|---|
| 761 | } |
|---|
| 762 | last_state=state; |
|---|
| 763 | |
|---|
| 764 | } |
|---|
| 765 | |
|---|
| 766 | cc3_led_set_state (0, false); |
|---|
| 767 | // cc3_uart0_write("done...\r\n"); |
|---|
| 768 | |
|---|
| 769 | |
|---|
| 770 | |
|---|
| 771 | |
|---|
| 772 | return 1; // return ack bit eventually |
|---|
| 773 | |
|---|
| 774 | } |
|---|
| 775 | |
|---|
| 776 | void cmucam1_send_image_direct (bool auto_led) |
|---|
| 777 | { |
|---|
| 778 | uint32_t x, y; |
|---|
| 779 | uint32_t size_x, size_y; |
|---|
| 780 | uint8_t *row = cc3_malloc_rows (1); |
|---|
| 781 | uint8_t num_channels = cc3_g_pixbuf_frame.coi == CC3_CHANNEL_ALL ? 3 : 1; |
|---|
| 782 | |
|---|
| 783 | |
|---|
| 784 | |
|---|
| 785 | size_x = cc3_g_pixbuf_frame.width; |
|---|
| 786 | size_y = cc3_g_pixbuf_frame.height; |
|---|
| 787 | |
|---|
| 788 | cc3_uart0_putchar (1); |
|---|
| 789 | cc3_uart0_putchar (size_x); |
|---|
| 790 | if (size_y > 255) |
|---|
| 791 | size_y = 255; |
|---|
| 792 | cc3_uart0_putchar (size_y); |
|---|
| 793 | for (y = 0; y < size_y; y++) { |
|---|
| 794 | cc3_uart0_putchar (2); |
|---|
| 795 | if (auto_led) { |
|---|
| 796 | if (y % 4 == 0) |
|---|
| 797 | cc3_led_set_state (0, true); |
|---|
| 798 | else |
|---|
| 799 | cc3_led_set_state (0, false); |
|---|
| 800 | } |
|---|
| 801 | cc3_pixbuf_read_rows (row, 1); |
|---|
| 802 | |
|---|
| 803 | for (x = 0; x < size_x * num_channels; x++) { |
|---|
| 804 | uint8_t p = row[x]; |
|---|
| 805 | |
|---|
| 806 | // avoid confusion from FIFO corruptions |
|---|
| 807 | if (p < 16) { |
|---|
| 808 | p = 16; |
|---|
| 809 | } |
|---|
| 810 | else if (p > 240) { |
|---|
| 811 | p = 240; |
|---|
| 812 | } |
|---|
| 813 | cc3_uart0_putchar (p); |
|---|
| 814 | } |
|---|
| 815 | } |
|---|
| 816 | cc3_uart0_putchar (3); |
|---|
| 817 | |
|---|
| 818 | cc3_led_set_state (0, false); |
|---|
| 819 | free (row); |
|---|
| 820 | } |
|---|
| 821 | |
|---|
| 822 | |
|---|
| 823 | |
|---|
| 824 | |
|---|
| 825 | void print_ACK () |
|---|
| 826 | { |
|---|
| 827 | if (!raw_mode_no_confirmations) |
|---|
| 828 | cc3_uart0_write("ACK\r"); |
|---|
| 829 | } |
|---|
| 830 | |
|---|
| 831 | void print_NCK () |
|---|
| 832 | { |
|---|
| 833 | if (!raw_mode_no_confirmations) |
|---|
| 834 | cc3_uart0_write("NCK\r"); |
|---|
| 835 | } |
|---|
| 836 | |
|---|
| 837 | void print_prompt () |
|---|
| 838 | { |
|---|
| 839 | cc3_uart0_write(":"); |
|---|
| 840 | } |
|---|
| 841 | |
|---|
| 842 | void print_cr () |
|---|
| 843 | { |
|---|
| 844 | if (!raw_mode_output) { |
|---|
| 845 | cc3_uart0_write("\r"); |
|---|
| 846 | } |
|---|
| 847 | } |
|---|
| 848 | |
|---|
| 849 | int32_t cmucam1_get_command (cmucam1_command_t * cmd, uint32_t * arg_list) |
|---|
| 850 | { |
|---|
| 851 | int c; |
|---|
| 852 | char *token; |
|---|
| 853 | bool fail = false; |
|---|
| 854 | uint32_t length, argc; |
|---|
| 855 | uint32_t i; |
|---|
| 856 | |
|---|
| 857 | length = 0; |
|---|
| 858 | c = 0; |
|---|
| 859 | while (c != '\r') { |
|---|
| 860 | c = cc3_uart0_getchar (); |
|---|
| 861 | |
|---|
| 862 | if (length < (MAX_LINE - 1) && c != EOF) { |
|---|
| 863 | line_buf[length] = c; |
|---|
| 864 | length++; |
|---|
| 865 | } |
|---|
| 866 | else { |
|---|
| 867 | // too long or EOF |
|---|
| 868 | return -1; |
|---|
| 869 | } |
|---|
| 870 | } |
|---|
| 871 | // null terminate |
|---|
| 872 | line_buf[length] = '\0'; |
|---|
| 873 | |
|---|
| 874 | // check for empty command |
|---|
| 875 | if (line_buf[0] == '\r' || line_buf[0] == '\n') { |
|---|
| 876 | *cmd = RETURN; |
|---|
| 877 | return 0; |
|---|
| 878 | } |
|---|
| 879 | |
|---|
| 880 | // start looking for command |
|---|
| 881 | token = strtok (line_buf, " \r\n"); |
|---|
| 882 | |
|---|
| 883 | if (token == NULL) { |
|---|
| 884 | // no command ? |
|---|
| 885 | return -1; |
|---|
| 886 | } |
|---|
| 887 | |
|---|
| 888 | // get name of the command |
|---|
| 889 | for (i = 0; i < strlen (token); i++) { |
|---|
| 890 | token[i] = toupper (token[i]); |
|---|
| 891 | } |
|---|
| 892 | |
|---|
| 893 | // do lookup of command |
|---|
| 894 | fail = true; |
|---|
| 895 | for (i = 0; i < CMUCAM1_CMDS_COUNT; i++) { |
|---|
| 896 | if (strcmp (token, cmucam1_cmds[i]) == 0) { |
|---|
| 897 | fail = false; |
|---|
| 898 | *cmd = i; |
|---|
| 899 | break; |
|---|
| 900 | } |
|---|
| 901 | } |
|---|
| 902 | if (fail) { |
|---|
| 903 | return -1; |
|---|
| 904 | } |
|---|
| 905 | |
|---|
| 906 | // now get the arguments |
|---|
| 907 | argc = 0; |
|---|
| 908 | while (true) { |
|---|
| 909 | // extract string from string sequence |
|---|
| 910 | token = strtok (NULL, " \r\n"); |
|---|
| 911 | // check if there is nothing else to extract |
|---|
| 912 | if (token == NULL) { |
|---|
| 913 | // printf("Tokenizing complete\n"); |
|---|
| 914 | return argc; |
|---|
| 915 | } |
|---|
| 916 | |
|---|
| 917 | // make sure the argument is fully numeric |
|---|
| 918 | for (i = 0; i < strlen (token); i++) { |
|---|
| 919 | if (!isdigit (token[i])) |
|---|
| 920 | return -1; |
|---|
| 921 | } |
|---|
| 922 | |
|---|
| 923 | // we have a valid token, add it |
|---|
| 924 | arg_list[argc] = atoi (token); |
|---|
| 925 | argc++; |
|---|
| 926 | } |
|---|
| 927 | |
|---|
| 928 | return -1; |
|---|
| 929 | } |
|---|
| 930 | |
|---|
| 931 | int32_t cmucam1_get_command_raw (cmucam1_command_t * cmd, uint32_t * arg_list) |
|---|
| 932 | { |
|---|
| 933 | bool fail; |
|---|
| 934 | int c; |
|---|
| 935 | unsigned int i; |
|---|
| 936 | uint32_t argc; |
|---|
| 937 | |
|---|
| 938 | char cmd_str[3]; |
|---|
| 939 | cmd_str[2] = '\0'; |
|---|
| 940 | |
|---|
| 941 | // read characters |
|---|
| 942 | for (i = 0; i < 2; i++) { |
|---|
| 943 | c = cc3_uart0_getchar (); |
|---|
| 944 | if (c == EOF) { |
|---|
| 945 | return -1; |
|---|
| 946 | } |
|---|
| 947 | |
|---|
| 948 | cmd_str[i] = c; |
|---|
| 949 | } |
|---|
| 950 | |
|---|
| 951 | // do lookup of command |
|---|
| 952 | fail = true; |
|---|
| 953 | for (i = 0; i < CMUCAM1_CMDS_COUNT; i++) { |
|---|
| 954 | if (strcmp (cmd_str, cmucam1_cmds[i]) == 0) { |
|---|
| 955 | fail = false; |
|---|
| 956 | *cmd = i; |
|---|
| 957 | break; |
|---|
| 958 | } |
|---|
| 959 | } |
|---|
| 960 | if (fail) { |
|---|
| 961 | return -1; |
|---|
| 962 | } |
|---|
| 963 | |
|---|
| 964 | // read argc |
|---|
| 965 | c = cc3_uart0_getchar (); |
|---|
| 966 | if (c == EOF) { |
|---|
| 967 | return -1; |
|---|
| 968 | } |
|---|
| 969 | argc = c; |
|---|
| 970 | if (argc > MAX_ARGS) { |
|---|
| 971 | return -1; |
|---|
| 972 | } |
|---|
| 973 | |
|---|
| 974 | // read args |
|---|
| 975 | for (i = 0; i < argc; i++) { |
|---|
| 976 | c = cc3_uart0_getchar (); |
|---|
| 977 | if (c == EOF) { |
|---|
| 978 | return -1; |
|---|
| 979 | } |
|---|
| 980 | |
|---|
| 981 | arg_list[i] = toupper (c); |
|---|
| 982 | } |
|---|
| 983 | |
|---|
| 984 | // done |
|---|
| 985 | return argc; |
|---|
| 986 | } |
|---|
| 987 | |
|---|
| 988 | void print_num(uint32_t x) |
|---|
| 989 | { |
|---|
| 990 | uint8_t t,set; |
|---|
| 991 | uint32_t div; |
|---|
| 992 | |
|---|
| 993 | set=0; |
|---|
| 994 | for(div=100000; div>=10; div/=10 ) |
|---|
| 995 | { |
|---|
| 996 | if((x>=div) | (set==1)) { t=x/div; cc3_uart0_putchar('0'+t); set=1; } |
|---|
| 997 | x=x%div; |
|---|
| 998 | } |
|---|
| 999 | |
|---|
| 1000 | x=x%10; |
|---|
| 1001 | cc3_uart0_putchar('0'+x); |
|---|
| 1002 | |
|---|
| 1003 | } |
|---|
| 1004 | |
|---|
| 1005 | void raw_print (uint8_t val) |
|---|
| 1006 | { |
|---|
| 1007 | if (val == 255) { |
|---|
| 1008 | cc3_uart0_putchar (254); // avoid confusion |
|---|
| 1009 | } |
|---|
| 1010 | else { |
|---|
| 1011 | cc3_uart0_putchar (val); |
|---|
| 1012 | } |
|---|
| 1013 | } |
|---|