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
Hardwares/ArduUTFT.h@100:ffbeefc9e218, 2017-04-20 (annotated)
- Committer:
- hazheng
- Date:
- Thu Apr 20 21:04:10 2017 +0000
- Revision:
- 100:ffbeefc9e218
- Parent:
- 97:0ed9ede9a995
Better version of Intersection detection.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hazheng | 92:e9bd429f16b5 | 1 | /** |
hazheng | 92:e9bd429f16b5 | 2 | * @file ArduUTFT.h |
hazheng | 92:e9bd429f16b5 | 3 | * @brief The header file for all functions that controls the ArduCam UTFT screen. |
hazheng | 92:e9bd429f16b5 | 4 | * @author Jordan Brack <jabrack@mix.wvu.edu>, Haofan Zheng <hazheng@mix.wvu.edu> |
hazheng | 92:e9bd429f16b5 | 5 | * |
hazheng | 92:e9bd429f16b5 | 6 | */ |
hazheng | 40:be98219930e4 | 7 | #pragma once |
hazheng | 40:be98219930e4 | 8 | #ifndef ARDU_UTFT_H |
hazheng | 40:be98219930e4 | 9 | #define ARDU_UTFT_H |
hazheng | 40:be98219930e4 | 10 | |
hazheng | 40:be98219930e4 | 11 | #include <mbed.h> |
hazheng | 40:be98219930e4 | 12 | #include "PinAssignment.h" |
hazheng | 40:be98219930e4 | 13 | |
hazheng | 92:e9bd429f16b5 | 14 | #define ARDUCHIP_MODE 0x02 /*!< @brief The address for the ArduCam bus mode setting register. */ |
hazheng | 92:e9bd429f16b5 | 15 | #define MCU2LCD_MODE 0x00 /*!< @brief The byte used to set the ArduCam bus to MCU to LCD mode. */ |
hazheng | 92:e9bd429f16b5 | 16 | #define CAM2LCD_MODE 0x01 /*!< @brief The byte used to set the ArduCam bus to CAM to LCD mode. */ |
hazheng | 40:be98219930e4 | 17 | |
hazheng | 92:e9bd429f16b5 | 18 | #define ARDUCHIP_TEST1_UTFT 0x00 /*!< @brief The address for the ArduCam test register. */ |
hazheng | 92:e9bd429f16b5 | 19 | #define ARDUCHIP_TEST_MSG_UTFT 0x72 /*!< @brief The message used to write/read/verify with the test register. */ |
hazheng | 40:be98219930e4 | 20 | |
hazheng | 92:e9bd429f16b5 | 21 | #define ARDUCHIP_VER_UTFT 0x40 /*!< @brief The address for the ArduCam version register. */ |
hazheng | 92:e9bd429f16b5 | 22 | #define ARDUCHIP_VER_NUM_UTFT 0x61 /*!< @brief The version num for the ArduCam Shield V2 */ |
hazheng | 42:c4e1606087ff | 23 | |
hazheng | 42:c4e1606087ff | 24 | |
hazheng | 92:e9bd429f16b5 | 25 | #define UTFT_DISP_X_SIZE 239 /*!< @brief The vertical size of the UTFT screen resolution. */ |
hazheng | 92:e9bd429f16b5 | 26 | #define UTFT_DISP_Y_SIZE 319 /*!< @brief The horizontal size of the UTFT screen resolution. */ |
hazheng | 42:c4e1606087ff | 27 | |
hazheng | 92:e9bd429f16b5 | 28 | #define UTFT_LEFT 0 /*!< @brief left alignment. */ |
hazheng | 92:e9bd429f16b5 | 29 | #define UTFT_RIGHT 9999 /*!< @brief Right alignment. */ |
hazheng | 92:e9bd429f16b5 | 30 | #define UTFT_CENTER 9998 /*!< @brief right alignment. */ |
hazheng | 44:15de535c4005 | 31 | |
hazheng | 92:e9bd429f16b5 | 32 | #define CAM_IMG_CANVAS_ROW_OFFSET 20 /*!< @brief The horizontal postion of the canvas that used to display the camera image. */ |
Bobymicjohn | 97:0ed9ede9a995 | 33 | #define CAM_IMG_CANVAS_COL_OFFSET 200 /*!< @brief The vertical postion of the canvas that used to display the camera image. */ |
hazheng | 46:a5eb9bd3bb55 | 34 | |
hazheng | 46:a5eb9bd3bb55 | 35 | |
hazheng | 46:a5eb9bd3bb55 | 36 | #ifdef __cplusplus |
hazheng | 46:a5eb9bd3bb55 | 37 | extern "C" { |
hazheng | 46:a5eb9bd3bb55 | 38 | #endif |
hazheng | 46:a5eb9bd3bb55 | 39 | |
hazheng | 92:e9bd429f16b5 | 40 | /** |
hazheng | 92:e9bd429f16b5 | 41 | * @brief Init the UTFT screen. There is only one screen in the system, thus, this function is required to be called only once during the system initialization. |
hazheng | 92:e9bd429f16b5 | 42 | */ |
hazheng | 40:be98219930e4 | 43 | void ardu_utft_init(); //We only use LANDSCAPE orientation! |
hazheng | 40:be98219930e4 | 44 | |
hazheng | 92:e9bd429f16b5 | 45 | /** |
hazheng | 92:e9bd429f16b5 | 46 | * @brief Set the ArduCam bus mode. |
hazheng | 92:e9bd429f16b5 | 47 | * @param mode The new bus mode for the ArduCam Shield V2. |
hazheng | 92:e9bd429f16b5 | 48 | */ |
hazheng | 40:be98219930e4 | 49 | void ardu_cam_set_mode(uint8_t mode); |
hazheng | 40:be98219930e4 | 50 | |
hazheng | 92:e9bd429f16b5 | 51 | /** |
hazheng | 92:e9bd429f16b5 | 52 | * @brief Write a pixel to the screen. |
hazheng | 92:e9bd429f16b5 | 53 | * @param VH The MSB of a RGB565 value. |
hazheng | 92:e9bd429f16b5 | 54 | * @param VL The LSB of a RGB565 value. |
hazheng | 92:e9bd429f16b5 | 55 | */ |
hazheng | 41:7b21c5e3599e | 56 | void ardu_utft_write_DATA(uint8_t VH, uint8_t VL); |
hazheng | 41:7b21c5e3599e | 57 | |
hazheng | 92:e9bd429f16b5 | 58 | /** |
hazheng | 92:e9bd429f16b5 | 59 | * @brief Clear the screen. |
hazheng | 92:e9bd429f16b5 | 60 | */ |
hazheng | 40:be98219930e4 | 61 | void ardu_utft_clr_scr(); |
hazheng | 40:be98219930e4 | 62 | |
hazheng | 92:e9bd429f16b5 | 63 | /** |
hazheng | 92:e9bd429f16b5 | 64 | * @brief Set the drawing range. |
hazheng | 92:e9bd429f16b5 | 65 | * @param x1 The start position in the x-axis. |
hazheng | 92:e9bd429f16b5 | 66 | * @param y1 The start position in the y-axis. |
hazheng | 92:e9bd429f16b5 | 67 | * @param x2 The end position in the x-axis. |
hazheng | 92:e9bd429f16b5 | 68 | * @param y2 The end position in the y-axis. |
hazheng | 92:e9bd429f16b5 | 69 | */ |
hazheng | 40:be98219930e4 | 70 | void ardu_utft_set_xy(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2); |
hazheng | 40:be98219930e4 | 71 | |
hazheng | 92:e9bd429f16b5 | 72 | /** |
hazheng | 92:e9bd429f16b5 | 73 | * @brief Set the drawing range from the (0,0) till the end of the screen. |
hazheng | 92:e9bd429f16b5 | 74 | */ |
hazheng | 40:be98219930e4 | 75 | void ardu_utft_reset_xy(); |
hazheng | 40:be98219930e4 | 76 | |
hazheng | 92:e9bd429f16b5 | 77 | /** |
hazheng | 92:e9bd429f16b5 | 78 | * @brief Set the drawing color. |
hazheng | 92:e9bd429f16b5 | 79 | * @param r The value for red channel. |
hazheng | 92:e9bd429f16b5 | 80 | * @param g The value for green channel. |
hazheng | 92:e9bd429f16b5 | 81 | * @param b The value for blue channel. |
hazheng | 92:e9bd429f16b5 | 82 | */ |
hazheng | 40:be98219930e4 | 83 | void ardu_utft_set_color(uint8_t r, uint8_t g, uint8_t b); |
hazheng | 40:be98219930e4 | 84 | |
hazheng | 92:e9bd429f16b5 | 85 | /** |
hazheng | 92:e9bd429f16b5 | 86 | * @brief Draw a rectangle on the srceen. |
hazheng | 92:e9bd429f16b5 | 87 | * @param x1 The first point of the rectangle in the x-axis. |
hazheng | 92:e9bd429f16b5 | 88 | * @param y1 The first point of the rectangle in the y-axis. |
hazheng | 92:e9bd429f16b5 | 89 | * @param x2 The last point of the rectangle in the x-axis. |
hazheng | 92:e9bd429f16b5 | 90 | * @param y2 The last point of the rectangle in the y-axis. |
hazheng | 92:e9bd429f16b5 | 91 | */ |
hazheng | 40:be98219930e4 | 92 | void ardu_utft_draw_rect(int x1, int y1, int x2, int y2); |
hazheng | 40:be98219930e4 | 93 | |
hazheng | 92:e9bd429f16b5 | 94 | /** |
hazheng | 92:e9bd429f16b5 | 95 | * @brief Draw a horizontal line on the srceen. |
hazheng | 92:e9bd429f16b5 | 96 | * @param x The start position of the line in the x-axis. |
hazheng | 92:e9bd429f16b5 | 97 | * @param y The start position of the line in the y-axis. |
hazheng | 92:e9bd429f16b5 | 98 | * @param l The length of the line. |
hazheng | 92:e9bd429f16b5 | 99 | */ |
hazheng | 40:be98219930e4 | 100 | void ardu_utft_draw_hline(int x, int y, int l); |
hazheng | 40:be98219930e4 | 101 | |
hazheng | 92:e9bd429f16b5 | 102 | /** |
hazheng | 92:e9bd429f16b5 | 103 | * @brief Draw a vertical line on the srceen. |
hazheng | 92:e9bd429f16b5 | 104 | * @param x The start position of the line in the x-axis. |
hazheng | 92:e9bd429f16b5 | 105 | * @param y The start position of the line in the y-axis. |
hazheng | 92:e9bd429f16b5 | 106 | * @param l The length of the line. |
hazheng | 92:e9bd429f16b5 | 107 | */ |
hazheng | 40:be98219930e4 | 108 | void ardu_utft_draw_vline(int x, int y, int l); |
hazheng | 40:be98219930e4 | 109 | |
hazheng | 92:e9bd429f16b5 | 110 | /** |
hazheng | 92:e9bd429f16b5 | 111 | * @brief Draw a single pixel on the srceen. |
hazheng | 92:e9bd429f16b5 | 112 | * @param x The position of the pixel in the x-axis. |
hazheng | 92:e9bd429f16b5 | 113 | * @param y The position of the pixel in the y-axis. |
hazheng | 92:e9bd429f16b5 | 114 | */ |
hazheng | 42:c4e1606087ff | 115 | void ardu_utft_draw_pixel(int x, int y); |
hazheng | 42:c4e1606087ff | 116 | |
hazheng | 92:e9bd429f16b5 | 117 | /** |
hazheng | 92:e9bd429f16b5 | 118 | * @brief Draw a filled rectangle on the srceen. |
hazheng | 92:e9bd429f16b5 | 119 | * @param x1 The first point of the rectangle in the x-axis. |
hazheng | 92:e9bd429f16b5 | 120 | * @param y1 The first point of the rectangle in the y-axis. |
hazheng | 92:e9bd429f16b5 | 121 | * @param x2 The last point of the rectangle in the x-axis. |
hazheng | 92:e9bd429f16b5 | 122 | * @param y2 The last point of the rectangle in the y-axis. |
hazheng | 92:e9bd429f16b5 | 123 | */ |
hazheng | 42:c4e1606087ff | 124 | void ardu_utft_fill_rect(int x1, int y1, int x2, int y2); |
hazheng | 42:c4e1606087ff | 125 | |
hazheng | 92:e9bd429f16b5 | 126 | /** |
hazheng | 92:e9bd429f16b5 | 127 | * @brief Set the font that used to print character on the screen. |
hazheng | 92:e9bd429f16b5 | 128 | * @param font The pointer to a bytes array that describe the font. For details, please refer to the ArduUTFTFont.h header file. |
hazheng | 92:e9bd429f16b5 | 129 | */ |
hazheng | 42:c4e1606087ff | 130 | void ardu_utft_set_font(uint8_t * font); |
hazheng | 42:c4e1606087ff | 131 | |
hazheng | 92:e9bd429f16b5 | 132 | /** |
hazheng | 92:e9bd429f16b5 | 133 | * @brief print a char on the screen. |
hazheng | 92:e9bd429f16b5 | 134 | * @param c The char that needs to print. |
hazheng | 92:e9bd429f16b5 | 135 | * @param x The position of the char in x-axis. |
hazheng | 92:e9bd429f16b5 | 136 | * @param y The position of the char in y-axis. |
hazheng | 92:e9bd429f16b5 | 137 | */ |
hazheng | 42:c4e1606087ff | 138 | void ardu_utft_print_char(char c, int x, int y); |
hazheng | 42:c4e1606087ff | 139 | |
hazheng | 92:e9bd429f16b5 | 140 | /** |
hazheng | 92:e9bd429f16b5 | 141 | * @brief print a char string on the screen. |
hazheng | 92:e9bd429f16b5 | 142 | * @param st The pointer to the char string. |
hazheng | 92:e9bd429f16b5 | 143 | * @param x The start position of the char string in x-axis. |
hazheng | 92:e9bd429f16b5 | 144 | * @param y The start position of the char string in y-axis. |
hazheng | 92:e9bd429f16b5 | 145 | */ |
hazheng | 42:c4e1606087ff | 146 | void ardu_utft_print(char * st, int x, int y); |
hazheng | 40:be98219930e4 | 147 | |
hazheng | 92:e9bd429f16b5 | 148 | /** |
hazheng | 92:e9bd429f16b5 | 149 | * @brief Set the current row when printing the camera image on the screen. |
hazheng | 92:e9bd429f16b5 | 150 | * @param row The row index. |
hazheng | 92:e9bd429f16b5 | 151 | */ |
hazheng | 44:15de535c4005 | 152 | inline void ardu_utft_set_camimg_row(const uint16_t row) |
hazheng | 44:15de535c4005 | 153 | { |
hazheng | 44:15de535c4005 | 154 | ardu_utft_set_xy(0, row + CAM_IMG_CANVAS_ROW_OFFSET, CAM_IMG_CANVAS_COL_OFFSET, row + CAM_IMG_CANVAS_ROW_OFFSET); |
hazheng | 44:15de535c4005 | 155 | } |
hazheng | 44:15de535c4005 | 156 | |
hazheng | 92:e9bd429f16b5 | 157 | /** |
hazheng | 92:e9bd429f16b5 | 158 | * @brief Set the current row and colum when printing the camera image on the screen. |
hazheng | 92:e9bd429f16b5 | 159 | * @param row The row index. |
hazheng | 92:e9bd429f16b5 | 160 | * @param col The col index. |
hazheng | 92:e9bd429f16b5 | 161 | */ |
hazheng | 44:15de535c4005 | 162 | inline void ardu_utft_set_camimg_rowcol(const uint16_t row, const uint16_t col) |
hazheng | 44:15de535c4005 | 163 | { |
hazheng | 44:15de535c4005 | 164 | ardu_utft_set_xy(0, row + CAM_IMG_CANVAS_ROW_OFFSET, CAM_IMG_CANVAS_COL_OFFSET - col, row + CAM_IMG_CANVAS_ROW_OFFSET); |
hazheng | 44:15de535c4005 | 165 | } |
hazheng | 44:15de535c4005 | 166 | |
Bobymicjohn | 97:0ed9ede9a995 | 167 | /** |
Bobymicjohn | 97:0ed9ede9a995 | 168 | * @brief Gets the version number from ArduCam Shield V2. |
Bobymicjohn | 97:0ed9ede9a995 | 169 | * @return The version number. |
Bobymicjohn | 97:0ed9ede9a995 | 170 | */ |
Bobymicjohn | 97:0ed9ede9a995 | 171 | uint8_t ardu_utft_get_ver_num(); |
hazheng | 46:a5eb9bd3bb55 | 172 | #ifdef __cplusplus |
hazheng | 46:a5eb9bd3bb55 | 173 | } |
hazheng | 46:a5eb9bd3bb55 | 174 | #endif |
hazheng | 46:a5eb9bd3bb55 | 175 | |
hazheng | 40:be98219930e4 | 176 | #endif //ARDU_UTFT_H |