SmartWheels self-driving race car. Designed for NXP Cup. Uses FRDM-KL25Z, area-scan camera, and simple image processing to detect and navigate any NXP spec track.

Dependencies:   TSI USBDevice mbed-dev

Fork of SmartWheels by haofan Zheng

Committer:
Bobymicjohn
Date:
Thu Apr 06 17:55:40 2017 +0000
Revision:
47:a682be9908b9
Parent:
46:a5eb9bd3bb55
Child:
49:be46291ee6ea
Added differential calculations in main.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hazheng 28:271fc8445e89 1 #pragma once
hazheng 28:271fc8445e89 2 #ifndef ARDU_CAM_H
hazheng 28:271fc8445e89 3 #define ARDU_CAM_H
hazheng 28:271fc8445e89 4
hazheng 29:f87d8790f57d 5 #include <mbed.h>
hazheng 44:15de535c4005 6 #include <rtos.h>
hazheng 28:271fc8445e89 7 #include "PinAssignment.h"
hazheng 28:271fc8445e89 8
hazheng 41:7b21c5e3599e 9 #define RESOLUTION_WIDTH 160
hazheng 41:7b21c5e3599e 10 #define RESOLUTION_HEIGHT 120
hazheng 41:7b21c5e3599e 11 //#define MANUAL_REDUCE_RESULOTION_BY2
Bobymicjohn 47:a682be9908b9 12 #define CAM_ROI_UPPER_LIMIT 5
hazheng 38:0fb273b28cee 13
hazheng 36:7e747e19f660 14
hazheng 36:7e747e19f660 15 //=====Must pick one and only one here!=====
hazheng 37:7074a6118d03 16 //#define ARDUCAM_SHIELD_OV2640
hazheng 36:7e747e19f660 17 //#define ARDUCAM_SHIELD_OV7725
hazheng 38:0fb273b28cee 18 //#define ARDUCAM_SHIELD_OV7670
hazheng 38:0fb273b28cee 19 #define ARDUCAM_MINI_OV2640
hazheng 36:7e747e19f660 20 //==========================================
hazheng 36:7e747e19f660 21
hazheng 37:7074a6118d03 22
hazheng 37:7074a6118d03 23 #if defined(ARDUCAM_SHIELD_OV2640) || defined(ARDUCAM_SHIELD_OV7725) || defined(ARDUCAM_SHIELD_OV7670)
hazheng 36:7e747e19f660 24 #define ARDUCAM_SHIELD
hazheng 36:7e747e19f660 25 #elif defined(ARDUCAM_MINI_OV2640)
hazheng 36:7e747e19f660 26 #define ARDUCAM_MINI
hazheng 36:7e747e19f660 27 #else
hazheng 36:7e747e19f660 28 #error Must pick one and only one ArduCam type!
hazheng 36:7e747e19f660 29 #endif
hazheng 36:7e747e19f660 30
hazheng 36:7e747e19f660 31 #if defined(ARDUCAM_SHIELD_OV2640) || defined(ARDUCAM_MINI_OV2640)
hazheng 36:7e747e19f660 32 #define ARDUCAM_OV2640
hazheng 36:7e747e19f660 33 #elif defined(ARDUCAM_SHIELD_OV7725)
hazheng 36:7e747e19f660 34 #define ARDUCAM_OV7725
hazheng 37:7074a6118d03 35 #elif defined(ARDUCAM_SHIELD_OV7670)
hazheng 37:7074a6118d03 36 #define ARDUCAM_OV7670
hazheng 36:7e747e19f660 37 #else
hazheng 36:7e747e19f660 38 #error Must pick one and only one ArduCam type!
hazheng 36:7e747e19f660 39 #endif
hazheng 36:7e747e19f660 40
hazheng 36:7e747e19f660 41 #if defined(ARDUCAM_OV2640)
hazheng 36:7e747e19f660 42 #include "OV2640RegProg.h"
hazheng 46:a5eb9bd3bb55 43 //using namespace OV2640Prog;
hazheng 36:7e747e19f660 44 #elif defined(ARDUCAM_OV7725)
hazheng 36:7e747e19f660 45 #include "OV7725RegProg.h"
hazheng 46:a5eb9bd3bb55 46 //using namespace OV7725Prog;
hazheng 37:7074a6118d03 47 #elif defined(ARDUCAM_OV7670)
hazheng 37:7074a6118d03 48 #include "OV7670RegProg.h"
hazheng 46:a5eb9bd3bb55 49 //using namespace OV7670Prog;
hazheng 36:7e747e19f660 50 #endif
hazheng 36:7e747e19f660 51
hazheng 36:7e747e19f660 52 #if defined(ARDUCAM_SHIELD)
hazheng 36:7e747e19f660 53 #define ARDUCHIP_VER_NUM 0x61
hazheng 36:7e747e19f660 54 #elif defined(ARDUCAM_MINI)
hazheng 36:7e747e19f660 55 #define ARDUCHIP_VER_NUM 0x55
hazheng 36:7e747e19f660 56 #endif
hazheng 36:7e747e19f660 57
hazheng 29:f87d8790f57d 58 #define ARDUCHIP_TEST1 0x00 //TEST register
hazheng 29:f87d8790f57d 59 #define ARDUCHIP_TEST_MSG 0x72
hazheng 29:f87d8790f57d 60
hazheng 29:f87d8790f57d 61 #define ARDUCHIP_CAP_CTRL 0x01 //Capture Control Register
hazheng 29:f87d8790f57d 62
hazheng 40:be98219930e4 63 #if defined(ARDUCAM_SHIELD)
hazheng 40:be98219930e4 64 #define ARDUCHIP_MODE 0x02 //Mode register
hazheng 40:be98219930e4 65 //#define MCU2LCD_MODE 0x00
hazheng 40:be98219930e4 66 //#define CAM2LCD_MODE 0x01
hazheng 40:be98219930e4 67 #define MCU2LCD_MODE 0x01
hazheng 40:be98219930e4 68 #define CAM2LCD_MODE 0x02
hazheng 40:be98219930e4 69 //#define LCD2MCU_MODE 0x04
hazheng 40:be98219930e4 70 #endif
hazheng 29:f87d8790f57d 71
hazheng 29:f87d8790f57d 72 #define ARDUCHIP_FIFO 0x04 //FIFO and I2C control
hazheng 29:f87d8790f57d 73 #define FIFO_CLEAR_MASK 0x01
hazheng 29:f87d8790f57d 74 #define FIFO_START_MASK 0x02
hazheng 29:f87d8790f57d 75 #define FIFO_RDPTR_RST_MASK 0x10
hazheng 29:f87d8790f57d 76 #define FIFO_WRPTR_RST_MASK 0x20
hazheng 29:f87d8790f57d 77
hazheng 44:15de535c4005 78 #define ARDUCHIP_TRIG 0x41 //Trigger source
hazheng 44:15de535c4005 79 #define VSYNC_MASK 0x01
hazheng 44:15de535c4005 80 #define SHUTTER_MASK 0x02
hazheng 44:15de535c4005 81 #define CAP_DONE_MASK 0x08
hazheng 44:15de535c4005 82
hazheng 32:5badeff825dc 83 #define FIFO_SIZE1 0x42 //Camera write FIFO size[7:0] for burst to read
hazheng 32:5badeff825dc 84 #define FIFO_SIZE2 0x43 //Camera write FIFO size[15:8]
hazheng 44:15de535c4005 85 #define FIFO_SIZE3 0x44 //Camera write FIFO size[18:16]
hazheng 32:5badeff825dc 86
hazheng 32:5badeff825dc 87 #define BURST_FIFO_READ 0x3C //Burst FIFO read operation
hazheng 32:5badeff825dc 88 #define SINGLE_FIFO_READ 0x3D //Single FIFO read operation
hazheng 29:f87d8790f57d 89
hazheng 46:a5eb9bd3bb55 90 #ifdef __cplusplus
hazheng 46:a5eb9bd3bb55 91 extern "C" {
hazheng 46:a5eb9bd3bb55 92 #endif
hazheng 46:a5eb9bd3bb55 93
hazheng 28:271fc8445e89 94 bool ardu_cam_init();
hazheng 28:271fc8445e89 95
hazheng 29:f87d8790f57d 96 void ardu_cam_start_capture();
hazheng 29:f87d8790f57d 97
hazheng 32:5badeff825dc 98 uint32_t ardu_cam_get_fifo_length();
hazheng 32:5badeff825dc 99
hazheng 32:5badeff825dc 100 void ardu_cam_print_debug();
hazheng 32:5badeff825dc 101
hazheng 44:15de535c4005 102 volatile const uint8_t* ardu_cam_get_center_array();
hazheng 44:15de535c4005 103
hazheng 44:15de535c4005 104 uint8_t ardu_cam_is_capture_finished();
hazheng 43:0d1886f4848a 105
hazheng 46:a5eb9bd3bb55 106 void ardu_cam_display_img_utft();
hazheng 46:a5eb9bd3bb55 107
hazheng 46:a5eb9bd3bb55 108 #ifdef __cplusplus
hazheng 46:a5eb9bd3bb55 109 }
hazheng 46:a5eb9bd3bb55 110 #endif
hazheng 46:a5eb9bd3bb55 111
hazheng 34:f79db3bc2f86 112 //uint8_t ardu_cam_read_reg(uint8_t addr);
hazheng 34:f79db3bc2f86 113
hazheng 34:f79db3bc2f86 114 //void ardu_cam_write_reg(uint8_t addr, uint8_t data);
hazheng 34:f79db3bc2f86 115
hazheng 34:f79db3bc2f86 116 //int ardu_cam_bus_write(int address, int value);
hazheng 34:f79db3bc2f86 117
hazheng 34:f79db3bc2f86 118 //uint8_t ardu_cam_bus_read(int address);
hazheng 34:f79db3bc2f86 119
hazheng 28:271fc8445e89 120 #endif //ARDU_CAM_H