It's nucleo f4 DMA trandfer for ov7670&ILI9341.
Dependencies: mbed ILI9341_SPI OV7670_SCCB
main.cpp@0:ce10b2e08479, 2016-04-04 (annotated)
- Committer:
- tmnt
- Date:
- Mon Apr 04 02:05:59 2016 +0000
- Revision:
- 0:ce10b2e08479
- Child:
- 2:de327fb4e2c5
ov7670_dma for nculeof401re
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tmnt | 0:ce10b2e08479 | 1 | #include "mbed.h" |
tmnt | 0:ce10b2e08479 | 2 | #include "TIM_DMAInit.h" |
tmnt | 0:ce10b2e08479 | 3 | #include "SPI_DMAInit.h" |
tmnt | 0:ce10b2e08479 | 4 | |
tmnt | 0:ce10b2e08479 | 5 | /* |
tmnt | 0:ce10b2e08479 | 6 | |
tmnt | 0:ce10b2e08479 | 7 | ********ov7670******** |
tmnt | 0:ce10b2e08479 | 8 | +3V3 - 3V3 GND-GND |
tmnt | 0:ce10b2e08479 | 9 | PC_12 - SIOC SIDO - PC10 |
tmnt | 0:ce10b2e08479 | 10 | PD_2 - VSYNC HREF - A3 |
tmnt | 0:ce10b2e08479 | 11 | B4,A4 - PCLK XCLK - PC_9 |
tmnt | 0:ce10b2e08479 | 12 | PB_7 - D7 D6 - PB_6 |
tmnt | 0:ce10b2e08479 | 13 | PB_5 - D5 D4 - PB_4 |
tmnt | 0:ce10b2e08479 | 14 | PB_3 - D3 D2 - PB_2 |
tmnt | 0:ce10b2e08479 | 15 | PB_1 - D1 D0 - PB_0 |
tmnt | 0:ce10b2e08479 | 16 | +3V3-330Ω-RESET |
tmnt | 0:ce10b2e08479 | 17 | |
tmnt | 0:ce10b2e08479 | 18 | ********74HC00********* |
tmnt | 0:ce10b2e08479 | 19 | A1 VCC - +5V |
tmnt | 0:ce10b2e08479 | 20 | B1 B4 -- PCLK |
tmnt | 0:ce10b2e08479 | 21 | Y1 A4 -- PCLK |
tmnt | 0:ce10b2e08479 | 22 | A2 Y4 - B3 |
tmnt | 0:ce10b2e08479 | 23 | B2 B3 - Y4 |
tmnt | 0:ce10b2e08479 | 24 | Y2 A3 - HREF |
tmnt | 0:ce10b2e08479 | 25 | GND Y3 - PA8 |
tmnt | 0:ce10b2e08479 | 26 | |
tmnt | 0:ce10b2e08479 | 27 | ********ILI9341********* |
tmnt | 0:ce10b2e08479 | 28 | SDO - PA6 |
tmnt | 0:ce10b2e08479 | 29 | LED - 100Ω - +5V |
tmnt | 0:ce10b2e08479 | 30 | SCK - PA5 |
tmnt | 0:ce10b2e08479 | 31 | SDI - PA7 |
tmnt | 0:ce10b2e08479 | 32 | DC - PA_4 |
tmnt | 0:ce10b2e08479 | 33 | RS - PA_12 |
tmnt | 0:ce10b2e08479 | 34 | CS - PA_11 |
tmnt | 0:ce10b2e08479 | 35 | GND - GND |
tmnt | 0:ce10b2e08479 | 36 | VCC - +5V |
tmnt | 0:ce10b2e08479 | 37 | |
tmnt | 0:ce10b2e08479 | 38 | ********NUCLEOF401RE******* |
tmnt | 0:ce10b2e08479 | 39 | |
tmnt | 0:ce10b2e08479 | 40 | U5V× |
tmnt | 0:ce10b2e08479 | 41 | E5V○ |
tmnt | 0:ce10b2e08479 | 42 | |
tmnt | 0:ce10b2e08479 | 43 | */ |
tmnt | 0:ce10b2e08479 | 44 | |
tmnt | 0:ce10b2e08479 | 45 | |
tmnt | 0:ce10b2e08479 | 46 | |
tmnt | 0:ce10b2e08479 | 47 | |
tmnt | 0:ce10b2e08479 | 48 | |
tmnt | 0:ce10b2e08479 | 49 | |
tmnt | 0:ce10b2e08479 | 50 | #define REG_COM1 0x04 /* Control 1 */ |
tmnt | 0:ce10b2e08479 | 51 | #define REG_COM6 0x0f /* Control 6 */ |
tmnt | 0:ce10b2e08479 | 52 | #define REG_AECH 0x10 /* More bits of AEC value */ |
tmnt | 0:ce10b2e08479 | 53 | #define REG_CLKRC 0x11 /* Clocl control */ |
tmnt | 0:ce10b2e08479 | 54 | #define CLK_EXT 0x40 /* Use external clock directly */ |
tmnt | 0:ce10b2e08479 | 55 | #define CLK_SCALE 0x3f /* Mask for internal clock scale */ |
tmnt | 0:ce10b2e08479 | 56 | #define REG_COM7 0x12 /* Control 7 */ |
tmnt | 0:ce10b2e08479 | 57 | #define COM7_RESET 0x80 /* Register reset */ |
tmnt | 0:ce10b2e08479 | 58 | #define COM7_FMT_MASK 0x38 |
tmnt | 0:ce10b2e08479 | 59 | #define COM7_FMT_VGA 0x00 |
tmnt | 0:ce10b2e08479 | 60 | #define COM7_FMT_CIF 0x20 /* CIF format */ |
tmnt | 0:ce10b2e08479 | 61 | #define COM7_FMT_QVGA 0x10 /* QVGA format */ |
tmnt | 0:ce10b2e08479 | 62 | #define COM7_FMT_QCIF 0x08 /* QCIF format */ |
tmnt | 0:ce10b2e08479 | 63 | #define COM7_RGB 0x04 /* bits 0 and 2 - RGB format */ |
tmnt | 0:ce10b2e08479 | 64 | #define COM7_YUV 0x00 /* YUV */ |
tmnt | 0:ce10b2e08479 | 65 | #define COM7_BAYER 0x01 /* Bayer format */ |
tmnt | 0:ce10b2e08479 | 66 | #define COM7_PBAYER 0x05 /* "Processed bayer" */ |
tmnt | 0:ce10b2e08479 | 67 | #define REG_COM8 0x13 /* Control 8 */ |
tmnt | 0:ce10b2e08479 | 68 | #define REG_COM9 0x14 /* Control 9 - gain ceiling */ |
tmnt | 0:ce10b2e08479 | 69 | #define REG_TSLB 0x3a /* lots of stuff */ |
tmnt | 0:ce10b2e08479 | 70 | #define REG_COM15 0x40 /* Control 15 */ |
tmnt | 0:ce10b2e08479 | 71 | #define COM15_R10F0 0x00 /* Data range 10 to F0 */ |
tmnt | 0:ce10b2e08479 | 72 | #define COM15_R01FE 0x80 /* 01 to FE */ |
tmnt | 0:ce10b2e08479 | 73 | #define COM15_R00FF 0xc0 /* 00 to FF */ |
tmnt | 0:ce10b2e08479 | 74 | #define COM15_RGB565 0x10 /* RGB565 output */ |
tmnt | 0:ce10b2e08479 | 75 | #define COM15_RGB555 0x30 /* RGB555 output */ |
tmnt | 0:ce10b2e08479 | 76 | #define REG_COM16 0x41 /* Control 16 */ |
tmnt | 0:ce10b2e08479 | 77 | #define COM16_AWBGAIN 0x08 /* AWB gain enable */ |
tmnt | 0:ce10b2e08479 | 78 | #define REG_COM17 0x42 /* Control 17 */ |
tmnt | 0:ce10b2e08479 | 79 | #define COM17_AECWIN 0xc0 /* AEC window - must match COM4 */ |
tmnt | 0:ce10b2e08479 | 80 | #define COM17_CBAR 0x08 /* DSP Color bar */ |
tmnt | 0:ce10b2e08479 | 81 | #define REG_CMATRIX_BASE 0x4f |
tmnt | 0:ce10b2e08479 | 82 | #define CMATRIX_LEN 6 |
tmnt | 0:ce10b2e08479 | 83 | #define REG_CMATRIX_SIGN 0x58 |
tmnt | 0:ce10b2e08479 | 84 | #define REG_BRIGHT 0x55 /* Brightness */ |
tmnt | 0:ce10b2e08479 | 85 | #define REG_CONTRAS 0x56 /* Contrast control */ |
tmnt | 0:ce10b2e08479 | 86 | |
tmnt | 0:ce10b2e08479 | 87 | #define REG_GFIX 0x69 /* Fix gain control */ |
tmnt | 0:ce10b2e08479 | 88 | |
tmnt | 0:ce10b2e08479 | 89 | #define REG_REG76 0x76 /* OV's name */ |
tmnt | 0:ce10b2e08479 | 90 | #define R76_BLKPCOR 0x80 /* Black pixel correction enable */ |
tmnt | 0:ce10b2e08479 | 91 | #define R76_WHTPCOR 0x40 /* White pixel correction enable */ |
tmnt | 0:ce10b2e08479 | 92 | |
tmnt | 0:ce10b2e08479 | 93 | #define REG_RGB444 0x8c /* RGB 444 control */ |
tmnt | 0:ce10b2e08479 | 94 | #define R444_ENABLE 0x02 /* Turn on RGB444, overrides 5x5 */ |
tmnt | 0:ce10b2e08479 | 95 | #define R444_RGBX 0x01 /* Empty nibble at end */ |
tmnt | 0:ce10b2e08479 | 96 | |
tmnt | 0:ce10b2e08479 | 97 | #define REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */ |
tmnt | 0:ce10b2e08479 | 98 | #define REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */ |
tmnt | 0:ce10b2e08479 | 99 | |
tmnt | 0:ce10b2e08479 | 100 | #define REG_BD50MAX 0xa5 /* 50hz banding step limit */ |
tmnt | 0:ce10b2e08479 | 101 | #define REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */ |
tmnt | 0:ce10b2e08479 | 102 | #define REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */ |
tmnt | 0:ce10b2e08479 | 103 | #define REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */ |
tmnt | 0:ce10b2e08479 | 104 | #define REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */ |
tmnt | 0:ce10b2e08479 | 105 | #define REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */ |
tmnt | 0:ce10b2e08479 | 106 | #define REG_BD60MAX 0xab /* 60hz banding step limit */ |
tmnt | 0:ce10b2e08479 | 107 | |
tmnt | 0:ce10b2e08479 | 108 | |
tmnt | 0:ce10b2e08479 | 109 | |
tmnt | 0:ce10b2e08479 | 110 | uint8_t dma_buf[145][300]; |
tmnt | 0:ce10b2e08479 | 111 | uint8_t flag_dma; |
tmnt | 0:ce10b2e08479 | 112 | |
tmnt | 0:ce10b2e08479 | 113 | |
tmnt | 0:ce10b2e08479 | 114 | |
tmnt | 0:ce10b2e08479 | 115 | InterruptIn VSYNC(PD_2); |
tmnt | 0:ce10b2e08479 | 116 | |
tmnt | 0:ce10b2e08479 | 117 | SPI spi(PA_7,PA_6,PA_5); |
tmnt | 0:ce10b2e08479 | 118 | |
tmnt | 0:ce10b2e08479 | 119 | DigitalOut dc(PA_4); |
tmnt | 0:ce10b2e08479 | 120 | DigitalOut rs(PA_12); |
tmnt | 0:ce10b2e08479 | 121 | DigitalOut cs(PA_11); |
tmnt | 0:ce10b2e08479 | 122 | |
tmnt | 0:ce10b2e08479 | 123 | DigitalInOut SDA(PC_10); |
tmnt | 0:ce10b2e08479 | 124 | DigitalInOut SCL(PC_12); |
tmnt | 0:ce10b2e08479 | 125 | |
tmnt | 0:ce10b2e08479 | 126 | PortIn cdata(PortB, 0x00ff); |
tmnt | 0:ce10b2e08479 | 127 | |
tmnt | 0:ce10b2e08479 | 128 | void window (unsigned int x, unsigned int y, unsigned int w, unsigned int h); |
tmnt | 0:ce10b2e08479 | 129 | void pixel(int x, int y, int color); |
tmnt | 0:ce10b2e08479 | 130 | void vline(int x, int y0, int y1, int color); |
tmnt | 0:ce10b2e08479 | 131 | void circle(int x0, int y0, int r, int color); |
tmnt | 0:ce10b2e08479 | 132 | void fillcircle(int x0, int y0, int r, int color); |
tmnt | 0:ce10b2e08479 | 133 | void fillrect(int x0, int y0, int x1, int y1, int color); |
tmnt | 0:ce10b2e08479 | 134 | void wr_cmd(unsigned char cmd); |
tmnt | 0:ce10b2e08479 | 135 | void wr_dat(unsigned char dat); |
tmnt | 0:ce10b2e08479 | 136 | char rd_byte(unsigned char cmd); |
tmnt | 0:ce10b2e08479 | 137 | int rd_32(unsigned char cmd); |
tmnt | 0:ce10b2e08479 | 138 | int Read_ID(void); |
tmnt | 0:ce10b2e08479 | 139 | void tft_reset(); |
tmnt | 0:ce10b2e08479 | 140 | void fillrect(int x0, int y0, int x1, int y1, int color); |
tmnt | 0:ce10b2e08479 | 141 | |
tmnt | 0:ce10b2e08479 | 142 | void I2cstart(void); |
tmnt | 0:ce10b2e08479 | 143 | void I2cstop(void); |
tmnt | 0:ce10b2e08479 | 144 | void I2cout(unsigned char datar); |
tmnt | 0:ce10b2e08479 | 145 | void c(unsigned char adrs,unsigned char datak); |
tmnt | 0:ce10b2e08479 | 146 | void cam_init(); |
tmnt | 0:ce10b2e08479 | 147 | |
tmnt | 0:ce10b2e08479 | 148 | void camdma_start(); |
tmnt | 0:ce10b2e08479 | 149 | |
tmnt | 0:ce10b2e08479 | 150 | void test_color(); |
tmnt | 0:ce10b2e08479 | 151 | |
tmnt | 0:ce10b2e08479 | 152 | |
tmnt | 0:ce10b2e08479 | 153 | |
tmnt | 0:ce10b2e08479 | 154 | |
tmnt | 0:ce10b2e08479 | 155 | int main() { |
tmnt | 0:ce10b2e08479 | 156 | |
tmnt | 0:ce10b2e08479 | 157 | |
tmnt | 0:ce10b2e08479 | 158 | GPIO_InitTypeDef gpioconf1; |
tmnt | 0:ce10b2e08479 | 159 | __GPIOB_CLK_ENABLE(); |
tmnt | 0:ce10b2e08479 | 160 | gpioconf1.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 |GPIO_PIN_14 | GPIO_PIN_15;//pa13 |
tmnt | 0:ce10b2e08479 | 161 | gpioconf1.Mode = GPIO_MODE_INPUT; |
tmnt | 0:ce10b2e08479 | 162 | gpioconf1.Pull = GPIO_PULLDOWN; |
tmnt | 0:ce10b2e08479 | 163 | gpioconf1.Speed = GPIO_SPEED_HIGH; |
tmnt | 0:ce10b2e08479 | 164 | HAL_GPIO_Init(GPIOB, &gpioconf1); |
tmnt | 0:ce10b2e08479 | 165 | |
tmnt | 0:ce10b2e08479 | 166 | |
tmnt | 0:ce10b2e08479 | 167 | HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_HSE, RCC_MCODIV_1); |
tmnt | 0:ce10b2e08479 | 168 | |
tmnt | 0:ce10b2e08479 | 169 | GPIO_InitTypeDef GPIO_InitStruct; |
tmnt | 0:ce10b2e08479 | 170 | /*Configure GPIO pin : PC9 MCO2 for cam XCLK*/ |
tmnt | 0:ce10b2e08479 | 171 | __GPIOC_CLK_ENABLE(); |
tmnt | 0:ce10b2e08479 | 172 | GPIO_InitStruct.Pin = GPIO_PIN_9; |
tmnt | 0:ce10b2e08479 | 173 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
tmnt | 0:ce10b2e08479 | 174 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
tmnt | 0:ce10b2e08479 | 175 | GPIO_InitStruct.Speed = GPIO_SPEED_LOW; |
tmnt | 0:ce10b2e08479 | 176 | GPIO_InitStruct.Alternate = GPIO_AF0_MCO; |
tmnt | 0:ce10b2e08479 | 177 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
tmnt | 0:ce10b2e08479 | 178 | // spi_Init(); |
tmnt | 0:ce10b2e08479 | 179 | dma_init(); |
tmnt | 0:ce10b2e08479 | 180 | |
tmnt | 0:ce10b2e08479 | 181 | spi.format(8,3); |
tmnt | 0:ce10b2e08479 | 182 | spi.frequency(20000000); |
tmnt | 0:ce10b2e08479 | 183 | tft_reset(); |
tmnt | 0:ce10b2e08479 | 184 | |
tmnt | 0:ce10b2e08479 | 185 | __disable_irq(); |
tmnt | 0:ce10b2e08479 | 186 | |
tmnt | 0:ce10b2e08479 | 187 | VSYNC.rise(&camdma_start);//PCLK割り込み |
tmnt | 0:ce10b2e08479 | 188 | cam_init(); |
tmnt | 0:ce10b2e08479 | 189 | |
tmnt | 0:ce10b2e08479 | 190 | fillrect(0,0,150,290,0xf800);//red |
tmnt | 0:ce10b2e08479 | 191 | |
tmnt | 0:ce10b2e08479 | 192 | |
tmnt | 0:ce10b2e08479 | 193 | wait(1); |
tmnt | 0:ce10b2e08479 | 194 | wr_cmd(0x2C); |
tmnt | 0:ce10b2e08479 | 195 | spi.write(0x66); |
tmnt | 0:ce10b2e08479 | 196 | spi_Init(); |
tmnt | 0:ce10b2e08479 | 197 | |
tmnt | 0:ce10b2e08479 | 198 | __enable_irq(); |
tmnt | 0:ce10b2e08479 | 199 | |
tmnt | 0:ce10b2e08479 | 200 | |
tmnt | 0:ce10b2e08479 | 201 | while(1) { |
tmnt | 0:ce10b2e08479 | 202 | } |
tmnt | 0:ce10b2e08479 | 203 | } |
tmnt | 0:ce10b2e08479 | 204 | |
tmnt | 0:ce10b2e08479 | 205 | |
tmnt | 0:ce10b2e08479 | 206 | |
tmnt | 0:ce10b2e08479 | 207 | |
tmnt | 0:ce10b2e08479 | 208 | void wr_cmd(unsigned char cmd) |
tmnt | 0:ce10b2e08479 | 209 | { |
tmnt | 0:ce10b2e08479 | 210 | dc = 0; |
tmnt | 0:ce10b2e08479 | 211 | cs = 0; |
tmnt | 0:ce10b2e08479 | 212 | spi.write(cmd); // mbed lib |
tmnt | 0:ce10b2e08479 | 213 | dc = 1; |
tmnt | 0:ce10b2e08479 | 214 | } |
tmnt | 0:ce10b2e08479 | 215 | void wr_dat(unsigned char dat) |
tmnt | 0:ce10b2e08479 | 216 | { |
tmnt | 0:ce10b2e08479 | 217 | spi.write(dat); // mbed lib |
tmnt | 0:ce10b2e08479 | 218 | } |
tmnt | 0:ce10b2e08479 | 219 | char rd_byte(unsigned char cmd) |
tmnt | 0:ce10b2e08479 | 220 | { |
tmnt | 0:ce10b2e08479 | 221 | char r; |
tmnt | 0:ce10b2e08479 | 222 | dc = 0; |
tmnt | 0:ce10b2e08479 | 223 | cs = 0; |
tmnt | 0:ce10b2e08479 | 224 | spi.write(cmd); // mbed lib |
tmnt | 0:ce10b2e08479 | 225 | cs = 1; |
tmnt | 0:ce10b2e08479 | 226 | r = spi.write(0xff); |
tmnt | 0:ce10b2e08479 | 227 | cs = 1; |
tmnt | 0:ce10b2e08479 | 228 | return(r); |
tmnt | 0:ce10b2e08479 | 229 | } |
tmnt | 0:ce10b2e08479 | 230 | |
tmnt | 0:ce10b2e08479 | 231 | // read 32 bit |
tmnt | 0:ce10b2e08479 | 232 | int rd_32(unsigned char cmd) |
tmnt | 0:ce10b2e08479 | 233 | { |
tmnt | 0:ce10b2e08479 | 234 | int d; |
tmnt | 0:ce10b2e08479 | 235 | char r; |
tmnt | 0:ce10b2e08479 | 236 | dc = 0; |
tmnt | 0:ce10b2e08479 | 237 | cs = 0; |
tmnt | 0:ce10b2e08479 | 238 | d = cmd; |
tmnt | 0:ce10b2e08479 | 239 | d = d << 1; |
tmnt | 0:ce10b2e08479 | 240 | spi.format(9,3); // we have to add a dummy clock cycle |
tmnt | 0:ce10b2e08479 | 241 | spi.write(d); |
tmnt | 0:ce10b2e08479 | 242 | spi.format(8,3); |
tmnt | 0:ce10b2e08479 | 243 | dc = 1; |
tmnt | 0:ce10b2e08479 | 244 | r = spi.write(0xff); |
tmnt | 0:ce10b2e08479 | 245 | d = r; |
tmnt | 0:ce10b2e08479 | 246 | r = spi.write(0xff); |
tmnt | 0:ce10b2e08479 | 247 | d = (d << 8) | r; |
tmnt | 0:ce10b2e08479 | 248 | r = spi.write(0xff); |
tmnt | 0:ce10b2e08479 | 249 | d = (d << 8) | r; |
tmnt | 0:ce10b2e08479 | 250 | r = spi.write(0xff); |
tmnt | 0:ce10b2e08479 | 251 | d = (d << 8) | r; |
tmnt | 0:ce10b2e08479 | 252 | cs = 1; |
tmnt | 0:ce10b2e08479 | 253 | return(d); |
tmnt | 0:ce10b2e08479 | 254 | } |
tmnt | 0:ce10b2e08479 | 255 | |
tmnt | 0:ce10b2e08479 | 256 | int Read_ID(void){ |
tmnt | 0:ce10b2e08479 | 257 | int r; |
tmnt | 0:ce10b2e08479 | 258 | r = rd_byte(0x0A); |
tmnt | 0:ce10b2e08479 | 259 | r = rd_byte(0x0A); |
tmnt | 0:ce10b2e08479 | 260 | r = rd_byte(0x0A); |
tmnt | 0:ce10b2e08479 | 261 | r = rd_byte(0x0A); |
tmnt | 0:ce10b2e08479 | 262 | return(r); |
tmnt | 0:ce10b2e08479 | 263 | } |
tmnt | 0:ce10b2e08479 | 264 | |
tmnt | 0:ce10b2e08479 | 265 | |
tmnt | 0:ce10b2e08479 | 266 | // Init code based on MI0283QT datasheet |
tmnt | 0:ce10b2e08479 | 267 | |
tmnt | 0:ce10b2e08479 | 268 | void tft_reset() |
tmnt | 0:ce10b2e08479 | 269 | { |
tmnt | 0:ce10b2e08479 | 270 | cs = 1; // cs high |
tmnt | 0:ce10b2e08479 | 271 | dc = 1; // dc high |
tmnt | 0:ce10b2e08479 | 272 | rs = 0; // display reset |
tmnt | 0:ce10b2e08479 | 273 | |
tmnt | 0:ce10b2e08479 | 274 | wait_us(50); |
tmnt | 0:ce10b2e08479 | 275 | rs = 1; // end hardware reset |
tmnt | 0:ce10b2e08479 | 276 | wait_ms(5); |
tmnt | 0:ce10b2e08479 | 277 | |
tmnt | 0:ce10b2e08479 | 278 | wr_cmd(0x01); // SW reset |
tmnt | 0:ce10b2e08479 | 279 | wait_ms(5); |
tmnt | 0:ce10b2e08479 | 280 | wr_cmd(0x28); // display off |
tmnt | 0:ce10b2e08479 | 281 | |
tmnt | 0:ce10b2e08479 | 282 | /* Start Initial Sequence ----------------------------------------------------*/ |
tmnt | 0:ce10b2e08479 | 283 | wr_cmd(0xCF); |
tmnt | 0:ce10b2e08479 | 284 | spi.write(0x00); |
tmnt | 0:ce10b2e08479 | 285 | spi.write(0x83); |
tmnt | 0:ce10b2e08479 | 286 | spi.write(0x30); |
tmnt | 0:ce10b2e08479 | 287 | cs = 1; |
tmnt | 0:ce10b2e08479 | 288 | |
tmnt | 0:ce10b2e08479 | 289 | wr_cmd(0xED); |
tmnt | 0:ce10b2e08479 | 290 | spi.write(0x64); |
tmnt | 0:ce10b2e08479 | 291 | spi.write(0x03); |
tmnt | 0:ce10b2e08479 | 292 | spi.write(0x12); |
tmnt | 0:ce10b2e08479 | 293 | spi.write(0x81); |
tmnt | 0:ce10b2e08479 | 294 | cs = 1; |
tmnt | 0:ce10b2e08479 | 295 | |
tmnt | 0:ce10b2e08479 | 296 | wr_cmd(0xE8); |
tmnt | 0:ce10b2e08479 | 297 | spi.write(0x85); |
tmnt | 0:ce10b2e08479 | 298 | spi.write(0x01); |
tmnt | 0:ce10b2e08479 | 299 | spi.write(0x79); |
tmnt | 0:ce10b2e08479 | 300 | cs = 1; |
tmnt | 0:ce10b2e08479 | 301 | |
tmnt | 0:ce10b2e08479 | 302 | wr_cmd(0xCB); |
tmnt | 0:ce10b2e08479 | 303 | spi.write(0x39); |
tmnt | 0:ce10b2e08479 | 304 | spi.write(0x2C); |
tmnt | 0:ce10b2e08479 | 305 | spi.write(0x00); |
tmnt | 0:ce10b2e08479 | 306 | spi.write(0x34); |
tmnt | 0:ce10b2e08479 | 307 | spi.write(0x02); |
tmnt | 0:ce10b2e08479 | 308 | cs = 1; |
tmnt | 0:ce10b2e08479 | 309 | |
tmnt | 0:ce10b2e08479 | 310 | wr_cmd(0xF7); |
tmnt | 0:ce10b2e08479 | 311 | spi.write(0x20); |
tmnt | 0:ce10b2e08479 | 312 | cs = 1; |
tmnt | 0:ce10b2e08479 | 313 | |
tmnt | 0:ce10b2e08479 | 314 | wr_cmd(0xEA); |
tmnt | 0:ce10b2e08479 | 315 | spi.write(0x00); |
tmnt | 0:ce10b2e08479 | 316 | spi.write(0x00); |
tmnt | 0:ce10b2e08479 | 317 | cs = 1; |
tmnt | 0:ce10b2e08479 | 318 | |
tmnt | 0:ce10b2e08479 | 319 | wr_cmd(0xC0); // POWER_CONTROL_1 |
tmnt | 0:ce10b2e08479 | 320 | spi.write(0x26); |
tmnt | 0:ce10b2e08479 | 321 | cs = 1; |
tmnt | 0:ce10b2e08479 | 322 | |
tmnt | 0:ce10b2e08479 | 323 | wr_cmd(0xC1); // POWER_CONTROL_2 |
tmnt | 0:ce10b2e08479 | 324 | spi.write(0x11); |
tmnt | 0:ce10b2e08479 | 325 | cs = 1; |
tmnt | 0:ce10b2e08479 | 326 | |
tmnt | 0:ce10b2e08479 | 327 | wr_cmd(0xC5); // VCOM_CONTROL_1 |
tmnt | 0:ce10b2e08479 | 328 | spi.write(0x35); |
tmnt | 0:ce10b2e08479 | 329 | spi.write(0x3E); |
tmnt | 0:ce10b2e08479 | 330 | cs = 1; |
tmnt | 0:ce10b2e08479 | 331 | |
tmnt | 0:ce10b2e08479 | 332 | wr_cmd(0xC7); // VCOM_CONTROL_2 |
tmnt | 0:ce10b2e08479 | 333 | spi.write(0xBE); |
tmnt | 0:ce10b2e08479 | 334 | cs = 1; |
tmnt | 0:ce10b2e08479 | 335 | |
tmnt | 0:ce10b2e08479 | 336 | wr_cmd(0x36); // MEMORY_ACCESS_CONTROL |
tmnt | 0:ce10b2e08479 | 337 | spi.write(0x48); |
tmnt | 0:ce10b2e08479 | 338 | cs = 1; |
tmnt | 0:ce10b2e08479 | 339 | |
tmnt | 0:ce10b2e08479 | 340 | wr_cmd(0x3A); // COLMOD_PIXEL_FORMAT_SET |
tmnt | 0:ce10b2e08479 | 341 | spi.write(0x55); // 16 bit pixel |
tmnt | 0:ce10b2e08479 | 342 | cs = 1; |
tmnt | 0:ce10b2e08479 | 343 | |
tmnt | 0:ce10b2e08479 | 344 | wr_cmd(0xB1); // Frame Rate |
tmnt | 0:ce10b2e08479 | 345 | spi.write(0x00); |
tmnt | 0:ce10b2e08479 | 346 | spi.write(0x1B); |
tmnt | 0:ce10b2e08479 | 347 | cs = 1; |
tmnt | 0:ce10b2e08479 | 348 | |
tmnt | 0:ce10b2e08479 | 349 | wr_cmd(0xF2); // Gamma Function Disable |
tmnt | 0:ce10b2e08479 | 350 | spi.write(0x08); |
tmnt | 0:ce10b2e08479 | 351 | cs = 1; |
tmnt | 0:ce10b2e08479 | 352 | |
tmnt | 0:ce10b2e08479 | 353 | wr_cmd(0x26); |
tmnt | 0:ce10b2e08479 | 354 | spi.write(0x01); // gamma set for curve 01/2/04/08 |
tmnt | 0:ce10b2e08479 | 355 | cs = 1; |
tmnt | 0:ce10b2e08479 | 356 | |
tmnt | 0:ce10b2e08479 | 357 | wr_cmd(0xE0); // positive gamma correction |
tmnt | 0:ce10b2e08479 | 358 | spi.write(0x1F); |
tmnt | 0:ce10b2e08479 | 359 | spi.write(0x1A); |
tmnt | 0:ce10b2e08479 | 360 | spi.write(0x18); |
tmnt | 0:ce10b2e08479 | 361 | spi.write(0x0A); |
tmnt | 0:ce10b2e08479 | 362 | spi.write(0x0F); |
tmnt | 0:ce10b2e08479 | 363 | spi.write(0x06); |
tmnt | 0:ce10b2e08479 | 364 | spi.write(0x45); |
tmnt | 0:ce10b2e08479 | 365 | spi.write(0x87); |
tmnt | 0:ce10b2e08479 | 366 | spi.write(0x32); |
tmnt | 0:ce10b2e08479 | 367 | spi.write(0x0A); |
tmnt | 0:ce10b2e08479 | 368 | spi.write(0x07); |
tmnt | 0:ce10b2e08479 | 369 | spi.write(0x02); |
tmnt | 0:ce10b2e08479 | 370 | spi.write(0x07); |
tmnt | 0:ce10b2e08479 | 371 | spi.write(0x05); |
tmnt | 0:ce10b2e08479 | 372 | spi.write(0x00); |
tmnt | 0:ce10b2e08479 | 373 | cs = 1; |
tmnt | 0:ce10b2e08479 | 374 | |
tmnt | 0:ce10b2e08479 | 375 | wr_cmd(0xE1); // negativ gamma correction |
tmnt | 0:ce10b2e08479 | 376 | spi.write(0x00); |
tmnt | 0:ce10b2e08479 | 377 | spi.write(0x25); |
tmnt | 0:ce10b2e08479 | 378 | spi.write(0x27); |
tmnt | 0:ce10b2e08479 | 379 | spi.write(0x05); |
tmnt | 0:ce10b2e08479 | 380 | spi.write(0x10); |
tmnt | 0:ce10b2e08479 | 381 | spi.write(0x09); |
tmnt | 0:ce10b2e08479 | 382 | spi.write(0x3A); |
tmnt | 0:ce10b2e08479 | 383 | spi.write(0x78); |
tmnt | 0:ce10b2e08479 | 384 | spi.write(0x4D); |
tmnt | 0:ce10b2e08479 | 385 | spi.write(0x05); |
tmnt | 0:ce10b2e08479 | 386 | spi.write(0x18); |
tmnt | 0:ce10b2e08479 | 387 | spi.write(0x0D); |
tmnt | 0:ce10b2e08479 | 388 | spi.write(0x38); |
tmnt | 0:ce10b2e08479 | 389 | spi.write(0x3A); |
tmnt | 0:ce10b2e08479 | 390 | spi.write(0x1F); |
tmnt | 0:ce10b2e08479 | 391 | cs = 1; |
tmnt | 0:ce10b2e08479 | 392 | |
tmnt | 0:ce10b2e08479 | 393 | wr_cmd(0x2A); |
tmnt | 0:ce10b2e08479 | 394 | spi.write(0); |
tmnt | 0:ce10b2e08479 | 395 | spi.write(0); |
tmnt | 0:ce10b2e08479 | 396 | spi.write(0); |
tmnt | 0:ce10b2e08479 | 397 | spi.write(0x95); |
tmnt | 0:ce10b2e08479 | 398 | |
tmnt | 0:ce10b2e08479 | 399 | cs = 1; |
tmnt | 0:ce10b2e08479 | 400 | wr_cmd(0x2B); |
tmnt | 0:ce10b2e08479 | 401 | spi.write(0); |
tmnt | 0:ce10b2e08479 | 402 | spi.write(0); |
tmnt | 0:ce10b2e08479 | 403 | spi.write(0x00); |
tmnt | 0:ce10b2e08479 | 404 | spi.write(0x90); |
tmnt | 0:ce10b2e08479 | 405 | cs = 1; |
tmnt | 0:ce10b2e08479 | 406 | |
tmnt | 0:ce10b2e08479 | 407 | //wr_cmd(0x34); // tearing effect off |
tmnt | 0:ce10b2e08479 | 408 | //_cs = 1; |
tmnt | 0:ce10b2e08479 | 409 | |
tmnt | 0:ce10b2e08479 | 410 | //wr_cmd(0x35); // tearing effect on |
tmnt | 0:ce10b2e08479 | 411 | //_cs = 1; |
tmnt | 0:ce10b2e08479 | 412 | |
tmnt | 0:ce10b2e08479 | 413 | wr_cmd(0xB7); // entry mode |
tmnt | 0:ce10b2e08479 | 414 | spi.write(0x07); |
tmnt | 0:ce10b2e08479 | 415 | cs = 1; |
tmnt | 0:ce10b2e08479 | 416 | |
tmnt | 0:ce10b2e08479 | 417 | wr_cmd(0xB6); // display function control |
tmnt | 0:ce10b2e08479 | 418 | spi.write(0x0A); |
tmnt | 0:ce10b2e08479 | 419 | spi.write(0x82); |
tmnt | 0:ce10b2e08479 | 420 | spi.write(0x27); |
tmnt | 0:ce10b2e08479 | 421 | spi.write(0x00); |
tmnt | 0:ce10b2e08479 | 422 | cs = 1; |
tmnt | 0:ce10b2e08479 | 423 | |
tmnt | 0:ce10b2e08479 | 424 | wr_cmd(0x11); // sleep out |
tmnt | 0:ce10b2e08479 | 425 | cs = 1; |
tmnt | 0:ce10b2e08479 | 426 | |
tmnt | 0:ce10b2e08479 | 427 | wait_ms(100); |
tmnt | 0:ce10b2e08479 | 428 | |
tmnt | 0:ce10b2e08479 | 429 | wr_cmd(0x29); // display on |
tmnt | 0:ce10b2e08479 | 430 | cs = 1; |
tmnt | 0:ce10b2e08479 | 431 | |
tmnt | 0:ce10b2e08479 | 432 | wait_ms(100); |
tmnt | 0:ce10b2e08479 | 433 | |
tmnt | 0:ce10b2e08479 | 434 | } |
tmnt | 0:ce10b2e08479 | 435 | void pixel(int x, int y, int color) |
tmnt | 0:ce10b2e08479 | 436 | { |
tmnt | 0:ce10b2e08479 | 437 | wr_cmd(0x2A); |
tmnt | 0:ce10b2e08479 | 438 | spi.write(x >> 8); |
tmnt | 0:ce10b2e08479 | 439 | spi.write(x); |
tmnt | 0:ce10b2e08479 | 440 | cs = 1; |
tmnt | 0:ce10b2e08479 | 441 | wr_cmd(0x2B); |
tmnt | 0:ce10b2e08479 | 442 | spi.write(y >> 8); |
tmnt | 0:ce10b2e08479 | 443 | spi.write(y); |
tmnt | 0:ce10b2e08479 | 444 | cs = 1; |
tmnt | 0:ce10b2e08479 | 445 | wr_cmd(0x2C); // send pixel |
tmnt | 0:ce10b2e08479 | 446 | //#if defined TARGET_KL25Z // 8 Bit SPI |
tmnt | 0:ce10b2e08479 | 447 | spi.write(color >> 8); |
tmnt | 0:ce10b2e08479 | 448 | spi.write(color & 0xff); |
tmnt | 0:ce10b2e08479 | 449 | /*#else |
tmnt | 0:ce10b2e08479 | 450 | SPI::format(16,3); // switch to 16 bit Mode 3 |
tmnt | 0:ce10b2e08479 | 451 | SPI::write(color); // Write D0..D15 |
tmnt | 0:ce10b2e08479 | 452 | SPI::format(8,3); |
tmnt | 0:ce10b2e08479 | 453 | #endif*/ |
tmnt | 0:ce10b2e08479 | 454 | cs = 1; |
tmnt | 0:ce10b2e08479 | 455 | } |
tmnt | 0:ce10b2e08479 | 456 | |
tmnt | 0:ce10b2e08479 | 457 | void window (unsigned int x, unsigned int y, unsigned int w, unsigned int h) |
tmnt | 0:ce10b2e08479 | 458 | { |
tmnt | 0:ce10b2e08479 | 459 | wr_cmd(0x2A); |
tmnt | 0:ce10b2e08479 | 460 | spi.write(x >> 8); |
tmnt | 0:ce10b2e08479 | 461 | spi.write(x); |
tmnt | 0:ce10b2e08479 | 462 | spi.write((x+w-1) >> 8); |
tmnt | 0:ce10b2e08479 | 463 | spi.write(x+w-1); |
tmnt | 0:ce10b2e08479 | 464 | |
tmnt | 0:ce10b2e08479 | 465 | cs = 1; |
tmnt | 0:ce10b2e08479 | 466 | wr_cmd(0x2B); |
tmnt | 0:ce10b2e08479 | 467 | spi.write(y >> 8); |
tmnt | 0:ce10b2e08479 | 468 | spi.write(y); |
tmnt | 0:ce10b2e08479 | 469 | spi.write((y+h-1) >> 8); |
tmnt | 0:ce10b2e08479 | 470 | spi.write(y+h-1); |
tmnt | 0:ce10b2e08479 | 471 | cs = 1; |
tmnt | 0:ce10b2e08479 | 472 | } |
tmnt | 0:ce10b2e08479 | 473 | |
tmnt | 0:ce10b2e08479 | 474 | void vline(int x, int y0, int y1, int color) |
tmnt | 0:ce10b2e08479 | 475 | { |
tmnt | 0:ce10b2e08479 | 476 | int h; |
tmnt | 0:ce10b2e08479 | 477 | h = y1 - y0 + 1; |
tmnt | 0:ce10b2e08479 | 478 | window(x,y0,1,h); |
tmnt | 0:ce10b2e08479 | 479 | wr_cmd(0x2C); // send pixel |
tmnt | 0:ce10b2e08479 | 480 | //#if defined TARGET_KL25Z // 8 Bit SPI |
tmnt | 0:ce10b2e08479 | 481 | for (int y=0; y<h; y++) { |
tmnt | 0:ce10b2e08479 | 482 | spi.write(color >> 8); |
tmnt | 0:ce10b2e08479 | 483 | spi.write(color & 0xff); |
tmnt | 0:ce10b2e08479 | 484 | } |
tmnt | 0:ce10b2e08479 | 485 | /* #else |
tmnt | 0:ce10b2e08479 | 486 | SPI::format(16,3); // switch to 16 bit Mode 3 |
tmnt | 0:ce10b2e08479 | 487 | for (int y=0; y<h; y++) { |
tmnt | 0:ce10b2e08479 | 488 | SPI::write(color); |
tmnt | 0:ce10b2e08479 | 489 | } |
tmnt | 0:ce10b2e08479 | 490 | SPI::format(8,3);*/ |
tmnt | 0:ce10b2e08479 | 491 | //#endif |
tmnt | 0:ce10b2e08479 | 492 | cs = 1; |
tmnt | 0:ce10b2e08479 | 493 | //WindowMax(); |
tmnt | 0:ce10b2e08479 | 494 | return; |
tmnt | 0:ce10b2e08479 | 495 | } |
tmnt | 0:ce10b2e08479 | 496 | |
tmnt | 0:ce10b2e08479 | 497 | void fillcircle(int x0, int y0, int r, int color) |
tmnt | 0:ce10b2e08479 | 498 | { |
tmnt | 0:ce10b2e08479 | 499 | int x = -r, y = 0, err = 2-2*r, e2; |
tmnt | 0:ce10b2e08479 | 500 | do { |
tmnt | 0:ce10b2e08479 | 501 | vline(x0-x, y0-y, y0+y, color); |
tmnt | 0:ce10b2e08479 | 502 | vline(x0+x, y0-y, y0+y, color); |
tmnt | 0:ce10b2e08479 | 503 | e2 = err; |
tmnt | 0:ce10b2e08479 | 504 | if (e2 <= y) { |
tmnt | 0:ce10b2e08479 | 505 | err += ++y*2+1; |
tmnt | 0:ce10b2e08479 | 506 | if (-x == y && e2 <= x) e2 = 0; |
tmnt | 0:ce10b2e08479 | 507 | } |
tmnt | 0:ce10b2e08479 | 508 | if (e2 > x) err += ++x*2+1; |
tmnt | 0:ce10b2e08479 | 509 | } while (x <= 0); |
tmnt | 0:ce10b2e08479 | 510 | } |
tmnt | 0:ce10b2e08479 | 511 | |
tmnt | 0:ce10b2e08479 | 512 | |
tmnt | 0:ce10b2e08479 | 513 | void circle(int x0, int y0, int r, int color) |
tmnt | 0:ce10b2e08479 | 514 | { |
tmnt | 0:ce10b2e08479 | 515 | |
tmnt | 0:ce10b2e08479 | 516 | int x = -r, y = 0, err = 2-2*r, e2; |
tmnt | 0:ce10b2e08479 | 517 | do { |
tmnt | 0:ce10b2e08479 | 518 | pixel(x0-x, y0+y,color); |
tmnt | 0:ce10b2e08479 | 519 | pixel(x0+x, y0+y,color); |
tmnt | 0:ce10b2e08479 | 520 | pixel(x0+x, y0-y,color); |
tmnt | 0:ce10b2e08479 | 521 | pixel(x0-x, y0-y,color); |
tmnt | 0:ce10b2e08479 | 522 | e2 = err; |
tmnt | 0:ce10b2e08479 | 523 | if (e2 <= y) { |
tmnt | 0:ce10b2e08479 | 524 | err += ++y*2+1; |
tmnt | 0:ce10b2e08479 | 525 | if (-x == y && e2 <= x) e2 = 0; |
tmnt | 0:ce10b2e08479 | 526 | } |
tmnt | 0:ce10b2e08479 | 527 | if (e2 > x) err += ++x*2+1; |
tmnt | 0:ce10b2e08479 | 528 | } while (x <= 0); |
tmnt | 0:ce10b2e08479 | 529 | } |
tmnt | 0:ce10b2e08479 | 530 | void fillrect(int x0, int y0, int x1, int y1, int color) |
tmnt | 0:ce10b2e08479 | 531 | { |
tmnt | 0:ce10b2e08479 | 532 | |
tmnt | 0:ce10b2e08479 | 533 | int h = y1 - y0 + 1; |
tmnt | 0:ce10b2e08479 | 534 | int w = x1 - x0 + 1; |
tmnt | 0:ce10b2e08479 | 535 | int pixel = h * w; |
tmnt | 0:ce10b2e08479 | 536 | //window(x0,y0,w,h); |
tmnt | 0:ce10b2e08479 | 537 | wr_cmd(0x2C); // send pixel |
tmnt | 0:ce10b2e08479 | 538 | //#if defined TARGET_KL25Z // 8 Bit SPI |
tmnt | 0:ce10b2e08479 | 539 | for (int p=0; p<pixel; p++) { |
tmnt | 0:ce10b2e08479 | 540 | spi.write(color >> 8); |
tmnt | 0:ce10b2e08479 | 541 | spi.write(color & 0xff); |
tmnt | 0:ce10b2e08479 | 542 | } |
tmnt | 0:ce10b2e08479 | 543 | /*#else |
tmnt | 0:ce10b2e08479 | 544 | SPI::format(16,3); // switch to 16 bit Mode 3 |
tmnt | 0:ce10b2e08479 | 545 | for (int p=0; p<pixel; p++) { |
tmnt | 0:ce10b2e08479 | 546 | SPI::write(color); |
tmnt | 0:ce10b2e08479 | 547 | } |
tmnt | 0:ce10b2e08479 | 548 | SPI::format(8,3); |
tmnt | 0:ce10b2e08479 | 549 | #endif*/ |
tmnt | 0:ce10b2e08479 | 550 | cs = 1; |
tmnt | 0:ce10b2e08479 | 551 | //WindowMax(); |
tmnt | 0:ce10b2e08479 | 552 | return; |
tmnt | 0:ce10b2e08479 | 553 | } |
tmnt | 0:ce10b2e08479 | 554 | |
tmnt | 0:ce10b2e08479 | 555 | void I2cstart(void) |
tmnt | 0:ce10b2e08479 | 556 | { |
tmnt | 0:ce10b2e08479 | 557 | SDA=1;SCL=1; /* SCL,SDAは常時Highとする */ |
tmnt | 0:ce10b2e08479 | 558 | wait_us(2); |
tmnt | 0:ce10b2e08479 | 559 | SDA=0; |
tmnt | 0:ce10b2e08479 | 560 | wait_us(2); // SDA出力 |
tmnt | 0:ce10b2e08479 | 561 | } |
tmnt | 0:ce10b2e08479 | 562 | |
tmnt | 0:ce10b2e08479 | 563 | void I2cstop(void) |
tmnt | 0:ce10b2e08479 | 564 | { |
tmnt | 0:ce10b2e08479 | 565 | SCL=0; // 先にSDA Low |
tmnt | 0:ce10b2e08479 | 566 | wait_us(2); |
tmnt | 0:ce10b2e08479 | 567 | SDA=0; // SCL Low |
tmnt | 0:ce10b2e08479 | 568 | wait_us(2); |
tmnt | 0:ce10b2e08479 | 569 | SCL=1; // SDA Low // 出力モードに戻す SDA =Low |
tmnt | 0:ce10b2e08479 | 570 | wait_us(2); |
tmnt | 0:ce10b2e08479 | 571 | SDA=1; // 先にSCLをHigh |
tmnt | 0:ce10b2e08479 | 572 | wait_us(2); |
tmnt | 0:ce10b2e08479 | 573 | // 後からSDAをHigh |
tmnt | 0:ce10b2e08479 | 574 | |
tmnt | 0:ce10b2e08479 | 575 | } |
tmnt | 0:ce10b2e08479 | 576 | void I2cout(unsigned char datar) |
tmnt | 0:ce10b2e08479 | 577 | { |
tmnt | 0:ce10b2e08479 | 578 | int ia; |
tmnt | 0:ce10b2e08479 | 579 | for(ia=0;ia<8;ia++){ |
tmnt | 0:ce10b2e08479 | 580 | SCL=0; |
tmnt | 0:ce10b2e08479 | 581 | if(datar & 0x80){SDA=1;} |
tmnt | 0:ce10b2e08479 | 582 | else SDA=0; |
tmnt | 0:ce10b2e08479 | 583 | datar<<=1; |
tmnt | 0:ce10b2e08479 | 584 | wait_us(1); |
tmnt | 0:ce10b2e08479 | 585 | SCL=1; |
tmnt | 0:ce10b2e08479 | 586 | wait_us(2); |
tmnt | 0:ce10b2e08479 | 587 | SCL=0; |
tmnt | 0:ce10b2e08479 | 588 | wait_us(1);//wait(); |
tmnt | 0:ce10b2e08479 | 589 | } |
tmnt | 0:ce10b2e08479 | 590 | wait_us(1); |
tmnt | 0:ce10b2e08479 | 591 | |
tmnt | 0:ce10b2e08479 | 592 | SCL=1; |
tmnt | 0:ce10b2e08479 | 593 | datar<<=1; |
tmnt | 0:ce10b2e08479 | 594 | wait_us(2); |
tmnt | 0:ce10b2e08479 | 595 | SCL=0; |
tmnt | 0:ce10b2e08479 | 596 | |
tmnt | 0:ce10b2e08479 | 597 | wait_us(1); |
tmnt | 0:ce10b2e08479 | 598 | } |
tmnt | 0:ce10b2e08479 | 599 | |
tmnt | 0:ce10b2e08479 | 600 | |
tmnt | 0:ce10b2e08479 | 601 | void c(unsigned char adrs,unsigned char datak) |
tmnt | 0:ce10b2e08479 | 602 | { |
tmnt | 0:ce10b2e08479 | 603 | I2cstart(); |
tmnt | 0:ce10b2e08479 | 604 | I2cout(0x42); |
tmnt | 0:ce10b2e08479 | 605 | I2cout(adrs); |
tmnt | 0:ce10b2e08479 | 606 | I2cout(datak); |
tmnt | 0:ce10b2e08479 | 607 | I2cstop(); |
tmnt | 0:ce10b2e08479 | 608 | wait_ms(10); |
tmnt | 0:ce10b2e08479 | 609 | } |
tmnt | 0:ce10b2e08479 | 610 | |
tmnt | 0:ce10b2e08479 | 611 | |
tmnt | 0:ce10b2e08479 | 612 | void cam_init(){ |
tmnt | 0:ce10b2e08479 | 613 | c(REG_COM7, COM7_RESET); //0x12:COM7(Reset,QCIF,Cbar,RGBformat) |
tmnt | 0:ce10b2e08479 | 614 | wait_ms(200); //200ms |
tmnt | 0:ce10b2e08479 | 615 | |
tmnt | 0:ce10b2e08479 | 616 | c(REG_COM7,COM7_RGB|COM7_FMT_QCIF); //0x12:COM7 , 0x0C) //QCIF, RGB |
tmnt | 0:ce10b2e08479 | 617 | |
tmnt | 0:ce10b2e08479 | 618 | c(REG_RGB444, 0x00); //0x8c:RGB 444 control |
tmnt | 0:ce10b2e08479 | 619 | c(REG_COM1, 0x00); //0x40 //0x04:COM1(CCIR656,AEC) //0) //0x40) |
tmnt | 0:ce10b2e08479 | 620 | c(REG_COM15, COM15_R01FE|COM15_RGB565); //0x40:COM15 |
tmnt | 0:ce10b2e08479 | 621 | |
tmnt | 0:ce10b2e08479 | 622 | c(REG_COM9, 0x48); // 38 0x14:COM9=max AGC gain ceiling, Freeze AGC/AEC |
tmnt | 0:ce10b2e08479 | 623 | |
tmnt | 0:ce10b2e08479 | 624 | //c(0x3d,0xc3); //(REG_COM13, COM13_GAMMA|COM13_UVSAT|0x2) //0x3d:COM13 |
tmnt | 0:ce10b2e08479 | 625 | c(REG_HAECC7,0x94); //0xaa:Hist AEC/AGC control 7 c(0xAA,0x94) //AEC algorithm |
tmnt | 0:ce10b2e08479 | 626 | |
tmnt | 0:ce10b2e08479 | 627 | c(REG_TSLB,0x04); //0x3a:Neg,UVval,YUYV,window TSLB_YLAST) //0x04) //0x0C) //0x80) //0x00) //0x04) |
tmnt | 0:ce10b2e08479 | 628 | c(0x20,0x04); //ADCCTR0, A/D range&ref, mu0102 |
tmnt | 0:ce10b2e08479 | 629 | |
tmnt | 0:ce10b2e08479 | 630 | /******* ringo *********/ |
tmnt | 0:ce10b2e08479 | 631 | c(REG_COM8,0xfd); //AGC,AWB OFF,res OK |
tmnt | 0:ce10b2e08479 | 632 | |
tmnt | 0:ce10b2e08479 | 633 | c(0x10,0x0f);//AECコントロール(中位ビット) |
tmnt | 0:ce10b2e08479 | 634 | c(0x07,0x00);//AECコントロール(上位ビット) |
tmnt | 0:ce10b2e08479 | 635 | //by Mr.Shiono |
tmnt | 0:ce10b2e08479 | 636 | |
tmnt | 0:ce10b2e08479 | 637 | c(0x01,0x40); |
tmnt | 0:ce10b2e08479 | 638 | c(0x02,0x60); |
tmnt | 0:ce10b2e08479 | 639 | c(0x03,0x0a); |
tmnt | 0:ce10b2e08479 | 640 | c(0x0c,0x00); |
tmnt | 0:ce10b2e08479 | 641 | c(0x0e,0x61); |
tmnt | 0:ce10b2e08479 | 642 | c(0x0f,0x4b); |
tmnt | 0:ce10b2e08479 | 643 | c(0x15,0x00); |
tmnt | 0:ce10b2e08479 | 644 | c(0x16,0x02); |
tmnt | 0:ce10b2e08479 | 645 | c(0x17,0x18); //HSTART |
tmnt | 0:ce10b2e08479 | 646 | c(0x18,0x01); |
tmnt | 0:ce10b2e08479 | 647 | c(0x19,0x02); |
tmnt | 0:ce10b2e08479 | 648 | c(0x1a,0x7a); |
tmnt | 0:ce10b2e08479 | 649 | c(0x1e,0x07); |
tmnt | 0:ce10b2e08479 | 650 | c(0x21,0x02); |
tmnt | 0:ce10b2e08479 | 651 | c(0x22,0x91); |
tmnt | 0:ce10b2e08479 | 652 | c(0x29,0x07); |
tmnt | 0:ce10b2e08479 | 653 | c(0x32,0xb6); |
tmnt | 0:ce10b2e08479 | 654 | c(0x33,0x0b); |
tmnt | 0:ce10b2e08479 | 655 | c(0x34,0x11); |
tmnt | 0:ce10b2e08479 | 656 | c(0x35,0x0b); |
tmnt | 0:ce10b2e08479 | 657 | c(0x37,0x1d); |
tmnt | 0:ce10b2e08479 | 658 | c(0x38,0x71); |
tmnt | 0:ce10b2e08479 | 659 | c(0x39,0x2a); |
tmnt | 0:ce10b2e08479 | 660 | c(0x3b,0x92);//com11 ナイトモード |
tmnt | 0:ce10b2e08479 | 661 | c(0x3c,0x78); |
tmnt | 0:ce10b2e08479 | 662 | c(0x3d,0xc3); |
tmnt | 0:ce10b2e08479 | 663 | c(0x3e,0x00); |
tmnt | 0:ce10b2e08479 | 664 | c(0x3f,0x00); |
tmnt | 0:ce10b2e08479 | 665 | c(0x41,0x08); |
tmnt | 0:ce10b2e08479 | 666 | c(0x41,0x38); |
tmnt | 0:ce10b2e08479 | 667 | c(0x43,0x0a); |
tmnt | 0:ce10b2e08479 | 668 | c(0x44,0xf0); |
tmnt | 0:ce10b2e08479 | 669 | c(0x45,0x34); |
tmnt | 0:ce10b2e08479 | 670 | c(0x46,0x58); |
tmnt | 0:ce10b2e08479 | 671 | c(0x47,0x28); |
tmnt | 0:ce10b2e08479 | 672 | c(0x48,0x3a); |
tmnt | 0:ce10b2e08479 | 673 | c(0x4b,0x09); |
tmnt | 0:ce10b2e08479 | 674 | c(0x4c,0x00); |
tmnt | 0:ce10b2e08479 | 675 | c(0x4d,0x40); |
tmnt | 0:ce10b2e08479 | 676 | c(0x4e,0x20); |
tmnt | 0:ce10b2e08479 | 677 | c(0x4f,0x80);//c(0x4f,0x80); 彩度調整 |
tmnt | 0:ce10b2e08479 | 678 | c(0x50,0x80);//c(0x50,0x80); |
tmnt | 0:ce10b2e08479 | 679 | c(0x51,0x00); |
tmnt | 0:ce10b2e08479 | 680 | c(0x52,0x22);//c(0x52,0x22); |
tmnt | 0:ce10b2e08479 | 681 | c(0x53,0x5e);//c(0x52,0x5e); |
tmnt | 0:ce10b2e08479 | 682 | c(0x54,0x80);//c(0x54,0x80); |
tmnt | 0:ce10b2e08479 | 683 | c(0x56,0x40); |
tmnt | 0:ce10b2e08479 | 684 | c(0x58,0x9e); |
tmnt | 0:ce10b2e08479 | 685 | c(0x59,0x88); |
tmnt | 0:ce10b2e08479 | 686 | c(0x5a,0x88); |
tmnt | 0:ce10b2e08479 | 687 | c(0x5b,0x44); |
tmnt | 0:ce10b2e08479 | 688 | c(0x5c,0x67); |
tmnt | 0:ce10b2e08479 | 689 | c(0x5d,0x49); |
tmnt | 0:ce10b2e08479 | 690 | c(0x5e,0x0e); |
tmnt | 0:ce10b2e08479 | 691 | c(0x69,0x00); |
tmnt | 0:ce10b2e08479 | 692 | c(0x6a,0x40); |
tmnt | 0:ce10b2e08479 | 693 | c(0x6b,0x0a); |
tmnt | 0:ce10b2e08479 | 694 | c(0x6c,0x0a); |
tmnt | 0:ce10b2e08479 | 695 | c(0x6d,0x55); |
tmnt | 0:ce10b2e08479 | 696 | c(0x6e,0x11); |
tmnt | 0:ce10b2e08479 | 697 | c(0x6f,0x9f); |
tmnt | 0:ce10b2e08479 | 698 | c(0x70,0x3a); |
tmnt | 0:ce10b2e08479 | 699 | c(0x71,0x35); |
tmnt | 0:ce10b2e08479 | 700 | c(0x72,0x11); |
tmnt | 0:ce10b2e08479 | 701 | c(0x73,0xf0); |
tmnt | 0:ce10b2e08479 | 702 | c(0x74,0x10); |
tmnt | 0:ce10b2e08479 | 703 | c(0x75,0x05); |
tmnt | 0:ce10b2e08479 | 704 | c(0x76,0xe1); |
tmnt | 0:ce10b2e08479 | 705 | c(0x77,0x01); |
tmnt | 0:ce10b2e08479 | 706 | c(0x78,0x04); |
tmnt | 0:ce10b2e08479 | 707 | c(0x79,0x01); |
tmnt | 0:ce10b2e08479 | 708 | c(0x8d,0x4f); |
tmnt | 0:ce10b2e08479 | 709 | c(0x8e,0x00); |
tmnt | 0:ce10b2e08479 | 710 | c(0x8f,0x00); |
tmnt | 0:ce10b2e08479 | 711 | c(0x90,0x00); |
tmnt | 0:ce10b2e08479 | 712 | c(0x91,0x00); |
tmnt | 0:ce10b2e08479 | 713 | c(0x96,0x00); |
tmnt | 0:ce10b2e08479 | 714 | c(0x96,0x00); //? |
tmnt | 0:ce10b2e08479 | 715 | c(0x97,0x30); |
tmnt | 0:ce10b2e08479 | 716 | c(0x98,0x20); |
tmnt | 0:ce10b2e08479 | 717 | c(0x99,0x30); |
tmnt | 0:ce10b2e08479 | 718 | c(0x9a,0x00); |
tmnt | 0:ce10b2e08479 | 719 | c(0x9a,0x84); //? |
tmnt | 0:ce10b2e08479 | 720 | c(0x9b,0x29); |
tmnt | 0:ce10b2e08479 | 721 | c(0x9c,0x03); |
tmnt | 0:ce10b2e08479 | 722 | c(0x9d,0x4c); |
tmnt | 0:ce10b2e08479 | 723 | c(0x9e,0x3f); |
tmnt | 0:ce10b2e08479 | 724 | c(0xa2,0x02); |
tmnt | 0:ce10b2e08479 | 725 | c(0xa4,0x88); |
tmnt | 0:ce10b2e08479 | 726 | c(0xb0,0x84); |
tmnt | 0:ce10b2e08479 | 727 | c(0xb1,0x0c); |
tmnt | 0:ce10b2e08479 | 728 | c(0xb2,0x0e); |
tmnt | 0:ce10b2e08479 | 729 | c(0xb3,0x82); |
tmnt | 0:ce10b2e08479 | 730 | c(0xb8,0x0a); |
tmnt | 0:ce10b2e08479 | 731 | c(0xc8,0xf0); |
tmnt | 0:ce10b2e08479 | 732 | c(0xc9,0x60); |
tmnt | 0:ce10b2e08479 | 733 | c(0x6b,0x40);//入力クロックx4 |
tmnt | 0:ce10b2e08479 | 734 | c(REG_CLKRC,0x40); //0xaf //PCLK*(1/48) |
tmnt | 0:ce10b2e08479 | 735 | |
tmnt | 0:ce10b2e08479 | 736 | } |
tmnt | 0:ce10b2e08479 | 737 | |
tmnt | 0:ce10b2e08479 | 738 | |
tmnt | 0:ce10b2e08479 | 739 | |
tmnt | 0:ce10b2e08479 | 740 | void camdma_start() |
tmnt | 0:ce10b2e08479 | 741 | { |
tmnt | 0:ce10b2e08479 | 742 | if(flag_dma==0){ |
tmnt | 0:ce10b2e08479 | 743 | HAL_DMA_Start_IT(&DMA_HandleType/*DMA初期設定構造体*/, (uint32_t)&GPIOB->IDR/*&0x00ff転送元アドレス*/, (uint32_t)dma_buf/*転送先アドレス*/,43500/*データ転送回数*/); |
tmnt | 0:ce10b2e08479 | 744 | |
tmnt | 0:ce10b2e08479 | 745 | HAL_SPI_Transmit_DMA(&spi1, (uint8_t*)dma_buf, sizeof(dma_buf)); |
tmnt | 0:ce10b2e08479 | 746 | |
tmnt | 0:ce10b2e08479 | 747 | // HAL_ADC_Start_DMA(&ADC_1_dma,(uint32_t*)ad_dma_buf,3); |
tmnt | 0:ce10b2e08479 | 748 | } |
tmnt | 0:ce10b2e08479 | 749 | flag_dma=1; |
tmnt | 0:ce10b2e08479 | 750 | } |